Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extended schedules #729

Merged
merged 10 commits into from
Jun 15, 2018
1 change: 1 addition & 0 deletions gsad/src/gsad.c
Original file line number Diff line number Diff line change
Expand Up @@ -745,6 +745,7 @@ init_validator ()
openvas_validator_add (validator, "z_fields:value", "^[\\[\\]_[:alnum:]]{1,80}$");
openvas_validator_add (validator, "calendar_unit", "^(second|minute|hour|day|week|month|year|decade)$");
openvas_validator_add (validator, "chart_title", "(?s)^.*$");
openvas_validator_add (validator, "icalendar", "(?s)^BEGIN:VCALENDAR.+$");

/* Beware, the rule must be defined before the alias. */

Expand Down
117 changes: 15 additions & 102 deletions gsad/src/gsad_gmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -16276,40 +16276,23 @@ get_schedules_gmp (gvm_connection_t *connection, credentials_t * credentials, pa
* @return Enveloped XML object.
*/
char *
create_schedule_gmp (gvm_connection_t *connection, credentials_t * credentials, params_t *params,
cmd_response_data_t* response_data)
create_schedule_gmp (gvm_connection_t *connection, credentials_t *credentials,
params_t *params, cmd_response_data_t *response_data)
{
char *ret;
gchar *response;
const char *name, *comment, *hour, *minute, *day_of_month, *month, *year;
const char *period, *period_unit, *duration, *duration_unit, *timezone;
const char *name, *comment, *timezone, *icalendar;
entity_t entity;

name = params_value (params, "name");
comment = params_value (params, "comment");
hour = params_value (params, "hour");
minute = params_value (params, "minute");
day_of_month = params_value (params, "day_of_month");
duration = params_value (params, "duration");
duration_unit = params_value (params, "duration_unit");
month = params_value (params, "month");
period = params_value (params, "period");
period_unit = params_value (params, "period_unit");
year = params_value (params, "year");
timezone = params_value (params, "timezone");
icalendar = params_value (params, "icalendar");

CHECK_PARAM_INVALID (name, "Create Schedule");
CHECK_PARAM_INVALID (comment, "Create Schedule");
CHECK_PARAM_INVALID (hour, "Create Schedule");
CHECK_PARAM_INVALID (minute, "Create Schedule");
CHECK_PARAM_INVALID (day_of_month, "Create Schedule");
CHECK_PARAM_INVALID (duration, "Create Schedule");
CHECK_PARAM_INVALID (duration_unit, "Create Schedule");
CHECK_PARAM_INVALID (month, "Create Schedule");
CHECK_PARAM_INVALID (period, "Create Schedule");
CHECK_PARAM_INVALID (period_unit, "period_unit");
CHECK_PARAM_INVALID (year, "Create Schedule");
CHECK_PARAM_INVALID (timezone, "Create Schedule");
CHECK_PARAM_INVALID (icalendar, "Create Schedule");

response = NULL;
entity = NULL;
Expand All @@ -16320,39 +16303,13 @@ create_schedule_gmp (gvm_connection_t *connection, credentials_t * credentials,
"<create_schedule>"
"<name>%s</name>"
"<comment>%s</comment>"
"<first_time>"
"<hour>%s</hour>"
"<minute>%s</minute>"
"<day_of_month>%s</day_of_month>"
"<month>%s</month>"
"<year>%s</year>"
"</first_time>"
"<period>"
"<unit>%s</unit>"
"%s"
"</period>"
"<duration>"
"<unit>%s</unit>"
"%s"
"</duration>"
"<timezone>%s</timezone>"
"<icalendar>%s</icalendar>"
"</create_schedule>",
name,
comment,
hour,
minute,
day_of_month,
month,
year,
(strcmp (period_unit, "")
? period_unit
: "second"),
period,
(strcmp (duration_unit, "")
? duration_unit
: "second"),
duration,
timezone))
timezone,
icalendar))
{
case 0:
case -1:
Expand Down Expand Up @@ -22311,42 +22268,24 @@ export_schedules_gmp (gvm_connection_t *connection,
* @return Enveloped XML object.
*/
char *
save_schedule_gmp (gvm_connection_t *connection, credentials_t * credentials, params_t *params,
cmd_response_data_t* response_data)
save_schedule_gmp (gvm_connection_t *connection, credentials_t *credentials,
params_t *params, cmd_response_data_t *response_data)
{
gchar *response;
entity_t entity;
const char *schedule_id, *name, *comment;
const char *hour, *minute, *day_of_month, *month, *year, *timezone;
const char *period, *period_unit, *duration, *duration_unit;
const char *schedule_id, *name, *comment, *timezone, *icalendar;
char *ret;

schedule_id = params_value (params, "schedule_id");
name = params_value (params, "name");
comment = params_value (params, "comment");
hour = params_value (params, "hour");
minute = params_value (params, "minute");
day_of_month = params_value (params, "day_of_month");
duration = params_value (params, "duration");
duration_unit = params_value (params, "duration_unit");
month = params_value (params, "month");
period = params_value (params, "period");
period_unit = params_value (params, "period_unit");
year = params_value (params, "year");
icalendar = params_value (params, "icalendar");
timezone = params_value (params, "timezone");

CHECK_PARAM_INVALID (schedule_id, "Save Schedule");
CHECK_PARAM_INVALID (name, "Save Schedule");
CHECK_PARAM_INVALID (comment, "Save Schedule");
CHECK_PARAM_INVALID (hour, "Save Schedule");
CHECK_PARAM_INVALID (minute, "Save Schedule");
CHECK_PARAM_INVALID (day_of_month, "Save Schedule");
CHECK_PARAM_INVALID (duration, "Save Schedule");
CHECK_PARAM_INVALID (duration_unit, "Save Schedule");
CHECK_PARAM_INVALID (month, "Save Schedule");
CHECK_PARAM_INVALID (period, "Save Schedule");
CHECK_PARAM_INVALID (period_unit, "Save Schedule");
CHECK_PARAM_INVALID (year, "Save Schedule");
CHECK_PARAM_INVALID (icalendar, "Save Schedule");
CHECK_PARAM_INVALID (timezone, "Save Schedule");

response = NULL;
Expand All @@ -22358,40 +22297,14 @@ save_schedule_gmp (gvm_connection_t *connection, credentials_t * credentials, pa
"<modify_schedule schedule_id=\"%s\">"
"<name>%s</name>"
"<comment>%s</comment>"
"<first_time>"
"<hour>%s</hour>"
"<minute>%s</minute>"
"<day_of_month>%s</day_of_month>"
"<month>%s</month>"
"<year>%s</year>"
"</first_time>"
"<timezone>%s</timezone>"
"<period>"
"<unit>%s</unit>"
"%s"
"</period>"
"<duration>"
"<unit>%s</unit>"
"%s"
"</duration>"
"<icalendar>%s</icalendar>"
"</modify_schedule>",
schedule_id,
name ? name : "",
comment ? comment : "",
hour,
minute,
day_of_month,
month,
year,
timezone,
(strcmp (period_unit, "")
? period_unit
: "second"),
period,
(strcmp (duration_unit, "")
? duration_unit
: "second"),
duration))
icalendar))
{
case 0:
case -1:
Expand Down
1 change: 1 addition & 0 deletions ng/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ set (NG_JS_SRC_FILES
${NG_SRC_DIR}/src/gmp/models/credential.js
${NG_SRC_DIR}/src/gmp/models/cve.js
${NG_SRC_DIR}/src/gmp/models/dfncert.js
${NG_SRC_DIR}/src/gmp/models/event.js
${NG_SRC_DIR}/src/gmp/models/filter.js
${NG_SRC_DIR}/src/gmp/models/filter/convert.js
${NG_SRC_DIR}/src/gmp/models/filter/filterterm.js
Expand Down
45 changes: 5 additions & 40 deletions ng/src/gmp/commands/schedules.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,70 +39,35 @@ class ScheduleCommand extends EntityCommand {
const {
name,
comment = '',
hour,
minute,
icalendar,
timezone,
date,
period,
period_unit,
duration,
duration_unit,
} = args;
const day_of_month = date.date();
const month = date.month() + 1;
const year = date.year();
log.debug('Creating new schedule', args);
return this.action({
cmd: 'create_schedule',
name,
comment,
day_of_month,
month,
year,
hour,
minute,
icalendar,
timezone,
period,
period_unit,
duration,
duration_unit,
});
}

save(args) {
const {
comment = '',
icalendar,
id,
name,
comment = '',
hour,
minute,
timezone,
date,
period,
period_unit,
duration,
duration_unit,
} = args;

const day_of_month = date.date();
const month = date.month() + 1;
const year = date.year();

const data = {
cmd: 'save_schedule',
comment,
day_of_month,
duration,
duration_unit,
hour,
id,
minute,
month,
icalendar,
name,
period,
period_unit,
timezone,
year,
};
log.debug('Saving schedule', args, data);
return this.action(data);
Expand Down
Loading