diff options
Diffstat (limited to 'src/scanviewer.cpp')
-rw-r--r-- | src/scanviewer.cpp | 151 |
1 files changed, 96 insertions, 55 deletions
diff --git a/src/scanviewer.cpp b/src/scanviewer.cpp index d61f4a4..0e5e702 100644 --- a/src/scanviewer.cpp +++ b/src/scanviewer.cpp @@ -39,9 +39,9 @@ ScanViewer::ScanViewer(TQWidget *parent, const char *name) : TQWidget(parent, name) { - scanInProgress = TRUE; - multiScan = FALSE; - + scanInProgress = TRUE; + multiScan = FALSE; + //TQGridLayout *layout = new TQGridLayout(this, 6, 3, 10, 4); layout = new TQGridLayout(this, 6, 3, 10, 4); layout->setColStretch(0, 10); @@ -53,9 +53,9 @@ ScanViewer::ScanViewer(TQWidget *parent, const char *name) layout->setRowStretch(2, 10); layout->addRowSpacing(4, 10); layout->setRowStretch(4, 0); - - - + + + resultview = new TQListView(this); resultview->setShowSortIndicator(true); @@ -77,24 +77,24 @@ ScanViewer::ScanViewer(TQWidget *parent, const char *name) menu = new TQPopupMenu( resultview ); - connect(resultview, SIGNAL( contextMenuRequested( TQListViewItem *, const TQPoint& , int ) ), + connect(resultview, SIGNAL( contextMenuRequested( TQListViewItem *, const TQPoint& , int ) ), this, SLOT( slotRMB( TQListViewItem *, const TQPoint &, int ) ) ); - + status_frame = new TQFrame(this); status_frame->setFrameStyle(TQFrame::Panel | TQFrame::Sunken); TQBoxLayout *status_layout = new TQHBoxLayout(status_frame, 2); - + status_label = new TQLabel("", status_frame); status_layout->addWidget(status_label, 10); - + //matches_label = new TQLabel(status_frame); //TQFontMetrics ml_fm(matches_label->fontMetrics()); //matches_label->setFixedWidth(ml_fm.width(i18n("9999 viruses/errors found"))); //matches_label->setFixedHeight(ml_fm.lineSpacing()); //status_layout->addWidget(matches_label, 0); - - + + status_layout->activate(); status_frame->adjustSize(); status_frame->setMinimumSize(status_frame->size()); @@ -103,7 +103,7 @@ ScanViewer::ScanViewer(TQWidget *parent, const char *name) status2_frame = new TQFrame(this); status2_frame->setFrameStyle(TQFrame::Panel | TQFrame::Sunken); status2_layout = new TQHBoxLayout(status2_frame, 2); - + status2_label = new TQLabel(i18n("Files scanned: 0"), status2_frame); status2_layout->addWidget(status2_label, 10); status2_label->hide(); @@ -135,7 +135,7 @@ ScanViewer::ScanViewer(TQWidget *parent, const char *name) matches2_label->setFixedWidth(ml_fm2.width(i18n("9999 viruses/problems found"))); matches2_label->setFixedHeight(ml_fm2.lineSpacing()); status2_layout->addWidget(matches2_label, 0); - + TQToolTip::add(matches2_label, i18n("cf. 'Flanderseses' - Homer Simpson. This childish joke will be removed when KlamAV is more mature.")); status2_layout->activate(); @@ -144,7 +144,7 @@ ScanViewer::ScanViewer(TQWidget *parent, const char *name) layout->addMultiCellWidget(status2_frame, 4, 4, 0, 2); - + layout->activate(); @@ -209,7 +209,7 @@ void ScanViewer::processOutput() filesscanned++; if (!(showProgress)) status2_label->setText(i18n("Files scanned: %1").arg(filesscanned)); - + //}else if ((pos = buf.section('\n',j,j).find("ERROR:")) != -1){ }else if ((pos = (item2.find("ERROR:"))) != -1){ TQString tmpVirusName = item2.mid((fnameEndPoint+1),(item2.length() - (fnameEndPoint+1))); @@ -241,7 +241,7 @@ void ScanViewer::processOutput() "- Access Denied!").arg(tmpFName)); CollectionDB::instance()->insertEvent("Error Found","Access Denied",tmpFName); //}else if ((pos = buf.section('\n',j,j).find(": Can't open")) != -1){ - + }else if ((pos = (item2.find(": Can't open"))) != -1){ //status2_label->setText(i18n("Files scanned: %1").arg(++filesscanned)); filesscanned++; @@ -280,9 +280,9 @@ void ScanViewer::processOutput() void ScanViewer::slotScan(const TQStringList & filepattern, int mode, bool recursive, bool dcopscan) { - //KMessageBox::information (this, filepattern); + //KMessageBox::information (this, filepattern); TDECmdLineArgs *args = TDECmdLineArgs::parsedArgs(); - + if(( args->isSet( "scanthis" ) ) || (dcopscan)) { calculateTime = FALSE; showProgress = FALSE; @@ -341,13 +341,16 @@ void ScanViewer::slotScan(const TQStringList & filepattern, int mode, bool recur //kdDebug() << filepattern << endl; prog->setTotalSteps(cnt); - kdDebug() << "COUNT" << cnt << endl; + kdDebug() << "COUNT" << cnt << endl; config = TDEGlobal::config(); + config->setGroup("KlamavBackend"); + clamdscan = config->readBoolEntry("ScannerClamdscan", false); + slotClear(); QuarantineList.clear(); - + errorsEncountered = FALSE; filesscanned = 0; //status2_label->setText(i18n("Scan in Progress...")); @@ -363,17 +366,17 @@ void ScanViewer::slotScan(const TQStringList & filepattern, int mode, bool recur db = *ita; } } - - ////kdDebug() << "here 2" << endl; + + ////kdDebug() << "here 2" << endl; TQString dbpath; TQString excludes; - TQString options; - + TQString options; // can not be used for clamdscan + if (!(db.isEmpty())) dbpath = TQString(" -d %1 ").arg(db); config->setGroup("Klamscan"); - + if (config->readEntry("ExcludeQuarantine") == "Yes"){ config->setGroup("Kuarantine"); TQStringList lastQuarLocations = config->readListEntry("KuarantineLocations"); @@ -384,7 +387,7 @@ void ScanViewer::slotScan(const TQStringList & filepattern, int mode, bool recur excludes += TQString(" --exclude=%1 ").arg(quarloc); } - + //if ((recursive_box->isChecked() && !(multiScan)) || (multi_recursive && multiScan)) if (recursive) options += " -r "; @@ -397,7 +400,7 @@ void ScanViewer::slotScan(const TQStringList & filepattern, int mode, bool recur // if (KlamavConfig::mBsToExtract() > 0) // options += "--max-space=" + TQString("%1").arg(KlamavConfig::mBsToExtract()) + " "; -// +// // if (KlamavConfig::compressionRatio() > 0) // options += "--max-ratio=" + TQString("%1").arg(KlamavConfig::compressionRatio()) + " "; @@ -410,7 +413,7 @@ void ScanViewer::slotScan(const TQStringList & filepattern, int mode, bool recur if (KlamavConfig::maxScanSize() > 0) options += "--max-scansize=" + TQString("%1").arg(KlamavConfig::maxScanSize()) + "M "; - + //config->setGroup("Klamscan"); // if (KlamavConfig::virusLimitsExceeded()) // options += "--block-max "; @@ -423,7 +426,7 @@ void ScanViewer::slotScan(const TQStringList & filepattern, int mode, bool recur if (!(KlamavConfig::scanHTML())) options += "--no-html "; - + if (!(KlamavConfig::scanPE())) options += "--no-pe "; @@ -449,7 +452,7 @@ void ScanViewer::slotScan(const TQStringList & filepattern, int mode, bool recur else options+=" "; } - + if (KlamavConfig::scanArj()){ options += "--arj"; if ((KlamavConfig::arjUsing()) != "") @@ -465,7 +468,7 @@ void ScanViewer::slotScan(const TQStringList & filepattern, int mode, bool recur else options+=" "; } - + if (KlamavConfig::scanLzh()){ options += "--lha"; if ((KlamavConfig::lzhUsing()) != "") @@ -506,21 +509,59 @@ void ScanViewer::slotScan(const TQStringList & filepattern, int mode, bool recur options+=" "; } - kdDebug() << "clamscan -v " - << excludes << " " - << dbpath << " " - << options << " " - << "'" + m_filepattern.join("' '") + "'" << endl; + if(clamdscan) { + // make sure that clamd is running + FILE* clamdpid; + if( clamdpid = fopen("/run/clamav/clamd.pid","r") ) + fclose(clamdpid); // it's ok + else { + int choice = KMessageBox::warningYesNoCancel( + this, + i18n("The ClamAV daemon does not seem to be running on this system. Do you really want to continue with this scan or would you like to launch a standalone scan instead?'"), + i18n("Clamd not running"), + i18n("Continue this scan"), + i18n("Launch standalone scan"), + i18n("Do not ask me again") + ); + + switch(choice) { + case 2: // cancel + return; + break; + case 4: // launch standalone scan + clamdscan = false; + break; + } + } + } childproc = new KProcIO(); childproc->setUseShell(TRUE); childproc->setUsePty (KProcIO::Stdout,TRUE); - *childproc << "clamscan -v "; - *childproc << excludes << " "; - *childproc << dbpath << " "; - *childproc << options << " "; - + if(clamdscan) { + config->setGroup("KlamavBackend"); + TQString multiscanOption = config->readBoolEntry("ClamdMultiscan", true) ? " -m " : ""; + + kdDebug() << "clamdscan -v " + << multiscanOption + << "'" + m_filepattern.join("' '") + "'" << endl; + + *childproc << "clamdscan -v "; + *childproc << multiscanOption; + } else { + kdDebug() << "clamscan -v " + << excludes << " " + << dbpath << " " + << options << " " + << "'" + m_filepattern.join("' '") + "'" << endl; + + *childproc << "clamscan -v "; + *childproc << excludes << " "; + *childproc << dbpath << " "; + *childproc << options << " "; + } + *childproc << "'" + m_filepattern.join("' '") + "'"; @@ -601,7 +642,7 @@ void ScanViewer::childExited() int status = childproc->exitStatus(); int result; - + status2_label->setText( i18n("Scan Complete") ); CollectionDB::instance()->insertEvent("Manual Scan",TQString("Scan Complete"),m_filepattern.join(" ")); @@ -743,7 +784,7 @@ void ScanViewer::Quarantine(){ KMessageBox::information (this,i18n("<p>There was a problem quarantining <b>%1</b>. Check your diskspace, the permissions on your quarantine location and whether a file with the same name already exists in the quarantine. </p>").arg(fname)); } - + } } if (allQuarantined) @@ -752,7 +793,7 @@ void ScanViewer::Quarantine(){ tdemain->_tray->setPixmap(KSystemTray::loadIcon("klamav_scan_found")); config->writeEntry(TQString("Items %1").arg(quarloc), lastQuarItems); config->sync(); - + //tdemain->kuarantine->refresh(); @@ -807,7 +848,7 @@ void ScanViewer::slotQuarantineSelected() TQPtrList<TQListViewItem> list; TQListViewItemIterator it( resultview, TQListViewItemIterator::Selected ); - + QuarantineList = ""; while ( it.current() ) { TQListViewItem* tItem = it.current(); @@ -844,7 +885,7 @@ void ScanViewer::slotStartAgain() calculateTime = TRUE; emit scanStartingAgain(this); slotScan(m_filepattern, m_mode, m_recursive,false); - + } @@ -865,22 +906,22 @@ void ScanViewer::slotCancelScanTime() // void ScanViewer::startProgress() // { -// +// // cnt = 0; // //kdDebug() << "m_filepattern" << m_filepattern << endl; // TQDir d( m_filepattern ); // // int num = countFiles(d); // // if (countFiles(d) > 0) // // //kdDebug() << "count" << num << endl; -// +// // progress = new KProgressDialog (this, "progress", i18n( "Loading .." ), i18n( "Loading..." ), true); // progress->setAllowCancel(false); // prog = progress->progressBar(); // progress->setLabel(i18n( "Loading lots and lots and lots of virus information" )); // //int cnt = countFiles(d); // prog->setTotalSteps(countFiles(d)); -// //kdDebug() << "COUNT" << countFiles(d) << endl; -// +// //kdDebug() << "COUNT" << countFiles(d) << endl; +// // } int ScanViewer::countFiles( TQDir & root) @@ -894,15 +935,15 @@ int ScanViewer::countFiles( TQDir & root) } TQStringList entries = root.entryList( TQDir::Dirs | TQDir::Files | TQDir::Hidden); - - ////kdDebug() << "count" << counter << endl; + + ////kdDebug() << "count" << counter << endl; for (TQStringList::size_type j = 0; j < entries.size(); j++ ) { TQString entry = entries[j]; if( entry == "." || entry == "..") continue; - + TQFileInfo fi(root, entry ); entry = fi.absFilePath(); @@ -980,7 +1021,7 @@ void ScanViewer::slotOnItem( TQListViewItem * lineitem) status_label->setText( message); - + } void ScanViewer::slotOffItem( ) |