updating log entry server scripts
This commit is contained in:
Binary file not shown.
Binary file not shown.
@@ -6,14 +6,14 @@
|
|||||||
"AbsoluteMoniker": "D:0:0:{56E65283-AAC9-43F6-9613-72BE8D648AC4}|client_backend.vcxproj|C:\\Users\\janis\\Documents\\Projekte_mit_c\\ma\\ma\\src\\client_backend\\log.h||{D0E1A5C6-B359-4E41-9B60-3365922C2A22}",
|
"AbsoluteMoniker": "D:0:0:{56E65283-AAC9-43F6-9613-72BE8D648AC4}|client_backend.vcxproj|C:\\Users\\janis\\Documents\\Projekte_mit_c\\ma\\ma\\src\\client_backend\\log.h||{D0E1A5C6-B359-4E41-9B60-3365922C2A22}",
|
||||||
"RelativeMoniker": "D:0:0:{56E65283-AAC9-43F6-9613-72BE8D648AC4}|client_backend.vcxproj|solutionrelative:log.h||{D0E1A5C6-B359-4E41-9B60-3365922C2A22}"
|
"RelativeMoniker": "D:0:0:{56E65283-AAC9-43F6-9613-72BE8D648AC4}|client_backend.vcxproj|solutionrelative:log.h||{D0E1A5C6-B359-4E41-9B60-3365922C2A22}"
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"AbsoluteMoniker": "D:0:0:{56E65283-AAC9-43F6-9613-72BE8D648AC4}|client_backend.vcxproj|C:\\Users\\janis\\Documents\\Projekte_mit_c\\ma\\ma\\src\\client_backend\\connect.h||{D0E1A5C6-B359-4E41-9B60-3365922C2A22}",
|
|
||||||
"RelativeMoniker": "D:0:0:{56E65283-AAC9-43F6-9613-72BE8D648AC4}|client_backend.vcxproj|solutionrelative:connect.h||{D0E1A5C6-B359-4E41-9B60-3365922C2A22}"
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"AbsoluteMoniker": "D:0:0:{56E65283-AAC9-43F6-9613-72BE8D648AC4}|client_backend.vcxproj|C:\\Users\\janis\\Documents\\Projekte_mit_c\\ma\\ma\\src\\client_backend\\connect.cpp||{D0E1A5C6-B359-4E41-9B60-3365922C2A22}",
|
"AbsoluteMoniker": "D:0:0:{56E65283-AAC9-43F6-9613-72BE8D648AC4}|client_backend.vcxproj|C:\\Users\\janis\\Documents\\Projekte_mit_c\\ma\\ma\\src\\client_backend\\connect.cpp||{D0E1A5C6-B359-4E41-9B60-3365922C2A22}",
|
||||||
"RelativeMoniker": "D:0:0:{56E65283-AAC9-43F6-9613-72BE8D648AC4}|client_backend.vcxproj|solutionrelative:connect.cpp||{D0E1A5C6-B359-4E41-9B60-3365922C2A22}"
|
"RelativeMoniker": "D:0:0:{56E65283-AAC9-43F6-9613-72BE8D648AC4}|client_backend.vcxproj|solutionrelative:connect.cpp||{D0E1A5C6-B359-4E41-9B60-3365922C2A22}"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"AbsoluteMoniker": "D:0:0:{56E65283-AAC9-43F6-9613-72BE8D648AC4}|client_backend.vcxproj|C:\\Users\\janis\\Documents\\Projekte_mit_c\\ma\\ma\\src\\client_backend\\connect.h||{D0E1A5C6-B359-4E41-9B60-3365922C2A22}",
|
||||||
|
"RelativeMoniker": "D:0:0:{56E65283-AAC9-43F6-9613-72BE8D648AC4}|client_backend.vcxproj|solutionrelative:connect.h||{D0E1A5C6-B359-4E41-9B60-3365922C2A22}"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"AbsoluteMoniker": "D:0:0:{56E65283-AAC9-43F6-9613-72BE8D648AC4}|client_backend.vcxproj|C:\\Users\\janis\\Documents\\Projekte_mit_c\\ma\\ma\\src\\client_backend\\virus_ctrl.cpp||{D0E1A5C6-B359-4E41-9B60-3365922C2A22}",
|
"AbsoluteMoniker": "D:0:0:{56E65283-AAC9-43F6-9613-72BE8D648AC4}|client_backend.vcxproj|C:\\Users\\janis\\Documents\\Projekte_mit_c\\ma\\ma\\src\\client_backend\\virus_ctrl.cpp||{D0E1A5C6-B359-4E41-9B60-3365922C2A22}",
|
||||||
"RelativeMoniker": "D:0:0:{56E65283-AAC9-43F6-9613-72BE8D648AC4}|client_backend.vcxproj|solutionrelative:virus_ctrl.cpp||{D0E1A5C6-B359-4E41-9B60-3365922C2A22}"
|
"RelativeMoniker": "D:0:0:{56E65283-AAC9-43F6-9613-72BE8D648AC4}|client_backend.vcxproj|solutionrelative:virus_ctrl.cpp||{D0E1A5C6-B359-4E41-9B60-3365922C2A22}"
|
||||||
@@ -74,13 +74,13 @@
|
|||||||
"Children": [
|
"Children": [
|
||||||
{
|
{
|
||||||
"$type": "Document",
|
"$type": "Document",
|
||||||
"DocumentIndex": 1,
|
"DocumentIndex": 2,
|
||||||
"Title": "connect.h",
|
"Title": "connect.h",
|
||||||
"DocumentMoniker": "C:\\Users\\janis\\Documents\\Projekte_mit_c\\ma\\ma\\src\\client_backend\\connect.h",
|
"DocumentMoniker": "C:\\Users\\janis\\Documents\\Projekte_mit_c\\ma\\ma\\src\\client_backend\\connect.h",
|
||||||
"RelativeDocumentMoniker": "connect.h",
|
"RelativeDocumentMoniker": "connect.h",
|
||||||
"ToolTip": "C:\\Users\\janis\\Documents\\Projekte_mit_c\\ma\\ma\\src\\client_backend\\connect.h",
|
"ToolTip": "C:\\Users\\janis\\Documents\\Projekte_mit_c\\ma\\ma\\src\\client_backend\\connect.h",
|
||||||
"RelativeToolTip": "connect.h",
|
"RelativeToolTip": "connect.h",
|
||||||
"ViewState": "AQIAAAAAAAAAAAAAAAAAAAoAAAABAAAA",
|
"ViewState": "AQIAAAAAAAAAAAAAAAAAAAsAAABPAAAA",
|
||||||
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000680|",
|
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000680|",
|
||||||
"WhenOpened": "2024-03-09T12:32:01.859Z",
|
"WhenOpened": "2024-03-09T12:32:01.859Z",
|
||||||
"EditorCaption": ""
|
"EditorCaption": ""
|
||||||
@@ -105,7 +105,7 @@
|
|||||||
"RelativeDocumentMoniker": "log.h",
|
"RelativeDocumentMoniker": "log.h",
|
||||||
"ToolTip": "C:\\Users\\janis\\Documents\\Projekte_mit_c\\ma\\ma\\src\\client_backend\\log.h",
|
"ToolTip": "C:\\Users\\janis\\Documents\\Projekte_mit_c\\ma\\ma\\src\\client_backend\\log.h",
|
||||||
"RelativeToolTip": "log.h",
|
"RelativeToolTip": "log.h",
|
||||||
"ViewState": "AQIAAFEAAAAAAAAAAAAAAHEAAABCAAAA",
|
"ViewState": "AQIAAGYAAAAAAAAAAAAYwJMAAAAkAAAA",
|
||||||
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000680|",
|
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000680|",
|
||||||
"WhenOpened": "2024-02-25T09:02:55.874Z",
|
"WhenOpened": "2024-02-25T09:02:55.874Z",
|
||||||
"EditorCaption": ""
|
"EditorCaption": ""
|
||||||
@@ -120,8 +120,7 @@
|
|||||||
"RelativeToolTip": "log.cpp",
|
"RelativeToolTip": "log.cpp",
|
||||||
"ViewState": "AQIAAAAAAAAAAAAAAAAAABkAAAAeAAAA",
|
"ViewState": "AQIAAAAAAAAAAAAAAAAAABkAAAAeAAAA",
|
||||||
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000677|",
|
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000677|",
|
||||||
"WhenOpened": "2024-02-25T09:08:59.07Z",
|
"WhenOpened": "2024-02-25T09:08:59.07Z"
|
||||||
"EditorCaption": ""
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"$type": "Document",
|
"$type": "Document",
|
||||||
@@ -157,8 +156,7 @@
|
|||||||
"RelativeToolTip": "thread_ctrl.cpp",
|
"RelativeToolTip": "thread_ctrl.cpp",
|
||||||
"ViewState": "AQIAAAAAAAAAAAAAAAAAADoAAAAqAAAA",
|
"ViewState": "AQIAAAAAAAAAAAAAAAAAADoAAAAqAAAA",
|
||||||
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000677|",
|
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000677|",
|
||||||
"WhenOpened": "2024-01-28T20:40:06.264Z",
|
"WhenOpened": "2024-01-28T20:40:06.264Z"
|
||||||
"EditorCaption": ""
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"$type": "Document",
|
"$type": "Document",
|
||||||
@@ -170,8 +168,7 @@
|
|||||||
"RelativeToolTip": "client_backend.cpp",
|
"RelativeToolTip": "client_backend.cpp",
|
||||||
"ViewState": "AQIAAAAAAAAAAAAAAAAAACwAAAAiAAAA",
|
"ViewState": "AQIAAAAAAAAAAAAAAAAAACwAAAAiAAAA",
|
||||||
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000677|",
|
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000677|",
|
||||||
"WhenOpened": "2024-01-28T20:40:06.279Z",
|
"WhenOpened": "2024-01-28T20:40:06.279Z"
|
||||||
"EditorCaption": ""
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"$type": "Document",
|
"$type": "Document",
|
||||||
@@ -183,8 +180,7 @@
|
|||||||
"RelativeToolTip": "scan.cpp",
|
"RelativeToolTip": "scan.cpp",
|
||||||
"ViewState": "AQIAABgAAAAAAAAAAAAAAA4AAAAVAAAA",
|
"ViewState": "AQIAABgAAAAAAAAAAAAAAA4AAAAVAAAA",
|
||||||
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000677|",
|
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000677|",
|
||||||
"WhenOpened": "2024-01-28T20:40:06.248Z",
|
"WhenOpened": "2024-01-28T20:40:06.248Z"
|
||||||
"EditorCaption": ""
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"$type": "Document",
|
"$type": "Document",
|
||||||
@@ -196,8 +192,7 @@
|
|||||||
"RelativeToolTip": "update.cpp",
|
"RelativeToolTip": "update.cpp",
|
||||||
"ViewState": "AQIAABMAAAAAAAAAAAAkwEQAAABzAAAA",
|
"ViewState": "AQIAABMAAAAAAAAAAAAkwEQAAABzAAAA",
|
||||||
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000677|",
|
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000677|",
|
||||||
"WhenOpened": "2024-01-28T20:40:06.248Z",
|
"WhenOpened": "2024-01-28T20:40:06.248Z"
|
||||||
"EditorCaption": ""
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"$type": "Document",
|
"$type": "Document",
|
||||||
@@ -237,13 +232,13 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"$type": "Document",
|
"$type": "Document",
|
||||||
"DocumentIndex": 2,
|
"DocumentIndex": 1,
|
||||||
"Title": "connect.cpp",
|
"Title": "connect.cpp",
|
||||||
"DocumentMoniker": "C:\\Users\\janis\\Documents\\Projekte_mit_c\\ma\\ma\\src\\client_backend\\connect.cpp",
|
"DocumentMoniker": "C:\\Users\\janis\\Documents\\Projekte_mit_c\\ma\\ma\\src\\client_backend\\connect.cpp",
|
||||||
"RelativeDocumentMoniker": "connect.cpp",
|
"RelativeDocumentMoniker": "connect.cpp",
|
||||||
"ToolTip": "C:\\Users\\janis\\Documents\\Projekte_mit_c\\ma\\ma\\src\\client_backend\\connect.cpp",
|
"ToolTip": "C:\\Users\\janis\\Documents\\Projekte_mit_c\\ma\\ma\\src\\client_backend\\connect.cpp",
|
||||||
"RelativeToolTip": "connect.cpp",
|
"RelativeToolTip": "connect.cpp",
|
||||||
"ViewState": "AQIAAG8AAAAAAAAAAAAAAIMAAAABAAAA",
|
"ViewState": "AQIAAJUAAAAAAAAAAAAQwLsAAAAaAAAA",
|
||||||
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000677|",
|
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000677|",
|
||||||
"WhenOpened": "2024-01-28T20:40:06.315Z",
|
"WhenOpened": "2024-01-28T20:40:06.315Z",
|
||||||
"EditorCaption": ""
|
"EditorCaption": ""
|
||||||
@@ -258,8 +253,7 @@
|
|||||||
"RelativeToolTip": "virus_ctrl.cpp",
|
"RelativeToolTip": "virus_ctrl.cpp",
|
||||||
"ViewState": "AQIAADYAAAAAAAAAAAAAAGEAAAAvAAAA",
|
"ViewState": "AQIAADYAAAAAAAAAAAAAAGEAAAAvAAAA",
|
||||||
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000677|",
|
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000677|",
|
||||||
"WhenOpened": "2024-02-18T12:49:41.861Z",
|
"WhenOpened": "2024-02-18T12:49:41.861Z"
|
||||||
"EditorCaption": ""
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -164,4 +164,35 @@ char* url_encode(const char* input) {
|
|||||||
|
|
||||||
return encoded;
|
return encoded;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int upload_to_srv(const char* url, const char* filepath,bool ignore_insecure) {
|
||||||
|
//upload a file to the server
|
||||||
|
CURL* curl;
|
||||||
|
CURLcode res;
|
||||||
|
struct curl_httppost* formpost = NULL;
|
||||||
|
struct curl_httppost* lastptr = NULL;
|
||||||
|
struct curl_slist* headerlist = NULL;
|
||||||
|
static const char buf[] = "Expect:";
|
||||||
|
curl_global_init(CURL_GLOBAL_ALL);
|
||||||
|
curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME, "file", CURLFORM_FILE, filepath, CURLFORM_END);
|
||||||
|
curl = curl_easy_init();
|
||||||
|
if (curl) {
|
||||||
|
curl_easy_setopt(curl, CURLOPT_URL, url);
|
||||||
|
if(ignore_insecure==true)
|
||||||
|
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
|
||||||
|
headerlist = curl_slist_append(headerlist, buf);
|
||||||
|
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headerlist);
|
||||||
|
curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost);
|
||||||
|
res = curl_easy_perform(curl);
|
||||||
|
curl_easy_cleanup(curl);
|
||||||
|
curl_formfree(formpost);
|
||||||
|
curl_slist_free_all(headerlist);
|
||||||
|
if (res == CURLE_OK) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
@@ -8,4 +8,5 @@
|
|||||||
int connect_to_srv(const char* url, char* out, int max_len, bool ignore_insecure);
|
int connect_to_srv(const char* url, char* out, int max_len, bool ignore_insecure);
|
||||||
int download_file_from_srv(const char* url, const char* outputFileName,bool ignore_insecure);
|
int download_file_from_srv(const char* url, const char* outputFileName,bool ignore_insecure);
|
||||||
int fast_send(const char* url, bool ignore_insecure);
|
int fast_send(const char* url, bool ignore_insecure);
|
||||||
char* url_encode(const char* input);
|
char* url_encode(const char* input);
|
||||||
|
int upload_to_srv(const char* url, const char* filepath, bool ignore_insecure);
|
||||||
@@ -9,6 +9,8 @@
|
|||||||
#include "well_known.h"
|
#include "well_known.h"
|
||||||
#include "settings.h"
|
#include "settings.h"
|
||||||
#include "security.h"
|
#include "security.h"
|
||||||
|
int srv_timeout = 0;
|
||||||
|
int timeout_reset = 0;
|
||||||
enum class LOGLEVEL {
|
enum class LOGLEVEL {
|
||||||
INFO,
|
INFO,
|
||||||
WARN,
|
WARN,
|
||||||
@@ -26,6 +28,7 @@ std::string get_loglevel(LOGLEVEL level);
|
|||||||
|
|
||||||
template <typename... Args>
|
template <typename... Args>
|
||||||
void log(LOGLEVEL level, const std::string& message, Args&&... args) {
|
void log(LOGLEVEL level, const std::string& message, Args&&... args) {
|
||||||
|
timeout_reset++;
|
||||||
std::string prefix = get_loglevel(level);
|
std::string prefix = get_loglevel(level);
|
||||||
std::time_t now = std::time(nullptr);
|
std::time_t now = std::time(nullptr);
|
||||||
std::tm tm;
|
std::tm tm;
|
||||||
@@ -92,8 +95,8 @@ void log(LOGLEVEL level, const std::string& message, Args&&... args) {
|
|||||||
fprintf_s(fp, "%s", logString.c_str());
|
fprintf_s(fp, "%s", logString.c_str());
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
}
|
}
|
||||||
//write to server log file
|
//write to server log file only if we werent able to send the logs directly. this file will store them until we can upload them
|
||||||
if (fopen_s(&fp, SRV_LOGFILE, "a") == 0) {
|
if (fopen_s(&fp, SRV_LOGFILE, "a") == 0 && srv_timout>=5) { //if server already did not respon over 5 times, we add it to the log file
|
||||||
fprintf_s(fp, "%s\n", to_srv_string.c_str());
|
fprintf_s(fp, "%s\n", to_srv_string.c_str());
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
}
|
}
|
||||||
@@ -102,8 +105,9 @@ void log(LOGLEVEL level, const std::string& message, Args&&... args) {
|
|||||||
//build up the log string: loglevel&logtext&machineid&date
|
//build up the log string: loglevel&logtext&machineid&date
|
||||||
//to_srv_string=includes the log message
|
//to_srv_string=includes the log message
|
||||||
//we now need to build up the request string and append the machineid
|
//we now need to build up the request string and append the machineid
|
||||||
if (level!=LOGLEVEL::INFO_NOSEND && level!=LOGLEVEL::WARN_NOSEND && level!=LOGLEVEL::ERR_NOSEND && level!=LOGLEVEL::PANIC_NOSEND) {
|
if (level!=LOGLEVEL::INFO_NOSEND && level!=LOGLEVEL::WARN_NOSEND && level!=LOGLEVEL::ERR_NOSEND && level!=LOGLEVEL::PANIC_NOSEND && srv_timeout<5) {
|
||||||
char* url = new char[3000];
|
char* url = new char[3000];
|
||||||
|
int res = 0;
|
||||||
if (get_setting("server:server_url", url) == 0 or strcmp(url, "nan") == 0) {
|
if (get_setting("server:server_url", url) == 0 or strcmp(url, "nan") == 0) {
|
||||||
strcat_s(url, 3000, "/api/php/log/add_entry.php?logtext=");//need to add machine_id and apikey
|
strcat_s(url, 3000, "/api/php/log/add_entry.php?logtext=");//need to add machine_id and apikey
|
||||||
strcat_s(url, 3000, url_encode(to_srv_string.c_str()));
|
strcat_s(url, 3000, url_encode(to_srv_string.c_str()));
|
||||||
@@ -111,7 +115,11 @@ void log(LOGLEVEL level, const std::string& message, Args&&... args) {
|
|||||||
strcat_s(url, 3000, get_machineid(SECRETS));
|
strcat_s(url, 3000, get_machineid(SECRETS));
|
||||||
strcat_s(url, 3000, "&apikey=");
|
strcat_s(url, 3000, "&apikey=");
|
||||||
strcat_s(url, 3000, get_apikey(SECRETS));
|
strcat_s(url, 3000, get_apikey(SECRETS));
|
||||||
fast_send(url, get_setting("communication:unsafe_tls");
|
res=fast_send(url, get_setting("communication:unsafe_tls");
|
||||||
|
if (res != 0) {
|
||||||
|
//we know that the server might be down, so we will increment the timeout counter
|
||||||
|
srv_timeout++;
|
||||||
|
}
|
||||||
//we might not want to log an error occuring here because it will create a loop
|
//we might not want to log an error occuring here because it will create a loop
|
||||||
delete[] url;
|
delete[] url;
|
||||||
}
|
}
|
||||||
@@ -120,6 +128,29 @@ void log(LOGLEVEL level, const std::string& message, Args&&... args) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}//else we do not send the log to the server
|
}//else we do not send the log to the server
|
||||||
|
if(timeout_reset>100){ //after 100 log entrys, we cna try again to reach out ot the server.
|
||||||
|
timeout_reset=0;
|
||||||
|
srv_timeout=0;
|
||||||
|
//try to upload the server_log file, where we stored the logs which we could not upload.
|
||||||
|
char* url = new char[3000];
|
||||||
|
int res = 0;
|
||||||
|
if (get_setting("server:server_url", url) == 0 or strcmp(url, "nan") == 0) {
|
||||||
|
strcat_s(url, 3000, "/api/php/log/add_log.php?machine_id=");
|
||||||
|
strcat_s(url, 3000, get_machineid(SECRETS));
|
||||||
|
strcat_s(url, 3000, "&apikey=");
|
||||||
|
strcat_s(url, 3000, get_apikey(SECRETS));
|
||||||
|
res=upload_to_srv(SRV_LOGFILE, url, get_setting("communication:unsafe_tls"));
|
||||||
|
if (res != 0) {
|
||||||
|
//we know that the server might be down, so we will increment the timeout counter
|
||||||
|
srv_timeout++;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
//remove the logfile
|
||||||
|
remove(SRV_LOGFILE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
delete [] url;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ else{
|
|||||||
$message=$log[2];
|
$message=$log[2];
|
||||||
$loglevel=$log[1];
|
$loglevel=$log[1];
|
||||||
$machine_id=htmlspecialchars($_GET["machine_id"]);
|
$machine_id=htmlspecialchars($_GET["machine_id"]);
|
||||||
$time=log[0];
|
$time=$log[0];
|
||||||
|
|
||||||
//include db pw
|
//include db pw
|
||||||
include "../../../config.php";
|
include "../../../config.php";
|
||||||
@@ -26,7 +26,7 @@ else{
|
|||||||
}
|
}
|
||||||
$sql = "INSERT INTO log (loglevel,machine_id,logtext,time) VALUES (?,?,?,?);";
|
$sql = "INSERT INTO log (loglevel,machine_id,logtext,time) VALUES (?,?,?,?);";
|
||||||
$stmt = $conn->prepare($sql);
|
$stmt = $conn->prepare($sql);
|
||||||
$stmt->bind_param("ssss", $loglevel,$machine_id,$logtext,$time);
|
$stmt->bind_param("ssss", $loglevel,$machine_id,$message,$time);
|
||||||
// Execute the statement
|
// Execute the statement
|
||||||
if(!$stmt->execute())
|
if(!$stmt->execute())
|
||||||
echo("wrt_err");
|
echo("wrt_err");
|
||||||
|
|||||||
38
src/server/cyberhex-code/api/php/log/add_logfile.php
Normal file
38
src/server/cyberhex-code/api/php/log/add_logfile.php
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
<?php
|
||||||
|
include "../accessctrl/check_apikey.php";
|
||||||
|
if(check_apikey()!==true){
|
||||||
|
die("no_auth");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if a file was uploaded
|
||||||
|
if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_FILES["file"])) {
|
||||||
|
//echo($_FILES["file"]["tmp_name"]);
|
||||||
|
//include db pw
|
||||||
|
include "../../../config.php";
|
||||||
|
$conn = new mysqli($DB_SERVERNAME, $DB_USERNAME, $DB_PASSWORD, $DB_DATABASE);
|
||||||
|
if ($conn->connect_error) {
|
||||||
|
die("conn_err");
|
||||||
|
}
|
||||||
|
$fp=fopen($_FILES["file"]["tmp_name"],"r");
|
||||||
|
while(!feof($fp)){
|
||||||
|
$log_entry=fgets($fp);
|
||||||
|
$log_entry=str_replace("\n","",$log_entry);
|
||||||
|
$log=explode(";",$log_entry);
|
||||||
|
$message=$log[2];
|
||||||
|
$loglevel=$log[1];
|
||||||
|
$machine_id=htmlspecialchars($_GET["machine_id"]);
|
||||||
|
$time=$log[0];
|
||||||
|
|
||||||
|
$sql = "INSERT INTO log (loglevel,machine_id,logtext,time) VALUES (?,?,?,?);";
|
||||||
|
$stmt = $conn->prepare($sql);
|
||||||
|
$stmt->bind_param("ssss", $loglevel,$machine_id,$message,$time);
|
||||||
|
// Execute the statement
|
||||||
|
if(!$stmt->execute())
|
||||||
|
echo("wrt_err");
|
||||||
|
else
|
||||||
|
echo("wrt_ok");
|
||||||
|
$stmt->close();
|
||||||
|
}
|
||||||
|
$conn->close();
|
||||||
|
}
|
||||||
|
?>
|
||||||
@@ -29,7 +29,7 @@ if($perms[2]!=="1"){
|
|||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
<div class="container mt-5">
|
<div class="container-fluid">
|
||||||
<div class="row justify-content-center">
|
<div class="row justify-content-center">
|
||||||
<div class="col-md-12">
|
<div class="col-md-12">
|
||||||
<div class="card">
|
<div class="card">
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ $email = $_SESSION["email"];
|
|||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
<div class="container mt-5">
|
<div class="container-fluid">
|
||||||
<div class="row justify-content-center">
|
<div class="row justify-content-center">
|
||||||
<div class="col-md-12">
|
<div class="col-md-12">
|
||||||
<div class="card">
|
<div class="card">
|
||||||
|
|||||||
Reference in New Issue
Block a user