Example #1
0
function ona_find_vlan($vlan_search = "", $campus_search = "")
{
    global $self;
    if (!$vlan_search and !$campus_search) {
        return array(1, 0, array());
    }
    // If we got a vlan campus search string, let's look for that first.
    if ($campus_search) {
        $campus_search = strtoupper($campus_search);
        // Do a few sql queries and see if we can get a unique match
        $search = $campus_search;
        foreach (array('name', 'id') as $field) {
            list($status, $rows, $campus) = ona_get_vlan_campus_record(array($field => $search));
            if (!$status and $rows == 1) {
                printmsg("DEBUG => ona_find_vlan() found vlan campus record by {$field}", 2);
                break;
            } else {
                $campus = array();
            }
        }
    }
    // Search by a vlan number
    if (is_numeric($vlan_search)) {
        $where = array('number' => $vlan_search);
    } else {
        // Search for a vlan by NAME, use the campus[ID] if we have one
        $vlan_search = strtoupper($vlan_search);
        $where = array('name' => $vlan_search);
    }
    if ($campus['id']) {
        $where['vlan_campus_id'] = $campus['id'];
    }
    list($status, $rows, $vlan) = ona_get_vlan_record($where);
    if (!$status and $rows == 1) {
        return array($status, $rows, $vlan);
    }
    // We didn't find it - return and error code, 0 matches, and an empty record.
    $self['error'] = "NOTICE => couldn't find a unique vlan record with specified search criteria";
    printmsg($self['error'], 1);
    return array(2, 0, array());
}
Example #2
0
function ws_editor($window_name, $form = '')
{
    global $conf, $self, $onadb;
    global $font_family, $color, $style, $images;
    $window = array();
    // Check permissions
    if (!(auth('subnet_modify') and auth('subnet_add'))) {
        $response = new xajaxResponse();
        $response->addScript("alert('Permission denied!');");
        return $response->getXML();
    }
    // If the user supplied an array in a string, build the array and store it in $form
    $form = parse_options_string($form);
    // If $form is a number, it's an record ID- so we transform $form into an array
    if (is_numeric($form)) {
        $form = array('subnet_id' => $form);
    }
    $subnet = array();
    // Load an existing record (and associated info) if $form is an id
    if (is_numeric($form['subnet_id'])) {
        list($status, $rows, $subnet) = ona_get_subnet_record(array('id' => $form['subnet_id']));
        if ($rows) {
            if (strlen($subnet['ip_addr']) > 11) {
                $subnet['ip_mask'] = '/' . ip_mangle($subnet['ip_mask'], 'cidr');
            } else {
                $subnet['ip_mask'] = ip_mangle($subnet['ip_mask'], 'dotted');
            }
            $subnet['ip_addr'] = ip_mangle($subnet['ip_addr'], 'dotted');
            // Vlan Record
            list($status, $rows, $vlan) = ona_get_vlan_record(array('id' => $subnet['vlan_id']));
            $subnet['vlan_desc'] = $vlan['vlan_campus_name'] . ' / ' . $vlan['name'];
        }
    } else {
        if (strlen($form['ip_addr']) > 1) {
            $subnet['ip_addr'] = ip_mangle($form['ip_addr'], 'dotted');
        }
        if (strlen($form['ip_mask']) > 1) {
            $subnet['ip_mask'] = ip_mangle($form['ip_mask'], 'dotted');
        }
        if (strlen($form['name']) > 1) {
            $subnet['name'] = $form['name'];
        }
    }
    if (!$subnet['vlan_id']) {
        $subnet['vlan_desc'] = 'None';
    }
    // Escape data for display in html
    foreach (array_keys((array) $subnet) as $key) {
        $subnet[$key] = htmlentities($subnet[$key], ENT_QUOTES, $conf['php_charset']);
    }
    // Set the window title:
    $window['title'] = "Add Subnet";
    if ($subnet['id']) {
        $window['title'] = "Edit Subnet";
    }
    // Build subnet type list
    list($status, $rows, $subnettypes) = db_get_records($onadb, 'subnet_types', 'id > 0', 'display_name');
    $subnet_type_list = '<option value="">&nbsp;</option>\\n';
    $subnettypes['subnet_type_name'] = htmlentities($subnettypes['display_name']);
    foreach ($subnettypes as $record) {
        $selected = "";
        if ($record['id'] == $subnet['subnet_type_id']) {
            $selected = "SELECTED=\"selected\"";
        }
        if ($record['id']) {
            $subnet_type_list .= "<option {$selected} value=\"{$record['id']}\">{$record['display_name']}</option>\n";
        }
    }
    // 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}_edit_form').onsubmit = function() { return false; };


    /* Setup the Quick Find VLAN icon */
    var _button = el('qf_vlan_{$window_name}');
    _button.style.cursor = 'pointer';
    _button.onclick =
        function(ev) {
            if (!ev) ev = event;
            /* Create the popup div */
            wwTT(this, ev,
                 'id', 'tt_qf_vlan_{$window_name}',
                 'type', 'static',
                 'direction', 'south',
                 'delay', 0,
                 'styleClass', 'wwTT_qf',
                 'javascript',
                 "xajax_window_submit('tooltips', '" +
                     "tooltip=>qf_vlan," +
                     "id=>tt_qf_vlan_{$window_name}," +
                     "text_id=>vlan_text_{$window_name}," +
                     "input_id=>set_vlan_{$window_name}');"
            );
        };

    suggest_setup('masks_{$window_name}', 'suggest_masks_{$window_name}');

    el('set_name').focus();

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

    <!-- Subnet Edit Form -->
    <form id="{$window_name}_edit_form" onSubmit="return false;">
    <input type="hidden" name="subnet" value="{$subnet['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;">

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

        <tr>
            <td align="right" nowrap="true">
                VLAN
            </td>
            <td class="padding" align="left" width="100%" nowrap="true">
                <input
                    type="hidden"
                    id="set_vlan_{$window_name}"
                    name="set_vlan"
                    value="{$subnet['vlan_id']}">

                <span id="qf_vlan_{$window_name}">
                    <a id="vlan_text_{$window_name}"
                       class="nav"
                    >{$subnet['vlan_desc']}</a>
                    <img src="{$images}/silk/find.png" border="0"
                /></span>
            </td>
        </tr>

        <tr>
            <td class="input_required" align="right" nowrap="true">
                Name
            </td>
            <td class="padding" align="left" width="100%">
                <input
                    id="set_name"
                    name="set_name"
                    alt="Subnet name"
                    value="{$subnet['name']}"
                    class="edit"
                    type="text"
                    size="35" maxlength="100"
                >
            </td>
        </tr>

        <tr>
            <td class="input_required" align="right" nowrap="true">
                Subnet type
            </td>
            <td class="padding" align="left" width="100%">
                <select name="set_type" class="edit" accesskey="t">
                    {$subnet_type_list}
                </select>
            </td>
        </tr>

        <tr>
            <td class="input_required" align="right" nowrap="true">
                IP Address
            </td>
            <td class="padding" align="left" width="100%">
                <input
                    name="set_ip"
                    alt="IP Address"
                    value="{$subnet['ip_addr']}"
                    class="edit"
                    type="text"
                    size="35" maxlength="40"
                >
            </td>
        </tr>

        <tr>
            <td class="input_required" align="right" nowrap="true">
                Netmask
            </td>
            <td class="padding" align="left" width="100%">
                <input
                    id="masks_{$window_name}"
                    name="set_netmask"
                    alt="Netmask (i.e. 255.255.255.0 or /24)"
                    value="{$subnet['ip_mask']}"
                    class="edit"
                    type="text"
                    size="35" maxlength="17"
                >
                <div id="suggest_masks_{$window_name}" class="suggest"></div>
            </td>
        </tr>

EOL;
    // Show a "keep adding" checkbox if they are adding records
    if (!isset($subnet['id'])) {
        $window['html'] .= <<<EOL
        <tr>
            <td align="right" nowrap="true">
                &nbsp;
            </td>
            <td class="padding" align="left" width="100%">
                <input
                    name="keepadding"
                    alt="Keep adding more subnets"
                    type="checkbox"
                > Keep adding more subnets
            </td>
        </tr>

        <tr>
            <td colspan="2" class="padding" align="center" width="100%">
            <span id="statusinfo_{$window_name}" style="color: green;" ></span>
            </td>
        </tr>

EOL;
    }
    $window['html'] .= <<<EOL

        <tr>
            <td align="right" valign="top" nowrap="true">
                &nbsp;
            </td>
            <td class="padding" align="right" width="100%">
                <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);
}
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);
}
Example #4
0
function subnet_display($options = "")
{
    global $conf, $self, $onadb;
    printmsg('DEBUG => subnet_display(' . $options . ') called', 3);
    $text_array = array();
    // Version - UPDATE on every edit!
    $version = '1.03';
    // 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']) {
        // 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_display-v{$version}
Displays an subnet record from the database

  Synopsis: subnet_display [KEY=VALUE] ...

  Required:
    subnet=[ID|IP]               display subnet by search string

  Optional:
    verbose=[yes|no]              display additional info (yes)

  Notes:
    * An error is returned if search string returns more than one subnet
    * IP can be in dotted, numeric, or IPv6 format


EOM
);
    }
    // Sanitize "options[verbose]" (yes is the default)
    $options['verbose'] = sanitize_YN($options['verbose'], 'Y');
    // They provided a subnet ID or IP address
    // Find a subnet record
    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");
    }
    // Gather sizing
    list($percent, $total_used, $size) = get_subnet_usage($subnet['id']);
    $subnet['total_allocated_percent'] = $percent;
    $subnet['total_allocated'] = $total_used;
    $subnet['total_available'] = $size;
    // get subnet type name
    list($status, $rows, $sntype) = ona_get_subnet_type_record(array('id' => $subnet['subnet_type_id']));
    $subnet['subnet_type_name'] = $sntype['display_name'];
    // Convert some data
    $text_array = $subnet;
    $text_array['ip_addr_text'] = ip_mangle($subnet['ip_addr'], 'dotted');
    $text_array['ip_mask_text'] = ip_mangle($subnet['ip_mask'], 'dotted');
    $text_array['ip_mask_cidr'] = ip_mangle($subnet['ip_mask'], 'cidr');
    // Build text to return
    $text = "SUBNET RECORD\n";
    $text .= format_array($subnet);
    // If 'verbose' is enabled, grab some additional info to display
    if ($options['verbose'] == 'Y') {
        // Tag records
        list($status, $rows, $tags) = db_get_records($onadb, 'tags', array('type' => 'subnet', 'reference' => $subnet['id']));
        if ($rows) {
            $text .= "\nASSOCIATED TAG RECORDS\n";
            foreach ($tags as $tag) {
                $text_array['tags'][] = $tag['name'];
                $text .= "  {$tag['name']}\n";
            }
        }
        // VLAN record
        list($status, $rows, $vlan) = ona_get_vlan_record(array('id' => $subnet['vlan_id']));
        if ($rows) {
            $text_array['vlan'] = $vlan;
            $text .= "\nASSOCIATED VLAN RECORD\n";
            $text .= format_array($vlan);
        }
    }
    // cleanup some un-used junk
    unset($text_array['network_role_id']);
    unset($text_array['vlan_id']);
    // change the output format if other than default
    if ($options['format'] == 'json') {
        $text = $text_array;
    }
    if ($options['format'] == 'yaml') {
        $text = $text_array;
    }
    // Return the success notice
    return array(0, $text);
}
Example #5
0
function vlan_campus_display($options = "")
{
    global $conf, $self, $onadb;
    // Version - UPDATE on every edit!
    $version = '1.00';
    printmsg("DEBUG => vlan_campus_display({$options}) called", 3);
    // Parse incoming options string to an array
    $options = parse_options($options);
    // Sanitize options[verbose] (default is yes)
    $options['verbose'] = sanitize_YN($options['verbose'], 'Y');
    // Return the usage summary if we need to
    if ($options['help'] or !$options['campus']) {
        // 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_display-v{$version}
Displays a vlan campus record from the database

  Synopsis: vlan_campus_display [KEY=VALUE] ...

  Required:
    campus=NAME or ID      Campus name or ID of the campus display

  Optional:
    verbose=[yes|no]       Display additional info (DEFAULT: yes)


EOM
);
    }
    // The formatting rule on campus names is all upper and trim it
    $options['campus'] = strtoupper(trim($options['campus']));
    // If the campus provided is numeric, check to see if it's valid
    if (is_numeric($options['campus'])) {
        // See if it's an vlan_campus_id
        list($status, $rows, $campus) = ona_get_vlan_campus_record(array('id' => $options['campus']));
        if (!$campus['id']) {
            printmsg("DEBUG => Unable to find campus using the ID {$options['campus']}!", 3);
            $self['error'] = "ERROR => Unable to find campus using the ID {$options['campus']}!";
            return array(2, $self['error'] . "\n");
        }
    } else {
        list($status, $rows, $campus) = ona_get_vlan_campus_record(array('name' => $options['campus']));
        if (!$campus['id']) {
            $self['error'] = "ERROR => Unable to find campus using the name {$options['campus']}!";
            printmsg("DEBUG => Unable to find campus using the name {$options['campus']}!", 3);
            return array(2, $self['error'] . "\n");
        }
    }
    printmsg("DEBUG => Found campus: {$campus['name']}", 3);
    // Build text to return
    $text = "VLAN CAMPUS RECORD\n";
    $text .= format_array($campus);
    // If 'verbose' is enabled, grab some additional info to display
    if ($options['verbose'] == 'Y') {
        // vlan record(s)
        $i = 0;
        do {
            list($status, $rows, $vlan) = ona_get_vlan_record(array('vlan_campus_id' => $campus['id']));
            if ($rows == 0) {
                break;
            }
            $i++;
            $text .= "\nASSOCIATED VLAN RECORD ({$i} of {$rows})\n";
            $text .= format_array($vlan);
        } while ($i < $rows);
    }
    // Return the success notice
    return array(0, $text);
}
Example #6
0
function ws_display($window_name, $form = '')
{
    global $conf, $self, $onadb;
    global $images, $color, $style;
    $html = '';
    $js = '';
    $debug_val = 3;
    // used in the auth() calls to supress logging
    // If the user supplied an array in a string, build the array and store it in $form
    $form = parse_options_string($form);
    // Load the subnet record
    if ($form['subnet_id']) {
        list($status, $rows, $record) = ona_get_subnet_record(array('id' => $form['subnet_id']));
    } else {
        if ($form['ip']) {
            list($status, $rows, $record) = ona_get_subnet_record("ip_addr like '" . ip_mangle($form['ip'], 'numeric') . "'");
        } else {
            if ($form['subnet']) {
                list($status, $rows, $record) = ona_get_subnet_record(array('name' => $form['subnet']));
            }
        }
    }
    if ($status or !$rows) {
        array_pop($_SESSION['ona']['work_space']['history']);
        $html .= "<br><center><font color=\"red\"><b>Subnet doesn't exist!</b></font></center>";
        $response = new xajaxResponse();
        $response->addAssign("work_space_content", "innerHTML", $html);
        return $response->getXML();
    }
    // Update History Title
    $history = array_pop($_SESSION['ona']['work_space']['history']);
    $js .= "xajax_window_submit('work_space', ' ', 'rewrite_history');";
    if ($history['title'] == $window_name) {
        $history['title'] = $record['name'];
        array_push($_SESSION['ona']['work_space']['history'], $history);
    }
    // Create some javascript to refresh the current page
    $refresh = htmlentities(str_replace(array("'", '"'), array("\\'", '\\"'), $history['url']), ENT_QUOTES, $conf['php_charset']);
    $refresh = "xajax_window_submit('work_space', '{$refresh}');";
    // is this an ipv6 subnet?
    if (strlen($record['ip_addr']) > 11) {
        $extravars['isipv6'] = TRUE;
    }
    // Convert IP and Netmask to a presentable format
    $record['ip_addr'] = ip_mangle($record['ip_addr'], 'dotted');
    $record['ip_mask'] = ip_mangle($record['ip_mask'], 'dotted');
    $record['ip_subnet_mask_cidr'] = ip_mangle($record['ip_mask'], 'cidr');
    list($status, $rows, $type) = ona_get_subnet_type_record(array('id' => $record['subnet_type_id']));
    $record['type'] = $type['display_name'];
    // Vlan Record
    list($status, $rows, $vlan) = ona_get_vlan_record(array('id' => $record['vlan_id']));
    $record['vlan_name'] = $vlan['name'];
    $record['vlan_campus_id'] = $vlan['vlan_campus_id'];
    $record['vlan_campus_name'] = $vlan['vlan_campus_name'];
    // extra stuff to pass to ws_plugins
    $extravars['refresh'] = $refresh;
    $extravars['window_name'] = $window_name;
    // Escape data for display in html
    foreach (array_keys($record) as $key) {
        $record[$key] = htmlentities($record[$key], ENT_QUOTES, $conf['php_charset']);
    }
    // Create a div for workspace plugins to live
    $html .= "<div id='wsplugins' style='margin: 10px;'>";
    $wspl = workspace_plugin_loader('subnet_detail', $record, $extravars);
    $html .= $wspl[0];
    $js .= $wspl[1];
    $wsmenu[] = $wspl[2];
    $wspl = workspace_plugin_loader('dhcp_servers', $record, $extravars);
    $html .= $wspl[0];
    $js .= $wspl[1];
    $wsmenu[] = $wspl[2];
    $wspl = workspace_plugin_loader('dhcp_pools', $record, $extravars);
    $html .= $wspl[0];
    $js .= $wspl[1];
    $wsmenu[] = $wspl[2];
    $wspl = workspace_plugin_loader('dhcp_entries', $record, $extravars);
    $html .= $wspl[0];
    $js .= $wspl[1];
    $wsmenu[] = $wspl[2];
    $wspl = workspace_plugin_loader('custom_attributes', $record, $extravars);
    $html .= $wspl[0];
    $js .= $wspl[1];
    $wsmenu[] = $wspl[2];
    // Display messages
    $wspl = workspace_plugin_loader('messages', $record, $extravars);
    $html .= $wspl[0];
    $js .= $wspl[1];
    $wsmenu[] = $wspl[2];
    // Display messages
    $wspl = workspace_plugin_loader('reports', $record, $extravars);
    $html .= $wspl[0];
    $js .= $wspl[1];
    $wsmenu[] = $wspl[2];
    // Get all the plugin based worspace items
    $wspl_list = plugin_list('wspl_item');
    // Load all the dynamic plugins
    foreach ($wspl_list as $p) {
        $wspl = workspace_plugin_loader($p['path'], $record, $extravars);
        $html .= $wspl[0];
        $js .= $wspl[1];
        $wsmenu[] = $wspl[2];
    }
    // Gather our menuitems and build the HTML
    $wsmenuhtml = build_workspace_menu($wsmenu);
    $html .= <<<EOL

    </div>
    <br style="clear:both;">

    <form id="form_subnet_{$record['id']}"
        ><input type="hidden" name="subnet_id" value="{$record['id']}"
        ><input type="hidden" name="js" value="{$refresh}"
    ></form>

    <div id='wsmenu' style='display:none;'>{$wsmenuhtml}</div>

EOL;
    // HOST LIST
    $tab = 'hosts';
    $submit_window = "list_{$tab}";
    $form_id = "{$submit_window}_filter_form";
    $_SESSION['ona'][$form_id]['tab'] = $tab;
    $content_id = "{$window_name}_{$submit_window}";
    $html .= <<<EOL
    <!-- HOST LIST -->
    <div style="border: 1px solid {$color['border']}; margin: 10px 20px;">

        <!-- Tab & Quick Filter -->
        <table id="{$form_id}_table" cellspacing="0" border="0" cellpadding="0">
            <tr>
                <td id="{$form_id}_{$tab}_tab" class="table-tab-active">
                    Associated {$tab} <span id="{$form_id}_{$tab}_count"></span>
                </td>

                <td id="{$form_id}_quick_filter" class="padding" align="right" width="100%">
                    <form id="{$form_id}" onSubmit="return false;">
                    <input id="{$form_id}_page" name="page" value="1" type="hidden">
                    <input name="content_id" value="{$content_id}" type="hidden">
                    <input name="form_id" value="{$form_id}" type="hidden">
                    <input name="subnet_id" value="{$record['id']}" type="hidden">
                    <div id="{$form_id}_filter_overlay"
                         title="Filter"
                         style="position: relative;
                                display: inline;
                                color: #CACACA;
                                cursor: text;"
                         onClick="this.style.display = 'none'; el('{$form_id}_filter').focus();"
                    >Name</div>
                    <input
                        id="{$form_id}_filter"
                        name="filter"
                        class="filter"
                        type="text"
                        value=""
                        size="10"
                        maxlength="20"
                        alt="Quick Filter"
                        onFocus="el('{$form_id}_filter_overlay').style.display = 'none';"
                        onBlur="if (this.value == '') el('{$form_id}_filter_overlay').style.display = 'inline';"
                        onKeyUp="
                            if (typeof(timer) != 'undefined') clearTimeout(timer);
                            code = 'if ({$form_id}_last_search != el(\\'{$form_id}_filter\\').value) {' +
                                   '    {$form_id}_last_search = el(\\'{$form_id}_filter\\').value;' +
                                   '    document.getElementById(\\'{$form_id}_page\\').value = 1;' +
                                   '    xajax_window_submit(\\'{$submit_window}\\', xajax.getFormValues(\\'{$form_id}\\'), \\'display_list\\');' +
                                   '}';
                            timer = setTimeout(code, 700);"
                    >
                    </form>
                </td>

            </tr>
        </table>

        <div id='{$content_id}'>{$conf['loading_icon']}</div>

        <!-- ADD HOST LINK -->
        <div class="act-box" style="padding: 2px 4px; border-top: 1px solid {$color['border']}">
            <form id="form_host_add_{$record['id']}"
                ><input type="hidden" name="subnet_id" value="{$record['id']}"
                ><input type="hidden" name="js" value="{$refresh}"
            ></form>
EOL;
    if (auth('host_add', $debug_val)) {
        $html .= <<<EOL
            <a title="Add host"
               class="act"
               onClick="xajax_window_submit('edit_host', xajax.getFormValues('form_host_add_{$record['id']}'), 'editor');"
            ><img src="{$images}/silk/page_add.png" border="0"></a>&nbsp;

            <a title="Add host"
               class="act"
               onClick="xajax_window_submit('edit_host', xajax.getFormValues('form_host_add_{$record['id']}'), 'editor');"
            >Add a new host</a>&nbsp;
EOL;
    }
    if (auth('interface_modify', $debug_val)) {
        $html .= <<<EOL

             <a title="Add interface"
               class="act"
               onClick="xajax_window_submit('edit_interface', xajax.getFormValues('form_host_add_{$record['id']}'), 'editor');"
            ><img src="{$images}/silk/page_add.png" border="0"></a>&nbsp;

            <a title="Add interface"
               class="act"
               onClick="xajax_window_submit('edit_interface', xajax.getFormValues('form_host_add_{$record['id']}'), 'editor');"
            >Add interface to an existing host</a>&nbsp;
EOL;
    }
    $html .= <<<EOL

            <!-- List by IP Address LINK -->
            <a title="List Hosts by IP"
               class="act"
               onClick="xajax_window_submit('app_full_list',  xajax.getFormValues('{$form_id}'), 'display');"
            ><img src="{$images}/silk/page_white_go.png" border="0"></a>&nbsp;

            <a title="List Hosts by IP"
               class="act"
               onClick="xajax_window_submit('app_full_list',  xajax.getFormValues('{$form_id}'), 'display');"
            >List Hosts by IP</a>&nbsp;

        </div>

    </div>
EOL;
    $js .= <<<EOL
        /* Setup the quick filter */
        el('{$form_id}_filter_overlay').style.left = (el('{$form_id}_filter_overlay').offsetWidth + 10) + 'px';
        {$form_id}_last_search = '';

        /* Tell the browser to load/display the list */
        xajax_window_submit('{$submit_window}', xajax.getFormValues('{$form_id}'), 'display_list');
EOL;
    // Temp turn OFF of the dhcp lease list.. its not ready yet.
    $haspool = 0;
    if ($haspool == 1) {
        // DHCP Lease LIST
        $tab = 'dhcp_leases';
        $submit_window = "list_{$tab}";
        $form_id = "{$submit_window}_filter_form";
        $_SESSION['ona'][$form_id]['tab'] = $tab;
        $content_id = "{$window_name}_{$submit_window}";
        $html .= <<<EOL
    <!-- Lease LIST -->
    <div style="border: 1px solid {$color['border']}; margin: 10px 20px;">

        <!-- Tab & Quick Filter -->
        <table id="{$form_id}_table" cellspacing="0" border="0" cellpadding="0">
            <tr>
                <td id="{$form_id}_{$tab}_tab" class="table-tab-active">
                    Associated {$tab} <span id="{$form_id}_{$tab}_count"></span>
                </td>

                <td id="{$form_id}_quick_filter" class="padding" align="right" width="100%">
                    <form id="{$form_id}" onSubmit="return false;">
                    <input id="{$form_id}_page" name="page" value="1" type="hidden">
                    <input name="content_id" value="{$content_id}" type="hidden">
                    <input name="form_id" value="{$form_id}" type="hidden">
                    <input name="subnet" value="{$record['id']}" type="hidden">
                    <div id="{$form_id}_filter_overlay"
                         style="position: relative;
                                display: inline;
                                color: #CACACA;
                                cursor: text;"
                         onClick="this.style.display = 'none'; el('{$form_id}_filter').focus();"
                    >Filter</div>
                    <input
                        id="{$form_id}_filter"
                        name="filter"
                        class="filter"
                        type="text"
                        value=""
                        size="10"
                        maxlength="20"
                        alt="Quick Filter"
                        onFocus="el('{$form_id}_filter_overlay').style.display = 'none';"
                        onBlur="if (this.value == '') el('{$form_id}_filter_overlay').style.display = 'inline';"
                        onKeyUp="
                            if (typeof(timer) != 'undefined') clearTimeout(timer);
                            code = 'if ({$form_id}_last_search != el(\\'{$form_id}_filter\\').value) {' +
                                   '    {$form_id}_last_search = el(\\'{$form_id}_filter\\').value;' +
                                   '    document.getElementById(\\'{$form_id}_page\\').value = 1;' +
                                   '    xajax_window_submit(\\'{$submit_window}\\', xajax.getFormValues(\\'{$form_id}\\'), \\'display_list\\');' +
                                   '}';
                            timer = setTimeout(code, 700);"
                    >
                    </form>
                </td>

            </tr>
        </table>

        <div id='{$content_id}'>
            {$conf['loading_icon']}
        </div>


    </div>
EOL;
        $js .= <<<EOL
        /* Setup the quick filter */
        el('{$form_id}_filter_overlay').style.left = (el('{$form_id}_filter_overlay').offsetWidth + 10) + 'px';
        {$form_id}_last_search = '';

        /* Tell the browser to load/display the list */
        xajax_window_submit('{$submit_window}', xajax.getFormValues('{$form_id}'), 'display_list');

EOL;
    }
    // Insert the new html into the window
    // Instantiate the xajaxResponse object
    $response = new xajaxResponse();
    $response->addAssign("work_space_content", "innerHTML", $html);
    if ($js) {
        $response->addScript($js);
    }
    return $response->getXML();
}
Example #7
0
function vlan_modify($options = "")
{
    // The important globals
    global $conf, $self, $onadb;
    // Version - UPDATE on every edit!
    $version = '1.01';
    printmsg("DEBUG => vlan_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['vlan'] or !($options['set_name'] or $options['set_number'] or $options['set_campus'])) {
        // 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_modify-v{$version}
Modifies an vlan entry in the database

  Synopsis: vlan_modify [KEY=VALUE] ...

  Where:
    vlan=ID                        vlan ID

  Update:
    set_name=NAME                  change vlan name
    set_number=NUMBER              change vlan number
    set_campus=NAME or ID          change campus the vlan belongs to



EOM
);
    }
    // The formatting rule on vlan names/campus names is all upper and trim it, spaces to -
    $options['set_name'] = strtoupper(trim($options['set_name']));
    $options['set_name'] = preg_replace('/\\s+/', '-', $options['set_name']);
    $options['set_campus'] = strtoupper(trim($options['set_campus']));
    $options['set_number'] = trim($options['set_number']);
    // Load the record we will be modifying
    list($status, $rows, $vlan) = ona_get_vlan_record(array('id' => $options['vlan']));
    // Validate that we got a record back, or return an error
    if (!$vlan['id']) {
        printmsg("DEBUG => The VLAN ID specified ({$options['vlan']}) does not exist!", 3);
        $self['error'] = "ERROR => The VLAN ID specified, {$options['vlan']}, does not exist!";
        return array(2, $self['error'] . "\n");
    }
    printmsg("DEBUG => Found VLAN: {$vlan['name']}", 3);
    // This variable will contain the updated info we'll insert into the DB
    $SET = array();
    // If they are specifying a new name, process it.
    if ($options['set_name']) {
        // Validate that there isn't already an vlan with this name
        $options['set_name'] = strtoupper(trim($options['set_name']));
        list($status, $rows, $record) = db_get_records($onadb, 'vlans', "vlan_campus_id = {$vlan['vlan_campus_id']} AND name LIKE '{$options['set_name']}' AND number != {$vlan['number']}");
        if ($status or $rows) {
            printmsg("DEBUG => The VLAN ({$options['set_name']}) already exists on this campus!", 3);
            $self['error'] = "ERROR => The VLAN {$options['set_name']} already exists on this campus!";
            return array(4, $self['error'] . "\n");
        }
        if ($vlan['name'] != $options['set_name']) {
            $SET['name'] = $options['set_name'];
        }
    }
    if ($options['set_number']) {
        // Validate that there isn't already an vlan on this campus with this vlan number
        list($status, $rows, $record) = db_get_records($onadb, 'vlans', "vlan_campus_id = {$vlan['vlan_campus_id']} AND number = {$options['set_number']} AND name NOT LIKE '{$vlan['name']}'");
        if ($status or $rows) {
            printmsg("DEBUG => The VLAN with the number ({$options['set_number']}) already exists on this campus!", 3);
            $self['error'] = "ERROR => The vlan with the number {$options['set_number']} already exists on this campus!";
            return array(3, $self['error'] . "\n");
        }
        // Add the new info to $SET
        if ($vlan['number'] != $options['set_number']) {
            $SET['number'] = $options['set_number'];
        }
    }
    // FIXME: yes I'm lazy.. test that the new campus does not have the vlan name or number already on it.
    // If they are changing the campus the vlan points to, process it
    if ($options['set_campus']) {
        $options['set_campus'] = strtoupper(trim($options['set_campus']));
        if (is_numeric($options['set_campus'])) {
            list($status, $rows, $record) = ona_get_vlan_campus_record(array('id' => $options['set_campus']));
        }
        if (!array_key_exists('id', $record)) {
            list($status, $rows, $record) = ona_get_vlan_campus_record(array('name' => $options['set_campus']));
        }
        // Make sure that worked - or return an error
        if (!$record['id']) {
            printmsg("DEBUG => The campus ({$options['set_campus']}) does not exist!", 3);
            $self['error'] = "ERROR => The campus specified, {$options['set_campus']}, does not exist!";
            return array(5, $self['error'] . "\n");
        }
        // test that the new campus does not have the vlan name or number already on it.
        // only check if the campus has changed
        if ($record['id'] != $vlan['vlan_campus_id']) {
            // build where clause for checking the new campus for the vlan name/number
            $where = '';
            $OR = '';
            if (array_key_exists('number', $SET)) {
                $where .= " number = {$SET['number']} ";
                $OR = " OR ";
            }
            if (array_key_exists('name', $SET)) {
                $where .= "{$OR} name LIKE '{$SET['name']}' ";
            }
            list($status, $rows, $new_campus_record) = db_get_records($onadb, 'vlans', "vlan_campus_id = {$record['id']} AND ({$where})");
            if ($rows > 0) {
                printmsg("DEBUG => The campus ({$options['set_campus']}) already contains this VLAN name or number ({$SET['name']} {$SET['number']})!", 3);
                $self['error'] = "ERROR => The campus specified, {$options['set_campus']}, already contains this VLAN name or number ({$SET['name']} {$SET['number']})!";
                return array(7, $self['error'] . "\n");
            }
        }
        // Add the new info to $SET
        if ($vlan['vlan_campus_id'] != $record['id']) {
            $SET['vlan_campus_id'] = $record['id'];
        }
    }
    // Check permissions
    if (!auth('vlan_modify')) {
        $self['error'] = "Permission denied!";
        printmsg($self['error'], 0);
        return array(10, $self['error'] . "\n");
    }
    if ($SET) {
        // Update the record
        list($status, $rows) = db_update_record($onadb, 'vlans', array('id' => $vlan['id']), $SET);
        if ($status or !$rows) {
            $self['error'] = "ERROR => vlan_modify() SQL Query failed: " . $self['error'];
            printmsg($self['error'], 0);
            return array(6, $self['error'] . "\n");
        }
    }
    // Get the VLAN record after updating (logging)
    list($status, $rows, $new_vlan) = ona_get_vlan_record(array('id' => $options['vlan']));
    list($status, $rows, $campus) = ona_get_vlan_campus_record(array('id' => $new_vlan['vlan_campus_id']));
    $text = <<<EOL

    NAME:   {$new_vlan['name']}
    NUMBER: {$new_vlan['number']}
    CAMPUS: {$campus['name']}


EOL;
    // Return the success notice
    $renamed = '';
    if ($new_vlan['name'] != $vlan['name']) {
        $renamed .= "{$vlan['name']} => {$new_vlan['name']} ";
    }
    if ($new_vlan['number'] != $vlan['number']) {
        $renamed .= "VLAN Num {$vlan['number']} => {$new_vlan['number']} ";
    }
    if ($new_vlan['vlan_campus_id'] != $vlan['vlan_campus_id']) {
        $renamed .= "Campus ID {$vlan['vlan_campus_id']} => {$new_vlan['vlan_campus_id']}";
    }
    $self['error'] = "INFO => VLAN UPDATED: {$renamed}";
    return array(0, $self['error'] . "\n {$text}");
}
Example #8
0
function ws_display($window_name, $form = '')
{
    global $conf, $self, $onadb;
    global $images, $color, $style;
    $html = '';
    $js = '';
    $debug_val = 3;
    // used in the auth() calls to supress logging
    // 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, $record) = ona_get_vlan_record(array('id' => $form['vlan_id']));
    if ($status or !$rows) {
        array_pop($_SESSION['ona']['work_space']['history']);
        $html .= "<br><center><font color=\"red\"><b>VLAN doesn't exist!</b></font></center>";
        $response = new xajaxResponse();
        $response->addAssign("work_space_content", "innerHTML", $html);
        return $response->getXML();
    }
    // Get campus info
    list($status, $rows, $vlan_campus) = ona_get_vlan_campus_record(array('id' => $record['vlan_campus_id']));
    $record['vlan_campus_name'] = $vlan_campus['name'];
    $record['vlan_campus_id'] = $vlan_campus['id'];
    // Update History Title (and tell the browser to re-draw the history div)
    $history = array_pop($_SESSION['ona']['work_space']['history']);
    $js .= "xajax_window_submit('work_space', ' ', 'rewrite_history');";
    if ($history['title'] == $window_name) {
        $history['title'] = $record['name'];
        array_push($_SESSION['ona']['work_space']['history'], $history);
    }
    // Create some javascript to refresh the current page
    $refresh = htmlentities(str_replace(array("'", '"'), array("\\'", '\\"'), $history['url']), ENT_QUOTES, $conf['php_charset']);
    $refresh = "xajax_window_submit('work_space', '{$refresh}');";
    $style['content_box'] = <<<EOL
        margin: 10px 20px;
        padding: 2px 4px;
        background-color: #FFFFFF;
        vertical-align: top;
EOL;
    $style['label_box'] = <<<EOL
        font-weight: bold;
        padding: 2px 4px;
        border: solid 1px {$color['border']};
        background-color: {$color['window_content_bg']};
EOL;
    // Escape data for display in html
    foreach (array_keys($record) as $key) {
        $record[$key] = htmlentities($record[$key], ENT_QUOTES, $conf['php_charset']);
    }
    // Create a div for workspace plugins to live
    $html .= "<div id='wsplugins' style='margin: 10px;'>";
    $html .= <<<EOL
    <!-- FORMATTING TABLE -->
      <div id="vlan_detail" class="ws_plugin_content">

EOL;
    // VLAN INFORMATION
    $html .= <<<EOL
            <table width=100% cellspacing="0" border="0" cellpadding="0" style="margin-bottom: 8px;">

                <tr><td colspan="99" nowrap="true" style="{$style['label_box']}">
                    <!-- LABEL -->
                    <form id="form_vlan_{$record['id']}"
                        ><input type="hidden" name="vlan_id" value="{$record['id']}"
                        ><input type="hidden" name="js" value="{$refresh}"
                    ></form>
EOL;
    if (auth('vlan_del', $debug_val)) {
        $html .= <<<EOL
                    <a title="Edit Vlan. ID: {$record['id']}"
                       class="act"
                       onClick="xajax_window_submit('edit_vlan', xajax.getFormValues('form_vlan_{$record['id']}'), 'editor');"
                    ><img src="{$images}/silk/page_edit.png" border="0"></a>&nbsp;

                    <a title="Delete Vlan. ID: {$record['id']}"
                       class="act"
                       onClick="var doit=confirm('Are you sure you want to delete this vlan?');
                                if (doit == true)
                                    xajax_window_submit('edit_vlan', xajax.getFormValues('form_vlan_{$record['id']}'), 'delete');"
                    ><img src="{$images}/silk/delete.png" border="0"></a>&nbsp;
                    {$record['name']}</a>
EOL;
    } else {
        $html .= "                    &nbsp;{$record['name']}";
    }
    $html .= <<<EOL
                </td></tr>

                <tr>
                    <td align="right" nowrap="true"><b>Vlan Campus</b>&nbsp;</td>
                    <td class="padding" align="left">
                        <a title="View Vlan Campus"
                           class="nav"
                           onClick="xajax_window_submit('work_space', 'xajax_window_submit(\\'display_vlan_campus\\', \\'vlan_campus_id=>{$record['vlan_campus_id']}\\', \\'display\\')');"
                        >{$record['vlan_campus_name']}</a>
                    </td>
                </tr>

                <tr>
                    <td align="right" nowrap="true"><b>Vlan Name</b>&nbsp;</td>
                    <td class="padding" align="left">{$record['name']}&nbsp;</td>
                </tr>

                <tr>
                    <td align="right" nowrap="true"><b>Vlan Number</b>&nbsp;</td>
                    <td class="padding" align="left">{$record['number']}&nbsp;</td>
                </tr>

            </table>
      </div>
EOL;
    // END VLAN INFORMATION
    // extra stuff to pass to ws_plugins
    $extravars['refresh'] = $refresh;
    $extravars['window_name'] = $window_name;
    $wspl = workspace_plugin_loader('custom_attributes', $record, $extravars);
    $html .= $wspl[0];
    $js .= $wspl[1];
    $html .= "</div>";
    $html .= <<<EOL
    </div>
    <br style="clear:both;">
    <!-- END OF TOP SECTION -->
EOL;
    // SUBNET LIST
    $tab = 'subnets';
    $submit_window = "list_{$tab}";
    $form_id = "{$submit_window}_filter_form";
    $_SESSION['ona'][$form_id]['tab'] = $tab;
    $content_id = "{$window_name}_{$submit_window}";
    $html .= <<<EOL
    <!-- SUBNET LIST -->
    <div style="border: 1px solid {$color['border']}; margin: 10px 20px;">

        <!-- Tab & Quick Filter -->
        <table id="{$form_id}_table" cellspacing="0" border="0" cellpadding="0">
            <tr>
                <td id="{$form_id}_{$tab}_tab" class="table-tab-active">
                    Associated {$tab} <span id="{$form_id}_{$tab}_count"></span>
                </td>

                <td id="{$form_id}_quick_filter" class="padding" align="right" width="100%">
                    <form id="{$form_id}" onSubmit="return false;">
                    <input id="{$form_id}_page" name="page" value="1" type="hidden">
                    <input name="content_id" value="{$content_id}" type="hidden">
                    <input name="form_id" value="{$form_id}" type="hidden">
                    <input name="vlan_id" value="{$record['id']}" type="hidden">
                    <div id="{$form_id}_filter_overlay"
                         title="Filter"
                         style="position: relative;
                                display: inline;
                                color: #CACACA;
                                cursor: text;"
                         onClick="this.style.display = 'none'; el('{$form_id}_filter').focus();"
                    >Name</div>
                    <input
                        id="{$form_id}_filter"
                        name="filter"
                        class="filter"
                        type="text"
                        value=""
                        size="10"
                        maxlength="20"
                        alt="Quick Filter"
                        onFocus="el('{$form_id}_filter_overlay').style.display = 'none';"
                        onBlur="if (this.value == '') el('{$form_id}_filter_overlay').style.display = 'inline';"
                        onKeyUp="
                            if (typeof(timer) != 'undefined') clearTimeout(timer);
                            code = 'if ({$form_id}_last_search != el(\\'{$form_id}_filter\\').value) {' +
                                   '    {$form_id}_last_search = el(\\'{$form_id}_filter\\').value;' +
                                   '    document.getElementById(\\'{$form_id}_page\\').value = 1;' +
                                   '    xajax_window_submit(\\'{$submit_window}\\', xajax.getFormValues(\\'{$form_id}\\'), \\'display_list\\');' +
                                   '}';
                            timer = setTimeout(code, 700);"
                    >
                    </form>
                </td>

            </tr>
        </table>

        <div id='{$content_id}'>
            {$conf['loading_icon']}
        </div>

    </div>

EOL;
    $js .= <<<EOL
        /* Setup the quick filter */
        el('{$form_id}_filter_overlay').style.left = (el('{$form_id}_filter_overlay').offsetWidth + 10) + 'px';
        {$form_id}_last_search = '';

        /* Tell the browser to load/display the list */
        xajax_window_submit('{$submit_window}', xajax.getFormValues('{$form_id}'), 'display_list');
EOL;
    // Insert the new html into the window
    // Instantiate the xajaxResponse object
    $response = new xajaxResponse();
    $response->addAssign("work_space_content", "innerHTML", $html);
    if ($js) {
        $response->addScript($js);
    }
    return $response->getXML();
}
Example #9
0
function ws_editor($window_name, $form = '')
{
    global $conf, $self, $onadb;
    global $font_family, $color, $style, $images;
    $window = array();
    // Check permissions
    if (!auth('vlan_add')) {
        $response = new xajaxResponse();
        $response->addScript("alert('Permission denied!');");
        return $response->getXML();
    }
    // If the user supplied an array in a string, build the array and store it in $form
    $form = parse_options_string($form);
    // Load an existing vlan if $form is a
    if (is_array($form)) {
        list($status, $rows, $record) = ona_get_vlan_record(array('id' => $form['vlan_id']));
        if ($rows) {
            list($status, $rows, $vlan_campus) = ona_get_vlan_campus_record(array('id' => $record['vlan_campus_id']));
            $record['vlan_campus_id'] = $vlan_campus['id'];
            $record['vlan_campus_name'] = $vlan_campus['name'];
        } else {
            $record['vlan_campus_name'] = $form['vlan_campus_name'];
        }
    }
    // Escape data for display in html
    foreach (array_keys((array) $record) as $key) {
        $record[$key] = htmlentities($record[$key], ENT_QUOTES, $conf['php_charset']);
    }
    // Set the window title:
    $window['title'] = "Add VLAN";
    if ($record['id']) {
        $window['title'] = "Edit VLAN";
    }
    // 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('vlan_edit',     'suggest_vlan_edit');
        el('{$window_name}_edit_form').onsubmit = function() { return false; };

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

    <!-- Vlan Edit Form -->
    <form id="{$window_name}_edit_form" onSubmit="return false;">
    <input type="hidden" name="vlan_id" value="{$record['id']}">
    <input type="hidden" name="vlan_campus_name" value="{$form['vlan_campus_name']}">
    <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;">

        <!-- VLAN CAMPUS RECORD -->
        <tr>
            <td align="left" nowrap="true"><b><u>Vlan Record</u></b>&nbsp;</td>
            <td class="padding" align="left" width="100%">&nbsp;</td>
        </tr>


        <tr>
            <td class="input_required" align="right" nowrap="true">
                Vlan Campus
            </td>
            <td class="padding" align="left" width="100%">
                <input
                    id="vlan_edit"
                    name="campus"
                    alt="Vlan Campus"
                    value="{$record['vlan_campus_name']}"
                    class="edit"
                    type="text"
                    size="27" maxlength="255"
                >
                <div id="suggest_vlan_edit" class="suggest"></div>
            </td>
        </tr>

        <tr>
            <td class="input_required" align="right" nowrap="true">
                Vlan Name
            </td>
            <td class="padding" align="left" width="100%">
                <input
                    name="name"
                    alt="Vlan Name"
                    value="{$record['name']}"
                    class="edit"
                    type="text"
                    size="27" maxlength="255"
                >
            </td>
        </tr>

        <tr>
            <td class="input_required" align="right" nowrap="true">
                Vlan Number
            </td>
            <td class="padding" align="left" width="100%">
                <input
                    name="number"
                    alt="Vlan Number"
                    value="{$record['number']}"
                    class="edit"
                    type="text"
                    size="6" maxlength="10"
                >
            </td>
        </tr>
EOL;
    if (!$record['id']) {
        $window['html'] .= <<<EOL
        <tr>
            <td align="right" nowrap="true">
                &nbsp;
            </td>
            <td class="padding" align="left" width="100%">
                <input
                    name="keepadding"
                    alt="Keep adding more VLANS"
                    type="checkbox"
                > Keep adding more VLANS
            </td>
        </tr>

        <tr>
            <td colspan="2" class="padding" align="center" width="100%">
            <span id="statusinfo_{$window_name}" style="color: green;" ></span>
            </td>
        </tr>

EOL;
    }
    $window['html'] .= <<<EOL

        <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 #10
0
function ws_display_list($window_name, $form = '')
{
    global $conf, $self, $onadb;
    global $images, $color, $style;
    $html = '';
    $js = '';
    $debug_val = 3;
    // used in the auth() calls to supress logging
    // If the user supplied an array in a string, build the array and store it in $form
    $form = parse_options_string($form);
    // Find the "tab" we're on
    $tab = $_SESSION['ona'][$form['form_id']]['tab'];
    // Build js to refresh this list
    $refresh = "xajax_window_submit('{$window_name}', xajax.getFormValues('{$form['form_id']}'), 'display_list');";
    // If it's not a new query, load the previous query from the session
    // into $form and save the current page and filter in the session.
    // Also find/set the "page" we're viewing
    $page = 1;
    if ($form['page'] and is_numeric($form['page'])) {
        $form = array_merge($form, (array) $_SESSION['ona'][$form['form_id']][$tab]['q']);
        $_SESSION['ona'][$form['form_id']][$tab]['page'] = $page = $form['page'];
        $_SESSION['ona'][$form['form_id']][$tab]['filter'] = $form['filter'];
    }
    // Calculate the SQL query offset (based on the page being displayed)
    $offset = $conf['search_results_per_page'] * ($page - 1);
    if ($offset == 0) {
        $offset = -1;
    }
    // Search results go in here
    $results = array();
    $count = 0;
    // Start building the "where" clause for the sql query to find the vlans to display
    $where = "";
    $and = "";
    // DISPLAY ALL VLANS
    if ($form['all_flag']) {
        $where .= $and . "id > 0";
        $and = " AND ";
    }
    // VLAN CAMPUS ID
    if ($form['vlan_campus_id']) {
        $where .= $and . "vlan_campus_id = " . $onadb->qstr($form['vlan_campus_id']);
        $and = " AND ";
    }
    // Do the SQL Query
    $filter = '';
    if ($form['filter']) {
        // do a toupper on the filter text
        $filter = $and . ' name LIKE ' . $onadb->qstr('%' . strtoupper($form['filter']) . '%');
    }
    list($status, $rows, $results) = db_get_records($onadb, 'vlans', $where . $filter, "number ASC", $conf['search_results_per_page'], $offset);
    // If we got less than search_results_per_page, add the current offset to it
    // so that if we're on the last page $rows still has the right number in it.
    if ($rows > 0 and $rows < $conf['search_results_per_page']) {
        $rows += $conf['search_results_per_page'] * ($page - 1);
    } else {
        if ($rows >= $conf['search_results_per_page']) {
            list($status, $rows, $records) = db_get_records($onadb, 'vlans', $where . $filter, "", 0);
        }
    }
    $count = $rows;
    $html .= <<<EOL
        <!-- Vlan List -->
        <table id="{$form['form_id']}_vlan_list" class="list-box" cellspacing="0" border="0" cellpadding="0">

            <!-- Table Header -->
            <tr>
                <td class="list-header" align="center" style="{$style['borderR']};">Vlan Name</td>
                <td class="list-header" align="center" style="{$style['borderR']};">Vlan Number</td>
                <td class="list-header" align="center" style="{$style['borderR']};">Subnets In Vlan</td>
                <td class="list-header" align="center">&nbsp;</td>
            </tr>
EOL;
    // Loop and display each record
    foreach ($results as $record) {
        // Grab some info from the associated vlan record
        list($status, $rows, $vlan) = ona_get_vlan_record(array('id' => $record['id']));
        $record['name'] = $vlan['name'];
        $record['vlan_number'] = $vlan['number'];
        // Count how many vlans are on this vlan
        list($status, $rows, $network) = db_get_records($onadb, 'subnets', array('vlan_id' => $record['id']), '', 0);
        $record['network_count'] = $rows;
        // Escape data for display in html
        foreach (array_keys($record) as $key) {
            $record[$key] = htmlentities($record[$key], ENT_QUOTES, $conf['php_charset']);
        }
        $html .= <<<EOL
            <tr onMouseOver="this.className='row-highlight'" onMouseOut="this.className='row-normal'">

                <td class="list-row" align="left">
                    <a title="View vlan. ID: {$record['id']}"
                       class="nav"
                       onClick="xajax_window_submit('work_space', 'xajax_window_submit(\\'display_vlan\\', \\'vlan_id=>{$record['id']}\\', \\'display\\')');"
                    >{$record['name']}</a>
                </td>

                <td class="list-row" align="center">
                    {$record['vlan_number']}&nbsp;
                </td>

                <td class="list-row" align="center">
                    {$record['network_count']}&nbsp;
                </td>

                <td class="list-row" align="right">
                    <form id="{$form['form_id']}_list_vlan_{$record['id']}"
                        ><input type="hidden" name="vlan_id" value="{$record['id']}"
                        ><input type="hidden" name="js" value="{$refresh}"
                    ></form>
EOL;
        if (auth('advanced', $debug_val)) {
            $html .= <<<EOL

                    <a title="Edit vlan. ID: {$record['id']}"
                       class="act"
                       onClick="xajax_window_submit('edit_vlan', xajax.getFormValues('{$form['form_id']}_list_vlan_{$record['id']}'), 'editor');"
                    ><img src="{$images}/silk/page_edit.png" border="0"></a>&nbsp;

                    <a title="Delete vlan"
                       class="act"
                       onClick="var doit=confirm('Are you sure you want to delete this vlan?');
                                if (doit == true)
                                    xajax_window_submit('edit_vlan', xajax.getFormValues('{$form['form_id']}_list_vlan_{$record['id']}'), 'delete');"
                    ><img src="{$images}/silk/delete.png" border="0"></a>
EOL;
        }
        $html .= <<<EOL
                    &nbsp;
                </td>

            </tr>

EOL;
    }
    $html .= <<<EOL
    </table>
EOL;
    // Build page links if there are any
    $html .= get_page_links($page, $conf['search_results_per_page'], $count, $window_name, $form['form_id']);
    // Insert the new html into the content div specified
    // Instantiate the xajaxResponse object
    $response = new xajaxResponse();
    $response->addAssign("{$form['form_id']}_{$tab}_count", "innerHTML", "({$count})");
    $response->addAssign($form['content_id'], "innerHTML", $html);
    if ($js) {
        $response->addScript($js);
    }
    return $response->getXML();
}