char *ves_ip = getVesIpFromConfigJson();
int ves_port = getVesPortFromConfigJson();
+ char *ves_auth_method = getVesAuthMethodFromConfigJson();
+ if (strcmp(ves_auth_method, "basic-auth") == 0)
+ {
+ char *ves_username = getVesUsernameFromConfigJson();
+ char *ves_password = getVesPasswordFromConfigJson();
+
+ char credentials[200];
+ sprintf(credentials, "%s:%s", ves_username, ves_password);
+
+ free(ves_username);
+ free(ves_password);
+
+ curl_easy_setopt(curl, CURLOPT_USERPWD, credentials);
+ }
+ free(ves_auth_method);
+
+ char url[300];
+ char ves_protocol[15] = "https";
+ if( !strcmp(getenv("VES_HTTPS"), "false") )
+ {
+ strcpy(ves_protocol ,"http" );
+ printf("VES connection protocol %s enabled\n", ves_protocol);
+ }
- char url[100];
- sprintf(url, "http://%s:%d/eventListener/v7", ves_ip, ves_port);
+ sprintf(url, "%s://%s:%d/eventListener/v7", ves_protocol, ves_ip, ves_port);
curl_easy_setopt(curl, CURLOPT_URL, url);
+ curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
+ curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
+ curl_easy_setopt(curl, CURLOPT_PROXY_SSL_VERIFYPEER, 0L);
+ curl_easy_setopt(curl, CURLOPT_PROXY_SSL_VERIFYHOST, 0L);
+
free(ves_ip);
return;
char * buffer = 0;
long length;
char config_file[200];
- sprintf(config_file, "%s/configuration.json", getenv("SCRIPTS_DIR"));
+
+ //sprintf(config_file, "%s/configuration.json", getenv("SCRIPTS_DIR"));
+
+ // --> recommended fix, Karl Koch, Deutsche Telekom AG, 22. 5. 2020.
+ // Path to config_file contains NULL when env variable is unset.
+ char *scripts_dir = getenv("SCRIPTS_DIR");
+ char *scripts_dir_default = "/opt/dev/ntsimulator/scripts";
+
+ if(NULL != scripts_dir)
+ {
+ sprintf(config_file, "%s/configuration.json", scripts_dir);
+ }
+ else
+ {
+ sprintf(config_file, "%s/configuration.json", scripts_dir_default);
+ printf("warning: opening config file in default path: <%s>\n",
+ config_file);
+ }
+ // end of fix <--
+
FILE * f = fopen (config_file, "rb");
if (f)
void writeConfigFile(char *config)
{
char config_file[200];
- sprintf(config_file, "%s/configuration.json", getenv("SCRIPTS_DIR"));
+
+ //sprintf(config_file, "%s/configuration.json", getenv("SCRIPTS_DIR"));
+
+ // --> recommended fix, Karl Koch, Deutsche Telekom AG, 22. 5. 2020.
+ // Path to config_file contains NULL when env variable is unset.
+ char *scripts_dir = getenv("SCRIPTS_DIR");
+ char *scripts_dir_default = "/opt/dev/ntsimulator/scripts";
+
+ if(NULL != scripts_dir)
+ {
+ sprintf(config_file, "%s/configuration.json", scripts_dir);
+ }
+ else
+ {
+ sprintf(config_file, "%s/configuration.json", scripts_dir_default);
+ printf("warning: opening config file in default path: <%s>\n",
+ config_file);
+ }
+ // end of fix <--
+
FILE * f = fopen (config_file, "w");
if (f)
*/
char* getVesIpFromConfigJson(void)
{
- char *stringConfig = readConfigFileInString();
+ char *stringConfig = readConfigFileInString();
- if (stringConfig == NULL)
- {
- printf("Could not read JSON configuration file in string.");
- return 0;
- }
+ if (stringConfig == NULL)
+ {
+ printf("Could not read JSON configuration file in string.");
+ return 0;
+ }
- cJSON *jsonConfig = cJSON_Parse(stringConfig);
- if (jsonConfig == NULL)
- {
- free(stringConfig);
- const char *error_ptr = cJSON_GetErrorPtr();
- if (error_ptr != NULL)
- {
- fprintf(stderr, "Could not parse JSON configuration! Error before: %s\n", error_ptr);
- }
- return NULL;
- }
- //we don't need the string anymore
- free(stringConfig);
- stringConfig = NULL;
+ cJSON *jsonConfig = cJSON_Parse(stringConfig);
+ if (jsonConfig == NULL)
+ {
+ free(stringConfig);
+ const char *error_ptr = cJSON_GetErrorPtr();
+ if (error_ptr != NULL)
+ {
+ fprintf(stderr, "Could not parse JSON configuration! Error before: %s\n", error_ptr);
+ }
+ return NULL;
+ }
+ //we don't need the string anymore
+ free(stringConfig);
+ stringConfig = NULL;
- cJSON *vesDetails = cJSON_GetObjectItemCaseSensitive(jsonConfig, "ves-endpoint-details");
- if (!cJSON_IsObject(vesDetails))
- {
- printf("Configuration JSON is not as expected: ves-endpoint-details is not an object");
- cJSON_Delete(jsonConfig);
- return NULL;
- }
+ cJSON *vesDetails = cJSON_GetObjectItemCaseSensitive(jsonConfig, "ves-endpoint-details");
+ if (!cJSON_IsObject(vesDetails))
+ {
+ printf("Configuration JSON is not as expected: ves-endpoint-details is not an object");
+ cJSON_Delete(jsonConfig);
+ return NULL;
+ }
- cJSON *vesIp = cJSON_GetObjectItemCaseSensitive(vesDetails, "ves-endpoint-ip");
- if (!cJSON_IsString(vesIp))
- {
- printf("Configuration JSON is not as expected: ves-endpoint-ip is not an object");
- cJSON_Delete(jsonConfig);
- return NULL;
- }
+ cJSON *vesIp = cJSON_GetObjectItemCaseSensitive(vesDetails, "ves-endpoint-ip");
+ if (!cJSON_IsString(vesIp))
+ {
+ printf("Configuration JSON is not as expected: ves-endpoint-ip is not an object");
+ cJSON_Delete(jsonConfig);
+ return NULL;
+ }
- char *ves_ip = strdup(cJSON_GetStringValue(vesIp));
+ char *ves_ip = strdup(cJSON_GetStringValue(vesIp));
- cJSON_Delete(jsonConfig);
+ cJSON_Delete(jsonConfig);
- return ves_ip;
+ return ves_ip;
+}
+
+/*
+ * Dynamically allocated memory;
+ * Caller needs to free the memory after it uses the value.
+ *
+*/
+char* getVesUsernameFromConfigJson(void)
+{
+ char *stringConfig = readConfigFileInString();
+
+ if (stringConfig == NULL)
+ {
+ printf("Could not read JSON configuration file in string.");
+ return 0;
+ }
+
+ cJSON *jsonConfig = cJSON_Parse(stringConfig);
+ if (jsonConfig == NULL)
+ {
+ free(stringConfig);
+ const char *error_ptr = cJSON_GetErrorPtr();
+ if (error_ptr != NULL)
+ {
+ fprintf(stderr, "Could not parse JSON configuration! Error before: %s\n", error_ptr);
+ }
+ return NULL;
+ }
+ //we don't need the string anymore
+ free(stringConfig);
+ stringConfig = NULL;
+
+ cJSON *vesDetails = cJSON_GetObjectItemCaseSensitive(jsonConfig, "ves-endpoint-details");
+ if (!cJSON_IsObject(vesDetails))
+ {
+ printf("Configuration JSON is not as expected: ves-endpoint-details is not an object");
+ cJSON_Delete(jsonConfig);
+ return NULL;
+ }
+
+ cJSON *vesUsername = cJSON_GetObjectItemCaseSensitive(vesDetails, "ves-endpoint-username");
+ if (!cJSON_IsString(vesUsername))
+ {
+ printf("Configuration JSON is not as expected: ves-endpoint-username is not an object");
+ cJSON_Delete(jsonConfig);
+ return NULL;
+ }
+
+ char *ves_username = strdup(cJSON_GetStringValue(vesUsername));
+
+ cJSON_Delete(jsonConfig);
+
+ return ves_username;
+}
+
+/*
+ * Dynamically allocated memory;
+ * Caller needs to free the memory after it uses the value.
+ *
+*/
+char* getVesPasswordFromConfigJson(void)
+{
+ char *stringConfig = readConfigFileInString();
+
+ if (stringConfig == NULL)
+ {
+ printf("Could not read JSON configuration file in string.");
+ return 0;
+ }
+
+ cJSON *jsonConfig = cJSON_Parse(stringConfig);
+ if (jsonConfig == NULL)
+ {
+ free(stringConfig);
+ const char *error_ptr = cJSON_GetErrorPtr();
+ if (error_ptr != NULL)
+ {
+ fprintf(stderr, "Could not parse JSON configuration! Error before: %s\n", error_ptr);
+ }
+ return NULL;
+ }
+ //we don't need the string anymore
+ free(stringConfig);
+ stringConfig = NULL;
+
+ cJSON *vesDetails = cJSON_GetObjectItemCaseSensitive(jsonConfig, "ves-endpoint-details");
+ if (!cJSON_IsObject(vesDetails))
+ {
+ printf("Configuration JSON is not as expected: ves-endpoint-details is not an object");
+ cJSON_Delete(jsonConfig);
+ return NULL;
+ }
+
+ cJSON *vesPassword = cJSON_GetObjectItemCaseSensitive(vesDetails, "ves-endpoint-password");
+ if (!cJSON_IsString(vesPassword))
+ {
+ printf("Configuration JSON is not as expected: ves-endpoint-password is not an object");
+ cJSON_Delete(jsonConfig);
+ return NULL;
+ }
+
+ char *ves_password = strdup(cJSON_GetStringValue(vesPassword));
+
+ cJSON_Delete(jsonConfig);
+
+ return ves_password;
}
int getVesPortFromConfigJson(void)
return NULL;
}
- if (cJSON_AddStringToObject(pnfRegistrationFields, "oamV4IpAddress", getenv("NTS_IP")) == NULL)
+ if (cJSON_AddStringToObject(pnfRegistrationFields, "oamV4IpAddress", getenv("EXTERNAL_NTS_IP")) == NULL)
{
printf("Could not create JSON object: oamV4IpAddress\n");
cJSON_Delete(pnfRegistrationFields);
}
char serial_number[100];
- sprintf(serial_number, "%s-%s-%d-Simulated Device Melacon", getenv("HOSTNAME"), getenv("NTS_IP"), port);
+ sprintf(serial_number, "%s-%s-%d-Simulated Device Melacon", getenv("HOSTNAME"), getenv("EXTERNAL_NTS_IP"), port);
if (cJSON_AddStringToObject(pnfRegistrationFields, "serialNumber", serial_number) == NULL)
{
return SR_ERR_OPERATION_FAILED;
}
+ cJSON *controllerDetails = cJSON_CreateObject();
+ if (controllerDetails == NULL)
+ {
+ printf("Could not create JSON object: controllerDetails\n");
+ cJSON_Delete(configObject);
+ return SR_ERR_OPERATION_FAILED;
+ }
+ cJSON_AddItemToObject(configObject, "controller-details", controllerDetails);
+
+ if (cJSON_AddStringToObject(controllerDetails, "controller-ip", "172.17.0.1") == NULL)
+ {
+ printf("Could not create JSON object: controller-ip\n");
+ cJSON_Delete(configObject);
+ return SR_ERR_OPERATION_FAILED;
+ }
+
+ if (cJSON_AddNumberToObject(controllerDetails, "controller-port", 8181) == NULL)
+ {
+ printf("Could not create JSON object: controller-port\n");
+ cJSON_Delete(configObject);
+ return SR_ERR_OPERATION_FAILED;
+ }
+
+ if (cJSON_AddNumberToObject(controllerDetails, "netconf-call-home-port", 6666) == NULL)
+ {
+ printf("Could not create JSON object: netconf-call-home-port\n");
+ cJSON_Delete(configObject);
+ return SR_ERR_OPERATION_FAILED;
+ }
+
+ if (cJSON_AddStringToObject(controllerDetails, "controller-username", "admin") == NULL)
+ {
+ printf("Could not create JSON object: controller-username\n");
+ cJSON_Delete(configObject);
+ return SR_ERR_OPERATION_FAILED;
+ }
+
+ if (cJSON_AddStringToObject(controllerDetails, "controller-password", "admin") == NULL)
+ {
+ printf("Could not create JSON object: controller-password\n");
+ cJSON_Delete(configObject);
+ return SR_ERR_OPERATION_FAILED;
+ }
+
if (cJSON_AddNumberToObject(configObject, "ssh-connections", 1) == NULL)
{
printf("Could not create JSON object: ssh-connections\n");
return SR_ERR_OPERATION_FAILED;
}
+ if (cJSON_AddFalseToObject(configObject, "netconf-call-home") == NULL)
+ {
+ printf("Could not create JSON object: netconf-call-home\n");
+ cJSON_Delete(configObject);
+ return SR_ERR_OPERATION_FAILED;
+ }
+
char *config_string = NULL;
config_string = cJSON_PrintUnformatted(configObject);