function process_prior($window, $id) { global $mainwin, $prior_table; switch ($id) { case ID_PRIORITYLIST: update_prior_controls($window); break; case ID_NEWITEM: $name = wb_get_text(wb_get_control($window, ID_NAME)); db_edit_record($prior_table, 0, "name", array($name)); update_priors($window); update_prior_controls($window); break; case ID_SETITEM: $name = wb_get_text(wb_get_control($window, ID_NAME)); $itemlist = wb_get_control($window, ID_PRIORITYLIST); $id = db_get_id($prior_table, wb_get_selected($itemlist)); db_edit_record($prior_table, $id, "name", array($name)); update_priors($window); update_prior_controls($window); break; case ID_DELETEITEM: $itemlist = wb_get_control($window, ID_PRIORITYLIST); $selected = wb_get_selected($itemlist); $id = db_get_id($prior_table, $selected); db_delete_records($prior_table, db_get_id($prior_table, $selected)); update_priors($window); update_prior_controls($window); break; case ID_MOVEUP: $itemlist = wb_get_control($window, ID_PRIORITYLIST); $selected = wb_get_selected($itemlist); $id = db_get_id($prior_table, $selected); db_swap_records($prior_table, db_get_id($prior_table, $selected), db_get_id($prior_table, $selected - 1)); update_priors($window); update_prior_controls($window); break; case ID_MOVEDOWN: $itemlist = wb_get_control($window, ID_PRIORITYLIST); $selected = wb_get_selected($itemlist); $id = db_get_id($prior_table, $selected); db_swap_records($prior_table, db_get_id($prior_table, $selected), db_get_id($prior_table, $selected + 1)); update_priors($window); update_prior_controls($window); break; case IDCANCEL: case IDCLOSE: case IDOK: wb_destroy_window($window); break; } }
function ws_delete_configs($window_name, $form = '') { global $conf, $self, $onadb; global $images, $color, $style; // If the user supplied an array in a string, build the array and store it in $form $form = parse_options_string($form); // Load the host record list($status, $rows, $host) = ona_find_host($form['host_id']); if (!$host['id']) { array_pop($_SESSION['ona']['work_space']['history']); $html .= "<br><center><font color=\"red\"><b>Host doesn't exist!</b></font></center>"; $response = new xajaxResponse(); $response->addAssign("work_space_content", "innerHTML", $html); return $response->getXML(); } // Check permissions if (!(auth('host_config_admin') and authlvl($host['lvl']))) { $response = new xajaxResponse(); $response->addScript("alert('Permission denied!');"); return $response->getXML(); } // Load the config type list($status, $rows, $type) = ona_get_config_type_record(array('id' => $form['type_id'])); if ($status or !$rows) { $response = new xajaxResponse(); $response->addScript("alert('ERROR => Invalid config type!');"); return $response->getXML(); } // Delete the config text records that match // FIXME, this should probably use a module, but there isn't one! list($status, $rows) = db_delete_records($onadb, 'configurations', array('host_id' => $host['id'], 'configuration_type_id' => $type['id'])); if ($status or !$rows) { $response = new xajaxResponse(); $response->addScript("alert('Delete failed!');"); return $response->getXML(); } // Insert the new html into the window // Instantiate the xajaxResponse object $response = new xajaxResponse(); if ($form['js']) { $response->addScript($form['js']); } return $response->getXML(); }
function host_del($options = "") { global $conf, $self, $onadb; printmsg("DEBUG => host_del({$options}) called", 3); // Version - UPDATE on every edit! $version = '1.19'; // Parse incoming options string to an array $options = parse_options($options); // Sanitize options[commit] (default is no) $options['commit'] = sanitize_YN($options['commit'], 'N'); // Return the usage summary if we need to if ($options['help'] or !$options['host']) { // NOTE: Help message lines should not exceed 80 characters for proper display on a console $self['error'] = 'ERROR => Insufficient parameters'; return array(1, <<<EOM host_del-v{$version} Deletes a host, and all related records from the database Synopsis: host_del [KEY=VALUE] ... Required: host=NAME[.DOMAIN] or ID Hostname or ID of the host to delete Optional: commit=[yes|no] Commit db transaction (no) Notes: * A host won't be deleted if it has config text records * A host won't be deleted if it's configured as a dns or dhcp server EOM ); } // Find the host (and domain) record from $options['host'] list($status, $rows, $host) = ona_find_host($options['host']); printmsg("DEBUG => host_del() Host: {$host['fqdn']} ({$host['id']})", 3); if (!$host['id']) { printmsg("DEBUG => Unknown host: {$host['fqdn']}", 3); $self['error'] = "ERROR => Unknown host: {$host['fqdn']}"; return array(2, $self['error'] . "\n"); } // Check permissions if (!auth('host_del') or !authlvl($host['LVL'])) { $self['error'] = "Permission denied!"; printmsg($self['error'], 0); return array(10, $self['error'] . "\n"); } // If "commit" is yes, delete the host if ($options['commit'] == 'Y') { $text = ""; $add_to_error = ""; $add_to_status = 0; // SUMMARY: // Don't allow a delete if it is performing server duties // Don't allow a delete if config text entries exist // Delete Interfaces // Delete interface cluster entries // Delete dns records // Delete custom attributes // Delete DHCP entries // Delete device record if it is the last host associated with it. // // IDEA: If it's the last host in a domain (maybe do the same for or a networks & vlans in the interface delete) // It could just print a notice or something. // Check that it is the host is not performing server duties // FIXME: MP mostly fixed..needs testing $serverrow = 0; // check ALL the places server_id is used and remove the entry from server_b if it is not used list($status, $rows, $srecord) = db_get_record($onadb, 'dhcp_server_subnets', array('host_id' => $host['id'])); if ($rows) { $serverrow++; } list($status, $rows, $srecord) = db_get_record($onadb, 'dhcp_failover_groups', array('primary_server_id' => $host['id'])); if ($rows) { $serverrow++; } list($status, $rows, $srecord) = db_get_record($onadb, 'dhcp_failover_groups', array('secondary_server_id' => $host['id'])); if ($rows) { $serverrow++; } if ($serverrow > 0) { printmsg("DEBUG => Host ({$host['fqdn']}) cannot be deleted, it is performing duties as a DHCP server!", 3); $self['error'] = "ERROR => Host ({$host['fqdn']}) cannot be deleted, it is performing duties as a DHCP server!"; return array(5, $self['error'] . "\n"); } // Check if host is a dns server $serverrow = 0; list($status, $rows, $srecord) = db_get_record($onadb, 'dns_server_domains', array('host_id' => $host['id'])); if ($rows) { $serverrow++; } if ($serverrow > 0) { printmsg("DEBUG => Host ({$host['fqdn']}) cannot be deleted, it is performing duties as a DNS server!", 3); $self['error'] = "ERROR => Host ({$host['fqdn']}) cannot be deleted, it is performing duties as a DNS server!"; return array(5, $self['error'] . "\n"); } // Display an error if it has any entries in configurations list($status, $rows, $server) = db_get_record($onadb, 'configurations', array('host_id' => $host['id'])); if ($rows) { printmsg("DEBUG => Host ({$host['fqdn']}) cannot be deleted, it has config archives!", 3); $self['error'] = "ERROR => Host ({$host['fqdn']}) cannot be deleted, it has config archives!"; return array(5, $self['error'] . "\n"); } // Delete interface(s) // get list for logging $clustcount = 0; $dnscount = 0; list($status, $rows, $interfaces) = db_get_records($onadb, 'interfaces', array('host_id' => $host['id'])); // Cant delete if one of the interfaces is primary for a cluster foreach ($interfaces as $int) { list($status, $rows, $records) = db_get_records($onadb, 'interface_clusters', array('interface_id' => $int['id'])); $clustcount = $clustcount + $rows; } if ($clustcount) { $self['error'] = "ERROR => host_del() An interface on this host is primary for some interface shares, delete the share or move the interface first."; printmsg($self['error'], 0); return array(5, $self['error'] . "\n"); } // do the interface_cluster delete. This just removes this host from the cluster, not the whole cluster itself // It will error out as well if this interface is the primary in the cluster list($status, $rows) = db_delete_records($onadb, 'interface_clusters', array('host_id' => $host['id'])); if ($status) { $self['error'] = "ERROR => host_del() interface_cluster delete SQL Query failed: {$self['error']}"; printmsg($self['error'], 0); return array(5, $self['error'] . "\n"); } // log deletions printmsg("INFO => {$rows} Shared interface(s) DELETED from {$host['fqdn']}", 0); $add_to_error .= "INFO => {$rows} Shared interface(s) DELETED from {$host['fqdn']}\n"; // Delete each DNS record associated with this hosts interfaces. // foreach ($interfaces as $int) { // // Loop through each dns record associated with this interface. // list($status, $rows, $records) = db_get_records($onadb, 'dns', array('interface_id' => $int['id'])); // if ($rows) { // foreach($records as $record) { // // Run the module // list($status, $output) = run_module('dns_record_del', array('name' => $record['id'], 'type' => $record['type'], 'commit' => 'Y', 'delete_by_module' => 'Y')); // $add_to_error .= $output; // $add_to_status = $add_to_status + $status; // } // } // } // Delete messages // get list for logging list($status, $rows, $records) = db_get_records($onadb, 'messages', array('table_name_ref' => 'hosts', 'table_id_ref' => $host['id'])); // do the delete list($status, $rows) = db_delete_records($onadb, 'messages', array('table_name_ref' => 'hosts', 'table_id_ref' => $host['id'])); if ($status) { $self['error'] = "ERROR => host_del() message delete SQL Query failed: {$self['error']}"; printmsg($self['error'], 0); return array(5, $self['error'] . "\n"); } // log deletions printmsg("INFO => {$rows} Message(s) DELETED from {$host['fqdn']}", 0); $add_to_error .= "INFO => {$rows} Message(s) DELETED from {$host['fqdn']}\n"; // Delete the interfaces.. this should delete dns names and other things associated with interfaces.. foreach ($interfaces as $record) { // Run the module list($status, $output) = run_module('interface_del', array('interface' => $record['id'], 'commit' => 'on', 'delete_by_module' => 'Y')); $add_to_error .= $output; $add_to_status = $add_to_status + $status; } // Delete device record // Count how many hosts use this same device list($status, $rows, $records) = db_get_records($onadb, 'hosts', array('device_id' => $host['device_id'])); // if device count is just 1 do the delete if ($rows == 1) { list($status, $rows) = db_delete_records($onadb, 'devices', array('id' => $host['device_id'])); if ($status) { $self['error'] = "ERROR => host_del() device delete SQL Query failed: {$self['error']}"; printmsg($self['error'], 0); return array(5, $add_to_error . $self['error'] . "\n"); } // log deletions printmsg("INFO => Device record DELETED: [{$record['id']}] no remaining hosts using this device", 0); } else { printmsg("INFO => Device record NOT DELETED: [{$record['id']}] there are other hosts using this device.", 1); } // Delete tag entries list($status, $rows, $records) = db_get_records($onadb, 'tags', array('type' => 'host', 'reference' => $host['id'])); $log = array(); $i = 0; foreach ($records as $record) { $log[$i] = "INFO => Tag DELETED: {$record['name']} from {$host['fqdn']}"; $i++; } //do the delete list($status, $rows) = db_delete_records($onadb, 'tags', array('type' => 'host', 'reference' => $host['id'])); if ($status) { $self['error'] = "ERROR => host_del() Tag delete SQL Query failed: {$self['error']}"; printmsg($self['error'], 0); return array(5, $add_to_error . $self['error'] . "\n"); } //log deletions foreach ($log as $log_msg) { printmsg($log_msg, 0); $add_to_error .= $log_msg . "\n"; } // Delete custom attribute entries // get list for logging list($status, $rows, $records) = db_get_records($onadb, 'custom_attributes', array('table_name_ref' => 'hosts', 'table_id_ref' => $host['id'])); $log = array(); $i = 0; foreach ($records as $record) { list($status, $rows, $ca) = ona_get_custom_attribute_record(array('id' => $record['id'])); $log[$i] = "INFO => Custom Attribute DELETED: {$ca['name']} ({$ca['value']}) from {$host['fqdn']}"; $i++; } //do the delete list($status, $rows) = db_delete_records($onadb, 'custom_attributes', array('table_name_ref' => 'hosts', 'table_id_ref' => $host['id'])); if ($status) { $self['error'] = "ERROR => host_del() Custom attribute delete SQL Query failed: {$self['error']}"; printmsg($self['error'], 0); return array(5, $add_to_error . $self['error'] . "\n"); } //log deletions foreach ($log as $log_msg) { printmsg($log_msg, 0); $add_to_error .= $log_msg . "\n"; } // Delete DHCP options // get list for logging list($status, $rows, $records) = db_get_records($onadb, 'dhcp_option_entries', array('host_id' => $host['id'])); $log = array(); $i = 0; foreach ($records as $record) { list($status, $rows, $dhcp) = ona_get_dhcp_option_entry_record(array('id' => $record['id'])); $log[$i] = "INFO => DHCP entry DELETED: {$dhcp['display_name']}={$dhcp['value']} from {$host['fqdn']}"; $i++; } // do the delete list($status, $rows) = db_delete_records($onadb, 'dhcp_option_entries', array('host_id' => $host['id'])); if ($status) { $self['error'] = "ERROR => host_del() DHCP option entry delete SQL Query failed: {$self['error']}"; printmsg($self['error'], 0); return array(5, $add_to_error . $self['error'] . "\n"); } // log deletions foreach ($log as $log_msg) { printmsg($log_msg, 0); $add_to_error .= $log_msg . "\n"; } // Delete the host list($status, $rows) = db_delete_records($onadb, 'hosts', array('id' => $host['id'])); if ($status) { $self['error'] = "ERROR => host_del() host delete SQL Query failed: {$self['error']}"; printmsg($self['error'], 0); return array(5, $add_to_error . $self['error'] . "\n"); } // Return the success notice if ($add_to_status == 0) { $self['error'] = "INFO => Host DELETED: {$host['fqdn']}"; } printmsg($self['error'], 0); return array($add_to_status, $add_to_error . $self['error'] . "\n"); } // // We are just displaying records that would have been deleted // // SUMMARY: // Display a warning if it is a server // Display a warning if it has config text entries // Display Interfaces // Display dns records // Display custom attributes // Display DHCP entries // Otherwise just display the host record for the host we would have deleted $text = "Record(s) NOT DELETED (see \"commit\" option)\n" . "Displaying record(s) that would have been deleted:\n"; // Display a warning if host is performing server duties list($status, $rows, $srecord) = db_get_record($onadb, 'dhcp_server_subnets', array('host_id' => $host['id'])); if ($rows) { $text .= "\nWARNING! This host is a DHCP server for {$rows} subnet(s)\n"; } list($status, $rows, $srecord) = db_get_record($onadb, 'dns_server_domains', array('host_id' => $host['id'])); if ($rows) { $text .= "\nWARNING! This host is a DNS server for one or more domains!\n"; } list($status, $rows, $srecord) = db_get_record($onadb, 'dhcp_failover_groups', array('primary_server_id' => $host['id'])); if ($rows) { $text .= "\nWARNING! This host is a server that is primary in a DHCP failover group\n"; } list($status, $rows, $srecord) = db_get_record($onadb, 'dhcp_failover_groups', array('secondary_server_id' => $host['id'])); if ($rows) { $text .= "\nWARNING! This host is a server that is secondary in a DHCP failover group\n"; } // Display a warning if it has any configurations list($status, $rows, $server) = db_get_record($onadb, 'configurations', array('host_id' => $host['id'])); if ($rows) { $text .= "\nWARNING! Host can not be deleted, it has config archives!\n"; } if ($rows) { $text .= "\nWARNING! Host will NOT be deleted, due to previous warnings!\n"; } // Display the Host's complete record list($status, $tmp) = host_display("host={$host['id']}&verbose=N"); $text .= "\n" . $tmp; // Display count of messages list($status, $rows, $records) = db_get_records($onadb, 'messages', array('table_name_ref' => 'hosts', 'table_id_ref' => $host['id'])); if ($rows) { $text .= "\nASSOCIATED MESSAGE RECORDS ({$rows}):\n"; } // Display associated interface(s) list($status, $int_rows, $interfaces) = db_get_records($onadb, 'interfaces', array('host_id' => $host['id'])); // show the dns records associated foreach ($interfaces as $record) { list($status, $rows, $dnsrec) = db_get_records($onadb, 'dns', array('interface_id' => $record['id'])); if ($rows) { $text .= "\nASSOCIATED DNS RECORDS ({$rows}) ON INTERFACE (" . ip_mangle($record['ip_addr'], 'dotted') . "):\n"; foreach ($dnsrec as $rec) { // show AAAA or A type as needed if ($record['ip_addr'] > 4294967295 and $rec['type'] == 'A') { $rec['type'] = 'AAAA'; } $text .= " TYPE: [ID:{$rec['id']}] {$rec['type']}, {$rec['name']} -> " . ip_mangle($record['ip_addr'], 'dotted') . "\n"; } } } if ($int_rows) { $text .= "\nASSOCIATED INTERFACE RECORDS ({$int_rows}):\n"; } foreach ($interfaces as $record) { $text .= " [ID:{$record['id']}] " . ip_mangle($record['ip_addr'], 'dotted') . "\n"; } // Display associated interface_clusters(s) list($status, $clust_rows, $interfaceclusters) = db_get_records($onadb, 'interface_clusters', array('host_id' => $host['id'])); if ($clust_rows) { $text .= "\nASSOCIATED SHARED INTERFACE RECORDS ({$clust_rows}):\n"; } foreach ($interfaceclusters as $record) { list($status, $rows, $int) = ona_get_interface_record(array('id' => $record['interface_id'])); $text .= " [ID:{$int['id']}] {$int['ip_addr_text']}\n"; } // Display associated tags list($status, $rows, $records) = db_get_records($onadb, 'tags', array('type' => 'host', 'reference' => $host['id'])); if ($rows) { $text .= "\nASSOCIATED TAG RECORDS ({$rows}):\n"; } foreach ($records as $record) { $text .= " {$record['name']}\n"; } // Display associated custom attributes list($status, $rows, $records) = db_get_records($onadb, 'custom_attributes', array('table_name_ref' => 'hosts', 'table_id_ref' => $host['id'])); if ($rows) { $text .= "\nASSOCIATED CUSTOM ATTRIBUTE RECORDS ({$rows}):\n"; } foreach ($records as $record) { list($status, $rows, $ca) = ona_get_custom_attribute_record(array('id' => $record['id'])); $text .= " {$ca['name']} => {$ca['value']}\n"; } // Display associated DHCP entries list($status, $rows, $records) = db_get_records($onadb, 'dhcp_option_entries', array('host_id' => $host['id'])); if ($rows) { $text .= "\nASSOCIATED DHCP OPTION RECORDS ({$rows}):\n"; } foreach ($records as $record) { list($status, $rows, $dhcp) = ona_get_dhcp_option_entry_record(array('id' => $record['id'])); $text .= " {$dhcp['display_name']} => {$dhcp['value']}\n"; } return array(7, $text); }
function tag_del($options = "") { // The important globals global $conf, $self, $onadb; // Version - UPDATE on every edit! $version = '1.00'; printmsg("DEBUG => tag_del({$options}) called", 3); // Parse incoming options string to an array $options = parse_options($options); // Return the usage summary if we need to if ($options['help'] or !$options['tag']) { // NOTE: Help message lines should not exceed 80 characters for proper display on a console $self['error'] = 'ERROR => Insufficient parameters'; return array(1, <<<EOM tag_del-v{$version} Deletes an tag from the database Synopsis: tag_del [KEY=VALUE] ... Required: tag=ID ID of the tag to delete Optional: commit=[yes|no] commit db transaction (no) EOM ); } // Sanitize options[commit] (default is no) $options['commit'] = sanitize_YN($options['commit'], 'N'); // If the tag provided is numeric, check to see if it's an tag if (is_numeric($options['tag'])) { // See if it's a tag_id list($status, $rows, $tag) = db_get_record($onadb, 'tags', array('id' => $options['tag'])); } if (!$tag['id']) { printmsg("DEBUG => Unable to find tag ({$options['tag']})!", 3); $self['error'] = "ERROR => Unable to find tag ({$options['tag']})!"; return array(2, $self['error'] . "\n"); } // If "commit" is yes, delete the record if ($options['commit'] == 'Y') { // Check permissions if (!(auth('host_del') or auth('subnet_del'))) { $self['error'] = "Permission denied!"; printmsg($self['error'], 0); return array(10, $self['error'] . "\n"); } list($status, $rows) = db_delete_records($onadb, 'tags', array('id' => $tag['id'])); if ($status or !$rows) { $self['error'] = "ERROR => tag_del() SQL Query failed: " . $self['error']; printmsg($self['error'], 0); return array(4, $self['error'] . "\n"); } // Return the success notice $self['error'] = "INFO => TAG DELETED: {$tag['name']} from {$tag['type']}[{$tag['reference']}]"; printmsg($self['error'], 0); return array(0, $self['error'] . "\n"); } // Otherwise display the record that would have been deleted $text = <<<EOL Record(s) NOT DELETED (see "commit" option) Displaying record(s) that would have been deleted: NAME: {$tag['name']} TYPE: {$tag['type']} REFERENCE: {$tag['reference']} EOL; return array(6, $text); }
function interface_share_del($options = "") { global $conf, $self, $onadb; printmsg("DEBUG => interface_share_del({$options['ip']}) called", 3); // Version - UPDATE on every edit! $version = '1.00'; // Parse incoming options string to an array $options = parse_options($options); // Return the usage summary if we need to if ($options['help'] or !($options['host'] and $options['ip'])) { // NOTE: Help message lines should not exceed 80 characters for proper display on a console $self['error'] = 'ERROR => Insufficient parameters'; return array(1, <<<EOM interface_share_del-v{$version} Delete a shareed interface from another host. An IP address only exists once in the database. This allows you to share that IP with several other hosts which are configured to use technologies such as HSRP, CARP, VRRP etc. Synopsis: interface_share_del [KEY=VALUE] ... Required: ip=[address|ID] the IP address or ID of the interface host=[fqdn|ID] the fqdn or ID of the host EOM ); } // Find the Host they are looking for list($status, $rows, $host) = ona_find_host($options['host']); if (!$host['id']) { printmsg("DEBUG => The host specified, {$options['host']}, does not exist!", 3); $self['error'] = "ERROR => The host specified, {$options['host']}, does not exist!"; return array(2, $self['error'] . "\n"); } printmsg("DEBUG => Host selected: {$options['host']}", 3); // Find the interface list($status, $rows, $interface) = ona_find_interface($options['ip']); if (!$interface['id']) { printmsg("DEBUG => The interface specified, {$options['ip']}, does not exist!", 3); $self['error'] = "ERROR => The interface specified, {$options['ip']}, does not exist!"; return array(3, $self['error'] . "\n"); } printmsg("DEBUG => Interface selected: {$options['ip']}", 3); // Check that this interface is not associated with this host via an interface_cluster already list($status, $rows, $int_cluster) = db_get_records($onadb, 'interface_clusters', array('host_id' => $host['id'], 'interface_id' => $interface['id']), '', 0); if ($rows == 0) { printmsg("DEBUG => Unable to find share ({$host['fqdn']}-{$interface['ip_addr_text']}).", 3); $self['error'] = "ERROR => Unable to find share ({$host['fqdn']}-{$interface['ip_addr_text']})."; return array(13, $self['error'] . "\n"); } // Drop the record list($status, $rows) = db_delete_records($onadb, 'interface_clusters', array('host_id' => $host['id'], 'interface_id' => $interface['id'])); if ($status or !$rows) { $self['error'] = "ERROR => interface_share_del() SQL Query failed: " . $self['error']; printmsg($self['error'], 0); return array(5, $self['error']); } // Return the success notice $self['error'] = "INFO => Interface Share deleted: {$interface['ip_addr_text']} from {$host['fqdn']}."; printmsg($self['error'], 0); return array(0, $self['error'] . "\n"); }
function dns_record_del($options = "") { global $conf, $self, $onadb; printmsg("DEBUG => dns_record_del({$options}) called", 3); // Version - UPDATE on every edit! $version = '1.03'; // Parse incoming options string to an array $options = parse_options($options); // Sanitize options[commit] (default is no) $options['commit'] = sanitize_YN($options['commit'], 'N'); // Return the usage summary if we need to if ($options['help'] or !$options['name']) { // NOTE: Help message lines should not exceed 80 characters for proper display on a console $self['error'] = 'ERROR => Insufficient parameters'; return array(1, <<<EOM dns_record_del-v{$version} Deletes a DNS record from the database Synopsis: dns_record_del [KEY=VALUE] ... Required: name=NAME[.DOMAIN] or ID hostname or ID of the record to delete type=TYPE record type (A,CNAME,PTR...) Optional: ip=ADDRESS ip address (numeric or dotted) commit=[yes|no] commit db transaction (no) EOM ); } /* thoughts on the flow of things: A records: remove any CNAMES using this A record remove any PTR records using this A record test that it is not a primary_dns_id, if it is, it must be reassigned should make a find_dns_record(s) function. a find by host option would be good. need to do a better delete of DNS records when deleting a host.. currently its a problem. MP: TODO: this delete will not handle DNS views unless you use the ID of the record to delete. add a view option at some point. */ // If the name we were passed has a leading . in it then remove the dot. $options['name'] = preg_replace("/^\\./", '', $options['name']); // FIXME: MP Fix this to use a find_dns_record function ID only for now // Find the DNS record from $options['name'] list($status, $rows, $dns) = ona_find_dns_record($options['name'], $options['type']); printmsg("DEBUG => dns_record_del() DNS record: {$options['name']}", 3); if (!$dns['id']) { printmsg("DEBUG => Unknown DNS record: {$options['name']} ({$options['type']})", 3); $self['error'] = "ERROR => Unknown DNS record: {$options['name']} ({$options['type']})"; return array(2, $self['error'] . "\n"); } // Check permissions if (!auth('host_del') or !authlvl($host['LVL'])) { $self['error'] = "Permission denied!"; printmsg($self['error'], 0); return array(10, $self['error'] . "\n"); } // If "commit" is yes, delete the host if ($options['commit'] == 'Y') { $text = ""; $add_to_error = ""; // SUMMARY: // Display any associated PTR records for an A record // Display any associated CNAMEs for an A record // Test if it is used as a primary_dns_id unless it is the host_del module calling if (!isset($options['delete_by_module'])) { list($status, $rows, $srecord) = db_get_record($onadb, 'hosts', array('primary_dns_id' => $dns['id'])); if ($rows) { $self['error'] = "ERROR => dns_record_del() The DNS record, {$dns['name']}.{$dns['domain_fqdn']}[{$dns['id']}], is a primary A record for a host! You can not delete it until you associate a new primary record, or delete the host."; printmsg($self['error'], 0); return array(5, $self['error'] . "\n"); } } // Delete related Points to records // get list for logging list($status, $rows, $records) = db_get_records($onadb, 'dns', array('dns_id' => $dns['id'])); // do the delete list($status, $rows) = db_delete_records($onadb, 'dns', array('dns_id' => $dns['id'])); if ($status) { $self['error'] = "ERROR => dns_record_del() Child record delete SQL Query failed: {$self['error']}"; printmsg($self['error'], 0); return array(5, $self['error'] . "\n"); } if ($rows) { // log deletions // FIXME: do better logging here printmsg("INFO => {$rows} child DNS record(s) DELETED from {$dns['fqdn']}", 0); $add_to_error .= "INFO => {$rows} child record(s) DELETED from {$dns['fqdn']}\n"; } // TRIGGER: flag the domains for rebuild foreach ($records as $record) { list($status, $rows) = db_update_record($onadb, 'dns_server_domains', array('domain_id' => $record['domain_id']), array('rebuild_flag' => 1)); if ($status) { $self['error'] = "ERROR => dns_record_del() Unable to update rebuild flags for domain.: {$self['error']}"; printmsg($self['error'], 0); return array(7, $self['error'] . "\n"); } } // Delete the DNS record list($status, $rows) = db_delete_records($onadb, 'dns', array('id' => $dns['id'])); if ($status) { $self['error'] = "ERROR => dns_record_del() DNS record delete SQL Query failed: {$self['error']}"; printmsg($self['error'], 0); return array(5, $add_to_error . $self['error'] . "\n"); } // TRIGGER: flag the current dnsrecords domain for rebuild list($status, $rows) = db_update_record($onadb, 'dns_server_domains', array('domain_id' => $dns['domain_id']), array('rebuild_flag' => 1)); if ($status) { $self['error'] = "ERROR => dns_record_del() Unable to update rebuild flags for domain.: {$self['error']}"; printmsg($self['error'], 0); return array(7, $self['error'] . "\n"); } // FIXME: if it is a NS or something display a proper FQDN message here // Display proper PTR information if ($dns['type'] == 'PTR') { list($status, $rows, $pointsto) = ona_get_dns_record(array('id' => $dns['dns_id']), ''); list($status, $rows, $ptrint) = ona_get_interface_record(array('id' => $dns['interface_id']), ''); $ipflip = ip_mangle($ptrint['ip_addr'], 'flip'); $octets = explode(".", $ipflip); if (count($octets) > 4) { $arpa = '.ip6.arpa'; $octcount = 31; } else { $arpa = '.in-addr.arpa'; $octcount = 3; } $dns['fqdn'] = "{$ipflip}{$arpa} -> {$pointsto['fqdn']}"; } // Return the success notice $self['error'] = "INFO => DNS {$dns['type']} record DELETED: {$dns['fqdn']}"; printmsg($self['error'], 0); return array(0, $add_to_error . $self['error'] . "\n"); } // // We are just displaying records that would have been deleted // // SUMMARY: // Display any associated PTR records for an A record // Display any associated CNAMEs for an A record // Otherwise just display the host record for the host we would have deleted $text = "Record(s) NOT DELETED (see \"commit\" option)\n" . "Displaying record(s) that would have been deleted:\n"; // Test if it is used as a primary_dns_id list($status, $rows, $srecord) = db_get_record($onadb, 'hosts', array('primary_dns_id' => $dns['id'])); if ($rows) { $text .= "\nWARNING! This DNS record is a primary A record for a host\n"; } // Display the complete dns record list($status, $tmp) = dns_record_display("name={$dns['id']}&verbose=N"); $text .= "\n" . $tmp; // Display associated Child records list($status, $rows, $records) = db_get_records($onadb, 'dns', array('dns_id' => $dns['id'])); if ($rows) { $text .= "\nASSOCIATED POINTS-TO RECORDS ({$rows}):\n"; } foreach ($records as $record) { if ($record['type'] == 'NS') { $record['name'] = ''; } // FIXME:I could fix this but I'm lazy if ($record['type'] == 'PTR') { $record['name'] = '??'; } list($status, $rows, $domain) = ona_get_domain_record(array('id' => $record['domain_id']), ''); $text .= " {$record['type']}: {$record['name']}.{$domain['fqdn']} -> {$dns['fqdn']}\n"; } return array(7, $text); }
function domain_server_del($options = "") { // The important globals global $conf, $self, $onadb; // Version - UPDATE on every edit! $version = '1.02'; printmsg("DEBUG => domain_server_del({$options}) called", 3); // Parse incoming options string to an array $options = parse_options($options); // Sanitize options[commit] (default is yes) $options['commit'] = sanitize_YN($options['commit'], 'N'); // Return the usage summary if we need to if ($options['help'] or !($options['domain'] and $options['server'])) { // NOTE: Help message lines should not exceed 80 characters for proper display on a console $self['error'] = 'ERROR => Insufficient parameters'; return array(1, <<<EOM domain_server_del-v{$version} Removes a domain record from a DNS server Synopsis: domain_server_del [KEY=VALUE] ... Required: domain=NAME or ID domain name or ID server=NAME[.DOMAIN] or ID server name or ID Optional: commit=[Y|N] commit db transaction (no) EOM ); } if (is_numeric($options['domain'])) { $domainsearch['id'] = $options['domain']; } else { $domainsearch['name'] = strtoupper($options['domain']); } // Determine the entry itself exists list($status, $rows, $domain) = ona_get_domain_record($domainsearch); // Test to see that we were able to find the specified record if (!$domain['id']) { printmsg("DEBUG => Unable to find the domain record using {$options['domain']}!", 3); $self['error'] = "ERROR => Unable to find the domain record using {$options['domain']}!"; return array(4, $self['error'] . "\n"); } printmsg("DEBUG => domain_server_del(): Found domain, {$domain['name']}", 3); if ($options['server']) { // Determine the server is valid list($status, $rows, $host) = ona_find_host($options['server']); if (!$host['id']) { printmsg("DEBUG => The server ({$options['server']}) does not exist!", 3); $self['error'] = "ERROR => The server specified, {$options['server']}, does not exist!"; return array(2, $self['error'] . "\n"); } } // Test that this domain is even assigned to the server list($status, $rows, $domainserver) = ona_get_dns_server_domain_record(array('host_id' => $host['id'], 'domain_id' => $domain['id'])); if (!$rows) { printmsg("DEBUG => Unable to find {$domain['name']} on server {$host['fqdn']}", 3); $self['error'] = "ERROR => Unable to find {$domain['name']} on server {$host['fqdn']}"; return array(11, $self['error'] . "\n"); } // Test that there are no NS records for this pair // ASSUMPTION: MP this will always be just one record?? // depending on how the user has their NS records set up, we may not find anything. list($status, $dnsrows, $dnsrec) = db_get_record($onadb, 'dns', "domain_id = {$domain['id']} AND type = 'NS' AND interface_id in (select id from interfaces where host_id = {$host['id']})"); // If "commit" is yes, delete the record if ($options['commit'] == 'Y') { // Check permissions if (!auth('advanced') or !authlvl($host['LVL']) or !authlvl($domain['LVL'])) { $self['error'] = "Permission denied!"; printmsg($self['error'], 0); return array(10, $self['error'] . "\n"); } // delete record from domain_server_domains list($status, $rows) = db_delete_records($onadb, 'dns_server_domains', array('id' => $domainserver['id'])); if ($status) { $self['error'] = "ERROR => domain_server_del() SQL Query failed:" . $self['error']; printmsg($self['error'], 0); return array(9, $self['error'] . "\n"); } // Run the module to delete the associated NS record.. Only if we found a dns record for NS if ($dnsrec['id']) { list($status, $output) = run_module('dns_record_del', array('name' => $dnsrec['id'], 'type' => 'NS', 'commit' => 'Y')); if ($status) { $self['error'] = "ERROR => domain_server_del() NS record delete failed:" . $output; printmsg($self['error'], 0); return array(9, $self['error'] . "\n"); } else { // add the output to self error for display $add_to_error = $output; } } // Return the success notice $self['error'] = "INFO => DNS Domain/Server Pair DELETED: {$domain['name']}/{$host['fqdn']} "; printmsg($self['error'], 0); return array(0, $add_to_error . $self['error'] . "\n"); } // Otherwise display the record that would have been deleted $text = <<<EOL Record(s) NOT DELETED (see "commit" option) Displaying record(s) that would have been removed: {$domain['name']} from: {$host['fqdn']} EOL; if ($dnsrows) { $text .= " Removing related NS record, if any. Please double check your NS records for this domain.\n"; } return array(6, $text); }
function ws_delete($window_name, $form = '') { global $conf, $self, $onadb; // Check permissions if (!auth('advanced')) { $response = new xajaxResponse(); $response->addScript("alert('Permission denied!');"); return $response->getXML(); } // Instantiate the xajaxResponse object $response = new xajaxResponse(); $js = ''; // Load the record to make sure it exists list($status, $rows, $subnet_type) = db_get_record($onadb, 'subnet_types', array('id' => $form)); if ($status or !$rows) { $response->addScript("alert('Delete failed: Subnet type ID {$form} doesnt exist');"); return $response->getXML(); } // Get a list of subnets that use this subnet type list($status, $rows, $subnet) = db_get_records($onadb, 'subnets', array('subnet_type_id' => $form), '', 0); // Check that there are no parent records using this type if ($rows > 0) { $js .= "alert('Delete failed: There are {$rows} subnets using this subnet type.');"; } else { // Delete the record list($status, $rows) = db_delete_records($onadb, 'subnet_types', array('id' => $subnet_type['id'])); // If the module returned an error code display a popup warning if ($status != 0) { $js .= "alert('Delete failed: " . trim($self['error']) . "');"; } } // Refresh the current list.. it's changed! $js .= "xajax_window_submit('{$window_name}', xajax.getFormValues('{$window_name}_filter_form'), 'display_list');"; // Send an XML response $response->addScript($js); return $response->getXML(); }
function subnet_del($options = "") { global $conf, $self, $onadb; // Version - UPDATE on every edit! $version = '1.06'; printmsg('DEBUG => subnet_del(' . $options . ') called', 3); // Parse incoming options string to an array $options = parse_options($options); // Sanitize options[commit] (default is no) $options['commit'] = sanitize_YN($options['commit'], 'N'); // Return the usage summary if we need to if ($options['help'] or !$options['subnet']) { // NOTE: Help message lines should not exceed 80 characters for proper display on a console $self['error'] = 'ERROR => Insufficient parameters'; return array(1, <<<EOM subnet_del-v{$version} Deletes a subnet (subnet) from the database Synopsis: subnet_del [KEY=VALUE] ... Required: subnet=IP or ID select subnet by search string Optional: commit=[yes|no] commit db transaction (no) EOM ); } // Find the subnet record we're deleting list($status, $rows, $subnet) = ona_find_subnet($options['subnet']); if ($status or !$rows) { $self['error'] = "ERROR => Subnet not found"; return array(2, $self['error'] . "\n"); } // Check permissions if (!auth('subnet_del') or !authlvl($subnet['lvl'])) { $self['error'] = "Permission denied!"; printmsg($self['error'], 0); return array(3, $self['error'] . "\n"); } // If "commit" is yes, delete the subnet if ($options['commit'] == 'Y') { $text = ""; // FIXME: (add all this) ... // SUMMARY: // Delete assignments to any DHCP servers // Delete any DHCP pools on the current subnet // Delete any DHCP options associated with this subnet // Delete any interfaces belonging to hosts with more than one interface // Delete any hosts (and all their associated info) that have only one interface // Delete subnet Record // Delete custom attributes // // FIXME: display a warning if there are no more subnets that a dhcp server is serving dhcp for? // Delete DHCP server assignments list($status, $rows) = db_delete_records($onadb, 'dhcp_server_subnets', array('subnet_id' => $subnet['id'])); if ($status) { $self['error'] = "ERROR => DHCP server assignment delete failed: {$self['error']}"; return array(5, $self['error'] . "\n"); } // Delete DHCP pools list($status, $rows) = db_delete_records($onadb, 'dhcp_pools', array('subnet_id' => $subnet['id'])); if ($status) { $self['error'] = "ERROR => DHCP pool delete failed: {$self['error']}"; return array(5, $self['error'] . "\n"); } // Delete DHCP options list($status, $rows) = db_delete_records($onadb, 'dhcp_option_entries', array('subnet_id' => $subnet['id'])); if ($status) { $self['error'] = "ERROR => DHCP parameter delete failed: {$self['error']}"; return array(5, $self['error'] . "\n"); } // Delete tag entries list($status, $rows, $records) = db_get_records($onadb, 'tags', array('type' => 'subnet', 'reference' => $subnet['id'])); $log = array(); $i = 0; foreach ($records as $record) { $log[$i] = "INFO => Tag DELETED: {$record['name']} from {$subnet['name']}"; $i++; } //do the delete list($status, $rows) = db_delete_records($onadb, 'tags', array('type' => 'subnet', 'reference' => $subnet['id'])); if ($status) { $self['error'] = "ERROR => subnet_del() Tag delete SQL Query failed: {$self['error']}"; printmsg($self['error'], 0); return array(5, $add_to_error . $self['error'] . "\n"); } //log deletions foreach ($log as $log_msg) { printmsg($log_msg, 0); $add_to_error .= $log_msg . "\n"; } // Delete custom attribute entries // get list for logging list($status, $rows, $records) = db_get_records($onadb, 'custom_attributes', array('table_name_ref' => 'subnets', 'table_id_ref' => $subnet['id'])); $log = array(); $i = 0; foreach ($records as $record) { list($status, $rows, $ca) = ona_get_custom_attribute_record(array('id' => $record['id'])); $log[$i] = "INFO => Custom Attribute DELETED: {$ca['name']} ({$ca['value']}) from {$subnet['name']}"; $i++; } //do the delete list($status, $rows) = db_delete_records($onadb, 'custom_attributes', array('table_name_ref' => 'subnets', 'table_id_ref' => $subnet['id'])); if ($status) { $self['error'] = "ERROR => subnet_del() Custom attribute delete SQL Query failed: {$self['error']}"; printmsg($self['error'], 0); return array(5, $self['error'] . "\n"); } //log deletions foreach ($log as $log_msg) { printmsg($log_msg, 0); //$add_to_error .= $log_msg . "\n"; } // Delete associated host / interface records that need to be deleted // BUSINESS RULE: We delete hosts that have only one interface (and it's on this subnet) // BUSINESS RULE: We delete interfaces from hosts that have multiple interfaces list($status, $rows, $interfaces) = db_get_records($onadb, 'interfaces', array('subnet_id' => $subnet['id'])); $hosts_to_delete = array(); $interfaces_to_delete = array(); foreach ($interfaces as $interface) { // Select all interfaces for the associated host where the subnet ID is not our subnet ID $where = "host_id = {$interface['host_id']} AND subnet_id != {$subnet['id']}"; list($status, $rows, $tmp) = db_get_records($onadb, 'interfaces', $where, '', 0); // We'll delete hosts that have only one interface (i.e. no interfaces on any other subnets) if ($rows == 0) { array_push($hosts_to_delete, $interface['host_id']); } else { array_push($interfaces_to_delete, $interface['id']); } } unset($interfaces); // make sure we only have one reference for each host and interface $interfaces_to_delete = array_unique($interfaces_to_delete); $hosts_to_delete = array_unique($hosts_to_delete); // Delete interfaces we have selected foreach ($interfaces_to_delete as $interface_id) { list($status, $output) = run_module('interface_del', array('interface' => $interface_id, 'commit' => 'Y')); if ($status) { return array(5, $output); } } // Delete hosts we have selected foreach ($hosts_to_delete as $host_id) { list($status, $output) = run_module('host_del', array('host' => $host_id, 'commit' => 'Y')); if ($status) { return array(5, $output); } } // Delete the subnet list($status, $rows) = db_delete_records($onadb, 'subnets', array('id' => $subnet['id'])); if ($status or !$rows) { $self['error'] = "ERROR => Subnet delete failed: {$self['error']}"; return array(5, $self['error'] . "\n"); } // Return the success notice $ip = ip_mangle($subnet['ip_addr'], 'dotted'); $cidr = ip_mangle($subnet['ip_mask'], 'cidr'); $self['error'] = "INFO => Subnet DELETED: {$subnet['name']} IP: {$ip}/{$cidr}"; printmsg($self['error'], 0); return array(0, $self['error'] . "\n"); } // // We are just displaying records that would have been deleted // // SUMMARY: // Display assignments to any DHCP servers // Display any DHCP pools on the current subnet // Display any DHCP parameters associated with this subnet // Display subnet Record // Display Host records (and all their sub-records) // Display custom attributes // Otherwise just display the host record for the host we would have deleted $text = "Record(s) NOT DELETED (see \"commit\" option)\n" . "Displaying record(s) that would have been deleted:\n"; // Display the Subnet's complete record list($status, $tmp) = subnet_display("subnet={$subnet['id']}&verbose=N"); $text .= "\n" . $tmp; // Display assignments to any DHCP servers list($status, $rows, $records) = db_get_records($onadb, 'dhcp_server_subnets', array('subnet_id' => $subnet['id'])); if ($rows) { $text .= "\nASSOCIATED DHCP SERVER ASSIGNMENT RECORDS ({$rows}):\n"; } foreach ($records as $record) { $text .= format_array($record); } // Display any DHCP pools on the current subnet list($status, $rows, $records) = db_get_records($onadb, 'dhcp_pools', array('subnet_id' => $subnet['id'])); if ($rows) { $text .= "\nASSOCIATED DHCP POOL RECORDS ({$rows}):\n"; } foreach ($records as $record) { $text .= format_array($record); } // Display associated DHCP entries list($status, $rows, $records) = db_get_records($onadb, 'dhcp_option_entries', array('subnet_id' => $subnet['id'])); if ($rows) { $text .= "\nASSOCIATED DHCP ENTRY RECORDS ({$rows}):\n"; } foreach ($records as $record) { list($status, $rows, $dhcp) = ona_get_dhcp_option_entry_record(array('id' => $record['id'])); $text .= " {$dhcp['display_name']} => {$dhcp['value']}\n"; } // Display associated tags list($status, $rows, $records) = db_get_records($onadb, 'tags', array('type' => 'subnet', 'reference' => $subnet['id'])); if ($rows) { $text .= "\nASSOCIATED TAG RECORDS ({$rows}):\n"; } foreach ($records as $record) { $text .= " {$record['name']}\n"; } // Display associated custom attributes list($status, $rows, $records) = db_get_records($onadb, 'custom_attributes', array('table_name_ref' => 'subnets', 'table_id_ref' => $subnet['id'])); if ($rows) { $text .= "\nASSOCIATED CUSTOM ATTRIBUTE RECORDS ({$rows}):\n"; } foreach ($records as $record) { list($status, $rows, $ca) = ona_get_custom_attribute_record(array('id' => $record['id'])); $text .= " {$ca['name']} => {$ca['value']}\n"; } // Display associated host / interface records that would be deleted // BUSINESS RULE: We delete hosts that have only one interface (and it's on this subnet) // BUSINESS RULE: We delete interfaces from hosts that have multiple interfaces (including at least one on a different subnet) list($status, $rows, $interfaces) = db_get_records($onadb, 'interfaces', array('subnet_id' => $subnet['id'])); $hosts_to_delete = array(); $interfaces_to_delete = array(); foreach ($interfaces as $interface) { // Select all interfaces for the associated host where the subnet ID is not our subnet ID $where = "host_id = {$interface['host_id']} AND subnet_id != {$subnet['id']}"; list($status, $rows, $tmp) = db_get_records($onadb, 'interfaces', $where, '', 0); // We'll delete hosts that have only one interface (i.e. no interfaces on any other subnets) if ($rows == 0) { array_push($hosts_to_delete, $interface['host_id']); } else { array_push($interfaces_to_delete, $interface['id']); } } unset($interfaces); // make sure we only have one reference for each host and interface $interfaces_to_delete = array_unique($interfaces_to_delete); $hosts_to_delete = array_unique($hosts_to_delete); // Display interfaces we would have deleted $rows = count($interfaces_to_delete); if ($rows) { $text .= "\n----- ASSOCIATED HOST INTERFACE RECORDS ({$rows}) -----\n"; } foreach ($interfaces_to_delete as $interface_id) { list($status, $output) = run_module('interface_del', array('interface' => $interface_id), false); $output = preg_replace('/^(.*)?\\n(.*)?\\n/', '', $output); $text .= $output; } // Display hosts we would have deleted $rows = count($hosts_to_delete); if ($rows) { $text .= "\n-----ASSOCIATED HOSTS ({$rows}) -----\n"; } foreach ($hosts_to_delete as $host_id) { list($status, $output) = run_module('host_del', array('host' => $host_id), false); $output = preg_replace('/^(.*)?\\n(.*)?\\n/', '', $output); $text .= $output; } return array(7, $text); }
function dhcp_entry_del($options = "") { // The important globals global $conf, $self, $onadb; // Version - UPDATE on every edit! $version = '1.01'; printmsg("DEBUG => dhcp_entry_del({$options}) called", 3); // Parse incoming options string to an array $options = parse_options($options); // Sanitize options[commit] (default is yes) $options['commit'] = sanitize_YN($options['commit'], 'N'); // Return the usage summary if we need to if ($options['help'] or !$options['id']) { // NOTE: Help message lines should not exceed 80 characters for proper display on a console $self['error'] = 'ERROR => Insufficient parameters'; return array(1, <<<EOM dhcp_entry_del-v{$version} Deletes a DHCP entry from the database Synopsis: dhcp_entry_del [KEY=VALUE] ... Required: id=ID ID of the dhcp entry to delete Optional: commit=[yes|no] commit db transaction (no) EOM ); } // Sanitize options[commit] (default is no) $options['commit'] = sanitize_YN($options['commit'], 'N'); $desc = 'Global level'; // If the option provided is numeric, check to see if it exists if (is_numeric($options['id'])) { // Debugging printmsg("DEBUG => DHCP entry ID selected: {$options['id']}", 3); list($status, $tmp_rows, $entry) = ona_get_dhcp_option_entry_record(array('id' => $options['id'])); // Test to see that we were able to find the specified record if (!$entry['id']) { printmsg("DEBUG => Unable to find the DHCP entry record using ID {$options['id']}!", 3); $self['error'] = "ERROR => Unable to find the DHCP entry record using ID {$options['id']}!"; return array(4, $self['error'] . "\n"); } // Assign a search option based on host or server id if ($entry['host_id']) { $search = $entry['host_id']; } if ($entry['server_id']) { $search = $entry['server_id']; } if ($entry['host_id'] or $entry['server_id']) { // Get some host information to display later and determine its valid list($status, $rows, $host) = ona_find_host($search); // Bail out if you cant find a host if (!$host['id']) { printmsg("DEBUG => The ID specified, {$search}, does not exist!", 3); $self['error'] = "ERROR => The ID specified, {$search}, does not exist!"; return array(3, $self['error'] . "\n"); } printmsg("DEBUG => dhcp_entry_del(): Using host: {$host['fqdn']} ID: {$host['id']}", 3); $desc = $host['fqdn']; $lvl = $host['lvl']; } elseif ($entry['subnet_id']) { // Determine the subnet is valid list($status, $rows, $subnet) = ona_find_subnet($entry['subnet_id']); if (!$subnet['id']) { printmsg("DEBUG => The subnet specified, {$options['subnet']}, does not exist!", 3); $self['error'] = "ERROR => The subnet specified, {$options['subnet']}, does not exist!"; return array(3, $self['error'] . "\n"); } printmsg("DEBUG => dhcp_entry_del(): Using subnet: {$subnet['name']} ID: {$subnet['id']}", 3); $desc = "{$subnet['name']} (" . ip_mangle($subnet['ip_addr']) . ")"; $lvl = $subnet['lvl']; } } else { printmsg("DEBUG => {$options['id']} is not a numeric value", 3); $self['error'] = "ERROR => {$options['id']} is not a numeric value"; return array(15, $self['error'] . "\n"); } // If "commit" is yes, delte the record if ($options['commit'] == 'Y') { // Check permissions if (!auth('advanced') or !authlvl($lvl)) { $self['error'] = "Permission denied!"; printmsg($self['error'], 0); return array(10, $self['error'] . "\n"); } list($status, $rows) = db_delete_records($onadb, 'dhcp_option_entries', array('id' => $entry['id'])); if ($status or !$rows) { $self['error'] = "ERROR => dhcp_entry_del() SQL Query failed: " . $self['error']; printmsg($self['error'], 0); return array(4, $self['error'] . "\n"); } // Return the success notice $self['error'] = "INFO => DHCP entry DELETED: {$entry['display_name']}={$entry['value']} from {$desc} "; printmsg($self['error'], 0); return array(0, $self['error'] . "\n"); } // Otherwise display the record that would have been deleted $text = <<<EOL Record(s) NOT DELETED (see "commit" option) Displaying record(s) that would have been deleted: ON: {$desc} Delete the following dhcp entry: ENTRY: {$entry['display_name']} = {$entry['value']} EOL; return array(6, $text); }
function dhcp_failover_group_del($options = "") { global $conf, $self, $onadb; printmsg("DEBUG => dhcp_failover_group_del({$options}) called", 3); // Version - UPDATE on every edit! $version = '1.00'; // Parse incoming options string to an array $options = parse_options($options); // Sanitize options[commit] (default is yes) $options['commit'] = sanitize_YN($options['commit'], 'N'); // Return the usage summary if we need to if ($options['help'] or !$options['id']) { // NOTE: Help message lines should not exceed 80 characters for proper display on a console $self['error'] = 'ERROR => Insufficient parameters'; return array(1, <<<EOM dhcp_failover_group_del-v{$version} Deletes a DHCP failover group from the database Synopsis: dhcp_failover_group_del [KEY=VALUE] ... Required: id=id id of the failover group to delete Optional: commit=[Y|N] commit db transaction (no) EOM ); } // Test that the group actually exists. list($status, $tmp_rows, $entry) = ona_get_dhcp_failover_group_record(array('id' => $options['id'])); if (!$entry['id']) { printmsg("DEBUG => Unable to find a DHCP failover group record using id {$options['id']}!", 3); $self['error'] = "ERROR => Unable to find a DHCP failover group record using id {$options['id']}!"; return array(4, $self['error'] . "\n"); } // Debugging printmsg("DEBUG => DHCP failover group selected: {$entry['id']}", 3); // Display an error if pools are using this zone list($status, $rows, $pool) = db_get_record($onadb, 'dhcp_pools', array('id' => $entry['id'])); if ($rows) { printmsg("DEBUG => DHCP failover group ({$entry['id']}) can't be deleted, it is in use on 1 or more pools!", 3); $self['error'] = "ERROR => DHCP failover group ({$entry['id']}) can't be deleted, it is in use on 1 or more pools!"; return array(5, $self['error'] . "\n"); } list($status, $rows, $pri_host) = ona_find_host($entry['primary_server_id']); list($status, $rows, $sec_host) = ona_find_host($entry['secondary_server_id']); // If "commit" is yes, delete the record if ($options['commit'] == 'Y') { // Check permissions if (!auth('advanced')) { $self['error'] = "Permission denied!"; printmsg($self['error'], 0); return array(10, $self['error'] . "\n"); } // Delete actual zone list($status, $rows) = db_delete_records($onadb, 'dhcp_failover_groups', array('id' => $entry['id'])); if ($status) { $self['error'] = "ERROR => dhcp_failover_group_del() SQL Query failed: {$self['error']}"; printmsg($self['error'], 0); return array(9, $self['error'] . "\n"); } // Return the success notice $self['error'] = "INFO => DHCP failover group DELETED: {$entry['id']} => PRI:{$pri_host['fqdn']} SEC:{$sec_host['fqdn']}"; printmsg($self['error'], 0); return array(0, $self['error'] . "\n"); } // Otherwise display the record that would have been deleted $text = <<<EOL Record(s) NOT DELETED (see "commit" option) Displaying record(s) that would have been deleted: NAME: {$entry['id']} PRIMARY: {$pri_host['fqdn']} SECONDARY: {$sec_host['fqdn']} EOL; return array(6, $text); }
function ws_save($window_name, $form = '') { global $conf, $self, $onadb; // Check permissions if (!auth('user_admin')) { $response = new xajaxResponse(); $response->addScript("alert('Permission denied!');"); return $response->getXML(); } // Instantiate the xajaxResponse object $response = new xajaxResponse(); $js = ''; $exit_status = 0; // Validate input if (!$form['username']) { $js .= "alert('Error! All fields are required!');"; $response->addScript($js); return $response->getXML(); } if (!preg_match('/^[A-Za-z0-9.\\-_]+$/', $form['username'])) { $js .= "alert('Invalid username! Valid characters: A-Z 0-9 .-_');"; $response->addScript($js); return $response->getXML(); } // Create a new record? if (!$form['user_id']) { list($status, $rows) = db_insert_record($onadb, 'users', array('username' => $form['username'], 'password' => $form['password'])); if ($status or !$rows) { $self['error'] = "ERROR => user_edit_add ws_save() SQL Query failed: " . $self['error']; printmsg($self['error'], 0); } else { $self['error'] = "INFO => User ADDED: {$form['username']} "; printmsg($self['error'], 0); } } else { list($status, $rows, $user) = db_get_record($onadb, 'users', array('id' => $form['user_id'])); if ($rows != 1 or $user['id'] != $form['user_id']) { $js .= "alert('Error! The record requested could not be loaded from the database!');"; $response->addScript($js); return $response->getXML(); } list($status, $rows) = db_update_record($onadb, 'users', array('id' => $user['id']), array('username' => $form['username'], 'password' => $form['password'])); if ($status) { $self['error'] = "ERROR => user_edit update ws_save() SQL Query failed: " . $self['error']; printmsg($self['error'], 0); } else { list($status, $rows, $new_record) = db_get_record($onadb, 'users', array('id' => $user['id'])); // Return the success notice $self['error'] = "INFO => User UPDATED:{$user['id']}: {$new_record['username']}"; $log_msg = "INFO => User UPDATED:{$user['id']}: "; $more = ""; foreach (array_keys($user) as $key) { if ($user[$key] != $new_record[$key]) { $log_msg .= $more . $key . "[" . $user[$key] . "=>" . $new_record[$key] . "]"; $more = ";"; } } } } // Make sure we can load the user record from the db list($status, $rows, $user) = db_get_record($onadb, 'users', array('username' => $form['username'])); if ($status or $rows != 1) { $js .= "alert('Save failed: " . trim($self['error']) . "');"; // Return some javascript to the browser $response->addScript($js); return $response->getXML(); } // This is a bit tricky because we want to make sure the user has all the groups // that are checked in the form, but no others. And of course we want to make as // few sql queries as possible. It's tricky because the form only submits us the // groups that are checked. // Get a list of every group list($status, $rows, $groups) = db_get_records($onadb, 'groups', 'id > 0'); // Loop through each group foreach ($groups as $group) { // See if the user is assigned to this group or not list($status, $rows, $tmp) = db_get_record($onadb, 'group_assignments', array('user_id' => $user['id'], 'group_id' => $group['id'])); $exit_status += $status; // If the user is supposed to be assigned to this group, make sure she is. if (array_key_exists($group['name'], $form['groups'])) { if ($status == 0 and $rows == 0) { list($status, $rows) = db_insert_record($onadb, 'group_assignments', array('user_id' => $user['id'], 'group_id' => $group['id'])); $log_msg .= $more . "group_add[" . $group['name'] . "]"; $more = ";"; $exit_status += $status; } } else { if ($status == 0 and $rows == 1) { list($status, $rows) = db_delete_records($onadb, 'group_assignments', array('user_id' => $user['id'], 'group_id' => $group['id'])); $log_msg .= $more . "group_del[" . $group['name'] . "]"; $more = ";"; $exit_status += $status; } } } // If the module returned an error code display a popup warning if ($status) { $js .= "alert('Save failed: " . trim($self['error']) . "');"; } else { // only print to logfile if a change has been made to the record if ($more != '') { printmsg($self['error'], 0); printmsg($log_msg, 0); } $js .= "removeElement('{$window_name}');"; $js .= "xajax_window_submit('app_user_list', xajax.getFormValues('app_user_list_filter_form'), 'display_list');"; } // Return some javascript to the browser $response->addScript($js); return $response->getXML(); }
function location_del($options = "") { // The important globals global $conf, $self, $onadb; // Version - UPDATE on every edit! $version = '1.01'; printmsg("DEBUG => location_del({$options}) called", 3); // Parse incoming options string to an array $options = parse_options($options); // Return the usage summary if we need to if ($options['help'] or !$options['reference']) { // NOTE: Help message lines should not exceed 80 characters for proper display on a console $self['error'] = 'ERROR => Insufficient parameters'; return array(1, <<<EOM locaiton_del-v{$version} Deletes a location from the database Synopsis: location_del [KEY=VALUE] ... Required: reference=NAME or ID Reference or ID of the location to delete Optional: commit=[yes|no] commit db transaction (no) EOM ); } // Sanitize options[commit] (default is no) $options['commit'] = sanitize_YN($options['commit'], 'N'); // Find the Location to use list($status, $rows, $loc) = ona_find_location($options['reference']); if ($status or !$rows) { printmsg("DEBUG => The location specified, {$options['reference']}, does not exist!", 3); return array(2, "ERROR => The location specified, {$options['reference']}, does not exist!\n"); } printmsg("DEBUG => Location selected: {$loc['reference']}, location name: {$loc['name']}", 3); list($status, $rows, $usage) = db_get_records($onadb, 'devices', array('location_id' => $loc['id']), '', 0); if ($rows != 0) { printmsg("DEBUG => The location ({$loc['reference']}) is in use by {$rows} devices(s)!", 3); $self['error'] = "ERROR => The location ({$loc['reference']}) is in use by {$rows} devices(s)!"; return array(6, $self['error'] . "\n"); } // If "commit" is yes, delete the record if ($options['commit'] == 'Y') { // Check permissions if (!auth('location_del')) { $self['error'] = "Permission denied!"; printmsg($self['error'], 0); return array(10, $self['error'] . "\n"); } list($status, $rows) = db_delete_records($onadb, 'locations', array('id' => $loc['id'])); if ($status or !$rows) { $self['error'] = "ERROR => location_del() SQL Query failed: " . $self['error']; printmsg($self['error'], 0); return array(4, $self['error'] . "\n"); } // Return the success notice $self['error'] = "INFO => Location DELETED: {$loc['reference']} ({$loc['name']})"; printmsg($self['error'], 0); return array(0, $self['error'] . "\n"); } // Otherwise display the record that would have been deleted $text = <<<EOL Record(s) NOT DELETED (see "commit" option) Displaying record(s) that would have been deleted: EOL; $text .= format_array($loc); $text .= "\n"; return array(6, $text); }
function ws_save($window_name, $form = '') { global $conf, $self, $onadb; // Check permissions if (!auth('user_admin')) { $response = new xajaxResponse(); $response->addScript("alert('Permission denied!');"); return $response->getXML(); } // Instantiate the xajaxResponse object $response = new xajaxResponse(); $js = ''; $exit_status = 0; // This is a bit tricky because we want to make sure the user has all the permissions // that are checked in the form, but no others. And of course we want to make as // few sql queries as possible. It's tricky because the form only submits us the // permissions that were checked. // Get a list of every permission list($status, $rows, $permissions) = db_get_records($onadb, 'permissions', 'id > 0'); // Loop through each permission foreach ($permissions as $permission) { // Get the user/group permissions for the current perm_id list($status, $rows, $p) = db_get_record($onadb, 'permission_assignments', array($form['type'] => $form['id'], 'perm_id' => $permission['id'])); $exit_status += $status; // If the user/group is supposed to have this permission, make sure she does. if ($form['perms'][$permission['id']]) { if ($status == 0 and $rows == 0) { list($status, $rows) = db_insert_record($onadb, 'permission_assignments', array($form['type'] => $form['id'], 'perm_id' => $permission['id'])); $exit_status += $status; } } else { if ($status == 0 and $rows == 1) { list($status, $rows) = db_delete_records($onadb, 'permission_assignments', array($form['type'] => $form['id'], 'perm_id' => $permission['id'])); $exit_status += $status; } } } // If the module returned an error code display a popup warning if ($status) { $js .= "alert('Save failed: " . trim($self['error']) . "');"; } else { $js .= "removeElement('{$window_name}');"; } // Return some javascript to the browser $response->addScript($js); return $response->getXML(); }
function domain_del($options = "") { global $conf, $self, $onadb; printmsg("DEBUG => domain_del({$options}) called", 3); // Version - UPDATE on every edit! $version = '1.02'; // Parse incoming options string to an array $options = parse_options($options); // Sanitize options[commit] (default is yes) $options['commit'] = sanitize_YN($options['commit'], 'N'); // Return the usage summary if we need to if ($options['help'] or !$options['domain']) { // NOTE: Help message lines should not exceed 80 characters for proper display on a console $self['error'] = 'ERROR => Insufficient parameters'; return array(1, <<<EOM domain_del-v{$version} Deletes a DNS domain from the database Synopsis: domain_del [KEY=VALUE] ... Required: domain=NAME or ID name or ID of the domain to delete Optional: commit=[Y|N] commit db transaction (no) EOM ); } // Check if it is an ID or NAME if (is_numeric($options['domain'])) { $domainsearch = array('id' => $options['domain']); } else { $domainsearch = array('name' => $options['domain']); } // Test that the domain actually exists. list($status, $tmp_rows, $entry) = ona_get_domain_record($domainsearch); if (!$entry['id']) { printmsg("DEBUG => Unable to find a domain record using ID {$options['domain']}!", 3); $self['error'] = "ERROR => Unable to find a domain record using ID {$options['domain']}!"; return array(4, $self['error'] . "\n"); } // Debugging list($status, $tmp_rows, $tmp_parent) = ona_get_domain_record(array('id' => $entry['parent_id'])); printmsg("DEBUG => Domain selected: {$entry['name']}.{$tmp_parent['name']}", 3); // Display an error if DNS records are using this domain list($status, $rows, $dns) = db_get_records($onadb, 'dns', array('domain_id' => $entry['id'])); if ($rows) { printmsg("DEBUG => Domain ({$entry['name']}) can't be deleted, it is in use by {$rows} DNS entries!", 3); $self['error'] = "ERROR => Domain ({$entry['name']}) can't be deleted, it is in use by {$rows} DNS entries!"; return array(5, $self['error'] . "\n"); } // Display an error if it is a parent of other domains list($status, $rows, $parent) = db_get_records($onadb, 'domains', array('parent_id' => $entry['id'])); if ($rows) { printmsg("DEBUG => Domain ({$entry['name']}) can't be deleted, it is the parent of {$rows} other domain(s)!", 3); $self['error'] = "ERROR => Domain ({$entry['name']}) can't be deleted, it is the parent of {$rows} other domain(s)!"; return array(7, $self['error'] . "\n"); } // If "commit" is yes, delete the record if ($options['commit'] == 'Y') { // Check permissions if (!auth('advanced')) { $self['error'] = "Permission denied!"; printmsg($self['error'], 0); return array(10, $self['error'] . "\n"); } // Delete association with any servers list($status, $rows) = db_delete_records($onadb, 'dns_server_domains', array('domain_id' => $entry['id'])); if ($status) { $self['error'] = "ERROR => domain_del() SQL Query (dns_server_domains) failed: {$self['error']}"; printmsg($self['error'], 0); return array(8, $self['error'] . "\n"); } // Delete actual domain list($status, $rows) = db_delete_records($onadb, 'domains', array('id' => $entry['id'])); if ($status) { $self['error'] = "ERROR => domain_del() SQL Query failed: {$self['error']}"; printmsg($self['error'], 0); return array(9, $self['error'] . "\n"); } // Return the success notice $self['error'] = "INFO => Domain DELETED: {$entry['name']}"; printmsg($self['error'], 0); return array(0, $self['error'] . "\n"); } // Otherwise display the record that would have been deleted $text = <<<EOL Record(s) NOT DELETED (see "commit" option) Displaying record(s) that would have been deleted: NAME: {$entry['name']} EOL; return array(6, $text); }
function custom_attribute_del($options = "") { // The important globals global $conf, $self, $onadb; // Version - UPDATE on every edit! $version = '1.01'; printmsg("DEBUG => custom_attribute_del({$options}) called", 3); // Parse incoming options string to an array $options = parse_options($options); // Return the usage summary if we need to if ($options['help'] or !$options['subnet'] and !$options['host'] and !$options['vlan'] or !$options['type']) { // NOTE: Help message lines should not exceed 80 characters for proper display on a console $self['error'] = 'ERROR => Insufficient parameters'; return array(1, <<<EOM custom_attribute_del-v{$version} Deletes a custom attribute from the database Synopsis: custom_attribute_del [KEY=VALUE] ... Required: host=NAME[.DOMAIN]|IP hostname or IP of the host OR subnet=NAME|IP name or IP of the subnet OR vlan=NAME name of the VLAN type=ID|STRING the name or ID of the attribute type Optional: commit=[yes|no] commit db transaction (no) EOM ); } // Sanitize options[commit] (default is no) $options['commit'] = sanitize_YN($options['commit'], 'N'); // If they provided a hostname / ID let's look it up if ($options['host']) { list($status, $rows, $host) = ona_find_host($options['host']); $table_name_ref = 'hosts'; $table_id_ref = $host['id']; $desc = $host['fqdn']; } else { if ($options['subnet']) { list($status, $rows, $subnet) = ona_find_subnet($options['subnet']); $table_name_ref = 'subnets'; $table_id_ref = $subnet['id']; $desc = $subnet['name']; } else { if ($options['vlan']) { list($status, $rows, $vlan) = ona_find_vlan($options['vlan']); $table_name_ref = 'vlans'; $table_id_ref = $vlan['id']; $desc = $vlan['name']; } } } // If we didn't get a record then exit if (!$host['id'] and !$subnet['id'] and !$vlan['id']) { printmsg("DEBUG => No host, subnet or vlan found!", 3); $self['error'] = "ERROR => No host, subnet or vlan found!"; return array(1, $self['error'] . "\n"); } // If the type provided is numeric, check to see if it's an vlan if (is_numeric($options['type'])) { // See if it's an vlan_campus_id list($status, $rows, $catype) = ona_get_custom_attribute_type_record(array('id' => $options['type'])); if (!$catype['id']) { printmsg("DEBUG => Unable to find custom attribute type using the ID {$options['name']}!", 3); $self['error'] = "ERROR => Unable to find custom attribute type using the ID {$options['name']}!"; return array(2, $self['error'] . "\n"); } } else { $options['type'] = trim($options['type']); list($status, $rows, $catype) = ona_get_custom_attribute_type_record(array('name' => $options['type'])); if (!$catype['id']) { printmsg("DEBUG => Unable to find custom attribute type using the name {$options['type']}!", 3); $self['error'] = "ERROR => Unable to find custom attribute type using the name {$options['type']}!"; return array(3, $self['error'] . "\n"); } } list($status, $rows, $record) = ona_get_custom_attribute_record(array('table_name_ref' => $table_name_ref, 'table_id_ref' => $table_id_ref, 'custom_attribute_type_id' => $catype['id'])); if (!$rows) { printmsg("DEBUG => Unable to find custom attribute!", 3); $self['error'] = "ERROR => Unable to find custom attribute!"; return array(4, $self['error'] . "\n"); } // If "commit" is yes, delete the record if ($options['commit'] == 'Y') { // Check permissions if (!auth('custom_attribute_del')) { $self['error'] = "Permission denied!"; printmsg($self['error'], 0); return array(5, $self['error'] . "\n"); } list($status, $rows) = db_delete_records($onadb, 'custom_attributes', array('id' => $record['id'])); if ($status or !$rows) { $self['error'] = "ERROR => custom_attribute_del() SQL Query failed: " . $self['error']; printmsg($self['error'], 0); return array(6, $self['error'] . "\n"); } // Return the success notice $self['error'] = "INFO => Custom Attribute DELETED: {$record['name']} ({$record['value']}) from {$desc}"; printmsg($self['error'], 0); return array(0, $self['error'] . "\n"); } // Otherwise display the record that would have been deleted $text = <<<EOL Record(s) NOT DELETED (see "commit" option) Displaying record(s) that would have been deleted: ASSOCIATED WITH: {$desc} NAME: {$record['name']} VALUE: {$record['value']} EOL; return array(6, $text); }
function dhcp_server_del($options = "") { // The important globals global $conf, $self, $onadb; // Version - UPDATE on every edit! $version = '1.03'; printmsg("DEBUG => dhcp_server_del({$options}) called", 3); // Parse incoming options string to an array $options = parse_options($options); // Sanitize options[commit] (default is yes) $options['commit'] = sanitize_YN($options['commit'], 'N'); // Return the usage summary if we need to if ($options['help'] or !($options['subnet'] and $options['server'])) { // NOTE: Help message lines should not exceed 80 characters for proper display on a console $self['error'] = 'ERROR => Insufficient parameters'; return array(1, <<<EOM dhcp_server_del-v{$version} Removes a subnet record from a DHCP server Synopsis: dhcp_server_del [KEY=VALUE] ... Required: subnet=NAME or ID subnet name or ID server=NAME[.DOMAIN] or ID server name or ID Optional: commit=[Y|N] commit db transaction (no) Notes: DOMAIN will default to {$conf['dns_defaultdomain']} if not specified EOM ); } // Determine the entry itself exists list($status, $rows, $subnet) = ona_find_subnet($options['subnet']); // Test to see that we were able to find the specified record if (!$subnet['id']) { printmsg("DEBUG => Unable to find the subnet record using {$options['subnet']}!", 3); $self['error'] = "ERROR => Unable to find the subnet record using {$options['subnet']}!"; return array(4, $self['error'] . "\n"); } printmsg("DEBUG => dhcp_server_del(): Found subnet, {$subnet['name']}", 3); if ($options['server']) { // Determine the server is valid list($status, $rows, $host) = ona_find_host($options['server']); if (!$host['id']) { printmsg("DEBUG => The server ({$options['server']}) does not exist!", 3); $self['error'] = "ERROR => The server specified, {$options['server']}, does not exist!"; return array(2, $self['error'] . "\n"); } } //printmsg("DEBUG => dhcp_server_del(): Found server, {$host['FQDN']}", 3); // Test that this subnet is even assigned to the server list($status, $rows, $dhcpserver) = ona_get_dhcp_server_subnet_record(array('host_id' => $host['id'], 'subnet_id' => $subnet['id'])); if (!$rows) { printmsg("DEBUG => Unable to find {$subnet['name']} on server {$host['fqdn']}", 3); $self['error'] = "ERROR => Unable to find {$subnet['name']} on server {$host['fqdn']}"; return array(11, $self['error'] . "\n"); } // If "commit" is yes, delete the record if ($options['commit'] == 'Y') { // Check permissions if (!auth('advanced') or !authlvl($host['LVL']) or !authlvl($subnet['LVL'])) { $self['error'] = "Permission denied!"; printmsg($self['error'], 0); return array(10, $self['error'] . "\n"); } // check if allowed to remove subnet from server // check for pool assigned to the server itself list($status, $rows, $pools) = db_get_records($onadb, 'dhcp_pools', array('subnet_id' => $subnet['id'])); foreach ($pools as $pool) { if ($pool['dhcp_failover_group_id']) { $foundfg = 0; list($status, $rows, $primary) = ona_get_dhcp_failover_group_record(array('id' => $pool['dhcp_failover_group_id'], 'primary_server_id' => $host['id'])); if ($rows) { $foundfg++; } list($status, $rows, $secondary) = ona_get_dhcp_failover_group_record(array('id' => $pool['dhcp_failover_group_id'], 'secondary_server_id' => $host['id'])); if ($rows) { $foundfg++; } // if a subnet/server pair is found in dhcp pools, don't allow removal if ($foundfg > 0) { printmsg("DEBUG => Subnet ({$subnet['name']}) has a pool assigned to this Server ({$host['fqdn']}), which is part of a failover group. The server must be removed from the failover group first.", 3); $self['error'] = "ERROR => Subnet ({$subnet['name']}) has a pool assigned to this Server ({$host['fqdn']}), which is part of a failover group. The server must be removed from the failover group first."; return array(12, $self['error'] . "\n"); } } } // MP: remove this after testing. dhcp options should not stop us from dis-associating a subnet from a server // Not really sure why I have this.. probably left over cruft from old thoughts // // check if there are any DHCP parameters assigned to the subnet // list($status, $rows, $tmp) = ona_get_dhcp_option_entry_record(array('subnet_id' => $subnet['id'])); // // // if so, check that this is not the last DHCP server that services this subnet // if ($rows > 0) { // list($status, $rows, $tmp) = ona_get_dhcp_server_subnet_record(array('subnet_id' => $subnet['id'])); // // // If this is the last DHCP server that services this subnet, don't allow removal until DHCP parameters are removed // if($rows <= 1){ // printmsg("DEBUG => Subnet ({$subnet['name']}) has DHCP parameters assigned which need to be removed first",3); // $self['error'] = "ERROR => Subnet ({$subnet['name']}) has DHCP parameters assigned which need to be removed first"; // return(array(12, $self['error'] . "\n")); // } // } // delete record from dhcp_server_subnets list($status, $rows) = db_delete_records($onadb, 'dhcp_server_subnets', array('id' => $dhcpserver['id'])); if ($status) { $self['error'] = "ERROR => dhcp_server_del() SQL Query failed:" . $self['error']; printmsg($self['error'], 0); return array(9, $self['error'] . "\n"); } // Return the success notice $self['error'] = "INFO => DHCP Subnet/Server Pair DELETED: {$subnet['name']}/{$host['fqdn']} "; printmsg($self['error'], 0); return array(0, $self['error'] . "\n"); } // Otherwise display the record that would have been deleted $text = <<<EOL Record(s) NOT DELETED (see "commit" option) Displaying record(s) that would have been removed: {$subnet['name']} from: {$host['fqdn']} EOL; return array(6, $text); }
function dhcp_pool_del($options = "") { // The important globals global $conf, $self, $onadb; // Version - UPDATE on every edit! $version = '1.00'; printmsg("DEBUG => dhcp_pool_del({$options}) called", 3); // Parse incoming options string to an array $options = parse_options($options); // Sanitize options[commit] (default is yes) $options['commit'] = sanitize_YN($options['commit'], 'N'); // Return the usage summary if we need to if ($options['help'] or !$options['id']) { // NOTE: Help message lines should not exceed 80 characters for proper display on a console $self['error'] = 'ERROR => Insufficient parameters'; return array(1, <<<EOM dhcp_pool_del-v{$version} Deletes a DHCP pool from the database Synopsis: dhcp_pool_del [KEY=VALUE] ... Required: id=ID ID of the DHCP pool to delete Optional: commit=[yes|no] commit db transaction (no) EOM ); } // Sanitize options[commit] (default is no) $options['commit'] = sanitize_YN($options['commit'], 'N'); // If the option provided is numeric, check to see if it exists if (is_numeric($options['id'])) { list($status, $tmp_rows, $pool) = ona_get_dhcp_pool_record(array('id' => $options['id'])); // Test to see that we were able to find the specified pool record if (!$pool['id']) { printmsg("DEBUG => Unable to find the DHCP pool record using ID: {$options['id']}!", 3); $self['error'] = "ERROR => Unable to find the DHCP pool record using ID: {$options['id']}!"; return array(2, $self['error'] . "\n"); } $start = ip_mangle($pool['ip_addr_start'], 'dotted'); $end = ip_mangle($pool['ip_addr_end'], 'dotted'); list($status, $tmp_rows, $subnet) = ona_get_subnet_record(array('id' => $pool['subnet_id'])); } else { printmsg("DEBUG => {$options['id']} is not a numeric value!", 3); $self['error'] = "ERROR => {$options['id']} is not a numeric value"; return array(3, $self['error'] . "\n"); } // If "commit" is yes, delte the record if ($options['commit'] == 'Y') { // Check permissions if (!auth('advanced') or !authlvl($subnet['lvl'])) { $self['error'] = "Permission denied!"; printmsg($self['error'], 0); return array(4, $self['error'] . "\n"); } list($status, $rows) = db_delete_records($onadb, 'dhcp_pools', array('id' => $pool['id'])); if ($status or !$rows) { $self['error'] = "ERROR => dhcp_pool_del() SQL Query failed: " . $self['error']; printmsg($self['error'], 0); return array(5, $self['error'] . "\n"); } // Return the success notice $self['error'] = "INFO => DHCP pool DELETED: {$start}-{$end} from {$subnet['name']}."; printmsg($self['error'], 0); return array(0, $self['error'] . "\n"); } // Otherwise display the record that would have been deleted $text = <<<EOL Record(s) NOT DELETED (see "commit" option) Displaying record(s) that would have been deleted: Delete the following dhcp pool: ENTRY: {$start}=>{$end} from {$subnet['name']} EOL; return array(6, $text); }
function ws_delete($window_name, $form = '') { global $conf, $self, $onadb; // Check permissions if (!auth('advanced')) { $response = new xajaxResponse(); $response->addScript("alert('Permission denied!');"); return $response->getXML(); } // Instantiate the xajaxResponse object $response = new xajaxResponse(); $js = ''; // Load the record to make sure it exists list($status, $rows, $role) = db_get_record($onadb, 'roles', array('id' => $form)); if ($status or !$rows) { $response->addScript("alert('Delete failed: Role id {$form} does not exist');"); return $response->getXML(); } // Get a list of device models that use this role list($status, $rows, $devicemodels) = db_get_records($onadb, 'models', array('role_id' => $form), '', 0); // Check that there are no parent records using this type if ($rows > 0) { $js .= "alert('Delete failed: There are {$rows} device models using this role.');"; } else { // Delete the record list($status, $rows) = db_delete_records($onadb, 'roles', array('id' => $role['id'])); if ($status or !$rows) { // If the module returned an error code display a popup warning $js .= "alert('Delete failed: " . trim($self['error']) . "');"; $self['error'] = "ERROR => role_list ws_delete() SQL Query failed: " . $self['error']; printmsg($self['error'], 0); } else { $self['error'] = "INFO => Role DELETED: {$role['name']} "; printmsg($self['error'], 0); } } // Refresh the current list.. it's changed! $js .= "xajax_window_submit('{$window_name}', xajax.getFormValues('{$window_name}_filter_form'), 'display_list');"; // Send an XML response $response->addScript($js); return $response->getXML(); }
function sess_gc($lifetime) { global $SESS_DBH; list($status, $rows) = db_delete_records($SESS_DBH, "`sessions`", "`expiry` < " . time()); return $rows; }
function vlan_campus_del($options = "") { // The important globals global $conf, $self, $onadb; // Version - UPDATE on every edit! $version = '1.00'; printmsg("DEBUG => vlan_campus_del({$options}) called", 3); // Parse incoming options string to an array $options = parse_options($options); // Return the usage summary if we need to if ($options['help'] or !$options['name']) { // NOTE: Help message lines should not exceed 80 characters for proper display on a console $self['error'] = 'ERROR => Insufficient parameters'; return array(1, <<<EOM vlan_campus_del-v{$version} Deletes a vlan campus from the database Synopsis: vlan_campus_del [KEY=VALUE] ... Required: name=NAME or ID Name or ID of the vlan campus to delete Optional: commit=[yes|no] commit db transaction (no) EOM ); } // Sanitize options[commit] (default is no) $options['commit'] = sanitize_YN($options['commit'], 'N'); // If the vlan provided is numeric, check to see if it's an vlan if (is_numeric($options['name'])) { // See if it's an vlan_campus_id list($status, $rows, $campus) = ona_get_vlan_campus_record(array('id' => $options['name'])); if (!$campus['id']) { printmsg("DEBUG => Unable to find VLAN campus using the ID {$options['name']}!", 3); $self['error'] = "ERROR => Unable to find VLAN campus using the ID {$options['name']}!"; return array(2, $self['error'] . "\n"); } } else { $options['name'] = strtoupper(trim($options['name'])); list($status, $rows, $campus) = ona_get_vlan_campus_record(array('name' => $options['name'])); if (!$campus['id']) { printmsg("DEBUG => Unable to find VLAN campus using the name {$options['name']}!", 3); $self['error'] = "ERROR => Unable to find VLAN campus using the name {$options['name']}!"; return array(2, $self['error'] . "\n"); } } list($status, $rows, $vlan) = db_get_records($onadb, 'vlans', array('vlan_campus_id' => $campus['id']), '', 0); if ($rows != 0) { printmsg("DEBUG => This VLAN campus ({$campus['name']}) is in use by {$rows} VLAN(s)!", 3); $self['error'] = "ERROR => This VLAN campus ({$campus['name']}) is in use by {$rows} VLAN(s)!"; return array(6, $self['error'] . "\n" . "INFO => Please dis-associate those VLANS from this campus before deleting.\n"); } // If "commit" is yes, delete the record if ($options['commit'] == 'Y') { // Check permissions if (!auth('vlan_del')) { $self['error'] = "Permission denied!"; printmsg($self['error'], 0); return array(10, $self['error'] . "\n"); } list($status, $rows) = db_delete_records($onadb, 'vlan_campuses', array('id' => $campus['id'])); if ($status or !$rows) { $self['error'] = "ERROR => vlan_campus_del() SQL Query failed: " . $self['error']; printmsg($self['error'], 0); return array(4, $self['error'] . "\n"); } // Return the success notice $self['error'] = "INFO => VLAN Campus DELETED: {$campus['name']}"; printmsg($self['error'], 0); return array(0, $self['error'] . "\n"); } // Otherwise display the record that would have been deleted $text = <<<EOL Record(s) NOT DELETED (see "commit" option) Displaying record(s) that would have been deleted: NAME: {$campus['name']} EOL; return array(6, $text); }
function ws_delete($window_name, $form = '') { global $conf, $self, $onadb; // Check permissions if (!auth('user_admin')) { $response = new xajaxResponse(); $response->addScript("alert('Permission denied!');"); return $response->getXML(); } // Instantiate the xajaxResponse object $response = new xajaxResponse(); $js = ''; // Load the user record to make sure it exists list($status, $rows, $user) = db_get_record($onadb, 'users', array('id' => $form)); if ($status or !$rows) { $response->addScript("alert('Delete failed: User ID {$form} doesnt exist');"); return $response->getXML(); } // Delete the user's group assignments do { list($status, $rows) = db_delete_records($onadb, 'group_assignments', array('user_id' => $user['id'])); } while ($rows >= 1); // Delete the user's permission assignments do { list($status, $rows) = db_delete_records($onadb, 'permission_assignments', array('user_id' => $user['id'])); } while ($rows >= 1); // Delete the user's record list($status, $rows) = db_delete_records($onadb, 'users', array('id' => $user['id'])); // If the module returned an error code display a popup warning if ($status != 0) { $js .= "alert('Delete failed');"; $self['error'] = "ERROR => user_list delete ws_save() SQL Query failed: " . $self['error']; printmsg($self['error'], 0); } else { $self['error'] = "INFO => User DELETED: {$user['username']} "; printmsg($self['error'], 0); // Refresh the current list of users.. it's changed! $js .= "xajax_window_submit('{$window_name}', xajax.getFormValues('{$window_name}_filter_form'), 'display_list');"; } // Send an XML response $response->addScript($js); return $response->getXML(); }
function block_del($options = "") { // The important globals global $conf, $self, $onadb; // Version - UPDATE on every edit! $version = '1.00'; printmsg("DEBUG => block_del({$options}) called", 3); // Parse incoming options string to an array $options = parse_options($options); // Return the usage summary if we need to if ($options['help'] or !$options['block']) { // NOTE: Help message lines should not exceed 80 characters for proper display on a console $self['error'] = 'ERROR => Insufficient parameters'; return array(1, <<<EOM block_del-v{$version} Deletes a block from the database Synopsis: block_del [KEY=VALUE] ... Required: block=name or ID name or ID of the block to delete Optional: commit=[yes|no] commit db transaction (no) EOM ); } // Sanitize options[commit] (default is no) $options['commit'] = sanitize_YN($options['commit'], 'N'); // If the block provided is numeric, check to see if it's an block if (is_numeric($options['block'])) { // See if it's an block_id list($status, $rows, $block) = ona_get_block_record(array('id' => $options['block'])); if (!$block['id']) { $self['error'] = "ERROR => Unable to find block using the ID {$options['block']}!"; printmsg("DEBUG => Unable to find block using the ID {$options['block']}!", 3); return array(2, $self['error'] . "\n"); } } else { list($status, $rows, $block) = ona_get_block_record(array('name' => $options['block'])); if (!$block['id']) { $self['error'] = "ERROR => Unable to find block using the name {$options['block']}!"; printmsg("DEBUG => Unable to find block using the name {$options['block']}!", 3); return array(2, $self['error'] . "\n"); } } // If "commit" is yes, delete the record if ($options['commit'] == 'Y') { // Check permissions if (!auth('advanced')) { $self['error'] = "Permission denied!"; printmsg($self['error'], 0); return array(10, $self['error'] . "\n"); } list($status, $rows) = db_delete_records($onadb, 'blocks', array('id' => $block['id'])); if ($status or !$rows) { $self['error'] = "ERROR => block_del() SQL Query failed: " . $self['error']; printmsg($self['error'], 0); return array(4, $self['error'] . "\n"); } // Return the success notice $self['error'] = "INFO => Block DELETED: {$block['name']}"; printmsg($self['error'], 0); return array(0, $self['error'] . "\n"); } $start = ip_mangle($block['ip_addr_start'], 'dotted'); $end = ip_mangle($block['ip_addr_end'], 'dotted'); // Otherwise display the record that would have been deleted $text = <<<EOL Record(s) NOT DELETED (see "commit" option) Displaying record(s) that would have been deleted: DESCRIPTION: {$block['name']} IP START: {$start} IP END: {$end} Notes: {$block['notes']} EOL; return array(6, $text); }
function ws_delete($window_name, $form = '') { global $conf, $self, $onadb; // Check permissions if (!auth('advanced')) { $response = new xajaxResponse(); $response->addScript("alert('Permission denied!');"); return $response->getXML(); } // Instantiate the xajaxResponse object $response = new xajaxResponse(); $js = ''; // Load the record to make sure it exists list($status, $rows, $syscnf) = db_get_record($onadb, 'sys_config', array('name' => $form)); if ($status or !$rows) { $response->addScript("alert('Delete failed: sys_config entry {$form} does not exist');"); return $response->getXML(); } // Delete the record list($status, $rows) = db_delete_records($onadb, 'sys_config', array('name' => $syscnf['name'])); if ($status or !$rows) { // If the module returned an error code display a popup warning $js .= "alert('Delete failed: " . trim($self['error']) . "');"; $self['error'] = "ERROR => sys_config_list ws_delete() SQL Query failed: " . $self['error']; printmsg($self['error'], 0); } else { $self['error'] = "INFO => Sys Config entry DELETED: {$syscnf['name']} "; printmsg($self['error'], 0); } // Refresh the current list.. it's changed! $js .= "xajax_window_submit('{$window_name}', xajax.getFormValues('{$window_name}_filter_form'), 'display_list');"; // Send an XML response $response->addScript($js); return $response->getXML(); }