function check_writable_relative($dir) { $uid = posix_getuid(); $gid = posix_getgid(); $user_info = posix_getpwuid($uid); $user = $user_info['name']; $group_info = posix_getgrgid($gid); $group = $group_info['name']; $fix_cmd = '. ' . _("To fix that, execute following commands as root") . ':<br><br>' . "cd " . getcwd() . "<br>" . "mkdir -p {$dir}<br>" . "chown {$user}:{$group} {$dir}<br>" . "chmod 0700 {$dir}"; if (!is_dir($dir)) { $config_nt = array('content' => _("Required directory " . getcwd() . "{$dir} does not exist") . $fix_cmd, 'options' => array('type' => 'nf_warning', 'cancel_button' => FALSE), 'style' => 'width: 80%; margin: 20px auto;'); $nt = new Notification('nt_1', $config_nt); $nt->show(); exit; } if (!($stat = stat($dir))) { $config_nt = array('content' => _("Could not stat configs dir") . $fix_cmd, 'options' => array('type' => 'nf_warning', 'cancel_button' => FALSE), 'style' => 'width: 80%; margin: 20px auto;'); $nt = new Notification('nt_1', $config_nt); $nt->show(); exit; } // 2 -> file perms (must be 0700) // 4 -> uid (must be the apache uid) // 5 -> gid (must be the apache gid) if ($stat[2] != 16832 || $stat[4] !== $uid || $stat[5] !== $gid) { $config_nt = array('content' => _("Invalid perms for configs dir") . $fix_cmd, 'options' => array('type' => 'nf_warning', 'cancel_button' => FALSE), 'style' => 'width: 80%; margin: 20px auto;'); $nt = new Notification('nt_1', $config_nt); $nt->show(); exit; } }
function display_errors($info_error) { $errors = implode("</div><div style='padding-top: 3px;'>", $info_error); $error_msg = "<div>" . _("The following errors occurred:") . "</div><div style='padding-left: 15px;'><div>{$errors}</div></div>"; $config_nt = array('content' => $error_msg, 'options' => array('type' => 'nf_error', 'cancel_button' => FALSE), 'style' => 'width: 90%; margin: 20px auto; padding: 10px 0px; text-align: left; font-style: italic'); $nt = new Notification('nt_1', $config_nt); return $nt->show(FALSE); }
function show_notification($msg, $type = 'nf_error') { echo "<div class='container' style='width:100%;height:30px;margin:10px auto;text-align:center'>"; $config_nt = array('content' => $msg, 'options' => array('type' => $type, 'cancel_button' => FALSE), 'style' => ' margin:0 auto;text-align:center;'); $nt = new Notification('nt_panel', $config_nt); $nt->show(); echo "</div>"; die; }
function notify_and_die($msg, $db) { $config_nt = array('content' => $msg, 'options' => array('type' => 'nf_error', 'cancel_button' => ''), 'style' => ' margin:25px auto 0 auto;text-align:center;padding:3px 30px;'); $nt = new Notification('nt_panel', $config_nt); $nt->show(); if (is_object($db)) { $db->close(); } die; }
function check_deploy_perms() { if (!Session::am_i_admin()) { $config_nt = array('content' => _("You do not have permission to see this section"), 'options' => array('type' => 'nf_error', 'cancel_button' => false), 'style' => 'width: 60%; margin: 30px auto; text-align:center;'); $nt = new Notification('nt_1', $config_nt); $nt->show(); die; } return true; }
public function prepare() { $notification = new Notification($this->curpage, $this->db, $this->config); $notification->prepare(); $mainToggle = ''; $tasksToggle = ''; $usersToggle = ''; $serversToggle = ''; $storeToggle = ''; $settingsToggle = ''; $route = getroute(); if ($route == '') { $mainToggle = 'active'; } if ($route == 'servers' || strpos('##' . $route, 'servers/')) { $serversToggle = 'active'; } elseif ($route == 'tasks' || strpos('##' . $route, 'tasks/')) { $tasksToggle = 'active'; } if ($route == 'users' || strpos('##' . $route, 'users/')) { $usersToggle = 'active'; } if ($route == 'store' || strpos('##' . $route, 'store/')) { $storeToggle = 'active'; } if ($route == 'settings' || strpos('##' . $route, 'settings/')) { $settingsToggle = 'active'; } $this->data['mainToggle'] = $mainToggle; $this->data['tasksToggle'] = $tasksToggle; $this->data['usersToggle'] = $usersToggle; $this->data['serversToggle'] = $serversToggle; $this->data['storeToggle'] = $storeToggle; $this->data['settingsToggle'] = $settingsToggle; $this->data['notification'] = $notification->show(); }
echo $back_url; ?> ";return false;'/> </div> <div id='av_info'> <?php if ($update == 1) { $config_nt = array('content' => _('Server saved successfully'), 'options' => array('type' => 'nf_success', 'cancel_button' => true), 'style' => 'width: 100%; margin: auto; text-align:center;'); $nt = new Notification('nt_1', $config_nt); $nt->show(); } if (!$can_i_modify_elem) { $config_nt = array('content' => _('The properties of this asset can only be modified at the USM:') . " <strong>" . $external_ctx . "</strong>", 'options' => array('type' => 'nf_warning', 'cancel_button' => TRUE), 'style' => 'width: 100%; margin: auto; text-align:center;'); $nt = new Notification('nt_1', $config_nt); $nt->show(); } ?> </div> <div id='server_container'> <div class='legend'> <?php echo _('Values marked with (*) are mandatory'); ?> </div> <form method="post" name='form_server' id='form_server' action="<?php echo $action; ?> ">
function show_notif($msg, $type) { $config_nt = array('content' => $msg, 'options' => array('type' => $type, 'cancel_button' => true), 'style' => 'position:absolute;top:15px;left:0;right:0;margin:0 auto;width:400px;text-align:center;padding:1px 20px;z-index:999'); $nt = new Notification('nt_notif', $config_nt); $nt->show(); }
</div> </td> </tr> </table> <?php if ($can_i_modify_elem) { ?> <table id='table_so'> <?php if (!empty($config_nt['content'])) { $config_nt = array('content' => $config_nt['content'], 'options' => array('type' => $config_nt['options']['type'], 'cancel_button' => FALSE), 'style' => 'width: 100%; margin: auto; text-align:center;'); $nt = new Notification('nt_1', $config_nt); ?> <tr><td class='noborder center' style="padding:0px 0px 9px 0px;"><?php echo $nt->show(); ?> </td></tr> <?php } ?> <!-- Inventory Tasks --> <tr> <td class="sec_title"><?php echo _("Inventory Task"); ?> </td> </tr>
<span class="s_label" id="sl_sboxs[]"><?php echo _('Sensors'); ?> </span> </td> </tr> <!-- Sensor inputs --> <?php $s_chks = array(); $no_sensors = ''; if ($s_total <= 0) { $config_nt = array('content' => _('Warning! No sensors found'), 'options' => array('type' => 'nf_warning', 'cancel_button' => FALSE), 'style' => 'width: 80%; margin: 25px auto; text-align: left; font-size: 11px;'); $nt = new Notification('nt_1', $config_nt); $no_sensors = $nt->show(FALSE); } else { $i = 1; foreach ($all_sensors as $s_id => $s_data) { $s_name = $s_data['name']; $s_ip = $s_data['ip']; $all_ctxs = $s_data['ctx']; $s_ctxs = ''; $s_status = 'disabled'; //Search enabled sensors by CTXs foreach ($all_ctxs as $e_id => $e_name) { if ($e_id == $ctx && !empty($ctx)) { $s_status = 'enabled'; } $s_ctxs .= ' ' . $e_id; }
function display_errors($info_error) { $errors = implode("</div><div style='padding-top: 3px;'>", $info_error); $error_msg = "<div style='padding-bottom: 3px;'>" . _("We found the following errors:") . "</div>\n <div style='margin-left: 15px;'><div>{$errors}</div></div>"; $style = empty($style) ? 'margin: 20px auto; width: 60%; text-align:left' : $style; $config_nt = array('content' => $error_msg, 'options' => array('type' => 'nf_error', 'cancel_button' => true), 'style' => $style); $nt = new Notification('nt_1', $config_nt); return $nt->show(false); }
function show_incident_error($msg, $style = '', $type = 'nf_error') { $config_nt = array('content' => $msg, 'options' => array('type' => $type, 'cancel_button' => FALSE), 'style' => $style); $nt = new Notification('nt_1', $config_nt); $nt->show(); }
function submit_scan($vuln_op, $sched_id, $sname, $notify_email, $schedule_type, $ROYEAR, $ROMONTH, $ROday, $time_hour, $time_min, $dayofweek, $dayofmonth, $timeout, $SVRid, $sid, $tarSel, $ip_list, $ip_exceptions_list, $ip_start, $ip_end, $named_list, $cidr, $subnet, $system, $cred_type, $credid, $acc, $domain, $accpass, $acctype, $passtype, $passstore, $wpolicies, $wfpolicies, $upolicies, $custadd_type, $cust_plugins, $is_enabled, $hosts_alive, $scan_locally, $nthweekday, $semail, $not_resolve, $time_interval, $biyear, $bimonth, $biday, $ssh_credential = "", $smb_credential = "") { global $wdaysMap, $daysMap, $allowscan, $uroles, $username, $schedOptions, $adminmail, $mailfrom, $dbk, $dbconn; // credentials $credentials = $ssh_credential . "|" . $smb_credential; $btime_hour = $time_hour; // save local time $btime_min = $time_min; $bbiyear = $biyear; $bbimonth = $bimonth; $bbiday = $biday; $tz = Util::get_timezone(); if ($schedule_type == "O") { // date and time for run once if (empty($ROYEAR)) { $ROYEAR = gmdate("Y"); } if (empty($ROMONTH)) { $ROMONTH = gmdate("m"); } if (empty($ROday)) { $ROday = gmdate("d"); } list($_y, $_m, $_d, $_h, $_u, $_s, $_time) = Util::get_utc_from_date($dbconn, "{$ROYEAR}-{$ROMONTH}-{$ROday} {$time_hour}:{$time_min}:00", $tz); $ROYEAR = $_y; $ROMONTH = $_m; $ROday = $_d; $time_hour = $_h; $time_min = $_u; } else { if ($schedule_type == "D" || $schedule_type == "W" || $schedule_type == "M" || $schedule_type == "NW") { // date and time for Daily, Day of Week, Day of month, Nth weekday of month list($b_y, $b_m, $b_d, $b_h, $b_u, $b_s, $b_time) = Util::get_utc_from_date($dbconn, "{$biyear}-{$bimonth}-{$biday} {$time_hour}:{$time_min}:00", $tz); $biyear = $b_y; $bimonth = $b_m; $biday = $b_d; $time_hour = $b_h; $time_min = $b_u; } } if ($not_resolve == "1") { $resolve_names = 0; } else { $resolve_names = 1; } $notify_email = str_replace(";", ",", $notify_email); $requested_run = ""; $jobType = "M"; $recurring = False; $targets = array(); $time_value = ""; $profile_desc = getProfileName($sid); $target_list = ""; $need_authorized = ""; $request = ""; $plugs_list = "NULL"; $fk_name = "NULL"; $target_list = "NULL"; $tmp_target_list = ""; $jobs_names = array(); $sjobs_names = array(); $I3crID = ""; if ($hosts_alive == "1") { // option: Only scan hosts that are alive $I3crID = "1"; } else { $I3crID = "0"; } // if ( $custadd_type == "" ) { $custadd_type = "N"; } // if ( $custadd_type != "N" && $cust_plugins != "" ) { // $plugs_list=""; // $vals=preg_split( "/\s+|\r\n|,|;/", $cust_plugins ); // foreach($vals as $v) { // $v=trim($v); // if ( strlen($v)>0 ) { // $plugs_list .= $v . "\n"; // } // } // $plugs_list = "'".$plugs_list."'"; // } if ($schedule_type != "N") { // current datetime in UTC $arrTime = explode(":", gmdate('Y:m:d:w:H:i:s')); $year = $arrTime[0]; $mon = $arrTime[1]; $mday = $arrTime[2]; $wday = $arrTime[3]; $hour = $arrTime[4]; $min = $arrTime[5]; $sec = $arrTime[6]; $timenow = $hour . $min . $sec; $run_wday = $wdaysMap[$dayofweek]; $run_time = sprintf("%02d%02d%02d", $time_hour, $time_min, "00"); $run_mday = $dayofmonth; $time_value = "{$time_hour}:{$time_min}:00"; $ndays = array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"); $begin_in_seconds = mktime($bihour, $bimin, 0, $bimonth, $biday, $biyear); // selected datetime by user in UTC $current_in_seconds = mktime($hour, $min, 0, $mon, $mday, $year); // current datetime in UTC if (strlen($bimonth) == 1) { $bimonth = "0" . $bimonth; } if (strlen($biday) == 1) { $biday = "0" . $biday; } } switch ($schedule_type) { case "N": $requested_run = gmdate("YmdHis"); $sched_message = "No reccurring Jobs Necessary"; break; case "O": $requested_run = sprintf("%04d%02d%02d%06d", $ROYEAR, $ROMONTH, $ROday, $run_time); //error_log("O-> $requested_run\n" ,3,"/tmp/sched.log"); $sched_message = "No reccurring Jobs Necessary"; $recurring = True; $reccur_type = "Run Once"; break; case "D": if ($begin_in_seconds > $current_in_seconds) { $next_day = $biyear . $bimonth . $biday; // selected date by user } else { if ($run_time > $timenow) { $next_day = $year . $mon . $mday; } else { $next_day = gmdate("Ymd", strtotime("+1 day GMT", gmdate("U"))); } // next day } $requested_run = sprintf("%08d%06d", $next_day, $run_time); //error_log("D-> $requested_run\n" ,3,"/tmp/sched.log"); $recurring = True; $sched_message = "Schedule Reccurring"; $reccur_type = "Daily"; break; case "W": if ($begin_in_seconds > $current_in_seconds) { // if it is a future date $wday = date("w", mktime(0, 0, 0, $bimonth, $biday, $biyear)); // make week day for begin day if ($run_wday == $wday) { $next_day = $biyear . $bimonth . $biday; // selected date by user } else { $next_day = gmdate("Ymd", strtotime("next " . $ndays[$run_wday] . " GMT", mktime(0, 0, 0, $bimonth, $biday, $biyear))); } } else { if ($run_wday == $wday && $run_time > $timenow || $run_wday > $wday) { $next_day = $year . $mon . $mday; } else { $next_day = gmdate("Ymd", strtotime("next " . $ndays[$run_wday] . " GMT", gmdate("U"))); } // next week } preg_match("/(\\d{4})(\\d{2})(\\d{2})/", $next_day, $found); list($b_y, $b_m, $b_d, $b_h, $b_u, $b_s, $b_time) = Util::get_utc_from_date($dbconn, $found[1] . "-" . $found[2] . "-" . $found[3] . " {$btime_hour}:{$btime_min}:00", $tz); $requested_run = sprintf("%04d%02d%02d%02d%02d%02d", $b_y, $b_m, $b_d, $b_h, $b_u, "00"); //error_log("W-> $requested_run\n" ,3,"/tmp/sched.log"); $recurring = True; $sched_message = "Schedule Reccurring"; $reccur_type = "Weekly"; break; case "M": if ($begin_in_seconds > $current_in_seconds) { // if it is a future date if ($run_mday >= $biday) { $next_day = $biyear . $bimonth . ($run_mday < 10 ? "0" : "") . $run_mday; // this month } else { $next_day = sprintf("%06d%02d", gmdate("Ym", strtotime("next month GMT", mktime(0, 0, 0, $bimonth, $biday, $biyear))), $run_mday); } } else { if ($run_mday > $mday || $run_mday == $mday && $run_time > $timenow) { $next_day = $year . $mon . ($run_mday < 10 ? "0" : "") . $run_mday; // this month } else { $next_day = sprintf("%06d%02d", gmdate("Ym", strtotime("next month GMT", gmdate("U"))), $run_mday); } } preg_match("/(\\d{4})(\\d{2})(\\d{2})/", $next_day, $found); list($b_y, $b_m, $b_d, $b_h, $b_u, $b_s, $b_time) = Util::get_utc_from_date($dbconn, $found[1] . "-" . $found[2] . "-" . $found[3] . " {$btime_hour}:{$btime_min}:00", $tz); $requested_run = sprintf("%04d%02d%02d%02d%02d%02d", $b_y, $b_m, $b_d, $b_h, $b_u, "00"); //error_log("M-> $requested_run $begin_in_seconds $current_in_seconds\n" ,3,"/tmp/sched.log"); $recurring = True; $sched_message = "Schedule Reccurring"; $reccur_type = "Montly"; break; case "NW": if ($begin_in_seconds > $current_in_seconds) { // if it is a future date $array_time = array('month' => $bbimonth, 'day' => $bbiday, 'year' => $bbiyear); $requested_run = weekday_month(strtolower($daysMap[$dayofweek]), $nthweekday, $btime_hour, $btime_min, $array_time); } else { $requested_run = weekday_month(strtolower($daysMap[$dayofweek]), $nthweekday, $btime_hour, $btime_min); } preg_match("/(\\d{4})(\\d{2})(\\d{2})(\\d{2})(\\d{2})(\\d{2})/", $requested_run, $found); list($b_y, $b_m, $b_d, $b_h, $b_u, $b_s, $b_time) = Util::get_utc_from_date($dbconn, $found[1] . "-" . $found[2] . "-" . $found[3] . " " . $found[4] . ":" . $found[5] . ":00", $tz); $requested_run = sprintf("%04d%02d%02d%02d%02d%02d", $b_y, $b_m, $b_d, $b_h, $b_u, "00"); //error_log("NW-> $requested_run\n" ,3,"/tmp/sched.log"); $dayofmonth = $nthweekday; $recurring = True; $sched_message = "Schedule Reccurring"; $reccur_type = "Nth weekday of the month"; break; default: break; } $insert_time = gmdate("YmdHis"); if (!empty($_SESSION["_vuln_targets"]) && count($_SESSION["_vuln_targets"]) > 0) { $arr_ctx = array(); $sgr = array(); foreach ($_SESSION["_vuln_targets"] as $target_selected => $server_id) { $sgr[$server_id][] = $target_selected; if (preg_match("/^\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\/\\d{1,2}\$/i", $target_selected)) { $related_ctxs = array_values(Asset_net::get_id_by_ips($dbconn, $target_selected)); if (is_array($related_ctxs) && count($related_ctxs) > 0) { $arr_ctx[$target_selected] = key(array_shift($related_ctxs)); } } else { if (preg_match("/^\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\$/i", $target_selected)) { $related_ctxs = array_values(Asset_host::get_id_by_ips($dbconn, $target_selected)); if (is_array($related_ctxs) && count($related_ctxs) > 0) { $arr_ctx[$target_selected] = key(array_shift($related_ctxs)); // to assign a ctx for a IP } } else { if (valid_hostname($target_selected) || valid_fqdns($target_selected)) { $filters = array('where' => "hostname like '{$target_selected}' OR fqdns like '{$target_selected}'"); $_hosts_data = Asset_host::get_basic_list($dbconn, $filters); $host_list = $_hosts_data[1]; if (count($host_list) > 0) { $first_host = array_shift($host_list); $hips = explode(",", $first_host['ips']); foreach ($hips as $hip) { $hip = trim($hip); $arr_ctx[$hip] = $first_host['ctx']; } } } } } } ossim_clean_error(); unset($_SESSION["_vuln_targets"]); // clean scan targets $query = array(); $IP_ctx = array(); foreach ($arr_ctx as $aip => $actx) { $IP_ctx[] = $actx . "#" . $aip; } if ($vuln_op == "editrecurring" && $sched_id > 0) { $query[] = "DELETE FROM vuln_job_schedule WHERE id='{$sched_id}'"; $i = 1; foreach ($sgr as $notify_sensor => $targets) { $target_list = implode("\n", $targets); $target_list .= "\n" . implode("\n", $ip_exceptions_list); $query[] = "INSERT INTO vuln_job_schedule ( name, username, fk_name, job_TYPE, schedule_type, day_of_week, day_of_month, \n time, email, meth_TARGET, meth_CRED, meth_VSET, meth_CUSTOM, meth_CPLUGINS, meth_Wfile, \n meth_Ucheck, meth_TIMEOUT, next_CHECK, createdate, enabled, resolve_names, time_interval, IP_ctx, credentials) VALUES ( '{$sname}', '{$username}', '" . Session::get_session_user() . "', '{$jobType}',\n '{$schedule_type}', '{$dayofweek}', '{$dayofmonth}', '{$time_value}', '{$notify_sensor}', '{$target_list}',\n {$I3crID}, '{$sid}', '{$custadd_type}', {$plugs_list}, {$semail}, '{$scan_locally}',\n '{$timeout}', '{$requested_run}', '{$insert_time}', '1', '{$resolve_names}' ,'{$time_interval}', '" . implode("\n", $IP_ctx) . "', '{$credentials}') "; $sjobs_names[] = $sname . $i; $i++; } } elseif ($recurring) { $i = 1; foreach ($sgr as $notify_sensor => $targets) { $target_list = implode("\n", $targets); $target_list .= "\n" . implode("\n", $ip_exceptions_list); $query[] = "INSERT INTO vuln_job_schedule ( name, username, fk_name, job_TYPE, schedule_type, day_of_week, day_of_month, \n time, email, meth_TARGET, meth_CRED, meth_VSET, meth_CUSTOM, meth_CPLUGINS, meth_Wfile, \n meth_Ucheck, meth_TIMEOUT, scan_ASSIGNED, next_CHECK, createdate, enabled, resolve_names, time_interval, IP_ctx, credentials) VALUES ( '{$sname}', '{$username}', '" . Session::get_session_user() . "', '{$jobType}',\n '{$schedule_type}', '{$dayofweek}', '{$dayofmonth}', '{$time_value}', '{$notify_sensor}', '{$target_list}',\n {$I3crID}, '{$sid}', '{$custadd_type}', {$plugs_list}, {$semail}, '{$scan_locally}',\n '{$timeout}', '{$SVRid}', '{$requested_run}', '{$insert_time}', '1', '{$resolve_names}' , '{$time_interval}', '" . implode("\n", $IP_ctx) . "', '{$credentials}') "; $sjobs_names[] = $sname . $i; $i++; } } else { $i = 1; foreach ($sgr as $notify_sensor => $targets) { $target_list = implode("\n", $targets); $target_list .= "\n" . implode("\n", $ip_exceptions_list); $query[] = "INSERT INTO vuln_jobs ( name, username, fk_name, job_TYPE, meth_SCHED, meth_TARGET, meth_CRED,\n meth_VSET, meth_CUSTOM, meth_CPLUGINS, meth_Wfile, meth_TIMEOUT, scan_ASSIGNED,\n scan_SUBMIT, scan_next, scan_PRIORITY, status, notify, authorized, author_uname, resolve_names, credentials ) VALUES ( '{$sname}',\n '{$username}', '" . Session::get_session_user() . "', '{$jobType}', '{$schedule_type}', '{$target_list}', {$I3crID}, '{$sid}', '{$custadd_type}', {$plugs_list},\n {$semail}, '{$timeout}', '{$SVRid}', '{$insert_time}', '{$requested_run}', '3',\n 'S', '{$notify_sensor}', '{$scan_locally}', '" . implode("\n", $IP_ctx) . "', '{$resolve_names}' , '{$credentials}') "; // echo "$query1"; // die(); $jobs_names[] = $sname . $i; $i++; } } $query_insert_time = gen_strtotime($insert_time, ""); foreach ($query as $sql) { $error_updating = false; $error_inserting = false; if ($dbconn->execute($sql) === false) { echo _("Error creating scan job") . ": " . $dbconn->ErrorMsg(); if ($vuln_op == "editrecurring") { $error_updating = true; } else { $error_creating = true; } } else { $config_nt = array('content' => "", 'options' => array('type' => "nf_success", 'cancel_button' => false), 'style' => 'width: 40%; margin: 20px auto; text-align: center;'); if ($vuln_op == "editrecurring" && !$error_updating) { $config_nt["content"] = _("Successfully Updated Recurring Job"); $nt = new Notification('nt_1', $config_nt); $nt->show(); } elseif (!$error_creating) { $config_nt["content"] = _("Successfully Submitted Job"); $nt = new Notification('nt_1', $config_nt); $nt->show(); //logAccess( "Submitted Job [ $jid ] $request" ); foreach ($jobs_names as $job_name) { $infolog = array($job_name); Log_action::log(66, $infolog); } foreach ($sjobs_names as $job_name) { $infolog = array($job_name); Log_action::log(67, $infolog); } } else { echo "<br><center>" . _("Failed Job Creation") . "</center>"; } ?> <script type="text/javascript"> //<![CDATA[ document.location.href='<?php echo Menu::get_menu_url(AV_MAIN_PATH . '/vulnmeter/manage_jobs.php', 'environment', 'vulnerabilities', 'scan_jobs'); ?> '; //]]> </script> <?php } } } // count($_SESSION["_vuln_targets"])>0 echo "</b></center>"; }
$header = _('Policy and auditing database'); if (count($res) > 0) { $data['data'] = "<div style='font-weight: bold; font-size: 11px; padding: 10px 0px;'>" . _($header) . ":</div>\n <table class='table_files table_data' id='tf'>\n <thead>\n <tr>\n <th class='cf_type'>" . _('Type') . "</th>\n <th class='cf_date'>" . _('Last Date') . "</th>\n <th class='cf_date'>" . _('First Date') . "</th>\n <th>" . _('Event') . "</th>\n </tr>\n </thead>\n \n <tbody>"; $days = 0; $dates = array(); foreach ($res as $line) { $r_data = explode(',', $line); if (!empty($r_data)) { if (empty($dates[$r_data[1]])) { $dates[$data[1]] = $r_data[1]; $days = $days + 1; $color = $days % 2 == 0 ? 'class="odd"' : 'class="even"'; } $data['data'] .= "<tr {$color}>\n <td class='cf_type'>" . $r_data[0] . "</td>\n <td class='cf_date'>" . $r_data[1] . "</td>\n <td class='cf_date'>" . $r_data[2] . "</td>\n <td class='cf_path'>" . $r_data[3] . "</td>\n </tr>"; } } $data['data'] .= "</tbody>\n </table>"; } else { $config_nt = array('content' => $header . ": <span style='font-weight: bold;'>" . _('No results') . "</span>", 'options' => array('type' => 'nf_info', 'cancel_button' => FALSE), 'style' => 'width: 80%; margin: 20px auto; text-align: left;'); $nt = new Notification('nt_1', $config_nt); $data['data'] = $nt->show(FALSE); } } catch (Exception $e) { $data['status'] = 'error'; $data['data'] = _('Error! Policy and auditing database could not be extracted for this agent'); } break; } echo json_encode($data); exit; }
function submit_scan($SVRid, $job_name, $ssh_credential, $smb_credential, $schedule_type, $not_resolve, $user, $entity, $targets, $scheduled_status, $hosts_alive, $sid, $send_email, $timeout, $scan_locally, $dayofweek, $dayofmonth, $ROYEAR, $ROMONTH, $ROday, $time_hour, $time_min, $time_interval, $sched_id, $biyear, $bimonth, $biday, $nthweekday, $tz, $daysMap) { $db = new ossim_db(); $dbconn = $db->connect(); $credentials = $ssh_credential . '|' . $smb_credential; $username = valid_hex32($entity) ? $entity : $user; if (empty($username)) { $username = Session::get_session_user(); } $btime_hour = $time_hour; // save local time $btime_min = $time_min; $bbiyear = $biyear; $bbimonth = $bimonth; $bbiday = $biday; if ($schedule_type == 'O') { // date and time for run once if (empty($ROYEAR)) { $ROYEAR = gmdate('Y'); } if (empty($ROMONTH)) { $ROMONTH = gmdate('m'); } if (empty($ROday)) { $ROday = gmdate('d'); } list($_y, $_m, $_d, $_h, $_u, $_s, $_time) = Util::get_utc_from_date($dbconn, "{$ROYEAR}-{$ROMONTH}-{$ROday} {$time_hour}:{$time_min}:00", $tz); $ROYEAR = $_y; $ROMONTH = $_m; $ROday = $_d; $time_hour = $_h; $time_min = $_u; } else { if (in_array($schedule_type, array('D', 'W', 'M', 'NW'))) { // date and time for Daily, Day of Week, Day of month, Nth weekday of month list($b_y, $b_m, $b_d, $b_h, $b_u, $b_s, $b_time) = Util::get_utc_from_date($dbconn, "{$biyear}-{$bimonth}-{$biday} {$time_hour}:{$time_min}:00", $tz); $biyear = $b_y; $bimonth = $b_m; $biday = $b_d; $time_hour = $b_h; $time_min = $b_u; } } $resolve_names = $not_resolve == '1' ? 0 : 1; if ($schedule_type != 'N') { // current datetime in UTC $arrTime = explode(":", gmdate('Y:m:d:w:H:i:s')); $year = $arrTime[0]; $mon = $arrTime[1]; $mday = $arrTime[2]; $wday = $arrTime[3]; $hour = $arrTime[4]; $min = $arrTime[5]; $sec = $arrTime[6]; $timenow = $hour . $min . $sec; $run_wday = $daysMap[$dayofweek]['number']; $run_time = sprintf('%02d%02d%02d', $time_hour, $time_min, '00'); $run_mday = $dayofmonth; $time_value = "{$time_hour}:{$time_min}:00"; $ndays = array('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'); $begin_in_seconds = Util::get_utc_unixtime("{$biyear}-{$bimonth}-{$biday} {$time_hour}:{$time_min}:00") - 3600 * $tz; $current_in_seconds = gmdate('U'); // current datetime in UTC if (strlen($bimonth) == 1) { $bimonth = '0' . $bimonth; } if (strlen($biday) == 1) { $biday = '0' . $biday; } } switch ($schedule_type) { case 'N': $requested_run = gmdate('YmdHis'); break; case 'O': $requested_run = sprintf('%04d%02d%02d%06d', $ROYEAR, $ROMONTH, $ROday, $run_time); break; case 'D': if ($begin_in_seconds > $current_in_seconds) { $next_day = $biyear . $bimonth . $biday; // selected date by user } else { if ($run_time > $timenow) { $next_day = $year . $mon . $mday; // today } else { $next_day = gmdate("Ymd", strtotime("+1 day GMT", gmdate("U"))); // next day } } $requested_run = sprintf("%08d%06d", $next_day, $run_time); break; case 'W': if ($begin_in_seconds > $current_in_seconds) { // if it is a future date $wday = date("w", mktime(0, 0, 0, $bimonth, $biday, $biyear)); // make week day for begin day if ($run_wday == $wday) { $next_day = $biyear . $bimonth . $biday; // selected date by user } else { $next_day = gmdate("Ymd", strtotime("next " . $ndays[$run_wday] . " GMT", mktime(0, 0, 0, $bimonth, $biday, $biyear))); } } else { if ($run_wday == $wday && $run_time > $timenow) { $next_day = $year . $mon . $mday; // today } else { $next_day = gmdate("Ymd", strtotime("next " . $ndays[$run_wday] . " GMT", gmdate("U"))); // next week } } preg_match("/(\\d{4})(\\d{2})(\\d{2})/", $next_day, $found); list($b_y, $b_m, $b_d, $b_h, $b_u, $b_s, $b_time) = Util::get_utc_from_date($dbconn, $found[1] . "-" . $found[2] . "-" . $found[3] . " {$btime_hour}:{$btime_min}:00", $tz); $requested_run = sprintf("%04d%02d%02d%02d%02d%02d", $b_y, $b_m, $b_d, $b_h, $b_u, "00"); break; case 'M': if ($begin_in_seconds > $current_in_seconds) { // if it is a future date if ($run_mday >= $biday) { $next_day = $biyear . $bimonth . ($run_mday < 10 ? "0" : "") . $run_mday; // this month } else { $next_day = sprintf("%06d%02d", gmdate("Ym", strtotime("next month GMT", mktime(0, 0, 0, $bimonth, $biday, $biyear))), $run_mday); } } else { if ($run_mday > $mday || $run_mday == $mday && $run_time > $timenow) { $next_day = $year . $mon . ($run_mday < 10 ? "0" : "") . $run_mday; // this month } else { $next_day = sprintf("%06d%02d", gmdate("Ym", strtotime("next month GMT", gmdate("U"))), $run_mday); } } preg_match("/(\\d{4})(\\d{2})(\\d{2})/", $next_day, $found); list($b_y, $b_m, $b_d, $b_h, $b_u, $b_s, $b_time) = Util::get_utc_from_date($dbconn, $found[1] . "-" . $found[2] . "-" . $found[3] . " {$btime_hour}:{$btime_min}:00", $tz); $requested_run = sprintf("%04d%02d%02d%02d%02d%02d", $b_y, $b_m, $b_d, $b_h, $b_u, "00"); break; case 'NW': if ($begin_in_seconds > $current_in_seconds) { // if it is a future date $array_time = array('month' => $bbimonth, 'day' => $bbiday, 'year' => $bbiyear); $requested_run = weekday_month(strtolower($daysMap[$dayofweek]['text']), $nthweekday, $btime_hour, $btime_min, $array_time); } else { $requested_run = weekday_month(strtolower($daysMap[$dayofweek]['text']), $nthweekday, $btime_hour, $btime_min); } preg_match("/(\\d{4})(\\d{2})(\\d{2})(\\d{2})(\\d{2})(\\d{2})/", $requested_run, $found); list($b_y, $b_m, $b_d, $b_h, $b_u, $b_s, $b_time) = Util::get_utc_from_date($dbconn, $found[1] . "-" . $found[2] . "-" . $found[3] . " " . $found[4] . ":" . $found[5] . ":00", $tz); $requested_run = sprintf("%04d%02d%02d%02d%02d%02d", $b_y, $b_m, $b_d, $b_h, $b_u, "00"); $dayofmonth = $nthweekday; break; default: break; } $insert_time = gmdate('YmdHis'); if (!empty($_SESSION['_vuln_targets']) && count($_SESSION['_vuln_targets']) > 0) { $sgr = array(); foreach ($_SESSION['_vuln_targets'] as $target_selected => $server_id) { $sgr[$server_id][] = $target_selected; } ossim_clean_error(); unset($_SESSION['_vuln_targets']); // clean scan targets $resolve_names = $not_resolve == '1' ? 0 : 1; $queries = array(); $bbimonth = strlen($bbimonth) == 1 ? '0' . $bbimonth : $bbimonth; $bbiday = strlen($bbiday) == 1 ? '0' . $bbiday : $bbiday; $qc = 0; if ($schedule_type == 'N') { foreach ($sgr as $notify_sensor => $target_list) { $target_list = implode("\n", $target_list); $params = array($job_name, $username, Session::get_session_user(), $schedule_type, $target_list, $hosts_alive, $sid, $send_email, $timeout, $SVRid, $insert_time, $requested_run, '3', 'S', $notify_sensor, $scan_locally, '', $resolve_names, $credentials); $queries[$qc]['query'] = 'INSERT INTO vuln_jobs ( name, username, fk_name, meth_SCHED, meth_TARGET, meth_CRED, meth_VSET, meth_Wfile, meth_TIMEOUT, scan_ASSIGNED, scan_SUBMIT, scan_next, scan_PRIORITY, status, notify, authorized, author_uname, resolve_names, credentials ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'; $queries[$qc]['params'] = $params; $qc++; } } else { $params = array($bbiyear . $bbimonth . $bbiday, $job_name, $username, Session::get_session_user(), $schedule_type, $dayofweek, $dayofmonth, $time_value, implode("\n", $targets), $hosts_alive, $sid, $send_email, $scan_locally, $timeout, $requested_run, $insert_time, strval($scheduled_status), $resolve_names, $time_interval, '', $credentials, $SVRid); $queries[$qc]['query'] = 'INSERT INTO vuln_job_schedule ( begin, name, username, fk_name, schedule_type, day_of_week, day_of_month, time, meth_TARGET, meth_CRED, meth_VSET, meth_Wfile, meth_Ucheck, meth_TIMEOUT, next_CHECK, createdate, enabled, resolve_names, time_interval, IP_ctx, credentials, email) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) '; $queries[$qc]['params'] = $params; $qc++; } $execute_errors = array(); foreach ($queries as $id => $sql_data) { $rs = $dbconn->execute($sql_data['query'], $sql_data['params']); if ($rs === FALSE) { $execute_errors[] = $dbconn->ErrorMsg(); } } if (empty($execute_errors) && $schedule_type != 'N') { // We have to update the vuln_job_assets if (intval($sched_id) == 0) { $query = ossim_query('SELECT LAST_INSERT_ID() as sched_id'); $rs = $dbconn->Execute($query); if (!$rs) { Av_exception::throw_error(Av_exception::DB_ERROR, $dbconn->ErrorMsg()); } else { $sched_id = $rs->fields['sched_id']; } } Vulnerabilities::update_vuln_job_assets($dbconn, 'insert', $sched_id, 0); } $config_nt = array('content' => '', 'options' => array('type' => 'nf_success', 'cancel_button' => FALSE), 'style' => 'width: 40%; margin: 20px auto; text-align: center;'); $config_nt['content'] = empty($execute_errors) ? _('Successfully Submitted Job') : _('Error creating scan job:') . implode('<br>', $execute_errors); $nt = new Notification('nt_1', $config_nt); $nt->show(); $dbconn->close(); } }