Esempio n. 1
0
function ona_get_dns_server_domain_record($array)
{
    return ona_get_record($array, 'dns_server_domains');
}
Esempio n. 2
0
function ws_save($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 = '';
    // Strip whitespace
    // FIXME: (PK) What about SQL injection attacks?  This is a user-entered string...
    // Sanitize "name" option
    // We require view names to be in upper case and spaces are converted to -'s.
    $form['dns_view_name'] = strtoupper(trim($form['dns_view_name']));
    $form['dns_view_name'] = preg_replace('/\\s+/', '-', $form['dns_view_name']);
    $form['dns_view_description'] = trim($form['dns_view_description']);
    // Don't insert a string of all white space!
    if (trim($form['dns_view_name']) == "") {
        $self['error'] = "ERROR => Blank names not allowed.";
        printmsg($self['error'], 1);
        $response->addScript("alert('{$self['error']}');");
        return $response->getXML();
    }
    // If you get a numeric in $form, update the record
    if (is_numeric($form['id'])) {
        // Get the record before updating (logging)
        list($status, $rows, $original_type) = ona_get_record(array('id' => $form['id']), 'dns_views');
        $SET = array();
        if (strtoupper($form['dns_view_name']) != $original_type['name']) {
            // check for an existing entry like this
            list($status, $rows, $test) = ona_get_record(array('name' => $form['dns_view_name']), 'dns_views');
            if ($rows) {
                $self['error'] = "ERROR => The name you are trying to use already exists.";
                printmsg($self['error'], 1);
                $response->addScript("alert('{$self['error']}');");
                return $response->getXML();
            }
            $SET['name'] = strtoupper($form['dns_view_name']);
        }
        if ($form['dns_view_description'] != $original_type['description']) {
            $SET['description'] = $form['dns_view_description'];
        }
        list($status, $rows) = db_update_record($onadb, 'dns_views', array('id' => $form['id']), $SET);
        if ($status or !$rows) {
            $self['error'] = "ERROR => dns_view_edit update ws_save() failed: " . $self['error'];
            printmsg($self['error'], 1);
            $response->addScript("alert('{$self['error']}');");
        } else {
            // Get the record after updating (logging)
            list($status, $rows, $new_type) = ona_get_record(array('id' => $form['id']), 'dns_views');
            // Return the success notice
            $self['error'] = "INFO => DNS view UPDATED:{$new_type['id']}: {$new_type['name']}";
            printmsg($self['error'], 0);
            $log_msg = "INFO => DNS view UPDATED:{$new_type['id']}: name[{$original_type['name']}=>{$new_type['name']}]";
            printmsg($log_msg, 0);
        }
    } else {
        // check for an existing entry like this
        list($status, $rows, $test) = ona_get_record(array('name' => $form['dns_view_name']), 'dns_views');
        if ($rows) {
            $self['error'] = "ERROR => The name you are trying to use already exists.";
            printmsg($self['error'], 1);
            $response->addScript("alert('{$self['error']}');");
            return $response->getXML();
        }
        $id = ona_get_next_id('dns_views');
        if (!$id) {
            $self['error'] = "ERROR => The ona_get_next_id() call failed!";
            printmsg($self['error'], 1);
        } else {
            printmsg("DEBUG => id for new dns view record: {$id}", 3);
            list($status, $rows) = db_insert_record($onadb, "dns_views", array('id' => $id, 'name' => strtoupper(trim($form['dns_view_name'])), 'description' => $form['dns_view_description']));
            if ($status or !$rows) {
                $self['error'] = "ERROR => dns_view_edit add ws_save() failed: " . $self['error'];
                printmsg($self['error'], 1);
            } else {
                $self['error'] = "INFO => DNS view ADDED: {$form['dns_view_name']} ";
                printmsg($self['error'], 0);
            }
        }
    }
    // If the module returned an error code display a popup warning
    if ($status or !$rows) {
        $js .= "alert(\"Save failed. " . trim($self['error']) . " (Hint: Does the name you're trying to insert already exist?)\");";
    } else {
        $js .= "removeElement('{$window_name}');";
        $js .= "xajax_window_submit('app_dns_view_list', xajax.getFormValues('app_dns_view_list_filter_form'), 'display_list');";
    }
    // Return some javascript to the browser
    $response->addScript($js);
    return $response->getXML();
}
Esempio n. 3
0
function get_host_interface_list_html($form)
{
    global $conf, $self, $onadb;
    global $font_family, $color, $style, $images;
    $html = $js = '';
    // Interface Record
    list($status, $introws, $interfaces) = db_get_records($onadb, 'interfaces', "host_id = {$form['host_id']} or id in (select interface_id from interface_clusters where host_id ={$form['host_id']})", 'ip_addr ASC');
    if ($introws == 0 or $status) {
        return array('', '');
    }
    $style['label_box'] = <<<EOL
        font-weight: bold;
        padding: 2px 4px;
        text-align: center;
        border: solid 1px {$color['border']};
        background-color: {$color['window_content_bg']};
EOL;
    $html .= <<<EOL
        <!-- INTERFACE INFORMATION -->
        <table cellspacing="0" border="0" cellpadding="0">

            <!-- LABEL -->
            <tr>
                <td colspan=5 style="{$style['label_box']}">{$introws} interface(s)</td>
            </tr>
EOL;
    $i = 0;
    foreach ($interfaces as $interface) {
        list($status, $rows, $subnet) = ona_get_subnet_record(array('id' => $interface['subnet_id']));
        foreach (array_keys((array) $interface) as $key) {
            $interface[$key] = htmlentities($interface[$key], ENT_QUOTES, $conf['php_charset']);
        }
        foreach (array_keys((array) $subnet) as $key) {
            $subnet[$key] = htmlentities($subnet[$key], ENT_QUOTES, $conf['php_charset']);
        }
        $ip = ip_mangle($interface['ip_addr'], 'dotted');
        $clusticon = '';
        list($status, $clustrows, $clustrecord) = ona_get_record(array('interface_id' => $interface['id']), 'interface_clusters');
        if ($interface['host_id'] != $form['host_id'] or $clustrows > 0) {
            $clusticon = "<img title=\"This interface is shared with another host.\" src=\"{$images}/silk/sitemap.png\" border=\"0\">";
        }
        $html .= <<<EOL
            <tr>
                <td align="left" style="color: #FFFFFF;" nowrap="true">{$clusticon}&nbsp;</td>
                <td align="left" class="padding" style="color: #FFFFFF;" nowrap="true">{$ip}</td>
                <td align="left" class="padding" style="color: #FFFFFF;" nowrap="true">
                    <a title="View subnet. ID: {$subnet['id']}"
                         style="color: #6CB3FF;"
                         class="nav"
                         onClick="xajax_window_submit('work_space', 'xajax_window_submit(\\'display_subnet\\', \\'subnet_id=>{$subnet['id']}\\', \\'display\\')'); removeElement('{$form['id']}');"
                    >{$subnet['name']}</a>&nbsp;</td>
            </tr>

EOL;
        // increment counter
        $i++;
        if ($i == 15) {
            $html .= <<<EOL
            <tr>
                <td align="center" class="padding" style="color: #FFFFFF;" nowrap="true" colspan=2>
                    Only displaying first 15 interfaces on host.&nbsp;&nbsp;
                    <a title="View host. ID: {$interface['host_id']}"
                         style="color: #6CB3FF;"
                         class="nav"
                         onClick="xajax_window_submit('work_space', 'xajax_window_submit(\\'display_host\\', \\'host_id=>{$interface['host_id']}\\', \\'display\\')'); removeElement('{$form['id']}');"
                    >View Host</a>&nbsp;</td>
            </tr>
EOL;
            break;
        }
    }
    $html .= <<<EOL
        </table>
EOL;
    return array($html, $js);
}
function build_dhcpd_conf($options = "")
{
    global $self;
    global $conf;
    global $onadb;
    // Version - UPDATE on every edit!
    $version = '1.10';
    // Exit status of the function
    $exit = 0;
    printmsg('DEBUG => build_dhcpd_conf(' . $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['server']) {
        // NOTE: Help message lines should not exceed 80 characters for proper display on a console
        return array(1, <<<EOM

build_dhcpd_conf-v{$version}
Builds configuration for dhcpcd from the database

  Synopsis: build_dhcpd_conf [KEY=VALUE] ...

  Required:
    server=NAME[.DOMAIN] or ID    Build conf by hostname or HOST_ID

  Optional:
    header_path=PATH              Path to the server local header to include

  Notes:
    * Specified host must be a valid DHCP server
    * header_path is a file on the DHCP server.  It will be defined at
      the very top of your configuration using the DHCP "include" directive.


EOM
);
    }
    // TODO: ipv6 need to pass in if we want v4 or v6.. default to v4 for now.
    //       looks like you cant have a mixed config
    // Debugging
    printmsg("DEBUG => Building DHCP config for: {$options['server']}", 3);
    // Validate that there is already a host named $options['server'].
    list($status, $rows, $host) = ona_find_host($options['server']);
    if (!$host['id']) {
        return array(2, "ERROR => No such host: {$options['server']}\n");
    }
    // Now determine if that host is a valid server
    list($status, $dhcp_rows, $dhcp_server) = db_get_records($onadb, 'dhcp_server_subnets', array('host_id' => $host['id']), '');
    list($status, $dhcpf_rows, $dhcpf_server) = db_get_records($onadb, 'dhcp_failover_groups', "primary_server_id = {$host['id']} or secondary_server_id = {$host['id']}", '');
    if ($dhcp_rows == 0 and $dhcpf_rows == 0) {
        return array(3, "ERROR => Specified host is not a DHCP server: {$options['server']}\n");
    }
    // Throw the host id into a self variable for later use
    $self['serverid'] = $host['id'];
    // Start an output variable with build timestamp
    $text .= "###### DO NOT EDIT THIS FILE ###### \n";
    $text .= "# dhcpd.conf file for {$host['fqdn']} built on " . date($conf['date_format']) . "\n#\n";
    $text .= "# This file is built by an automated script.  Any change to this \n";
    $text .= "# file will be lost at the next build.\n\n";
    // setup standard include path
    // TODO: MP possibly put this into a configuration option like header so the user can easily change where this is.
    if (isset($options['header_path'])) {
        $text .= "include \"{$options['header_path']}\";\n";
    }
    /////////////////////////////// Build global options //////////////////////////////////////////
    list($status, $globals) = build_global($host['id']);
    $text .= $globals;
    /////////////////////////////// Failover groups //////////////////////////////////////////
    // build list of failover group statements for provided server
    list($status, $failovergroup) = ona_dhcp_build_failover_group($host['id']);
    $text .= $failovergroup;
    /////////////////////////////// shared subnets //////////////////////////////////////////
    // setup a variable to keep track of which vlan we are on
    $vlananchor = '';
    // Loop through all of the vlan subnets and print them
    printmsg("DEBUG => Processing all Shared (VLAN) Subnets", 1);
    $i = 0;
    do {
        list($status, $rows, $vlan_subnet) = ona_get_record('vlan_id != 0 AND
                                                              id IN (SELECT subnet_id
                                                                     FROM   dhcp_server_subnets
                                                                     WHERE  host_id = ' . $host['id'] . '
                                                                     UNION
                                                                     SELECT subnet_id
                                                                     FROM dhcp_pools
                                                                     WHERE dhcp_failover_group_id IN (SELECT id
                                                                                                      FROM dhcp_failover_groups
                                                                                                      WHERE primary_server_id = ' . $host['id'] . '
                                                                                                      OR secondary_server_id = ' . $host['id'] . '))', 'subnets', 'vlan_id ASC');
        if ($status) {
            printmsg($self['error'], 0);
            $exit += $status;
        }
        if ($rows == 0) {
            printmsg("DEBUG => build_dhcpd_conf(): Found no shared subnets.", 3);
            break;
        } else {
            if ($i == 0) {
                $text .= "# --------SHARED SUBNETS (count={$rows})--------\n\n";
            }
        }
        printmsg("DEBUG => Processing vlan subnet " . ($i + 1) . " of {$rows}", 3);
        // pull info about the vlan itself
        list($status, $vlanrows, $vlan) = ona_get_vlan_record(array('id' => $vlan_subnet['vlan_id']));
        if ($status) {
            printmsg($self['error'], 0);
            $exit += $status;
        }
        // check to see if we have switched to a new vlan
        if ($vlananchor != $vlan_subnet['vlan_id']) {
            // if this is NOT the first loop through, close the previous shared network block
            if ($i >= 1) {
                $text .= "}\n\n";
            }
            // print the opening statement for the shared network block and strip characters that may cause errors
            $text .= "shared-network " . preg_replace('/[^A-Za-z0-9_-]/', '', "{$vlan['vlan_campus_name']}-{$vlan['number']}-{$vlan['name']}") . " {\n";
        }
        // print the subnet block for the current subnet in the loop
        list($status, $subnetblock) = subnet_conf($vlan_subnet, 1);
        if ($status) {
            printmsg("ERROR => subnet_conf() returned an error: vlan subnet: {$vlan_subnet['name']}", 0);
            $exit += $status;
        } else {
            $text .= $subnetblock;
        }
        $i++;
        // If the loop is at the end,and this isnt the first time we've come through the loop, print a close statement
        // if ($i == $rows && $vlananchor != '') {$text .= "}\n\n";}
        if ($i == $rows) {
            $text .= "}\n\n";
        }
        // continue to update the vlan anchor
        $vlananchor = $vlan_subnet['vlan_id'];
    } while ($i < $rows);
    /////////////////////////////// standard subnets //////////////////////////////////////////
    // Loop through all of the NON vlan subnets and print them
    printmsg("DEBUG => Processing all Non-Shared (Standard) Subnets", 1);
    // We do our own sql query here because it makes more sense than calling ona_get_record() a zillion times ;)
    $q = "SELECT *\n          FROM subnets\n          WHERE vlan_id = 0 AND\n                id IN (SELECT subnet_id\n                       FROM dhcp_server_subnets\n                       WHERE host_id = {$host['id']}\n                       UNION\n                       SELECT subnet_id\n                       FROM dhcp_pools\n                       WHERE dhcp_failover_group_id IN (SELECT id\n                                                        FROM dhcp_failover_groups\n                                                        WHERE primary_server_id = {$host['id']}\n                                                        OR secondary_server_id = {$host['id']}))\n\n          ORDER BY name ASC";
    $rs = $onadb->Execute($q);
    if ($rs === false) {
        $self['error'] = 'ERROR => build_dhcpd_conf(): standard_subnets: SQL query failed: ' . $onadb->ErrorMsg();
        printmsg($self['error'], 0);
        $exit += 1;
    }
    $rows = $rs->RecordCount();
    if ($rows > 0) {
        $text .= "# --------STANDARD SUBNETS (count={$rows})--------\n";
    }
    $i = 0;
    // Loop through the record set
    while ($std_subnet = $rs->FetchRow()) {
        printmsg("DEBUG => build_dhcpd_conf() Processing standard subnet " . ($i + 1) . " of {$rows}", 3);
        // print the subnet info for the current subnet in the loop
        list($status, $subnetblock) = subnet_conf($std_subnet, 0);
        if ($status) {
            printmsg("ERROR => subnet_conf() returned an error: non-vlan subnet: {$std_subnet['description']}", 0);
            $exit += $status;
        } else {
            $text .= $subnetblock;
        }
        $i++;
    }
    $rs->Close();
    /////////////////////////////// build static hosts //////////////////////////////////////////
    list($status, $hostconf) = build_hosts($host['id']);
    $text .= $hostconf;
    /////////////////////////////// Yer done, go home //////////////////////////////////////////
    // Return the config file
    return array($exit, $text);
}
Esempio n. 5
0
function ws_save($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 = '';
    // Strip whitespace
    // FIXME: (PK) What about SQL injection attacks?  This is a user-entered string...
    $form['value'] = trim($form['value']);
    $form['name'] = trim($form['name']);
    // Don't insert a string of all white space!
    if (trim($form['name']) == "") {
        $self['error'] = "ERROR => Blank names not allowed.";
        printmsg($self['error'], 0);
        $response->addScript("alert('{$self['error']}');");
        return $response->getXML();
    }
    // If you get a numeric in $form, update the record
    if ($form['id']) {
        // Get the record before updating (logging)
        list($status, $rows, $original_sysconf) = ona_get_record(array('name' => $form['id']), 'sys_config');
        // Bail if it is a non editable entry
        if ($original_sysconf['editable'] == 0) {
            $self['error'] = "ERROR => This system config entry is not editable.";
            printmsg($self['error'], 0);
            $response->addScript("alert('{$self['error']}');");
            return $response->getXML();
        }
        if ($form['value'] !== $original_sysconf['value'] or $form['description'] !== $original_sysconf['description']) {
            list($status, $rows) = db_update_record($onadb, 'sys_config', array('name' => $form['name']), array('value' => $form['value'], 'description' => $form['description']));
            if ($status or !$rows) {
                $self['error'] = "ERROR => sys_config_edit update ws_save() failed: " . $self['error'];
                printmsg($self['error'], 0);
            } else {
                // Get the record after updating (logging)
                list($status, $rows, $new_sysconf) = ona_get_record(array('name' => $form['id']), 'sys_config');
                // Return the success notice
                $self['error'] = "INFO => Sys_config UPDATED:{$new_sysconf['name']}: {$new_sysconf['value']}";
                printmsg($self['error'], 0);
                $log_msg = "INFO => Sys_config UPDATED:{$new_sysconf['name']} NAME[{$original_sysconf['name']}]{$original_sysconf['value']}=>{$new_sysconf['value']}";
                printmsg($log_msg, 0);
            }
        } else {
            $self['error'] = "INFO => You have not made a change to the value or description.";
            printmsg($self['error'], 0);
            $response->addScript("alert('{$self['error']}');");
            return $response->getXML();
        }
    } else {
        // check for an existing entry like this
        list($status, $rows, $test) = ona_get_record(array('name' => $form['name']), 'sys_config');
        if ($rows) {
            $self['error'] = "ERROR => The name you are trying to use already exists.";
            printmsg($self['error'], 0);
            $response->addScript("alert('{$self['error']}');");
            return $response->getXML();
        }
        list($status, $rows) = db_insert_record($onadb, "sys_config", array('name' => $form['name'], 'value' => $form['value'], 'description' => $form['description'], 'editable' => 1, 'deleteable' => 1));
        if ($status or !$rows) {
            $self['error'] = "ERROR => Sys_config_edit add ws_save() failed: " . $self['error'];
            printmsg($self['error'], 0);
        } else {
            $self['error'] = "INFO => Sys_config ADDED: {$form['name']} ";
            printmsg($self['error'], 0);
        }
    }
    // 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}');";
        $js .= "xajax_window_submit('app_sysconf_list', xajax.getFormValues('app_sysconf_list_filter_form'), 'display_list');";
    }
    // Return some javascript to the browser
    $response->addScript($js);
    return $response->getXML();
}
Esempio n. 6
0
 $hval['url'] = str_replace('%onadomain', $record['domain_fqdn'], $hval['url']);
 // Get custom attributes if there is "%ca[.*]" string in URL
 // Patch from Greg.  It allows custom attribute replacements in host actions
 // if it does not find a CA it will check in the system_config table for that name
 // beginning with "default_"
 $found_ca_types = preg_match_all("#%ca\\[(.*?)\\]#", $hval['url'], $ca_types, PREG_PATTERN_ORDER);
 if ($found_ca_types) {
     foreach ($ca_types[1] as $name) {
         $replace_with = '';
         // Get the CA value for this host
         list($status, $rows, $attribute) = ona_get_record("custom_attribute_type_id in (select id from custom_attribute_types where name='" . $name . "') and table_id_ref = " . $record['id'] . " and table_name_ref = 'hosts'", 'custom_attributes');
         if ($rows) {
             $replace_with = $attribute['value'];
         } else {
             // If there's no CA for this host, last chance search in system config
             list($status, $conf_rows, $conf) = ona_get_record("name = 'default_" . $name . "'", 'sys_config');
             if ($conf_rows) {
                 $replace_with = $conf['value'];
             }
         }
         $hval['url'] = str_replace("%ca[{$name}]", $replace_with, $hval['url']);
     }
 }
 // If the URL has data in it, print.
 // TODO: MDP, maybe offer an $hval['icon'] option to use a different icon specified in the $conf['hostaction']['Name']['icon'] variable
 if ($hval['url']) {
     $modbodyhtml .= <<<EOL
         <span>
             <a title="{$hval['title']}"
                 class="act"
                 href="{$hval['url']}"