FileInclude/Exclude
-
Hallo.
Folgender Code stimmt an der Logik nicht:
#include <iostream> using namespace std; string* pattern_array = new string[5000]; string* exclude_array = new string[5000]; int pattern_lines = 0; int exclude_lines = 0; void print_rec_dir(const char *path, string scan_pattern[], int scan_pattern_elements) { char cmd [1000]; string* found_array = new string [5000]; int found_lines = 0; for (int i=0; i < pattern_lines; i++) { strcpy (cmd, "find "); strcat (cmd, path); strcat (cmd, " -type f -exec grep -l \""); strcat (cmd, pattern_array[i].c_str()); strcat (cmd, "\" {} \\; >> /tmp/foundfile"); system (cmd); } /* Check if files were found and send an email */ FILE* f = fopen("/tmp/foundfile", "r"); if (f) { found_array = read_config ("/tmp/foundfile"); found_lines = count_lines ("/tmp/foundfile"); for (int i = 0; i <= found_lines; i++) { for (int j = 0; j < exclude_lines; j++) { cout << "Found array hat den Wert: " << found_array[i] << endl; cout << "Exclude array hat den Wert: " << exclude_array[j] << endl <<endl; if (strstr(found_array[i].c_str(), exclude_array[j].c_str()) == NULL) { cout << "innen: " <<found_array[i]<<endl; char command [5000]; //memset (command, '\0', sizeof(command)); strcpy (command, "echo \""); strcat (command, found_array[i].c_str()); strcat (command, "\" >> /tmp/foundfile.clean"); system (command); } else { //break; j = exclude_lines+99; } } } FILE* fx = fopen ("/tmp/foundfile.clean", "r"); if (fx) { system ("logger -t SIS.BadFile < /tmp/foundfile"); mail_raw ("alexander@localhost", "Found a file", "text"); } fclose(fx); } else { system ("logger -t SIS \"SIS: Scan completed - nothing was found\""); // no files were found } fclose(f); }
Der find Befehl geht mir ein Verzeichnis /syWeb durch und scannt dort jede Datei. Sollte er auf ein Pattern treffen, welches in einer pattern Datei geschrieben ist, so schreibt er den Pfad zu der Datei in /tmp/foundfile.
Nun gibt es eine Exclude Datei, die im Moment folgendermaßen aussieht:
/home/alexander/syweb/usr/local/solarys/backup/tmp/20080901-0300/www.kit-vorarlberg.at/tmp/templates_c/4.php
/home/alexander/syweb/usr/local/solarys/backup/tmp/20080901-0300/www.kit-vorarlberg.at/tmp/templates_c/b77dd.phpNach meinem Programm sollte er nun diese beiden Dateien exkludieren, sprich NICHT in die Datei /tmp/foundfiles.clean schreiben.
Nach dem Programmlauf:
cat /tmp/foundfiles.clean/home/alexander/syweb/usr/local/solarys/backup/tmp/20080901-0300/www.kit-vorarlberg.at/tmp/templates_c/b77dd.php
/home/alexander/syweb/usr/local/solarys/backup/tmp/20080901-0300/www.kit-vorarlberg.at/modules/SystemInfo/external/phpsysinfo/includes/xml/filesystems.php
/home/alexander/syweb/usr/local/solarys/backup/tmp/20080901-0300/www.kit-vorarlberg.at/modules/SystemInfo/external/phpsysinfo/includes/xml/filesystems.php
/home/alexander/syweb/usr/local/solarys/backup/tmp/20080901-0300/www.kit-vorarlberg.at/modules/SystemInfo/external/phpsysinfo/includes/xml/filesystems.php
/home/alexander/syweb/usr/local/solarys/backup/tmp/20080901-0300/www.kit-vorarlberg.at/modules/SystemInfo/external/phpsysinfo/index.php
/home/alexander/syweb/usr/local/solarys/backup/tmp/20080901-0300/www.kit-vorarlberg.at/modules/SystemInfo/external/phpsysinfo/index.php
/home/alexander/syweb/usr/local/solarys/backup/tmp/20080901-0300/www.kit-vorarlberg.at/modules/SystemInfo/external/phpsysinfo/index.php
/home/alexander/syweb/usr/local/solarys/backup/tmp/20080901-0300/www.kit-vorarlberg.at/modules/SystemInfo/external/phpsysinfo/ChangeLog
/home/alexander/syweb/usr/local/solarys/backup/tmp/20080901-0300/www.kit-vorarlberg.at/modules/SystemInfo/external/phpsysinfo/ChangeLog
/home/alexander/syweb/usr/local/solarys/backup/tmp/20080901-0300/www.kit-vorarlberg.at/modules/SystemInfo/external/phpsysinfo/ChangeLog
/home/alexander/syweb/usr/local/solarys/backup/tmp/20080901-0300/www.kit-vorarlberg.at/lib/filemanager/ImageManager/Classes/NetPBM.php
/home/alexander/syweb/usr/local/solarys/backup/tmp/20080901-0300/www.kit-vorarlberg.at/lib/filemanager/ImageManager/Classes/NetPBM.php
/home/alexander/syweb/usr/local/solarys/backup/tmp/20080901-0300/www.kit-vorarlberg.at/lib/filemanager/ImageManager/Classes/NetPBM.phpEr schreibt mir also die erste Datei in der exclude (4.php) NICHT in /tmp/foundfiles.clean, jedoch die 2te Datei (b77dd.php) schon. Außerdem schreibt er jede andere Datei doppelt rein.
Hoffe hier kann wer helfen.
Danke!