function collect_pppoe_users_api(&$host)
{
    $rows = array();
    $api = new RouterosAPI();
    $api->debug = false;
    $rekey_array = array('host_id', 'name', 'index', 'userType', 'serverID', 'domain', 'bytesIn', 'bytesOut', 'packetsIn', 'packetsOut', 'curBytesIn', 'curBytesOut', 'curPacketsIn', 'curPacketsOut', 'prevBytesIn', 'prevBytesOut', 'prevPacketsIn', 'prevPacketsOut', 'present', 'last_seen');
    // Put the queues into an array
    $users = array_rekey(db_fetch_assoc_prepared("SELECT \n\t\thost_id, '0' AS `index`, '1' AS userType, '0' AS serverID, SUBSTRING(name, 7) AS name, '' AS domain,\n\t\tBytesIn AS bytesIn, BytesOut AS bytesOut, PacketsIn as packetsIn, PacketsOut AS packetsOut,\n\t\tcurBytesIn, curBytesOut, curPacketsIn, curPacketsOut, \n\t\tprevBytesIn, prevBytesOut, prevPacketsIn, prevPacketsOut, present, last_seen\n\t\tFROM plugin_mikrotik_queues \n\t\tWHERE host_id = ? \n\t\tAND name LIKE 'PPPOE-%'", array($host['id'])), 'name', $rekey_array);
    $creds = db_fetch_row_prepared('SELECT * FROM plugin_mikrotik_credentials WHERE host_id = ?', array($host['id']));
    $start = microtime(true);
    if (sizeof($creds)) {
        if ($api->connect($host['hostname'], $creds['user'], $creds['password'])) {
            $api->write('/ppp/active/getall');
            $read = $api->read(false);
            $array = $api->parseResponse($read);
            $end = microtime(true);
            $sql = array();
            cacti_log('MIKROTIK RouterOS API STATS: API Returned ' . sizeof($array) . ' PPPoe Users in ' . round($end - $start, 2) . ' seconds.', false, 'SYSTEM');
            if (sizeof($array)) {
                foreach ($array as $row) {
                    if (!isset($row['name'])) {
                        continue;
                    }
                    $name = strtoupper($row['name']);
                    if (isset($users[$name])) {
                        $user = $users[$name];
                        $user['mac'] = $row['caller-id'];
                        $user['ip'] = $row['address'];
                        $user['connectTime'] = uptimeToSeconds($row['uptime']);
                        $user['host_id'] = $host['id'];
                        $user['radius'] = $row['radius'] == 'true' ? 1 : 0;
                        $user['limitBytesIn'] = $row['limit-bytes-in'];
                        $user['limitBytesOut'] = $row['limit-bytes-out'];
                        $user['userType'] = 1;
                        $sql[] = '(' . $user['host_id'] . ',' . $user['index'] . ',' . $user['userType'] . ',' . $user['serverID'] . ',' . db_qstr($user['name']) . ',' . db_qstr($user['domain']) . ',' . db_qstr($user['mac']) . ',' . db_qstr($user['ip']) . ',' . $user['connectTime'] . ',' . $user['bytesIn'] . ',' . $user['bytesOut'] . ',' . $user['packetsIn'] . ',' . $user['packetsOut'] . ',' . $user['curBytesIn'] . ',' . $user['curBytesOut'] . ',' . $user['curPacketsIn'] . ',' . $user['curPacketsOut'] . ',' . $user['prevBytesIn'] . ',' . $user['prevBytesOut'] . ',' . $user['prevPacketsIn'] . ',' . $user['prevPacketsOut'] . ',' . $user['limitBytesIn'] . ',' . $user['limitBytesOut'] . ',' . $user['radius'] . ',' . $user['present'] . ',' . db_qstr($user['last_seen']) . ')';
                    }
                }
                if (sizeof($sql)) {
                    db_execute('INSERT INTO plugin_mikrotik_users 
						(host_id, `index`, userType, serverID, name, domain, mac, ip, connectTime, 
						bytesIn, bytesOut, packetsIn, packetsOut, 
						curBytesIn, curBytesOut, curPacketsIn, curPacketsOut, 
						prevBytesIn, prevBytesOut, prevPacketsIn, prevPacketsOut, 
						limitBytesIn, limitBytesOut, radius, present, last_seen) 
						VALUES ' . implode(', ', $sql) . '
						ON DUPLICATE KEY UPDATE connectTime=VALUES(connectTime), 
						bytesIn=VALUES(bytesIn), bytesOut=VALUES(bytesOut), 
						packetsIn=VALUES(packetsIn), packetsOut=VALUES(packetsOut), 
						curBytesIn=VALUES(curBytesIn), curBytesOut=VALUES(curBytesOut),
						curPacketsIn=VALUES(curPacketsIn), curPacketsOut=VALUES(curPacketsOut),
						prevBytesIn=VALUES(prevBytesIn), prevBytesOut=VALUES(prevBytesOut),
						prevPacketsIn=VALUES(prevPacketsIn), prevPacketsOut=VALUES(prevPacketsOut),
						limitBytesIn=VALUES(limitBytesIn), limitBytesOut=VALUES(limitBytesOut),
						radius=VALUES(radius), present=VALUES(present), last_seen=VALUES(last_seen)');
                }
            }
            $idle_users = db_fetch_assoc_prepared('SELECT name 
				FROM plugin_mikrotik_users 
				WHERE last_seen < FROM_UNIXTIME(UNIX_TIMESTAMP() - ?) 
				AND present=1 
				AND host_id = ?', array(read_config_option('mikrotik_queues_freq'), $host['id']));
            db_execute_prepared('UPDATE IGNORE plugin_mikrotik_users SET
				bytesIn=0, bytesOut=0, packetsIn=0, packetsOut=0, connectTime=0,
				curBytesIn=0, curBytesOut=0, curPacketsIn=0, curPacketsOut=0,
				prevBytesIn=0, prevBytesOut=0, prevPacketsIn=0, prevPacketsOut=0, present=0
				WHERE host_id = ? 
				AND userType = 1 
				AND last_seen < FROM_UNIXTIME(UNIX_TIMESTAMP() - ?)', array($host['id'], read_config_option('mikrotik_queues_freq')));
            $api->disconnect();
        } else {
            cacti_log('ERROR:RouterOS @ ' . $host['description'] . ' Timed Out');
        }
    }
}
Exemple #2
0
function color_remove()
{
    /* ================= input validation ================= */
    input_validate_input_number(get_request_var_request('id'));
    /* ==================================================== */
    db_execute_prepared('DELETE FROM colors WHERE id = ?', array(get_request_var_request('id')));
}
Exemple #3
0
function form_save()
{
    global $settings_graphs;
    while (list($tab_short_name, $tab_fields) = each($settings_graphs)) {
        while (list($field_name, $field_array) = each($tab_fields)) {
            /* Check every field with a numeric default value and reset it to default if the inputted value is not numeric  */
            if (isset($field_array['default']) && is_numeric($field_array['default']) && !is_numeric(get_request_var_post($field_name))) {
                $_POST[$field_name] = $field_array['default'];
            }
            if ($field_array['method'] == 'checkbox') {
                if (isset($_POST[$field_name])) {
                    db_execute_prepared("REPLACE INTO settings_graphs (user_id,name,value) VALUES (?, ?, 'on')", array($_SESSION['sess_user_id'], $field_name));
                } else {
                    db_execute_prepared("REPLACE INTO settings_graphs (user_id,name,value) VALUES (?, ?, '')", array($_SESSION['sess_user_id'], $field_name));
                }
            } elseif ($field_array['method'] == 'checkbox_group') {
                while (list($sub_field_name, $sub_field_array) = each($field_array['items'])) {
                    if (isset($_POST[$sub_field_name])) {
                        db_execute_prepared("REPLACE INTO settings_graphs (user_id,name,value) VALUES (?, ?, 'on')", array($_SESSION['sess_user_id'], $sub_field_name));
                    } else {
                        db_execute_prepared("REPLACE INTO settings_graphs (user_id,name,value) VALUES (?, ?, '')", array($_SESSION['sess_user_id'], $sub_field_name));
                    }
                }
            } elseif ($field_array['method'] == 'textbox_password') {
                if ($_POST[$field_name] != $_POST[$field_name . '_confirm']) {
                    raise_message(4);
                    break;
                } elseif (isset($_POST[$field_name])) {
                    db_execute_prepared('REPLACE INTO settings_graphs (user_id, name, value) VALUES (?, ?, ?)', array($_SESSION['sess_user_id'], $field_name, get_request_var_post($field_name)));
                }
            } elseif (isset($field_array['items']) && is_array($field_array['items'])) {
                while (list($sub_field_name, $sub_field_array) = each($field_array['items'])) {
                    if (isset($_POST[$sub_field_name])) {
                        db_execute_prepared('REPLACE INTO settings_graphs (user_id, name, value) values (?, ?, ?)', array($_SESSION['sess_user_id'], $sub_field_name, get_request_var_post($sub_field_name)));
                    }
                }
            } else {
                if (isset($_POST[$field_name])) {
                    db_execute_prepared('REPLACE INTO settings_graphs (user_id, name, value) values (?, ?, ?)', array($_SESSION['sess_user_id'], $field_name, get_request_var_post($field_name)));
                }
            }
        }
    }
    raise_message(1);
    /* reset local settings cache so the user sees the new settings */
    kill_session_var('sess_graph_config_array');
}
Exemple #4
0
function form_save()
{
    if (isset($_POST['save_component_rra'])) {
        $save['id'] = $_POST['id'];
        $save['hash'] = get_hash_round_robin_archive($_POST['id']);
        $save['name'] = form_input_validate($_POST['name'], 'name', '', false, 3);
        $dummy = form_input_validate(count($_POST['consolidation_function_id']), 'consolidation_function_id', '^[0-9]*$', false, 3);
        $save['x_files_factor'] = form_input_validate($_POST['x_files_factor'], 'x_files_factor', "^[01]?(\\.[0-9]+)?\$", false, 3);
        $save['steps'] = form_input_validate($_POST['steps'], 'steps', '^[0-9]*$', false, 3);
        $save['rows'] = form_input_validate($_POST['rows'], 'rows', '^[0-9]*$', false, 3);
        $save['timespan'] = form_input_validate($_POST['timespan'], 'timespan', '^[0-9]*$', false, 3);
        if (!is_error_message()) {
            $rra_id = sql_save($save, 'rra');
            if ($rra_id) {
                raise_message(1);
                db_execute_prepared('DELETE FROM rra_cf WHERE rra_id = ?', array($rra_id));
                if (isset($_POST['consolidation_function_id'])) {
                    for ($i = 0; $i < count($_POST['consolidation_function_id']); $i++) {
                        /* ================= input validation ================= */
                        input_validate_input_number($_POST['consolidation_function_id'][$i]);
                        /* ==================================================== */
                        db_execute_prepared('INSERT INTO rra_cf (rra_id, consolidation_function_id) VALUES (?, ?)', array($rra_id, $_POST['consolidation_function_id'][$i]));
                    }
                } else {
                    raise_message(2);
                }
            } else {
                raise_message(2);
            }
        }
        if (is_error_message()) {
            header('Location: rra.php?action=edit&id=' . (empty($rra_id) ? $_POST['id'] : $rra_id));
        } else {
            header('Location: rra.php');
        }
        exit;
    }
}
Exemple #5
0
 public function install($path, $replace = false, $mib_name = 'optional')
 {
     global $config;
     include_once $config['library_path'] . '/mib_parser.php';
     $mp = new MibParser();
     $mp->add_mib($path, $mib_name);
     $mp->generate();
     if (isset($mp->mib) && isset($mp->oids) && $mp->mib) {
         /* check if this mib has already been installed */
         $existing = db_fetch_cell("SELECT 1 FROM snmpagent_mibs WHERE `name` = '" . $mp->mib . "'");
         if ($existing) {
             if ($replace == false) {
                 unset($mp->oids);
                 unset($mp->mib);
                 return false;
             } else {
                 $this->uninstall();
             }
         }
         db_execute("INSERT INTO snmpagent_mibs SET `id` = 0, `name` = '" . $mp->mib . "', `file` = '" . $path . "'");
         foreach ($mp->oids as $object_name => $object_params) {
             if ($object_params["otype"] != "TEXTUAL-CONVENTION") {
                 db_execute_prepared("INSERT INTO `snmpagent_cache` (`oid`, `name`, `mib`, `type`, `otype`, `kind`, `max-access`, `description`) VALUES ('" . $object_params["oid"] . "','" . $object_name . "','" . $object_params["mib"] . "','" . $object_params["syntax"] . "','" . $object_params["otype"] . "','" . $object_params["kind"] . "','" . $object_params["max-access"] . "','" . nl2br($object_params["description"]) . "')");
                 if ($object_params["otype"] == "NOTIFICATION-TYPE") {
                     foreach ($object_params["objects"] as $notication_object_index => $notication_object) {
                         db_execute("INSERT INTO `snmpagent_cache_notifications` (`name`, `mib`, `attribute`, `sequence_id`) VALUES ('" . $object_name . "','" . $object_params["mib"] . "','" . $notication_object . "','" . $notication_object_index . "')");
                     }
                 }
             } else {
                 db_execute_prepared("INSERT INTO `snmpagent_cache_textual_conventions` (`name`, `mib`, `type`, `description`) VALUES ('" . $object_name . "','" . $object_params["mib"] . "','" . $object_params["syntax"] . "','" . nl2br($object_params["description"]) . "')");
             }
         }
         unset($mp->oids);
         unset($mp->mib);
     } else {
         return false;
     }
 }
Exemple #6
0
function template_rrd_add()
{
    /* ================= input validation ================= */
    input_validate_input_number(get_request_var_request('id'));
    input_validate_input_number(get_request_var_request('local_data_id'));
    /* ==================================================== */
    $hash = get_hash_data_template(0, 'data_template_item');
    db_execute_prepared("INSERT INTO data_template_rrd (hash, data_template_id, rrd_maximum, rrd_minimum, rrd_heartbeat, data_source_type_id, data_source_name) \n\t\t    VALUES (?, ?, 0, 0, 600, 1, 'ds')", array($hash, $_REQUEST['id']));
    $data_template_rrd_id = db_fetch_insert_id();
    /* add this data template item to each data source using this data template */
    $children = db_fetch_assoc_prepared('SELECT local_data_id FROM data_template_data WHERE data_template_id = ? AND local_data_id > 0', array($_REQUEST['id']));
    if (sizeof($children) > 0) {
        foreach ($children as $item) {
            db_execute_prepared("INSERT INTO data_template_rrd (local_data_template_rrd_id, local_data_id, data_template_id, rrd_maximum, rrd_minimum, rrd_heartbeat, data_source_type_id, data_source_name) \n\t\t\t\t     VALUES (?, ?, ?, 0, 0, 600, 1, 'ds')", array($data_template_rrd_id, $item['local_data_id'], $_REQUEST['id']));
        }
    }
    header('Location: data_templates.php?action=template_edit&id=' . $_REQUEST['id'] . "&view_rrd={$data_template_rrd_id}");
}
Exemple #7
0
function secpass_login_process()
{
    $users = db_fetch_assoc('SELECT username FROM user_auth WHERE realm = 0');
    $username = sanitize_search_string(get_request_var_post('login_username'));
    # Mark failed login attempts
    if (read_config_option('secpass_lockfailed') > 0) {
        $max = intval(read_config_option('secpass_lockfailed'));
        if ($max > 0) {
            $p = get_request_var_post('login_password');
            foreach ($users as $fa) {
                if ($fa['username'] == $username) {
                    $user = db_fetch_assoc_prepared("SELECT * FROM user_auth WHERE username = ? AND realm = 0 AND enabled = 'on'", array($username));
                    if (isset($user[0]['username'])) {
                        $user = $user[0];
                        $unlock = intval(read_config_option('secpass_unlocktime'));
                        if ($unlock > 1440) {
                            $unlock = 1440;
                        }
                        if ($unlock > 0 && time() - $user['lastfail'] > 60 * $unlock) {
                            db_execute_prepared("UPDATE user_auth SET lastfail = 0, failed_attempts = 0, locked = '' WHERE username = ? AND realm = 0 AND enabled = 'on'", array($username));
                            $user['failed_attempts'] = $user['lastfail'] = 0;
                            $user['locked'] == '';
                        }
                        if ($user['password'] != md5($p)) {
                            $failed = $user['failed_attempts'] + 1;
                            if ($failed >= $max) {
                                db_execute_prepared("UPDATE user_auth SET locked = 'on' WHERE username = ? AND realm = 0 AND enabled = 'on'", array($username));
                                $user['locked'] = 'on';
                            }
                            $user['lastfail'] = time();
                            db_execute_prepared("UPDATE user_auth SET lastfail = ?, failed_attempts = ? WHERE username = ? AND realm = 0 AND enabled = 'on'", array($user['lastfail'], $failed, $username));
                            if ($user['locked'] != '') {
                                auth_display_custom_error_message('This account has been locked.');
                                exit;
                            }
                            return false;
                        }
                        if ($user['locked'] != '') {
                            auth_display_custom_error_message('This account has been locked.');
                            exit;
                        }
                    }
                }
            }
        }
    }
    # Check if old password doesn't meet specifications and must be changed
    if (read_config_option('secpass_forceold') == 'on') {
        $p = get_request_var_post('login_password');
        $error = secpass_check_pass($p);
        if ($error != '') {
            foreach ($users as $fa) {
                if ($fa['username'] == $username) {
                    db_execute_prepared("UPDATE user_auth SET must_change_password = '******' WHERE username = ? AND password = ? AND realm = 0 AND enabled = 'on'", array($username, md5(get_request_var_post('login_password'))));
                    return true;
                }
            }
        }
    }
    # Set the last Login time
    if (read_config_option('secpass_expireaccount') > 0) {
        $p = get_request_var_post('login_password');
        foreach ($users as $fa) {
            if ($fa['username'] == $username) {
                db_execute_prepared("UPDATE user_auth SET lastlogin = ? WHERE username = ? AND password = ? AND realm = 0 AND enabled = 'on'", array(time(), $username, md5(get_request_var_post('login_password'))));
            }
        }
    }
    return true;
}
Exemple #8
0
function data_query_remove($id)
{
    $snmp_query_graph = db_fetch_assoc_prepared('SELECT id FROM snmp_query_graph WHERE snmp_query_id = ?', array($id));
    if (sizeof($snmp_query_graph) > 0) {
        foreach ($snmp_query_graph as $item) {
            db_execute('DELETE FROM snmp_query_graph_rrd WHERE snmp_query_graph_id=' . $item['id']);
        }
    }
    db_execute_prepared('DELETE FROM snmp_query WHERE id = ?', array($id));
    db_execute_prepared('DELETE FROM snmp_query_graph WHERE snmp_query_id = ?', array($id));
    db_execute_prepared('DELETE FROM host_template_snmp_query WHERE snmp_query_id = ?', array($id));
    db_execute_prepared('DELETE FROM host_snmp_query WHERE snmp_query_id = ?', array($id));
    db_execute_prepared('DELETE FROM host_snmp_cache WHERE snmp_query_id = ?', array($id));
}
Exemple #9
0
function domain_default($domain_id)
{
    db_execute('UPDATE user_domains SET defdomain = 0');
    db_execute_prepared('UPDATE user_domains SET defdomain = 1 WHERE domain_id = ?', array($domain_id));
}
function form_mactrack_actions()
{
    global $config, $device_actions, $fields_mactrack_device_edit, $fields_mactrack_snmp_item;
    /* ================= input validation ================= */
    get_filter_request_var('drp_action');
    /* ==================================================== */
    include_once $config['base_path'] . '/lib/functions.php';
    /* if we are to save this form, instead of display it */
    if (isset_request_var('selected_items')) {
        $selected_items = sanitize_unserialize_selected_items(get_nfilter_request_var('selected_items'));
        if ($selected_items != false) {
            if (get_request_var('drp_action') == '2') {
                /* Enable Selected Devices */
                for ($i = 0; $i < count($selected_items); $i++) {
                    db_execute_prepared("UPDATE mac_track_devices SET disabled='' WHERE device_id = ?", array($selected_items[$i]));
                }
            } elseif (get_request_var('drp_action') == '3') {
                /* Disable Selected Devices */
                for ($i = 0; $i < count($selected_items); $i++) {
                    db_execute_prepared("UPDATE mac_track_devices SET disabled='on' WHERE device_id = ?", array($selected_items[$i]));
                }
            } elseif (get_request_var('drp_action') == '4') {
                /* change snmp options */
                for ($i = 0; $i < count($selected_items); $i++) {
                    reset($fields_mactrack_device_edit);
                    while (list($field_name, $field_array) = each($fields_mactrack_device_edit)) {
                        if (isset_request_var("t_{$field_name}")) {
                            db_execute_prepared("UPDATE mac_track_devices \n\t\t\t\t\t\t\t\tSET {$field_name} = ?\n\t\t\t\t\t\t\t\tWHERE device_id = ?", array(get_request_var($field_name), $selected_items[$i]));
                        }
                    }
                }
            } elseif (get_request_var('drp_action') == '5') {
                /* change port settings for multiple devices */
                for ($i = 0; $i < count($selected_items); $i++) {
                    reset($fields_mactrack_device_edit);
                    while (list($field_name, $field_array) = each($fields_host_edit)) {
                        if (isset_request_var("t_{$field_name}")) {
                            db_execute_prepared("UPDATE mac_track_devices \n\t\t\t\t\t\t\t\tSET {$field_name} = ? WHERE id = ?", array(get_request_var($field_name), $selected_items[$i]));
                        }
                    }
                }
            } elseif (get_request_var('drp_action') == '6') {
                /* Connect Selected Devices */
                for ($i = 0; $i < count($selected_items); $i++) {
                    $cacti_host = db_fetch_row_prepared('SELECT host.id, host.description FROM mac_track_devices 
						LEFT JOIN host ON (mac_track_devices.hostname=host.hostname) 
						WHERE mac_track_devices.device_id=?', array($selected_items[$i]));
                    if (sizeof($cacti_host)) {
                        db_execute_prepared('UPDATE mac_track_devices SET host_id = ?, device_name = ? WHERE device_id = ?', array($cacti_host['id'], $cacti_host['description'], $selected_items[$i]));
                    }
                }
            } elseif (get_request_var('drp_action') == '7') {
                /* Copy SNMP Settings */
                for ($i = 0; $i < count($selected_items); $i++) {
                    $cacti_host = db_fetch_row_prepared("SELECT host.*, \n\t\t\t\t\t\thost.snmp_community as snmp_readstring, \n\t\t\t\t\t\thost.ping_retries as snmp_retries\n\t\t\t\t\t\tFROM mac_track_devices \n\t\t\t\t\t\tLEFT JOIN host ON (mac_track_devices.hostname=host.hostname) \n\t\t\t\t\t\tWHERE mac_track_devices.device_id = ?", array($selected_items[$i]));
                    if (isset($cacti_host['id'])) {
                        reset($fields_mactrack_snmp_item);
                        $updates = '';
                        while (list($field_name, $field_array) = each($fields_mactrack_snmp_item)) {
                            if (isset($cacti_host[$field_name])) {
                                $updates .= ($updates != '' ? ', ' : '') . $field_name . "='" . $cacti_host[$field_name] . "'";
                            }
                        }
                        if (strlen($updates)) {
                            db_execute('UPDATE mac_track_devices SET ' . $updates . ' WHERE device_id=' . $selected_items[$i]);
                        }
                    } else {
                        # skip silently; possible enhacement: tell the user what we did
                    }
                }
            } elseif (get_request_var('drp_action') == '1') {
                /* delete */
                for ($i = 0; $i < count($selected_items); $i++) {
                    api_mactrack_device_remove($selected_items[$i]);
                }
            }
            header('Location: mactrack_devices.php');
            exit;
        }
    }
    /* setup some variables */
    $device_list = '';
    $i = 0;
    /* loop through each of the host templates selected on the previous page and get more info about them */
    while (list($var, $val) = each($_POST)) {
        if (preg_match('/^chk_([0-9]+)$/', $var, $matches)) {
            /* ================= input validation ================= */
            input_validate_input_number($matches[1]);
            /* ==================================================== */
            $device_info = db_fetch_row_prepared('SELECT hostname, device_name FROM mac_track_devices WHERE device_id = ?', array($matches[1]));
            $device_list .= '<li>' . $device_info['device_name'] . ' (' . $device_info['hostname'] . ')</li>';
            $device_array[] = $matches[1];
        }
    }
    top_header();
    form_start('mactrack_devices.php');
    html_start_box($device_actions[get_request_var('drp_action')], '60%', '', '3', 'center', '');
    if (!sizeof($device_array)) {
        print "<tr><td class='even'><span class='textError'>" . __('You must select at least one device.') . "</span></td></tr>\n";
        $save_html = "";
    } else {
        $save_html = "<input type='submit' value='" . __('Yes') . "' name='save'>";
        if (get_request_var('drp_action') == '2') {
            /* Enable Devices */
            print "<tr>\n\t\t\t\t<td colspan='2' class='textArea'>\n\t\t\t\t\t<p>" . __('To enable the following devices, press the "yes" button below.') . "</p>\n\t\t\t\t\t<p><ul>{$device_list}</ul></p>\n\t\t\t\t</td>\n\t\t\t</tr>";
        } elseif (get_request_var('drp_action') == '3') {
            /* Disable Devices */
            print "<tr>\n\t\t\t\t<td colspan='2' class='textArea'>\n\t\t\t\t\t<p>" . __('To disable the following devices, press the "yes" button below.') . "</p>\n\t\t\t\t\t<p><ul>{$device_list}</ul></p>\n\t\t\t\t</td>\n\t\t\t</tr>";
        } elseif (get_request_var('drp_action') == '4') {
            /* change snmp options */
            print "<tr>\n\t\t\t\t<td colspan='2' class='textArea'>\n\t\t\t\t\t<p>" . __('To change SNMP parameters for the following devices, check the box next to the fields you want to update, fill in the new value, and click Save.') . "</p>\n\t\t\t\t\t<p><ul>{$device_list}</ul></p>\n\t\t\t\t</td>\n\t\t\t</tr>";
            $form_array = array();
            while (list($field_name, $field_array) = each($fields_mactrack_device_edit)) {
                if (preg_match('/^snmp_/', $field_name)) {
                    $form_array += array($field_name => $fields_mactrack_device_edit[$field_name]);
                    $form_array[$field_name]['value'] = '';
                    $form_array[$field_name]['device_name'] = '';
                    $form_array[$field_name]['form_id'] = 0;
                    $form_array[$field_name]['sub_checkbox'] = array('name' => 't_' . $field_name, 'friendly_name' => 'Update this Field<br/>', 'value' => '');
                }
            }
            draw_edit_form(array('config' => array('no_form_tag' => true), 'fields' => $form_array));
        } elseif (get_request_var('drp_action') == '5') {
            /* change port settngs for multiple devices */
            print "<tr>\n\t\t\t\t<td colspan='2' class='textArea'>\n\t\t\t\t\t<p>" . __('To change upper or lower port parameters for the following devices, check the box next to the fields you want to update, fill in the new value, and click Save.') . "</p>\n\t\t\t\t\t<p><ul>{$device_list}</ul></p>\n\t\t\t\t</td>\n\t\t\t</tr>";
            $form_array = array();
            while (list($field_name, $field_array) = each($fields_mactrack_device_edit)) {
                if (preg_match('/^port_/', $field_name)) {
                    $form_array += array($field_name => $fields_mactrack_device_edit[$field_name]);
                    $form_array[$field_name]['value'] = '';
                    $form_array[$field_name]['device_name'] = '';
                    $form_array[$field_name]['form_id'] = 0;
                    $form_array[$field_name]['sub_checkbox'] = array('name' => 't_' . $field_name, 'friendly_name' => 'Update this Field', 'value' => '');
                }
            }
            draw_edit_form(array('config' => array('no_form_tag' => true), 'fields' => $form_array));
        } elseif (get_request_var('drp_action') == '6') {
            /* Connect Devices */
            print "<tr>\n\t\t\t\t<td colspan='2' class='textArea'>\n\t\t\t\t\t<p>" . __('To connect the following devices to their respective Cacti Device, press the "yes" button below.  The relation will be built on equal hostnames. Description will be updated as well.') . "</p>\n\t\t\t\t\t<p><ul>{$device_list}</ul></p>\n\t\t\t\t</td>\n\t\t\t</tr>";
        } elseif (get_request_var('drp_action') == '7') {
            /* Copy SNMP Settings */
            print "<tr>\n\t\t\t\t<td colspan='2' class='textArea'>\n\t\t\t\t\t<p>" . __('To copy SNMP Settings from connected Cacti Device to MacTrack Device, press the "yes" button below.  All not connected Devices will silently be skipped. SNMP retries will be taken from Ping retries.') . "</p>\n\t\t\t\t\t<p><ul>{$device_list}</ul></p>\n\t\t\t\t</td>\n\t\t\t</tr>";
        } elseif (get_request_var('drp_action') == '1') {
            /* delete */
            print "<tr>\n\t\t\t\t<td class='textArea'>\n\t\t\t\t\t<p>" . __('Are you sure you want to delete the following devices?') . "</p>\n\t\t\t\t\t<p><ul>{$device_list}</ul></p>\n\t\t\t\t</td>\n\t\t\t</tr>";
        }
    }
    print "<tr>\n\t\t<td colspan='2' align='right' class='saveRow'>\n\t\t\t<input type='hidden' name='action' value='actions'>\n\t\t\t<input type='hidden' name='selected_items' value='" . (isset($device_array) ? serialize($device_array) : '') . "'>\n\t\t\t<input type='hidden' name='drp_action' value='" . get_request_var('drp_action') . "'>" . (strlen($save_html) ? "\n\t\t\t<input type='button' name='cancel' onClick='cactiReturnTo()' value='" . __('No') . "'>\n\t\t\t{$save_html}" : "<input type='button' onClick='cactiReturnTo()' name='cancel' value='" . __('Return') . "'>") . "\n\t\t</td>\n\t</tr>";
    html_end_box();
    form_end();
    bottom_footer();
}
Exemple #11
0
function api_poller_get_rrd_next_step($rrd_step = 300, $num_rrd_items = 1)
{
    global $config;
    $poller_interval = read_config_option('poller_interval');
    $rrd_next_step = 0;
    if ($rrd_step != $poller_interval && isset($poller_interval)) {
        if (!isset($config['rrd_step_counter'])) {
            $rrd_step_counter = read_config_option('rrd_step_counter');
        } else {
            $rrd_step_counter = $config['rrd_step_counter'];
        }
        if ($num_rrd_items == 1) {
            $config['rrd_num_counter'] = 0;
        } else {
            if (!isset($config['rrd_num_counter'])) {
                $config['rrd_num_counter'] = 1;
            } else {
                $config['rrd_num_counter']++;
            }
        }
        $modulus = $rrd_step / $poller_interval;
        if ($modulus < 1 || $rrd_step_counter == 0) {
            $rrd_next_step = 0;
        } else {
            $rrd_next_step = $poller_interval * ($rrd_step_counter % $modulus);
        }
        if ($num_rrd_items == 1) {
            $rrd_step_counter++;
        } else {
            if ($num_rrd_items == $config['rrd_num_counter']) {
                $rrd_step_counter++;
                $config['rrd_num_counter'] = 0;
            }
        }
        if ($rrd_step_counter >= $modulus) {
            $rrd_step_counter = 0;
        }
        /* save rrd_step_counter */
        $config['rrd_step_counter'] = $rrd_step_counter;
        db_execute_prepared("REPLACE INTO settings (name, value) VALUES ('rrd_step_counter', ?)", array($rrd_step_counter));
    }
    return $rrd_next_step;
}
Exemple #12
0
function api_plugin_remove_realms($plugin)
{
    $realms = db_fetch_assoc_prepared('SELECT id FROM plugin_realms WHERE plugin = ?', array($plugin), false);
    foreach ($realms as $realm) {
        $id = $realm['id'] + 100;
        db_execute_prepared('DELETE FROM user_auth_realm WHERE realm_id = ?', array($id));
        db_execute_prepared('DELETE FROM user_auth_group_realm WHERE realm_id = ?', array($id));
    }
    db_execute_prepared('DELETE FROM plugin_realms WHERE plugin = ?', array($plugin));
}
Exemple #13
0
function data_remove($id)
{
    $data_input_fields = db_fetch_assoc_prepared('SELECT id FROM data_input_fields WHERE data_input_id = ?', array($id));
    if (is_array($data_input_fields)) {
        foreach ($data_input_fields as $data_input_field) {
            db_execute_prepared('DELETE FROM data_input_data WHERE data_input_field_id = ?', array($data_input_field['id']));
        }
    }
    db_execute_prepared('DELETE FROM data_input WHERE id = ?', array($id));
    db_execute_prepared('DELETE FROM data_input_fields WHERE data_input_id = ?', array($id));
}
Exemple #14
0
function api_reapply_suggested_data_source_title($local_data_id)
{
    global $config;
    $data_template_data_id = db_fetch_cell_prepared('SELECT id FROM data_template_data WHERE local_data_id = ?', array($local_data_id));
    if (empty($data_template_data_id)) {
        return;
    }
    /* require query type data sources only (snmp_query_id > 0) */
    $data_local = db_fetch_row_prepared('SELECT id, host_id, data_template_id, snmp_query_id, snmp_index FROM data_local WHERE snmp_query_id > 0 AND id = ?', array($local_data_id));
    /* if this is not a data query graph, simply return */
    if (!isset($data_local['host_id'])) {
        return;
    }
    $snmp_query_graph_id = db_fetch_cell_prepared("SELECT \n\t\tdata_input_data.value FROM data_input_data \n\t\tJOIN data_input_fields ON (data_input_data.data_input_field_id = data_input_fields.id) \n\t\tJOIN data_template_data ON (data_template_data.id = data_input_data.data_template_data_id) \n\t\tWHERE data_input_fields.type_code = 'output_type' \n\t\tAND data_template_data.local_data_id = ?", array($data_local['id']));
    /* no snmp query graph id found */
    if ($snmp_query_graph_id == 0) {
        return;
    }
    $suggested_values = db_fetch_assoc_prepared("SELECT \n\t\ttext, \n\t\tfield_name \n\t\tFROM snmp_query_graph_rrd_sv \n\t\tWHERE snmp_query_graph_id = ?\n\t\tAND data_template_id = ?\n\t\tAND field_name = 'name'\n\t\tORDER BY sequence", array($snmp_query_graph_id, $data_local['data_template_id']));
    $suggested_values_data = array();
    if (sizeof($suggested_values) > 0) {
        foreach ($suggested_values as $suggested_value) {
            if (!isset($suggested_values_data[$suggested_value['field_name']])) {
                $subs_string = substitute_snmp_query_data($suggested_value['text'], $data_local['host_id'], $data_local['snmp_query_id'], $data_local['snmp_index'], read_config_option('max_data_query_field_length'));
                /* if there are no '|query' characters, all of the substitutions were successful */
                if (!substr_count($subs_string, '|query')) {
                    db_execute_prepared('UPDATE data_template_data SET ' . $suggested_value['field_name'] . ' = ? WHERE local_data_id = ?', array($suggested_value['text'], $local_data_id));
                    /* once we find a working value for that very field, stop */
                    $suggested_values_data[$suggested_value['field_name']] = true;
                }
            }
        }
    }
}
Exemple #15
0
function update_system_mibs($host_id)
{
    $system_mibs = array('snmp_sysDescr' => '.1.3.6.1.2.1.1.1.0', 'snmp_sysObjectID' => '.1.3.6.1.2.1.1.2.0', 'snmp_sysUpTimeInstance' => '.1.3.6.1.2.1.1.3.0', 'snmp_sysContact' => '.1.3.6.1.2.1.1.4.0', 'snmp_sysName' => '.1.3.6.1.2.1.1.5.0', 'snmp_sysLocation' => '.1.3.6.1.2.1.1.6.0');
    $h = db_fetch_row_prepared('SELECT * FROM host WHERE id = ?', array($host_id));
    if (sizeof($h)) {
        foreach ($system_mibs as $name => $oid) {
            $value = cacti_snmp_get($h['hostname'], $h['snmp_community'], $oid, $h['snmp_version'], $h['snmp_username'], $h['snmp_password'], $h['snmp_auth_protocol'], $h['snmp_priv_passphrase'], $h['snmp_priv_protocol'], $h['snmp_context'], $h['snmp_port'], $h['snmp_timeout'], read_config_option('snmp_retries'), SNMP_CMDPHP);
            if (!empty($value)) {
                db_execute_prepared("UPDATE host SET {$name} = ? WHERE id = ?", array($value, $host_id));
            }
        }
    }
}
Exemple #16
0
function db_execute($sql, $log = TRUE, $db_conn = FALSE)
{
    return db_execute_prepared($sql, array(), $log, $db_conn);
}
Exemple #17
0
                /* script (php script server) */
                if ($using_proc_function == true) {
                    $output = trim(str_replace("\n", "", exec_poll_php($item["arg1"], $using_proc_function, $pipes, $cactiphp)));
                    /* remove any quotes from string */
                    $output = strip_quotes($output);
                    if (!validate_result($output)) {
                        if (strlen($output) > 20) {
                            $strout = 20;
                        } else {
                            $strout = strlen($output);
                        }
                        $output = "U";
                    }
                } else {
                    $output = "U";
                }
                break;
        }
        if (isset($output)) {
            db_execute_prepared("INSERT INTO poller_output_realtime \n\t\t\t\t(local_data_id, rrd_name, time, poller_id, output) \n\t\t\t\tVALUES \n\t\t\t\t(?, ?, ?, ?, ?)", array($item["local_data_id"], $item["rrd_name"], $host_update_time, $poller_id, $output));
        }
    }
    if ($using_proc_function == true && $script_server_calls > 0) {
        /* close php server process */
        fwrite($pipes[0], "quit\r\n");
        fclose($pipes[0]);
        fclose($pipes[1]);
        fclose($pipes[2]);
        $return_value = proc_close($cactiphp);
    }
}
function api_mactrack_revoke_mac_addresses($mac_address)
{
    db_execute_prepared('UPDATE mac_track_ports SET authorized=0 WHERE mac_address = ?', array($mac_address));
    db_execute_prepared('DELETE FROM mac_track_macauth WHERE mac_address = ?', array($mac_address));
}
Exemple #19
0
function item_remove()
{
    /* ================= input validation ================= */
    input_validate_input_number(get_request_var_request('id'));
    /* ==================================================== */
    db_execute_prepared('DELETE FROM graph_templates_item WHERE id = ?', array(get_request_var_request('id')));
}
Exemple #20
0
function update_graph_title_cache($local_graph_id)
{
    db_execute_prepared('UPDATE graph_templates_graph SET title_cache = ? WHERE local_graph_id = ?', array(get_graph_title($local_graph_id), $local_graph_id));
}
function mactrack_snmp_remove()
{
    /* ================= input validation ================= */
    get_filter_request_var('id');
    /* ==================================================== */
    if (read_config_option('deletion_verification') == 'on' && !isset_request_var('confirm')) {
        general_header();
        form_confirm(__('Are You Sure?'), __('Are you sure you want to delete the SNMP Option Set(s) %s?', db_fetch_cell_prepared('SELECT name FROM mactrack WHERE id = ?', array(get_request_var('id')))), 'mactrack_snmp.php', 'mactrack_snmp.php?action=remove&id=' . get_request_var('id'));
        bottom_footer();
        exit;
    }
    if (read_config_option('deletion_verification') == '' || isset_request_var('confirm')) {
        db_execute_prepared('DELETE FROM mac_track_snmp_items WHERE snmp_id = ?', array(get_request_var('id')));
        db_execute_prepared('DELETE FROM mac_track_snmp WHERE id = ?', array(get_request_var('id')));
    }
}
Exemple #22
0
function template_item_remove_dq()
{
    /* ================= input validation ================= */
    input_validate_input_number(get_request_var_request('id'));
    input_validate_input_number(get_request_var_request('host_template_id'));
    /* ==================================================== */
    db_execute_prepared('DELETE FROM host_template_snmp_query WHERE snmp_query_id = ? AND host_template_id = ?', array(get_request_var_request('id'), get_request_var_request('host_template_id')));
}
Exemple #23
0
function do_rrd()
{
    global $config, $rra_path;
    /* suppress warnings */
    error_reporting(0);
    /* install the rrdclean error handler */
    set_error_handler('rrdclean_error_handler');
    while (list($var, $val) = each($_POST)) {
        if (ereg('^chk_(.*)$', $var, $matches)) {
            /* recreate the file name */
            $unused_file = db_fetch_row_prepared('SELECT id, name, local_data_id 
				FROM data_source_purge_temp
				WHERE id = ?', array($matches[1]));
            /* add to data_source_purge_action table */
            $sql = "INSERT INTO data_source_purge_action VALUES('', ?, ?, ?) ON DUPLICATE KEY UPDATE local_data_id = VALUES(local_data_id)";
            db_execute_prepared($sql, array($unused_file['name'], $unused_file['local_data_id'], $_POST['drp_action']));
            /* drop from data_source_purge table */
            db_execute_prepared('DELETE FROM data_source_purge_temp WHERE id = ?', array($matches[1]));
        }
    }
    /* restore original error handler */
    restore_error_handler();
}
function mactrack_disable()
{
    /* ================= input validation ================= */
    get_filter_request_var('device_id');
    /* ==================================================== */
    $dbinfo = db_fetch_row_prepared('SELECT * FROM mactrack_devices WHERE device_id = ?', array(get_request_var('device_id')));
    /* log the trasaction to the database */
    mactrack_log_action(__('Device Disable \'%d\'', $dbinfo['hostname']));
    db_execute_prepared("UPDATE mactack_devices SET disabled='on' WHERE device_id = ?", array(get_request_var('device_id')));
    /* get the new html */
    $html = mactrack_format_device_row($stat);
    /* send the response back to the browser */
    print 'disable!!!!' . $stat['device_id'] . '!!!!' . $html;
}
Exemple #25
0
function boost_process_poller_output($use_server = false, $local_data_id = '')
{
    global $config, $boost_sock, $boost_timeout, $debug, $get_memory, $memory_used;
    global $rrdtool_pipe, $rrdtool_read_pipe;
    include_once $config['library_path'] . '/rrd.php';
    /* suppress warnings */
    if (defined('E_DEPRECATED')) {
        error_reporting(E_ALL ^ E_DEPRECATED);
    } else {
        error_reporting(E_ALL);
    }
    /* install the boost error handler */
    set_error_handler('boost_error_handler');
    /* load system variables needed */
    $log_verbosity = read_config_option('log_verbosity');
    $upd_string_len = read_config_option('boost_rrd_update_string_length');
    /* tiny SQL where addendum for boost */
    if (strlen($local_data_id)) {
        /* we can simplify the delete process if only one local_data_id */
        $single_local_data_id = true;
        $orig_local_data_id = $local_data_id;
        /* aquire lock in order to prevent race conditions */
        while (!db_fetch_cell("SELECT GET_LOCK('boost.single_ds.{$local_data_id}', 1)")) {
            usleep(50000);
        }
    } else {
        $single_local_data_id = false;
        $poller_interval = read_config_option('poller_interval');
        $rrd_update_interval = read_config_option('boost_rrd_update_interval');
        $data_ids_to_get = read_config_option('boost_rrd_update_max_records_per_select');
        $archive_table = boost_get_arch_table_name();
        if ($archive_table === false) {
            cacti_log('Failed to determine archive table', false, 'BOOST');
            return 0;
        }
    }
    /* get the records */
    if ($single_local_data_id) {
        $query_string = '';
        $arch_tables = db_fetch_assoc("SELECT table_name AS name\n\t\t\tFROM information_schema.tables\n\t\t\tWHERE table_schema=SCHEMA()\n\t\t\tAND table_name LIKE 'poller_output_boost_arch_%'\n\t\t\tAND table_rows>0;");
        if (count($arch_tables)) {
            foreach ($arch_tables as $table) {
                if (strlen($query_string)) {
                    $query_string .= ' UNION ';
                }
                $query_string .= ' (SELECT local_data_id, UNIX_TIMESTAMP(time) AS timestamp, rrd_name, output FROM ' . $table['name'] . " WHERE local_data_id='{$local_data_id}') ";
            }
        }
        if (strlen($query_string)) {
            $query_string .= ' UNION ';
        }
        $timestamp = time();
        $query_string .= " (SELECT local_data_id, UNIX_TIMESTAMP(time) AS timestamp, rrd_name, output FROM poller_output_boost WHERE local_data_id='{$local_data_id}' AND time < FROM_UNIXTIME('{$timestamp}'))";
        $query_string .= ' ORDER BY local_data_id ASC, timestamp ASC, rrd_name ASC ';
    } else {
        $query_string = "SELECT local_data_id, UNIX_TIMESTAMP(time) AS timestamp, rrd_name, output FROM {$archive_table} FORCE INDEX (PRIMARY)\n\t\t\tORDER BY local_data_id ASC, time ASC, rrd_name ASC\n\t\t\tLIMIT {$data_ids_to_get} ";
    }
    boost_timer('get_records', BOOST_TIMER_START);
    $results = db_fetch_assoc($query_string);
    boost_timer('get_records', BOOST_TIMER_END);
    /* log memory */
    if ($get_memory) {
        $cur_memory = memory_get_usage();
        if ($cur_memory > $memory_used) {
            $memory_used = $cur_memory;
        }
    }
    if ($single_local_data_id && ($debug || $log_verbosity >= POLLER_VERBOSITY_MEDIUM)) {
        cacti_log("NOTE: Updating Local Data ID:'{$local_data_id}', Total of '" . sizeof($results) . "' Updates to Process", false, 'BOOST');
    }
    if (sizeof($results) > 0) {
        /* open the boost socket connection if applicable */
        if (read_config_option('boost_server_enable') == 'on' && $local_data_id != '' && $use_server) {
            $boost_timeout = read_config_option('boost_server_timeout');
            $boost_sock = boost_server_connect();
            if ($boost_sock < 0) {
                /* restore original error handler */
                restore_error_handler();
                return 0;
            }
        }
        /* create an array keyed off of each .rrd file */
        $local_data_id = -1;
        $time = -1;
        $outbuf = '';
        $last_update = -1;
        $last_item = array('local_data_id' => -1, 'timestamp' => -1, 'rrd_name' => '');
        /* we are going to blow away all record if ok */
        $vals_in_buffer = 0;
        /* cut last DS (likely to be incomplete due to LIMIT)*/
        if (!$single_local_data_id) {
            reset($results);
            $first_ds = $results[key($results)];
            $first_ds = intval($first_ds['local_data_id']);
            end($results);
            $last_ds = $results[key($results)];
            $last_ds = intval($last_ds['local_data_id']);
            reset($results);
            if ($first_ds == $last_ds) {
                if (sizeof($results) == $data_ids_to_get) {
                    cacti_log("FALURE: Current LIMIT ({$data_ids_to_get}) is too low to run multiple DS RRD writes, consider raising it", false, 'BOOST');
                }
                restore_error_handler();
                return boost_process_poller_output($use_server, $first_ds);
            }
        }
        boost_timer('results_cycle', BOOST_TIMER_START);
        /* go through each poller_output_boost entries and process */
        foreach ($results as $item) {
            $item['timestamp'] = trim($item['timestamp']);
            if ($single_local_data_id && $last_item['local_data_id'] == $item['local_data_id'] && $last_item['timestamp'] == $item['timestamp'] && strcmp($last_item['rrd_name'], $item['rrd_name']) == 0) {
                continue;
            }
            if (!$single_local_data_id && $first_ds != $last_ds && $last_ds == $item['local_data_id']) {
                /* we faced last and possibly incomplete DS, bail out */
                break;
            }
            /* if the local_data_id changes, we need to flush the buffer */
            if ($local_data_id != $item['local_data_id']) {
                /* update the rrd for the previous local_data_id */
                if ($vals_in_buffer) {
                    if ($debug || $log_verbosity >= POLLER_VERBOSITY_MEDIUM) {
                        cacti_log("NOTE: Updating Local Data Id:'{$local_data_id}', Template:" . $rrd_tmpl . ', Output:' . $outbuf, false, 'BOOST');
                    }
                    boost_timer('rrdupdate', BOOST_TIMER_START);
                    $return_value = boost_rrdtool_function_update($local_data_id, $rrd_path, $rrd_tmpl, $initial_time, $outbuf, $rrdtool_pipe);
                    boost_timer('rrdupdate', BOOST_TIMER_END);
                    $outbuf = '';
                    $vals_in_buffer = 0;
                    /* check return status for delete operation */
                    if (trim($return_value) != 'OK') {
                        cacti_log("WARNING: RRD Update Warning '" . $return_value . "' for Local Data ID '{$local_data_id}'", false, 'BOOST');
                    }
                }
                /* reset the rrd file path and templates, assume non multi output */
                boost_timer('rrd_filename_and_template', BOOST_TIMER_START);
                $rrd_data = boost_get_rrd_filename_and_template($item['local_data_id']);
                $rrd_tmpl = $rrd_data['rrd_template'];
                $rrd_path = $rrd_data['rrd_path'];
                boost_timer('rrd_filename_and_template', BOOST_TIMER_END);
                $pipe = is_resource($rrdtool_read_pipe) || is_array($rrdtool_read_pipe) ? $rrdtool_read_pipe : $rrdtool_pipe;
                boost_timer('rrd_lastupdate', BOOST_TIMER_START);
                $last_update = boost_rrdtool_get_last_update_time($rrd_path, $pipe);
                boost_timer('rrd_lastupdate', BOOST_TIMER_END);
                $local_data_id = $item['local_data_id'];
                $time = $item['timestamp'];
                $initial_time = $time;
                $outbuf = ' ' . $time;
                $multi_vals_set = false;
            }
            /* don't generate error messages if the RRD has already been updated */
            if ($time <= $last_update) {
                cacti_log("WARNING: Stale Poller Data Found! Item Time:'" . $time . "', RRD Time:'" . $last_update . "' Ignoring Value!", false, 'BOOST');
                $value = 'DNP';
            } else {
                $value = trim($item['output']);
            }
            if ($time != $item['timestamp']) {
                if (strlen($outbuf) > $upd_string_len) {
                    if ($log_verbosity >= POLLER_VERBOSITY_MEDIUM) {
                        cacti_log("NOTE: Updating Local Data Id:'{$local_data_id}', Template:" . $rrd_tmpl . ', Output:' . $outbuf, false, 'BOOST');
                    }
                    boost_timer('rrdupdate', BOOST_TIMER_START);
                    $return_value = boost_rrdtool_function_update($local_data_id, $rrd_path, $rrd_tmpl, $initial_time, $outbuf, $rrdtool_pipe);
                    boost_timer('rrdupdate', BOOST_TIMER_END);
                    $outbuf = '';
                    $vals_in_buffer = 0;
                    /* check return status for delete operation */
                    if (trim($return_value) != 'OK') {
                        cacti_log("WARNING: RRD Update Warning '" . $return_value . "' for Local Data ID '{$local_data_id}'", false, 'BOOST');
                    }
                }
                $outbuf .= ' ' . $item['timestamp'];
                $time = $item['timestamp'];
            }
            /* single one value output */
            if (strcmp($value, 'DNP') == 0) {
                /* continue, bad time */
            } elseif (is_numeric($value) || strcmp($value, 'U') == 0) {
                $outbuf .= ':' . $value;
                $vals_in_buffer++;
            } elseif (function_exists('is_hexadecimal') && is_hexadecimal($value)) {
                $outbuf .= ':' . hexdec($value);
                $vals_in_buffer++;
            } elseif (strlen($value)) {
                /* break out multiple value output to an array */
                $values = explode(' ', $value);
                if (!$multi_vals_set) {
                    $rrd_field_names = array_rekey(db_fetch_assoc_prepared('SELECT
						data_template_rrd.data_source_name,
						data_input_fields.data_name
						FROM (data_template_rrd, data_input_fields)
						WHERE data_template_rrd.data_input_field_id = data_input_fields.id
						AND data_template_rrd.local_data_id = ?', array($item['local_data_id'])), 'data_name', 'data_source_name');
                    $rrd_tmpl = '';
                }
                $first_tmpl = 1;
                $multi_ok = false;
                for ($i = 0; $i < count($values); $i++) {
                    if (preg_match("/^([a-zA-Z0-9_\\.-]+):([eE0-9\\+\\.-]+)\$/", $values[$i], $matches)) {
                        if (isset($rrd_field_names[$matches[1]])) {
                            $multi_ok = true;
                            if ($log_verbosity == POLLER_VERBOSITY_DEBUG) {
                                cacti_log("Parsed MULTI output field '" . $matches[0] . "' [map " . $matches[1] . '->' . $rrd_field_names[$matches[1]] . ']', false, 'BOOST');
                            }
                            if (!$multi_vals_set) {
                                if (!$first_tmpl) {
                                    $rrd_tmpl .= ':';
                                }
                                $rrd_tmpl .= $rrd_field_names[$matches[1]];
                                $first_tmpl = 0;
                            }
                            if (is_numeric($matches[2]) || $matches[2] == 'U') {
                                $outbuf .= ':' . $matches[2];
                            } elseif (function_exists('is_hexadecimal') && is_hexadecimal($matches[2])) {
                                $outbuf .= ':' . hexdec($matches[2]);
                            } else {
                                $outbuf .= ':U';
                            }
                        }
                    }
                }
                /* we only want to process the template and gather the fields once */
                $multi_vals_set = true;
                if ($multi_ok) {
                    $vals_in_buffer++;
                }
            } else {
                cacti_log('WARNING: Local Data Id [' . $item['local_data_id'] . '] Contains an empty value', false, 'BOOST');
            }
        }
        /* process the last rrdupdate if applicable */
        if ($vals_in_buffer) {
            if ($log_verbosity >= POLLER_VERBOSITY_MEDIUM) {
                cacti_log("NOTE: Updating Local Data Id:'{$local_data_id}', Template:" . $rrd_tmpl . ', Output:' . $outbuf, false, 'BOOST');
            }
            boost_timer('rrdupdate', BOOST_TIMER_START);
            $return_value = boost_rrdtool_function_update($local_data_id, $rrd_path, $rrd_tmpl, $initial_time, $outbuf, $rrdtool_pipe);
            boost_timer('rrdupdate', BOOST_TIMER_END);
            /* check return status for delete operation */
            if (trim($return_value) != 'OK') {
                cacti_log("WARNING: RRD Update Warning '" . $return_value . "' for Local Data ID '{$local_data_id}'", false, 'BOOST');
            }
        }
        boost_timer('results_cycle', BOOST_TIMER_END);
        /* remove the entries from the table */
        boost_timer('delete', BOOST_TIMER_START);
        if ($single_local_data_id) {
            $tables = db_fetch_assoc("SELECT table_name AS name\n\t\t\t\tFROM information_schema.tables\n\t\t\t\tWHERE table_schema=SCHEMA()\n\t\t\t\tAND (table_name LIKE 'poller_output_boost_arch_%' OR table_name LIKE 'poller_output_boost')\n\t\t\t\tAND table_rows>0;");
            if (count($tables)) {
                foreach ($tables as $table) {
                    db_execute_prepared('DELETE FROM ' . $table['name'] . ' WHERE local_data_id = ? AND time < FROM_UNIXTIME(?)', array($local_data_id, $timestamp));
                }
            }
        } else {
            db_execute_prepared("DELETE FROM {$archive_table} WHERE local_data_id BETWEEN ? AND ?", array($first_ds, $last_ds - 1));
        }
        boost_timer('delete', BOOST_TIMER_END);
        /* close the boost server connection, if applicable */
        if (read_config_option('boost_server_enable') == 'on' && $local_data_id != '' && $use_server) {
            boost_server_disconnect($boost_sock);
        }
    }
    if ($single_local_data_id) {
        db_execute("SELECT RELEASE_LOCK('boost.single_ds.{$orig_local_data_id}')");
    }
    /* restore original error handler */
    restore_error_handler();
    return sizeof($results);
}
function mactrack_utilities_ports_clear()
{
    global $config;
    if (read_config_option('remove_verification') == 'on' && !isset_request_var('confirm')) {
        top_header();
        form_confirm(__('Are You Sure?'), __('Are you sure you want to delete all the Port to MAC to IP results from the system?'), 'mactrack_utilities.php', 'mactrack_utilities.php?action=mactrack_utilities_truncate_ports_table');
        bottom_footer();
        exit;
    }
    if (read_config_option('remove_verification') == '' || isset_request_var('confirm')) {
        $rows = db_fetch_cell('SELECT COUNT(*) FROM mac_track_ports');
        db_execute('TRUNCATE TABLE mac_track_ports');
        db_execute('TRUNCATE TABLE mac_track_scan_dates');
        db_execute('TRUNCATE TABLE mac_track_ips');
        db_execute('TRUNCATE TABLE mac_track_ip_ranges');
        db_execute('TRUNCATE TABLE mac_track_vlans');
        db_execute('TRUNCATE TABLE mac_track_aggregated_ports');
        db_execute('UPDATE mac_track_sites SET total_macs=0, total_ips=0, total_user_ports=0, total_oper_ports=0, total_trunk_ports=0');
        db_execute('UPDATE mac_track_devices SET ips_total=0, ports_total=0, ports_active=0, ports_trunk=0, macs_active=0, vlans_total=0, last_runduration=0.0000');
        $device_rows = db_fetch_assoc('SELECT device_id FROM mac_track_devices');
        if (sizeof($device_rows)) {
            foreach ($device_rows as $device_row) {
                db_execute_prepared('UPDATE mac_track_devices SET ips_total=0 WHERE device_id = ?', array($device_row['device_id']));
                db_execute_prepared('UPDATE mac_track_devices SET ports_total=0 WHERE device_id = ?', array($device_row['device_id']));
                db_execute_prepared('UPDATE mac_track_devices SET ports_active=0 WHERE device_id = ?', array($device_row['device_id']));
                db_execute_prepared('UPDATE mac_track_devices SET ports_trunk=0 WHERE device_id = ?', array($device_row['device_id']));
                db_execute_prepared('UPDATE mac_track_devices SET macs_active=0 WHERE device_id = ?', array($device_row['device_id']));
                db_execute_prepared('UPDATE mac_track_devices SET vlans_total=0 WHERE device_id = ?', array($device_row['device_id']));
                db_execute_prepared('UPDATE mac_track_devices SET last_runduration=0.00000 WHERE device_id = ?', array($device_row['device_id']));
            }
        }
        $site_rows = db_fetch_assoc('SELECT site_id FROM mac_track_sites');
        if (sizeof($site_rows)) {
            foreach ($site_rows as $site_row) {
                db_execute('UPDATE mac_track_sites SET total_devices=0 WHERE site_id = ?', array($site_row['site_id']));
                db_execute('UPDATE mac_track_sites SET total_macs=0 WHERE site_id = ?', array($site_row['site_id']));
                db_execute('UPDATE mac_track_sites SET total_ips=0 WHERE site_id = ?', array($site_row['site_id']));
                db_execute('UPDATE mac_track_sites SET total_user_ports=0 WHERE site_id = ?', array($site_row['site_id']));
                db_execute('UPDATE mac_track_sites SET total_oper_ports=0 WHERE site_id = ?', array($site_row['site_id']));
                db_execute('UPDATE mac_track_sites SET total_trunk_ports=0 WHERE site_id = ?', array($site_row['site_id']));
            }
        }
        top_header();
        mactrack_utilities();
        html_start_box(__('Device Tracking Database Results'), '100%', '', '3', 'center', '');
        ?>
		<td>
			The following number of records have been removed from the database: <?php 
        print $rows;
        ?>
		</td>
		<?php 
        html_end_box();
    }
}
Exemple #27
0
function utilities_clear_user_log()
{
    $users = db_fetch_assoc('SELECT DISTINCT username FROM user_auth');
    if (sizeof($users)) {
        /* remove active users */
        foreach ($users as $user) {
            $total_rows = db_fetch_cell_prepared('SELECT COUNT(username) FROM user_log WHERE username = ? AND result = 1', array($user['username']));
            if ($total_rows > 1) {
                db_execute_prepared('DELETE FROM user_log WHERE username = ? AND result = 1 ORDER BY time LIMIT ' . ($total_rows - 1), array($user['username']));
            }
            db_execute_prepared('DELETE FROM user_log WHERE username = ? AND result = 0', array($user['username']));
        }
        /* delete inactive users */
        db_execute('DELETE FROM user_log WHERE user_id NOT IN (SELECT id FROM user_auth) OR username NOT IN (SELECT username FROM user_auth)');
    }
}
Exemple #28
0
function remove_files($file_array)
{
    global $config, $debug, $archived, $purged;
    include_once $config['library_path'] . '/api_graph.php';
    include_once $config['library_path'] . '/api_data_source.php';
    maint_debug('RRDClean is now running on ' . sizeof($file_array) . ' items');
    /* determine the location of the RRA files */
    if (isset($config['rra_path'])) {
        $rra_path = $config['rra_path'];
    } else {
        $rra_path = $config['base_path'] . '/rra';
    }
    /* let's prepare the archive directory */
    $rrd_archive = read_config_option('rrd_archive', TRUE);
    if ($rrd_archive == '') {
        $rrd_archive = $rra_path . '/archive';
    }
    rrdclean_create_path($rrd_archive);
    /* now scan the files */
    foreach ($file_array as $file) {
        $source_file = $rra_path . '/' . $file['name'];
        switch ($file['action']) {
            case '1':
                if (unlink($source_file)) {
                    maint_debug('Deleted: ' . $file['name']);
                } else {
                    cacti_log($file['name'] . " Error: unable to delete from {$rra_path}!", true, 'MAINT');
                }
                $purged++;
                break;
            case '3':
                $target_file = $rrd_archive . '/' . $file['name'];
                $target_dir = dirname($target_file);
                if (!is_dir($target_dir)) {
                    rrdclean_create_path($target_dir);
                }
                if (rename($source_file, $target_file)) {
                    maint_debug('Moved: ' . $file['name'] . ' to: ' . $rrd_archive);
                } else {
                    cacti_log($file['name'] . " Error: unable to move to {$rrd_archive}!", true, 'MAINT');
                }
                $archived++;
                break;
        }
        /* drop from data_source_purge_action table */
        db_execute_prepared('DELETE FROM `data_source_purge_action` WHERE name = ?', array($file['name']));
        maint_debug('Delete from data_source_purge_action: ' . $file['name']);
        //fetch all local_graph_id's according to this data source
        $lgis = db_fetch_assoc_prepared('SELECT DISTINCT gl.id
			FROM graph_local AS gl
			INNER JOIN graph_templates_item AS gti
			ON gl.id = gti.local_graph_id
			INNER JOIN data_template_rrd AS dtr
			ON dtr.id=gti.task_item_id
			INNER JOIN data_local AS dl
			ON dtr.local_data_id=dl.id
			WHERE (local_data_id=?)', array($file['local_data_id']));
        if (sizeof($lgis)) {
            /* anything found? */
            cacti_log('Processing ' . sizeof($lgis) . ' Graphs for data source id: ' . $file['local_data_id'], true, 'MAINT');
            /* get them all */
            foreach ($lgis as $item) {
                $remove_lgis[] = $item['id'];
                cacti_log('remove local_graph_id=' . $item['id'], true, 'MAINT');
            }
            /* and remove them in a single run */
            if (!empty($remove_lgis)) {
                api_graph_remove_multi($remove_lgis);
            }
        }
        /* remove related data source if any */
        if ($file['local_data_id'] > 0) {
            cacti_log('removing data source: ' . $file['local_data_id'], true, 'MAINT');
            api_data_source_remove($file['local_data_id']);
        }
    }
    cacti_log('RRDClean has finished a purge pass of ' . sizeof($file_array) . ' items', true, 'MAINT');
}
Exemple #29
0
function form_actions()
{
    global $device_actions, $fields_host_edit;
    /* ================= input validation ================= */
    input_validate_input_regex(get_request_var_post('drp_action'), '^([a-zA-Z0-9_]+)$');
    /* ==================================================== */
    /* if we are to save this form, instead of display it */
    if (isset($_POST['selected_items'])) {
        $selected_items = unserialize(stripslashes($_POST['selected_items']));
        if ($_POST['drp_action'] == '2') {
            /* Enable Selected Devices */
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                input_validate_input_number($selected_items[$i]);
                /* ==================================================== */
                db_execute_prepared("UPDATE host SET disabled = '' WHERE id = ?", array($selected_items[$i]));
                /* update poller cache */
                $data_sources = db_fetch_assoc_prepared('SELECT id FROM data_local WHERE host_id = ?', array($selected_items[$i]));
                $poller_items = $local_data_ids = array();
                if (sizeof($data_sources) > 0) {
                    foreach ($data_sources as $data_source) {
                        $local_data_ids[] = $data_source['id'];
                        $poller_items = array_merge($poller_items, update_poller_cache($data_source['id']));
                    }
                }
                if (sizeof($local_data_ids)) {
                    poller_update_poller_cache_from_buffer($local_data_ids, $poller_items);
                }
            }
        } elseif ($_POST['drp_action'] == '3') {
            /* Disable Selected Devices */
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                input_validate_input_number($selected_items[$i]);
                /* ==================================================== */
                db_execute_prepared("UPDATE host SET disabled='on' WHERE id = ?", array($selected_items[$i]));
                /* update poller cache */
                db_execute_prepared('DELETE FROM poller_item WHERE host_id = ?', array($selected_items[$i]));
                db_execute_prepared('DELETE FROM poller_reindex WHERE host_id = ?', array($selected_items[$i]));
            }
        } elseif ($_POST['drp_action'] == '4') {
            /* change snmp options */
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                input_validate_input_number($selected_items[$i]);
                /* ==================================================== */
                reset($fields_host_edit);
                while (list($field_name, $field_array) = each($fields_host_edit)) {
                    if (isset($_POST["t_{$field_name}"])) {
                        db_execute_prepared("UPDATE host SET {$field_name} = ? WHERE id = ?", array($_POST[$field_name], $selected_items[$i]));
                    }
                }
                push_out_host($selected_items[$i]);
            }
        } elseif ($_POST['drp_action'] == '5') {
            /* Clear Statisitics for Selected Devices */
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                input_validate_input_number($selected_items[$i]);
                /* ==================================================== */
                db_execute_prepared("UPDATE host SET min_time = '9.99999', max_time = '0', cur_time = '0', avg_time = '0',\n\t\t\t\t\t\ttotal_polls = '0', failed_polls = '0',\tavailability = '100.00'\n\t\t\t\t\t\twhere id = ?", array($selected_items[$i]));
            }
        } elseif ($_POST['drp_action'] == '6') {
            /* change availability options */
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                input_validate_input_number($selected_items[$i]);
                /* ==================================================== */
                reset($fields_host_edit);
                while (list($field_name, $field_array) = each($fields_host_edit)) {
                    if (isset($_POST["t_{$field_name}"])) {
                        db_execute_prepared("UPDATE host SET {$field_name} = ? WHERE id = ?", array($_POST[$field_name], $selected_items[$i]));
                    }
                }
                push_out_host($selected_items[$i]);
            }
        } elseif ($_POST['drp_action'] == '1') {
            /* delete */
            if (!isset($_POST['delete_type'])) {
                $_POST['delete_type'] = 2;
            }
            $data_sources_to_act_on = array();
            $graphs_to_act_on = array();
            $devices_to_act_on = array();
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                input_validate_input_number($selected_items[$i]);
                /* ==================================================== */
                $data_sources = db_fetch_assoc('SELECT
					data_local.id AS local_data_id
					FROM data_local
					WHERE ' . array_to_sql_or($selected_items, 'data_local.host_id'));
                if (sizeof($data_sources) > 0) {
                    foreach ($data_sources as $data_source) {
                        $data_sources_to_act_on[] = $data_source['local_data_id'];
                    }
                }
                if ($_POST['delete_type'] == 2) {
                    $graphs = db_fetch_assoc('SELECT
						graph_local.id AS local_graph_id
						FROM graph_local
						WHERE ' . array_to_sql_or($selected_items, 'graph_local.host_id'));
                    if (sizeof($graphs) > 0) {
                        foreach ($graphs as $graph) {
                            $graphs_to_act_on[] = $graph['local_graph_id'];
                        }
                    }
                }
                $devices_to_act_on[] = $selected_items[$i];
            }
            switch ($_POST['delete_type']) {
                case '1':
                    /* leave graphs and data_sources in place, but disable the data sources */
                    api_data_source_disable_multi($data_sources_to_act_on);
                    api_plugin_hook_function('data_source_remove', $data_sources_to_act_on);
                    break;
                case '2':
                    /* delete graphs/data sources tied to this device */
                    api_data_source_remove_multi($data_sources_to_act_on);
                    api_graph_remove_multi($graphs_to_act_on);
                    api_plugin_hook_function('graphs_remove', $graphs_to_act_on);
                    break;
            }
            api_device_remove_multi($devices_to_act_on);
            api_plugin_hook_function('device_remove', $devices_to_act_on);
        } elseif (preg_match('/^tr_([0-9]+)$/', $_POST['drp_action'], $matches)) {
            /* place on tree */
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                input_validate_input_number($selected_items[$i]);
                input_validate_input_number(get_request_var_post('tree_id'));
                input_validate_input_number(get_request_var_post('tree_item_id'));
                /* ==================================================== */
                api_tree_item_save(0, $_POST['tree_id'], TREE_ITEM_TYPE_HOST, $_POST['tree_item_id'], '', 0, read_graph_config_option('default_rra_id'), $selected_items[$i], 1, 1, false);
            }
        } else {
            api_plugin_hook_function('device_action_execute', $_POST['drp_action']);
        }
        /* update snmpcache */
        snmpagent_device_action_bottom(array($_POST['drp_action'], $selected_items));
        api_plugin_hook_function('device_action_bottom', array($_POST['drp_action'], $selected_items));
        header('Location: host.php');
        exit;
    }
    /* setup some variables */
    $host_list = '';
    $i = 0;
    /* loop through each of the host templates selected on the previous page and get more info about them */
    while (list($var, $val) = each($_POST)) {
        if (preg_match('/^chk_([0-9]+)$/', $var, $matches)) {
            /* ================= input validation ================= */
            input_validate_input_number($matches[1]);
            /* ==================================================== */
            $host_list .= '<li>' . htmlspecialchars(db_fetch_cell_prepared('SELECT description FROM host WHERE id = ?', array($matches[1]))) . '<br>';
            $host_array[$i] = $matches[1];
            $i++;
        }
    }
    top_header();
    /* add a list of tree names to the actions dropdown */
    add_tree_names_to_actions_array();
    html_start_box('<strong>' . $device_actions[get_request_var_post('drp_action')] . '</strong>', '60%', '', '3', 'center', '');
    print "<form action='host.php' autocomplete='off' method='post'>\n";
    if (isset($host_array) && sizeof($host_array)) {
        if ($_POST['drp_action'] == '2') {
            /* Enable Devices */
            print "\t<tr>\n\t\t\t\t\t<td colspan='2' class='textArea'>\n\t\t\t\t\t\t<p>To enable the following Device(s), click \"Continue\".</p>\n\t\t\t\t\t\t<p><ul>" . $host_list . "</ul></p>\n\t\t\t\t\t</td>\n\t\t\t\t\t</tr>";
            $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue' title='Enable Device(s)'>";
        } elseif ($_POST['drp_action'] == '3') {
            /* Disable Devices */
            print "\t<tr>\n\t\t\t\t\t<td colspan='2' class='textArea'>\n\t\t\t\t\t\t<p>To disable the following Device(s), click \"Continue\".</p>\n\t\t\t\t\t\t<p><ul>" . $host_list . '</ul></p>
					</td>
					</tr>';
            $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue' title='Disable Device(s)'>";
        } elseif ($_POST['drp_action'] == '4') {
            /* change snmp options */
            print "\t<tr>\n\t\t\t\t\t<td colspan='2' class='textArea'>\n\t\t\t\t\t\t<p>To change SNMP parameters for the following Device(s), check the box next to the fields\n\t\t\t\t\t\tyou want to update, fill in the new value, and click \"Continue\".</p>\n\t\t\t\t\t\t<p><ul>" . $host_list . '</ul></p>
					</td>
					</tr>';
            $form_array = array();
            while (list($field_name, $field_array) = each($fields_host_edit)) {
                if (preg_match('/^snmp_/', $field_name) || $field_name == 'max_oids') {
                    $form_array += array($field_name => $fields_host_edit[$field_name]);
                    $form_array[$field_name]['value'] = '';
                    $form_array[$field_name]['description'] = '';
                    $form_array[$field_name]['form_id'] = 0;
                    $form_array[$field_name]['sub_checkbox'] = array('name' => 't_' . $field_name, 'friendly_name' => 'Update this Field', 'value' => '');
                }
            }
            draw_edit_form(array('config' => array('no_form_tag' => true), 'fields' => $form_array));
            $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue' title='Change Device(s) SNMP Options'>";
        } elseif ($_POST['drp_action'] == '6') {
            /* change availability options */
            print "\t<tr>\n\t\t\t\t\t<td colspan='2' class='textArea'>\n\t\t\t\t\t\t<p>To change Availability parameters for the following Device(s), check the box next to the fields\n\t\t\t\t\t\tyou want to update, fill in the new value, and click \"Continue\".</p>\n\t\t\t\t\t\t<p><ul>" . $host_list . '</ul></p>
					</td>
					</tr>';
            $form_array = array();
            while (list($field_name, $field_array) = each($fields_host_edit)) {
                if (preg_match('/(availability_method|ping_method|ping_port)/', $field_name)) {
                    $form_array += array($field_name => $fields_host_edit[$field_name]);
                    $form_array[$field_name]['value'] = '';
                    $form_array[$field_name]['description'] = '';
                    $form_array[$field_name]['form_id'] = 0;
                    $form_array[$field_name]['sub_checkbox'] = array('name' => 't_' . $field_name, 'friendly_name' => 'Update this Field', 'value' => '');
                }
            }
            draw_edit_form(array('config' => array('no_form_tag' => true), 'fields' => $form_array));
            $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue' title='Change Device(s) Availability Options'>";
        } elseif ($_POST['drp_action'] == '5') {
            /* Clear Statisitics for Selected Devices */
            print "\t<tr>\n\t\t\t\t\t<td colspan='2' class='textArea'>\n\t\t\t\t\t\t<p>To clear the counters for the following Device(s), press the \"Continue\" button below.</p>\n\t\t\t\t\t\t<p><ul>" . $host_list . '</ul></p>
					</td>
					</tr>';
            $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue' title='Clear Statistics on Device(s)'>";
        } elseif ($_POST['drp_action'] == '1') {
            /* delete */
            print "\t<tr>\n\t\t\t\t\t<td class='textArea'>\n\t\t\t\t\t\t<p>When you click \"Continue\" the following Device(s) will be deleted.</p>\n\t\t\t\t\t\t<p><ul>" . $host_list . '</ul></p>';
            form_radio_button('delete_type', '2', '1', 'Leave all Graph(s) and Data Source(s) untouched.  Data Source(s) will be disabled however.', '1');
            print '<br>';
            form_radio_button('delete_type', '2', '2', 'Delete all associated <strong>Graph(s)</strong> and <strong>Data Source(s)</strong>.', '1');
            print '<br>';
            print "</td></tr>\n\t\t\t\t\t</td>\n\t\t\t\t</tr>\n\n\t\t\t\t";
            $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue' title='Delete Device(s)'>";
        } elseif (preg_match('/^tr_([0-9]+)$/', $_POST['drp_action'], $matches)) {
            /* place on tree */
            print "\t<tr>\n\t\t\t\t\t<td class='textArea'>\n\t\t\t\t\t\t<p>When you click \"Continue\", the following Device(s) will be placed under the branch selected\n\t\t\t\t\t\tbelow.</p>\n\t\t\t\t\t\t<p><ul>" . $host_list . '</ul></p>
						<p><strong>Destination Branch:</strong><br>';
            grow_dropdown_tree($matches[1], '0', 'tree_item_id', '0');
            print "</p>\n\t\t\t\t\t</td>\n\t\t\t\t</tr>\n\n\t\t\t\t<input type='hidden' name='tree_id' value='" . $matches[1] . "'>\n\n\t\t\t\t";
            $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue' title='Place Device(s) on Tree'>";
        } else {
            $save['drp_action'] = $_POST['drp_action'];
            $save['host_list'] = $host_list;
            $save['host_array'] = isset($host_array) ? $host_array : array();
            api_plugin_hook_function('device_action_prepare', $save);
            $save_html = "<input type='button' value='Cancel' onClick='window.history.back()'>&nbsp;<input type='submit' value='Continue'>";
        }
    } else {
        print "<tr><td class='even'><span class='textError'>You must select at least one device.</span></td></tr>\n";
        $save_html = "<input type='button' value='Return' onClick='window.history.back()'>";
    }
    print "\t<tr>\n\t\t\t<td colspan='2' align='right' class='saveRow'>\n\t\t\t\t<input type='hidden' name='action' value='actions'>\n\t\t\t\t<input type='hidden' name='selected_items' value='" . (isset($host_array) ? serialize($host_array) : '') . "'>\n\t\t\t\t<input type='hidden' name='drp_action' value='" . $_POST['drp_action'] . "'>\n\t\t\t\t{$save_html}\n\t\t\t</td>\n\t\t</tr>\n\t\t";
    html_end_box();
    bottom_footer();
}
Exemple #30
0
                     }
                     $output = 'U';
                 }
                 break;
             default:
                 /* invalid polling option */
                 cacti_log("Device[{$host_id}] DS[{$data_source}] ERROR: Invalid polling option: " . $item['action'], $stdout);
         }
         /* End Switch */
         if (isset($output)) {
             /* insert a U in place of the actual value if the snmp agent restarts */
             if ($set_spike_kill && !substr_count($output, ':')) {
                 db_execute_prepared("INSERT INTO poller_output (local_data_id, rrd_name, time, output) VALUES (?, ?, ?,'U')", array($item['local_data_id'], $item['rrd_name'], $host_update_time));
                 /* otherwise, just insert the value received from the poller */
             } else {
                 db_execute_prepared('INSERT INTO poller_output (local_data_id, rrd_name, time, output) VALUES (?, ?, ?, ?)', array($item['local_data_id'], $item['rrd_name'], $host_update_time, $output));
             }
         }
     }
     /* Next Cache Item */
 }
 /* End foreach */
 if ($using_proc_function == true && $script_server_calls > 0) {
     // close php server process
     fwrite($pipes[0], "quit\r\n");
     fclose($pipes[0]);
     fclose($pipes[1]);
     fclose($pipes[2]);
     $return_value = proc_close($cactiphp);
 }
 if ($print_data_to_stdout || read_config_option('log_verbosity') >= POLLER_VERBOSITY_MEDIUM) {