Exemplo n.º 1
0
function ona_find_config($options = array())
{
    global $self;
    $status = 1;
    $rows = 0;
    $config = array();
    // If the user specified a config text ID
    if ($options['config']) {
        if (!preg_match('/^\\d+$/', $options['config'])) {
            $self['error'] = "ERROR => A non-digit config ID was specified!";
            return array(2, 0, array());
        }
        list($status, $rows, $config) = ona_get_config_record(array('id' => $options['config']));
    } else {
        if ($options['host'] and $options['type']) {
            // Search for the host first
            list($status, $rows, $host) = ona_find_host($options['host']);
            // Error if the host doesn't exist
            if (!$host['id']) {
                $self['error'] = "ERROR => The host specified, {$options['host']}, does not exist!";
                return array(3, 0, array());
            }
            // Now find the ID of the config type they entered
            list($status, $rows, $config_type) = ona_get_config_type_record(array('name' => $options['type']));
            if (!$config_type['id']) {
                $self['error'] = "ERROR => The config type specified, {$options['type']}, is invalid!";
                return array(4, 0, array());
            }
            // Select the first config record of the specified type and host
            list($status, $rows, $config) = ona_get_config_record(array('host_id' => $host['id'], 'configuration_type_id' => $config_type['id']));
            if ($status) {
                $self['error'] = "ERROR => The config type specified, {$options['type']}, is invalid!";
                return array(5, 0, array());
            }
        }
    }
    // Return the config record we got
    return array($status, $rows, $config);
}
Exemplo n.º 2
0
function config_add($options = "")
{
    // The important globals
    global $conf;
    global $self;
    global $onadb;
    // Version - UPDATE on every edit!
    $version = '1.00';
    // This debug is set very high as it can contain large configs and sensitive data, you gotta mean it!
    printmsg('DEBUG => config_add(' . $options . ') called', 7);
    // Parse incoming options string to an array
    $options = parse_options($options);
    // Return the usage summary if we need to
    if ($options['help'] or !($options['host'] and $options['type'] and $options['config'])) {
        // NOTE: Help message lines should not exceed 80 characters for proper display on a console
        return array(1, <<<EOM

config_add-v{$version}
Adds a new config text record into the database

  Synopsis: config_add [KEY=VALUE] ...

  Required:
    config=TEXT                 the actual config text or filename to insert
    host=ID or NAME[.DOMAIN]    host the config text is from
    type=TYPE                   type of config text we're inserting -
                                  usually "IOS_VERSION" or "IOS_CONFIG"


EOM
);
    }
    // Search for the host first
    list($status, $rows, $host) = ona_find_host($options['host']);
    // Error if the host doesn't exist
    if (!$host['id']) {
        $self['error'] = "ERROR => The host specified, {$options['host']}, does not exist!";
        return array(2, $self['error']);
    }
    // Now find the ID of the config type they entered
    list($status, $rows, $config_type) = ona_get_config_type_record(array('name' => $options['type']));
    if (!$config_type['id']) {
        $self['error'] = "ERROR => The config type specified, {$options['type']}, is invalid!";
        return array(3, $self['error']);
    }
    $options['config'] = preg_replace('/\\\\"/', '"', $options['config']);
    $options['config'] = preg_replace('/\\\\=/', '=', $options['config']);
    // Get the next ID for the new config_text record
    $id = ona_get_next_id('configurations');
    if (!$id) {
        return array(4, "ERROR => The ona_get_next_id(configurations) call failed!\n");
    }
    printmsg("DEBUG => ID for new config_record: {$id}", 3);
    // Add the config_text
    list($status, $rows) = db_insert_record($onadb, 'configurations', array('id' => $id, 'configuration_type_id' => $config_type['id'], 'host_id' => $host['id'], 'md5_checksum' => md5($options['config']), 'config_body' => $options['config']));
    if ($status or !$rows) {
        $self['error'] = "ERROR => message_add() SQL Query failed: " . $self['error'];
        printmsg($self['error'], 0);
        return array(6, $self['error'] . "\n");
    }
    list($status, $rows, $record) = ona_get_config_record(array('id' => $id));
    if ($status or !$rows) {
        $self['error'] = 'ERROR => SQL INSERT failed.  Database error: ' . $error . "\n";
        return array(5, $self['error']);
    }
    // Return the success notice
    $text = "NOTICE => Config text record ADDED, ID: {$id}\n";
    return array(0, $text);
}
Exemplo n.º 3
0
// <html><body>
// Redirecting you to: <a href="{$https}{$baseURL}/login.php">{$https}{$baseURL}/login.php</a>
// <script type="text/javascript"><!--
//     setTimeout("window.location = \"{$https}{$baseURL}/login.php\";", 1000);
// --></script>
// </body></html>
// EOL;
//     exit;
// }
// This code is to provide a proper file attachment download for configuration archives
// If they have a session go for it
if ($_SESSION['ona']['auth']['user']['username']) {
    if (auth('host_config_admin', $debug_val)) {
        if ($_REQUEST['config_id'] and $_REQUEST['download']) {
            // Generate a SQL query to get the config to display
            list($status, $rows, $config) = ona_get_config_record(array('id' => $_REQUEST['config_id']));
            if (!$config['id']) {
                print "<html><body>Configuration record doesn't exist!</body></html>";
            }
            list($status, $rows, $host) = ona_get_host_record(array('id' => $config['host_id']));
            // Print the config file and exit
            $size = strlen($config['config_body']);
            header("Content-Disposition: attachment; filename=\"{$host['fqdn']}-{$config['config_type_name']}.txt\"; size=\"{$size}\"");
            print $config['config_body'];
            exit;
        }
    } else {
        print "<html><body>ERROR: You are unauthorized for this page!</body></html>";
    }
} else {
    print "<html><body>ERROR: You are unauthorized for this page!</body></html>";
Exemplo n.º 4
0
function ws_delete_config($window_name, $form = '')
{
    global $conf, $self, $onadb;
    global $images, $color, $style;
    // If the user supplied an array in a string, build the array and store it in $form
    $form = parse_options_string($form);
    // Load the config text record
    list($status, $rows, $config) = ona_get_config_record(array('id' => $form['config_id']));
    if (!$config['id']) {
        array_pop($_SESSION['ona']['work_space']['history']);
        $html .= "<br><center><font color=\"red\"><b>Configuration text record doesn't exist!</b></font></center>";
        $response = new xajaxResponse();
        $response->addAssign("work_space_content", "innerHTML", $html);
        return $response->getXML();
    }
    // Load the asscoiated host record
    list($status, $rows, $host) = ona_find_host($config['host_id']);
    if (!$host['id']) {
        array_pop($_SESSION['ona']['work_space']['history']);
        $html .= "<br><center><font color=\"red\"><b>Host doesn't exist!</b></font></center>";
        $response = new xajaxResponse();
        $response->addAssign("work_space_content", "innerHTML", $html);
        return $response->getXML();
    }
    // Check permissions
    if (!(auth('host_config_admin') and authlvl($host['lvl']))) {
        $response = new xajaxResponse();
        $response->addScript("alert('Permission denied!');");
        return $response->getXML();
    }
    // Delete the config text
    // FIXME, this should probably use a module, but there isn't one!
    list($status, $rows) = db_delete_records($onadb, 'configurations', array('id' => $config['id']));
    if ($status or !$rows) {
        $response = new xajaxResponse();
        $response->addScript("alert('Delete failed!');");
        return $response->getXML();
    }
    // Insert the new html into the window
    // Instantiate the xajaxResponse object
    $response = new xajaxResponse();
    if ($form['js']) {
        $response->addScript($form['js']);
    }
    return $response->getXML();
}
Exemplo n.º 5
0
// CONFIG ARCHIVE LIST
// List config archives if they have permission to see them
if (auth('host_config_admin', $debug_val)) {
    list($status, $total_configs, $tmp) = db_get_records($onadb, 'configurations', array('host_id' => $record['id']), '', 0);
    $title_left_html = "Config Archives{$extravars['host_name']} &#040;{$total_configs}&#041";
    if ($total_configs) {
        // Ok, basically we're going to get a list of each config type, and see how many of each type this host has
        $row_html = '';
        list($status, $rows, $types) = db_get_records($onadb, 'configuration_types', 'id > 0', 'name');
        foreach ($types as $type) {
            // See how many of this type the host has
            list($status, $rows, $tmp) = db_get_records($onadb, 'configurations', array('host_id' => $record['id'], 'configuration_type_id' => $type['id']), '', 0);
            if ($rows) {
                // Select the first config record of the specified type and host
                list($status, $rows, $config) = ona_get_config_record(array('host_id' => $record['id'], 'configuration_type_id' => $type['id']));
                // Escape data for display in html
                foreach (array_keys($type) as $key) {
                    $type[$key] = htmlentities($type[$key], ENT_QUOTES);
                }
                $row_html .= <<<EOL
        <tr title="View {$type['name']} archives"
            style="cursor: pointer;"
            onMouseOver="this.className='row-highlight';"
            onMouseOut="this.className='row-normal';"
            onClick="xajax_window_submit('work_space', 'xajax_window_submit(\\'display_config_text\\', \\'host_id=>{$record['id']},type_id=>{$type['id']},displayconf=>{$config['id']}\\', \\'display\\')');"
        >
            <td align="left">{$type['name']} ({$rows})</td>
            <td align="right"><img src="{$images}/silk/zoom.png" border="0">&nbsp;</td>
        </tr>
EOL;