示例#1
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');
         }
     }
 }
示例#2
0
                if ($row->$column_variable_name == "") {
                    $row->$column_variable_name = "unknown";
                }
                if ($column_align == '') {
                    $column_align = 'center';
                }
                if ($column->column_name == 'Icon') {
                    echo "\t\t\t<td style=\"text-align: center;\"><img src=\"".str_replace("index.php", "", site_url())."theme-tango/tango-images/16_".strtolower(str_replace(" ", "_", htmlentities($row->$column_variable_name))).".png\" style='border-width:0px;' title=\"".htmlentities($row->$column_variable_name_sec)."\" alt=\"".htmlentities($row->$column_variable_name_sec)."\" /></td>\n";
                }
                if ($column->column_name == 'Picture') {
                    echo "\t\t\t<td style=\"text-align: center;\"><img src=\"".str_replace("index.php", "", site_url())."device_images/".htmlentities($row->$column_variable_name).".jpg\" style='border-width:0px; height:100px' title=\"".htmlentities($row->$column_variable_name_sec)."\" alt=\"".htmlentities($row->$column_variable_name_sec)."\" /></td>\n";
                }
                break;

            case "ip_address":
                echo "\t\t\t<td style=\"text-align: $column_align;\"><span style=\"display: none;\">".htmlentities(str_replace(',', '', ip_address_to_db($row->$column_variable_name)))."&nbsp;</span>".htmlentities(ip_address_from_db($row->$column_variable_name))."</td>\n";
                break;

            case "multi":
                echo "\t\t\t<td style=\"text-align: $column_align;\">".str_replace(",  ", ",<br />", htmlentities($row->$column_variable_name))."</td>\n";
                break;

            case "timestamp":
                echo "\t\t\t<td style=\"text-align: $column_align;\">".htmlentities($row->$column_variable_name)."</td>\n";
                break;

            case "url":
                $href = '';
                if ($column_variable_name_ter > '') {
                    $image = base_url()."theme-tango/tango-images/16_".htmlentities($column_variable_name_ter).".png";
                } else {
	<thead>
		<tr>
			<th><?php echo __('ID')?></th>
			<th><?php echo __('Name')?></th>
			<th><?php echo __('Description')?></th>
			<th><?php echo __('Edited By')?></th>
			<th><?php echo __('Edited Date')?></th>
            <th align='center'><?php echo __('View')?></th>
            <th align='center'><?php echo __('Edit')?></th>
			<!-- <th align='center'><?php echo __('Delete')?></th> -->
		</tr>
	</thead>
	<tbody>
		<?php
        foreach ($this->response->data as $item):
        	$sortable_name = ip_address_to_db(substr($item->name, 0, strpos($item->name, '/')));
        	$sortable_name = str_replace('.', '', $sortable_name);

            $edit_pic = "<a href=\"networks/".intval($item->id)."?action=edit\"><img src='".$oa_theme_images."/16_edit.png' alt='' title='' style='width:16'/></a>";
            $delete_pic = "<a href=\"#\" onclick=\"return confirm('Are you sure?');\" class=\"delete_link\" value=\"".intval($item->id)."\"><img src='".$oa_theme_images."/16_delete.png' alt='' title='' style='width:16' /></a>";
            $delete_pic = "<a href='#' class='delete_link' value='".intval($item->id)."' id='delete_link_".intval($item->id)."' name='delete_link_".intval($item->id)."'><img src='".$oa_theme_images."/16_delete.png' alt='' title='' style='width:16' /></a>";
            ?>
		<tr>
			<td><a style="font-weight:bold;" href="networks/<?php echo intval($item->id)?>"><?php echo intval($item->id)?></td>
			<td><span style="display: none"><?php echo $sortable_name; ?></span><?php echo htmlentities($item->name)?></td>
			<td><?php echo htmlentities($item->description)?></td>
			<td><?php echo htmlentities($item->edited_by)?></td>
			<td><?php echo htmlentities($item->edited_date)?></td>
            <td align='center'><a href="networks/<?php echo intval($item->id)?>"><img src="<?php echo $oa_theme_images; ?>/16_find.png" /></td>
			<td align='center'><?php echo $edit_pic?></td>
			<!-- <td align='center'><?php echo $delete_pic?></td> -->
示例#4
0
 public function process_subnet()
 {
     // accept or process the output of the discover subnet script - nmap details
     if (!isset($_POST['form_details'])) {
         $this->load->view('v_process_subnet', $this->data);
     } else {
         $display = '';
         if ($this->input->post('debug') and strpos($_SERVER['HTTP_ACCEPT'], 'html')) {
             $display = 'y';
             echo "<pre>\n";
             echo "DEBUG - Starting process_subnet.\n";
             echo "***********************************************************************************\n";
             echo "* NOTE - THIS PAGE WILL CONTINUOUSLY RENDER UNTIL THE DISCOVERY HAS FINISHED      *\n";
             echo "* WATCH YOUR BROSWER TO SEE WHEN THE PAGE FINISHES RENDERING                      *\n";
             echo "* DO NOT REFRESH THIS PAGE OR ATTEMPT TO GO 'back' UNTIL THE PAGE HAS COMPLETED   *\n";
             echo "***********************************************************************************\n";
         }
         $this->load->model('m_oa_user');
         $this->load->model('m_scripts');
         if (isset($this->session->userdata['user_id']) and is_numeric($this->session->userdata['user_id'])) {
             $this->user = $this->m_oa_user->get_user_details($this->session->userdata['user_id']);
         }
         // all logging will be as below, only the message will change
         $log_details = new stdClass();
         $log_details->severity = 7;
         $log_details->file = 'system';
         $log_details->display = $display;
         if (!$this->m_oa_config->check_blessed($_SERVER['REMOTE_ADDR'], '')) {
             if ($display == 'y') {
                 $log_details->message = "Audit submission from an IP (" . $_SERVER['REMOTE_ADDR'] . ") not in the list of blessed subnets, exiting.";
                 echo "\n" . $log_details->message . "\n";
                 stdlog($log_details);
             }
             exit;
         }
         $this->load->helper('url');
         $this->load->model('m_credentials');
         if ($display == 'y') {
             echo 'DEBUG - <a href=\'' . base_url() . "index.php/discovery/discover_subnet'>Back to input page</a>\n";
             echo 'DEBUG - <a href=\'' . base_url() . "index.php'>Front Page</a>\n";
         }
         if (php_uname('s') != 'Windows NT') {
             $filepath = $this->config->config['base_path'] . '/other';
         } else {
             $filepath = $this->config->config['base_path'] . '\\other';
         }
         $this->load->helper('xml');
         $xml_input = $_POST['form_details'];
         try {
             $xml = new SimpleXMLElement($xml_input);
         } catch (Exception $error) {
             // not a valid XML string
             $log_details->message = 'Invalid XML input for discovery from ' . $_SERVER['REMOTE_ADDR'];
             stdlog($log_details);
             exit;
         }
         $this->load->helper('url');
         $this->load->library('encrypt');
         $this->load->helper('ipmi');
         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');
         $this->load->model('m_change_log');
         $this->load->model('m_devices_components');
         $this->load->model('m_devices');
         $timestamp = $this->config->config['timestamp'];
         $count = 0;
         foreach ($xml->children() as $details) {
             $details = (object) $details;
             if (isset($details->complete) and $details->complete == 'y') {
                 // delete the credential set
                 if ($display == 'y') {
                     echo "DEBUG - ----------------------------------------------------\n";
                 }
                 $this->echo_details($details);
                 sleep(5);
                 $log_details->message = 'Deleting credential set for ' . $details->subnet_range . ' submitted on ' . $details->subnet_timestamp;
                 stdlog($log_details);
                 $sql = '/* discovery::process_subnet */ DELETE FROM oa_temp WHERE temp_name = \'Subnet Credentials - ' . $details->subnet_range . '\' and temp_timestamp = \'' . $details->subnet_timestamp . '\' ';
                 $query = $this->db->query($sql);
             } else {
                 $skip = false;
                 if (stripos(' ' . $this->config->config['discovery_ip_exclude'] . ' ', ' ' . $details->ip . ' ') !== false) {
                     # Our ip address matched an ip in the discovery_ip_exclude list - exit
                     $log_details->message = $details->ip . ' is in the list of excluded ip addresses - skipping.';
                     stdlog($log_details);
                     $skip = true;
                 }
                 if (!$skip) {
                     $log_details->message = 'Start processing ' . $details->ip;
                     stdlog($log_details);
                     $count++;
                     $details->last_seen = $timestamp;
                     $details->last_user = '';
                     $details->last_seen_by = 'nmap';
                     $details->domain = '';
                     $details->audits_ip = ip_address_to_db($_SERVER['REMOTE_ADDR']);
                     $details->hostname = '';
                     if ($this->config->item('discovery_use_dns') == 'y') {
                         $details = dns_validate($details, $display);
                     }
                     $details->id = '';
                     $details->id = $this->m_system->find_system($details);
                     $details->last_seen_user = '';
                     $details->network_address = '';
                     $details->limit = 1000000;
                     $details->count = 0;
                     $details->use_https = '';
                     // # 1.12.6
                     $credentials = array();
                     // If we find a device and we're in DEBUG, output a result line.
                     if ($display == 'y') {
                         if (!empty($details->id)) {
                             echo 'DEBUG - Device found with ID: <a href=\'' . base_url() . 'index.php/main/system_display/' . $details->id . '\'>' . $details->id . "</a>.\n";
                         }
                     }
                     // Device specific credentials
                     if (!empty($details->id)) {
                         $temp = $this->m_devices_components->read(intval($details->id), 'y', 'credential', '', '*');
                         if (count($temp) > 0) {
                             foreach ($temp as $credential) {
                                 $credentials[] = $credential;
                             }
                         }
                         unset($temp);
                     }
                     // Credential Sets
                     $temp = $this->m_credentials->collection();
                     if (count($temp) > 0) {
                         $credentials = array_merge($credentials, $temp);
                     }
                     unset($temp);
                     // supplied credentials
                     $sql = '/* discovery::process_subnet */ SELECT temp_value FROM oa_temp WHERE temp_name = \'Subnet Credentials - ' . $details->subnet_range . '\' and temp_timestamp = \'' . $details->subnet_timestamp . '\' ORDER BY temp_id DESC LIMIT 1';
                     $query = $this->db->query($sql);
                     $row = $query->row();
                     $supplied_credentials = @$row->temp_value;
                     $supplied = new stdClass();
                     if (isset($supplied_credentials) and $supplied_credentials > '') {
                         $supplied_credentials = $this->encrypt->decode($supplied_credentials);
                         $supplied_credentials = json_decode($supplied_credentials);
                         $details->last_seen_user = @$supplied_credentials->last_user;
                         $details->network_address = @$supplied_credentials->network_address;
                         $details->limit = (int) @$supplied_credentials->limit;
                         $details->count = (int) @$supplied_credentials->count;
                         $details->org_id = (int) @$supplied_credentials->org;
                         $details->location_id = (int) @$supplied_credentials->location;
                         $details->org_id = (int) @$supplied_credentials->org;
                         $details->location_id = (int) @$supplied_credentials->location;
                         $details->use_https = (string) @$supplied_credentials->use_https;
                     }
                     # TODO - replace the ugly code below
                     $creds = array();
                     foreach ($credentials as $credential) {
                         $creds[] = $credential->attributes;
                     }
                     unset($credentials);
                     $credentials = $creds;
                     unset($creds);
                     // default Open-AudIT credentials
                     // $default = $this->m_oa_config->get_credentials();
                     // unset($default);
                     if (intval($details->count) >= intval($details->limit)) {
                         # we have discovered the requested number of devcies
                         $log_details->message = 'Count from DB is higher than requested limit, exiting. Count: ' . $details->count . ' Limit: ' . $details->limit;
                         stdlog($log_details);
                         return;
                     }
                     if (empty($supplied_credentials)) {
                         $supplied_credentials = new stdClass();
                     }
                     if (empty($supplied_credentials->count)) {
                         $supplied_credentials->count = 0;
                     } else {
                         $supplied_credentials->count++;
                     }
                     $sql = '/* discovery::process_subnet */ UPDATE oa_temp SET temp_value = ? WHERE temp_name = \'Subnet Credentials - ' . $details->subnet_range . '\' and temp_timestamp = \'' . $details->subnet_timestamp . '\'';
                     $data_in = json_encode($supplied_credentials);
                     $data_in = $this->encrypt->encode($data_in);
                     $data = array("{$data_in}");
                     $query = $this->db->query($sql, $data);
                     $details->last_user = $details->last_seen_user;
                     $log_details->user = $details->last_seen_user;
                     // create the URL for use by the audit scripts
                     # use $_POST if supplied
                     if (isset($_POST['network_address']) and $_POST['network_address'] > '') {
                         $temp = explode('/', base_url());
                         $url = str_replace($temp[2], $_POST['network_address'], base_url());
                         # use $details->network_address if stored in DB
                     } elseif (isset($details->network_address) and $details->network_address != '') {
                         $temp = explode('/', base_url());
                         $url = str_replace($temp[2], $details->network_address, base_url());
                         # use the open-audit default config value
                     } elseif (isset($this->config->config['default_network_address']) and $this->config->config['default_network_address'] > '') {
                         $temp = explode('/', base_url());
                         $url = str_replace($temp[2], $this->config->config['default_network_address'], base_url());
                         # use the PHP function to guess as a last resort
                     } else {
                         $url = base_url();
                     }
                     unset($details->network_address);
                     if ($details->use_https == 'on') {
                         $url = str_ireplace('http://', 'https://', $url);
                     }
                     if (isset($supplied->snmp_community) and $supplied->snmp_community != '') {
                         $details->snmp_community = $supplied->snmp_community;
                     }
                     // output to log file and DEBUG the status of the three main services
                     $log_details->message = 'WMI Status is ' . $details->wmi_status . ' on ' . $details->ip;
                     stdlog($log_details);
                     // On OSX we cannot run Nmap and get a UDP port result for 161 as 'You requested a scan type which requires root privileges.' So just set the snmp_status to true and attempt to snmp_audit the target device
                     if (php_uname('s') == 'Darwin') {
                         $details->snmp_status = 'true';
                         $details->nmap_ports .= ',161/udp/snmp';
                     }
                     $log_details->message = 'SNMP Status is ' . $details->snmp_status . ' on ' . $details->ip;
                     stdlog($log_details);
                     $log_details->message = 'SSH Status is ' . $details->ssh_status . ' on ' . $details->ip;
                     stdlog($log_details);
                     // get rid of os_* as nmap only guesses
                     unset($details->os_group);
                     unset($details->os_family);
                     unset($details->os_name);
                     # IPMI audit
                     # TODO - make a ipmi_helper::ipmi_credentials function
                     // if (isset($this->config->config['discovery_use_ipmi']) and $this->config->config['discovery_use_ipmi'] == 'y') {
                     //     $credentials_ipmi = new stdClass();
                     //     $credentials_ipmi->type = 'ipmi';
                     //     $credentials_ipmi->credentials = new stdClass();
                     //     $credentials_ipmi->credentials->username = $this->config->config['default_ipmi_username'];
                     //     $credentials_ipmi->credentials->password = $this->config->config['default_ipmi_username'];
                     //     $credentials[] = $credentials_ipmi;
                     //     $ipmi_details = ipmi_audit($details->ip, $credentials_ipmi, $display);
                     //     if (!empty($ipmi_details)) {
                     //         foreach ($ipmi_details as $key => $value) {
                     //             if (!empty($value)) {
                     //                 $details->key = $value;
                     //             }
                     //         }
                     //     }
                     //     if ($details->serial) {
                     //         $details->last_seen_by = 'ipmi';
                     //         $details->audits_ip = '127.0.0.1';
                     //     }
                     // }
                     // SNMP audit
                     if (!extension_loaded('snmp') and $details->snmp_status == 'true') {
                         $log_details->message = 'PHP extension not loaded, skipping SNMP data retrieval for ' . $details->ip;
                         stdlog($log_details);
                     }
                     if (extension_loaded('snmp') and $details->snmp_status == 'true') {
                         $log_details->message = 'Testing SNMP credentials for ' . $details->ip;
                         stdlog($log_details);
                         $credentials_snmp = snmp_credentials($details->ip, $credentials, $display);
                     } else {
                         $credentials_snmp = false;
                     }
                     if ($credentials_snmp) {
                         $temp_array = snmp_audit($details->ip, $credentials_snmp, $display);
                         if (!empty($temp_array['details'])) {
                             foreach ($temp_array['details'] as $key => $value) {
                                 if (!empty($value)) {
                                     $details->{$key} = $value;
                                 }
                             }
                             $details->last_seen_by = 'snmp';
                             $details->audits_ip = '127.0.0.1';
                         }
                         if (!empty($temp_array['interfaces'])) {
                             $network_interfaces = $temp_array['interfaces'];
                         }
                         if (!empty($temp_array['modules'])) {
                             $modules = $temp_array['modules'];
                         }
                         if (!empty($temp_array['ip'])) {
                             $ip = $temp_array['ip'];
                         }
                         if (!empty($temp_array['guests'])) {
                             $guests = $temp_array['guests'];
                         }
                     }
                     // new for 1.8.4 - if we have a non-computer, do not attempt to connect using SSH
                     if ($details->type != 'computer' and $details->type != '' and $details->type != 'unknown' and $details->os_family != 'DD-WRT' and stripos($details->sysDescr, 'dd-wrt') === false) {
                         $log_details->message = 'Not a computer and not a DD-WRT device, setting SSH status to false for ' . $details->ip . ' (System ID ' . $details->id . ')';
                         stdlog($log_details);
                         $details->ssh_status = 'false';
                     }
                     # test for working SSH credentials
                     if ($details->ssh_status == 'true') {
                         $log_details->message = 'Testing SSH credentials for ' . $details->ip;
                         stdlog($log_details);
                         $credentials_ssh = ssh_credentials($details->ip, $credentials, $display);
                     } else {
                         $credentials_ssh = false;
                     }
                     # run SSH audit commands
                     if ($details->ssh_status == 'true' and $credentials_ssh) {
                         $ssh_details = ssh_audit($details->ip, $credentials_ssh, $display);
                         if (!empty($ssh_details)) {
                             $details->last_seen_by = 'ssh';
                             $details->audits_ip = '127.0.0.1';
                             foreach ($ssh_details as $key => $value) {
                                 if (!empty($value)) {
                                     $details->{$key} = $value;
                                 }
                             }
                         }
                     }
                     // test for working Windows credentials
                     if ($details->wmi_status == 'true') {
                         $log_details->message = 'Testing Windows credentials for ' . $details->ip;
                         stdlog($log_details);
                         $credentials_windows = windows_credentials($details->ip, $credentials, $display);
                     } else {
                         $credentials_windows = false;
                     }
                     # run Windows audit commands
                     if ($details->wmi_status == 'true' and $credentials_windows) {
                         $windows_details = wmi_audit($details->ip, $credentials_windows, $display);
                         if (!empty($windows_details)) {
                             $details->last_seen_by = 'windows';
                             $details->audits_ip = '127.0.0.1';
                             foreach ($windows_details as $key => $value) {
                                 if (!empty($value)) {
                                     $details->{$key} = $value;
                                 }
                             }
                         }
                     }
                     # in the case where port 5060 is detected and we have no other information, assign type 'voip phone'
                     if (empty($details->type) and empty($details->snmp_oid) and empty($details->uuid) and stripos($details->nmap_result, '5060/') !== false) {
                         $details->type = 'voip phone';
                     }
                     if ($this->config->item('discovery_use_dns') == 'y') {
                         $details = dns_validate($details, $display);
                     }
                     $details->id = $this->m_system->find_system($details, $display);
                     if ($display == 'y') {
                         $details->show_output = true;
                         echo "=======DETAILS======\n";
                         foreach ($details as $key => $value) {
                             echo "DEBUG - " . $key . ": " . (string) $value . "\n";
                         }
                         echo "====================\n";
                         ob_flush();
                         flush();
                     }
                     // insert or update the device
                     if (isset($details->id) and $details->id != '') {
                         // we have a system id - UPDATE
                         $log_details->message = strtoupper($details->last_seen_by) . " update for {$details->ip} (System ID {$details->id})";
                         stdlog($log_details);
                         $details->original_last_seen = $this->m_devices_components->read($details->id, 'y', 'system', '', 'last_seen');
                         $details->original_last_seen_by = $this->m_devices_components->read($details->id, 'y', 'system', '', 'last_seen_by');
                         $this->m_system->update_system($details, $display);
                     } else {
                         // we have a new system - INSERT
                         $log_details->message = strtoupper($details->last_seen_by) . " insert for {$details->ip}";
                         stdlog($log_details);
                         $details->id = $this->m_system->insert_system($details, $display);
                     }
                     // grab some timestamps
                     $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');
                     // Insert an audit log
                     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 the groups
                     if ($this->config->config['discovery_update_groups'] == 'y') {
                         $this->m_oa_group->update_system_groups($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, $display);
                     }
                     // insert any ip addresses
                     if (isset($ip->item) and count($ip->item) > 0) {
                         $this->m_devices_components->process_component('ip', $details, $ip, $display);
                     }
                     // finish off with updating any network IPs that don't have a matching interface
                     $this->m_devices_components->update_missing_interfaces($details->id);
                     // insert any modules
                     if (isset($modules) and count($modules) > 0) {
                         $input = new stdClass();
                         $input->item = array();
                         $input->item = $modules;
                         $this->m_devices_components->process_component('module', $details, $input, $display);
                     }
                     // insert any found virtual machines
                     if (isset($guests) and is_array($guests) and count($guests) > 0) {
                         $vm = new stdClass();
                         $vm->item = array();
                         $vm->item = $guests;
                         $this->m_devices_components->process_component('vm', $details, $vm, $display);
                     }
                     if (!empty($credentials_snmp) and $details->snmp_status == 'true') {
                         $log_details->message = 'SNMP credential update for ' . $details->ip . ' (System ID ' . $details->id . ')';
                         stdlog($log_details);
                         $this->m_devices->sub_resource_create($details->id, 'credential', $credentials_snmp);
                     }
                     if (!empty($credentials_ssh) and $details->ssh_status == 'true') {
                         $log_details->message = 'SSH credential update for ' . $details->ip . ' (System ID ' . $details->id . ')';
                         stdlog($log_details);
                         $this->m_devices->sub_resource_create($details->id, 'credential', $credentials_ssh);
                     }
                     if (isset($credentials_windows) and $details->wmi_status == 'true') {
                         $log_details->message = "Windows credential update for {$details->ip} (System ID {$details->id})";
                         stdlog($log_details);
                         $this->m_devices->sub_resource_create($details->id, 'credential', $credentials_windows);
                     }
                     // $details->id is now set
                     if ($display == 'y') {
                         echo "DEBUG - System ID <a href='" . base_url() . "index.php/devices/" . $details->id . "'>" . $details->id . "</a>\n";
                     }
                     // process and store the Nmap result
                     $nmap_result = array();
                     foreach (explode(',', $details->nmap_ports) as $port) {
                         $temp = explode('/', $port);
                         $nmap_item = new stdClass();
                         $nmap_item->ip = (string) $details->ip;
                         $nmap_item->port = $temp[0];
                         $nmap_item->protocol = $temp[1];
                         $nmap_item->program = $temp[2];
                         if ($nmap_item->port != '') {
                             $nmap_result[] = $nmap_item;
                         }
                         unset($nmap_item);
                         unset($temp);
                     }
                     if (count($nmap_result) > 0) {
                         $input = new stdClass();
                         $input->item = array();
                         $input->item = $nmap_result;
                         $this->m_devices_components->process_component('nmap', $details, $input, $display);
                     }
                     // insert a blank to indicate we're finished this part of the discovery
                     // if required, the audit scripts will insert their own audit logs
                     $this->m_audit_log->update('debug', '', $details->id, $details->last_seen);
                     # Audit Windows
                     if ($details->wmi_status == "true" and $credentials_windows) {
                         $log_details->message = "Starting windows audit for {$details->ip} (System ID {$details->id})";
                         stdlog($log_details);
                         $share = '\\admin$';
                         $destination = 'audit_windows.vbs';
                         if ($display = 'y') {
                             $debugging = 3;
                         } else {
                             $debugging = 0;
                         }
                         $sql = "/* discovery::process_subnet */ SELECT * FROM `scripts` WHERE `name` = 'audit_windows.vbs' AND `based_on` = 'audit_windows.vbs' ORDER BY `id` LIMIT 1";
                         $query = $this->db->query($sql);
                         $result = $query->result();
                         if (!empty($result[0])) {
                             $script_details = $result[0];
                             # Just ensure we delete any audit scripts that might exist.
                             # Shouldn't be required because we're creating based on the timestamp
                             # Then open the file for writing
                             $ts = date('y_m_d_H_i_s');
                             if (php_uname('s') == 'Windows NT') {
                                 $source_name = 'scripts\\audit_windows_' . $ts . '.vbs';
                                 @unlink($this->config->config['base_path'] . '\\other\\' . $source_name);
                                 try {
                                     $fp = fopen($this->config->config['base_path'] . '\\other\\' . $source_name, 'w');
                                 } catch (Exception $e) {
                                     print_r($e);
                                 }
                             } else {
                                 $source_name = 'scripts/audit_windows_' . $ts . '.vbs';
                                 @unlink($this->config->config['base_path'] . '/other/' . $source_name);
                                 try {
                                     $fp = fopen($this->config->config['base_path'] . '/other/' . $source_name, 'w');
                                 } catch (Exception $e) {
                                     print_r($e);
                                 }
                             }
                             $script = $this->m_scripts->download($script_details->id);
                             fwrite($fp, $script);
                             fclose($fp);
                         } else {
                             $source_name = 'audit_windows.vbs';
                         }
                         if (php_uname('s') != 'Windows NT') {
                             $source = $this->config->config['base_path'] . '/other/' . $source_name;
                             $command = "cscript c:\\windows\\audit_windows.vbs submit_online=y create_file=n strcomputer=. url=" . $url . "index.php/system/add_system debugging=" . $debugging . " system_id=" . $details->id . " last_seen_by=audit_wmi";
                             if (copy_to_windows($details->ip, $credentials_windows, $share, $source, $destination, $display)) {
                                 if (execute_windows($details->ip, $credentials_windows, $command, $display)) {
                                     # All complete!
                                 } else {
                                     # run audit script failed
                                 }
                             } else {
                                 # copy audit script to Windows failed
                             }
                             if ($source_name != 'audit_windows.vbs') {
                                 unlink($this->config->config['base_path'] . '/other/' . $source_name);
                             }
                         } else {
                             #if (strtolower($_SERVER['USERPROFILE']) == 'c:\windows\system32\config\systemprofile') {
                             if (exec('whoami') == 'nt authority\\system') {
                                 # We're running on the LocalSystem account.
                                 # We cannot copy the audit script to the target and then run it,
                                 # We _must_ run the script locally and use $details->ip as the script target
                                 # We will loose the ability to retrieve certain items like files, netstat, tasks, etc
                                 $log_details->message = "Windows audit for {$details->ip} (System ID {$details->id})";
                                 stdlog($log_details);
                                 $username = $credentials_windows->credentials->username;
                                 $temp = explode('@', $username);
                                 $username = $temp[0];
                                 if (count($temp) > 1) {
                                     $domain = $temp[1] . '\\';
                                 } else {
                                     $domain = '';
                                 }
                                 unset($temp);
                                 if ($display == 'y') {
                                     $script_string = "{$filepath}\\" . $source_name . " strcomputer=" . $details->ip . " submit_online=y create_file=n struser="******" strpass="******" url=" . $url . "index.php/system/add_system debugging=3 system_id=" . $details->id . " last_seen_by=audit_wmi";
                                     $command_string = "%comspec% /c start /b cscript //nologo " . $script_string;
                                     exec($command_string, $output, $return_var);
                                     $command_string = str_replace($credentials_windows->credentials->password, '******', $command_string);
                                     echo 'DEBUG - Command Executed: ' . $command_string . "\n";
                                     echo 'DEBUG - Return Value: ' . $return_var . "\n";
                                     echo "DEBUG - Command Output:\n";
                                     print_r($output);
                                     if ($return_var != '0') {
                                         $error = "Attempt to run audit_windows.vbs on {$details->ip} has failed";
                                         $log_details->message = $error;
                                         stdlog($log_details);
                                     } else {
                                         $log_details->message = "Attempt to run audit_windows.vbs on {$details->ip} has succeeded";
                                         stdlog($log_details);
                                     }
                                     $output = null;
                                     $return_var = null;
                                 } else {
                                     $script_string = "{$filepath}\\" . $source_name . " strcomputer=" . $details->ip . " submit_online=y create_file=n struser="******" strpass="******" url=" . $url . "index.php/system/add_system debugging=0  system_id=" . $details->id . " last_seen_by=audit_wmi";
                                     $command_string = "%comspec% /c start /b cscript //nologo " . $script_string . " &";
                                     pclose(popen($command_string, "r"));
                                 }
                                 $command_string = null;
                                 if ($source_name != 'audit_windows.vbs') {
                                     unlink($this->config->config['base_path'] . '/other/' . $source_name);
                                 }
                             } else {
                                 # We are running as something other than the LocalSystem account.
                                 # Therefore we _should_ be able to copy the audit script to tthe target and start it there
                                 # and therefore retrieve ALL information
                                 $source = $this->config->config['base_path'] . '\\other\\' . $source_name;
                                 rename($source, 'c:\\windows\\audit_windows_' . $ts . '.vbs');
                                 $source = 'audit_windows_' . $ts . '.vbs';
                                 $command = "cscript \\\\" . $details->ip . "\\admin\$\\audit_windows_" . $ts . ".vbs submit_online=y create_file=n strcomputer=. url=" . $url . "index.php/system/add_system debugging=" . $debugging . " system_id=" . $details->id . " self_delete=y last_seen_by=audit_wmi";
                                 if (copy_to_windows($details->ip, $credentials_windows, $share, $source, $destination, $display)) {
                                     if (execute_windows($details->ip, $credentials_windows, $command, $display)) {
                                         # All complete!
                                     } else {
                                         # run audit script failed
                                     }
                                 } else {
                                     # copy audit script to Windows failed
                                 }
                                 if ($source_name != 'audit_windows.vbs') {
                                     unlink('c:\\windows\\audit_windows_' . $ts . '.vbs');
                                 }
                             }
                         }
                     }
                     # Audit SSH
                     if ($details->ssh_status == "true" and $details->os_family != 'DD-WRT' and $credentials_ssh) {
                         $log_details->message = "Starting ssh audit for {$details->ip} (System ID {$details->id})";
                         stdlog($log_details);
                         // $command = 'uname';
                         // $ssh_result = ssh_command($details->ip, $credentials_ssh, $command, $display);
                         // if ($ssh_result['status'] == 0) {
                         //     $remote_os = $ssh_result['output'][0];
                         // }
                         // switch (strtolower($remote_os)) {
                         switch (strtolower($details->os_group)) {
                             case 'aix':
                                 $audit_script = 'audit_aix.sh';
                                 break;
                             case 'vmkernel':
                                 $audit_script = 'audit_esxi.sh';
                                 break;
                             case 'linux':
                                 $audit_script = 'audit_linux.sh';
                                 break;
                             case 'darwin':
                                 $audit_script = 'audit_osx.sh';
                                 break;
                             case 'windows':
                                 $audit_script = '';
                                 break;
                             default:
                                 $audit_script = '';
                                 break;
                         }
                         $destination = $audit_script;
                         if ($display = 'y') {
                             $debugging = 3;
                         } else {
                             $debugging = 0;
                         }
                         $sql = "/* discovery::process_subnet */ SELECT * FROM `scripts` WHERE `name` = '{$audit_script}' AND `based_on` = '{$audit_script}' ORDER BY `id` LIMIT 1";
                         $query = $this->db->query($sql);
                         $result = $query->result();
                         if (!empty($result[0])) {
                             $script_details = $result[0];
                             # Just ensure we delete any audit scripts that might exist.
                             # Shouldn't be required because we're creating based on the timestamp
                             # Then open the file for writing
                             $ts = date('y_m_d_H_i_s');
                             if (php_uname('s') == 'Windows NT') {
                                 $source_name = 'scripts\\' . str_replace('.sh', '_' . $ts . '.sh', $audit_script);
                                 $unlink = $this->config->config['base_path'] . '\\other\\' . $source_name;
                                 @unlink($unlink);
                                 $fp = fopen($this->config->config['base_path'] . '\\other\\' . $source_name, 'w');
                             } else {
                                 $source_name = 'scripts/' . str_replace('.sh', '_' . $ts . '.sh', $audit_script);
                                 $unlink = $this->config->config['base_path'] . '/other/' . $source_name;
                                 @unlink($unlink);
                                 try {
                                     $fp = fopen($this->config->config['base_path'] . '/other/' . $source_name, 'w');
                                 } catch (Exception $e) {
                                     print_r($e);
                                 }
                             }
                             $script = $this->m_scripts->download($script_details->id);
                             fwrite($fp, $script);
                             fclose($fp);
                         } else {
                             $unlink = '';
                             $source_name = $audit_script;
                         }
                         unset($temp);
                         if ($audit_script != '') {
                             # copy the audit script to the target ip
                             if (php_uname('s') == 'Windows NT') {
                                 $source = $filepath . '\\' . $source_name;
                             } else {
                                 $source = $filepath . '/' . $source_name;
                             }
                             $destination = $this->config->item('discovery_linux_script_directory');
                             if (substr($destination, -1) != '/') {
                                 $destination .= '/';
                             }
                             $destination .= $audit_script;
                             if ($ssh_result = scp($details->ip, $credentials_ssh, $source, $destination, $display)) {
                                 # Successfully copied the audit script
                                 $command = 'chmod ' . $this->config->item('discovery_linux_script_permissions') . ' ' . $destination;
                                 $temp = ssh_command($details->ip, $credentials_ssh, $command, $display);
                             }
                             if ($display = 'y') {
                                 $debugging = 3;
                             } else {
                                 $debugging = 0;
                             }
                         }
                         # audit anything that's not ESX
                         if ($audit_script != 'audit_esxi.sh' and $audit_script != '') {
                             # successfully copied and chmodded the audit script
                             if (!empty($credentials_ssh->sudo)) {
                                 # run the audit script as a normal user, using sudo
                                 $command = 'echo "' . $credentials_ssh->credentials->password . '" | ' . $credentials_ssh->sudo . ' -S ' . $this->config->item('discovery_linux_script_directory') . $audit_script . ' submit_online=y create_file=n url=' . $url . 'index.php/system/add_system debugging=' . $debugging . ' system_id=' . $details->id . ' display=' . $display . ' last_seen_by=audit_ssh';
                             } else {
                                 # run the script without using sudo
                                 $command = $this->config->item('discovery_linux_script_directory') . $audit_script . ' submit_online=y create_file=n url=' . $url . 'index.php/system/add_system debugging=' . $debugging . ' system_id=' . $details->id . ' display=' . $display . ' last_seen_by=audit_ssh';
                             }
                             $result = ssh_command($details->ip, $credentials_ssh, $command, $display);
                             if ($unlink != '') {
                                 unlink($unlink);
                             }
                         }
                         # audit ESX
                         if ($audit_script == 'audit_esxi.sh') {
                             $command = $this->config->item('discovery_linux_script_directory') . $audit_script . ' submit_online=y last_seen_by=audit_ssh create_file=n debugging=0 echo_output=y system_id=' . $details->id . ' 2>/dev/null';
                             if ($result = ssh_command($details->ip, $credentials_ssh, $command, $display)) {
                                 if ($result['status'] == 0) {
                                     $script_result = '';
                                     foreach ($result['output'] as $line) {
                                         $script_result .= $line . "\n";
                                     }
                                     $script_result = preg_replace('/\\s+/', ' ', $script_result);
                                     $script_result = str_replace("> <", "><", $script_result);
                                     $esx_input = trim($script_result);
                                     try {
                                         $esx_xml = new SimpleXMLElement($esx_input);
                                     } catch (Exception $error) {
                                         // not a valid XML string
                                         $log_details->message = 'Invalid XML input for ESX audit script';
                                         stdlog($log_details);
                                         exit;
                                     }
                                     $count = 0;
                                     foreach ($esx_xml->children() as $child) {
                                         if ($child->getName() === 'sys') {
                                             $esx_details = (object) $esx_xml->sys;
                                             if (!isset($esx_details->ip) or $esx_details->ip == '') {
                                                 $esx_details->ip = $details->ip;
                                             }
                                             $esx_details->system_id = $this->m_system->find_system($esx_details, $display);
                                             $esx_details->last_seen = $details->last_seen;
                                             if (isset($esx_details->system_id) and $esx_details->system_id != '') {
                                                 // we have an existing device
                                                 $esx_details->original_last_seen_by = $this->m_devices_components->read($esx_details->system_id, 'y', 'system', '', 'last_seen_by');
                                                 $esx_details->original_last_seen = $this->m_devices_components->read($esx_details->system_id, 'y', 'system', '', 'last_seen');
                                                 $this->m_system->update_system($esx_details);
                                                 $log_details->message = "ESX update for {$esx_details->ip} (System ID {$esx_details->system_id})";
                                                 stdlog($log_details);
                                             } else {
                                                 // we have a new system
                                                 $esx_details->system_id = $this->m_system->insert_system($esx_details);
                                                 $log_details->message = "ESX insert for {$esx_details->ip} (System ID {$esx_details->system_id})";
                                                 stdlog($log_details);
                                             }
                                             if (!isset($esx_details->audits_ip)) {
                                                 $esx_details->audits_ip = $details->audits_ip;
                                             }
                                             if (isset($this->user->full_name)) {
                                                 $temp_user = $this->user->full_name;
                                             } else {
                                                 $temp_user = '';
                                             }
                                             $this->m_audit_log->create($esx_details->system_id, $temp_user, $esx_details->last_seen_by, $esx_details->audits_ip, '', '', $esx_details->last_seen);
                                             unset($temp_user);
                                         }
                                     }
                                     $this->m_devices_components->process_component('network', $esx_details, $esx_xml->network, $display);
                                     $this->m_devices_components->process_component('software', $esx_details, $esx_xml->software, $display);
                                     $this->m_devices_components->process_component('processor', $esx_details, $esx_xml->processor, $display);
                                     $this->m_devices_components->process_component('bios', $esx_details, $esx_xml->bios, $display);
                                     $this->m_devices_components->process_component('memory', $esx_details, $esx_xml->memory, $display);
                                     $this->m_devices_components->process_component('motherboard', $esx_details, $esx_xml->motherboard, $display);
                                     $this->m_devices_components->process_component('video', $esx_details, $esx_xml->video, $display);
                                     $this->m_devices_components->process_component('vm', $esx_details, $esx_xml->vm, $display);
                                     $this->m_devices_components->process_component('ip', $esx_details, $esx_xml->ip, $display);
                                 }
                             }
                         }
                         $log_details->message = "Completed processing {$details->ip} (System ID {$details->id})";
                         stdlog($log_details);
                     }
                     // close the 'skip'
                 }
                 // close the device / complete switch
                 unset($details);
             }
             // close for each device in XML
         }
         // close for form submission
     }
     // close function
 }
示例#5
0
    /**
    * Insert a new device into the system table using whatever values we have and insert corresponding rows into the sys_edit_log table
    *
    * @param array $details the array of attributes from the system table
    * @access  public
    *
    * @return string $id which is the id of the device in the system table
    */
    public function create(&$details)
    {
        # nasty hack because when a simplexmlobject is sent (ie, from audit_windows.vbs)
        # the foreach iterators below don't work.
        # if we cast it to an "object", it stays as a SimpleXMLObject and doesn't work
        # because our XML is quite simple, we can cast it to an array and back to a 'normal'
        # object and the foreach below works.
        $details = (object) $details;
        $details = (array) $details;
        $details = (object) $details;
        # this is an insert - we do NOT want a system.id
        unset($details->id);

        // get a name we can use
        if (!empty($details->name)) {
            $name = $details->name;
        } elseif (!empty($details->hostname)) {
            $name = $details->hostname;
            $details->name = $details->hostname;
        } elseif (!empty($details->sysName)) {
            $name = $details->sysName;
            $details->name = $details->sysName;
        } elseif (!empty($details->dns_hostname)) {
            $name = $details->dns_hostname;
            $details->name = $details->dns_hostname;
        }

        if (!isset($details->ip)) {
            $details->ip = '';
        }

        $log_details = new stdClass();
        $log_details->message = 'System insert start for '.ip_address_from_db($details->ip).' ('.$name.')';
        $log_details->severity = 7;
        $log_details->file = 'system';
        stdlog($log_details);

        # remove some characters from the OS string
        if ( ! empty($details->os_name)) {
            $details->os_name = str_ireplace("(r)", "", $details->os_name);
            $details->os_name = str_ireplace("(tm)", "", $details->os_name);
        }


        if (empty($details->status)) {
            $details->status = 'production';
        }
        if (empty($details->type)) {
            $details->type = 'unknown';
        } else {
            $details->type = strtolower($details->type);
        }
        if (empty($details->environment)) {
            $details->environment = 'production';
        }

        # we now set a default location - 0 the location_id
        if (!isset($details->location_id)) {
            $details->location_id = '0';
        }

        # Set the form factor to virtual if required
        if ( ! empty($details->manufacturer)) {
            if ((strripos($details->manufacturer, "vmware") !== false) or
                (strripos($details->manufacturer, "parallels") !== false) or
                (strripos($details->manufacturer, "virtual") !== false)) {
                if (!isset($details->class) or $details->class != 'hypervisor') {
                    $details->form_factor = 'Virtual';
                }
            }
        }
        if ( ! empty($details->model)) {
            if (strripos($details->model, "bhyve") !== false) {
                if (!isset($details->class) or $details->class != 'hypervisor') {
                    $details->form_factor = 'Virtual';
                }
            }
        }

        # Pad the IP address
        if ( ! empty($details->ip)) {
            $details->ip = ip_address_to_db($details->ip);
        }

        if ( ! empty($details->hostname) and  ! empty($details->domain) and empty($details->fqdn)) {
            $details->fqdn = $details->hostname.".".$details->domain;
        }

        $sql = "SHOW COLUMNS FROM system";
        $query = $this->db->query($sql);
        $columns = $query->result();

        $sql = "INSERT INTO system ( ";
        foreach ($details as $key => $value) {
            if ($key > '') {
                # need to iterate through available columns and only insert where $key == valid column name
                foreach ($columns as $column) {
                    if ($key == $column->Field) {
                        $sql .= $key.", ";
                    }
                }
            }
        }
        $sql = mb_substr($sql, 0, mb_strlen($sql)-2);
        $sql .= " ) VALUES ( ";
        foreach ($details as $key => $value) {
            if ($key > '') {
                foreach ($columns as $column) {
                    if ($key == $column->Field) {
                        $sql .= "'".mysqli_real_escape_string($this->db->conn_id, str_replace('"', '', $value))."', ";
                    }
                }
            }
        }
        $sql = mb_substr($sql, 0, mb_strlen($sql)-2);
        $sql .= ")";

        $query = $this->db->query($sql);
        $details->id = $this->db->insert_id();

        // set the weight for these $details
        $weight = $this->weight($details->last_seen_by);

        // insert entries into the edit_log table for these $details columns
        foreach ($details as $key => $value) {
            if ($key > '') {
                foreach ($columns as $column) {
                    if ($key == $column->Field) {
                        $sql = "INSERT INTO edit_log VALUES (NULL, 0, ?, '', ?, ?, 'system', ?, ?, ?, ?)";
                        $data = array("$details->id", "$details->last_seen_by", "$weight", "$key", "$details->last_seen", "$value", "");
                        $query = $this->db->query($sql, $data);
                    }
                }
            }
        }

        # update the device icon
        $this->reset_icons($details->id);

        # insert a subnet so we have a default
        if (!isset($details->subnet) or $details->subnet == '') {
            $details->subnet = '0.0.0.0';
        }

        $log_details->message = 'System insert end for '.ip_address_from_db($details->ip).' ('.$name.') (System ID '.$details->id.')';
        stdlog($log_details);
        unset($log_details);
        return $details->id;
    }
示例#6
0
 function update_system($details)
 {
     if (!isset($details->system_id) or $details->system_id == '') {
         # this is an update - we need a system_id
         return;
     }
     # nasty hack because when a simplexmlobject is sent (ie, from audit_windows.vbs)
     # the foreach iterators below don't work.
     # if we cast it to an "object", it stays as a SimpleXMLObject and doesn't work
     # because our XML is quite simple, we can cast it to an array and back to a 'normal'
     # object and the foreach below works.
     $details = (object) $details;
     $details = (array) $details;
     $details = (object) $details;
     # if we're updating and we don't have a real hostname, only the ip address
     # stored in the hostname field, we shouldn't update it
     if (isset($details->hostname) and strpos($details->hostname, ".")) {
         $sql = "SELECT hostname FROM system WHERE system_id = ?";
         $data = array("{$details->system_id}");
         $query = $this->db->query($sql, $data);
         $result = $query->row();
         $db_hostname = $result->hostname;
         if (!strpos($db_hostname, ".")) {
             $details->hostname = $db_hostname;
         }
     }
     if (!isset($details->system_key_type)) {
         $details->system_key_type = '';
     }
     # we have to try to get the 'best' system key
     # the key in the db may be better than what we have
     if (isset($details->system_key)) {
         $sql = "SELECT system_key, system_key_type FROM system WHERE system_id = ?";
         $data = array("{$details->system_id}");
         $query = $this->db->query($sql, $data);
         $result = $query->row();
         $db_system_key = $result->system_key;
         $db_system_key_type = $result->system_key_type;
         if ($details->system_key_type == 'uuho') {
             # we already have a system key based on UUID . "_" . hostname
             #echo "1\n";
         } else {
             # we need to check the existing key
             if ($db_system_key_type == 'uuho') {
                 # the system key in the database is based on UUID . "_" . hostname
                 $details->system_key = $db_system_key;
                 $details->system_key_type = 'uuho';
                 #echo "2\n";
             } elseif ($db_system_key == 'fqdn') {
                 # the system key in the database is based on the fqdn
                 $details->system_key = $db_system_key;
                 $details->system_key_type = 'fqdn';
                 #echo "3\n";
             } elseif ($db_system_key_type == 'hodo') {
                 # the system key in the database is based on the fqdn
                 $details->system_key = $db_system_key;
                 $details->system_key_type = 'hodo';
                 #echo "4\n";
             } elseif ($db_system_key_type == 'ipad') {
                 # the system key in the database is based on the ip address
                 $details->system_key = $db_system_key;
                 $details->system_key_type = 'ipad';
                 #echo "5\n";
             } elseif ($db_system_key_type = 'tyse') {
                 # the system key in the database is based on the type and serial
                 $details->system_key = $db_system_key;
                 $details->system_key_type = 'tyse';
                 #echo "6\n";
             }
         }
     }
     # if submitting an nmap scan, do not update the type or man_type
     if (isset($details->last_seen_by) and $details->last_seen_by == 'nmap') {
         unset($details->type);
         unset($details->man_type);
     }
     # for removing existing symbols
     if (isset($details->os_name)) {
         $details->os_name = str_ireplace("(r)", "", $details->os_name);
         $details->os_name = str_ireplace("(tm)", "", $details->os_name);
     }
     # we check a few man_ items when we are submitting an audit script result
     # if they are blank (previously submitted info is incomplete) we over write them
     # we would not normally over write man_ items
     if (isset($details->last_seen_by) and ($details->last_seen_by == 'audit' or $details->last_seen_by == 'snmp')) {
         $sql = "SELECT * FROM system WHERE system_id = ? LIMIT 1";
         $data = array("{$details->system_id}");
         $query = $this->db->query($sql, $data);
         $row = $query->row();
         if ($row->man_manufacturer == '' and isset($details->manufacturer)) {
             $details->man_manufacturer = $details->manufacturer;
         }
         if ($row->man_model == '' and isset($details->model)) {
             $details->man_model = $details->model;
         }
         if ($row->man_serial == '' and isset($details->serial)) {
             $details->man_serial = $details->serial;
         }
         if ($row->man_description == '' and isset($details->description)) {
             $details->man_description = $details->description;
         }
         if ($row->man_form_factor == '' and isset($details->form_factor)) {
             $details->man_form_factor = $details->form_factor;
         }
         if ($row->man_os_group == '' and isset($details->os_group)) {
             $details->man_os_group = $details->os_group;
         }
         if ($row->man_os_family == '' and isset($details->os_family)) {
             $details->man_os_family = $details->os_family;
         }
         if ($row->man_os_name == '' and isset($details->os_name)) {
             $details->man_os_name = $details->os_name;
         }
         if (isset($details->manufacturer) and (strripos($details->manufacturer, "vmware") !== false or strripos($details->manufacturer, "parallels") !== false or strripos($details->manufacturer, "virtual") !== false)) {
             $details->form_factor = 'Virtual';
             $details->man_form_factor = 'Virtual';
         }
     }
     if (isset($details->last_seen_by) and $details->last_seen_by == 'snmp') {
         $details->icon = $details->type;
         $details->man_icon = $details->type;
     }
     # only update system.timestamp if we have an audit result - not for nmap, snmp, etc
     if (isset($details->last_seen_by) and $details->last_seen_by == 'audit') {
         # leave it alone
     } else {
         unset($details->timestamp);
         unset($details->first_timestamp);
     }
     if (isset($details->man_ip_address)) {
         $details->man_ip_address = ip_address_to_db($details->man_ip_address);
     }
     $sql = "SHOW COLUMNS FROM system";
     $query = $this->db->query($sql);
     $columns = $query->result();
     $sql = "UPDATE system SET ";
     foreach ($details as $key => $value) {
         if ($key != '' and $value != '') {
             # need to iterate through available columns and only insert where $key == valid column name
             foreach ($columns as $column) {
                 if ($key == $column->Field) {
                     $sql .= $key . "= '" . str_replace("'", "\\'", $value) . "', ";
                 }
             }
         }
     }
     $sql = mb_substr($sql, 0, mb_strlen($sql) - 2);
     $sql .= " WHERE system_id = '" . $details->system_id . "'";
     $query = $this->db->query($sql);
 }
示例#7
0
 function output_convert($data)
 {
     foreach ($data as $row) {
         if (is_array($row)) {
             $row = output_convert($row);
         } elseif (is_object($row)) {
             if (!empty($row->attributes)) {
                 foreach ($row->attributes as $key => $value) {
                     if (isset($key) and ($key == 'id' or $key == 'free' or $key == 'used' or $key == 'size' or $key == 'speed' or $key == 'total' or $key == 'col_order' or $key == 'access_level' or $key == 'count')) {
                         $row->attributes->{$key} = intval($value);
                     } elseif (strrpos($key, 'id') === strlen($key) - 2 or strrpos($key, 'count') === strlen($key) - 5 or strrpos($key, 'percent') === strlen($key) - 7 or strrpos($key, 'size') === strlen($key) - 4) {
                         $row->attributes->{$key} = intval($value);
                     } elseif (strrpos($key, 'ip') === strlen($key) - 2 or strrpos($key, 'next_hop') === strlen($key) - 8 or strrpos($key, 'destination') === strlen($key) - 11) {
                         $temp_name = $key . '_padded';
                         $row->attributes->{$temp_name} = ip_address_from_db($value);
                         $row->attributes->{$temp_name} = ip_address_to_db($row->attributes->{$temp_name});
                         $row->attributes->{$key} = ip_address_from_db($value);
                         if ($row->attributes->{$temp_name} == $row->attributes->{$key}) {
                             unset($row->attributes->{$temp_name});
                         }
                     }
                 }
             }
         }
     }
     return $data;
 }
示例#8
0
 function add_san()
 {
     if (isset($_POST['input']) and $_POST['input'] != '') {
         $this->benchmark->mark('code_start');
         $log_details = new stdClass();
         $log_details->severity = 7;
         $log_details->file = 'system';
         $log_details->message = 'Start processing audit result for a san';
         stdlog($log_details);
         $this->load->model('m_devices_components');
         $this->load->model('m_system');
         $this->load->model('m_oa_group');
         $this->load->model('m_audit_log');
         $this->load->helper('url');
         $input = explode(PHP_EOL, $_POST['input']);
         // echo "FILE: " . $input[0] . "\n";
         echo "<pre>\n";
         // print_r($input);
         $details = new stdClass();
         $details->hostname = '';
         $details->type = 'san';
         $san = array();
         $disk = array();
         $network = array();
         $ip = array();
         foreach ($input as $key => $value) {
             $value = trim($value);
             if (stripos($value, 'Feature pack:') === 0 and (!isset($details->description) or $details->description == '')) {
                 $details->description = trim(str_replace('Feature pack:', '', $value));
             }
             if (stripos($value, 'Chassis name:') === 0 and (!isset($details->description) or $details->description == '')) {
                 $details->description = trim(str_replace('Chassis name:', '', $value));
             }
             if (stripos($value, 'Storage Subsystem world-wide identifier (ID):') === 0 and (!isset($details->serial) or $details->serial == '')) {
                 $details->serial = str_replace('Storage Subsystem world-wide identifier (ID):', '', $value);
             }
             if (stripos($value, 'Storage Subsystem worldwide name (ID):') === 0 and (!isset($details->serial) or $details->serial == '')) {
                 $details->serial = str_replace('Storage Subsystem worldwide name (ID):', '', $value);
             }
             if (stripos($value, 'Storage array world-wide identifier (ID):') === 0 and (!isset($details->serial) or $details->serial == '')) {
                 $details->serial = str_replace('Storage array world-wide identifier (ID):', '', $value);
             }
             if (stripos($value, 'Controller DNS/Network name:') === 0 and $details->hostname == '') {
                 $details->hostname = trim(str_replace('Controller DNS/Network name:', '', $value));
             }
             if (stripos($value, 'Controller host name:') === 0 and $details->hostname == '') {
                 $details->hostname = trim(str_replace('Controller host name:', '', $value));
             }
             if (stripos($value, 'RAID Controller Module host name:') === 0 and $details->hostname == '') {
                 $details->hostname = trim(str_replace('RAID Controller Module host name:', '', $value));
             }
             if (stripos($value, 'Controller in Enclosure') === 0 or stripos($value, 'RAID Controller Module in Enclosure') === 0) {
                 $item = new stdClass();
                 $item->type = 'controller';
                 # get the parent
                 $item->attached_to = '';
                 $item->location = $value;
                 #
                 #$item->attached_to = substr($item->location, 0, $i);
                 $i = explode(' ', $item->location);
                 unset($i[0]);
                 unset($i[1]);
                 $item->attached_to = implode(' ', $i);
                 unset($i);
                 $i = stripos($item->attached_to, ',');
                 $item->attached_to = substr($item->attached_to, 0, $i);
                 # get the details
                 for ($i = $key; $i < $key + 40; $i++) {
                     $input[$i] = trim($input[$i]);
                     if (stripos(trim($input[$i]), 'Status:') === 0 and (!isset($item->status) or $item->status == '')) {
                         $item->status = trim(str_ireplace('Status:', '', $input[$i]));
                     }
                     if (stripos(trim($input[$i]), 'Firmware version:') === 0 and trim(str_ireplace('Firmware version:', '', $input[$i])) != '' and !isset($item->firmware_version)) {
                         $item->firmware_version = trim(str_ireplace('Firmware version:', '', $input[$i]));
                         if (isset($item->notes) and $item->notes != '') {
                             $item->notes .= ', Firmware Version: ' . trim(str_ireplace('Firmware version:', '', $input[$i]));
                         } else {
                             $item->notes = 'Firmware Version: ' . trim(str_ireplace('Firmware version:', '', $input[$i]));
                         }
                     }
                     if (stripos(trim($input[$i]), 'Replacement part number:') === 0 and trim(str_ireplace('Replacement part number:', '', $input[$i])) != '' and !isset($item->replacement_part_number)) {
                         $item->replacement_part_number = trim(str_ireplace('Replacement part number:', '', $input[$i]));
                         if (isset($item->notes) and $item->notes != '') {
                             $item->notes .= ', Replacement part number: ' . trim(str_ireplace('Replacement part number:', '', $input[$i]));
                         } else {
                             $item->notes = 'Replacement part number: ' . trim(str_ireplace('Replacement part number:', '', $input[$i]));
                         }
                     }
                     if (stripos(trim($input[$i]), 'Model name:') === 0 and trim(str_ireplace('Model name:', '', $input[$i])) != '' and !isset($item->model_name)) {
                         $item->model_name = trim(str_ireplace('Model name:', '', $input[$i]));
                         if (isset($item->notes) and $item->notes != '') {
                             $item->notes .= ', Model Name: ' . trim(str_ireplace('Model name:', '', $input[$i]));
                         } else {
                             $item->notes = 'Model Name: ' . trim(str_ireplace('Model Name:', '', $input[$i]));
                         }
                     }
                     if (stripos(trim($input[$i]), 'Board ID:') === 0 and trim(str_ireplace('Board ID:', '', $input[$i])) != '' and !isset($item->board_id)) {
                         $item->board_id = trim(str_ireplace('Board ID:', '', $input[$i]));
                         if (isset($item->notes) and $item->notes != '') {
                             $item->notes .= ', Board ID: ' . trim(str_ireplace('Board ID:', '', $input[$i]));
                         } else {
                             $item->notes = 'Board ID: ' . trim(str_ireplace('Board ID:', '', $input[$i]));
                         }
                     }
                     if (stripos(trim($input[$i]), 'Submodel ID:') === 0 and trim(str_ireplace('Submodel ID:', '', $input[$i])) != '' and !isset($item->submodel_id)) {
                         $item->submodel_id = trim(str_ireplace('Submodel ID:', '', $input[$i]));
                         if (isset($item->notes) and $item->notes != '') {
                             $item->notes .= ', Submodel ID: ' . trim(str_ireplace('Submodel ID:', '', $input[$i]));
                         } else {
                             $item->notes = 'Submodel ID: ' . trim(str_ireplace('Submodel ID:', '', $input[$i]));
                         }
                     }
                     if (stripos(trim($input[$i]), 'Product ID:') === 0 and trim(str_ireplace('Product ID:', '', $input[$i])) != '' and !isset($item->product_id)) {
                         $item->product_id = trim(str_ireplace('Product ID:', '', $input[$i]));
                         if (isset($item->notes) and $item->notes != '') {
                             $item->notes .= ', Product ID: ' . trim(str_ireplace('Product ID:', '', $input[$i]));
                         } else {
                             $item->notes = 'Product ID: ' . trim(str_ireplace('Product ID:', '', $input[$i]));
                         }
                     }
                     if (stripos(trim($input[$i]), 'Revision:') === 0 and trim(str_ireplace('Revision:', '', $input[$i])) != '' and !isset($item->revision)) {
                         $item->revision = trim(str_ireplace('Revision:', '', $input[$i]));
                         if (isset($item->notes) and $item->notes != '') {
                             $item->notes .= ', Revision: ' . trim(str_ireplace('Revision:', '', $input[$i]));
                         } else {
                             $item->notes = 'Revision: ' . trim(str_ireplace('Revision:', '', $input[$i]));
                         }
                     }
                     if (stripos(trim($input[$i]), 'Part number:') === 0 and (!isset($item->part_number) or $item->part_number == '')) {
                         $item->part_number = trim(str_ireplace('Part number:', '', $input[$i]));
                     }
                     if (stripos(trim($input[$i]), 'Serial number:') === 0 and (!isset($item->serial) or $item->serial == '')) {
                         $item->serial = trim(str_ireplace('Serial number:', '', $input[$i]));
                     }
                     if (stripos(trim($input[$i]), 'Vendor:') === 0 and (!isset($item->manufacturer) or $item->manufacturer == '')) {
                         $item->manufacturer = trim(str_ireplace('Vendor:', '', $input[$i]));
                     }
                     if (stripos(trim($input[$i]), 'Date of manufacture:') === 0 and (!isset($item->date_of_manufacture) or $item->date_of_manufacture == '')) {
                         $item->date_of_manufacture = trim(str_ireplace('Date of manufacture:', '', $input[$i]));
                     }
                 }
                 $san[] = $item;
                 unset($item);
             }
             if (stripos($value, 'Data Cache Module') === 0 or stripos($value, 'Cache Backup Device') === 0 or stripos($value, 'Host Interface Board') === 0) {
                 $item = new stdClass();
                 $item->type = strtolower($value);
                 # get the parent
                 for ($i = $key; $i >= 1; $i--) {
                     if (stripos(trim($input[$i]), 'Controller in Enclosure') !== false) {
                         $item->attached_to = trim($input[$i]);
                         break;
                     }
                 }
                 # get the details
                 for ($i = $key + 1; $i < $key + 15; $i++) {
                     if (trim($input[$i]) == 'Data Cache Module' or trim($input[$i]) == 'Cache Backup Device' or trim($input[$i]) == 'Host Interface Board') {
                         # we hit the next module, break, break from this loop
                         break;
                     }
                     if (stripos(trim($input[$i]), 'Status:') === 0 and (!isset($item->status) or $item->status == '')) {
                         $item->status = trim(str_ireplace('Status:', '', $input[$i]));
                     }
                     if (stripos(trim($input[$i]), 'Location:') === 0 and (!isset($item->location) or $item->location == '')) {
                         $item->location = trim(str_ireplace('Location:', '', $input[$i]));
                     }
                     if (stripos(trim($input[$i]), 'Capacity:') === 0 and trim(str_ireplace('Capacity:', '', $input[$i])) != '' and !isset($item->capacity)) {
                         $item->capacity = trim(str_ireplace('Capacity:', '', $input[$i]));
                         if (isset($item->notes) and $item->notes != '') {
                             $item->notes .= ', Capacity: ' . str_replace(',', '', trim(str_ireplace('Capacity:', '', $input[$i])));
                         } else {
                             $item->notes = 'Capacity: ' . str_replace(',', '', trim(str_ireplace('Capacity:', '', $input[$i])));
                         }
                     }
                     if (stripos(trim($input[$i]), 'Replacement part number:') === 0 and trim(str_ireplace('Replacement part number:', '', $input[$i])) != '' and !isset($item->replacement_part_number)) {
                         $item->replacement_part_number = trim(str_ireplace('Replacement part number:', '', $input[$i]));
                         if (isset($item->notes) and $item->notes != '') {
                             $item->notes .= ', Replacement part number: ' . trim(str_ireplace('Replacement part number:', '', $input[$i]));
                         } else {
                             $item->notes = 'Replacement part number: ' . trim(str_ireplace('Replacement part number:', '', $input[$i]));
                         }
                     }
                     if (stripos(trim($input[$i]), 'Manufacturer part number:') === 0 and (!isset($item->part_number) or $item->part_number == '')) {
                         $item->part_number = trim(str_ireplace('Manufacturer part number:', '', $input[$i]));
                     }
                     if (stripos(trim($input[$i]), 'Part number:') === 0 and (!isset($item->part_number) or $item->part_number == '')) {
                         $item->part_number = trim(str_ireplace('Part number:', '', $input[$i]));
                     }
                     if (stripos(trim($input[$i]), 'Serial number:') === 0 and (!isset($item->serial) or $item->serial == '')) {
                         $item->serial = trim(str_ireplace('Serial number:', '', $input[$i]));
                     }
                     if (stripos(trim($input[$i]), 'Manufacturer:') === 0 and (!isset($item->manufacturer) or $item->manufacturer == '')) {
                         $item->manufacturer = trim(str_ireplace('Manufacturer:', '', $input[$i]));
                     }
                     if (stripos(trim($input[$i]), 'Date of manufacture:') === 0 and (!isset($item->date_of_manufacture) or $item->date_of_manufacture == '')) {
                         $item->date_of_manufacture = trim(str_ireplace('Date of manufacture:', '', $input[$i]));
                     }
                 }
                 if ($item->serial != '' and $item->serial != 'Not Available') {
                     $san[] = $item;
                 }
                 unset($item);
             }
             if (stripos($value, 'Enclosure audible alarm:') === 0) {
                 $item = new stdClass();
                 $item->type = 'enclosure';
                 # as this IS a parent, get the name by reverse loop
                 for ($i = $key; $i >= 1; $i--) {
                     if (stripos(trim($input[$i]), 'Overall Component Information') !== false) {
                         $item->description = trim(str_ireplace(' Overall Component Information', '', $input[$i]));
                         $j = explode(' ', $item->description);
                         $item->type = strtolower($j[0] . ' ' . $j[1]);
                         $item->location = trim(@$j[1] . ' ' . @$j[2]);
                         unset($j);
                         unset($item->description);
                         break;
                     }
                 }
                 if ($item->location == 'Enclosure') {
                     $item->location = 'Enclosure 0';
                 }
                 # get the details
                 for ($i = $key; $i < $key + 10; $i++) {
                     if (trim($input[$i]) == '') {
                         # we hit an empty line, break from this loop
                         break;
                     }
                     if (stripos(trim($input[$i]), 'Serial number:') === 0) {
                         #and (!isset($item->serial) or $item->serial == '')) {
                         $item->serial = trim(str_ireplace('Serial number:', '', $input[$i]));
                     }
                     if (stripos(trim($input[$i]), 'Part number:') === 0 and (!isset($item->part_number) or $item->part_number == '')) {
                         $item->part_number = trim(str_ireplace('Part number:', '', $input[$i]));
                     }
                     if (stripos(trim($input[$i]), 'Vendor:') === 0 and (!isset($item->manufacturer) or $item->manufacturer == '')) {
                         $item->manufacturer = trim(str_ireplace('Vendor:', '', $input[$i]));
                     }
                     if (stripos(trim($input[$i]), 'Date of manufacture:') === 0 and (!isset($item->date_of_manufacture) or $item->date_of_manufacture == '')) {
                         $item->date_of_manufacture = trim(str_ireplace('Date of manufacture:', '', $input[$i]));
                     }
                 }
                 $san[] = $item;
                 unset($item);
             }
             if (stripos($value, 'ESM card status:') === 0) {
                 $item = new stdClass();
                 $item->type = 'esm canister';
                 # get the parent
                 for ($i = $key; $i >= 1; $i--) {
                     if (stripos(trim($input[$i]), 'Overall Component Information') !== false) {
                         $i = explode(' ', trim(str_ireplace(' Overall Component Information', '', $input[$i])));
                         $item->attached_to = trim(@$i[1] . ' ' . @$i[2]);
                         break;
                     }
                 }
                 # get the details
                 for ($i = $key; $i < $key + 20; $i++) {
                     if (trim($input[$i]) == '') {
                         # we hit an empty line, break from this loop
                         break;
                     }
                     if (stripos(trim($input[$i]), 'Serial number:') === 0 and (!isset($item->serial) or $item->serial == '')) {
                         $item->serial = trim(str_ireplace('Serial number:', '', $input[$i]));
                     }
                     if (stripos(trim($input[$i]), 'Part number:') === 0 and (!isset($item->part_number) or $item->part_number == '')) {
                         $item->part_number = trim(str_ireplace('Part number:', '', $input[$i]));
                     }
                     if (stripos(trim($input[$i]), 'Vendor:') === 0 and (!isset($item->manufacturer) or $item->manufacturer == '')) {
                         $item->manufacturer = trim(str_ireplace('Vendor:', '', $input[$i]));
                     }
                     if (stripos(trim($input[$i]), 'Date of manufacture:') === 0 and (!isset($item->date_of_manufacture) or $item->date_of_manufacture == '')) {
                         $item->date_of_manufacture = trim(str_ireplace('Date of manufacture:', '', $input[$i]));
                     }
                     if (stripos(trim($input[$i]), 'Location:') === 0 and (!isset($item->location) or $item->location == '')) {
                         $item->location = 'ESM Canister ' . trim(str_ireplace('Location:', '', $input[$i]));
                     }
                     if (stripos(trim($input[$i]), 'Product ID:') === 0 and trim(str_ireplace('Product ID:', '', $input[$i])) != '' and !isset($item->product_id)) {
                         $item->product_id = trim(str_ireplace('Product ID:', '', $input[$i]));
                         if (isset($item->notes) and $item->notes != '') {
                             $item->notes .= ', Product ID: ' . trim(str_ireplace('Product ID:', '', $input[$i]));
                         } else {
                             $item->notes = 'Product ID: ' . trim(str_ireplace('Product ID:', '', $input[$i]));
                         }
                     }
                 }
                 $san[] = $item;
                 unset($item);
             }
             if (stripos($value, 'SFP status:') === 0) {
                 $item = new stdClass();
                 $item->type = 'sfp';
                 # get the parent
                 for ($i = $key; $i >= 1; $i--) {
                     if (stripos(trim($input[$i]), 'Overall Component Information') !== false) {
                         $i = explode(' ', trim(str_ireplace(' Overall Component Information', '', $input[$i])));
                         $item->attached_to = trim(@$i[1] . ' ' . @$i[2]);
                         break;
                     }
                 }
                 # get the details
                 for ($i = $key; $i < $key + 20; $i++) {
                     if (trim($input[$i]) == '') {
                         # we hit an empty line, break from this loop
                         break;
                     }
                     if (stripos(trim($input[$i]), 'Attached to:') === 0 and (!isset($item->attached_to_location) or $item->attached_to_location == '')) {
                         $item->attached_to_location = trim(str_ireplace('Attached to:', '', $input[$i]));
                     }
                     if (stripos(trim($input[$i]), 'SFP status:') === 0 and (!isset($item->status) or $item->status == '')) {
                         $item->status = trim(str_ireplace('SFP status:', '', $input[$i]));
                     }
                     if (stripos(trim($input[$i]), 'Revision:') === 0 and trim(str_ireplace('Revision:', '', $input[$i])) != '' and !isset($item->revision)) {
                         $item->revision = trim(str_ireplace('Revision:', '', $input[$i]));
                         if (isset($item->notes) and $item->notes != '') {
                             $item->notes .= ', Revision: ' . trim(str_ireplace('Revision:', '', $input[$i]));
                         } else {
                             $item->notes = 'Revision: ' . trim(str_ireplace('Revision:', '', $input[$i]));
                         }
                     }
                     if (stripos(trim($input[$i]), 'Serial number:') === 0 and (!isset($item->serial) or $item->serial == '')) {
                         $item->serial = trim(str_ireplace('Serial number:', '', $input[$i]));
                     }
                     if (stripos(trim($input[$i]), 'Part number:') === 0 and (!isset($item->part_number) or $item->part_number == '')) {
                         $item->part_number = trim(str_ireplace('Part number:', '', $input[$i]));
                     }
                     if (stripos(trim($input[$i]), 'Vendor:') === 0 and (!isset($item->manufacturer) or $item->manufacturer == '')) {
                         $item->manufacturer = trim(str_ireplace('Vendor:', '', $input[$i]));
                     }
                     if (stripos(trim($input[$i]), 'Date of manufacture:') === 0 and (!isset($item->date_of_manufacture) or $item->date_of_manufacture == '')) {
                         $item->date_of_manufacture = trim(str_ireplace('Date of manufacture:', '', $input[$i]));
                     }
                     if (stripos(trim($input[$i]), 'Location:') === 0 and (!isset($item->location) or $item->location == '')) {
                         $item->location = trim(str_ireplace('Location:', '', $input[$i]));
                     }
                     if (stripos(trim($input[$i]), 'Product ID:') === 0 and trim(str_ireplace('Product ID:', '', $input[$i])) != '' and !isset($item->product_id)) {
                         $item->product_id = trim(str_ireplace('Product ID:', '', $input[$i]));
                         if (isset($item->notes) and $item->notes != '') {
                             $item->notes .= ', Product ID: ' . trim(str_ireplace('Product ID:', '', $input[$i]));
                         } else {
                             $item->notes = 'Product ID: ' . trim(str_ireplace('Product ID:', '', $input[$i]));
                         }
                     }
                 }
                 if (stripos($item->attached_to_location, 'ESM Canister') !== false) {
                     $item->attached_to = $item->attached_to_location;
                 } elseif (stripos($item->attached_to_location, 'controller') !== false) {
                     $j = substr($item->attached_to_location, strpos($item->attached_to_location, ',') - 1, 1);
                     $item->attached_to = 'Controller in ' . $item->attached_to . ', Slot ' . $j;
                     unset($j);
                     $j = explode(' ', $item->attached_to_location);
                     $item->location = $j[0] . ', ' . $item->location;
                 }
                 $san[] = $item;
                 unset($item);
             }
             if (stripos($value, 'Power-fan canister') === 0 and stripos($value, 'status:') !== false) {
                 $item = new stdClass();
                 $item->type = 'power fan cannister';
                 # get the parent
                 for ($i = $key; $i >= 1; $i--) {
                     if (stripos(trim($input[$i]), 'Overall Component Information') !== false) {
                         $i = explode(' ', trim(str_ireplace(' Overall Component Information', '', $input[$i])));
                         $item->attached_to = trim(@$i[1] . ' ' . @$i[2]);
                         break;
                     }
                 }
                 # get the details
                 for ($i = $key; $i < $key + 10; $i++) {
                     if (trim($input[$i]) == '') {
                         # we hit an empty line, break from this loop
                         break;
                     }
                     if (stripos(trim($input[$i]), 'Power-fan canister') === 0 and stripos($input[$i], 'status:') !== false and (!isset($item->status) or $item->status == '')) {
                         $item->status = trim(str_ireplace('Power-fan canister (Left) status:', '', $input[$i]));
                         $item->status = trim(str_ireplace('Power-fan canister (Right) status:', '', $item->status));
                         if (stripos($input[$i], 'Power-fan canister (Left) status:') !== false) {
                             #$item->description = 'Power-fan canister (Left)';
                             $item->location = 'Power-fan canister (Left)';
                         }
                         if (stripos($input[$i], 'Power-fan canister (Right) status:') !== false) {
                             #$item->description = 'Power-fan canister (Right)';
                             $item->location = 'Power-fan canister (Right)';
                         }
                     }
                     if (stripos(trim($input[$i]), 'Serial number:') === 0) {
                         #and (!isset($item->serial) or $item->serial == '')) {
                         $item->serial = trim(str_ireplace('Serial number:', '', $input[$i]));
                     }
                     if (stripos(trim($input[$i]), 'Part number:') === 0 and (!isset($item->part_number) or $item->part_number == '')) {
                         $item->part_number = trim(str_ireplace('Part number:', '', $input[$i]));
                     }
                     if (stripos(trim($input[$i]), 'Vendor:') === 0 and (!isset($item->manufacturer) or $item->manufacturer == '')) {
                         $item->manufacturer = trim(str_ireplace('Vendor:', '', $input[$i]));
                     }
                     if (stripos(trim($input[$i]), 'Date of manufacture:') === 0 and (!isset($item->date_of_manufacture) or $item->date_of_manufacture == '')) {
                         $item->date_of_manufacture = trim(str_ireplace('Date of manufacture:', '', $input[$i]));
                     }
                 }
                 $san[] = $item;
                 unset($item);
             }
             if (stripos($value, 'Drive at Enclosure') === 0) {
                 $item = new stdClass();
                 $item->type = 'disk';
                 $item->caption = trim($value);
                 $item->device = trim($value);
                 $item->hard_drive_index = trim($value);
                 $item->location = trim(str_ireplace('Drive at ', '', $value));
                 $item->attached_to = '';
                 $i = stripos($item->location, ',');
                 $item->attached_to = substr($item->location, 0, $i);
                 $item->size = '';
                 # get the details
                 for ($i = $key + 1; $i < $key + 50; $i++) {
                     if (stripos(trim($input[$i]), 'Drive at Enclosure') === 0) {
                         # we hit the next drive, break from this loop
                         break;
                     }
                     if (stripos(trim($input[$i]), 'Status:') === 0 and (!isset($item->status) or $item->status == '')) {
                         $item->status = trim(str_ireplace('Status:', '', $input[$i]));
                     }
                     if (stripos(trim($input[$i]), 'Usable capacity:') === 0 and $item->size == '') {
                         $item->size = $this->get_size(trim(str_replace('Usable capacity:', '', $input[$i])));
                     }
                     if (stripos(trim($input[$i]), 'Interface type:') === 0 and (!isset($item->interface_type) or $item->interface_type == '')) {
                         $item->interface_type = trim(str_replace('Interface type:', '', $input[$i]));
                     }
                     if (stripos(trim($input[$i]), 'Drive type:') === 0 and (!isset($item->interface_type) or $item->interface_type == '')) {
                         $item->interface_type = trim(str_replace('Drive type:', '', $input[$i]));
                     }
                     if (stripos(trim($input[$i]), 'Product ID:') === 0 and (!isset($item->model) or $item->model == '')) {
                         $item->model = trim(str_replace('Product ID:', '', $input[$i]));
                     }
                     if (stripos(trim($input[$i]), 'Firmware version:') === 0 and (!isset($item->firmware) or $item->firmware == '')) {
                         $item->firmware = trim(str_ireplace('Firmware version:', '', $input[$i]));
                     }
                     if (stripos(trim($input[$i]), 'Serial number:') === 0 and (!isset($item->serial) or $item->serial == '')) {
                         $item->serial = trim(str_ireplace('Serial number:', '', $input[$i]));
                     }
                     if (stripos(trim($input[$i]), 'Vendor:') === 0 and (!isset($item->manufacturer) or $item->manufacturer == '')) {
                         $item->manufacturer = trim(str_ireplace('Vendor:', '', $input[$i]));
                     }
                     if (stripos(trim($input[$i]), 'Date of manufacture:') === 0 and (!isset($item->date_of_manufacture) or $item->date_of_manufacture == '')) {
                         $item->date_of_manufacture = trim(str_ireplace('Date of manufacture:', '', $input[$i]));
                     }
                 }
                 if ($item->size != '') {
                     $disk[] = $item;
                 }
                 unset($item);
             }
             if (stripos($value, 'Ethernet port:') === 0) {
                 $item = new stdClass();
                 $item->attached_to = '';
                 $item_ip = new stdClass();
                 # get the parent
                 for ($i = $key; $i >= 1; $i--) {
                     if (stripos(trim($input[$i]), 'Controller in Enclosure') !== false) {
                         $item->attached_to = trim($input[$i]);
                         break;
                     }
                 }
                 $item->description = 'Ethernet port ' . trim(str_replace('Ethernet port:', '', $value)) . ' on ' . $item->attached_to;
                 # get the details
                 for ($i = $key + 1; $i < $key + 15; $i++) {
                     if (stripos(trim($input[$i]), 'Ethernet port:') === 0) {
                         # we hit the next module, break, break from this loop
                         break;
                     }
                     if (stripos(trim($input[$i]), 'Link status:') === 0 and (!isset($item->ip_enabled) or $item->ip_enabled == '')) {
                         $item->ip_enabled = trim(str_ireplace('Status:', '', $input[$i]));
                     }
                     if (stripos(trim($input[$i]), 'Network configuration:') === 0 and (!isset($item->dhcp_enabled) or $item->dhcp_enabled == '')) {
                         $item->dhcp_enabled = trim(str_ireplace('Network configuration:', '', $input[$i]));
                         if ($item->dhcp_enabled == 'Static') {
                             $item->dhcp_enabled = 'False';
                         } else {
                             $item->dhcp_enabled = 'True';
                         }
                     }
                     if (stripos(trim($input[$i]), 'MAC address:') === 0 and (!isset($item->mac) or $item->mac == '')) {
                         $item->mac = strtolower(trim(str_ireplace('MAC address:', '', $input[$i])));
                         $item_ip->mac = $item->mac;
                     }
                     if (stripos(trim($input[$i]), 'Port speed:') === 0 and (!isset($item->speed) or $item->speed == '')) {
                         $item->speed = $this->get_speed(trim(str_replace('Port speed:', '', $input[$i])));
                     }
                     if (stripos(trim($input[$i]), 'IP address:') === 0 and (!isset($item_ip->ip) or $item_ip->ip == '')) {
                         $item_ip->ip = trim(str_ireplace('IP address:', '', $input[$i]));
                         if (!filter_var($item_ip->ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) === false) {
                             $item_ip->version = 4;
                         }
                         if (!filter_var($item_ip->ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) === false) {
                             $item_ip->version = 6;
                         }
                     }
                     if (stripos(trim($input[$i]), 'Subnet mask:') === 0 and (!isset($item_ip->subnet) or $item_ip->subnet == '')) {
                         $item_ip->subnet = trim(str_ireplace('Subnet mask:', '', $input[$i]));
                     }
                     if (stripos(trim($input[$i]), 'Host name:') === 0 and (!isset($details->hostname) or $details->hostname == '')) {
                         $details->hostname = trim(str_ireplace('Host name:', '', $input[$i]));
                     }
                 }
                 if (isset($item_ip->ip) and (!isset($item->ip_enabled) or $item->ip_enabled == '')) {
                     $item->ip_enabled = 'Link Up';
                 }
                 if (isset($item->ip_enabled) and stripos($item->ip_enabled, 'up') and !isset($details->ip) and isset($item_ip->ip) and $item_ip->ip != '') {
                     $details->ip = $item_ip->ip;
                 }
                 foreach ($san as $each) {
                     if ($each->location == $item->attached_to) {
                         $item->manufacturer = @$each->manufacturer;
                     }
                 }
                 $network[] = $item;
                 $ip[] = $item_ip;
                 unset($item);
                 unset($item_ip);
             }
         }
         foreach ($san as $key => $value) {
             $class_vars = get_object_vars($value);
             foreach ($class_vars as $name => $item_value) {
                 if (stripos($san[$key]->{$name}, 'Not Available') !== false or stripos($san[$key]->{$name}, 'Unknown') !== false) {
                     $san[$key]->{$name} = '';
                 }
             }
         }
         $xml = new SimpleXMLElement('<root/>');
         foreach ($san as $key => $value) {
             $item = $xml->addChild('item');
             $class_vars = get_object_vars($value);
             foreach ($class_vars as $name => $item_value) {
                 $item->{$name} = $item_value;
             }
         }
         unset($san);
         $san = $xml;
         unset($xml);
         $xml = new SimpleXMLElement('<root/>');
         foreach ($network as $key => $value) {
             $item = $xml->addChild('item');
             $class_vars = get_object_vars($value);
             foreach ($class_vars as $name => $item_value) {
                 $item->{$name} = $item_value;
             }
         }
         unset($network);
         $network = $xml;
         unset($xml);
         $xml = new SimpleXMLElement('<root/>');
         foreach ($disk as $key => $value) {
             $item = $xml->addChild('item');
             $class_vars = get_object_vars($value);
             foreach ($class_vars as $name => $item_value) {
                 $item->{$name} = $item_value;
             }
         }
         unset($disk);
         $disk = $xml;
         unset($xml);
         $xml = new SimpleXMLElement('<root/>');
         foreach ($ip as $key => $value) {
             $item = $xml->addChild('item');
             $class_vars = get_object_vars($value);
             foreach ($class_vars as $name => $item_value) {
                 $item->{$name} = $item_value;
             }
         }
         unset($ip);
         $ip = $xml;
         unset($xml);
         if ($details->hostname == 'target') {
             $details->hostname .= '-' . str_replace('.', '', $details->ip);
         }
         $details->name = $details->hostname;
         if (!empty($details->description)) {
             if ($details->description == 'DS5100') {
                 $details->model = $details->description;
             }
             if (stripos($details->description, 'DS5020') !== false) {
                 $details->model = 'DS5020';
             }
         }
         $log_details->message = 'Processing audit result for san at ' . $details->ip;
         stdlog($log_details);
         $details->last_seen = $this->config->config['timestamp'];
         $details->id = intval($this->m_system->find_system($details, 'y'));
         $details->last_seen_by = 'audit';
         $details->audits_ip = @ip_address_to_db($_SERVER['REMOTE_ADDR']);
         print_r($details);
         // // print_r($network);
         print_r($disk);
         // exit();
         if ($details->id == '') {
             // insert a new system
             $details->first_seen = $details->last_seen;
             $details->id = $this->m_system->insert_system($details);
             $log_details = new stdClass();
             $log_details->severity = 7;
             $log_details->file = 'system';
             $log_details->message = 'Inserting result for ' . $details->hostname . ' (System ID ' . $details->id . ')';
             stdlog($log_details);
             unset($log_details);
             $details->original_last_seen = "";
             echo "SystemID (new): <a href='" . base_url() . "index.php/main/system_display/" . $details->id . "'>" . $details->id . "</a>.<br />\n";
         } else {
             // update an existing system
             $log_details = new stdClass();
             $log_details->severity = 7;
             $log_details->file = 'system';
             $log_details->message = 'Updating result for ' . $details->hostname . ' (System ID ' . $details->id . ')';
             stdlog($log_details);
             unset($log_details);
             $details->original_last_seen_by = $this->m_devices_components->read($details->id, 'y', 'system', '', 'last_seen_by');
             $details->original_last_seen = $this->m_devices_components->read($details->id, 'y', 'system', '', 'last_seen');
             $this->m_system->update_system($details);
             echo "SystemID (updated): <a href='" . base_url() . "index.php/main/system_display/" . $details->id . "'>" . $details->id . "</a>.<br />\n";
         }
         $details->first_seen = $this->m_devices_components->read($details->id, 'y', 'system', '', 'first_seen');
         $temp_user = '';
         if (isset($this->user->full_name)) {
             $temp_user = $this->user->full_name;
         }
         $this->m_audit_log->create($details->id, $temp_user, $details->last_seen_by, $details->audits_ip, '', '', $details->last_seen);
         unset($temp_user);
         $this->m_audit_log->update('debug', 'san', $details->id, $details->last_seen);
         $this->m_devices_components->process_component('san', $details, $san);
         $this->m_audit_log->update('debug', 'network', $details->id, $details->last_seen);
         $this->m_devices_components->process_component('network', $details, $network);
         $this->m_audit_log->update('debug', 'disk', $details->id, $details->last_seen);
         $this->m_devices_components->process_component('disk', $details, $disk);
         $this->m_audit_log->update('debug', 'ip address', $details->id, $details->last_seen);
         $this->m_devices_components->process_component('ip', $details, $ip);
         // Finally, update any groups for this system if config item is set
         $discovery_update_groups = @$this->m_oa_config->get_config_item('discovery_update_groups');
         if (!isset($discovery_update_groups) or $discovery_update_groups == 'n') {
             # don't run the update group routine
         } else {
             $this->m_audit_log->update('debug', 'system groups', $details->id, $details->last_seen);
             $this->m_oa_group->update_system_groups($details);
         }
         $this->m_audit_log->update('debug', '', $details->id, $details->last_seen);
         $this->benchmark->mark('code_end');
         #$log_details->message = 'Processing completed for ' . $details->ip . ' (System ID ' . $details->id . '), took ' . $this->benchmark->elapsed_time('code_start', 'code_end') . ' seconds';
         #stdlog($log_details);
         unset($log_details);
     } else {
         # nothing sent, sending the form html input page
         $this->load->view('v_san_add');
     }
 }
示例#9
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";
         }
     }
 }
    public function process_component($table = '', $details, $input, $display = 'n', $match_columns = array())
    {
        $create_alerts = $this->m_oa_config->get_config_item('discovery_create_alerts');
        $delete_noncurrent = @$this->m_oa_config->get_config_item('delete_noncurrent');

        $log_details = new stdClass();
        $log_details->message = '';
        $log_details->severity = 7;
        $log_details->file = 'system';
        if ($display != 'y') {
            $display = 'n';
        }
        $log_details->display = $display;
        unset($display);

        if (empty($details->name) and !empty($details->hostname)) {
            $name = $details->hostname;
        } else {
            $name = $details->name;
        }

        // ensure we have a valid table name
        if (!$this->db->table_exists($table)) {
            $log_details->message = 'Table supplied does not exist (' . $table . ') for '.@ip_address_from_db($details->ip).' ('.$name.')';
            $log_details->severity = 5;
            stdlog($log_details);
            return;
        }

        if (!$input) {
            $log_details->message = 'No input supplied (' . $table . ') for '.@ip_address_from_db($details->ip).' ('.$name.')';
            $log_details->severity = 5;
            stdlog($log_details);
            return;
        }

        if (!isset($match_columns) or count($match_columns) == 0) {
            $match_columns = $this->match_columns($table);
        }

        if ($table == '' or count($match_columns) == 0 or !isset($details->id)) {
            if ($table == '') {
                $log_details->message = 'No table supplied for '.@ip_address_from_db($details->ip).' ('.$name.')';
                $message = "No table name supplied - failed";
            }
            if (count($match_columns) == 0) {
                $log_details->message = 'No columns to match supplied for '.@ip_address_from_db($details->ip).' ('.$name.')';
                $message = "$table - No columns to match supplied - failed";
            }
            # if (!isset($details->id)) { # this will be changed when we convert the system table
            if (!isset($details->id)) {
                $log_details->message = 'No id supplied for '.@ip_address_from_db($details->ip).' ('.$name.')';
                $message = "$table - No id supplied - failed";
            }
            $this->m_audit_log->update('debug', $message, $details->id, $details->last_seen);
            unset($message);
            $log_details->severity = 5;
            stdlog($log_details);
            return;
        } else {
            $this->m_audit_log->update('debug', "$table - start", $details->id, $details->last_seen);
            $log_details->message = 'Processing component (' . $table . ') start for '.@ip_address_from_db($details->ip).' ('.$name.')';
            $log_details->severity = 7;
            stdlog($log_details);
        }

        // make sure we have an entry for each match column, even if it's empty
        foreach ($match_columns as $match_column) {
            for ($i=0; $i<count($input->item); $i++) {
                if (isset($input->item[$i]) and !isset($input->item[$i]->$match_column)) {
                    $input->item[$i]->$match_column = '';
                }
            }
        }

        ### IP ADDRESS ###
        if ((string)$table == 'ip') {
            for ($i=0; $i<count($input->item); $i++) {
                # some devices may provide upper case MAC addresses - ensure all stored in the DB are lower
                $input->item[$i]->mac = strtolower($input->item[$i]->mac);
                # As at 1.5.6 we pass an additional attribute called 'type' for bonded adapters
                # We use this to test and not pad the MAC address if set
                if (!isset($input->item[$i]->type)) {
                    $input->item[$i]->type = '';
                }
                # calculate the network this address is on (assuming we have an ip AND subnet)
                if (isset($input->item[$i]->ip) and $input->item[$i]->ip != '' and isset($input->item[$i]->netmask) and $input->item[$i]->netmask != '' and $input->item[$i]->netmask != '0.0.0.0') {
                    $temp_long = ip2long($input->item[$i]->netmask);
                    $temp_base = ip2long('255.255.255.255');
                    $temp_subnet = 32-log(($temp_long ^ $temp_base)+1,2);
                    $net = network_details($input->item[$i]->ip.'/'.$temp_subnet);
                    if (isset($net->network) and $net->network != '') {
                        #$input->item[$i]->network = $net->network.' / '.$temp_subnet;
                        $input->item[$i]->network = $net->network.'/'.$temp_subnet;
                    } else {
                        $input->item[$i]->network = '';
                    }
                    if (isset($net->network_slash) and $net->network_slash != '') {
                        $input->item[$i]->cidr = $net->network_slash;
                    } else {
                        $input->item[$i]->cidr = '';
                    }
                    unset($temp_long);
                    unset($temp_base);
                    unset($temp_subnet);
                    unset($net);
                }
                if ($input->item[$i]->type != 'bonded') {
                    if (isset($input->item[$i]->mac) and $input->item[$i]->mac != '') {
                        $mymac = explode(":", $input->item[$i]->mac);
                        for ($j = 0; $j<count($mymac); $j++) {
                            $mymac[$j] = mb_substr("00".$mymac[$j], -2);
                        }
                        if (count($mymac) > 0) {
                            $input->item[$i]->mac = implode(":", $mymac);
                        }
                    }
                }
                if (!isset($input->item[$i]->version) or $input->item[$i]->version != '6') {
                    $input->item[$i]->version = 4;
                }
                # ensure we have the correctly padded ip v4 address
                if ($input->item[$i]->version == 4) {
                    $input->item[$i]->ip = ip_address_to_db($input->item[$i]->ip);
                }
                if (!isset($input->item[$i]->ip) or $input->item[$i]->ip == '') {
                    unset($input->item[$i]);
                }
                # ensure we add the network to the networks list
                if (!empty($input->item[$i]->network)) {
                    $this->m_oa_config->update_blessed($input->item[$i]->network);
                }
            }
            if ($details->type == 'computer' and $details->os_group == 'VMware') {
                # TODO - fix the below somewhow ?!??
                # the issue is that ESXi provides different values for network cards from the command line and from SNMP
                $sql = "DELETE FROM `ip` WHERE `ip`.`system_id` = ?";
                $sql = $this->clean_sql($sql);
                $data = array($details->id);
                $query = $this->db->query($sql, $data);
                # set the below so we don't generate alerts for this
                $create_alerts = 'n';
            }
        }

        ### NETSTAT ###
        if ((string)$table == 'netstat') {
            $input = $this->format_netstat_data($input, $details);
        }

        ### NETWORK ###
        # depending on the device type we need to alter our matching columns for the network card
        if ((string)$table == 'network') {
            if ($details->type == 'computer' and $details->os_group != 'VMware') {
                # we already match only on MAC Address
            } elseif ($details->type == 'computer' and $details->os_group == 'VMware') {
                # add index and connection id to the list to be matched
                $match_columns[] = 'net_index';
                $match_columns[] = 'connection';
                # TODO - fix the below somewhow ?!??
                # the issue is that ESXi provides different values for network cards from the command line and from SNMP
                $sql = "DELETE FROM `network` WHERE `network`.`system_id` = ?";
                $sql = $this->clean_sql($sql);
                $data = array($details->id);
                $query = $this->db->query($sql, $data);
                # set the below so we don't generate alerts for this
                $create_alerts = 'n';
            } else {
                # just match the index
                $match_columns[] = 'net_index';
            }

            # some devices may provide upper case MAC addresses - ensure all stored in the DB are lower
            for ($i=0; $i<count($input->item); $i++) {
                if (isset($input->item[$i]->mac)) {
                    $input->item[$i]->mac = strtolower($input->item[$i]->mac);
                } else {
                    $input->item[$i]->mac = '';
                }
            }
        }

        ### PARTITION ###
        # AIX needs to also match on partition.name
        if ((string)$table == 'partition' and strtolower($details->os_family) == 'ibm aix') {
            $match_columns[] = 'name';
        }

        ### PROCESSOR ###
        if ((string)$table == 'processor') {
            $input->item[0]->description = str_ireplace('(R)', '', $input->item[0]->description);
            $input->item[0]->description = str_ireplace('(TM)', '', $input->item[0]->description);
            $input->item[0]->description = str_ireplace('  ', ' ', $input->item[0]->description);
            $input->item[0]->manufacturer = str_ireplace('AuthenticAMD', 'AMD', $input->item[0]->manufacturer);
            $input->item[0]->manufacturer = str_ireplace('GenuineIntel', 'Intel', $input->item[0]->manufacturer);
        }

        ### SERVER ###
        if ((string)$table == 'server') {
            for ($i=0; $i<count($input->item); $i++) {
                if (isset($input->item[$i]->version) and $input->item[$i]->version != '' and $input->item[$i]->type == 'database') {
                    $input->item[$i]->full_name = (string)$this->get_sql_server_version_string($input->item[$i]->version);
                }
            }
        }

        ### SOFTWARE ###
        # need to pad the version
        if ((string)$table == 'software') {
            for ($i=0; $i<count($input->item); $i++) {
                if (isset($input->item[$i]->version) and $input->item[$i]->version != '') {
                    $pieces = array();
                    $pieces = preg_split("/[\s,\+\-\_\.\\\+\~]+/", $input->item[$i]->version);
                    $input->item[$i]->version_padded = (string)'';
                    foreach ($pieces as $piece) {
                        if (strlen($piece) > 10 ) {
                            $input->item[$i]->version_padded .= $piece;
                        } else {
                            $input->item[$i]->version_padded .= mb_substr("00000000000000000000".$piece, -10);
                        }
                    }
                } else {
                    $input->item[$i]->version_padded = '';
                }
            }
        }

        ### VIRTUAL MACHINE ###
        if ((string)$table == 'vm') {
            foreach ($input->item as $vm) {
                if (!isset($vm->group)) {
                    $vm->group = '';
                }
                if (!isset($vm->guest_system_id)) {
                    $vm->guest_system_id = '';
                }
                if (!isset($vm->icon)) {
                    $vm->icon = '';
                }
                if (!isset($vm->uuid) or $vm->uuid == '') {
                    $vm->uuid = '';
                } else {
                    $sql = "SELECT `system`.`id`, `system`.`icon` FROM `system` WHERE LOWER(`uuid`) = LOWER(?) and `system`.`status` = 'production'";
                    $sql = $this->clean_sql($sql);
                    $data = array("$vm->uuid");
                    $query = $this->db->query($sql, $data);
                    if ($query->num_rows() > 0) {
                        $row = $query->row();
                        $vm->guest_system_id = $row->system_id;
                        $vm->icon = $row->icon;
                        $sql = "UPDATE `system` SET `system`.`vm_server_name` = ?, `system`.`vm_system_id` = ? WHERE `system`.`id` = ?";
                        $sql = $this->clean_sql($sql);
                        $data = array("$details->name", "$details->id", $vm->guest_system_id);
                        $query = $this->db->query($sql, $data);
                    }
                }
            }
        }

        # make sure we have a populated org_id for adding items to the charts table
        if (empty($details->org_id)) {
            $sql = "SELECT `system`.`org_id` FROM `system` WHERE `system`.`id` = ?";
            $sql = $this->clean_sql($sql);
            $data = array($details->id);
            $query = $this->db->query($sql, $data);
            $row = $query->row();
            $details->org_id = $row->org_id;
        }

        // get any existing current rows from the database
        $sql = "SELECT *, '' AS updated FROM `$table` WHERE current = 'y' AND `$table`.`system_id` = ?";
        $sql = $this->clean_sql($sql);
        #$data = array($details->id); # this will be changed when we convert the system table
        $data = array($details->id);
        $query = $this->db->query($sql, $data);
        $db_result = $query->result();
        $alert = false;
        if (count($db_result) != 0) {
            // we have existing items in the database
            // we should raise an alert where required
            $alert = true;
        }

        // get the field list from the table
        $fields = $this->db->list_fields($table);

        // ensure we have a filtered array with only single copies of each $item
        $items = array();
        // for every input item
        foreach ($input->item as $input_key => $input_item) {
            $matched = 'n';
            // loop through the building up item array
            foreach ($items as $output_key => $output_item) {
                // the matched count is the number of columns in the match_columns array
                // that have equal values in our input items
                $match_count = 0;
                // loop through our match_columns array
                for ($i = 0; $i < count($match_columns); $i++) {
                    // and test if the variables match
                    if ((string)$input_item->$match_columns[$i] == (string)$output_item->$match_columns[$i]) {
                        // they match so increment the count
                        $match_count ++;
                    }
                }
                if ($match_count == (count($match_columns))) {
                    // we have two matching items - combine them
                    foreach ($fields as $field) {
                        if ((!isset($output_item->$field) or $output_item->$field == '') and isset($input_item->$field) and $input_item->$field != '') {
                            $output_item->$field = (string) $input_item->$field;
                        }
                    }
                    $items[$output_key] = $output_item;
                    $matched = 'y';
                }
            }
            if ($matched != 'y') {
                // no match, add the input item to the item array
                $items[] = $input_item;
            }
        }

        // for each item from the audit
        foreach ($items as $input_item) {
            // set these flags on a per audit item basis
            $flag = 'insert';
            // compare the audit data against the rows from the DB
            foreach ($db_result as $key => $db_item) {
                // check for a match against the columns in $match_columns
                $match_count = 0;
                for ($i = 0; $i < count($match_columns); $i++) {
                    if ((string)$input_item->$match_columns[$i] == (string)$db_item->$match_columns[$i] and $db_item->updated != 'y') {
                        $match_count ++;
                    }
                }
                if ($match_count == (count($match_columns))) {
                    // UPDATE because all supplied columns match
                    $flag = 'update';
                    $sql = '';
                    // if we have an audit value, replace the DB value
                    foreach ($fields as $field) {
                        if (isset($input_item->$field) and $input_item->$field != '') {
                            $db_item->$field = (string) $input_item->$field;
                        }
                        $sql .= " `" . $table . "`.`" . $field . "` = ? , ";
                    }
                    // remove the trailing characters
                    $sql = substr($sql, 0, -2);
                    // set the last_seen column to the same as in $details (system table)
                    $db_item->last_seen = (string)$details->last_seen;
                    // update all values in the table
                    $sql = "UPDATE `$table` SET $sql WHERE `" . $table . "`.`id` = '" . $db_item->id . "'";
                    // make sure no data is in $data
                    unset ($data);
                    // populate $data with the values from the database, combined with those of the audit
                    // this is stored in $fields
                    $data = array();
                    foreach ($fields as $field) {
                        $data[] = (string)$db_item->$field;
                    }
                    $sql = $this->clean_sql($sql);
                    $query = $this->db->query($sql, $data);
                    // remove this item from the database array
                    // we will later update the remaining items with current = n
                    // don't deletre it yet as we need to account for multiple items that are the same
                    //    typically in the Windows software listing
                    // unset($db_result[$key]);
                    $db_item->updated = 'y';
                    // set the $id so we can link to this row from graph, etc tables
                    $id = $db_item->id;
                    // stop the loop
                    break;
                } else {
                    // no match - $flag = 'insert' stays unchanged
                }
            }
            // we have looped through the database items
            // INSERT because the $flag is set to insert
            if ($flag == 'insert') {
                # $input_item->system_id  = $details->id; # this will be changed when we convert the system table
                $input_item->system_id  = $details->id;
                $input_item->current  = 'y';
                $input_item->first_seen = (string)$details->last_seen;
                $input_item->last_seen  = (string)$details->last_seen;
                $data = array();
                $set_fields = '';
                $set_values = '';
                foreach ($input_item as $key => $value) {
                    foreach($fields as $field) {
                        if ($key == $field) {
                            $set_fields .= " `$key`, ";
                            $set_values .= " ?, ";
                            $data[] = "$value";
                        }
                    }
                }
                $set_fields = substr($set_fields, 0, -2);
                $set_values = substr($set_values, 0, -2);
                $sql = "INSERT INTO `$table` ( $set_fields ) VALUES ( $set_values ) ";
                $sql = $this->clean_sql($sql);
                $query = $this->db->query($sql, $data);
                $id = $this->db->insert_id();

                if ($alert and strtolower($create_alerts) == 'y') {
                    // We have existing items and this is a new item - raise an alert
                    $alert_details = '';
                    foreach ($match_columns as $key => $value) {
                        $alert_details .= $value . ' is ' . $input_item->$value . ', ';
                    }
                    $alert_details = substr($alert_details, 0, -2);
                    $alert_details = "Item added to $table - " . $alert_details;
                    if (!isset($details->last_seen) or $details->last_seen == '0000-00-00 00:00:00' or $details->last_seen =='') {
                        $sql = "SELECT last_seen FROM `system` WHERE id = ?";
                        $sql = $this->clean_sql($sql);
                        $data = array($details->id);
                        $query = $this->db->query($sql, $data);
                        $result = $query->result();
                        $details->last_seen = $result[0]->last_seen;
                    }
                    $sql = "INSERT INTO change_log (system_id, db_table, db_row, db_action, details, `timestamp`) VALUES (?, ?, ?, ?, ?, ?)";
                    $sql = $this->clean_sql($sql);
                    $data = array("$details->id", "$table", "$id", "create", "$alert_details", "$details->last_seen");
                    $query = $this->db->query($sql, $data);
                    # add a count to our chart table
                    $sql = "INSERT INTO chart (`when`, `what`, `org_id`, `count`) VALUES (DATE(NOW()), '" . $table . "_create', " . intval($details->org_id) . ", 1) ON DUPLICATE KEY UPDATE `count` = `count` + 1";
                    $sql = $this->clean_sql($sql);
                    $query = $this->db->query($sql);
                }
            }
            if ((string)$table == 'partition') {
                // insert an entry into the graph table
                $used_percent = @intval(($input_item->used / $input_item->size) * 100);
                $free_percent = @intval(100 - $used_percent);
                $sql = "INSERT INTO graph VALUES (NULL, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
                $sql = $this->clean_sql($sql);
                $data = array(intval($details->id), "$table", intval($id), "$table", intval($used_percent),
                        intval($free_percent), intval($input_item->used), intval($input_item->free), intval($input_item->size), "$details->last_seen");
                $query = $this->db->query($sql, $data);
            }
        }

        // remove the duplicated DB_items
        foreach ($db_result as $key => $db_item) {
            if ($db_item->updated) {
                unset($db_result[$key]);
            }
        }

        // we have now inserted or updated all items in the audit set
        // we have also unset any items that were inserted (from the audit set above) from the db set
        // any remaining rows in the db set should have their current flag set to n as they were not found in the audit set
        if (count($db_result) > 0) {
            $log_details->message = 'Inserting change logs (' . $table . ') for '.@ip_address_from_db($details->ip).' ('.$name.')';
            $log_details->severity = 7;
            stdlog($log_details);
        }
        foreach ($db_result as $db_item) {
            if (strtolower($delete_noncurrent) == 'y') {
                $sql = "DELETE FROM `$table` WHERE `id` = ?";
                $sql = $this->clean_sql($sql);
                $data = array($db_item->id);
                $query = $this->db->query($sql, $data);

            } else {
                $sql = "UPDATE `$table` SET current = 'n' WHERE id = ?";
                $sql = $this->clean_sql($sql);
                $data = array($db_item->id);
                $query = $this->db->query($sql, $data);
                if (strtolower($create_alerts) == 'y') {
                    $alert_details = '';
                    foreach ($match_columns as $key => $value) {
                        $alert_details .= $value . ' is ' . $db_item->$value . ', ';
                    }
                    $alert_details = substr($alert_details, 0, -2);
                    $alert_details = "Item removed from $table - " . $alert_details;
                    if (!isset($details->last_seen) or $details->last_seen == '0000-00-00 00:00:00' or $details->last_seen =='') {
                        $sql = "SELECT last_seen FROM `system` WHERE id = ?";
                        $sql = $this->clean_sql($sql);
                        $data = array($details->id);
                        $query = $this->db->query($sql, $data);
                        $result = $query->result();
                        $details->last_seen = $result[0]->last_seen;
                    }
                    $sql = "INSERT INTO change_log (system_id, db_table, db_row, db_action, details, `timestamp`) VALUES (?, ?, ?, ?, ?, ?)";
                    $sql = $this->clean_sql($sql);
                    $data = array("$details->id", "$table", "$db_item->id", "delete", "$alert_details", "$details->last_seen");
                    $query = $this->db->query($sql, $data);
                    # add a count to our chart table
                    $sql = "INSERT INTO chart (`when`, `what`, `org_id`, `count`) VALUES (DATE(NOW()), '" . $table . "_delete', " . intval($details->org_id) . ", 1) ON DUPLICATE KEY UPDATE `count` = `count` + 1";
                    $sql = $this->clean_sql($sql);
                    $query = $this->db->query($sql);
                }
            }
        }
        // update the audit log
        $this->m_audit_log->update('debug', "$table - end", $details->id, $details->last_seen);
        $log_details->message = 'Processing component (' . $table . ') end for '.@ip_address_from_db($details->ip).' ('.$name.')';
        $log_details->severity = 7;
        stdlog($log_details);
        return;
    }
示例#11
0
    public function update_system($details, $display = 'n')
    {
        if (!isset($details->id) or $details->id == '') {
            # this is an update - we need a system.id
            return;
        }

        # nasty hack because when a simplexmlobject is sent (ie, from audit_windows.vbs)
        # the foreach iterators below don't work.
        # if we cast it to an "object", it stays as a SimpleXMLObject and doesn't work
        # because our XML is quite simple, we can cast it to an array and back to a 'normal'
        # object and the foreach below works.
        $details = (object) $details;
        $details = (array) $details;
        $details = (object) $details;

        if (isset($details->ip) and $details->ip != '') {
            $temp_ip = $details->ip.' ';
        } else {
            $temp_ip = '';
        }

        $log_details = new stdClass();
        $log_details->message = 'System update start for '.ip_address_from_db($temp_ip).'('.$details->hostname.') (System ID '.$details->id.')';
        $log_details->severity = 7;
        $log_details->file = 'system';
        if ($display != 'y') {
            $display = 'n';
        }
        $log_details->display = $display;
        unset($display);

        stdlog($log_details);

        unset($temp_ip);

        # If we have an ip address in the hostname field - see if we have other attributes available
        if (filter_var($details->hostname, FILTER_VALIDATE_IP)) {
            # try getting the dns hostname
            $details->hostname = strtolower(gethostbyaddr($details->ip));
            # make sure we use the hostname and not a fqdn if returned
            if (strpos($details->hostname, ".") != false) {
                if (!filter_var($details->hostname, FILTER_VALIDATE_IP)) {
                    # we got a FQDN back from DNS - split it up
                    $details->fqdn = strtolower($details->hostname);
                    $i = explode(".", $details->hostname);
                    $details->hostname = $i[0];
                    unset($i[0]);
                    $details->domain = implode(".", $i);
                    unset($i);
                } else {
                    # we got an ip address back from DNS which is now the hostname
                }
            } else {
                # we should have a real hostname if we get to here
            }
        }
        if (filter_var($details->hostname, FILTER_VALIDATE_IP) and isset($details->sysName) and $details->sysName != '') {
            # use the sysName from SNMP if set
            $details->hostname = $details->sysName;
        }

        $sql = "SELECT name FROM system WHERE id = ?";
        $sql = $this->clean_sql($sql);
        $data = array("$details->id");
        $query = $this->db->query($sql, $data);
        $result = $query->row();
        $db_name = $result->name;
        if (empty($db_name)) {
            if (!empty($details->hostname) != '' and empty($details->name)) {
                $details->name = $details->hostname;
            }
        }
        # if submitting an nmap scan, do not update the type or type
        if (isset($details->last_seen_by) and $details->last_seen_by == 'nmap') {
            unset($details->type);
        } else {
            if (!empty($details->type)) {
                $details->type = strtolower($details->type);
            }
        }

        # for removing existing symbols
        if (isset($details->os_name)) {
            $details->os_name = str_ireplace("(r)", "", $details->os_name);
            $details->os_name = str_ireplace("(tm)", "", $details->os_name);
        }

        # we check a few  items when we are submitting an audit script result
        # if they are blank (previously submitted info is incomplete) we over write them
        if (isset($details->last_seen_by) and ($details->last_seen_by == 'audit' or $details->last_seen_by == 'snmp' or $details->last_seen_by == 'ipmi')) {
            $sql = "SELECT * FROM system WHERE id = ? LIMIT 1";
            $sql = $this->clean_sql($sql);
            $data = array("$details->id");
            $query = $this->db->query($sql, $data);
            $row = $query->row();

            if (count($row) > 0) {
                if (strlen($row->hostname) > 15 and isset($details->hostname) and strlen($details->hostname) == 15) {
                    unset($details->hostname);
                }

                if (isset($details->manufacturer) and (
                    (strripos($details->manufacturer, "vmware") !== false) or
                    (strripos($details->manufacturer, "parallels") !== false) or
                    (strripos($details->manufacturer, "virtual") !== false))) {
                    $details->form_factor = 'Virtual';
                }

                if ($row->icon != '') {
                    if (isset($details->icon)) {
                        unset($details->icon);
                    }
                } else {
                    if (!isset($details->icon) or $details->icon == '') {
                        $details->icon = $details->type;
                    }
                }
            } // end of row count > 0
        }

        if (!isset($details->timestamp) or $details->timestamp == '') {
            $details->timestamp = $this->config->config['timestamp'];
        }

        if (!isset($details->original_timestamp) or $details->original_timestamp == '') {
            $sql = "SELECT last_seen FROM system WHERE id = ?";
            $sql = $this->clean_sql($sql);
            $data = array("$details->id");
            $query = $this->db->query($sql, $data);
            $row = $query->row();
            $details->original_timestamp = $row->last_seen;
        }

        if (isset($details->ip)) {
            $details->ip = ip_address_to_db($details->ip);
        }

        # if we don't have a real ip address, remove it
        if ((isset($details->ip)) and
            ($details->ip == '' or
            $details->ip == '0.0.0.0' or
            $details->ip == '000.000.000.000')) {
            unset($details->ip);
        }

        $fields = implode(' ', $this->db->list_fields('system'));
        foreach ($details as $key => $value) {
            if (($key != '') and ($value != '')) {
                # need to iterate through available columns and only insert where $key == valid column name
                if ($key != 'id' and stripos($fields, ' '.$key.' ') !== false) {
                    // OK, we have a valid attribute name ($key)
                    // get the current value
                    $sql = "SELECT `$key` AS `$key` FROM `system` WHERE `id` = ?";
                    $data = array(intval($details->id));
                    $query = $this->db->query($sql, $data);
                    $result = $query->result();
                    $previous_value = $result[0]->{$key};
                    # get the current entry in the edit_log
                    $sql = "SELECT * FROM `edit_log` WHERE `system_id` = ? AND `db_table` = 'system' AND `db_column` = ? ORDER BY `timestamp` DESC LIMIT 1";
                    $data = array(intval($details->id), "$key");
                    $query = $this->db->query($sql, $data);
                    $result = $query->result();
                    if (!empty($result[0]->weight)) {
                        $previous_weight = intval($result[0]->weight);
                    } else {
                        $previous_weight = 10000;
                    }
                    // calculate the weight
                    $weight = intval($this->weight($details->last_seen_by));
                    if ($weight <= $previous_weight and $value != $previous_value) {
                         if ($key != 'id' and $key != 'last_seen' and $key != 'last_seen_by' and $key != 'first_seen') {
                            // update the system table
                            $sql = "UPDATE `system` SET `" . $key . "` = ? WHERE id = ?";
                            $data = array((string)$value, intval($details->id));
                            $query = $this->db->query($sql, $data);
                            // insert an entry into the edit table
                            $columns_that_dont_get_edit_log = ' id sysUpTime uptime ';
                            if (stripos($columns_that_dont_get_edit_log, $key) === false) {
                                $sql = "INSERT INTO edit_log VALUES (NULL, ?, ?, 'Data was changed', ?, ?, 'system', ?, NOW(), ?, ?)";
                                $data = array(0, intval($details->id), (string)$details->last_seen_by, intval($weight), (string)$key, (string)$value, (string)$previous_value);;
                                $query = $this->db->query($sql, $data);
                            }
                        }
                    } else {
                        # We have an existing edit_log entry with a more important change - don't touch the `system`.`$key` value
                    }
                }

            }
        }

        if (!empty($details->last_seen_by)) {
            $last_seen_by = $details->last_seen_by;
        } else {
            $last_seen_by = '';
        }
        if (!empty($details->last_seen)) {
            $last_seen = $details->last_seen;
        } else {
            $last_seen = '';
        }
        $sql = "UPDATE system SET `last_seen_by` = ?, `last_seen` = ? WHERE id = ?";
        $query = $this->db->query($sql, array((string)$last_seen_by, (string)$last_seen, intval($details->id)));


        # finally, update the device icon
        $this->m_system->reset_icons($details->id);

        if (isset($details->mac_address) and $details->mac_address != '' and
            isset($details->ip) and $details->ip != '' and
            isset($details->subnet) and $details->subnet != '') {
            # we need to check if we have an entry in `network`
            # if we do not, but we have details (ex- an nmap device that previously existed but did not have a MAC, but now does)
            # we need to insert it.
            # ideally this would have already been done when the device was initially discovered, but we cannot count on that.
            # need to check if an entry in `network` exists and if it does not AND we have details, insert something

            # search for any entries in `ip`
            $sql = "SELECT * FROM ip WHERE system_id = ? AND mac = ? AND current = 'y' AND ip = ?";
            $sql = $this->clean_sql($sql);
            $data = array("$details->id", "$details->mac_address", "$details->ip");
            $query = $this->db->query($sql, $data);
            $result = $query->result();
            if (count($result) == 0) {
                # no match - insert
                $sql = "INSERT INTO ip (id, system_id, current, first_seen, last_seen, mac, net_index, ip, netmask, version, network, set_by) VALUES(NULL, ?, 'y', ?, ?, ?, '', ?, ?, '', '', '')";
                $sql = $this->clean_sql($sql);
                $data = array("$details->id", "$details->timestamp", "$details->timestamp", "$details->mac_address", "$details->ip", "$details->subnet");
                $query = $this->db->query($sql, $data);
            } else {
                # match - update timestamp only
                $sql = "UPDATE ip SET last_seen = ? WHERE system_id = ? AND mac = ? AND current = 'y' AND ip = ?";
                $sql = $this->clean_sql($sql);
                $data = array("$details->timestamp", "$details->id", "$details->mac_address", "$details->ip");
                $query = $this->db->query($sql, $data);
            }
        }

        if (isset($details->ip) and $details->ip != '') {
            $temp_ip = $details->ip.' ';
        } else {
            $temp_ip = '';
        }

        # check if we have a matching entry in the vm table and update it if required
        if (isset($details->uuid) and $details->uuid != '') {
            if (!empty($details->serial)) {
                # becauseWindows doesn't supply an identical UUID, but it does supply the required digits, make a UUID from the serial
                # which is taken from Win32_ComputerSystemProduct.IdentifyingNumber
                # Vmware supplies - 564d3739-b4cb-1a7e-fbb1-b10dcc0335e1
                # audit_windows supples - VMware-56 4d 37 39 b4 cb 1a 7e-fb b1 b1 0d cc 03 35 e1
                $windows_vm_uuid = str_ireplace('VMware-', '', $details->serial);
                $windows_vm_uuid = str_ireplace('-', ' ', $windows_vm_uuid);
                $windows_vm_uuid = strtolower($windows_vm_uuid);
                $windows_vm_uuid = str_ireplace(' ', '', $windows_vm_uuid);
                $windows_vm_uuid = substr($windows_vm_uuid, 0, 8) . '-'. substr($windows_vm_uuid, 8, 4) . '-' . substr($windows_vm_uuid, 12, 4) . '-' . substr($windows_vm_uuid, 16, 4) . '-' . substr($windows_vm_uuid, 20, 12);
            } else {
                $windows_vm_uuid = '';
            }
            $sql = "SELECT vm.id, vm.system_id AS 'vm_system_id', system.hostname AS 'vm_server_name' FROM vm, system WHERE LOWER(vm.uuid) = LOWER(?) OR LOWER(vm.uuid) = LOWER(?) AND vm.current = 'y' and vm.system_id = system.id and vm.uuid != ''";
            $sql = $this->clean_sql($sql);
            $data = array("$details->uuid", "$windows_vm_uuid");
            $query = $this->db->query($sql, $data);
            if ($query->num_rows() > 0) {
                $row = $query->row();
                $temp_vm_id = $row->id;
                $details->vm_system_id = $row->vm_system_id;
                $details->vm_server_name = $row->vm_server_name;
                $sql = "SELECT icon  FROM system WHERE system.id = ?";
                $sql = $this->clean_sql($sql);
                $data = array($details->id);
                $query = $this->db->query($sql, $data);
                $row = $query->row();
                $details->icon = $row->icon;
                $sql = "UPDATE vm SET guest_system_id = ?, icon = ? WHERE id = ?";
                $sql = $this->clean_sql($sql);
                $data = array($details->id, "$details->icon", "$temp_vm_id");
                $query = $this->db->query($sql, $data);
                $sql = "UPDATE system SET vm_system_id = ?, vm_server_name = ? WHERE id = ?";
                $sql = $this->clean_sql($sql);
                $data = array($details->vm_system_id, $details->vm_server_name, $details->id);
                $query = $this->db->query($sql, $data);
            }
        }

        if (empty($details->org_id)) {
            $sql = "SELECT org_id FROM system WHERE id = ?";
            $sql = $this->clean_sql($sql);
            $data = array($details->id);
            $query = $this->db->query($sql, $data);
            $row = $query->row();
            $details->org_id = $row->org_id;
        }

        # add a count to our chart table
        $sql = "INSERT INTO chart (`when`, `what`, `org_id`, `count`) VALUES (DATE(NOW()), '" . $details->last_seen_by . "', " . $details->org_id . ", 1) ON DUPLICATE KEY UPDATE `count` = `count` + 1";
        $sql = $this->clean_sql($sql);
        $query = $this->db->query($sql);

        $log_details->message = 'System update end for '.ip_address_from_db($temp_ip).'('.$details->hostname.') (System ID '.$details->id.')';
        stdlog($log_details);
        unset($log_details);
        unset($temp_ip);
    }
示例#12
0
 function add_system()
 {
     $this->benchmark->mark('code_start');
     $this->load->helper('url');
     set_time_limit(600);
     $this->load->helper('html');
     echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \r\n\t\t\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\r\n\t\t<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"en\" xml:lang=\"en\">";
     echo meta('Content-type', 'text/html; charset=utf-8', 'equiv');
     echo "<head>\r\n\t\t<title>Open-AudIT</title>\r\n\t\t</head>\n\r\n\t\t<body>\n";
     echo "<a href='" . base_url() . "index.php/system'>Back to input page</a><br />\n";
     echo "<a href='" . base_url() . "index.php'>Front Page</a><br />\n";
     $this->load->model("m_alerts");
     $this->load->model("m_bios");
     $this->load->model("m_database");
     $this->load->model("m_database_details");
     $this->load->model("m_dns");
     $this->load->model("m_group");
     $this->load->model("m_hard_drive");
     $this->load->model("m_ip_address");
     $this->load->model("m_log");
     $this->load->model("m_memory");
     $this->load->model("m_monitor");
     $this->load->model("m_motherboard");
     $this->load->model("m_network_card");
     $this->load->model("m_optical_drive");
     $this->load->model("m_partition");
     $this->load->model("m_print_queue");
     $this->load->model("m_printer");
     $this->load->model("m_processor");
     $this->load->model("m_route");
     $this->load->model("m_scsi_controller");
     $this->load->model("m_service");
     $this->load->model("m_share");
     $this->load->model("m_software");
     $this->load->model("m_software_key");
     $this->load->model("m_sound");
     $this->load->model("m_sys_man_audits");
     $this->load->model("m_user");
     $this->load->model("m_video");
     $this->load->model("m_variable");
     $this->load->model("m_windows");
     $this->load->model("m_webserver");
     $this->load->model("m_oa_general");
     #date_default_timezone_set("Australia/Queensland");
     $timestamp = date('Y-m-d H:i:s');
     # first, undo what the XSS filter does
     $input = html_entity_decode($_POST['form_systemXML']);
     # then convert to UTF8 (if required)
     if (mb_detect_encoding($input) != "UTF-8") {
         $input = utf8_encode($input);
     }
     $xml_input = iconv("UTF-8", "UTF-8//TRANSLIT", $input);
     libxml_use_internal_errors(true);
     $xml = simplexml_load_string($xml_input);
     if ($xml === false) {
         echo "Failed loading XML\n";
         foreach (libxml_get_errors() as $error) {
             echo "<pre>\n";
             print_r($error);
             echo "</pre>\n";
         }
         exit;
     }
     try {
         $xml = new SimpleXMLElement($xml_input, LIBXML_NOCDATA);
     } catch (Exception $e) {
         # not a valid XML string
         $xml_split = explode("\n", $xml_input, 10);
         $hostname = str_replace("\t\t<system_hostname>", "", $xml_split[5]);
         $hostname = str_replace("</system_hostname>", "", $hostname);
         $error_output = "Invalid XML input for: " . $hostname;
         error_log($error_output);
         exit;
     }
     foreach ($xml->children() as $child) {
         if ($child->getName() == 'sys') {
             $details = (object) $xml->sys;
             $details->system_id = '';
             $details->fqdn = $details->hostname . "." . $details->domain;
             $details->type = 'computer';
             $details->man_type = 'computer';
             $details->system_key = $this->m_system->create_system_key($details);
             $i = $this->m_system->find_system($details);
             $details->system_id = $i;
             $details->last_seen = $details->timestamp;
             $details->last_seen_by = 'audit';
             $details->last_user = '';
             $details->audits_ip = ip_address_to_db($_SERVER['REMOTE_ADDR']);
             if ($i == '') {
                 # insert a new system
                 $details->system_id = $this->m_system->insert_system($details);
                 echo "SystemID (new): <a href='" . base_url() . "index.php/main/system_display/" . $details->system_id . "'>" . $details->system_id . "</a>.<br />\n";
             } else {
                 # update an existing system
                 $details->original_timestamp = $this->m_oa_general->get_attribute('system', 'timestamp', $details->system_id);
                 $this->m_system->update_system($details);
                 echo "SystemID (updated): <a href='" . base_url() . "index.php/main/system_display/" . $details->system_id . "'>" . $details->system_id . "</a>.<br />\n";
             }
             $this->m_sys_man_audits->insert_audit($details);
         }
         if ($child->getName() == 'audit_wmi_fail') {
             $this->m_sys_man_audits->update_audit($details, $child->getName());
             $this->m_sys_man_audits->update_wmi_fails($xml->audit_wmi_fail, $details);
         }
         if ($child->getName() == 'windows') {
             $this->m_sys_man_audits->update_audit($details, $child->getName());
             $this->m_windows->process_windows($xml->windows, $details);
         }
         if ($child->getName() == 'bios') {
             $this->m_sys_man_audits->update_audit($details, $child->getName());
             $this->m_bios->process_bios($xml->bios, $details);
         }
         if ($child->getName() == 'processor') {
             $this->m_sys_man_audits->update_audit($details, $child->getName());
             $this->m_processor->process_processor($xml->processor, $details);
         }
         if ($child->getName() == 'motherboard') {
             $this->m_sys_man_audits->update_audit($details, $child->getName());
             $this->m_motherboard->process_motherboard($xml->motherboard, $details);
         }
         if ($child->getName() == 'database') {
             $this->m_sys_man_audits->update_audit($details, $child->getName());
             $this->m_database->process_database($xml->database, $details);
         }
         if ($child->getName() == 'webserver') {
             $this->m_sys_man_audits->update_audit($details, $child->getName());
             $this->m_webserver->process_webserver($xml->webserver, $details);
         }
         if ($child->getName() == 'services') {
             $this->m_sys_man_audits->update_audit($details, $child->getName());
             $this->m_service->process_service($xml->services, $details);
         }
         if ($child->getName() == 'software') {
             $this->m_sys_man_audits->update_audit($details, $child->getName());
             $this->m_software->process_software($xml->software, $details);
         }
         if ($child->getName() == 'dns') {
             $this->m_sys_man_audits->update_audit($details, $child->getName());
             foreach ($xml->dns->dns_entry as $input) {
                 $this->m_dns->process_dns($input, $details);
             }
         }
         if ($child->getName() == 'database_details') {
             $this->m_sys_man_audits->update_audit($details, $child->getName());
             foreach ($xml->database_details->details as $input) {
                 $this->m_database_details->process_db_details($input, $details);
             }
         }
         if ($child->getName() == 'groups') {
             $this->m_sys_man_audits->update_audit($details, $child->getName());
             foreach ($xml->groups->group as $input) {
                 $this->m_group->process_group($input, $details);
             }
         }
         if ($child->getName() == 'hard_disks') {
             $this->m_sys_man_audits->update_audit($details, $child->getName());
             foreach ($xml->hard_disks->hard_disk as $input) {
                 $this->m_hard_drive->process_hard_drive($input, $details);
             }
         }
         if ($child->getName() == 'logs') {
             $this->m_sys_man_audits->update_audit($details, $child->getName());
             foreach ($xml->logs->log as $input) {
                 $this->m_log->process_log($input, $details);
             }
         }
         if ($child->getName() == 'memory') {
             $this->m_sys_man_audits->update_audit($details, $child->getName());
             foreach ($xml->memory->slot as $input) {
                 $this->m_memory->process_memory($input, $details);
             }
         }
         if ($child->getName() == 'monitors') {
             $this->m_sys_man_audits->update_audit($details, $child->getName());
             foreach ($xml->monitors->monitor as $input) {
                 $this->m_monitor->process_monitor($input, $details);
             }
         }
         if ($child->getName() == 'addresses') {
             $this->m_sys_man_audits->update_audit($details, $child->getName());
             foreach ($xml->addresses->ip_address as $input) {
                 $this->m_ip_address->process_addresses($input, $details);
             }
         }
         if ($child->getName() == 'partitions') {
             $this->m_sys_man_audits->update_audit($details, $child->getName());
             foreach ($xml->partitions->partition as $input) {
                 $this->m_partition->process_partitions($input, $details);
             }
         }
         if ($child->getName() == 'printers') {
             $this->m_sys_man_audits->update_audit($details, $child->getName());
             foreach ($xml->printers->printer as $input) {
                 $this->m_printer->process_printer($input, $details);
                 $this->m_print_queue->process_print_queue($input, $details);
             }
         }
         if ($child->getName() == 'routes') {
             $this->m_sys_man_audits->update_audit($details, $child->getName());
             foreach ($xml->routes->route as $input) {
                 $this->m_route->process_route($input, $details);
             }
         }
         if ($child->getName() == 'shares') {
             $this->m_sys_man_audits->update_audit($details, $child->getName());
             foreach ($xml->shares->share as $input) {
                 $this->m_share->process_shares($input, $details);
             }
         }
         if ($child->getName() == 'software_keys') {
             $this->m_sys_man_audits->update_audit($details, $child->getName());
             foreach ($xml->software_keys->key as $input) {
                 $this->m_software_key->process_software_key($input, $details);
             }
         }
         if ($child->getName() == 'sound_cards') {
             $this->m_sys_man_audits->update_audit($details, $child->getName());
             foreach ($xml->sound_cards->sound_card as $input) {
                 $this->m_sound->process_sound_cards($input, $details);
             }
         }
         if ($child->getName() == 'users') {
             $this->m_sys_man_audits->update_audit($details, $child->getName());
             foreach ($xml->users->user as $input) {
                 $this->m_user->process_user($input, $details);
             }
         }
         if ($child->getName() == 'variables') {
             $this->m_sys_man_audits->update_audit($details, $child->getName());
             foreach ($xml->variables->variable as $input) {
                 $this->m_variable->process_variable($input, $details);
             }
         }
         if ($child->getName() == 'video_cards') {
             $this->m_sys_man_audits->update_audit($details, $child->getName());
             foreach ($xml->video_cards->video_card as $input) {
                 $this->m_video->process_video_cards($input, $details);
             }
         }
         if ($child->getName() == 'scsi_controllers') {
             $this->m_sys_man_audits->update_audit($details, $child->getName());
             foreach ($xml->scsi_controllers->scsi_controller as $input) {
                 $this->m_scsi_controller->process_scsi_controller($input, $details);
             }
         }
         if ($child->getName() == 'optical_drives') {
             $this->m_sys_man_audits->update_audit($details, $child->getName());
             foreach ($xml->optical_drives->optical_drive as $input) {
                 $this->m_optical_drive->process_optical_drives($input, $details);
             }
         }
         if ($child->getName() == 'network_cards') {
             $this->m_sys_man_audits->update_audit($details, $child->getName());
             foreach ($xml->network_cards->network_card as $input) {
                 $this->m_network_card->process_network_cards($input, $details);
             }
         }
     }
     $this->m_sys_man_audits->update_audit($details, 'finished xml processing');
     // Now generate any needed alerts
     $this->m_sys_man_audits->update_audit($details, 'generate initial audit alert');
     if ($details->original_timestamp == '') {
         // We have a new PC, so generate an alert
         $this->m_alerts->generate_alert($details->system_id, 'system', $details->system_id, 'system detected', $details->timestamp);
         // And also set it's IP Address in system.man_ip_address
         $this->m_ip_address->set_initial_address($details);
     }
     // double check man_ip_address
     $this->m_sys_man_audits->update_audit($details, 'check man_ip_address');
     $dhcp = FALSE;
     $network_details = $this->m_network_card->get_system_network($details->system_id);
     foreach ($network_details as $card) {
         if ($card->net_dhcp_enabled != '') {
             $dhcp = TRUE;
         }
     }
     $this->m_sys_man_audits->update_audit($details, 'double check man_ip_address');
     $man_ip_address = $this->m_system->check_man_ip_address($details->system_id);
     if ($man_ip_address == '000.000.000.000' or $man_ip_address == '' or $dhcp == TRUE) {
         $this->m_ip_address->set_initial_address($details);
     }
     $this->m_sys_man_audits->update_audit($details, 'now generate any needed alerts');
     if ($details->original_timestamp != '' && $details->exist_type != 'bulk') {
         $this->m_sys_man_audits->update_audit($details, 'alerts');
         // We have to go through all tables, checking for
         // entries with current_timestamp = first_timestamp
         $this->m_bios->alert_bios($details);
         $this->m_group->alert_group($details);
         $this->m_hard_drive->alert_hard_drive($details);
         if ($dhcp != TRUE) {
             $this->m_ip_address->alert_ip_address($details);
         }
         $this->m_log->alert_log($details);
         $this->m_memory->alert_memory($details);
         $this->m_monitor->alert_monitor($details);
         $this->m_motherboard->alert_motherboard($details);
         $this->m_network_card->alert_network_card($details);
         $this->m_optical_drive->alert_optical_drive($details);
         $this->m_partition->alert_partition($details);
         #TODO - check if NOT a USB drive
         $this->m_processor->alert_processor($details);
         if ($dhcp != TRUE) {
             $this->m_route->alert_route($details);
         }
         $this->m_scsi_controller->alert_scsi_controller($details);
         $this->m_service->alert_service($details);
         $this->m_share->alert_share($details);
         $this->m_software->alert_software($details);
         $this->m_software_key->alert_software_key($details);
         $this->m_sound->alert_sound($details);
         $this->m_variable->alert_variable($details);
         $this->m_video->alert_video($details);
         #$this->m_database_details->alert_db_details($details);  #TODO check if this is complete
     }
     $this->load->model("m_oa_group");
     // update any tags for new printers
     $this->m_sys_man_audits->update_audit($details, 'network printers');
     $network_printers = $this->m_printer->get_new_network_printer($details);
     if (count($network_printers) > 0) {
         foreach ($network_printers as $printer) {
             $this->m_oa_group->update_system_groups($printer);
         }
     }
     // Finally, update any tags for this system
     $this->m_sys_man_audits->update_audit($details, 'system groups');
     $this->m_oa_group->update_system_groups($details);
     $this->m_sys_man_audits->update_audit($details, "");
     $this->benchmark->mark('code_end');
     echo "<br />Time: " . $this->benchmark->elapsed_time('code_start', 'code_end') . ' seconds.';
     echo "</body>\n</html>";
 }