From db65bd01162d919b1926c4e3b5f33f22b2b43716 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mustafa=20=C3=96zcelik=C3=B6rs?= Date: Thu, 1 Mar 2018 13:13:48 +0100 Subject: [PATCH] Bugfixes and new package management and log features MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mustafa Özcelikörs --- forms/mainwindow.ui | 333 +++++++++++++++----- include/mainwindow.h | 3 + include/{ => systemmanager}/aliases.h | 0 include/{ => systemmanager}/environment.h | 0 include/{ => systemmanager}/filesearch.h | 0 include/{ => systemmanager}/networksearch.h | 0 include/{ => systemmanager}/packages.h | 7 + include/{ => systemmanager}/processes.h | 0 include/{ => systemmanager}/sockets.h | 0 include/{ => systemmanager}/systeminfo.h | 11 + install.sh | 8 + src/mainwindow.cpp | 58 ++++ src/{ => systemmanager}/aliases.cpp | 0 src/{ => systemmanager}/environment.cpp | 0 src/{ => systemmanager}/filesearch.cpp | 0 src/{ => systemmanager}/networksearch.cpp | 0 src/{ => systemmanager}/packages.cpp | 77 +++++ src/{ => systemmanager}/processes.cpp | 0 src/{ => systemmanager}/sockets.cpp | 0 src/{ => systemmanager}/systeminfo.cpp | 101 ++++++ src/thread_systeminfo.cpp | 1 + yakala.pro | 41 +-- 22 files changed, 545 insertions(+), 95 deletions(-) rename include/{ => systemmanager}/aliases.h (100%) rename include/{ => systemmanager}/environment.h (100%) rename include/{ => systemmanager}/filesearch.h (100%) rename include/{ => systemmanager}/networksearch.h (100%) rename include/{ => systemmanager}/packages.h (78%) rename include/{ => systemmanager}/processes.h (100%) rename include/{ => systemmanager}/sockets.h (100%) rename include/{ => systemmanager}/systeminfo.h (88%) rename src/{ => systemmanager}/aliases.cpp (100%) rename src/{ => systemmanager}/environment.cpp (100%) rename src/{ => systemmanager}/filesearch.cpp (100%) rename src/{ => systemmanager}/networksearch.cpp (100%) rename src/{ => systemmanager}/packages.cpp (59%) rename src/{ => systemmanager}/processes.cpp (100%) rename src/{ => systemmanager}/sockets.cpp (100%) rename src/{ => systemmanager}/systeminfo.cpp (81%) diff --git a/forms/mainwindow.ui b/forms/mainwindow.ui index 2ada9ec..583d817 100644 --- a/forms/mainwindow.ui +++ b/forms/mainwindow.ui @@ -509,6 +509,106 @@ + + + System Logs and Messages + + + + + 10 + 10 + 661 + 411 + + + + QTabWidget::North + + + 0 + + + + System Logs + + + + + 10 + 10 + 641 + 351 + + + + + Ubuntu + 50 + false + + + + true + + + + + + Driver + + + + + 10 + 10 + 641 + 351 + + + + true + + + + + + Interfaces + + + + + 10 + 10 + 641 + 351 + + + + true + + + + + + USB + + + + + 10 + 10 + 641 + 351 + + + + true + + + + + @@ -820,9 +920,9 @@ - Courier New - 75 - true + Ubuntu + 50 + false @@ -858,7 +958,7 @@ - Commands and Processes + Processes and Packages @@ -939,71 +1039,77 @@ - + - Aliases + Installed Packages - + 10 - 150 + 10 661 - 271 + 411 - List Aliases + List / Uninstall Packages - + + + + 360 + 30 + 131 + 41 + + + + PointingHandCursor + + + Remove Selected + + + 10 - 20 + 80 641 - 241 + 321 - - - - - 10 - 10 - 661 - 131 - - - - Add/Remove Alias - - + - 100 + 140 30 - 291 + 211 41 - + - 100 - 80 - 551 + 20 + 30 + 121 41 + + Filter Packages: + - + - 400 + 500 30 - 121 + 151 41 @@ -1011,15 +1117,43 @@ PointingHandCursor - Add Alias + Autoremove Unused - + + + + + Apt-Cache + + + + + 10 + 10 + 661 + 411 + + + + Package Cache Search + + - 530 + 160 30 - 121 + 331 + 41 + + + + + + + 500 + 30 + 151 41 @@ -1027,40 +1161,37 @@ PointingHandCursor - Remove Alias + Search Cache - + - 20 - 30 - 71 - 41 + 10 + 80 + 641 + 321 - - Alias - - + 20 - 80 - 81 + 30 + 131 41 - Command + Search Package: - Environment Variables + Env. Vars @@ -1180,28 +1311,71 @@ - + - List / Uninstall Packages + Aliases - + + + + 10 + 150 + 661 + 271 + + + + List Aliases + + + + + 10 + 20 + 641 + 241 + + + + + 10 10 661 - 411 + 131 - List / Uninstall Packages + Add/Remove Alias - + - 500 + 100 30 - 151 + 291 + 41 + + + + + + + 100 + 80 + 551 + 41 + + + + + + + 400 + 30 + 121 41 @@ -1209,40 +1383,49 @@ PointingHandCursor - Uninstall Selected + Add Alias - + - 10 - 80 - 641 - 321 + 530 + 30 + 121 + 41 + + PointingHandCursor + + + Remove Alias + - + - 140 + 20 30 - 351 + 71 41 + + Alias + - + 20 - 30 - 121 + 80 + 81 41 - Filter Packages: + Command diff --git a/include/mainwindow.h b/include/mainwindow.h index 32e27b9..ff6a628 100644 --- a/include/mainwindow.h +++ b/include/mainwindow.h @@ -37,6 +37,7 @@ class MainWindow : public QMainWindow void yakalaUpdateProcessTable (void); void yakalaUpdateSocketsTable (void); void yakalaUpdatePackagesTable (void); + void yakalaUpdateAptCacheTable (void); void loadingAnimStart (void); void loadingAnimStop (void); @@ -82,6 +83,8 @@ private slots: void handlePackagesTableClicked (int row, int col); void handlePackageUninstallButton(void); void inputPackageChanged (void); + void handleAutoremovePackageButton (void); + void handlePackageAptCacheButton (void); }; diff --git a/include/aliases.h b/include/systemmanager/aliases.h similarity index 100% rename from include/aliases.h rename to include/systemmanager/aliases.h diff --git a/include/environment.h b/include/systemmanager/environment.h similarity index 100% rename from include/environment.h rename to include/systemmanager/environment.h diff --git a/include/filesearch.h b/include/systemmanager/filesearch.h similarity index 100% rename from include/filesearch.h rename to include/systemmanager/filesearch.h diff --git a/include/networksearch.h b/include/systemmanager/networksearch.h similarity index 100% rename from include/networksearch.h rename to include/systemmanager/networksearch.h diff --git a/include/packages.h b/include/systemmanager/packages.h similarity index 78% rename from include/packages.h rename to include/systemmanager/packages.h index 17fffd8..2860c2c 100644 --- a/include/packages.h +++ b/include/systemmanager/packages.h @@ -23,6 +23,8 @@ class Packages { private: QStringList names; + QStringList aptcachename; + QStringList aptcachedescription; QString uninstallpackage; public: @@ -32,9 +34,14 @@ class Packages QStringList getNames (void); void setUninstallPackage (QString packagename); void searchPackages (QString needle); + void removeUnusedPackages (void); void uninstallPackage (void); QString getUninstallPackage (void); + + void searchAptcache (QString needle); + QStringList getAptcachenames (void); + QStringList getAptcachedescription (void); }; diff --git a/include/processes.h b/include/systemmanager/processes.h similarity index 100% rename from include/processes.h rename to include/systemmanager/processes.h diff --git a/include/sockets.h b/include/systemmanager/sockets.h similarity index 100% rename from include/sockets.h rename to include/systemmanager/sockets.h diff --git a/include/systeminfo.h b/include/systemmanager/systeminfo.h similarity index 88% rename from include/systeminfo.h rename to include/systemmanager/systeminfo.h index e47664f..0ae340a 100644 --- a/include/systeminfo.h +++ b/include/systemmanager/systeminfo.h @@ -48,6 +48,11 @@ class SystemInfo char mac_addr[MAX_BUFSIZE]; + QString ifconfig_out; + QString lsusb_out; + QString syslog_out; + QString dmesg_out; + public: SystemInfo(); void readMemoryTotal(); @@ -91,6 +96,12 @@ class SystemInfo void readMACAddress(QString ip_addr); QString getMACAddress (void); + + void readSysLogs (void); + QString getSysLogOut (void); + QString getDmesgOut (void); + QString getIfconfigOut (void); + QString getLsusbOut (void); }; #endif // SYSTEMINFO_H diff --git a/install.sh b/install.sh index 3b0f2a9..8194220 100755 --- a/install.sh +++ b/install.sh @@ -71,6 +71,14 @@ if [ "" == "$PKG_OK" ]; then sudo apt-get --force-yes --yes install gksu fi +## Check for usbutils +PKG_OK=$(dpkg-query -W --showformat='${Status}\n' 'usbutils' | grep "install ok installed") +echo "Checking for usbutils: $PKG_OK" +if [ "" == "$PKG_OK" ]; then + echo "No usbutils. Setting up usbutils." + sudo apt-get --force-yes --yes install usbutils +fi + ## Check for xterm PKG_OK=$(dpkg-query -W --showformat='${Status}\n' 'xterm' | grep "install ok installed") echo "Checking for xterm: $PKG_OK" diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index cc46e41..dc7c1a4 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -419,6 +419,34 @@ void MainWindow::yakalaUpdateEnvironmentTable (void) ui->tableWidget_env->repaint(); } +void MainWindow::yakalaUpdateAptCacheTable (void) +{ + /* Load table widget for Aliases section */ + ui->tableWidget_aptcache->setColumnCount(2); + ui->tableWidget_aptcache->setRowCount(pa.getAptcachenames().count()); + QStringList TableHeader; + TableHeader<<"Package" << "Description"; + ui->tableWidget_aptcache->setColumnWidth(0, 200); + ui->tableWidget_aptcache->setHorizontalHeaderLabels(TableHeader); + ui->tableWidget_aptcache->horizontalHeader()->setStretchLastSection(true); + + if (pa.getAptcachedescription().count() == pa.getAptcachenames().count()) + { + for (int i = 0; i < pa.getAptcachenames().count(); i++) + { + QTableWidgetItem *item = new QTableWidgetItem(pa.getAptcachenames().at(i)); + item->setFlags(item->flags() ^ Qt::ItemIsEditable); + ui->tableWidget_aptcache->setItem(i, 0, item); + + QTableWidgetItem *item2 = new QTableWidgetItem(pa.getAptcachedescription().at(i)); + item2->setFlags(item2->flags() ^ Qt::ItemIsEditable); + ui->tableWidget_aptcache->setItem(i, 1, item2); + } + } + + this->ui->tableWidget_aptcache->repaint(); +} + void MainWindow::yakalaUpdateNetworkTable (void) { /* Load table widget for Network section */ @@ -582,6 +610,11 @@ void MainWindow::yakalaUiManipulations(void) ui->tabWidget_system->tabBar()->setCursor(Qt::PointingHandCursor); ui->tabWidget_system->tabBar()->setStyleSheet("QTabBar::tab {border-top-left-radius:5px; border-top-right-radius:5px; border-bottom-left-radius:0px; } QTabBar::tab:selected, QTabBar::tab:selected::hover { background: #93C83E; border-bottom-right-radius:0px; color:#333; }"); + /* tabWidget system log and messages */ + ui->tabWidget_systemlogs->tabBar()->setCursor(Qt::PointingHandCursor); + ui->tabWidget_systemlogs->tabBar()->setStyleSheet("QTabBar::tab {border-top-left-radius:5px; border-top-right-radius:5px; border-bottom-left-radius:0px; } QTabBar::tab:selected, QTabBar::tab:selected::hover { background: #ffe100; border-bottom-right-radius:0px; color:#333; }"); + + /* Process part UI manipulations */ this->ui->pushButton_killproc->setStyleSheet("QPushButton { color:white; background-color:red;} QPushButton::hover{color:black; background-color:white;}"); @@ -594,6 +627,17 @@ void MainWindow::yakalaUiManipulations(void) /* Configure graphs */ this->configureGraphs (); + /* System logs */ + s.readSysLogs(); + this->ui->textEdit_driver->setStyleSheet("font-family:'Courier New'; font-size:14px;"); + this->ui->textEdit_interfaces->setStyleSheet("font-family:'Courier New'; font-size:14px;"); + this->ui->textEdit_systemlogs->setStyleSheet("font-family:'Courier New'; font-size:14px;"); + this->ui->textEdit_usb->setStyleSheet("font-family:'Courier New'; font-size:14px;"); + this->ui->textEdit_driver->setText(s.getDmesgOut()); + this->ui->textEdit_interfaces->setText(s.getIfconfigOut()); + this->ui->textEdit_systemlogs->setText(s.getSysLogOut()); + this->ui->textEdit_usb->setText(s.getLsusbOut()); + /*********** CONNECT and TIMERs ***************/ /* Tab bar signal-slot */ @@ -646,9 +690,12 @@ void MainWindow::yakalaUiManipulations(void) connect(ui->tableWidget_packages, SIGNAL(cellClicked(int,int)), this, SLOT(handlePackagesTableClicked(int,int))); connect(ui->pushButton_uninstallpackage, SIGNAL(released()), this, SLOT (handlePackageUninstallButton())); connect(ui->lineEdit_searchpackage, SIGNAL(textChanged(const QString &)), this, SLOT(inputPackageChanged())); + connect(ui->pushButton_aptcache, SIGNAL(released()), this, SLOT (handlePackageAptCacheButton())); /* File search button signal-slot */ connect(ui->pushButton_browsefolder, SIGNAL(released()), this, SLOT (handleBrowseFolderButton())); + + connect(ui->pushButton_autoremove, SIGNAL(released()), this, SLOT (handleAutoremovePackageButton())); } MainWindow::~MainWindow() @@ -658,6 +705,17 @@ MainWindow::~MainWindow() /**************** SLOTS *******************/ +void MainWindow::handlePackageAptCacheButton (void) +{ + pa.searchAptcache(this->ui->lineEdit_searchaptcache->text()); + this->yakalaUpdateAptCacheTable(); +} + +void MainWindow::handleAutoremovePackageButton (void) +{ + pa.removeUnusedPackages(); +} + void MainWindow::handleBrowseFolderButton (void) { QFileDialog *file_dialog = new QFileDialog; diff --git a/src/aliases.cpp b/src/systemmanager/aliases.cpp similarity index 100% rename from src/aliases.cpp rename to src/systemmanager/aliases.cpp diff --git a/src/environment.cpp b/src/systemmanager/environment.cpp similarity index 100% rename from src/environment.cpp rename to src/systemmanager/environment.cpp diff --git a/src/filesearch.cpp b/src/systemmanager/filesearch.cpp similarity index 100% rename from src/filesearch.cpp rename to src/systemmanager/filesearch.cpp diff --git a/src/networksearch.cpp b/src/systemmanager/networksearch.cpp similarity index 100% rename from src/networksearch.cpp rename to src/systemmanager/networksearch.cpp diff --git a/src/packages.cpp b/src/systemmanager/packages.cpp similarity index 59% rename from src/packages.cpp rename to src/systemmanager/packages.cpp index aa68c91..d95fc6c 100644 --- a/src/packages.cpp +++ b/src/systemmanager/packages.cpp @@ -31,6 +31,52 @@ Packages::Packages () this->uninstallpackage = QString("0"); } +void Packages::searchAptcache (QString needle) +{ + this->aptcachename.clear(); + + FILE *fp; + + /* Process retrieval */ + fp = popen ((QString("timeout 30 apt-cache search ") +needle+ QString(" 2>/dev/null | sed 's/\ -.*//' > /tmp/yakala.aptcache && apt-cache search ")+needle+QString(" 2>/dev/null | sed 's/.*- //' > /tmp/yakala.aptcache2")).toLocal8Bit(),"w"); + + if (fp != NULL) + { + + } + else + { + + } + fclose(fp); + + QFile MyFile3("/tmp/yakala.aptcache"); + if (MyFile3.open(QIODevice::ReadWrite)) + { + QTextStream in3 (&MyFile3); + QString line3; + while (!in3.atEnd()) + { + line3 = in3.readLine(); + this->aptcachename.append(line3); + } + MyFile3.close(); + } + + QFile MyFile4("/tmp/yakala.aptcache2"); + if (MyFile4.open(QIODevice::ReadWrite)) + { + QTextStream in4 (&MyFile4); + QString line4; + while (!in4.atEnd()) + { + line4 = in4.readLine(); + this->aptcachedescription.append(line4); + } + MyFile4.close(); + } +} + void Packages::readPackageList (void) { this->names.clear(); @@ -89,6 +135,16 @@ QStringList Packages::getNames (void) return this->names; } +QStringList Packages::getAptcachenames (void) +{ + return this->aptcachename; +} + +QStringList Packages::getAptcachedescription (void) +{ + return this->aptcachedescription; +} + void Packages::uninstallPackage (void) { FILE *fp; @@ -110,6 +166,27 @@ void Packages::uninstallPackage (void) this->readPackageList(); } +void Packages::removeUnusedPackages (void) +{ + FILE *fp; + + /* Process retrieval */ + fp = popen ((QString("echo 'Y' | sudo apt-get autoremove ")+QString(" 1>/dev/null 2>/dev/null")).toLocal8Bit(), "w"); + + if (fp != NULL) + { + + } + else + { + + } + fclose(fp); + + /* Package list update */ + this->readPackageList(); +} + void Packages::setUninstallPackage (QString packagename) { this->uninstallpackage = packagename; diff --git a/src/processes.cpp b/src/systemmanager/processes.cpp similarity index 100% rename from src/processes.cpp rename to src/systemmanager/processes.cpp diff --git a/src/sockets.cpp b/src/systemmanager/sockets.cpp similarity index 100% rename from src/sockets.cpp rename to src/systemmanager/sockets.cpp diff --git a/src/systeminfo.cpp b/src/systemmanager/systeminfo.cpp similarity index 81% rename from src/systeminfo.cpp rename to src/systemmanager/systeminfo.cpp index 5b6dfb3..f35e3f0 100644 --- a/src/systeminfo.cpp +++ b/src/systemmanager/systeminfo.cpp @@ -18,6 +18,9 @@ #include #include #include +#include +#include +#include // To debug, uncomment below, and run 'valgrind -v ./yakala' //#define DEBUG 1 @@ -488,4 +491,102 @@ int SystemInfo::getDiskPercentage (void) return this->disk_percentage; } +void SystemInfo::readSysLogs (void) +{ + this->syslog_out.clear(); + this->lsusb_out.clear(); + this->dmesg_out.clear(); + this->ifconfig_out.clear(); + + /* Syslog */ + QFile MyFile3("/var/log/syslog"); + if (MyFile3.open(QIODevice::ReadWrite)) + { + QTextStream in3 (&MyFile3); + QString line3; + while (!in3.atEnd()) + { + line3 = in3.readLine(); + this->syslog_out.append(line3); + this->syslog_out.append("\n"); + } + MyFile3.close(); + } + + /* Dmesg */ + FILE *fp; + fp = popen ("timeout 5 dmesg > /tmp/yakala.dmesg ","w"); + fclose(fp); + + QFile MyFile4("/tmp/yakala.dmesg"); + if (MyFile4.open(QIODevice::ReadWrite)) + { + QTextStream in3 (&MyFile4); + QString line3; + while (!in3.atEnd()) + { + line3 = in3.readLine(); + this->dmesg_out.append(line3); + this->dmesg_out.append("\n"); + } + MyFile4.close(); + } + + /* Ifconfig */ + FILE *fp2; + fp2 = popen ("timeout 5 ifconfig > /tmp/yakala.ifconfig ","w"); + fclose(fp2); + + QFile MyFile5("/tmp/yakala.ifconfig"); + if (MyFile5.open(QIODevice::ReadWrite)) + { + QTextStream in3 (&MyFile5); + QString line3; + while (!in3.atEnd()) + { + line3 = in3.readLine(); + this->ifconfig_out.append(line3); + this->ifconfig_out.append("\n"); + } + MyFile5.close(); + } + /* Lsusb */ + FILE *fp3; + fp3 = popen ("timeout 5 lsusb > /tmp/yakala.lsusb ","w"); + fclose(fp3); + + QFile MyFile6("/tmp/yakala.lsusb"); + if (MyFile6.open(QIODevice::ReadWrite)) + { + QTextStream in3 (&MyFile6); + QString line3; + while (!in3.atEnd()) + { + line3 = in3.readLine(); + this->lsusb_out.append(line3); + this->lsusb_out.append("\n"); + } + MyFile6.close(); + } +} + +QString SystemInfo::getSysLogOut (void) +{ + return this->syslog_out; +} + +QString SystemInfo::getDmesgOut (void) +{ + return this->dmesg_out; +} + +QString SystemInfo::getIfconfigOut (void) +{ + return this->ifconfig_out; +} + +QString SystemInfo::getLsusbOut (void) +{ + return this->lsusb_out; +} diff --git a/src/thread_systeminfo.cpp b/src/thread_systeminfo.cpp index 774ee75..4e67d84 100644 --- a/src/thread_systeminfo.cpp +++ b/src/thread_systeminfo.cpp @@ -78,6 +78,7 @@ void *Thread_SystemInfo (void *arg) s.readDiskTotal(); pa.readPackageList(); + while (1) { /* Get Periodic System Details*/ diff --git a/yakala.pro b/yakala.pro index d7ecb65..493cda1 100644 --- a/yakala.pro +++ b/yakala.pro @@ -10,34 +10,35 @@ greaterThan(QT_MAJOR_VERSION, 4): QT += widgets printsupport TARGET = yakala TEMPLATE = app -INCLUDEPATH += include/ +INCLUDEPATH += include/ +INCLUDEPATH += include/systemmanager -SOURCES += src/aliases.cpp \ - src/filesearch.cpp \ - src/main.cpp \ +SOURCES += src/main.cpp \ src/mainwindow.cpp \ - src/networksearch.cpp \ - src/systeminfo.cpp \ src/thread_systeminfo.cpp \ - src/environment.cpp \ - src/processes.cpp \ - src/sockets.cpp \ src/qcustomplot.cpp \ - src/packages.cpp - -HEADERS += include/aliases.h \ - include/filesearch.h \ - include/main.h \ + src/systemmanager/aliases.cpp \ + src/systemmanager/filesearch.cpp \ + src/systemmanager/networksearch.cpp \ + src/systemmanager/systeminfo.cpp \ + src/systemmanager/environment.cpp \ + src/systemmanager/processes.cpp \ + src/systemmanager/sockets.cpp \ + src/systemmanager/packages.cpp + +HEADERS += include/main.h \ include/mainwindow.h \ - include/networksearch.h \ - include/systeminfo.h \ include/thread_systeminfo.h \ - include/environment.h \ - include/processes.h \ - include/sockets.h \ include/qcustomplot.h \ - include/packages.h + include/systemmanager/aliases.h \ + include/systemmanager/filesearch.h \ + include/systemmanager/networksearch.h \ + include/systemmanager/systeminfo.h \ + include/systemmanager/environment.h \ + include/systemmanager/processes.h \ + include/systemmanager/sockets.h \ + include/systemmanager/packages.h FORMS += forms/mainwindow.ui