function save_filter($conn, $filters, $data) { //Getting the number of filters to be applied of the group $cont = $filters->get_num_filter_added(); //We need at least one, otherwise we show an error. if ($cont < 1) { $return['error'] = TRUE; $return['msg'] = _('At least one filter needed'); return $return; } $name = utf8_decode($data['name']); $descr = utf8_decode($data['descr']); ossim_valid($name, OSS_NOECHARS, OSS_ALPHA, OSS_PUNC, 'illegal:' . _('Group Name')); ossim_valid($descr, OSS_ALPHA, OSS_NULLABLE, OSS_PUNC, OSS_AT, OSS_NL, 'illegal:' . _('Description')); if (ossim_error()) { $response['error'] = TRUE; $response['msg'] = ossim_get_error(); ossim_clean_error(); return $response; } //Trying to save the filters, in case of error an exception will arise try { $new_id = Util::uuid(); $ctx = Session::get_default_ctx(); $group = new Asset_group($new_id); $group->set_name($name); $group->set_descr($descr); $group->set_ctx($ctx); $group->save_in_db($conn); $group->save_assets_from_search($conn); $filters->empty_filter_search($conn); $return['error'] = FALSE; $return['id'] = $new_id; $return['msg'] = 'ok'; Asset_filter_list::delete_filters_from_session(); } catch (Exception $e) { $return['error'] = TRUE; $return['msg'] = $e->getMessage(); } return $return; }
<?php //CSS Files $_files = array(array('src' => 'av_common.css', 'def_path' => TRUE)); Util::print_include_files($_files, 'css'); ?> </head> <body> <?php if ($data['status'] != 'error') { try { $db = new ossim_db(); $conn = $db->connect(); $asset_group = new Asset_group($id); $asset_group->load_from_db($conn); $asset_group->set_name($name); $asset_group->set_owner($owner); $asset_group->set_descr($descr); $asset_group->save_in_db($conn); $data['status'] = 'OK'; $data['data'] = _('Your changes have been saved'); $db->close(); } catch (Exception $e) { $data['status'] = 'error'; $data['data'] = array('php_exception' => $e->getMessage()); } } if ($data['status'] == 'error') { $txt_error = '<div>' . _('The following errors occurred') . ":</div>\n <div style='padding: 10px;'>" . implode('<br/>', $data['data']) . '</div>'; $config_nt = array('content' => $txt_error, 'options' => array('type' => 'nf_error', 'cancel_button' => FALSE), 'style' => 'width: 80%; margin: 20px auto; text-align: left;'); $nt = new Notification('nt_1', $config_nt);
foreach ($data['by_host'] as $h_key => $h_data) { if ($h_data['status'] == 'warning') { $data['general']['status'] = 'warning'; $data['general']['data'] = _('Hosts saved with warnings'); break; } } } else { $data['general']['status'] = 'warning'; $data['general']['data'] = _('Warning! Some hosts could not be saved'); } //Create a Asset Group if (!empty($group_name)) { $new_group_id = Util::uuid(); $group = new Asset_group($new_group_id); $group->set_name($group_name); $group->set_ctx($ctx); $group->save_in_db($conn); $group->save_assets_from_list($conn, $data['general']['hosts_in_group']); } } /* echo '<pre style="white-space: pre;">'; print_r($data); print_r($scan_results); echo '</pre>'; */ //Showing scan results ?> <div id="summary_container">