mirror of
https://dev.iopsys.eu/bbf/bbfdm.git
synced 2025-12-10 07:44:39 +01:00
Fix vendor log/config upload to local path
This commit is contained in:
parent
386d1cddb0
commit
4515b63198
4 changed files with 68 additions and 15 deletions
|
|
@ -1963,6 +1963,23 @@ void strip_lead_trail_whitespace(char *str)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int dm_buf_to_file(char *buf, const char *filename)
|
||||||
|
{
|
||||||
|
FILE *file;
|
||||||
|
int ret = -1;
|
||||||
|
|
||||||
|
if (buf == NULL || filename == NULL)
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
file = fopen(filename, "w");
|
||||||
|
if (file) {
|
||||||
|
ret = fputs(buf, file);
|
||||||
|
fclose(file);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
int dm_file_to_buf(const char *filename, void *buf, size_t buf_size)
|
int dm_file_to_buf(const char *filename, void *buf, size_t buf_size)
|
||||||
{
|
{
|
||||||
FILE *file;
|
FILE *file;
|
||||||
|
|
|
||||||
|
|
@ -297,4 +297,5 @@ char *ioctl_get_ipv4(char *interface_name);
|
||||||
char *get_ipv6(char *interface_name);
|
char *get_ipv6(char *interface_name);
|
||||||
bool validate_blob_message(struct blob_attr *src, struct blob_attr *dst);
|
bool validate_blob_message(struct blob_attr *src, struct blob_attr *dst);
|
||||||
void strip_lead_trail_whitespace(char *str);
|
void strip_lead_trail_whitespace(char *str);
|
||||||
|
int dm_buf_to_file(char *buf, const char *filename);
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -179,23 +179,47 @@ static long upload_file(const char *file_path, const char *url, const char *user
|
||||||
{
|
{
|
||||||
long res_code = 0;
|
long res_code = 0;
|
||||||
|
|
||||||
CURL *curl = curl_easy_init();
|
if (strncmp(url, FILE_URI, strlen(FILE_URI)) == 0) {
|
||||||
if (curl) {
|
char dst_path[2046] = {0};
|
||||||
curl_easy_setopt(curl, CURLOPT_URL, url);
|
snprintf(dst_path, sizeof(dst_path), "%s", url+strlen(FILE_URI));
|
||||||
curl_easy_setopt(curl, CURLOPT_USERNAME, username);
|
FILE *fp = fopen(file_path, "r");
|
||||||
curl_easy_setopt(curl, CURLOPT_PASSWORD, password);
|
if (fp == NULL) {
|
||||||
curl_easy_setopt(curl, CURLOPT_TIMEOUT, CURL_TIMEOUT);
|
return -1;
|
||||||
curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L);
|
|
||||||
|
|
||||||
FILE *fp = fopen(file_path, "rb");
|
|
||||||
if (fp) {
|
|
||||||
curl_easy_setopt(curl, CURLOPT_READDATA, fp);
|
|
||||||
curl_easy_perform(curl);
|
|
||||||
fclose(fp);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &res_code);
|
fseek(fp, 0, SEEK_END);
|
||||||
curl_easy_cleanup(curl);
|
unsigned int length = ftell(fp);
|
||||||
|
fseek(fp, 0, SEEK_SET);
|
||||||
|
fclose(fp);
|
||||||
|
|
||||||
|
char buff[length];
|
||||||
|
memset(buff, 0, length);
|
||||||
|
|
||||||
|
if (dm_file_to_buf(file_path, buff, length) > 0) {
|
||||||
|
if (dm_buf_to_file(buff, dst_path) < 0)
|
||||||
|
res_code = -1;
|
||||||
|
} else {
|
||||||
|
res_code = -1;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
CURL *curl = curl_easy_init();
|
||||||
|
if (curl) {
|
||||||
|
curl_easy_setopt(curl, CURLOPT_URL, url);
|
||||||
|
curl_easy_setopt(curl, CURLOPT_USERNAME, username);
|
||||||
|
curl_easy_setopt(curl, CURLOPT_PASSWORD, password);
|
||||||
|
curl_easy_setopt(curl, CURLOPT_TIMEOUT, CURL_TIMEOUT);
|
||||||
|
curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L);
|
||||||
|
|
||||||
|
FILE *fp = fopen(file_path, "rb");
|
||||||
|
if (fp) {
|
||||||
|
curl_easy_setopt(curl, CURLOPT_READDATA, fp);
|
||||||
|
curl_easy_perform(curl);
|
||||||
|
fclose(fp);
|
||||||
|
}
|
||||||
|
|
||||||
|
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &res_code);
|
||||||
|
curl_easy_cleanup(curl);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return res_code;
|
return res_code;
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@ LIST_HEAD(process_list);
|
||||||
static int process_count = 0;
|
static int process_count = 0;
|
||||||
|
|
||||||
#define PROCPS_BUFSIZE 1024
|
#define PROCPS_BUFSIZE 1024
|
||||||
|
#define DEF_VENDOR_LOG_FILE "/tmp/.vend_log"
|
||||||
|
|
||||||
struct process_entry {
|
struct process_entry {
|
||||||
struct list_head list;
|
struct list_head list;
|
||||||
|
|
@ -1214,8 +1215,18 @@ static int operate_DeviceInfoVendorLogFile_Upload(char *refparam, struct dmctx *
|
||||||
|
|
||||||
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "log_file", &vlf_file_path);
|
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "log_file", &vlf_file_path);
|
||||||
|
|
||||||
|
if (DM_STRLEN(vlf_file_path) == 0) {
|
||||||
|
vlf_file_path = DEF_VENDOR_LOG_FILE;
|
||||||
|
char cmd[64] = {0};
|
||||||
|
snprintf(cmd, sizeof(cmd), "logread > %s", DEF_VENDOR_LOG_FILE);
|
||||||
|
system(cmd);
|
||||||
|
}
|
||||||
|
|
||||||
int res = bbf_upload_log(url, user, pass, vlf_file_path, upload_command, upload_path);
|
int res = bbf_upload_log(url, user, pass, vlf_file_path, upload_command, upload_path);
|
||||||
|
|
||||||
|
if (file_exists(DEF_VENDOR_LOG_FILE))
|
||||||
|
remove(DEF_VENDOR_LOG_FILE);
|
||||||
|
|
||||||
return res ? CMD_FAIL : CMD_SUCCESS;
|
return res ? CMD_FAIL : CMD_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue