Align with VendorLogFile

This commit is contained in:
Suvendhu Hansa 2024-10-04 18:55:57 +05:30 committed by Vivek Kumar Dutta
parent 78e522060b
commit c9d3ba0a1a
3 changed files with 69 additions and 45 deletions

View file

@ -74,7 +74,8 @@
#define BUF_SIZE_2048 (2048 + 1)
#define ICWMP_TMP_PATH "/tmp/icwmp"
#define FIREWALL_CWMP "/etc/firewall.cwmp"
#define VENDOR_LOG_SCRIPT "/etc/icwmpd/vendor_log.sh"
#define FIREWALL_CWMP "/etc/icwmpd/firewall.cwmp"
#define CWMP_CRITICAL_SERVICES "/etc/icwmpd/critical_services.json"
#define DM_PPP_INTERFACE_PATH "Device\\.PPP\\.Interface\\."
#define DM_IP_INTERFACE_PATH "Device\\.IP\\.Interface\\."

View file

@ -21,6 +21,7 @@
#include "subprocess.h"
#include "session.h"
#include "uci_utils.h"
#include "ubus_utils.h"
#define CURL_TIMEOUT 30
@ -48,22 +49,31 @@ static int lookup_vcf_name(int instance, char **value)
return 0;
}
static int lookup_vlf_name(int instance, char **value)
static int generate_log_archive(int instance, char *url)
{
char vlf_name_parameter[256];
LIST_HEAD(vlf_parameters);
snprintf(vlf_name_parameter, sizeof(vlf_name_parameter), "Device.DeviceInfo.VendorLogFile.%d.Name", instance);
if (cwmp_get_parameter_values(vlf_name_parameter, &vlf_parameters) != NULL) {
CWMP_LOG(ERROR, "Not able to get the value of the parameter %s", vlf_name_parameter);
return -1;
}
struct cwmp_dm_parameter *param_value = NULL;
list_for_each_entry (param_value, &vlf_parameters, list) {
*value = param_value->value ? strdup(param_value->value) : NULL;
break;
}
cwmp_free_all_dm_parameter_list(&vlf_parameters);
return 0;
char vlf_upload_operate[256];
struct blob_buf b = {0};
CWMP_MEMSET(&b, 0, sizeof(struct blob_buf));
blob_buf_init(&b, 0);
snprintf(vlf_upload_operate, sizeof(vlf_upload_operate), "Device.DeviceInfo.VendorLogFile.%d.Upload()", instance);
bb_add_string(&b, "command", vlf_upload_operate);
bb_add_string(&b, "command_key", "vendor_log_upload");
void *tbl = blobmsg_open_table(&b, "input");
bb_add_string(&b, "URL", url);
bb_add_string(&b, "Username", "");
bb_add_string(&b, "Password", "");
blobmsg_close_table(&b, tbl);
int e = icwmp_ubus_invoke(BBFDM_OBJECT_NAME, "operate", b.head, NULL, NULL);
blob_buf_free(&b);
return e;
}
/*
@ -239,17 +249,29 @@ int cwmp_launch_upload(struct upload *pupload, struct transfer_complete **ptrans
snprintf(file_path, sizeof(file_path), "%s/all_configs", ICWMP_TMP_PATH);
export_std_uci(file_path);
} else if (pupload->file_type[0] == '2') {
lookup_vlf_name(1, &name);
if (name && strlen(name) > 0) {
snprintf(file_path, sizeof(file_path), "%s/messages", ICWMP_TMP_PATH);
if (copy(name, file_path) != 0) {
if (file_exists(VENDOR_LOG_SCRIPT)) {
char cmd[256] = {0};
snprintf(cmd, sizeof(cmd), "sh %s", VENDOR_LOG_SCRIPT);
memset(file_path, 0, sizeof(file_path));
FILE *pp = popen(cmd, "r"); // flawfinder: ignore
if (pp != NULL) {
fgets(file_path, sizeof(file_path), pp);
pclose(pp);
}
int path_len = strlen(file_path);
if (path_len == 0) {
error = FAULT_CPE_UPLOAD_FAILURE;
snprintf(err_msg, sizeof(err_msg), "Failed to copy the file content from %s to %s", file_path, name);
FREE(name);
snprintf(err_msg, sizeof(err_msg), "No log file to upload");
} else {
if (file_path[path_len - 1] == '\n')
file_path[path_len - 1] = '\0';
}
} else {
error = FAULT_CPE_UPLOAD_FAILURE;
snprintf(err_msg, sizeof(err_msg), "No filename found");
snprintf(err_msg, sizeof(err_msg), "Error in generating log file");
}
} else if (pupload->file_type[0] == '3') {
lookup_vcf_name(pupload->f_instance, &name);
@ -263,18 +285,19 @@ int cwmp_launch_upload(struct upload *pupload, struct transfer_complete **ptrans
goto end_upload;
}
} else { //file_type is 4
lookup_vlf_name(pupload->f_instance, &name);
if (name && strlen(name) > 0) {
snprintf(file_path, sizeof(file_path), "%s/.cwmp_upload", ICWMP_TMP_PATH);
if (copy(name, file_path) != 0) {
error = FAULT_CPE_UPLOAD_FAILURE;
snprintf(err_msg, sizeof(err_msg), "Failed to copy the file content from %s to %s", file_path, name);
FREE(name);
}
FREE(name);
} else {
char arch_path[135] = {0};
snprintf(file_path, sizeof(file_path), "%s/.cwmp_upload.tar", ICWMP_TMP_PATH);
snprintf(arch_path, sizeof(arch_path), "file://%s", file_path);
if (0 != generate_log_archive(pupload->f_instance, arch_path)) {
error = FAULT_CPE_UPLOAD_FAILURE;
snprintf(err_msg, sizeof(err_msg), "No filename found");
snprintf(err_msg, sizeof(err_msg), "Internal error to archive the log files");
}
if (!file_exists(file_path)) {
error = FAULT_CPE_UPLOAD_FAILURE;
snprintf(err_msg, sizeof(err_msg), "Failed to archive the logs");
}
}
@ -286,7 +309,7 @@ int cwmp_launch_upload(struct upload *pupload, struct transfer_complete **ptrans
}
int ret = upload_file_in_subprocess(file_path, pupload->url, pupload->username, pupload->password);
if (ret == 200 || ret == 204)
if (ret == 200 || ret == 201 || ret == 204)
error = FAULT_CPE_NO_FAULT;
else {
error = FAULT_CPE_UPLOAD_FAILURE;

View file

@ -8,14 +8,14 @@ TEST_NAME="ICWMP COMMAND LINE"
log "Running: $TEST_NAME"
log "GET METHOD: Correct Path"
res=$(./icwmpd -c get Device.DeviceInfo.VendorLogFile.1.Alias 2>&1)
res=$(./icwmpd -c get Device.DeviceInfo.VendorConfigFile.1.Alias 2>&1)
if [[ $res != *"cpe-1"* ]]; then
log "Error: Get Method with correct path doesn't work correctly"
exit 1
fi
log "GET METHOD: Wrong Path"
res=$(./icwmpd -c get Device.DeviceInfo.VendorLogFile.1.Alia 2>&1)
res=$(./icwmpd -c get Device.DeviceInfo.VendorConfigFile.1.Alia 2>&1)
if [[ $res != *"9005"* ]]; then
log "Error: Get Method with wrong path doesn't work correctly"
exit 1
@ -43,21 +43,21 @@ if [[ $res != *"9007"* ]]; then
fi
log "GET NAME METHOD: Correct Path && level"
res=$(./icwmpd -c get_names Device.DeviceInfo.VendorLogFile.1.Alias 0 2>&1)
res=$(./icwmpd -c get_names Device.DeviceInfo.VendorConfigFile.1.Alias 0 2>&1)
if [[ $res != *"=> writable"* ]]; then
log "Error: Get Name Method with correct path && level doesn't work correctly"
exit 1
fi
log "GET NAME METHOD: Correct Path && Wrong level"
res=$(./icwmpd -c get_names Device.DeviceInfo.VendorLogFile.1.Alias 1 2>&1)
res=$(./icwmpd -c get_names Device.DeviceInfo.VendorConfigFile.1.Alias 1 2>&1)
if [[ $res != *"9003"* ]]; then
log "Error: Get Name Method with correct path && wrong level doesn't work correctly"
exit 1
fi
log "GET NAME METHOD: Wrong Path && Correct level"
res=$(./icwmpd -c get_names Device.DeviceInfo.VendorLogFile.1.Ali 0 2>&1)
res=$(./icwmpd -c get_names Device.DeviceInfo.VendorConfigFile.1.Ali 0 2>&1)
if [[ $res != *"9005"* ]]; then
log "Error: Get Name Method with wrong path && correct level doesn't work correctly"
exit 1
@ -71,21 +71,21 @@ if [[ $res != *"=> active"* ]]; then
fi
log "GET NOTIFICATION METHOD: Wrong Path"
res=$(./icwmpd -c get_notif Device.DeviceInfo.VendorLogFile.1.Ali 2>&1)
res=$(./icwmpd -c get_notif Device.DeviceInfo.VendorConfigFile.1.Ali 2>&1)
if [[ $res != *"9005"* ]]; then
log "Error: Get Notification Method with wrong path doesn't work correctly"
exit 1
fi
log "SET NOTIFICATION METHOD: Correct Path"
res=$(./icwmpd -c set_notif Device.DeviceInfo.VendorLogFile.1.Alias 2 2>&1)
res=$(./icwmpd -c set_notif Device.DeviceInfo.VendorConfigFile.1.Alias 2 2>&1)
if [[ $res != *"=> 2"* ]]; then
log "Error: Set Notification Method with correct path doesn't work correctly"
exit 1
fi
log "SET NOTIFICATION METHOD: Wrong Path"
res=$(./icwmpd -c set_notif Device.DeviceInfo.VendorLogFile.1.Ali 1 2>&1)
res=$(./icwmpd -c set_notif Device.DeviceInfo.VendorConfigFile.1.Ali 1 2>&1)
if [[ $res != *"9005"* ]]; then
log "Error: Set Notification Method with wrong path doesn't work correctly"
exit 1
@ -108,14 +108,14 @@ fi
del_path=$(echo "${res}" | cut -d' ' -f 2)
log "ADD METHOD: Wrong Path"
res=$(./icwmpd -c add Device.DeviceInfo.VendorLogFil 2>&1)
res=$(./icwmpd -c add Device.DeviceInfo.VendorConfigFil 2>&1)
if [[ $res != *"9005"* ]]; then
log "Error: Add Method with wrong path doesn't work correctly"
exit 1
fi
log "DELETE METHOD: Wrong Path"
res=$(./icwmpd -c del Device.DeviceInfo.VendorLogFil 2>&1)
res=$(./icwmpd -c del Device.DeviceInfo.VendorConfigFil 2>&1)
if [[ $res != *"9005"* ]]; then
log "Error: Delete Method with wrong path doesn't work correctly"
exit 1