예제 #1
0
 function add_systems()
 {
     if (!isset($_POST['submit_file'])) {
         # nothing submitted - display the form
         $this->data['heading'] = 'Add Devices';
         $this->data['include'] = 'v_add_systems';
         $this->load->view('v_template', $this->data);
     }
     if (isset($_POST['submit_file'])) {
         # we have an uploaded file - store and process
         $timestamp = date("Y-m-d H:i:s");
         $target_path = BASEPATH . "../application/uploads/" . basename($_FILES['upload_file']['name']);
         if (!move_uploaded_file($_FILES['upload_file']['tmp_name'], $target_path)) {
             $this->data['error'] = "The file " . basename($_FILES['upload_file']['name']) . " could not be uploaded.<br />";
             $this->data['query'] = $this->data['error'];
             $this->data['heading'] = 'Error';
             $this->data['include'] = 'v_error';
             $this->data['export_report'] = 'y';
             $this->data['group_id'] = '0';
             $this->load->view('v_template', $this->data);
             exit;
         }
         require_once BASEPATH . '../application/libraries/phpexcel/PHPExcel/IOFactory.php';
         if (!($objPHPExcel = PHPExcel_IOFactory::load($target_path))) {
             $this->data['error'] = "Error creating the PHPExcel_IOFactory object.<br />";
             $this->data['query'] = $this->data['error'];
             $this->data['heading'] = 'Error';
             $this->data['include'] = 'v_error';
             $this->data['export_report'] = 'y';
             $this->data['group_id'] = '0';
             $this->load->view('v_template', $this->data);
             exit;
         }
         $attributes = array();
         $details = array();
         $object = new stdClass();
         $this->load->model("m_system");
         $this->load->model("m_oa_org");
         $this->load->model("m_oa_location");
         $this->load->model("m_sys_man_audits");
         $this->load->model("m_oa_group");
         $this->load->helper('snmp');
         $this->load->helper('snmp_oid');
         $this->load->library('encrypt');
         $objWorksheet = $objPHPExcel->getActiveSheet();
         $count = 0;
         $error = '';
         $this->data['error'] = '';
         foreach ($objWorksheet->getRowIterator() as $row) {
             $count++;
             $cellIterator = $row->getCellIterator();
             $cellIterator->setIterateOnlyExistingCells(true);
             if ($count == 1) {
                 # grab the first row and use as column names
                 foreach ($cellIterator as $cell) {
                     $attributes[] = $cell->getValue();
                 }
             } else {
                 # populate the array values
                 $cellIterator->setIterateOnlyExistingCells(false);
                 unset($details);
                 $details = array();
                 $details = array_fill_keys($attributes, '');
                 $cell_number = 0;
                 foreach ($cellIterator as $cell) {
                     if ($cell_number < count($attributes)) {
                         $details[$attributes[$cell_number]] = $cell->getValue();
                         $cell_number++;
                     }
                 }
                 // convert the $details array to an object
                 $details = (object) $details;
                 $details->last_seen_by = "spreadsheet";
                 $details->last_seen = $timestamp;
                 $details->last_user = $this->data['user_full_name'];
                 $details->timestamp = $timestamp;
                 $error = '';
                 if (isset($details->org_name)) {
                     # we have an org name - need to find it's ID
                     if ($org_id = $this->m_oa_org->select_org($details->org_name)) {
                         # we have a matching org
                         $details->man_org_id = $org_id;
                     }
                 }
                 if (isset($details->location_name)) {
                     # we have a location name - need to find it's ID
                     if ($location_id = $this->m_oa_location->get_location_id($details->location_name)) {
                         # we have a match
                         $details->man_location_id = $location_id;
                     }
                 }
                 if (isset($details->snmp_community) and $details->snmp_community != '') {
                     if (isset($details->snmp_port) and $details->snmp_port != '') {
                         # leave it
                     } else {
                         $details->snmp_port = '161';
                     }
                     if (isset($details->snmp_version) and $details->snmp_version != '') {
                         # leave it
                     } else {
                         $details->snmp_version = '2c';
                     }
                     if (isset($details->man_ip_address) and $details->man_ip_address != '') {
                         $encode = array();
                         $encode->ip_address = $details->man_ip_address;
                         $encode->snmp_version = $details->snmp_version;
                         $encode->snmp_community = $details->snmp_community;
                         $encode->snmp_port = $details->snmp_port;
                         $encoded = json_encode($encode);
                         $encoded = $this->encrypt->encode($encoded);
                         $details->access_details = $encoded;
                         if (extension_loaded('snmp')) {
                             get_snmp($details);
                             $details->last_seen_by = 'snmp';
                         }
                     }
                 }
                 # first test to see if we have a system_id -
                 # if so, just send the submitted details to the system_update function
                 if (!isset($details->system_id) or $details->system_id == '') {
                     if (!isset($details->system_key) or $details->system_key == '') {
                         $details->system_key = $this->m_system->create_system_key($details);
                     }
                     # setting the system_key - we don't have the required info to create a unique key
                     if (!isset($details->system_key) or $details->system_key == '') {
                         $error = "Error on row #" . $count . ". Insufficient details to create system key. Please supply (in order of preference) fqdn, hostname and domain, ip address, type and (unique) serial.<br />";
                         $this->data['error'] .= $error;
                     }
                     # make sure we have a hostname variable
                     if (!isset($details->hostname)) {
                         $details->hostname = '';
                     }
                     $details->hostname = preg_replace("/[^a-z0-9-.]+/i", "", $details->hostname);
                     $details->hostname = mb_strtolower($details->hostname);
                     # try to determine if this device is already in the database
                     $details->system_id = $this->m_system->find_system($details);
                 }
                 error_log($details->system_id);
                 if ($error != '') {
                     $error = '';
                 } else {
                     if (isset($details->system_id) and $details->system_id > '') {
                         # we need to update an existing system
                         $this->m_system->update_system($details);
                     } else {
                         # this is a new system (we don't have a system_key match)
                         $details->first_timestamp = $details->timestamp;
                         $details->system_id = $this->m_system->insert_system($details);
                     }
                     // Insert an entry in to the audit log
                     $details->audits_ip = '';
                     $details->type = $this->m_system->get_system_type($details->system_id);
                     $this->m_sys_man_audits->insert_audit($details);
                     // Finally, update groups
                     $this->m_oa_group->update_system_groups($details);
                     unset($details);
                 }
             }
         }
         unlink($target_path);
         if ($this->data['error'] != '') {
             # there were errors with processing.
             $this->data['query'] = $this->data['error'];
             $this->data['heading'] = 'Error';
             $this->data['include'] = 'v_error';
             $this->data['export_report'] = 'y';
             $this->data['group_id'] = '0';
             $this->load->view('v_template', $this->data);
         } else {
             redirect('main/index');
         }
     }
 }
예제 #2
0
    /**
     * WLC Memory
     */
    $total_memory = explode(" ", get_snmp("1.3.6.1.4.1.14179.1.1.5.2.0", "INTEGER"));
    sendGraphite("wlc_total_memory", $total_memory[0]);
    $free_memory = explode(" ", get_snmp("1.3.6.1.4.1.14179.1.1.5.3.0", "INTEGER"));
    sendGraphite("wlc_free_memory", $free_memory[0]);
    /**
     * WLC CPU - Overall
     */
    $wlc_cpu = explode(" ", get_snmp("1.3.6.1.4.1.14179.1.1.5.1.0", "INTEGER"));
    sendGraphite("wlc_cpu", $wlc_cpu[0]);
    /**
     * WLC Connected APs
     */
    $wlc_total_ap = explode(" ", get_snmp("1.3.6.1.4.1.9.9.618.1.8.4.0", "Gauge32"));
    sendGraphite("wlc_total_ap", $wlc_total_ap[0]);
}
foreach ($controllers as $c_name => $ip) {
    /**
     * Clients per radio
     */
    $aps = getApTable();
    $radios = getRadioTable($aps);
    $clientsPerRadio = getNoOfClientsPerRadio($radios);
    $clientsPerRadio["bogus.bogus"] = 0;
    $total = 0;
    $assoc_band = array();
    $prev_ap = "";
    $prev_no = 0;
    foreach ($clientsPerRadio as $radio => $no) {
예제 #3
0
 public function add_systems()
 {
     if (!isset($_POST['submit'])) {
         # nothing submitted - display the form
         $this->data['heading'] = 'Add Devices';
         $this->data['include'] = 'v_add_systems';
         $this->load->view('v_template', $this->data);
     }
     if (isset($_POST['submit'])) {
         # we have an uploaded file - store and process
         $last_seen = $this->config->config['timestamp'];
         $target_path = BASEPATH . "../application/uploads/" . basename($_FILES['upload_file']['name']);
         if (!move_uploaded_file($_FILES['upload_file']['tmp_name'], $target_path)) {
             $this->data['error'] = "The file " . basename($_FILES['upload_file']['name']) . " could not be uploaded.<br />";
             $this->data['query'] = $this->data['error'];
             $this->data['heading'] = 'Error';
             $this->data['include'] = 'v_error';
             $this->data['export_report'] = 'y';
             $this->data['group_id'] = '0';
             $this->load->view('v_template', $this->data);
             exit;
         }
         require_once BASEPATH . '../application/libraries/phpexcel/PHPExcel/IOFactory.php';
         if (!($objPHPExcel = PHPExcel_IOFactory::load($target_path))) {
             $this->data['error'] = "Error creating the PHPExcel_IOFactory object.<br />";
             $this->data['query'] = $this->data['error'];
             $this->data['heading'] = 'Error';
             $this->data['include'] = 'v_error';
             $this->data['export_report'] = 'y';
             $this->data['group_id'] = '0';
             $this->load->view('v_template', $this->data);
             exit;
         }
         $attributes = array();
         $details = array();
         $object = new stdClass();
         $this->load->model("m_system");
         $this->load->model("m_oa_org");
         $this->load->model("m_oa_location");
         $this->load->model("m_audit_log");
         $this->load->model("m_oa_group");
         $this->load->model("m_devices_components");
         $this->load->helper('snmp');
         $this->load->helper('snmp_oid');
         $this->load->library('encrypt');
         $objWorksheet = $objPHPExcel->getActiveSheet();
         $count = 0;
         $error = '';
         $this->data['error'] = '';
         foreach ($objWorksheet->getRowIterator() as $row) {
             $count++;
             $cellIterator = $row->getCellIterator();
             $cellIterator->setIterateOnlyExistingCells(true);
             if ($count == 1) {
                 # grab the first row and use as column names
                 foreach ($cellIterator as $cell) {
                     $temp = $cell->getValue();
                     $temp = trim($temp);
                     if ($temp != '') {
                         # $attributes[] = $cell->getValue();
                         $attributes[] = $temp;
                     }
                 }
             } else {
                 # populate the array values
                 $cellIterator->setIterateOnlyExistingCells(false);
                 unset($details);
                 $details = array();
                 $details = array_fill_keys($attributes, '');
                 $cell_number = 0;
                 foreach ($cellIterator as $cell) {
                     if ($cell_number < count($attributes)) {
                         $details[$attributes[$cell_number]] = $cell->getValue();
                         $cell_number++;
                     }
                 }
                 // convert the $details array to an object
                 $details = (object) $details;
                 $details->last_seen = $last_seen;
                 $details->last_seen_by = "spreadsheet";
                 $details->last_user = $this->user->full_name;
                 $error = '';
                 if (isset($details->org_name)) {
                     # we have an org name - need to find it's ID
                     if ($org_id = $this->m_oa_org->select_org($details->org_name)) {
                         # we have a matching org
                         $details->org_id = $org_id;
                     }
                 }
                 if (isset($details->location_name)) {
                     # we have a location name - need to find it's ID
                     if ($location_id = $this->m_oa_location->get_location_id($details->location_name)) {
                         # we have a match
                         $details->location_id = $location_id;
                     }
                 }
                 if (isset($details->snmp_community) and $details->snmp_community != '') {
                     if (isset($details->snmp_port) and $details->snmp_port != '') {
                         # leave it
                     } else {
                         $details->snmp_port = '161';
                     }
                     if (isset($details->snmp_version) and $details->snmp_version != '') {
                         # leave it
                     } else {
                         $details->snmp_version = '2c';
                     }
                     if (isset($details->ip) and $details->ip != '') {
                         $encode = array();
                         $encode->ip_address = $details->ip;
                         $encode->snmp_version = $details->snmp_version;
                         $encode->snmp_community = $details->snmp_community;
                         $encode->snmp_port = $details->snmp_port;
                         $encoded = json_encode($encode);
                         $encoded = $this->encrypt->encode($encoded);
                         $details->access_details = $encoded;
                         if (extension_loaded('snmp')) {
                             $temp_array = get_snmp($details);
                             $details = $temp_array['details'];
                             $network_interfaces = $temp_array['interfaces'];
                             $details->last_seen_by = 'snmp';
                         }
                     }
                 }
                 # first test to see if we have a system.id -
                 # if not, make a system key and find (or not) the device
                 if (!isset($details->id) or $details->id == '') {
                     # make sure we have a hostname variable
                     if (!isset($details->hostname)) {
                         $details->hostname = '';
                     }
                     $details->hostname = preg_replace("/[^a-z0-9-.]+/i", "", $details->hostname);
                     $details->hostname = mb_strtolower($details->hostname);
                     # try to determine if this device is already in the database
                     $details->id = $this->m_system->find_system($details);
                 }
                 if ($error != '') {
                     $error = '';
                 } else {
                     if (isset($details->id) and $details->id > '') {
                         # we need to update an existing system
                         $this->m_system->update_system($details);
                     } else {
                         # this is a new system
                         $details->first_seen = $details->last_seen;
                         $details->id = $this->m_system->insert_system($details);
                     }
                     // Insert an entry in to the audit log
                     $details->audits_ip = ip_address_to_db($_SERVER['REMOTE_ADDR']);
                     if (!isset($details->type) or $details->type == '') {
                         $details->type = $this->m_system->get_system_type($details->id);
                     }
                     if (isset($this->user->full_name)) {
                         $temp_user = $this->user->full_name;
                     } else {
                         $temp_user = '';
                     }
                     $this->m_audit_log->create($details->id, $temp_user, $details->last_seen_by, $details->audits_ip, '', '', $details->last_seen);
                     unset($temp_user);
                     # update any network interfaces and ip addresses retrieved by SNMP
                     $details->last_seen = $this->m_devices_components->read($details->id, 'y', 'system', '', 'last_seen');
                     $details->first_seen = $this->m_devices_components->read($details->id, 'y', 'system', '', 'first_seen');
                     if (isset($network_interfaces) and is_array($network_interfaces) and count($network_interfaces) > 0) {
                         $this->m_devices_components->process_component('network', $details, $xml->network);
                         foreach ($network_interfaces as $input) {
                             if (isset($input->ip_addresses) and is_array($input->ip_addresses)) {
                                 $this->m_devices_components->process_component('ip', $details, $ip_input);
                             }
                         }
                     }
                     // Finally, update groups
                     $this->m_oa_group->update_system_groups($details);
                     unset($details);
                 }
             }
         }
         unlink($target_path);
         if ($this->data['error'] != '') {
             # there were errors with processing.
             $this->data['query'] = $this->data['error'];
             $this->data['heading'] = 'Error';
             $this->data['include'] = 'v_error';
             $this->data['export_report'] = 'y';
             $this->data['group_id'] = '0';
             $this->load->view('v_template', $this->data);
         } else {
             redirect('main/index');
         }
     }
 }
예제 #4
0
 function import_nmis()
 {
     if (!isset($_POST['import'])) {
         # show the form
         $this->data['heading'] = 'Import from NMIS';
         $this->data['include'] = 'v_import_nmis';
         $this->data['sortcolumn'] = '1';
         $this->load->view('v_template', $this->data);
     } else {
         $nodes_file = $_POST['nodes_file'];
         $this->load->helper('snmp_oid');
         $this->load->helper('snmp');
         $this->load->library('encrypt');
         $this->load->model("m_system");
         $this->load->model("m_oa_group");
         # the Nodes.nmis file should be located at /usr/local/nmis8/conf/Nodes.nmis
         # grab a list of the devices in the file
         # read in the Nodes.nmis file
         #$file_handle = fopen('/usr/local/nmis8/conf/Nodes.nmis', "r");
         #$string = fread($file_handle, filesize('/usr/local/nmis8/conf/Nodes.nmis'));
         $file_handle = fopen($nodes_file, "r");
         $string = fread($file_handle, filesize($nodes_file));
         $string = str_replace(PHP_EOL, " ", $string);
         $string = str_replace("\r\n", " ", $string);
         $string = str_replace("\n", " ", $string);
         $string = str_replace(chr(13), " ", $string);
         $string = str_replace("%hash = (", "{", $string);
         $string = str_replace(");", "}", $string);
         $string = str_replace("=>", ":", $string);
         $string = str_replace("'undef'", "''", $string);
         $string = str_replace("undef", "''", $string);
         $string = str_replace("'", "\"", $string);
         $conf = json_decode($string, TRUE);
         switch (json_last_error()) {
             case JSON_ERROR_NONE:
                 # no errors
                 break;
             case JSON_ERROR_DEPTH:
                 echo "Error importing Nmis.nodes file<br />\n";
                 echo 'JSON_ERROR_DEPTH - Maximum stack depth exceeded<br />';
                 exit;
                 break;
             case JSON_ERROR_STATE_MISMATCH:
                 echo "Error importing Nmis.nodes file<br />\n";
                 echo 'JSON_ERROR_STATE_MISMATCH - Underflow or the modes mismatch<br />';
                 exit;
                 break;
             case JSON_ERROR_CTRL_CHAR:
                 echo "Error importing Nmis.nodes file<br />\n";
                 echo 'JSON_ERROR_CTRL_CHAR - Unexpected control character found<br />';
                 exit;
                 break;
             case JSON_ERROR_SYNTAX:
                 echo "Error importing Nmis.nodes file<br />\n";
                 echo 'JSON_ERROR_SYNTAX - Syntax error, malformed JSON<br />';
                 exit;
                 break;
             case JSON_ERROR_UTF8:
                 echo "Error importing Nmis.nodes file<br />\n";
                 echo 'JSON_ERROR_UTF8 - Malformed UTF-8 characters, possibly incorrectly encoded<br />';
                 exit;
                 break;
             default:
                 echo "Error importing Nmis.nodes file<br />\n";
                 echo 'Unknown error<br />';
                 exit;
                 break;
         }
         foreach ($conf as $device) {
             $device['ip_address'] = '';
             $device['hostname'] = '';
             $device['fqdn'] = '';
             if (filter_var($device['host'], FILTER_VALIDATE_IP)) {
                 # we have an ip address as opposed to a name or fqdn
                 $device['ip_address'] = $device['host'];
             } else {
                 # we have a name or fqdn
                 if (strpos($device['host'], ".")) {
                     # fqdn - explode it
                     $device['fqdn'] = $device['host'];
                     $i = explode(".", $device['host']);
                     $device['hostname'] = $i[0];
                 } else {
                     # it's just a name
                     $device['hostname'] = $device['host'];
                 }
             }
             if ($device['ip_address'] > '') {
                 # lookup the name
                 $device['hostname'] = gethostbyaddr($device['ip_address']);
             } else {
                 # lookup the ip
                 if ($device['fqdn'] > '') {
                     $device['ip_address'] = gethostbyname($device['fqdn']);
                 } else {
                     $device['ip_address'] = gethostbyname($device['host']);
                 }
             }
             if ($device['version'] == 'snmpv2c') {
                 $device['version'] = '2c';
             }
             $snmp_details->name = '';
             if ($device['community'] > '' and $device['version'] == '2c' and $device['ip_address'] > '') {
                 $encode['ip_address'] = $device['ip_address'];
                 $encode['fqdn'] = $device['fqdn'];
                 $encode['hostname'] = $device['hostname'];
                 $encode['snmp_version'] = $device['version'];
                 $encode['snmp_community'] = $device['community'];
                 $encode['snmp_v3_sec_name'] = '';
                 $encode['snmp_v3_sec_level'] = '';
                 $encode['snmp_v3_auth_protocol'] = $device['authprotocol'];
                 $encode['snmp_v3_auth_passphrase'] = $device['authpassword'];
                 $encode['snmp_v3_priv_protocol'] = $device['privprotocol'];
                 $encode['snmp_v3_priv_passphrase'] = $device['privpassword'];
                 $encoded = json_encode($encode);
                 $encoded = $this->encrypt->encode($encoded);
                 // $encoded = json_encode($encode);
                 // print_r($encoded);
                 // echo "\n";
                 // $encoded = $this->encrypt->encode($encoded);
                 // echo $encoded . "\n";
                 // $decoded = $this->encrypt->decode($encoded);
                 // echo $decoded . "\n";
                 // $decoded = json_decode($decoded);
                 // print_r($decoded);
                 $snmp_details = get_snmp($device['ip_address'], $device['version'], $device['community']);
                 $snmp_details->access_details = $encoded;
                 $snmp_details->hostname = $device['hostname'];
                 $snmp_details->nmis_group = $device['group'];
                 $snmp_details->nmis_name = $device['name'];
                 $snmp_details->nmis_role = $device['roleType'];
             }
             if ($snmp_details->name > '') {
                 # we have a result from the SNMP query.
                 # use this information to update the database
                 $snmp_details->system_id = '';
                 $snmp_details->system_id = $this->m_system->find_system($snmp_details);
                 if ($snmp_details->system_id == '') {
                     # insert a new device
                     $this->m_system->insert_snmp($snmp_details);
                 } else {
                     # update an existing device
                     $this->m_system->update_snmp($snmp_details);
                 }
                 $this->m_oa_group->update_system_groups($snmp_details);
             } else {
                 # todo - nothing from SNMP
                 # just use the info we have from the file
                 # $this->m_system->process_nmis($snmp_details);
             }
         }
         redirect('/');
     }
     # end "form" if
 }
예제 #5
0
 public function add_nmap()
 {
     if (!isset($_POST['form_nmap'])) {
         $this->load->view('v_system_add_nmap', $this->data);
     } else {
         // check if the submitting IP is in the list of allowable subnets
         if (!$this->m_oa_config->check_blessed($_SERVER['REMOTE_ADDR'], '')) {
             exit;
         }
         $log_details = new stdClass();
         $log_details->severity = 7;
         $log_details->file = 'system';
         $log_details->message = 'Start processing nmap submitted data';
         stdlog($log_details);
         $log_details->message = 'ATTENTION - audit_subnet script being used. This is deprecated. Please use discovery scripts instead.';
         $log_details->severity = 5;
         stdlog($log_details);
         unset($log_details);
         $this->load->helper('url');
         $this->load->helper('xml');
         $this->load->helper('network');
         $this->load->library('encrypt');
         if (extension_loaded('snmp')) {
             $this->load->helper('snmp');
             $this->load->helper('snmp_oid');
         }
         $this->load->model('m_system');
         $this->load->model('m_oa_group');
         $this->load->model('m_audit_log');
         $timestamp = $this->config->config['timestamp'];
         $xml_input = $_POST['form_nmap'];
         try {
             $xml_post = new SimpleXMLElement($xml_input);
         } catch (Exception $error) {
             // not a valid XML string
             $log_details = new stdClass();
             $log_details->severity = 5;
             $log_details->file = 'system';
             $log_details->message = 'Invalid XML input for NMap import';
             stdlog($log_details);
             unset($log_details);
             exit;
         }
         $count = 0;
         foreach ($xml_post->children() as $details) {
             $details = (object) $details;
             if (isset($this->session->userdata['user_id']) and is_numeric($this->session->userdata['user_id'])) {
                 echo 'Device IP: ' . $details->ip . "\n";
             }
             $count++;
             $details->last_seen = $timestamp;
             $details->last_user = '';
             $details->hostname = '';
             if ($this->config->item('discovery_use_dns') == 'y') {
                 $details = dns_validate($details);
             }
             $details->audits_ip = ip_address_to_db($_SERVER['REMOTE_ADDR']);
             $log_details = new stdClass();
             $log_details->severity = 7;
             $log_details->file = 'system';
             $log_details->message = 'Processing nmap audit result for ' . $details->ip . ' (' . $details->hostname . ')';
             stdlog($log_details);
             unset($log_details);
             if (!isset($details->type) or $details->type === '') {
                 $details->type = 'unknown';
             }
             if (extension_loaded('snmp')) {
                 // try to get more information using SNMP
                 if (!isset($details->access_details)) {
                     $details->access_details = $this->m_system->get_access_details($details->id);
                 }
                 $decoded_access = $this->encrypt->decode($details->access_details);
                 $decoded_access = json_decode($decoded_access);
                 $details->snmp_community = @$decoded_access->snmp_community;
                 $details->snmp_version = @$decoded_access->snmp_version;
                 $details->snmp_port = @$decoded_access->snmp_port;
                 $temp_array = get_snmp($details);
                 $details = $temp_array['details'];
                 $network_interfaces = $temp_array['interfaces'];
                 $ip = $temp_array['ip'];
             }
             $details->id = '';
             $details->id = $this->m_system->find_system($details);
             if (isset($details->snmp_oid) and $details->snmp_oid > '') {
                 // we received a result from SNMP, use this data to update OR insert
                 $details->last_seen_by = 'snmp';
                 $details->audits_ip = '127.0.0.1';
                 if ($this->config->item('discovery_use_dns') == 'y') {
                     $details = dns_validate($details);
                 }
                 if (isset($details->id) and !empty($details->id)) {
                     // we have a system.id and snmp details to update
                     $log_details = new stdClass();
                     $log_details->severity = 7;
                     $log_details->file = 'system';
                     $log_details->message = 'SNMP update for ' . $details->ip . ' (system id ' . $details->id . ')';
                     stdlog($log_details);
                     unset($log_details);
                     $this->m_system->update_system($details);
                 } else {
                     // we have a new system
                     $details->id = $this->m_system->insert_system($details);
                     $log_details = new stdClass();
                     $log_details->severity = 7;
                     $log_details->message = 'SNMP insert for ' . $details->ip . ' (system id ' . $details->id . ')';
                     stdlog($log_details);
                     unset($log_details);
                 }
                 # update any network interfaces and ip addresses retrieved by SNMP
                 if (isset($network_interfaces) and is_array($network_interfaces) and count($network_interfaces) > 0) {
                     $input = new stdClass();
                     $input->item = array();
                     $input->item = $network_interfaces;
                     $this->m_devices_components->process_component('network', $details, $input);
                 }
                 if (isset($ip->item) and count($ip->item) > 0) {
                     $this->m_devices_components->process_component('ip', $details, $ip);
                 }
             } else {
                 // we received a result from nmap only, use this data to update OR insert
                 $details->last_seen_by = 'nmap';
                 if (isset($details->id) and $details->id !== '') {
                     // we have a system id and nmap details to update
                     $log_details = new stdClass();
                     $log_details->severity = 7;
                     $log_details->message = 'Nmap update for ' . $details->ip . ' (system id ' . $details->id . ')';
                     stdlog($log_details);
                     unset($log_details);
                     $this->m_system->update_system($details);
                 } else {
                     // we have a new system
                     $details->id = $this->m_system->insert_system($details);
                     $log_details = new stdClass();
                     $log_details->severity = 7;
                     $log_details->message = 'Nmap insert for ' . $details->ip . ' (system id ' . $details->id . ')';
                     stdlog($log_details);
                     unset($log_details);
                 }
             }
             if (isset($this->user->full_name)) {
                 $temp_user = $this->user->full_name;
             } else {
                 $temp_user = '';
             }
             $this->m_audit_log->create($details->id, $temp_user, $details->last_seen_by, $details->audits_ip, '', '', $details->last_seen);
             unset($temp_user);
             $this->m_oa_group->update_system_groups($details);
         }
         if (isset($this->session->userdata['user_id']) and is_numeric($this->session->userdata['user_id'])) {
             echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"\n\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"en\" xml:lang=\"en\">";
             echo "<head>\n<title>Open-AudIT</title>\n</head>\n<body>\n<pre>\n";
             echo $count . ' systems processed.<br />';
             echo "<a href='" . base_url() . "index.php/system/add_nmap'>Back to input page</a><br />\n";
             echo "<a href='" . base_url() . "index.php'>Front Page</a><br />\n";
             echo "<pre>\n";
             print_r($details);
             echo "</pre>\n";
         }
     }
 }
예제 #6
0
 function import_nmis()
 {
     # have to hack this string because code_igniter doesn't like /'s
     # in the variable passed via cli
     $nodes_file = str_replace("/admin_cli/import_nmis/", "", $this->uri->uri_string());
     $log_stamp = date('M j H:i:s') . " " . gethostname() . " " . getmypid() . " admin_cli/import_nmis Starting Nodes.nmis import" . PHP_EOL;
     file_put_contents("/usr/local/open-audit/other/open-audit.log", $log_stamp, FILE_APPEND | LOCK_EX);
     $this->load->helper('snmp_oid');
     $this->load->helper('snmp');
     $this->load->library('encrypt');
     $this->load->model("m_system");
     $this->load->model("m_oa_group");
     /*
     		# before the actual nodes, import the locations
     		$locations_file = str_replace("Nodes.nmis", "Locations.nmis", $nodes_file);
     		$file_handle = fopen($locations_file, "r");
     		$string = fread($file_handle, filesize($locations_file));
     		$string = str_replace(PHP_EOL, " ", $string);
     		$string = str_replace("\r\n", " ", $string);
     		$string = str_replace("\n", " ", $string);
     		$string = str_replace(chr(13), " ", $string);
     		$string = str_replace("%hash = (", "{", $string);
     		$string = str_replace(");", "}", $string);
     		$string = str_replace("=>", ":", $string);
     		$string = str_replace("'undef'", "''", $string);
     		$string = str_replace("undef", "''", $string);
     		$string = str_replace("'", "\"", $string);
     		$conf = json_decode($string, TRUE);		
     		switch (json_last_error()) {
     		  case JSON_ERROR_NONE:
     		    # no errors
     		  break;
     		  case JSON_ERROR_DEPTH:
     			echo "Error importing Nmis.nodes file<br />\n";
     			echo 'JSON_ERROR_DEPTH - Maximum stack depth exceeded<br />';
     			exit();
     		  break;
     		  case JSON_ERROR_STATE_MISMATCH:
     			echo "Error importing Nmis.nodes file<br />\n";
     			echo 'JSON_ERROR_STATE_MISMATCH - Underflow or the modes mismatch<br />';
     			exit();
     		  break;
     		  case JSON_ERROR_CTRL_CHAR:
     			echo "Error importing Nmis.nodes file<br />\n";
     			echo 'JSON_ERROR_CTRL_CHAR - Unexpected control character found<br />';
     			exit();
     		  break;
     		  case JSON_ERROR_SYNTAX:
     			echo "Error importing Nmis.nodes file<br />\n";
     			echo 'JSON_ERROR_SYNTAX - Syntax error, malformed JSON<br />';
     			exit();
     		  break;
     		  case JSON_ERROR_UTF8:
     			echo "Error importing Nmis.nodes file<br />\n";
     			echo 'JSON_ERROR_UTF8 - Malformed UTF-8 characters, possibly incorrectly encoded<br />';
     			exit();
     		  break;
     		  default:
     			echo "Error importing Nmis.nodes file<br />\n";
     			echo 'Unknown error<br />';
     			exit();
     		  break;
     		}
     
     		foreach ($conf as $location) {
     			$this->load->model("m_oa_location");
     		}	
     */
     # read in the Nodes.nmis file
     $log_stamp = date('M j H:i:s') . " " . gethostname() . " " . getmypid() . " admin_cli/import_nmis - importing nodes from {$nodes_file}" . PHP_EOL;
     file_put_contents("/usr/local/open-audit/other/open-audit.log", $log_stamp, FILE_APPEND | LOCK_EX);
     $file_handle = fopen($nodes_file, "r");
     $string = fread($file_handle, filesize($nodes_file));
     $string = str_replace(PHP_EOL, " ", $string);
     $string = str_replace("\r\n", " ", $string);
     $string = str_replace("\n", " ", $string);
     $string = str_replace(chr(13), " ", $string);
     $string = str_replace("%hash = (", "{", $string);
     $string = str_replace(");", "}", $string);
     $string = str_replace("=>", ":", $string);
     $string = str_replace("'undef'", "''", $string);
     $string = str_replace("undef", "''", $string);
     $string = str_replace("'", "\"", $string);
     $conf = json_decode($string, TRUE);
     switch (json_last_error()) {
         case JSON_ERROR_NONE:
             # no errors
             break;
         case JSON_ERROR_DEPTH:
             echo "Error importing Nmis.nodes file<br />\n";
             echo 'JSON_ERROR_DEPTH - Maximum stack depth exceeded<br />';
             exit;
             break;
         case JSON_ERROR_STATE_MISMATCH:
             echo "Error importing Nmis.nodes file<br />\n";
             echo 'JSON_ERROR_STATE_MISMATCH - Underflow or the modes mismatch<br />';
             exit;
             break;
         case JSON_ERROR_CTRL_CHAR:
             echo "Error importing Nmis.nodes file<br />\n";
             echo 'JSON_ERROR_CTRL_CHAR - Unexpected control character found<br />';
             exit;
             break;
         case JSON_ERROR_SYNTAX:
             echo "Error importing Nmis.nodes file<br />\n";
             echo 'JSON_ERROR_SYNTAX - Syntax error, malformed JSON<br />';
             exit;
             break;
         case JSON_ERROR_UTF8:
             echo "Error importing Nmis.nodes file<br />\n";
             echo 'JSON_ERROR_UTF8 - Malformed UTF-8 characters, possibly incorrectly encoded<br />';
             exit;
             break;
         default:
             echo "Error importing Nmis.nodes file<br />\n";
             echo 'Unknown error<br />';
             exit;
             break;
     }
     foreach ($conf as $device) {
         $device = (object) $device;
         $device->ip_address = '';
         $device->hostname = '';
         $device->fqdn = '';
         if ($device->host != '127.0.0.1') {
             if (filter_var($device->host, FILTER_VALIDATE_IP)) {
                 # we have an ip address as opposed to a name or fqdn
                 $device->ip_address = $device->host;
             } else {
                 # we have a name or fqdn
                 if (strpos($device->host, ".")) {
                     # fqdn - explode it
                     $device->fqdn = $device->host;
                     $i = explode(".", $device->host);
                     $device->hostname = $i[0];
                 } else {
                     # its just a name
                     $device->hostname = $device->host;
                 }
             }
             if ($device->ip_address > '') {
                 # lookup the name
                 $device->hostname = gethostbyaddr($device->ip_address);
             } else {
                 # lookup the ip
                 if ($device->fqdn > '') {
                     $device->ip_address = gethostbyname($device->fqdn);
                 } else {
                     $device->ip_address = gethostbyname($device->host);
                 }
             }
             $log_stamp = date('M j H:i:s') . " " . gethostname() . " " . getmypid() . " admin_cli/import_nmis " . $device->ip_address . " (" . $device->hostname . ") - scanning" . PHP_EOL;
             file_put_contents("/usr/local/open-audit/other/open-audit.log", $log_stamp, FILE_APPEND | LOCK_EX);
             if ($device->version == 'snmpv2c') {
                 $device->version = '2c';
             }
             $snmp_details->name = '';
             if ($device->community > '' and $device->version == '2c' and $device->ip_address > '') {
                 $encode['ip_address'] = $device->ip_address;
                 $encode['fqdn'] = $device->fqdn;
                 $encode['hostname'] = $device->hostname;
                 $encode['snmp_version'] = @$device->version;
                 $encode['snmp_community'] = @$device->community;
                 $encode['snmp_v3_sec_name'] = '';
                 $encode['snmp_v3_sec_level'] = '';
                 $encode['snmp_v3_auth_protocol'] = @$device->authprotocol;
                 $encode['snmp_v3_auth_passphrase'] = @$device->authpassword;
                 $encode['snmp_v3_priv_protocol'] = @$device->privprotocol;
                 $encode['snmp_v3_priv_passphrase'] = @$device->privpassword;
                 $encoded = json_encode($encode);
                 $encoded = $this->encrypt->encode($encoded);
                 // $encoded = json_encode($encode);
                 // print_r($encoded);
                 // echo "\n";
                 // $encoded = $this->encrypt->encode($encoded);
                 // echo $encoded . "\n";
                 // $decoded = $this->encrypt->decode($encoded);
                 // echo $decoded . "\n";
                 // $decoded = json_decode($decoded);
                 // print_r($decoded);
                 $device->snmp_version = $device->version;
                 $device->snmp_community = $device->community;
                 $device->snmp_port = '161';
                 $device = get_snmp($device);
                 $device->access_details = $encoded;
                 #$device->nmis_group = $device['group'];
                 #$device->nmis_name = $device['name'];
                 #$device->nmis_role = $device['roleType'];
                 $device->nmis_group = $device->group;
                 $device->nmis_name = $device->name;
                 $device->nmis_role = $device->roleType;
             }
             $device->system_key = '';
             $device->system_key = $this->m_system->create_system_key($device);
             $device->system_id = '';
             $device->system_id = $this->m_system->find_system($device);
             if (isset($device->oid) and $device->oid > '') {
                 # we received a result from snmp, use this data to update or insert
                 if (isset($device->system_id) and $device->system_id != '') {
                     # update an existing device with snmp
                     $device->last_seen_by = 'snmp nmis import';
                     $this->m_system->update_system($device);
                     $log_stamp = date('M j H:i:s') . " " . gethostname() . " " . getmypid() . " admin_cli/import_nmis " . $device->ip_address . " (" . $device->hostname . ") - update snmp result" . PHP_EOL;
                     file_put_contents("/usr/local/open-audit/other/open-audit.log", $log_stamp, FILE_APPEND | LOCK_EX);
                 } else {
                     # insert a new device
                     $device->last_seen_by = 'snmp nmis import';
                     $i = $this->m_system->insert_system($device);
                     $device->system_id = $i;
                     $log_stamp = date('M j H:i:s') . " " . gethostname() . " " . getmypid() . " admin_cli/import_nmis " . $device->ip_address . " (" . $device->hostname . ") - insert snmp result" . PHP_EOL;
                     file_put_contents("/usr/local/open-audit/other/open-audit.log", $log_stamp, FILE_APPEND | LOCK_EX);
                 }
                 $this->m_oa_group->update_system_groups($device);
             } else {
                 # just use hat we have from the nodes.nmis file
                 if (isset($device->system_id) and $device->system_id != '') {
                     # update an existing device
                     $device->last_seen_by = 'nmis import';
                     $this->m_system->update_system($device);
                     $log_stamp = date('M j H:i:s') . " " . gethostname() . " " . getmypid() . " admin_cli/import_nmis " . $device->ip_address . " (" . $device->hostname . ") - update basic result" . PHP_EOL;
                     file_put_contents("/usr/local/open-audit/other/open-audit.log", $log_stamp, FILE_APPEND | LOCK_EX);
                 } else {
                     # insert a new device
                     $device->last_seen_by = 'nmis import';
                     $i = $this->m_system->insert_system($device);
                     $device->system_id = $i;
                     $log_stamp = date('M j H:i:s') . " " . gethostname() . " " . getmypid() . " admin_cli/import_nmis " . $device->ip_address . " (" . $device->hostname . ") - new basic result" . PHP_EOL;
                     file_put_contents("/usr/local/open-audit/other/open-audit.log", $log_stamp, FILE_APPEND | LOCK_EX);
                 }
             }
             if (isset($device->system_id) and $device->system_id != '') {
                 $this->m_oa_group->update_system_groups($device);
             }
         }
     }
 }
예제 #7
0
function getNoisePerRadio($radioTable, $chanTable)
{
    global $ip, $community;
    foreach ($radioTable as $key => $radioName) {
        $noise = get_snmp(".1.3.6.1.4.1.14179.2.2.15.1.21." . $key . "." . $chanTable[$radioName], "INTEGER");
        $table[$radioName] = $noise;
    }
    return $table;
}
예제 #8
0
 function add_nmap()
 {
     if (!isset($_POST['form_nmap'])) {
         $this->load->view('v_system_add_nmap', $this->data);
     } else {
         $this->load->helper('url');
         $this->load->helper('xml');
         $this->load->library('encrypt');
         if (extension_loaded('snmp')) {
             $this->load->helper('snmp');
             $this->load->helper('snmp_oid');
         }
         $this->load->model("m_system");
         $this->load->model("m_oa_group");
         $this->load->model("m_sys_man_audits");
         $timestamp = date('Y-m-d H:i:s');
         $xml_input = $_POST['form_nmap'];
         try {
             $xml = new SimpleXMLElement($xml_input);
         } catch (Exception $e) {
             # not a valid XML string
             $error_output = "Invalid XML input for NMap import.";
             error_log($error_output);
             exit;
         }
         $count = 0;
         foreach ($xml->children() as $details) {
             $details = (object) $details;
             if (isset($loggedin) or $this->session->userdata('logged_in') == TRUE) {
                 echo "Device IP: " . $details->man_ip_address . "\n";
             }
             $count++;
             $details->last_seen = $timestamp;
             $details->last_user = '';
             $details->timestamp = $timestamp;
             $details->hostname = '';
             $details->hostname = gethostbyaddr($details->man_ip_address);
             $details->hostname = strtolower($details->hostname);
             $details->domain = '';
             if (!filter_var($details->hostname, FILTER_VALIDATE_IP)) {
                 if (strpos($details->hostname, ".") !== FALSE) {
                     # we have a domain returned
                     $details->fqdn = strtolower($details->hostname);
                     $i = explode(".", $details->hostname);
                     $details->hostname = $i[0];
                     unset($i[0]);
                     $details->domain = implode(".", $i);
                 }
             }
             $details->system_key = '';
             $details->system_key = $this->m_system->create_system_key($details);
             $details->system_id = '';
             $details->system_id = $this->m_system->find_system($details);
             if (extension_loaded('snmp')) {
                 # try to get more information using SNMP
                 if (!isset($details->access_details)) {
                     $details->access_details = $this->m_system->get_access_details($details->system_id);
                 }
                 $decoded_access_details = $this->encrypt->decode($details->access_details);
                 $decoded_access_details = json_decode($decoded_access_details);
                 $details->snmp_community = @$decoded_access_details->snmp_community;
                 $details->snmp_version = @$decoded_access_details->snmp_version;
                 $details->snmp_port = @$decoded_access_details->snmp_port;
                 #$details->snmp_community = 'OMKread';
                 #$details->snmp_version = '2c';
                 get_snmp($details);
             }
             if (isset($details->snmp_oid) and $details->snmp_oid > '') {
                 # we received a result from SNMP, use this data to update or insert
                 $details->last_seen_by = 'snmp';
                 if (isset($details->system_id) and $details->system_id != '') {
                     # we have a system_id and snmp details to update
                     $this->m_system->update_system($details);
                 } else {
                     # we have a new system
                     $details->system_id = $this->m_system->insert_system($details);
                 }
             } else {
                 # we received a result from nmap only, use this data to update or insert
                 $details->last_seen_by = 'nmap';
                 if (isset($details->system_id) and $details->system_id != '') {
                     # we have a system id and nmap details to update
                     $this->m_system->update_system($details);
                 } else {
                     # we have a new system
                     $details->system_id = $this->m_system->insert_system($details);
                 }
             }
             $this->m_sys_man_audits->insert_audit($details);
             $this->m_oa_group->update_system_groups($details);
         }
         if (isset($loggedin) or $this->session->userdata('logged_in') == TRUE) {
             echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \r\n\t\t\t\t\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\r\n\t\t\t\t<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"en\" xml:lang=\"en\">";
             echo "<head>\r\n\t\t\t\t<title>Open-AudIT</title>\r\n\t\t\t\t</head>\n\r\n\t\t\t\t<body>\r\n\t\t\t\t<pre>\n";
             echo $count . " systems processed.<br />";
             echo "<a href='" . base_url() . "index.php/system/add_nmap'>Back to input page</a><br />\n";
             echo "<a href='" . base_url() . "index.php'>Front Page</a><br />\n";
         }
     }
 }