diff --git a/src/client_backend/.vs/client_backend/FileContentIndex/03bced36-7795-49fb-b10a-1d6abc018983.vsidx b/src/client_backend/.vs/client_backend/FileContentIndex/03bced36-7795-49fb-b10a-1d6abc018983.vsidx deleted file mode 100644 index 90a2119..0000000 Binary files a/src/client_backend/.vs/client_backend/FileContentIndex/03bced36-7795-49fb-b10a-1d6abc018983.vsidx and /dev/null differ diff --git a/src/client_backend/.vs/client_backend/v17/Browse.VC.db b/src/client_backend/.vs/client_backend/v17/Browse.VC.db index 5bfd1c6..9ec9341 100644 Binary files a/src/client_backend/.vs/client_backend/v17/Browse.VC.db and b/src/client_backend/.vs/client_backend/v17/Browse.VC.db differ diff --git a/src/client_backend/client_backend.cpp b/src/client_backend/client_backend.cpp index 323a6c6..693dc62 100644 --- a/src/client_backend/client_backend.cpp +++ b/src/client_backend/client_backend.cpp @@ -63,6 +63,7 @@ int main() { //unlock_task("tsk1"); else it will only be executed once. but this function has to be called at the end of the task. else it will nvr be executed again. this would be bad :( //start a thread that executes check_scan_dir to scan folders for new files. this thread then should start a ock so only one scanfolder thread runs at a time //Sleep(1000); + if (can_run_thread()) { int queue_size = get_queue_size(); for (int i = 0; i < queue_size; i++) { @@ -70,7 +71,6 @@ int main() { queue_entry[0] = '\0'; queue_pop(queue_entry); //execute the function which starts the threads - // printf("%s\n", queue_entry); start_thread(queue_entry); delete[] queue_entry; } diff --git a/src/client_backend/connect.cpp b/src/client_backend/connect.cpp index 016e05e..74f505a 100644 --- a/src/client_backend/connect.cpp +++ b/src/client_backend/connect.cpp @@ -89,16 +89,16 @@ int download_file_from_srv(const char* url, const char* output_file_path) { fclose(output_file); return 5; } - else if(check_cert(buf, SECRETS)!=0){ - if (rename(temp_path, output_file_path)) { - fclose(output_file); + else if(check_cert(buf, SECRETS)==0){ + remove(output_file_path);//remove old file, so it can be overwritten + fclose(output_file); + if (rename(temp_path, output_file_path)!=0) { return 6; } }else { fclose(output_file); return 7; } - fclose(output_file); } delete[] buf; delete[] temp_path; diff --git a/src/client_backend/local_schedule.cpp b/src/client_backend/local_schedule.cpp index 8659ade..5cab90c 100644 --- a/src/client_backend/local_schedule.cpp +++ b/src/client_backend/local_schedule.cpp @@ -85,7 +85,7 @@ void unlock_task(const std::string& task_name) { int check_for_sched_tasks(const char* sched_name, const char* sched_path) { FILE* fp = nullptr; - char* command = new char[300]; + char* command = new char[505]; if ((fopen_s(&fp, sched_path, "r")) != 0) { //panic, create log entry, return 1; //no schedule file found. this is not normal @@ -94,77 +94,87 @@ int check_for_sched_tasks(const char* sched_name, const char* sched_path) { return 1; } else { + fscanf_s(fp, "%s", command, 500); //the cert is always the firs tline + fgetc(fp); //get the newline while (!feof(fp)) { - //read date-time config. it starts with " and ends with " - char* datetime = new char[300]; - datetime[0] = '\0'; - //search for datetime, starting ", then loop until ending " - int cnt = 0; - int chr = 0; - chr = fgetc(fp);//read in the first ", or at least try it - //printf("%c\n", chr); - if (chr == '\"'){ + if (!feof(fp)) { + //read date-time config. it starts with " and ends with " + char* datetime = new char[300]; + datetime[0] = '\0'; + //search for datetime, starting ", then loop until ending " + int cnt = 0; + int chr = 0; + chr = fgetc(fp);//read in the first ", or at least try it + //printf("%c\n", chr); + if (chr == '\"') { + chr = 0; + while (cnt < 295 && chr != '\"') { + chr = fgetc(fp); //get a char + if (chr != '\"') + datetime[cnt] = chr; + datetime[cnt + 1] = '\0'; + cnt++; + //printf("scanning...\n"); + } + } + //now we had datetime. we can scan the command and the path now + fscanf_s(fp, "%s", command, 295); // get the command + char* path = new char[300]; + path[0] = '\0'; + //search for arg, starting ", then loop until ending " + cnt = 0; chr = 0; - while (cnt < 295 && chr != '\"') { - chr = fgetc(fp); //get a char - if (chr != '\"') - datetime[cnt] = chr; - datetime[cnt + 1] = '\0'; - cnt++; - //printf("scanning...\n"); - } - } - //now we had datetime. we can scan the command and the path now - fscanf_s(fp, "%s", command, 295); // get the command - char* path = new char[300]; - path[0] = '\0'; - //search for datetime, starting ", then loop until ending " - cnt = 0; - chr = 0; - fgetc(fp); //get th ewhitespoace after the command - chr = fgetc(fp);//read in the first ", or at least try it - if (chr == '\"') { - chr = 0; - while (cnt < 295 && chr != '\"') { - chr = fgetc(fp); //get a char - if (chr != '\"') - path[cnt] = chr; - path[cnt + 1] = '\0'; - cnt++; - } - } - //now get the taskname - char* taskname = new char[300]; - taskname[0] = '\0'; - fscanf_s(fp, "%s", taskname, 295); // get the taskname + fgetc(fp); //get th ewhitespoace after the command + chr = fgetc(fp);//read in the first ", or at least try it - //lets check if the command should be executed - //get the current time - std::time_t t = std::time(nullptr); - struct std::tm current_time; - localtime_s(¤t_time, &t); - //printf("%s\n", datetime); - if (strcmp(datetime, "") != 0 && strcmp(command, "") != 0 && strcmp(path, "") != 0 && strcmp(taskname, "") != 0) { - if (is_task_due(taskname,datetime, current_time)) { - //printf("command:%s\n", command); - //printf("path:%s\n", path); - //now we can build up the command for the queue - char* queue_entry = new char[300 * 2 + 5]; //to enshure we have enough space - queue_entry[0] = '\0'; - strcpy_s(queue_entry, 600, command); //copy the command - strcat_s(queue_entry, 600, ";"); //add a ; to seperate command and path - strcat_s(queue_entry, 600, path); //add the path - - queue_push(queue_entry); - delete[] queue_entry; + if (chr == '\"') { + chr = 0; + while (cnt < 295 && chr != '\"') { + chr = fgetc(fp); //get a char + if (chr != '\"') + path[cnt] = chr; + path[cnt + 1] = '\0'; + cnt++; + } } + //now get the taskname + char* taskname = new char[300]; + taskname[0] = '\0'; + fscanf_s(fp, "%s", taskname, 295); // get the taskname + fgetc(fp); //get the newline + //lets check if the command should be executed + //get the current time + std::time_t t = std::time(nullptr); + struct std::tm current_time; + localtime_s(¤t_time, &t); + + //printf("%s\n", datetime); + if (strcmp(datetime, "") != 0 && strcmp(command, "") != 0 && strcmp(path, "") != 0 && strcmp(taskname, "") != 0) { + if (is_task_due(taskname, datetime, current_time)) { + //printf("command:%s\n", command); + //printf("path:%s\n", path); + //now we can build up the command for the queue + char* queue_entry = new char[300 * 2 + 5]; //to enshure we have enough space + queue_entry[0] = '\0'; + strcpy_s(queue_entry, 600, command); //copy the command + strcat_s(queue_entry, 600, ";"); //add a ; to seperate command and path + strcat_s(queue_entry, 600, path); //add the path + + queue_push(queue_entry); + delete[] queue_entry; + } + } + //else { + // printf("datetime:%s\n", datetime); + // printf("command:%s\n", command); + // printf("path:%s\n", path); + // printf("taskname:%s\n", taskname); + // log(LOGLEVEL::ERR, "[check_for_sched_tasks()]: Error reading schedule file: ", sched_path, " while checking for scheduled tasks (malformat); aborting"); + //} + delete[] datetime; + delete[] path; + delete[] taskname; } - else { - log(LOGLEVEL::ERR, "[check_for_sched_tasks()]: Error reading schedule file: ", sched_path, " while checking for scheduled tasks (malformat); aborting"); - } - delete[] datetime; - delete[] path; - delete[] taskname; } } delete[] command; diff --git a/src/client_backend/settings.cpp b/src/client_backend/settings.cpp index acb57ba..d2ec200 100644 --- a/src/client_backend/settings.cpp +++ b/src/client_backend/settings.cpp @@ -21,8 +21,9 @@ int load_settings() { return 1; } else { - char*settings_cmd=new char[300]; + char*settings_cmd=new char[505]; char*settings_arg= new char[300]; + fscanf_s(fp, "%s", settings_cmd, 500); //the cert is always the firs tline while (!feof(fp)) { fscanf_s(fp, "%s", settings_cmd, 295); // get the command //now check which setting it is. @@ -95,7 +96,8 @@ void load_included_folders() { return; } else { - char* path = new char[300]; + char* path = new char[505]; + fscanf_s(fp, "%s", path, 500); //the cert is always the firs tline while (!feof(fp)) { //get the path of an excluded folder path[0] = '\0'; @@ -136,7 +138,8 @@ void load_excluded_folders() { return; } else { - char* path = new char[300]; + char* path = new char[505]; + fscanf_s(fp, "%s", path,500); //the cert is always the firs tline while (!feof(fp)) { //get the path of an excluded folder path[0] = '\0'; diff --git a/src/client_backend/thread_ctrl.cpp b/src/client_backend/thread_ctrl.cpp index 131282a..6a7c2ee 100644 --- a/src/client_backend/thread_ctrl.cpp +++ b/src/client_backend/thread_ctrl.cpp @@ -5,6 +5,7 @@ #include "well_known.h" #include "scan.h" #include "app_ctrl.h" +#include "update.h" void split(char* input,const char delimiter, char* out1, char* out2) { //split a string at the delimiter. the delimiter only occurs once. so the first part is out1 and the second part is out2 int i = 0; @@ -48,6 +49,11 @@ int start_thread(const char* command) { std::thread t1(action_scanfolder, out2); t1.detach(); } + else if (strcmp(out1, "update_settings") == 0) { + //start a new thread with the scanfolder function + std::thread t1(action_update_settings); + t1.detach(); + } while (can_run_thread()) { //delay a bit, in order to wait until the thread is started diff --git a/src/client_backend/update.cpp b/src/client_backend/update.cpp index 5ec9741..d16e139 100644 --- a/src/client_backend/update.cpp +++ b/src/client_backend/update.cpp @@ -53,7 +53,7 @@ int update_settings(const char*settings_type) { int res = 1; if(strcmp(settings_type,"settings")==0) res = download_file_from_srv(url, SETTINGS_DB); - else if (strcmp(settings_type, "rtp_inlcuded") == 0) + else if (strcmp(settings_type, "rtp_included") == 0) res = download_file_from_srv(url, INCLUDED_FOLDERS); else if (strcmp(settings_type, "rtp_excluded") == 0) res = download_file_from_srv(url, EXCLUDED_FOLDERS); @@ -68,4 +68,24 @@ int update_settings(const char*settings_type) { delete[] url; return 0; } +int action_update_settings() { + //update the settings + int err = 0; + if (update_settings("settings") != 0) { + err= 1; + } + //update the included folders + if (update_settings("rtp_included") != 0) { + err= 2; + } + //update the excluded folders + if (update_settings("rtp_excluded") != 0) { + err= 3; + } + //update the schedule + if (update_settings("sched") != 0) { + err= 4; + } + return err; +} #endif \ No newline at end of file diff --git a/src/client_backend/update.h b/src/client_backend/update.h index f528eef..3fb2d61 100644 --- a/src/client_backend/update.h +++ b/src/client_backend/update.h @@ -5,4 +5,5 @@ #include int update_db(const std::string& folder_path); int update_settings(const char*settings_type); +int action_update_settings(); #endif \ No newline at end of file diff --git a/src/client_backend/x64/Debug/client_backend.ilk b/src/client_backend/x64/Debug/client_backend.ilk index f8324a6..044eaf3 100644 Binary files a/src/client_backend/x64/Debug/client_backend.ilk and b/src/client_backend/x64/Debug/client_backend.ilk differ diff --git a/src/client_backend/x64/Debug/client_backend.log b/src/client_backend/x64/Debug/client_backend.log index adad5d4..dfee2f3 100644 --- a/src/client_backend/x64/Debug/client_backend.log +++ b/src/client_backend/x64/Debug/client_backend.log @@ -1,3 +1,3 @@  Quellen werden auf Modulabhängigkeiten überprüft... - update.cpp + local_schedule.cpp client_backend.vcxproj -> C:\Users\janis\Documents\Projekte_mit_c\ma\ma\src\client_backend\x64\Debug\client_backend.exe diff --git a/src/client_backend/x64/Debug/client_backend.pdb b/src/client_backend/x64/Debug/client_backend.pdb index ae003f8..5c519f1 100644 Binary files a/src/client_backend/x64/Debug/client_backend.pdb and b/src/client_backend/x64/Debug/client_backend.pdb differ diff --git a/src/client_backend/x64/Debug/client_backend.tlog/CL.command.1.tlog b/src/client_backend/x64/Debug/client_backend.tlog/CL.command.1.tlog index ebcfa4f..27ea6fa 100644 Binary files a/src/client_backend/x64/Debug/client_backend.tlog/CL.command.1.tlog and b/src/client_backend/x64/Debug/client_backend.tlog/CL.command.1.tlog differ diff --git a/src/client_backend/x64/Debug/client_backend.tlog/CL.read.1.tlog b/src/client_backend/x64/Debug/client_backend.tlog/CL.read.1.tlog index 58d84d9..bd782ce 100644 Binary files a/src/client_backend/x64/Debug/client_backend.tlog/CL.read.1.tlog and b/src/client_backend/x64/Debug/client_backend.tlog/CL.read.1.tlog differ diff --git a/src/client_backend/x64/Debug/client_backend.tlog/CL.write.1.tlog b/src/client_backend/x64/Debug/client_backend.tlog/CL.write.1.tlog index c37ff74..d5df3b5 100644 Binary files a/src/client_backend/x64/Debug/client_backend.tlog/CL.write.1.tlog and b/src/client_backend/x64/Debug/client_backend.tlog/CL.write.1.tlog differ diff --git a/src/client_backend/x64/Debug/client_backend.tlog/client_backend.write.1u.tlog b/src/client_backend/x64/Debug/client_backend.tlog/client_backend.write.1u.tlog index aff65e6..2e6228f 100644 Binary files a/src/client_backend/x64/Debug/client_backend.tlog/client_backend.write.1u.tlog and b/src/client_backend/x64/Debug/client_backend.tlog/client_backend.write.1u.tlog differ diff --git a/src/client_backend/x64/Debug/vc143.idb b/src/client_backend/x64/Debug/vc143.idb index 4e9592d..2650bff 100644 Binary files a/src/client_backend/x64/Debug/vc143.idb and b/src/client_backend/x64/Debug/vc143.idb differ diff --git a/src/client_backend/x64/Debug/vc143.pdb b/src/client_backend/x64/Debug/vc143.pdb index 47c0f00..f07602f 100644 Binary files a/src/client_backend/x64/Debug/vc143.pdb and b/src/client_backend/x64/Debug/vc143.pdb differ diff --git a/src/server/cyberhex-code/system/secure_zone/php/client_settings.php b/src/server/cyberhex-code/system/secure_zone/php/client_settings.php index 1b4ee41..b7a09f4 100644 --- a/src/server/cyberhex-code/system/secure_zone/php/client_settings.php +++ b/src/server/cyberhex-code/system/secure_zone/php/client_settings.php @@ -424,6 +424,7 @@ function load_settings(){ +