本文整理汇总了PHP中db_fetch_assoc_prepared函数的典型用法代码示例。如果您正苦于以下问题:PHP db_fetch_assoc_prepared函数的具体用法?PHP db_fetch_assoc_prepared怎么用?PHP db_fetch_assoc_prepared使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了db_fetch_assoc_prepared函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: collect_pppoe_users_api
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');
}
}
}
示例2: get_cdef
function get_cdef($cdef_id)
{
$cdef_items = db_fetch_assoc_prepared('SELECT * FROM cdef_items WHERE cdef_id = ? ORDER BY sequence', array($cdef_id));
$i = 0;
$cdef_string = '';
if (sizeof($cdef_items) > 0) {
foreach ($cdef_items as $cdef_item) {
if ($i > 0) {
$cdef_string .= ',';
}
if ($cdef_item['type'] == 5) {
$current_cdef_id = $cdef_item['value'];
$cdef_string .= get_cdef($current_cdef_id);
} else {
$cdef_string .= get_cdef_item_name($cdef_item['id']);
}
$i++;
}
}
return $cdef_string;
}
示例3: api_device_save
function api_device_save($id, $host_template_id, $description, $hostname, $snmp_community, $snmp_version, $snmp_username, $snmp_password, $snmp_port, $snmp_timeout, $disabled, $availability_method, $ping_method, $ping_port, $ping_timeout, $ping_retries, $notes, $snmp_auth_protocol, $snmp_priv_passphrase, $snmp_priv_protocol, $snmp_context, $max_oids, $device_threads)
{
global $config;
include_once $config['base_path'] . '/lib/utility.php';
include_once $config['base_path'] . '/lib/variables.php';
include_once $config['base_path'] . '/lib/data_query.php';
/* fetch some cache variables */
if (empty($id)) {
$_host_template_id = 0;
} else {
$_host_template_id = db_fetch_cell_prepared('SELECT host_template_id FROM host WHERE id=?', array($id));
}
$save['id'] = form_input_validate($id, 'id', '^[0-9]+$', false, 3);
$save['host_template_id'] = form_input_validate($host_template_id, 'host_template_id', '^[0-9]+$', false, 3);
$save['description'] = form_input_validate($description, 'description', '', false, 3);
$save['hostname'] = form_input_validate(trim($hostname), 'hostname', '', false, 3);
$save['notes'] = form_input_validate($notes, 'notes', '', true, 3);
$save['snmp_version'] = form_input_validate($snmp_version, 'snmp_version', '', true, 3);
$save['snmp_community'] = form_input_validate($snmp_community, 'snmp_community', '', true, 3);
if ($save['snmp_version'] == 3) {
$save['snmp_username'] = form_input_validate($snmp_username, 'snmp_username', '', true, 3);
$save['snmp_password'] = form_input_validate($snmp_password, 'snmp_password', '', true, 3);
$save['snmp_auth_protocol'] = form_input_validate($snmp_auth_protocol, 'snmp_auth_protocol', "^\\[None\\]|MD5|SHA\$", true, 3);
$save['snmp_priv_passphrase'] = form_input_validate($snmp_priv_passphrase, 'snmp_priv_passphrase', '', true, 3);
$save['snmp_priv_protocol'] = form_input_validate($snmp_priv_protocol, 'snmp_priv_protocol', "^\\[None\\]|DES|AES128\$", true, 3);
$save['snmp_context'] = form_input_validate($snmp_context, 'snmp_context', '', true, 3);
} else {
$save['snmp_username'] = '';
$save['snmp_password'] = '';
$save['snmp_auth_protocol'] = '';
$save['snmp_priv_passphrase'] = '';
$save['snmp_priv_protocol'] = '';
$save['snmp_context'] = '';
}
$save['snmp_port'] = form_input_validate($snmp_port, 'snmp_port', '^[0-9]+$', false, 3);
$save['snmp_timeout'] = form_input_validate($snmp_timeout, 'snmp_timeout', '^[0-9]+$', false, 3);
/* disabled = 'on' => regexp '^on$'
* not disabled = '' => no regexp, but allow nulls */
$save['disabled'] = form_input_validate($disabled, 'disabled', '^on$', true, 3);
$save['availability_method'] = form_input_validate($availability_method, 'availability_method', '^[0-9]+$', false, 3);
$save['ping_method'] = form_input_validate($ping_method, 'ping_method', '^[0-9]+$', false, 3);
$save['ping_port'] = form_input_validate($ping_port, 'ping_port', '^[0-9]+$', true, 3);
$save['ping_timeout'] = form_input_validate($ping_timeout, 'ping_timeout', '^[0-9]+$', true, 3);
$save['ping_retries'] = form_input_validate($ping_retries, 'ping_retries', '^[0-9]+$', true, 3);
$save['max_oids'] = form_input_validate($max_oids, 'max_oids', '^[0-9]+$', true, 3);
$save['device_threads'] = form_input_validate($device_threads, 'device_threads', '^[0-9]+$', true, 3);
$save = api_plugin_hook_function('api_device_save', $save);
$host_id = 0;
if (!is_error_message()) {
$host_id = sql_save($save, 'host');
if ($host_id) {
raise_message(1);
/* push out relavant fields to data sources using this host */
push_out_host($host_id, 0);
/* the host substitution cache is now stale; purge it */
kill_session_var('sess_host_cache_array');
/* update title cache for graph and data source */
update_data_source_title_cache_from_host($host_id);
update_graph_title_cache_from_host($host_id);
} else {
raise_message(2);
}
/* if the user changes the host template, add each snmp query associated with it */
if ($host_template_id != $_host_template_id && !empty($host_template_id)) {
$snmp_queries = db_fetch_assoc_prepared('SELECT snmp_query_id FROM host_template_snmp_query WHERE host_template_id = ?', array($host_template_id));
if (sizeof($snmp_queries) > 0) {
foreach ($snmp_queries as $snmp_query) {
db_execute_prepared('REPLACE INTO host_snmp_query (host_id, snmp_query_id, reindex_method) VALUES (?, ?, ?)', array($host_id, $snmp_query['snmp_query_id'], read_config_option('reindex_method')));
/* recache snmp data */
run_data_query($host_id, $snmp_query['snmp_query_id']);
}
}
$graph_templates = db_fetch_assoc_prepared('SELECT graph_template_id FROM host_template_graph WHERE host_template_id = ?', array($host_template_id));
if (sizeof($graph_templates) > 0) {
foreach ($graph_templates as $graph_template) {
db_execute_prepared('REPLACE INTO host_graph (host_id, graph_template_id) VALUES (?, ?)', array($host_id, $graph_template['graph_template_id']));
api_plugin_hook_function('add_graph_template_to_host', array('host_id' => $host_id, 'graph_template_id' => $graph_template['graph_template_id']));
}
}
}
}
# now that we have the id of the new host, we may plugin postprocessing code
$save['id'] = $host_id;
snmpagent_api_device_new($save);
api_plugin_hook_function('api_device_new', $save);
return $host_id;
}
示例4: host_edit
//.........这里部分代码省略.........
$('#row_snmp_timeout').show();
$('#row_max_oids').show();
break;
}
}
$(function() {
changeHostForm();
$('#dbghide').click(function(data) {
$('#dqdebug').fadeOut('fast');
});
$.get('host.php?action=ping_host&id='+$('#id').val(), function(data) {
$('#ping_results').html(data);
});
});
-->
</script>
<?php
if (isset($_REQUEST['display_dq_details']) && isset($_SESSION['debug_log']['data_query'])) {
print "<table id='dqdebug' width='100%' class='cactiDebugTable' cellpadding='0' cellspacing='0' border='0' align='center'><tr><td>\n";
print "<table width='100%' class='cactiTableTitle' cellspacing='0' cellpadding='3' border='0'>\n";
print "<tr><td class='textHeaderDark'><a name='dqdbg'></a><strong>Data Query Debug Information</strong></td><td class='textHeaderDark' align='right'><a style='cursor:pointer;' id='dbghide' class='linkOverDark'>Hide</a></td></tr>\n";
print "</table>\n";
print "<table width='100%' class='cactiTable' cellspacing='0' cellpadding='3' border='0'>\n";
print "<tr><td class='odd'><span style='font-family: monospace;'>" . debug_log_return('data_query') . "</span></td></tr>";
print "</table>\n";
print "</table>\n";
}
if (!empty($host['id'])) {
html_start_box('<strong>Associated Graph Templates</strong>', '100%', '', '3', 'center', '');
html_header(array('Graph Template Name', 'Status'), 2);
$selected_graph_templates = db_fetch_assoc_prepared('SELECT
graph_templates.id,
graph_templates.name
FROM (graph_templates, host_graph)
WHERE graph_templates.id = host_graph.graph_template_id
AND host_graph.host_id = ?
ORDER BY graph_templates.name', array($_REQUEST['id']));
$available_graph_templates = db_fetch_assoc('SELECT
graph_templates.id, graph_templates.name
FROM snmp_query_graph RIGHT JOIN graph_templates
ON (snmp_query_graph.graph_template_id = graph_templates.id)
WHERE (((snmp_query_graph.name) Is Null)) ORDER BY graph_templates.name');
$i = 0;
if (sizeof($selected_graph_templates) > 0) {
foreach ($selected_graph_templates as $item) {
form_alternate_row('', true);
/* get status information for this graph template */
$is_being_graphed = sizeof(db_fetch_assoc_prepared('SELECT id FROM graph_local WHERE graph_template_id = ? AND host_id = ?', array($item['id'], $_REQUEST['id']))) > 0 ? true : false;
?>
<td style="padding: 4px;">
<strong><?php
print $i;
?>
)</strong> <?php
print htmlspecialchars($item['name']);
?>
</td>
<td>
<?php
print $is_being_graphed == true ? "<span style='color: green;'>Is Being Graphed</span> (<a href='" . htmlspecialchars('graphs.php?action=graph_edit&id=' . db_fetch_cell_prepared('SELECT id FROM graph_local WHERE graph_template_id = ? AND host_id = ? LIMIT 0,1', array($item['id'], $_REQUEST['id']))) . "'>Edit</a>)" : "<span style='color: #484848;'>Not Being Graphed</span>";
?>
</td>
<td align='right' nowrap>
示例5: utilities_view_snmp_cache
//.........这里部分代码省略.........
<form id="form_snmpcache" action="utilities.php">
<table cellpadding="2" cellspacing="0">
<tr>
<td width="50">
Device
</td>
<td>
<select id='host_id' name="host_id" onChange="applyFilter()">
<option value="-1"<?php
if (get_request_var_request('host_id') == '-1') {
?>
selected<?php
}
?>
>Any</option>
<option value="0"<?php
if (get_request_var_request('host_id') == '0') {
?>
selected<?php
}
?>
>None</option>
<?php
if (get_request_var_request('snmp_query_id') == -1) {
$hosts = db_fetch_assoc('SELECT DISTINCT
host.id,
host.description,
host.hostname
FROM (host_snmp_cache, snmp_query,host)
WHERE host_snmp_cache.host_id = host.id
AND host_snmp_cache.snmp_query_id = snmp_query.id
ORDER by host.description');
} else {
$hosts = db_fetch_assoc_prepared('SELECT DISTINCT
host.id,
host.description,
host.hostname
FROM (host_snmp_cache, snmp_query,host)
WHERE host_snmp_cache.host_id = host.id
AND host_snmp_cache.snmp_query_id = snmp_query.id
AND host_snmp_cache.snmp_query_id = ?
ORDER by host.description', array(get_request_var_request('snmp_query_id')));
}
if (sizeof($hosts) > 0) {
foreach ($hosts as $host) {
print "<option value='" . $host['id'] . "'";
if (get_request_var_request('host_id') == $host['id']) {
print ' selected';
}
print '>' . $host['description'] . "</option>\n";
}
}
?>
</select>
</td>
<td>
Query Name
</td>
<td>
<select id='snmp_query_id' name="snmp_query_id" onChange="applyFilter()">
<option value="-1"<?php
if (get_request_var_request('host_id') == '-1') {
?>
selected<?php
}
?>
示例6: boost_rrdtool_function_create
function boost_rrdtool_function_create($local_data_id, $initial_time, $show_source)
{
global $config;
include $config['include_path'] . '/global_arrays.php';
$data_source_path = get_data_source_path($local_data_id, true);
/* ok, if that passes lets check to make sure an rra does not already
exist, the last thing we want to do is overright data! */
if ($show_source != true) {
if (file_exists($data_source_path) == true) {
return -1;
}
}
/* the first thing we must do is make sure there is at least one
rra associated with this data source... *
UPDATE: As of version 0.6.6, we are splitting this up into two
SQL strings because of the multiple DS per RRD support. This is
not a big deal however since this function gets called once per
data source */
$rras = db_fetch_assoc_prepared('SELECT
data_template_data.rrd_step,
rra.x_files_factor,
rra.steps,
rra.rows,
rra_cf.consolidation_function_id,
(rra.rows * rra.steps) AS rra_order
FROM data_template_data
LEFT JOIN data_template_data_rra ON (data_template_data.id = data_template_data_rra.data_template_data_id)
LEFT JOIN rra ON (data_template_data_rra.rra_id = rra.id)
LEFT JOIN rra_cf ON (rra.id = rra_cf.rra_id)
WHERE data_template_data.local_data_id = ?
AND (rra.steps is not null OR rra.rows is not null)
ORDER BY rra_cf.consolidation_function_id, rra_order', array($local_data_id));
/* if we find that this DS has no RRA associated; get out. This would
* indicate that a data sources has been deleted
*/
if (sizeof($rras) <= 0) {
return false;
}
/* back off the initial time to allow updates */
$initial_time -= 300;
/* create the "--step" line */
$create_ds = RRD_NL . '--start ' . $initial_time . ' --step ' . $rras[0]['rrd_step'] . ' ' . RRD_NL;
/* query the data sources to be used in this .rrd file */
$data_sources = db_fetch_assoc_prepared('SELECT
data_template_rrd.id,
data_template_rrd.rrd_heartbeat,
data_template_rrd.rrd_minimum,
data_template_rrd.rrd_maximum,
data_template_rrd.data_source_type_id
FROM data_template_rrd
WHERE data_template_rrd.local_data_id = ?
ORDER BY local_data_template_rrd_id', array($local_data_id));
/* ONLY make a new DS entry if:
- There is multiple data sources and this item is not the main one.
- There is only one data source (then use it) */
if (sizeof($data_sources) > 0) {
foreach ($data_sources as $data_source) {
/* use the cacti ds name by default or the user defined one, if entered */
$data_source_name = get_data_source_item_name($data_source['id']);
if (empty($data_source['rrd_maximum'])) {
/* in case no maximum is given, use "Undef" value */
$data_source['rrd_maximum'] = 'U';
} elseif (strpos($data_source['rrd_maximum'], '|query_') !== false) {
$data_local = db_fetch_row_prepared('SELECT * FROM data_local WHERE id = ?', array($local_data_id));
if ($data_source['rrd_maximum'] == '|query_ifSpeed|' || $data_source['rrd_maximum'] == '|query_ifHighSpeed|') {
$highSpeed = db_fetch_cell_prepared("SELECT field_value\n\t\t\t\t\tFROM host_snmp_cache\n\t\t\t\t\tWHERE host_id = ?\n\t\t\t\t\tAND snmp_query_id = ?\n\t\t\t\t\tAND snmp_index = ?\n\t\t\t\t\tAND field_name = 'ifHighSpeed'", array($data_local['host_id'], $data_local['snmp_query_id'], $data_local['snmp_index']));
if (!empty($highSpeed)) {
$data_source['rrd_maximum'] = $highSpeed * 1000000;
} else {
$data_source['rrd_maximum'] = substitute_snmp_query_data('|query_ifSpeed|', $data_local['host_id'], $data_local['snmp_query_id'], $data_local['snmp_index']);
}
} else {
$data_source['rrd_maximum'] = substitute_snmp_query_data($data_source['rrd_maximum'], $data_local['host_id'], $data_local['snmp_query_id'], $data_local['snmp_index']);
}
} elseif ($data_source['rrd_maximum'] != 'U' && (int) $data_source['rrd_maximum'] <= (int) $data_source['rrd_minimum']) {
/* max > min required, but take care of an "Undef" value */
$data_source['rrd_maximum'] = (int) $data_source['rrd_minimum'] + 1;
}
/* min==max==0 won't work with rrdtool */
if ($data_source['rrd_minimum'] == 0 && $data_source['rrd_maximum'] == 0) {
$data_source['rrd_maximum'] = 'U';
}
$create_ds .= "DS:{$data_source_name}:" . $data_source_types[$data_source['data_source_type_id']] . ':' . $data_source['rrd_heartbeat'] . ':' . $data_source['rrd_minimum'] . ':' . $data_source['rrd_maximum'] . RRD_NL;
}
}
$create_rra = '';
/* loop through each available RRA for this DS */
foreach ($rras as $rra) {
$create_rra .= 'RRA:' . $consolidation_functions[$rra['consolidation_function_id']] . ':' . $rra['x_files_factor'] . ':' . $rra['steps'] . ':' . $rra['rows'] . RRD_NL;
}
/* check for structured path configuration, if in place verify directory
exists and if not create it.
*/
if (read_config_option('extended_paths') == 'on') {
if (!is_dir(dirname($data_source_path))) {
if (mkdir(dirname($data_source_path), 0775)) {
if ($config['cacti_server_os'] != 'win32') {
$owner_id = fileowner($config['rra_path']);
$group_id = filegroup($config['rra_path']);
if (chown(dirname($data_source_path), $owner_id) && chgrp(dirname($data_source_path), $group_id)) {
//.........这里部分代码省略.........
示例7: data_edit
function data_edit()
{
global $fields_data_input_edit;
/* ================= input validation ================= */
input_validate_input_number(get_request_var_request('id'));
/* ==================================================== */
if (!empty($_REQUEST['id'])) {
$data_input = db_fetch_row_prepared('SELECT * FROM data_input WHERE id = ?', array(get_request_var_request('id')));
$header_label = '[edit: ' . htmlspecialchars($data_input['name']) . ']';
} else {
$header_label = '[new]';
}
html_start_box("<strong>Data Input Methods</strong> {$header_label}", '100%', '', '3', 'center', '');
draw_edit_form(array('config' => array(), 'fields' => inject_form_variables($fields_data_input_edit, isset($data_input) ? $data_input : array())));
html_end_box();
if (!empty($_REQUEST['id'])) {
html_start_box('<strong>Input Fields</strong>', '100%', '', '3', 'center', 'data_input.php?action=field_edit&type=in&data_input_id=' . htmlspecialchars(get_request_var_request('id')));
print "<tr class='tableHeader'>";
DrawMatrixHeaderItem('Name', '', 1);
DrawMatrixHeaderItem('Field Order', '', 1);
DrawMatrixHeaderItem('Friendly Name', '', 2);
print '</tr>';
$fields = db_fetch_assoc_prepared("SELECT id, data_name, name, sequence FROM data_input_fields WHERE data_input_id = ? AND input_output = 'in' ORDER BY sequence, data_name", array(get_request_var_request('id')));
$i = 0;
if (sizeof($fields) > 0) {
foreach ($fields as $field) {
form_alternate_row('', true);
?>
<td>
<a class="linkEditMain" href="<?php
print htmlspecialchars('data_input.php?action=field_edit&id=' . $field['id'] . '&data_input_id=' . $_REQUEST['id']);
?>
"><?php
print htmlspecialchars($field['data_name']);
?>
</a>
</td>
<td>
<?php
print $field['sequence'];
if ($field['sequence'] == '0') {
print ' (Not In Use)';
}
?>
</td>
<td>
<?php
print htmlspecialchars($field['name']);
?>
</td>
<td align="right">
<a href="<?php
print htmlspecialchars('data_input.php?action=field_remove&id=' . $field['id'] . '&data_input_id=' . $_REQUEST['id']);
?>
"><img src="images/delete_icon.gif" style="height:10px;width:10px;" border="0" alt="Delete"></a>
</td>
</tr>
<?php
}
} else {
print '<tr><td><em>No Input Fields</em></td></tr>';
}
html_end_box();
html_start_box('<strong>Output Fields</strong>', '100%', '', '3', 'center', 'data_input.php?action=field_edit&type=out&data_input_id=' . $_REQUEST['id']);
print "<tr class='tableHeader'>";
DrawMatrixHeaderItem('Name', '', 1);
DrawMatrixHeaderItem('Field Order', '', 1);
DrawMatrixHeaderItem('Friendly Name', '', 1);
DrawMatrixHeaderItem('Update RRA', '', 2);
print '</tr>';
$fields = db_fetch_assoc_prepared("SELECT id, name, data_name, update_rra, sequence FROM data_input_fields WHERE data_input_id = ? and input_output = 'out' ORDER BY sequence, data_name", array(get_request_var_request('id')));
$i = 0;
if (sizeof($fields) > 0) {
foreach ($fields as $field) {
form_alternate_row('', true);
?>
<td>
<a class="linkEditMain" href="<?php
print htmlspecialchars('data_input.php?action=field_edit&id=' . $field['id'] . '&data_input_id=' . $_REQUEST['id']);
?>
"><?php
print htmlspecialchars($field['data_name']);
?>
</a>
</td>
<td>
<?php
print $field['sequence'];
if ($field['sequence'] == '0') {
print ' (Not In Use)';
}
?>
</td>
<td>
<?php
print htmlspecialchars($field['name']);
?>
</td>
<td>
<?php
//.........这里部分代码省略.........
示例8: secpass_login_process
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 = 'on' 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;
}
示例9: data_query_edit
function data_query_edit()
{
global $fields_data_query_edit, $config;
/* ================= input validation ================= */
input_validate_input_number(get_request_var_request('id'));
/* ==================================================== */
if (!empty($_REQUEST['id'])) {
$snmp_query = db_fetch_row_prepared('SELECT * FROM snmp_query WHERE id = ?', array($_REQUEST['id']));
$header_label = '[edit: ' . htmlspecialchars($snmp_query['name']) . ']';
} else {
$header_label = '[new]';
}
html_start_box("<strong>Data Queries</strong> {$header_label}", '100%', '', '3', 'center', '');
draw_edit_form(array('config' => array(), 'fields' => inject_form_variables($fields_data_query_edit, isset($snmp_query) ? $snmp_query : array())));
html_end_box();
if (!empty($snmp_query['id'])) {
$xml_filename = str_replace('<path_cacti>', $config['base_path'], $snmp_query['xml_path']);
if (file_exists($xml_filename) && is_file($xml_filename)) {
$text = "<font color='#0d7c09'><strong>Successfully located XML file</strong></font>";
$xml_file_exists = true;
} else {
$text = "<font class='txtErrorText'><strong>Could not locate XML file.</strong></font>";
$xml_file_exists = false;
}
html_start_box('', '100%', '', '3', 'center', '');
print "<tr class='tableRow'><td>{$text}</td></tr>";
html_end_box();
if ($xml_file_exists == true) {
html_start_box('<strong>Associated Graph Templates</strong>', '100%', '', '3', 'center', 'data_queries.php?action=item_edit&snmp_query_id=' . $snmp_query['id']);
print "<tr class='tableHeader'>\n\t\t\t\t\t<th class='textSubHeaderDark'>Name</th>\n\t\t\t\t\t<th class='textSubHeaderDark'>Graph Template Name</th>\n\t\t\t\t\t<th class='textSubHeaderDark' style='text-align:right;'>Mapping ID</th>\n\t\t\t\t\t<th width='40' style='text-align:right;'>Action</td>\n\t\t\t\t</tr>";
$snmp_query_graphs = db_fetch_assoc_prepared('SELECT
snmp_query_graph.id,
graph_templates.name AS graph_template_name,
snmp_query_graph.name
FROM snmp_query_graph
LEFT JOIN graph_templates ON (snmp_query_graph.graph_template_id = graph_templates.id)
WHERE snmp_query_graph.snmp_query_id = ?
ORDER BY snmp_query_graph.name', array($snmp_query['id']));
$i = 0;
if (sizeof($snmp_query_graphs) > 0) {
foreach ($snmp_query_graphs as $snmp_query_graph) {
form_alternate_row();
?>
<td>
<strong><a href="<?php
print htmlspecialchars('data_queries.php?action=item_edit&id=' . $snmp_query_graph['id'] . '&snmp_query_id=' . $snmp_query['id']);
?>
"><?php
print htmlspecialchars($snmp_query_graph['name']);
?>
</a></strong>
</td>
<td>
<?php
print htmlspecialchars($snmp_query_graph['graph_template_name']);
?>
</td>
<td style='text-align:right;'>
<?php
print $snmp_query_graph['id'];
?>
</td>
<td align="right">
<a href="<?php
print htmlspecialchars('data_queries.php?action=item_remove&id=' . $snmp_query_graph['id'] . '&snmp_query_id=' . $snmp_query['id']);
?>
"><img src="images/delete_icon.gif" style="height:10px;width:10px;" border="0" alt="Delete"></a>
</td>
</tr>
<?php
}
} else {
print "<tr class='tableRow'><td><em>No Graph Templates Defined.</em></td></tr>";
}
html_end_box();
}
}
form_save_button('data_queries.php', 'return');
}
示例10: mactrack_interface_actions
function mactrack_interface_actions($device_id, $ifName, $show_rescan = TRUE)
{
global $config;
$row = '';
$rescan = '';
$device = db_fetch_row_prepared('SELECT host_id, disabled FROM mac_track_devices WHERE device_id = ?', array($device_id));
if ($show_rescan) {
if (api_user_realm_auth('mactrack_sites.php')) {
if ($device['disabled'] == '') {
$rescan = "<img id='r_" . $device_id . '_' . $ifName . "' src='" . $config['url_path'] . "plugins/mactrack/images/rescan_device.gif' alt='' onMouseOver='style.cursor=\"pointer\"' onClick='scan_device_interface(" . $device_id . ",\"" . $ifName . "\")' title='Rescan Device' align='absmiddle' border='0'>";
} else {
$rescan = "<img src='" . $config['url_path'] . "plugins/mactrack/images/view_none.gif' alt='' align='absmiddle' border='0'>";
}
} else {
$rescan = "<img src='" . $config['url_path'] . "plugins/mactrack/images/view_none.gif' alt='' align='absmiddle' border='0'>";
}
}
if ($device['host_id'] != 0) {
/* get non-interface graphs */
$graphs = db_fetch_assoc_prepared('SELECT DISTINCT graph_local.id AS local_graph_id
FROM mac_track_interface_graphs
RIGHT JOIN graph_local
ON graph_local.host_id=mac_track_interface_graphs.host_id
AND graph_local.id=mac_track_interface_graphs.local_graph_id
WHERE graph_local.host_id = ?
AND mac_track_interface_graphs.device_id IS NULL', array($device['host_id']));
if (sizeof($graphs)) {
$url = $config['url_path'] . 'plugins/mactrack/mactrack_view_graphs.php?action=preview&report=graphs&style=selective&graph_list=';
$list = '';
foreach ($graphs as $graph) {
$list .= (strlen($list) ? ',' : '') . $graph['local_graph_id'];
}
$row .= "<a href='" . htmlspecialchars($url . $list . '&page=1') . "'><img src='" . $config['url_path'] . "plugins/mactrack/images/view_graphs.gif' alt='' onMouseOver='style.cursor=\"pointer\"' title='" . __('View Non Interface Graphs') . "' align='absmiddle' border='0'></a>";
} else {
$row .= "<img src='" . $config['url_path'] . "plugins/mactrack/images/view_graphs_disabled.gif' alt='' title='" . __('No Non Interface Graphs in Cacti') . "' align='absmiddle' border='0'/>";
}
/* get interface graphs */
$graphs = db_fetch_assoc_prepared('SELECT local_graph_id
FROM mac_track_interface_graphs
WHERE host_id = ? AND ifName = ?', array($device['host_id'], $ifName));
if (sizeof($graphs)) {
$url = $config['url_path'] . 'plugins/mactrack/mactrack_view_graphs.php?action=preview&report=graphs&style=selective&graph_list=';
$list = '';
foreach ($graphs as $graph) {
$list .= (strlen($list) ? ',' : '') . $graph['local_graph_id'];
}
$row .= "<a href='" . htmlspecialchars($url . $list . '&page=1') . "'><img src='" . $config['url_path'] . "plugins/mactrack/images/view_interface_graphs.gif' alt='' onMouseOver='style.cursor=\"pointer\"' title='" . __('View Interface Graphs') . "' align='absmiddle' border='0'></a>";
} else {
$row .= "<img src='" . $config['url_path'] . "plugins/mactrack/images/view_none.gif' alt='' align='absmiddle' border='0'>";
}
} else {
$row .= "<img src='" . $config['url_path'] . "plugins/mactrack/images/view_graphs_disabled.gif' alt='' title='" . __('Device Not in Cacti') . "' align='absmiddle' border='0'/>";
}
$row .= $rescan;
return $row;
}
示例11: thold_update_host_status
//.........这里部分代码省略.........
$msg = str_replace('<CUR_TIME>', round($host['cur_time'], 2), $msg);
$msg = str_replace('<AVG_TIME>', round($host['avg_time'], 2), $msg);
$msg = str_replace('<NOTES>', $host['notes'], $msg);
$msg = str_replace("\n", '<br>', $msg);
switch ($host['thold_send_email']) {
case '0':
// Disabled
$alert_email = '';
break;
case '1':
// Global List
break;
case '2':
// Devices List Only
$alert_email = get_thold_notification_emails($host['thold_host_email']);
break;
case '3':
// Global and Devices List
$alert_email = $alert_email . ',' . get_thold_notification_emails($host['thold_host_email']);
break;
}
if ($alert_email == '' && $host['thold_send_email'] > 0) {
cacti_log('Host[' . $host['id'] . '] Hostname[' . $host['hostname'] . '] WARNING: Can not send a Device recovering email for \'' . $host['description'] . '\' since the \'Alert Email\' setting is not set for Device!', true, 'THOLD');
} elseif ($host['thold_send_email'] == '0') {
cacti_log('Host[' . $host['id'] . '] Hostname[' . $host['hostname'] . '] NOTE: Did not send a Device recovering email for \'' . $host['description'] . '\', disabled per Device setting!', true, 'THOLD');
} elseif ($alert_email != '') {
thold_mail($alert_email, '', $subject, $msg, '');
}
}
}
}
}
// Lets find hosts that are down
$hosts = db_fetch_assoc_prepared('SELECT *
FROM host
WHERE disabled=""
AND status = ?
AND status_event_count = ?', array(HOST_DOWN, $ping_failure_count));
$total_hosts = sizeof($hosts);
if (count($hosts)) {
foreach ($hosts as $host) {
if (api_plugin_is_enabled('maint')) {
if (plugin_maint_check_cacti_host($host['id'])) {
continue;
}
}
$downtime = time() - strtotime($host['status_rec_date']);
$downtime_days = floor($downtime / 86400);
$downtime_hours = floor(($downtime - $downtime_days * 86400) / 3600);
$downtime_minutes = floor(($downtime - $downtime_days * 86400 - $downtime_hours * 3600) / 60);
$downtime_seconds = $downtime - $downtime_days * 86400 - $downtime_hours * 3600 - $downtime_minutes * 60;
if ($downtime_days > 0) {
$downtimemsg = $downtime_days . 'd ' . $downtime_hours . 'h ' . $downtime_minutes . 'm ' . $downtime_seconds . 's ';
} elseif ($downtime_hours > 0) {
$downtimemsg = $downtime_hours . 'h ' . $downtime_minutes . 'm ' . $downtime_seconds . 's';
} elseif ($downtime_minutes > 0) {
$downtimemsg = $downtime_minutes . 'm ' . $downtime_seconds . 's';
} else {
$downtimemsg = $downtime_seconds . 's ';
}
$subject = read_config_option('thold_down_subject');
if ($subject == '') {
$subject = __('Devices Error: <DESCRIPTION> (<HOSTNAME>) is DOWN');
}
$subject = str_replace('<HOSTNAME>', $host['hostname'], $subject);
$subject = str_replace('<DESCRIPTION>', $host['description'], $subject);
示例12: api_tree_delete_node_content
function api_tree_delete_node_content($tree_id, $branch_id)
{
$children = db_fetch_assoc_prepared("SELECT * \n\t\tFROM graph_tree_items \n\t\tWHERE graph_tree_id = ? AND parent = ?", array($tree_id, $branch_id));
if (sizeof($children)) {
foreach ($children as $child) {
if ($child['host_id'] == 0 && $child['graph_id'] == 0) {
api_tree_delete_node_content($tree_id, $child['id']);
}
db_execute_prepared("DELETE \n\t\t\tFROM graph_tree_items \n\t\t\tWHERE graph_tree_id = ?\n\t\t\tAND id = ?", array($tree_id, $child['id']));
}
}
}
示例13: header
if (basename($referer) == 'logout.php') {
$referer = $config['url_path'] . 'index.php';
}
} else {
if (isset($_SERVER['REQUEST_URI'])) {
$referer = $_SERVER['REQUEST_URI'];
if (basename($referer) == 'logout.php') {
$referer = $config['url_path'] . 'index.php';
}
} else {
$referer = $config['url_path'] . 'index.php';
}
}
if (substr_count($referer, 'plugins')) {
header('Location: ' . $referer);
} elseif (sizeof(db_fetch_assoc_prepared('SELECT realm_id FROM user_auth_realm WHERE realm_id = 8 AND user_id = ?', array($_SESSION['sess_user_id']))) == 0) {
header('Location: graph_view.php');
} else {
header("Location: {$referer}");
}
break;
case '2':
/* default console page */
header('Location: ' . $config['url_path'] . 'index.php');
break;
case '3':
/* default graph page */
header('Location: ' . $config['url_path'] . 'graph_view.php');
break;
default:
api_plugin_hook_function('login_options_navigate', $user['login_opts']);
示例14: ds_edit
function ds_edit()
{
global $struct_data_source, $struct_data_source_item, $data_source_types;
/* ================= input validation ================= */
input_validate_input_number(get_request_var_request('id'));
input_validate_input_number(get_request_var_request('host_id'));
/* ==================================================== */
api_plugin_hook('data_source_edit_top');
$use_data_template = true;
$host_id = 0;
if (!empty($_REQUEST['id'])) {
$data_local = db_fetch_row_prepared('SELECT host_id, data_template_id FROM data_local WHERE id = ?', array($_REQUEST['id']));
$data = db_fetch_row_prepared('SELECT * FROM data_template_data WHERE local_data_id = ?', array($_REQUEST['id']));
if (isset($data_local['data_template_id']) && $data_local['data_template_id'] >= 0) {
$data_template = db_fetch_row_prepared('SELECT id, name FROM data_template WHERE id = ?', array($data_local['data_template_id']));
$data_template_data = db_fetch_row_prepared('SELECT * FROM data_template_data WHERE data_template_id = ? AND local_data_id = 0', array($data_local['data_template_id']));
} else {
$_SESSION['sess_messages'] = 'Data Source "' . $_REQUEST['id'] . '" does not exist.';
header('Location: data_sources.php');
exit;
}
$header_label = '[edit: ' . htmlspecialchars(get_data_source_title($_REQUEST['id'])) . ']';
if (empty($data_local['data_template_id'])) {
$use_data_template = false;
}
} else {
$header_label = '[new]';
$use_data_template = false;
}
/* handle debug mode */
if (isset($_REQUEST['debug'])) {
if ($_REQUEST['debug'] == '0') {
kill_session_var('ds_debug_mode');
} elseif ($_REQUEST['debug'] == '1') {
$_SESSION['ds_debug_mode'] = true;
}
}
top_header();
if (!empty($_REQUEST['id'])) {
?>
<table width='100%' align='center'>
<tr>
<td class='textInfo' colspan='2' valign='top'>
<?php
print htmlspecialchars(get_data_source_title($_REQUEST['id']));
?>
</td>
<td class='textInfo' align='right' valign='top'>
<span class='linkMarker'>*<a href='<?php
print htmlspecialchars('data_sources.php?action=ds_edit&id=' . (isset($_REQUEST['id']) ? $_REQUEST['id'] : '0'));
?>
&debug=<?php
print isset($_SESSION['ds_debug_mode']) ? '0' : '1';
?>
'>Turn <strong><?php
print isset($_SESSION['ds_debug_mode']) ? 'Off' : 'On';
?>
</strong> Data Source Debug Mode.</a><br>
<?php
if (!empty($data_template['id'])) {
?>
<span class='linkMarker'>*<a href='<?php
print htmlspecialchars('data_templates.php?action=template_edit&id=' . (isset($data_template['id']) ? $data_template['id'] : '0'));
?>
'>Edit Data Template.</a><br><?php
}
if (!empty($_REQUEST['host_id']) || !empty($data_local['host_id'])) {
?>
<span class='linkMarker'>*<a href='<?php
print htmlspecialchars('host.php?action=edit&id=' . (isset($_REQUEST['host_id']) ? $_REQUEST['host_id'] : $data_local['host_id']));
?>
'>Edit Device.</a><br><?php
}
?>
</td>
</tr>
</table>
<br>
<?php
}
html_start_box("<strong>Data Template Selection</strong> {$header_label}", '100%', '', '3', 'center', '');
$form_array = array('data_template_id' => array('method' => 'drop_sql', 'friendly_name' => 'Selected Data Template', 'description' => 'The name given to this data template.', 'value' => isset($data_template) ? $data_template['id'] : '0', 'none_value' => 'None', 'sql' => 'SELECT id,name FROM data_template order by name'), 'host_id' => array('method' => 'drop_sql', 'friendly_name' => 'Device', 'description' => 'Choose the host that this graph belongs to.', 'value' => isset($_REQUEST['host_id']) ? $_REQUEST['host_id'] : $data_local['host_id'], 'none_value' => 'None', 'sql' => "SELECT id,CONCAT_WS('',description,' (',hostname,')') as name FROM host order by description,hostname"), '_data_template_id' => array('method' => 'hidden', 'value' => isset($data_template) ? $data_template['id'] : '0'), '_host_id' => array('method' => 'hidden', 'value' => empty($data_local['host_id']) ? isset($_REQUEST['host_id']) ? $_REQUEST['host_id'] : '0' : $data_local['host_id']), '_data_input_id' => array('method' => 'hidden', 'value' => isset($data['data_input_id']) ? $data['data_input_id'] : '0'), 'data_template_data_id' => array('method' => 'hidden', 'value' => isset($data) ? $data['id'] : '0'), 'local_data_template_data_id' => array('method' => 'hidden', 'value' => isset($data) ? $data['local_data_template_data_id'] : '0'), 'local_data_id' => array('method' => 'hidden', 'value' => isset($data) ? $data['local_data_id'] : '0'));
draw_edit_form(array('config' => array(), 'fields' => $form_array));
html_end_box();
/* only display the "inputs" area if we are using a data template for this data source */
if (!empty($data['data_template_id'])) {
$template_data_rrds = db_fetch_assoc_prepared('SELECT * FROM data_template_rrd WHERE local_data_id = ? ORDER BY data_source_name', array($_REQUEST['id']));
html_start_box('<strong>Supplemental Data Template Data</strong>', '100%', '', '3', 'center', '');
draw_nontemplated_fields_data_source($data['data_template_id'], $data['local_data_id'], $data, '|field|', '<strong>Data Source Fields</strong>', true, true, 0);
draw_nontemplated_fields_data_source_item($data['data_template_id'], $template_data_rrds, '|field|_|id|', '<strong>Data Source Item Fields</strong>', true, true, true, 0);
draw_nontemplated_fields_custom_data($data['id'], 'value_|id|', '<strong>Custom Data</strong>', true, true, 0);
form_hidden_box('save_component_data', '1', '');
html_end_box();
}
if ((isset($_REQUEST['id']) || isset($_REQUEST['new'])) && empty($data['data_template_id'])) {
html_start_box('<strong>Data Source</strong>', '100%', '', '3', 'center', '');
$form_array = array();
while (list($field_name, $field_array) = each($struct_data_source)) {
$form_array += array($field_name => $struct_data_source[$field_name]);
if (!($use_data_template == false || !empty($data_template_data['t_' . $field_name]) || $field_array['flags'] == 'NOTEMPLATE')) {
//.........这里部分代码省略.........
示例15: remove_files
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');
}