Example #1
0
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 ona_dhcp_build_failover_group($server_id = 0)
{
    printmsg("DEBUG => ona_dhcp_build_failover_group({$server_id}) called", 5);
    // Validate input
    if ($server_id == 0) {
        return array(1, "");
    }
    $field = array('primary' => 'primary_server_id', 'secondary' => 'secondary_server_id');
    // Define the two modes that failover could be in, and loop through (both of) them
    foreach (array('primary', 'secondary') as $mode) {
        // Loop through the records
        $i = 0;
        do {
            // Get a record from the db
            list($status, $rows, $record) = ona_get_dhcp_failover_group_record(array($field[$mode] => $server_id));
            $i++;
            // If there were no records, exit the loop
            if ($rows == 0) {
                break;
            }
            // print the first section info
            if ($i == 1) {
                $text = "# --------FAILOVER GROUPS (count={$rows})--------\n\n";
            }
            // call the function to get the dns name and ip address of each server
            list($pri_name, $pri_ip) = get_server_name_ip($record['primary_server_id']);
            list($sec_name, $sec_ip) = get_server_name_ip($record['secondary_server_id']);
            // begin printing failover statemens
            $text .= "# {$pri_name} (Primary) to {$sec_name} (Secondary)\n";
            $text .= "failover peer \"GROUP_ID-{$record['id']}\" {\n";
            $text .= "  {$mode};\n";
            if ($mode == "primary") {
                $text .= "  address " . long2ip($pri_ip) . ";\n";
                $text .= "  port {$record['primary_port']};\n";
                $text .= "  peer address " . long2ip($sec_ip) . ";\n";
                $text .= "  peer port {$record['peer_port']};\n";
                $text .= "  mclt {$record['mclt']};\n";
                $text .= "  split {$record['split']};\n";
            }
            if ($mode == "secondary") {
                $text .= "  address " . long2ip($sec_ip) . ";\n";
                $text .= "  port {$record['peer_port']};\n";
                $text .= "  peer address " . long2ip($pri_ip) . ";\n";
                $text .= "  peer port {$record['primary_port']};\n";
            }
            $text .= "  max-response-delay {$record['max_response_delay']};\n";
            $text .= "  max-unacked-updates {$record['max_unacked_updates']};\n";
            $text .= "  load balance max seconds {$record['max_load_balance']};\n";
            $text .= "}\n\n";
        } while ($i < $rows);
    }
    // Return the failover group config file
    return array(0, $text);
}
Example #3
0
        $hasserver = $rowstyle = '';
        if (!$fgrows and !$srows and $pool['dhcp_failover_group_id'] == 0) {
            $hasserver = "<img src='{$images}/silk/error.png' border='0'>";
            $rowstyle = 'style="background-color: #FFDDDD;" title="There is no DHCP server defined for this pool!"';
        }
        $pool['ip_addr_start'] = ip_mangle($pool['ip_addr_start'], 'dotted');
        $pool['ip_addr_end'] = ip_mangle($pool['ip_addr_end'], 'dotted');
        $modbodyhtml .= <<<EOL
            <tr {$rowstyle}>
                <td align="left" nowrap="true">
                    {$hasserver} {$pool['ip_addr_start']}&nbsp;Thru&nbsp;{$pool['ip_addr_end']}&nbsp;
EOL;
        // Display information about what pool group this pool is assigned to
        // TODO: make this more efficient.  seems like there would be a better way to do this
        if ($pool['dhcp_failover_group_id']) {
            list($status, $rows, $failover_group) = ona_get_dhcp_failover_group_record(array('id' => $pool['dhcp_failover_group_id']));
            list($status, $rows, $server_host1) = ona_get_host_record(array('id' => $failover_group['primary_server_id']));
            list($status, $rows, $server_host2) = ona_get_host_record(array('id' => $failover_group['secondary_server_id']));
            $modbodyhtml .= <<<EOL
                <a title="View DHCP server (Primary failover) - {$server_host1['fqdn']}"
                    class="nav"
                    onClick="xajax_window_submit('work_space', 'xajax_window_submit(\\'display_dhcp_server\\', \\'host_id=>{$server_host1['id']}\\', \\'display\\')');"
                >{$server_host1['name']}</a>&#047;
                <a title="View DHCP server (Secondary failover) - {$server_host2['fqdn']}"
                    class="nav"
                    onClick="xajax_window_submit('work_space', 'xajax_window_submit(\\'display_dhcp_server\\', \\'host_id=>{$server_host2['id']}\\', \\'display\\')');"
                >{$server_host2['name']}</a>
EOL;
        }
        $modbodyhtml .= <<<EOL
        </td>
Example #4
0
function dhcp_pool_modify($options = "")
{
    // The important globals
    global $conf, $self, $onadb;
    // Version - UPDATE on every edit!
    $version = '1.03';
    printmsg("DEBUG => dhcp_pool_modify({$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['pool'] and ($options['set_failover_group'] or $options['set_start'] or $options['set_end'] or $options['set_llength'] or $options['set_lgrace'] or $options['set_lrenewal'] or $options['set_lrebind']))) {
        // 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_modify-v{$version}
Updates a dhcp pool in the database pointing to the specified identifier

  Synopsis: dhcp_pool_modify [KEY=VALUE] ...

  Where:
    pool=ID                             Table ID for the pool

  Optional:
    set_failover_group=ID               group identifier
    set_server=NAME[.DOMAIN] or ID      server identifier
    set_start=IP                        Start ip address of pool
    set_end=IP                          End IP of pool
    set_llength=NUMBER                  Lease Time. Default ({$conf['dhcp_pool']['llength']})
    set_lgrace=NUMBER                   Lease Grace Period. Default ({$conf['dhcp_pool']['lgrace']})
    set_lrenewal=NUMBER                 Lease Renewal. Default ({$conf['dhcp_pool']['lrenewal']})
    set_lrebind=NUMBER                  Lease Rebind. Default ({$conf['dhcp_pool']['lrebind']})



EOM
);
    }
    // get the existing pool to edit
    list($status, $rows, $pool) = db_get_record($onadb, 'dhcp_pools', array('id' => $options['pool']));
    if (!$rows) {
        printmsg("DEBUG => Unable to find the DHCP pool record using id: {$options['id']}!", 3);
        $self['error'] = "ERROR => Unable to find a pool using id: {$options['pool']}";
        return array(1, $self['error'] . "\n");
    }
    // set the pool id in the set variable
    $SET['id'] = $pool['id'];
    // NOTE: currently modify pool does not allow you to change subnets
    // Get subnet info..
    list($status, $rows, $subnet) = ona_find_subnet($pool['subnet_id']);
    $SET['subnet_id'] = $subnet['id'];
    // make sure that the start address is actually part of an existing subnet
    if ($options['set_start']) {
        list($status, $rows, $subnetstart) = ona_find_subnet(ip_mangle($options['set_start'], 'dotted'));
        if (!$rows) {
            printmsg("DEBUG => Unable to find a subnet related to starting address ({$options['set_start']})!", 3);
            $self['error'] = "ERROR => Unable to find a subnet related to your starting address of {$options['set_start']}.";
            return array(1, $self['error'] . "\n");
        }
        if ($subnetstart['id'] != $pool['subnet_id']) {
            printmsg("DEBUG => The starting address ({$options['set_start']}) is not on the same subnet of the pool ({$pool['id']}) you are editing!", 3);
            $self['error'] = "ERROR => The starting address ({$options['set_start']}) is not on the same subnet of the pool ({$pool['id']}) you are editing!";
            return array(1, $self['error'] . "\n");
        }
    }
    // make sure that the end address is actually part of an existing subnet
    if ($options['set_end']) {
        list($status, $rows, $subnetend) = ona_find_subnet(ip_mangle($options['set_end'], 'dotted'));
        if (!$rows) {
            printmsg("DEBUG => Unable to find a subnet related to ending address ({$options['set_end']})!", 3);
            $self['error'] = "ERROR => Unable to find a subnet related to your ending address of {$options['set_end']}.";
            return array(1, $self['error'] . "\n");
        }
        if ($subnetend['id'] != $pool['subnet_id']) {
            printmsg("DEBUG => The ending address ({$options['set_end']}) is not on the same subnet of the pool ({$pool['id']}) you are editing!", 3);
            $self['error'] = "ERROR => The ending address ({$options['set_end']}) is not on the same subnet of the pool ({$pool['id']}) you are editing!";
            return array(1, $self['error'] . "\n");
        }
    }
    // Assign which failover group to use
    if ($options['set_failover_group'] == 0) {
        $desc = 'Not using a failover group';
        $SET['dhcp_failover_group_id'] = 0;
    } else {
        list($status, $rows, $fg) = ona_get_dhcp_failover_group_record(array('id' => $options['set_failover_group']));
        if (!$fg['id']) {
            printmsg("DEBUG => The failover_group specified ({$options['set_failover_group']}) does not exist", 3);
            $self['error'] = "ERROR => The failover_group specified ({$options['set_failover_group']}) does not exist!";
            return array(4, $self['error'] . "\n");
        }
        // get the server names for the two servers
        list($fail_host1, $fail_zone1) = ona_find_host($fg['primary_server_id']);
        list($fail_host2, $fail_zone2) = ona_find_host($fg['secondary_server_id']);
        $desc = $fail_host1['fqdn'] . '/' . $fail_host2['fqdn'];
        $SET['dhcp_failover_group_id'] = $fg['id'];
    }
    // check that start and end are not the same
    //if ($options['set_start'] and $options['set_end'] and $options['set_start'] == $options['set_end']) {
    //    printmsg("DEBUG => The start and end IP addresses (" . ip_mangle($options['set_start'],'dotted') . ") cannot be the same!",3);
    //    $self['error'] = "ERROR => The start and end IP addresses (" . ip_mangle($options['set_start'],'dotted') . ") cannot be the same!";
    //    return(array(2, $self['error'] . "\n"));
    //}
    if ($options['set_start']) {
        $start_dec = ip_mangle($options['set_start'], 'numeric');
    } else {
        $start_dec = $pool['ip_addr_start'];
    }
    if ($options['set_end']) {
        $end_dec = ip_mangle($options['set_end'], 'numeric');
    } else {
        $end_dec = $pool['ip_addr_end'];
    }
    $net_end = 4294967295 - $subnet['ip_mask'] + $subnet['ip_addr'];
    // Validate that the IP address supplied isn't the base or broadcast of the subnet
    if ($start_dec == $subnet['ip_addr'] or $end_dec == $subnet['ip_addr']) {
        printmsg("DEBUG => IP address can't be a subnet's base address (" . ip_mangle($subnet['ip_addr'], 'dotted') . ")!", 3);
        $self['error'] = "ERROR => IP address can't be a subnet's base address (" . ip_mangle($subnet['ip_addr'], 'dotted') . ")!";
        return array(7, $self['error'] . "\n");
    }
    if ($start_dec == $net_end or $end_dec == $net_end) {
        printmsg("DEBUG => IP address can't be a subnet's broadcast address (" . ip_mangle($net_end, 'dotted') . ")!", 3);
        $self['error'] = "ERROR => IP address can't be the subnet broadcast address(" . ip_mangle($net_end, 'dotted') . ")!";
        return array(8, $self['error'] . "\n");
    }
    // check that start is not after the end
    if ($start_dec > $end_dec) {
        printmsg("DEBUG => The start IP addresses (" . ip_mangle($start_dec, 'dotted') . ") falls after the end IP address (" . ip_mangle($end_dec, 'dotted') . ")!", 3);
        $self['error'] = "ERROR => The start IP addresses (" . ip_mangle($start_dec, 'dotted') . ") falls after the end IP address(" . ip_mangle($end_dec, 'dotted') . ")!";
        return array(2, $self['error'] . "\n");
    }
    // check for existing hosts inside the pool range
    list($status, $rows, $interface) = db_get_records($onadb, 'interfaces', 'subnet_id = ' . $subnet['id'] . ' AND ip_addr BETWEEN ' . $start_dec . ' AND ' . $end_dec, '', 0);
    if ($rows) {
        printmsg("DEBUG => IP conflict: Specified range (" . ip_mangle($start_dec, 'dotted') . "-" . ip_mangle($end_dec, 'dotted') . ") encompasses {$rows} host(s)!", 3);
        $self['error'] = "ERROR => IP conflict: Specified range (" . ip_mangle($start_dec, 'dotted') . "-" . ip_mangle($end_dec, 'dotted') . ") encompasses {$rows} host(s)";
        return array(4, $self['error'] . "\n");
    }
    // *** Check to see if the new pool overlaps any existing pools *** //
    // Look for overlaps like this (where new pool address starts inside an existing pool):
    //            [ -- new pool -- ]
    //    [ -- old pool --]
    list($status, $rows, $tmp) = db_get_record($onadb, 'dhcp_pools', 'id != ' . $SET['id'] . ' AND ' . $start_dec . ' BETWEEN ip_addr_start AND ip_addr_end');
    if ($rows != 0) {
        printmsg("DEBUG =>  Pool address conflict: New pool (" . ip_mangle($start_dec, 'dotted') . "-" . ip_mangle($end_dec, 'dotted') . ") starts inside an existing pool!", 3);
        $self['error'] = "ERROR => Pool address conflict! New pool (" . ip_mangle($start_dec, 'dotted') . "-" . ip_mangle($end_dec, 'dotted') . ") starts inside an existing pool.";
        return array(5, $self['error'] . "\n" . "INFO  => Conflicting pool record ID: {$tmp['id']}\n");
    }
    // Look for overlaps like this (where the new pool ends inside an existing pool):
    //    [ -- new pool -- ]
    //           [ -- old pool --]
    list($status, $rows, $tmp) = db_get_record($onadb, 'dhcp_pools', 'id != ' . $SET['id'] . ' AND ' . $end_dec . ' BETWEEN ip_addr_start AND ip_addr_end');
    if ($rows != 0) {
        printmsg("DEBUG =>  Pool address conflict: New pool (" . ip_mangle($start_dec, 'dotted') . "-" . ip_mangle($end_dec, 'dotted') . ") ends inside an existing pool!", 3);
        $self['error'] = "ERROR => Pool address conflict! New pool (" . ip_mangle($start_dec, 'dotted') . "-" . ip_mangle($end_dec, 'dotted') . ") ends inside an existing pool.";
        return array(6, $self['error'] . "\n" . "INFO  => Conflicting pool record ID: {$tmp['id']}\n");
    }
    // Look for overlaps like this (where the new pool entirely overlaps an existing pool):
    //    [ -------- new pool --------- ]
    //           [ -- old pool --]
    list($status, $rows, $tmp) = db_get_record($onadb, 'dhcp_pools', 'id != ' . $SET['id'] . ' AND (ip_addr_start BETWEEN ' . $start_dec . ' AND ' . $end_dec . ' OR ip_addr_end BETWEEN ' . $start_dec . ' AND ' . $end_dec . ')');
    if ($rows != 0) {
        printmsg("DEBUG =>  Pool address conflict: New pool (" . ip_mangle($start_dec, 'dotted') . "-" . ip_mangle($end_dec, 'dotted') . ") would encompass an existing pool!", 3);
        $self['error'] = "ERROR => Pool address conflict! New pool (" . ip_mangle($start_dec, 'dotted') . "-" . ip_mangle($end_dec, 'dotted') . ") would encompass an existing pool.";
        return array(7, $self['error'] . "\n" . "INFO  => Conflicting pool record ID: {$tmp['id']}\n");
    }
    // Check permissions
    if (!auth('advanced') or !authlvl($subnet['lvl'])) {
        $self['error'] = "Permission denied!";
        printmsg($self['error'], 0);
        return array(8, $self['error'] . "\n");
    }
    // define the remaining entries
    if (array_key_exists('set_lgrace', $options)) {
        $SET['lease_grace_period'] = $options['set_lgrace'];
    }
    if (array_key_exists('set_llength', $options)) {
        $SET['lease_length'] = $options['set_llength'];
    }
    if (array_key_exists('set_lrenewal', $options)) {
        $SET['lease_renewal_time'] = $options['set_lrenewal'];
    }
    if (array_key_exists('set_lrebind', $options)) {
        $SET['lease_rebind_time'] = $options['set_lrebind'];
    }
    // Set the IPs if you got this far
    $SET['ip_addr_start'] = $start_dec;
    $SET['ip_addr_end'] = $end_dec;
    // Get the DHCP pool record before updating (logging)
    list($status, $rows, $original_pool) = ona_get_dhcp_pool_record(array('id' => $SET['id']));
    // Update the record
    list($status, $rows) = db_update_record($onadb, 'dhcp_pools', array('id' => $SET['id']), $SET);
    if ($status or !$rows) {
        $self['error'] = "ERROR => dhcp_pool_modify() SQL Query failed: " . $self['error'];
        printmsg($self['error'], 0);
        return array(6, $add_to_error . $self['error'] . "\n");
    }
    $success_start = ip_mangle($SET['ip_addr_start'], 'dotted');
    $success_end = ip_mangle($SET['ip_addr_end'], 'dotted');
    // Get the DHCP pool record after updating (logging)
    list($status, $rows, $new_pool) = ona_get_dhcp_pool_record(array('id' => $SET['id']));
    // Return the success notice
    $self['error'] = "INFO => DHCP pool UPDATED:{$original_pool['id']}: {$success_start}-{$success_end} on {$subnet['name']}.";
    $log_msg = "INFO => DHCP pool UPDATED:{$original_pool['id']}: ";
    $more = "";
    foreach (array_keys($original_pool) as $key) {
        if ($original_pool[$key] != $new_pool[$key]) {
            $log_msg .= $more . $key . "[" . $original_pool[$key] . "=>" . $new_pool[$key] . "]";
            $more = ";";
        }
    }
    // only print to logfile if a change has been made to the record
    if ($more != '') {
        printmsg($self['error'], 0);
        printmsg($log_msg, 0);
    }
    return array(0, $add_to_error . $self['error'] . "\n");
}
Example #5
0
function dhcp_failover_group_display($options = "")
{
    // The important globals
    global $conf, $self, $onadb;
    // Version - UPDATE on every edit!
    $version = '1.00';
    printmsg("DEBUG => dhcp_failover_group_display({$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['id'] or $options['pri_server'] and $options['sec_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_failover_group_display-v{$version}
Displays an DHCP failover group record from the database

  Synopsis: dhcp_failover_group_display [KEY=VALUE] ...

  Required:
    id=id                              id of the DHCP failover group to display
    OR
    pri_server=NAME[.DOMAIN] or id     identifier of the primary server
    sec_server=NAME[.DOMAIN] or id     identifier of the secondary server



EOM
);
    }
    $search = array();
    if ($options['pri_server'] and $options['sec_server']) {
        // Determine the server is valid
        list($status, $rows, $pri_host) = ona_find_host($options['pri_server']);
        if (!$pri_host['id']) {
            printmsg("DEBUG => The server specified, {$options['pri_server']}, does not exist!", 3);
            $self['error'] = "ERROR => The server specified, {$options['pri_server']}, does not exist!";
            return array(2, $self['error'] . "\n");
        }
        // Determine the host that was found is actually a server
        // MP: FIXME: dont think I'm going to pursue doing a seperate server table.. lets remove
        //         list($status, $rows, $pri_server) = ona_get_server_record(array('host_id' => $pri_host['id']));
        //
        //         if (!$pri_server['id']) {
        //             printmsg("DEBUG => The host specified, {$pri_host['FQDN']}, is not a server!",3);
        //             $self['error'] = "ERROR => The host specified, {$pri_host['FQDN']}, is not a server!";
        //             return(array(5, $self['error'] . "\n"));
        //         }
        // Determine the server is valid
        list($status, $rows, $sec_host) = ona_find_host($options['sec_server']);
        if (!$sec_host['id']) {
            printmsg("DEBUG => The server specified, {$options['sec_server']}, does not exist!", 3);
            $self['error'] = "ERROR => The server specified, {$options['sec_server']}, does not exist!";
            return array(2, $self['error'] . "\n");
        }
        // Determine the host that was found is actually a server
        // MP: FIXME: dont think I'm going to pursue doing a seperate server table.. lets remove
        //         list($status, $rows, $sec_server) = ona_get_server_record(array('HOST_id' => $sec_host['id']));
        //
        //         if (!$sec_server['id']) {
        //             printmsg("DEBUG => The host specified, {$sec_host['fqdn']}, is not a server!",3);
        //             $self['error'] = "ERROR => The host specified, {$sec_host['fqdn']}, is not a server!";
        //             return(array(5, $self['error'] . "\n"));
        //         }
        $search['primary_server_id'] = $pri_server['id'];
        $search['secondary_server_id'] = $sec_server['id'];
    }
    if ($options['id']) {
        $search['id'] = $options['id'];
    }
    // Determine the entry itself exists
    list($status, $rows, $failovergroup) = ona_get_dhcp_failover_group_record($search);
    // Test to see that we were able to find the specified record
    if (!$failovergroup['id']) {
        printmsg("DEBUG => Unable to find the DHCP failover group record using {$options['id']}!", 3);
        $self['error'] = "ERROR => Unable to find the DHCP failover group record using {$options['id']}!";
        return array(4, $self['error'] . "\n");
    }
    list($status, $rows, $pri_server) = ona_find_host($failovergroup['primary_server_id']);
    list($status, $rows, $sec_server) = ona_find_host($failovergroup['secondary_server_id']);
    $failovergroup['pri_server_name'] = $pri_server['fqdn'];
    $failovergroup['sec_server_name'] = $sec_server['fqdn'];
    // Debugging
    printmsg("DEBUG => dhcp_failover_group_display(): Found id:{$failovergroup['id']}", 3);
    // Build text to return
    $text = "DHCP FAILOVER GROUP RECORD:\n";
    $text .= format_array($failovergroup);
    // Return the success notice
    return array(0, $text);
}
function ws_editor($window_name, $form = '')
{
    global $conf, $self, $onadb;
    global $font_family, $color, $style, $images;
    $window = array();
    // Check permissions
    if (!auth('advanced')) {
        $response = new xajaxResponse();
        $response->addScript("alert('Permission denied!');");
        return $response->getXML();
    }
    // If an array in a string was provided, build the array and store it in $form
    $form = parse_options_string($form);
    // Load an existing host record (and associated info) if $form is a host_id
    if ($form['id']) {
        list($status, $rows, $failovergroup) = ona_get_dhcp_failover_group_record(array('id' => $form['id']));
        if (!$rows) {
            $self['error'] = "ERROR => Unable to find the DHCP failover record using {$form['id']}!";
            return array(4, $self['error'] . "\n");
        }
        list($status, $rows, $pri_server) = ona_find_host($failovergroup['primary_server_id']);
        list($status, $rows, $sec_server) = ona_find_host($failovergroup['secondary_server_id']);
        $failovergroup['pri_server_name'] = $pri_server['fqdn'];
        $failovergroup['sec_server_name'] = $sec_server['fqdn'];
        // Set the window title:
        $window['title'] = "Edit DHCP Failover Group";
    } else {
        // Set up default failover information
        $failovergroup['max_response_delay'] = '60';
        $failovergroup['max_unacked_updates'] = '10';
        $failovergroup['max_load_balance'] = '3';
        $failovergroup['primary_port'] = '647';
        $failovergroup['peer_port'] = '847';
        $failovergroup['mclt'] = '1800';
        $failovergroup['split'] = '255';
        // Set the window title:
        $window['title'] = "Add DHCP Failover Group";
    }
    // Escape data for display in html
    foreach (array_keys((array) $failovergroup) as $key) {
        $failovergroup[$key] = htmlentities($failovergroup[$key], ENT_QUOTES, $conf['php_charset']);
    }
    // Javascript to run after the window is built
    $window['js'] = <<<EOL
        /* Put a minimize icon in the title bar */
        el('{$window_name}_title_r').innerHTML =
            '&nbsp;<a onClick="toggle_window(\\'{$window_name}\\');" title="Minimize window" style="cursor: pointer;"><img src="{$images}/icon_minimize.gif" border="0" /></a>' +
            el('{$window_name}_title_r').innerHTML;

        /* Put a help icon in the title bar */
        el('{$window_name}_title_r').innerHTML =
            '&nbsp;<a href="{$_ENV['help_url']}{$window_name}" target="null" title="Help" style="cursor: pointer;"><img src="{$images}/silk/help.png" border="0" /></a>' +
            el('{$window_name}_title_r').innerHTML;


        suggest_setup('failover_pri_hostname', 'suggest_failover_pri_hostname');
        suggest_setup('failover_sec_hostname', 'suggest_failover_sec_hostname');

        el('{$window_name}_edit_form').onsubmit = function() { return false; };

EOL;
    // Define the window's inner html
    $window['html'] = <<<EOL

    <!-- DHCP Failover Group Edit Form -->
    <form id="{$window_name}_edit_form" onSubmit="return false;">
    <input type="hidden" name="id" value="{$failovergroup['id']}">
    <input type="hidden" name="js" value="{$form['js']}">
    <table cellspacing="0" border="0" cellpadding="0" style="background-color: {$color['window_content_bg']}; padding-left: 20px; padding-right: 20px; padding-top: 5px; padding-bottom: 5px;">

        <!-- DHCP FAILOVER GROUP RECORD -->
        <tr>
            <td align="left" nowrap="true"><b><u>DHCP Failover Group Record</u></b>&nbsp;</td>
            <td class="padding" align="left" width="100%">&nbsp;</td>
        </tr>

        <tr>
            <td class="input_required" align="right" nowrap="true">
                Primary Server
            </td>
            <td class="padding" align="left" width="100%">
                <input
                    id="failover_pri_hostname"
                    name="pri_server"
                    alt="Primary Server"
                    value="{$failovergroup['pri_server_name']}"
                    class="edit"
                    type="text"
                    size="30" maxlength="255"
                >
                <div id="suggest_failover_pri_hostname" class="suggest"></div>
            </td>
        </tr>

        <tr>
            <td class="input_required" align="right" nowrap="true">
                Secondary Server
            </td>
            <td class="padding" align="left" width="100%">
                <input
                    id="failover_sec_hostname"
                    name="sec_server"
                    alt="Secondary Server"
                    value="{$failovergroup['sec_server_name']}"
                    class="edit"
                    type="text"
                    size="30" maxlength="255"
                >
                <div id="suggest_failover_sec_hostname" class="suggest"></div>
            </td>
        </tr>

        <tr>
            <td align="right" nowrap="true">
                Max Response Delay
            </td>
            <td class="padding" align="left" width="100%">
                <input
                    name="response_delay"
                    alt="Max Response Delay"
                    value="{$failovergroup['max_response_delay']}"
                    class="edit"
                    type="text"
                    size="10" maxlength="10"
                >
            </td>
        </tr>

        <tr>
            <td align="right" nowrap="true">
                Max Unacked Updates
            </td>
            <td class="padding" align="left" width="100%">
                <input
                    name="unacked_updates"
                    alt="Max Unacked Updates"
                    value="{$failovergroup['max_unacked_updates']}"
                    class="edit"
                    type="text"
                    size="10" maxlength="10"
                >
            </td>
        </tr>

        <tr>
            <td align="right" nowrap="true">
                Max Load Balance
            </td>
            <td class="padding" align="left" width="100%">
                <input
                    name="max_balance"
                    alt="Load Balance"
                    value="{$failovergroup['max_load_balance']}"
                    class="edit"
                    type="text"
                    size="10" maxlength="10"
                >
            </td>
        </tr>

        <tr>
            <td align="right" nowrap="true">
                Primary Port Num
            </td>
            <td class="padding" align="left" width="100%">
                <input
                    name="priport"
                    alt="Primary Port Num"
                    value="{$failovergroup['primary_port']}"
                    class="edit"
                    type="text"
                    size="10" maxlength="10"
                >
            </td>
        </tr>

        <tr>
            <td align="right" nowrap="true">
                Peer Port Num
            </td>
            <td class="padding" align="left" width="100%">
                <input
                    name="peerport"
                    alt="Peer Port Num"
                    value="{$failovergroup['peer_port']}"
                    class="edit"
                    type="text"
                    size="10" maxlength="10"
                >
            </td>
        </tr>

        <tr>
            <td align="right" nowrap="true">
                MCLT
            </td>
            <td class="padding" align="left" width="100%">
                <input
                    name="mclt"
                    alt="MCLT"
                    value="{$failovergroup['mclt']}"
                    class="edit"
                    type="text"
                    size="10" maxlength="10"
                >
            </td>
        </tr>

        <tr>
            <td align="right" nowrap="true">
                Split
            </td>
            <td class="padding" align="left" width="100%">
                <input
                    name="split"
                    alt="split"
                    value="{$failovergroup['split']}"
                    class="edit"
                    type="text"
                    size="10" maxlength="10"
                >
            </td>
        </tr>


        <tr>
            <td align="right" valign="top" nowrap="true">
                &nbsp;
            </td>
            <td class="padding" align="right" width="100%">
                <input type="hidden" name="overwrite" value="{$overwrite}">
                <input class="edit" type="button" name="cancel" value="Cancel" onClick="removeElement('{$window_name}');">
                <input class="edit" type="button"
                    name="submit"
                    value="Save"
                    accesskey=" "
                    onClick="xajax_window_submit('{$window_name}', xajax.getFormValues('{$window_name}_edit_form'), 'save');"
                >
            </td>
        </tr>

    </table>
    </form>
EOL;
    return window_open($window_name, $window);
}
Example #7
0
function ws_editor($window_name, $form = '')
{
    global $conf, $self, $onadb;
    global $font_family, $color, $style, $images;
    $window = array();
    // Check permissions
    if (!auth('advanced')) {
        $response = new xajaxResponse();
        $response->addScript("alert('Permission denied!');");
        return $response->getXML();
    }
    // If an array in a string was provided, build the array and store it in $form
    $form = parse_options_string($form);
    if ($form['subnet_id']) {
        $form['subnet'] = $form['subnet_id'];
    }
    // if it is a new pool, setup some things
    if (!$form['id']) {
        list($status, $rows, $subnet) = ona_get_subnet_record(array('id' => $form['subnet']));
        // set start and end IP to subnet IP
        $pool['start_ip'] = $pool['end_ip'] = ip_mangle($subnet['ip_addr'], 'dotted');
        // setup defaults for form values-- FIXME use $conf['dhcp_pool'] stuff later
        $pool['lease_length'] = '604800';
        $pool['lease_grace_period'] = '0';
        $pool['lease_rebind_time'] = '0';
        $pool['lease_renewal_time'] = '0';
        $pool['server_name_text'] = 'None';
        $window['title'] = "Add DHCP Pool";
    } else {
        list($status, $rows, $pool) = ona_get_dhcp_pool_record(array('id' => $form['id']));
        $pool['start_ip'] = ip_mangle($pool['ip_addr_start']);
        $pool['end_ip'] = ip_mangle($pool['ip_addr_end']);
        $pool['server_name_text'] = 'None';
        // Load the subnet record and associated info.
        if (is_numeric($form['subnet'])) {
            list($status, $rows, $subnet) = ona_get_subnet_record(array('id' => $form['subnet']));
        }
        // Load the server record and associated info.
        if ($pool['dhcp_failover_group_id'] >= 1) {
            list($status, $rows, $failover) = ona_get_dhcp_failover_group_record(array('id' => $pool['dhcp_failover_group_id']));
            list($status, $rows, $fail_host1) = ona_find_host($failover['primary_server_id']);
            list($status, $rows, $fail_host2) = ona_find_host($failover['secondary_server_id']);
            $pool['server_name_text'] = $fail_host1['fqdn'] . "/" . $fail_host2['fqdn'];
        }
        $window['title'] = "Edit DHCP Pool";
    }
    // Escape data for display in html
    foreach (array_keys((array) $subnet) as $key) {
        $subnet[$key] = htmlentities($subnet[$key], ENT_QUOTES, $conf['php_charset']);
    }
    foreach (array_keys((array) $failover) as $key) {
        $failover[$key] = htmlentities($failover[$key], ENT_QUOTES, $conf['php_charset']);
    }
    foreach (array_keys((array) $zone) as $key) {
        $zone[$key] = htmlentities($zone[$key], ENT_QUOTES, $conf['php_charset']);
    }
    foreach (array_keys((array) $host) as $key) {
        $host[$key] = htmlentities($host[$key], ENT_QUOTES, $conf['php_charset']);
    }
    foreach (array_keys((array) $server) as $key) {
        $server[$key] = htmlentities($server[$key], ENT_QUOTES, $conf['php_charset']);
    }
    // Javascript to run after the window is built
    $window['js'] = <<<EOL
        /* Put a minimize icon in the title bar */
        el('{$window_name}_title_r').innerHTML =
            '&nbsp;<a onClick="toggle_window(\\'{$window_name}\\');" title="Minimize window" style="cursor: pointer;"><img src="{$images}/icon_minimize.gif" border="0" /></a>' +
            el('{$window_name}_title_r').innerHTML;

        /* Put a help icon in the title bar */
        el('{$window_name}_title_r').innerHTML =
            '&nbsp;<a href="{$_ENV['help_url']}{$window_name}" target="null" title="Help" style="cursor: pointer;"><img src="{$images}/silk/help.png" border="0" /></a>' +
            el('{$window_name}_title_r').innerHTML;

        el('{$window_name}_form').onsubmit = function() { return false; };

        /* Setup the Quick Find pool server icon */
    var _button = el('qf_pool_server_{$window_name}');
    _button.style.cursor = 'pointer';
    _button.onclick =
        function(ev) {
            if (!ev) ev = event;
            /* Create the popup div */
            wwTT(this, ev,
                 'id', 'tt_qf_pool_server_{$window_name}',
                 'type', 'static',
                 'direction', 'south',
                 'delay', 0,
                 'styleClass', 'wwTT_qf',
                 'javascript',
                 "xajax_window_submit('tooltips', '" +
                     "tooltip=>qf_pool_server," +
                     "id=>tt_qf_pool_server_{$window_name}," +
                     "text_id=>pool_server_text_{$window_name}," +
                     "server=>set_pool_server_{$window_name}," +
                     "server_name=>{$pool['server_name_text']}," +
                     "failover_group_id=>{$pool['dhcp_failover_group_id']}," +
                     "failover_group=>set_failover_group_{$window_name}');"
            );
        };


EOL;
    // Define the window's inner html
    $window['html'] = <<<EOL

    <!-- DHCP pool Edit Form -->
    <form id="{$window_name}_form" onSubmit="return false;">
    <input type="hidden" name="id" value="{$pool['id']}">
    <input type="hidden" name="subnet_id" value="{$form['subnet']}">
    <input type="hidden" name="js" value="{$form['js']}">
    <table cellspacing="0" border="0" cellpadding="0" style="background-color: {$color['window_content_bg']}; padding-left: 20px; padding-right: 20px; padding-top: 5px; padding-bottom: 5px;">

        <!-- DHCP POOL RECORD -->
        <tr>
            <td align="left" nowrap="true"><b><u>DHCP Pool</u></b>&nbsp;</td>
            <td class="padding" align="left" width="100%">&nbsp;</td>
        </tr>

        <tr>
            <td align="right" nowrap="true">
                Subnet:
            </td>
            <td class="padding" align="left" width="100%">
                {$subnet['name']}
            </td>
        </tr>


        <tr>
            <td align="right" nowrap="true">
                Failover Group
            </td>
            <td class="padding" align="left" width="100%" nowrap="true">
                <input
                    type="hidden"
                    id="set_failover_group_{$window_name}"
                    name="failover_group"
                    value="{$pool['dhcp_failover_group_id']}">

                <span id="qf_pool_server_{$window_name}" title="DHCP Pool Server Quick Select">
                    <a id="pool_server_text_{$window_name}"
                       class="nav"
                    >{$pool['server_name_text']}</a>
                    <img src="{$images}/silk/find.png" border="0"
                /></span>
            </td>
        </tr>


        <!-- TODO: add a qf for IP addresses to list avail ips on subnet -->



        <tr>
            <td class="input_required" align="right" nowrap="true">
                IP Start
            </td>
            <td class="padding" align="left" width="100%">
                <input
                    name="start"
                    alt="IP Start"
                    value="{$pool['start_ip']}"
                    class="edit"
                    type="text"
                    size="25" maxlength="255"
                >
            </td>
        </tr>

        <tr>
            <td class="input_required" align="right" nowrap="true">
                IP End
            </td>
            <td class="padding" align="left" width="100%">
                <input
                    name="end"
                    alt="IP End"
                    value="{$pool['end_ip']}"
                    class="edit"
                    type="text"
                    size="25" maxlength="255"
                >
            </td>
        </tr>

        <tr>
            <td align="right" nowrap="true">
                Lease Length
            </td>
            <td class="padding" align="left" width="100%">
                <input
                    name="llength"
                    alt="Lease Length"
                    value="{$pool['lease_length']}"
                    class="edit"
                    type="text"
                    size="10" maxlength="10"
                >
            </td>
        </tr>

        <tr>
            <td align="right" nowrap="true">
                Lease Grace
            </td>
            <td class="padding" align="left" width="100%">
                <input
                    name="lgrace"
                    alt="Lease Grace"
                    value="{$pool['lease_grace_period']}"
                    class="edit"
                    type="text"
                    size="10" maxlength="10"
                >
            </td>
        </tr>

        <tr>
            <td align="right" nowrap="true">
                Lease Renewal
            </td>
            <td class="padding" align="left" width="100%">
                <input
                    name="lrenewal"
                    alt="Lease Renewal"
                    value="{$pool['lease_renewal_time']}"
                    class="edit"
                    type="text"
                    size="10" maxlength="10"
                >
            </td>
        </tr>


        <tr>
            <td align="right" nowrap="true">
                Lease Rebind
            </td>
            <td class="padding" align="left" width="100%">
                <input
                    name="lrebind"
                    alt="Lease Rebind"
                    value="{$pool['lease_rebind_time']}"
                    class="edit"
                    type="text"
                    size="10" maxlength="10"
                >
            </td>
        </tr>




        <tr>
            <td align="right" valign="top" nowrap="true">
                &nbsp;
            </td>
            <td class="padding" align="right" width="100%">
                <input type="hidden" name="overwrite" value="{$overwrite}">
                <input class="edit" type="button" name="cancel" value="Cancel" onClick="removeElement('{$window_name}');">
                <input class="edit" type="button"
                    name="submit"
                    value="Save"
                    accesskey=" "
                    onClick="xajax_window_submit('{$window_name}', xajax.getFormValues('{$window_name}_form'), 'save');"
                >
            </td>
        </tr>

    </table>
    </form>
EOL;
    return window_open($window_name, $window);
}