From 02f145af22132f6d48135226e184486f2c5e9d47 Mon Sep 17 00:00:00 2001 From: patrick Date: Sat, 22 Apr 2017 00:10:02 +0200 Subject: [PATCH 01/20] Optimisations for lib/data_query.php --- lib/data_query.php | 83 +++++++++++++++++++++++----------------------- 1 file changed, 41 insertions(+), 42 deletions(-) diff --git a/lib/data_query.php b/lib/data_query.php index cfb7b48997..a3dff3912d 100644 --- a/lib/data_query.php +++ b/lib/data_query.php @@ -26,14 +26,14 @@ function run_data_query($host_id, $snmp_query_id) { global $config, $input_types; /* don't run/rerun the query if the host is down, or disabled */ - $status = db_fetch_row_prepared('SELECT status, disabled FROM host WHERE id = ?', array($host_id)); + $status = db_fetch_row_prepared('SELECT status, disabled, poller_id FROM host WHERE id = ?', array($host_id)); if (!sizeof($status)) { return false; - }elseif ($status['status'] == HOST_DOWN || $status['disabled'] == 'on') { + } elseif ($status['status'] == HOST_DOWN || $status['disabled'] == 'on') { return true; } - $poller_id = db_fetch_cell_prepared('SELECT poller_id FROM host WHERE id = ?', array($host_id)); + $poller_id = $status['poller_id']; if ($poller_id != $config['poller_id']) { $hostname = db_fetch_cell_prepared('SELECT hostname FROM poller WHERE id = ?', array($poller_id)); @@ -70,7 +70,9 @@ function run_data_query($host_id, $snmp_query_id) { ON snmp_query.data_input_id=data_input.id WHERE snmp_query.id = ?', array($snmp_query_id)); - if (isset($input_types[$type_id])) query_debug_timer_offset('data_query', "Found type = '" . $type_id . "' [" . $input_types[$type_id] . "]."); + if (isset($input_types[$type_id])) { + query_debug_timer_offset('data_query', "Found type = '" . $type_id . "' [" . $input_types[$type_id] . "]."); + } if ($type_id == DATA_INPUT_TYPE_SNMP_QUERY) { $result = query_snmp_host($host_id, $snmp_query_id); @@ -105,22 +107,20 @@ function run_data_query($host_id, $snmp_query_id) { dl.snmp_index, dtd.local_data_id, dtd.data_input_id, did.data_template_data_id, did.data_input_field_id, did.value FROM data_local AS dl - LEFT JOIN data_template_data AS dtd - ON dl.id=dtd.local_data_id - LEFT JOIN data_input_fields AS dif - ON dtd.data_input_id = dif.data_input_id - LEFT JOIN data_input_data AS did - ON dtd.id = did.data_template_data_id - AND dif.id = did.data_input_field_id - WHERE dif.type_code="output_type" + INNER JOIN data_template_data AS dtd ON dl.id = dtd.local_data_id + INNER JOIN data_input_fields AS dif ON dtd.data_input_id = dif.data_input_id + LEFT JOIN data_input_data AS did ON dtd.id = did.data_template_data_id + AND dif.id = did.data_input_field_id + WHERE dif.type_code = "output_type" AND dl.snmp_query_id = ? AND dl.host_id = ?', array($host_id, $snmp_query_id)); + $bestDataQueryIndexType = get_best_data_query_index_type($host_id, $snmp_query_id); if (sizeof($data_queries)) { foreach($data_queries as $data_query) { /* build array required for function call */ - $data_query['snmp_index_on'] = get_best_data_query_index_type($host_id, $snmp_query_id); + $data_query['snmp_index_on'] = $bestDataQueryIndexType; /* as we request the output_type, 'value' gives the snmp_query_graph_id */ $data_query['snmp_query_graph_id'] = $data_query['value']; @@ -1051,7 +1051,9 @@ function update_data_source_data_query_cache($local_data_id, $host_id = '', $dat FROM data_template_data WHERE data_template_data.local_data_id = ?', array($local_data_id))); - if (empty($field)) { return; } + if (empty($field)) { + return; + } if (empty($data_query_id)) { $data_query_id = db_fetch_cell_prepared('SELECT snmp_query_id FROM snmp_query_graph WHERE id = ?', array($field['output_type'])); @@ -1202,7 +1204,8 @@ function get_ordered_index_type_list($host_id, $data_query_id, $data_query_index FROM host_snmp_cache WHERE host_id = ? AND snmp_query_id = ? - AND field_name = ? AND $sql_or", + AND field_name = ? + AND $sql_or", array($host_id, $data_query_id, $field_name)); } @@ -1375,18 +1378,16 @@ function verify_index_order($raw_xml) { */ function update_snmp_index_order($data_query) { if (sizeof($data_query)) { - $data_input_field = array_rekey(db_fetch_assoc_prepared('SELECT + $data_input_field = array_rekey(db_fetch_assoc_prepared("SELECT data_input_fields.id, - data_input_fields.type_code - FROM (snmp_query,data_input,data_input_fields) - WHERE snmp_query.data_input_id=data_input.id - AND data_input.id=data_input_fields.data_input_id - AND (data_input_fields.type_code="index_type" - OR data_input_fields.type_code="index_value" - OR data_input_fields.type_code="output_type") - AND snmp_query.id = ?', + data_input_fields.type_code + FROM snmp_query + INNER JOIN data_input ON snmp_query.data_input_id = data_input.id + INNER JOIN data_input_fields ON data_input.id = data_input_fields.data_input_id + WHERE data_input_fields.type_code IN('index_type', 'index_value', 'output_type') + AND snmp_query.id = ?", array($data_query['snmp_query_id'])), 'type_code', 'id'); - + $snmp_cache_value = db_fetch_cell_prepared('SELECT field_value FROM host_snmp_cache WHERE host_id = ? @@ -1394,25 +1395,23 @@ function update_snmp_index_order($data_query) { AND field_name = ? AND snmp_index = ?', array($data_query['host_id'], $data_query['snmp_query_id'], $data_query['snmp_index_on'], $data_query['snmp_index'])); - - /* save the value to index on (ie. ifindex, ifip, etc) */ + db_execute_prepared('REPLACE INTO data_input_data (data_input_field_id, data_template_data_id, t_value, value) - VALUES (?, ?, "", ?)', - array($data_input_field['index_type'], $data_query['data_template_data_id'], $data_query['snmp_index_on'])); - - /* save the actual value (ie. 3, 192.168.1.101, etc) */ - db_execute_prepared('REPLACE INTO data_input_data - (data_input_field_id,data_template_data_id,t_value,value) - VALUES (?, ?, "", ?)', - array($data_input_field['index_value'], $data_query['data_template_data_id'], $snmp_cache_value)); - - /* set the expected output type (ie. bytes, errors, packets) */ - db_execute_prepared('REPLACE INTO data_input_data - (data_input_field_id,data_template_data_id,t_value,value) - VALUES (?, ?, "", ?)', - array($data_input_field['output_type'], $data_query['data_template_data_id'], $data_query['snmp_query_graph_id'])); - + VALUES + (?, ?, "", ?), + (?, ?, "", ?), + (?, ?, "", ?)', + array( + /* save the value to index on (ie. ifindex, ifip, etc) */ + $data_input_field['index_type'], $data_query['data_template_data_id'], $data_query['snmp_index_on'], + /* save the actual value (ie. 3, 192.168.1.101, etc) */ + $data_input_field['index_value'], $data_query['data_template_data_id'], $snmp_cache_value, + /* set the expected output type (ie. bytes, errors, packets) */ + $data_input_field['output_type'], $data_query['data_template_data_id'], $data_query['snmp_query_graph_id'] + ) + ); + /* now that we have put data into the 'data_input_data' table, update the snmp cache for ds's */ update_data_source_data_query_cache($data_query['local_data_id']); } From 7672f93e0f31f8c9e1c32b1bedbb6184ff6a1d11 Mon Sep 17 00:00:00 2001 From: patrick Date: Sat, 22 Apr 2017 00:11:19 +0200 Subject: [PATCH 02/20] Optimisations for lib/utility.php - Fixed some alignment - Query refactor in push_out_data_input_method() --- lib/utility.php | 145 ++++++++++++++++++++++++------------------------ 1 file changed, 73 insertions(+), 72 deletions(-) diff --git a/lib/utility.php b/lib/utility.php index f81f1632c1..99eb46fc21 100644 --- a/lib/utility.php +++ b/lib/utility.php @@ -318,12 +318,12 @@ function update_poller_cache($data_source, $commit = false) { if (sizeof($host_fields)) { if (sizeof($data_template_fields)) { - foreach($data_template_fields as $key => $value) { - if (!isset($host_fields[$key])) { - $host_fields[$key] = $value; + foreach($data_template_fields as $key => $value) { + if (!isset($host_fields[$key])) { + $host_fields[$key] = $value; + } } } - } } elseif (sizeof($data_template_fields)) { $host_fields = $data_template_fields; } @@ -380,13 +380,14 @@ function update_poller_cache($data_source, $commit = false) { } function push_out_data_input_method($data_input_id) { - $data_sources = db_fetch_assoc_prepared('SELECT ' . SQL_NO_CACHE . ' * FROM data_local - WHERE id IN ( + $data_sources = db_fetch_assoc_prepared('SELECT ' . SQL_NO_CACHE . ' * + FROM data_local + INNER JOIN ( SELECT DISTINCT local_data_id FROM data_template_data WHERE data_input_id = ? - AND local_data_id>0 - )', array($data_input_id)); + AND local_data_id > 0 + ) AS data_template_data ON data_template_data.local_data_id = data_local.id', array($data_input_id)); $poller_items = array(); $_my_local_data_ids = array(); @@ -456,30 +457,30 @@ function poller_update_poller_cache_from_buffer($local_data_ids, &$poller_items) $buffer = ''; if (sizeof($poller_items)) { - foreach($poller_items AS $record) { - /* take care of invalid entries */ - if (strlen($record) == 0) continue; + foreach($poller_items AS $record) { + /* take care of invalid entries */ + if (strlen($record) == 0) continue; - if ($buf_count == 0) { - $delim = ' '; - } else { - $delim = ', '; + if ($buf_count == 0) { + $delim = ' '; + } else { + $delim = ', '; + } + + $buffer .= $delim . $record; + + $buf_len += strlen($record); + + if (($overhead + $buf_len) > ($max_packet - 1024)) { + db_execute($sql_prefix . $buffer . $sql_suffix); + + $buffer = ''; + $buf_len = 0; + $buf_count = 0; + } else { + $buf_count++; + } } - - $buffer .= $delim . $record; - - $buf_len += strlen($record); - - if (($overhead + $buf_len) > ($max_packet - 1024)) { - db_execute($sql_prefix . $buffer . $sql_suffix); - - $buffer = ''; - $buf_len = 0; - $buf_count = 0; - } else { - $buf_count++; - } - } } if ($buf_count > 0) { @@ -538,54 +539,54 @@ function push_out_host($host_id, $local_data_id = 0, $data_template_id = 0) { /* loop through each matching data source */ if (sizeof($data_sources)) { - foreach ($data_sources as $data_source) { - /* set the host information */ - if (!isset($hosts[$data_source['host_id']])) { - $hosts[$data_source['host_id']] = db_fetch_row_prepared('SELECT * FROM host WHERE id = ?', array($data_source['host_id'])); - } - $host = $hosts[$data_source['host_id']]; + foreach ($data_sources as $data_source) { + /* set the host information */ + if (!isset($hosts[$data_source['host_id']])) { + $hosts[$data_source['host_id']] = db_fetch_row_prepared('SELECT * FROM host WHERE id = ?', array($data_source['host_id'])); + } + $host = $hosts[$data_source['host_id']]; - /* get field information FROM the data template */ - if (!isset($template_fields{$data_source['local_data_template_data_id']})) { - $template_fields{$data_source['local_data_template_data_id']} = db_fetch_assoc_prepared('SELECT ' . SQL_NO_CACHE . ' - did.value, did.t_value, dif.id, dif.type_code - FROM data_input_fields AS dif - LEFT JOIN data_input_data AS did - ON dif.id=did.data_input_field_id - WHERE dif.data_input_id = ? - AND did.data_template_data_id = ? - AND (did.t_value="" OR did.t_value is null) - AND dif.input_output="in"', - array($data_source['data_input_id'], $data_source['local_data_template_data_id'])); - } + /* get field information FROM the data template */ + if (!isset($template_fields{$data_source['local_data_template_data_id']})) { + $template_fields{$data_source['local_data_template_data_id']} = db_fetch_assoc_prepared('SELECT ' . SQL_NO_CACHE . ' + did.value, did.t_value, dif.id, dif.type_code + FROM data_input_fields AS dif + LEFT JOIN data_input_data AS did + ON dif.id=did.data_input_field_id + WHERE dif.data_input_id = ? + AND did.data_template_data_id = ? + AND (did.t_value="" OR did.t_value is null) + AND dif.input_output="in"', + array($data_source['data_input_id'], $data_source['local_data_template_data_id'])); + } - /* loop through each field contained in the data template and push out a host value if: - - the field is a valid "host field" - - the value of the field is empty - - the field is set to 'templated' */ - if (sizeof($template_fields{$data_source['local_data_template_data_id']})) { - foreach ($template_fields[$data_source['local_data_template_data_id']] as $template_field) { - if ((preg_match('/^' . VALID_HOST_FIELDS . '$/i', $template_field['type_code'])) && ($template_field['value'] == '') && ($template_field['t_value'] == '')) { - // handle special case type_code - if ($template_field['type_code'] == 'host_id') $template_field['type_code'] = 'id'; + /* loop through each field contained in the data template and push out a host value if: + - the field is a valid "host field" + - the value of the field is empty + - the field is set to 'templated' */ + if (sizeof($template_fields{$data_source['local_data_template_data_id']})) { + foreach ($template_fields[$data_source['local_data_template_data_id']] as $template_field) { + if ((preg_match('/^' . VALID_HOST_FIELDS . '$/i', $template_field['type_code'])) && ($template_field['value'] == '') && ($template_field['t_value'] == '')) { + // handle special case type_code + if ($template_field['type_code'] == 'host_id') $template_field['type_code'] = 'id'; - db_execute_prepared('REPLACE INTO data_input_data - (data_input_field_id, data_template_data_id, value) - VALUES (?, ?, ?)', - array($template_field['id'], $data_source['id'], $host[$template_field['type_code']])); + db_execute_prepared('REPLACE INTO data_input_data + (data_input_field_id, data_template_data_id, value) + VALUES (?, ?, ?)', + array($template_field['id'], $data_source['id'], $host[$template_field['type_code']])); + } } } + + /* flag an update to the poller cache as well */ + $local_data_ids[] = $data_source['local_data_id']; + + /* create a new compatible structure */ + $data = $data_source; + $data['id'] = $data['local_data_id']; + + $poller_items = array_merge($poller_items, update_poller_cache($data)); } - - /* flag an update to the poller cache as well */ - $local_data_ids[] = $data_source['local_data_id']; - - /* create a new compatible structure */ - $data = $data_source; - $data['id'] = $data['local_data_id']; - - $poller_items = array_merge($poller_items, update_poller_cache($data)); - } } if (sizeof($local_data_ids)) { From bad78eb1e06835a86b48125b1b2ceb9b0b279037 Mon Sep 17 00:00:00 2001 From: patrick Date: Sat, 22 Apr 2017 00:12:12 +0200 Subject: [PATCH 03/20] Optimisations for lib/variables.php - Multiple str_replace() calls combined to one --- lib/variables.php | 99 ++++++++++++++++++++++++++++++++--------------- 1 file changed, 68 insertions(+), 31 deletions(-) diff --git a/lib/variables.php b/lib/variables.php index 10cb4a00ca..3720d9bfc8 100644 --- a/lib/variables.php +++ b/lib/variables.php @@ -168,45 +168,82 @@ function substitute_host_data($string, $l_escape_string, $r_escape_string, $host $_SESSION['sess_host_cache_array'][$host_id] = $host; } - $string = str_replace($l_escape_string . 'host_management_ip' . $r_escape_string, $_SESSION['sess_host_cache_array'][$host_id]['hostname'], $string); /* for compatability */ - $string = str_replace($l_escape_string . 'host_hostname' . $r_escape_string, $_SESSION['sess_host_cache_array'][$host_id]['hostname'], $string); - $string = str_replace($l_escape_string . 'host_description' . $r_escape_string, $_SESSION['sess_host_cache_array'][$host_id]['description'], $string); - $string = str_replace($l_escape_string . 'host_notes' . $r_escape_string, $_SESSION['sess_host_cache_array'][$host_id]['notes'], $string); - $string = str_replace($l_escape_string . 'host_polling_time' . $r_escape_string, $_SESSION['sess_host_cache_array'][$host_id]['polling_time'], $string); - $string = str_replace($l_escape_string . 'host_avg_time' . $r_escape_string, $_SESSION['sess_host_cache_array'][$host_id]['avg_time'], $string); - $string = str_replace($l_escape_string . 'host_cur_time' . $r_escape_string, $_SESSION['sess_host_cache_array'][$host_id]['cur_time'], $string); - $string = str_replace($l_escape_string . 'host_availability' . $r_escape_string, $_SESSION['sess_host_cache_array'][$host_id]['availability'], $string); + $search = array(); + $replace = array(); + + $search[] = $l_escape_string . 'host_management_ip' . $r_escape_string; /* for compatibility */ + $replace[] = $_SESSION['sess_host_cache_array'][$host_id]['hostname']; /* for compatibility */ + + $search[] = $l_escape_string . 'host_hostname' . $r_escape_string; + $replace[] = $_SESSION['sess_host_cache_array'][$host_id]['hostname']; + $search[] = $l_escape_string . 'host_description' . $r_escape_string; + $replace[] = $_SESSION['sess_host_cache_array'][$host_id]['description']; + $search[] = $l_escape_string . 'host_notes' . $r_escape_string; + $replace[] = $_SESSION['sess_host_cache_array'][$host_id]['notes']; + $search[] = $l_escape_string . 'host_polling_time' . $r_escape_string; + $replace[] = $_SESSION['sess_host_cache_array'][$host_id]['polling_time']; + $search[] = $l_escape_string . 'host_avg_time' . $r_escape_string; + $replace[] = $_SESSION['sess_host_cache_array'][$host_id]['avg_time']; + $search[] = $l_escape_string . 'host_cur_time' . $r_escape_string; + $replace[] = $_SESSION['sess_host_cache_array'][$host_id]['cur_time']; + $search[] = $l_escape_string . 'host_availability' . $r_escape_string; + $replace[] = $_SESSION['sess_host_cache_array'][$host_id]['availability']; /* snmp connectivity information */ - $string = str_replace($l_escape_string . 'host_snmp_community' . $r_escape_string, $_SESSION['sess_host_cache_array'][$host_id]['snmp_community'], $string); - $string = str_replace($l_escape_string . 'host_snmp_version' . $r_escape_string, $_SESSION['sess_host_cache_array'][$host_id]['snmp_version'], $string); - $string = str_replace($l_escape_string . 'host_snmp_username' . $r_escape_string, $_SESSION['sess_host_cache_array'][$host_id]['snmp_username'], $string); - $string = str_replace($l_escape_string . 'host_snmp_password' . $r_escape_string, $_SESSION['sess_host_cache_array'][$host_id]['snmp_password'], $string); - $string = str_replace($l_escape_string . 'host_snmp_auth_protocol' . $r_escape_string, $_SESSION['sess_host_cache_array'][$host_id]['snmp_auth_protocol'], $string); - $string = str_replace($l_escape_string . 'host_snmp_priv_passphrase' . $r_escape_string, $_SESSION['sess_host_cache_array'][$host_id]['snmp_priv_passphrase'], $string); - $string = str_replace($l_escape_string . 'host_snmp_priv_protocol' . $r_escape_string, $_SESSION['sess_host_cache_array'][$host_id]['snmp_priv_protocol'], $string); - $string = str_replace($l_escape_string . 'host_snmp_context' . $r_escape_string, $_SESSION['sess_host_cache_array'][$host_id]['snmp_context'], $string); - $string = str_replace($l_escape_string . 'host_snmp_engine_id' . $r_escape_string, $_SESSION['sess_host_cache_array'][$host_id]['snmp_engine_id'], $string); - $string = str_replace($l_escape_string . 'host_snmp_port' . $r_escape_string, $_SESSION['sess_host_cache_array'][$host_id]['snmp_port'], $string); - $string = str_replace($l_escape_string . 'host_snmp_timeout' . $r_escape_string, $_SESSION['sess_host_cache_array'][$host_id]['snmp_timeout'], $string); + $search[] = $l_escape_string . 'host_snmp_community' . $r_escape_string; + $replace[] = $_SESSION['sess_host_cache_array'][$host_id]['snmp_community']; + $search[] = $l_escape_string . 'host_snmp_version' . $r_escape_string; + $replace[] = $_SESSION['sess_host_cache_array'][$host_id]['snmp_version']; + $search[] = $l_escape_string . 'host_snmp_username' . $r_escape_string; + $replace[] = $_SESSION['sess_host_cache_array'][$host_id]['snmp_username']; + $search[] = $l_escape_string . 'host_snmp_password' . $r_escape_string; + $replace[] = $_SESSION['sess_host_cache_array'][$host_id]['snmp_password']; + $search[] = $l_escape_string . 'host_snmp_auth_protocol' . $r_escape_string; + $replace[] = $_SESSION['sess_host_cache_array'][$host_id]['snmp_auth_protocol']; + $search[] = $l_escape_string . 'host_snmp_priv_passphrase' . $r_escape_string; + $replace[] = $_SESSION['sess_host_cache_array'][$host_id]['snmp_priv_passphrase']; + $search[] = $l_escape_string . 'host_snmp_priv_protocol' . $r_escape_string; + $replace[] = $_SESSION['sess_host_cache_array'][$host_id]['snmp_priv_protocol']; + $search[] = $l_escape_string . 'host_snmp_context' . $r_escape_string; + $replace[] = $_SESSION['sess_host_cache_array'][$host_id]['snmp_context']; + $search[] = $l_escape_string . 'host_snmp_engine_id' . $r_escape_string; + $replace[] = $_SESSION['sess_host_cache_array'][$host_id]['snmp_engine_id']; + $search[] = $l_escape_string . 'host_snmp_port' . $r_escape_string; + $replace[] = $_SESSION['sess_host_cache_array'][$host_id]['snmp_port']; + $search[] = $l_escape_string . 'host_snmp_timeout' . $r_escape_string; + $replace[] = $_SESSION['sess_host_cache_array'][$host_id]['snmp_timeout']; /* snmp system information */ - $string = str_replace($l_escape_string . 'host_snmp_sysDescr' . $r_escape_string, $_SESSION['sess_host_cache_array'][$host_id]['snmp_sysDescr'], $string); - $string = str_replace($l_escape_string . 'host_snmp_sysObjectID' . $r_escape_string, $_SESSION['sess_host_cache_array'][$host_id]['snmp_sysObjectID'], $string); - $string = str_replace($l_escape_string . 'host_snmp_sysContact' . $r_escape_string, $_SESSION['sess_host_cache_array'][$host_id]['snmp_sysContact'], $string); - $string = str_replace($l_escape_string . 'host_snmp_sysLocation' . $r_escape_string, $_SESSION['sess_host_cache_array'][$host_id]['snmp_sysLocation'], $string); - $string = str_replace($l_escape_string . 'host_snmp_sysName' . $r_escape_string, $_SESSION['sess_host_cache_array'][$host_id]['snmp_sysName'], $string); - $string = str_replace($l_escape_string . 'host_snmp_sysUpTimeInstance' . $r_escape_string, $_SESSION['sess_host_cache_array'][$host_id]['snmp_sysUpTimeInstance'], $string); + $search[] = $l_escape_string . 'host_snmp_sysDescr' . $r_escape_string; + $replace[] = $_SESSION['sess_host_cache_array'][$host_id]['snmp_sysDescr']; + $search[] = $l_escape_string . 'host_snmp_sysObjectID' . $r_escape_string; + $replace[] = $_SESSION['sess_host_cache_array'][$host_id]['snmp_sysObjectID']; + $search[] = $l_escape_string . 'host_snmp_sysContact' . $r_escape_string; + $replace[] = $_SESSION['sess_host_cache_array'][$host_id]['snmp_sysContact']; + $search[] = $l_escape_string . 'host_snmp_sysLocation' . $r_escape_string; + $replace[] = $_SESSION['sess_host_cache_array'][$host_id]['snmp_sysLocation']; + $search[] = $l_escape_string . 'host_snmp_sysName' . $r_escape_string; + $replace[] = $_SESSION['sess_host_cache_array'][$host_id]['snmp_sysName']; + $search[] = $l_escape_string . 'host_snmp_sysUpTimeInstance' . $r_escape_string; + $replace[] = $_SESSION['sess_host_cache_array'][$host_id]['snmp_sysUpTimeInstance']; - $string = str_replace($l_escape_string . 'host_ping_retries' . $r_escape_string, $_SESSION['sess_host_cache_array'][$host_id]['ping_retries'], $string); - $string = str_replace($l_escape_string . 'host_max_oids' . $r_escape_string, $_SESSION['sess_host_cache_array'][$host_id]['max_oids'], $string); - $string = str_replace($l_escape_string . 'host_id' . $r_escape_string, $_SESSION['sess_host_cache_array'][$host_id]['id'], $string); + $search[] = $l_escape_string . 'host_ping_retries' . $r_escape_string; + $replace[] = $_SESSION['sess_host_cache_array'][$host_id]['ping_retries']; + $search[] = $l_escape_string . 'host_max_oids' . $r_escape_string; + $replace[] = $_SESSION['sess_host_cache_array'][$host_id]['max_oids']; + $search[] = $l_escape_string . 'host_id' . $r_escape_string; + $replace[] = $_SESSION['sess_host_cache_array'][$host_id]['id']; /* handle the external id */ - $string = str_replace($l_escape_string . 'host_external_id' . $r_escape_string, $_SESSION['sess_host_cache_array'][$host_id]['external_id'], $string); + $search[] = $l_escape_string . 'host_external_id' . $r_escape_string; + $replace[] = $_SESSION['sess_host_cache_array'][$host_id]['external_id']; - $temp = api_plugin_hook_function('substitute_host_data', - array('string' => $string, 'l_escape_string' => $l_escape_string, 'r_escape_string' => $r_escape_string, 'host_id' => $host_id)); + $string = str_replace($search, $replace, $string); + + $temp = api_plugin_hook_function( + 'substitute_host_data', + array('string' => $string, 'l_escape_string' => $l_escape_string, 'r_escape_string' => $r_escape_string, 'host_id' => $host_id) + ); $string = $temp['string']; } From a7623d12a22dbae1ed5b3ab248c76475a87fcddb Mon Sep 17 00:00:00 2001 From: patrick Date: Sat, 22 Apr 2017 15:13:40 +0200 Subject: [PATCH 04/20] Restoring db_add_index() --- lib/database.php | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/lib/database.php b/lib/database.php index a9a356764c..0ef4918d42 100644 --- a/lib/database.php +++ b/lib/database.php @@ -505,6 +505,27 @@ function db_remove_column($table, $column, $log = true, $db_conn = false) { return true; } +/* db_add_index - adds a new index to a table + @param $table - the name of the table + @param $type - the type of the index + @param $key - the name of the index + @param $columns - an array that defines the columns to include in the index + @returns - (bool) the result of the operation true or false */ +function db_add_index($table, $type, $key, $columns) { + if (!is_array($columns)) { + $columns = array($columns); + } + + $sql = 'ALTER TABLE `' . $table . '` ADD ' . $type . ' `' . $key . '`(`' . implode('`,`', $columns) . '`)'; + + if (db_index_exists($table, $key, false)) { + $type = str_ireplace('UNIQUE ', '', $type); + db_execute("ALTER TABLE $table DROP $type $key"); + } + + return db_execute($sql); +} + /* db_index_exists - checks whether an index exists @param $table - the name of the table @param $index - the name of the index From 05741794dc601df77dcb113f320f8c92e8cbedb6 Mon Sep 17 00:00:00 2001 From: patrick Date: Tue, 25 Apr 2017 21:29:01 +0200 Subject: [PATCH 05/20] -issue: List for creating a Graph type shows already added Graph Templates --- docs/CHANGELOG | 1 + graphs_new.php | 44 ++++++++++++++++++++++++-------------------- 2 files changed, 25 insertions(+), 20 deletions(-) diff --git a/docs/CHANGELOG b/docs/CHANGELOG index 15024a4fc3..4d33bc6282 100644 --- a/docs/CHANGELOG +++ b/docs/CHANGELOG @@ -13,6 +13,7 @@ Cacti CHANGELOG -issue#613: Network Automation, now requires a site or your are unable to save rules -issue#615: Data Input field length too short for longer scripts -issue#619: Export logging option in settings no longer used +-issue: List for creating a Graph type shows already added Graph Templates 1.1.4 -issue#524: Reporting not working when Tree branch is device diff --git a/graphs_new.php b/graphs_new.php index d5f830227b..11917bdb62 100644 --- a/graphs_new.php +++ b/graphs_new.php @@ -535,9 +535,9 @@ function graphs() { array($host['id'])); if (sizeof($snmp_queries) > 0) { - foreach ($snmp_queries as $query) { - print "\n"; - } + foreach ($snmp_queries as $query) { + print "\n"; + } } ?> @@ -618,15 +618,6 @@ function graphs() { \n \n"; - $graph_templates = db_fetch_assoc_prepared('SELECT - gt.id AS graph_template_id, - gt.name AS graph_template_name - FROM host_graph AS hg - INNER JOIN graph_templates AS gt - ON hg.graph_template_id=gt.id - WHERE hg.host_id = ? - ORDER BY gt.name', array(get_request_var('host_id'))); - if (!isempty_request_var('host_id')) { $template_graphs = db_fetch_assoc_prepared('SELECT gl.graph_template_id @@ -651,6 +642,17 @@ function graphs() { } } + $graph_templates = db_fetch_assoc_prepared('SELECT + gt.id AS graph_template_id, + gt.name AS graph_template_name + FROM host_graph AS hg + INNER JOIN graph_templates AS gt + ON hg.graph_template_id=gt.id + WHERE hg.host_id = ? + ORDER BY gt.name', + array(get_request_var('host_id')) + ); + /* create a row for each graph template associated with the host template */ if (sizeof($graph_templates)) { foreach ($graph_templates as $graph_template) { @@ -673,9 +675,14 @@ function graphs() { $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'); + 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 + AND graph_templates.id NOT IN (SELECT graph_template_id FROM host_graph WHERE host_id = ?) + ORDER BY graph_templates.name', + array(get_request_var('host_id')) + ); /* create a row at the bottom that lets the user create any graph they choose */ print " @@ -756,8 +763,8 @@ function graphs() { $cg_ctr = 0; if (sizeof($created_graphs)) { foreach ($created_graphs as $created_graph) { - $script .= (($cg_ctr > 0) ? ',' : '') . "'" . encode_data_query_index($created_graph['snmp_index']) . "'"; - $cg_ctr++; + $script .= ($cg_ctr > 0 ? ',' : '') . "'" . encode_data_query_index($created_graph['snmp_index']) . "'"; + ++$cg_ctr; } } @@ -769,9 +776,6 @@ function graphs() { if ($xml_array != false) { $html_dq_header = ''; - $snmp_query_indexes = array(); - - reset($xml_array['fields']); /* if there is a where clause, get the matching snmp_indexes */ $sql_where = ''; From e9aba07f3e51ca7b418048df1b5e27a30ad2ca8c Mon Sep 17 00:00:00 2001 From: Patrick Date: Wed, 26 Apr 2017 19:53:19 +0200 Subject: [PATCH 06/20] -issue: List for creating a Graph type shows already added Graph Templates --- docs/CHANGELOG | 2 +- graphs_new.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/CHANGELOG b/docs/CHANGELOG index 896e68bde0..e07eaf5fd4 100644 --- a/docs/CHANGELOG +++ b/docs/CHANGELOG @@ -3,6 +3,7 @@ Cacti CHANGELOG 1.1.6 -issue#620: The table poller_data_template_field_mappings can get out of sync when manipulating data templates -issue#622: Can not connect to MySQL over a socket +-issue: List for creating a Graph type shows already added Graph Templates 1.1.5 -issue#580: Data collection warnings when using cmd.php @@ -17,7 +18,6 @@ Cacti CHANGELOG -issue#613: Network Automation, now requires a site or your are unable to save rules -issue#615: Data Input field length too short for longer scripts -issue#619: Export logging option in settings no longer used --issue: List for creating a Graph type shows already added Graph Templates 1.1.4 -issue#524: Reporting not working when Tree branch is device diff --git a/graphs_new.php b/graphs_new.php index 11917bdb62..cc4c57cb6d 100644 --- a/graphs_new.php +++ b/graphs_new.php @@ -673,7 +673,7 @@ function graphs() { html_start_box('', '100%', '', '3', 'center', ''); - $available_graph_templates = db_fetch_assoc('SELECT + $available_graph_templates = db_fetch_assoc_prepared('SELECT graph_templates.id, graph_templates.name FROM snmp_query_graph RIGHT JOIN graph_templates From 80833d257f5fe87e1215678fbf1514b1b35abff1 Mon Sep 17 00:00:00 2001 From: patrick Date: Thu, 27 Apr 2017 11:16:31 +0200 Subject: [PATCH 07/20] - Added new column `multiple` to graph_templates - Changed the query for list for creating a Graph type - Prepped the 1.1.6 upgrade --- cacti.sql | 16 +++++++++------- graphs_new.php | 21 +++++++++++++-------- include/global.php | 2 +- include/global_arrays.php | 1 + install/1_1_4_to_1_1_5.php | 2 +- install/1_1_5_to_1_1_6.php | 37 +++++++++++++++++++++++++++++++++++++ install/index.php | 7 ++++++- 7 files changed, 68 insertions(+), 18 deletions(-) create mode 100644 install/1_1_5_to_1_1_6.php diff --git a/cacti.sql b/cacti.sql index 9e605fc319..f6f465dbd8 100644 --- a/cacti.sql +++ b/cacti.sql @@ -1573,12 +1573,13 @@ CREATE TABLE graph_template_input_defs ( -- CREATE TABLE graph_templates ( - id mediumint(8) unsigned NOT NULL auto_increment, - hash char(32) NOT NULL default '', - name char(255) NOT NULL default '', - PRIMARY KEY (id)) - ENGINE=InnoDB - COMMENT='Contains each graph template name.'; + `id` mediumint(8) unsigned NOT NULL auto_increment, + `hash` char(32) NOT NULL default '', + `name` char(255) NOT NULL default '', + `multiple` tinyint(1) unsigned NULL default '0', + PRIMARY KEY (`id`), + KEY `multiple_name` (`multiple`, `name`) +) ENGINE=InnoDB COMMENT='Contains each graph template name.'; -- -- Dumping data for table `graph_templates` @@ -2342,7 +2343,8 @@ CREATE TABLE snmp_query_graph ( snmp_query_id mediumint(8) unsigned NOT NULL default '0', name varchar(100) NOT NULL default '', graph_template_id mediumint(8) unsigned NOT NULL default '0', - PRIMARY KEY (id) + PRIMARY KEY (id), + KEY `graph_template_id_name` (`graph_template_id`, `name`) ) ENGINE=InnoDB; -- diff --git a/graphs_new.php b/graphs_new.php index cc4c57cb6d..90c63e237b 100644 --- a/graphs_new.php +++ b/graphs_new.php @@ -673,14 +673,19 @@ function graphs() { html_start_box('', '100%', '', '3', 'center', ''); - $available_graph_templates = db_fetch_assoc_prepared('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 - AND graph_templates.id NOT IN (SELECT graph_template_id FROM host_graph WHERE host_id = ?) - ORDER BY graph_templates.name', + $available_graph_templates = db_fetch_assoc_prepared(' + ( + SELECT graph_templates.id, graph_templates.name + FROM graph_templates + LEFT JOIN snmp_query_graph + ON snmp_query_graph.graph_template_id = graph_templates.id + WHERE snmp_query_graph.name IS NULL + AND graph_templates.id NOT IN (SELECT graph_template_id FROM host_graph WHERE host_id = ?) + AND graph_templates.multiple = 0 + ) UNION ( + SELECT id, name FROM graph_templates WHERE multiple = 1 + ) + ORDER BY name', array(get_request_var('host_id')) ); diff --git a/include/global.php b/include/global.php index 2669d3d189..c4f5b07d75 100644 --- a/include/global.php +++ b/include/global.php @@ -348,5 +348,5 @@ if ($is_web) { api_plugin_hook('config_insert'); /* current cacti version */ -$config['cacti_version'] = '1.1.5'; +$config['cacti_version'] = '1.1.6'; diff --git a/include/global_arrays.php b/include/global_arrays.php index efbc461842..99f51e647d 100644 --- a/include/global_arrays.php +++ b/include/global_arrays.php @@ -965,6 +965,7 @@ $hash_version_codes = array( '1.1.3' => '0100', '1.1.4' => '0100', '1.1.5' => '0100', + '1.1.6' => '0100', ); $hash_type_names = array( diff --git a/install/1_1_4_to_1_1_5.php b/install/1_1_4_to_1_1_5.php index d3d0357d83..dbfb2d7218 100644 --- a/install/1_1_4_to_1_1_5.php +++ b/install/1_1_4_to_1_1_5.php @@ -23,5 +23,5 @@ */ function upgrade_to_1_1_5() { - db_install_execute('ALTER TABLE data_input MODIFY COLUMN input_string varchar(512) default NULL'); + //Queries failed in upgrade to 1.1.5 -> Moved to 1.1.6 } diff --git a/install/1_1_5_to_1_1_6.php b/install/1_1_5_to_1_1_6.php new file mode 100644 index 0000000000..793bbe78ac --- /dev/null +++ b/install/1_1_5_to_1_1_6.php @@ -0,0 +1,37 @@ + Date: Fri, 28 Apr 2017 04:35:36 -0500 Subject: [PATCH 08/20] Make upgrade repeatable --- install/1_1_5_to_1_1_6.php | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/install/1_1_5_to_1_1_6.php b/install/1_1_5_to_1_1_6.php index 793bbe78ac..ef84c835d5 100644 --- a/install/1_1_5_to_1_1_6.php +++ b/install/1_1_5_to_1_1_6.php @@ -23,15 +23,26 @@ */ function upgrade_to_1_1_6() { - db_install_execute('ALTER TABLE `data_input` MODIFY COLUMN `input_string` varchar(512) default NULL'); - - db_install_execute("ALTER TABLE `snmp_query_graph` ADD KEY `graph_template_id_name` (`graph_template_id`, `name`)"); - - db_install_execute( - "ALTER TABLE `graph_templates` - ADD `multiple` TINYINT(1) UNSIGNED NULL DEFAULT '0' AFTER `name`, - ADD KEY `multiple_name` (`multiple`, `name`)" + db_install_execute('ALTER TABLE `data_input` + MODIFY COLUMN `input_string` varchar(512) default NULL' ); - db_execute_prepared("UPDATE graph_templates SET multiple = 1 WHERE hash = '010b90500e1fc6a05abfd542940584d0'"); + if (!db_index_exists('snmp_query_graph', 'graph_template_id_name')) { + db_install_execute("ALTER TABLE `snmp_query_graph` + ADD INDEX `graph_template_id_name` (`graph_template_id`, `name`)" + ); + } + + if (!db_index_exists('graph_templates', 'multiple_name')) { + db_install_execute( + "ALTER TABLE `graph_templates` + ADD `multiple` TINYINT(1) UNSIGNED NULL DEFAULT '0' AFTER `name`, + ADD KEY `multiple_name` (`multiple`, `name`)" + ); + } + + db_execute_prepared("UPDATE graph_templates + SET multiple = 1 + WHERE hash = '010b90500e1fc6a05abfd542940584d0'" + ); } From ab746b0e38df1a016fcf3bd920f449a8a61ec339 Mon Sep 17 00:00:00 2001 From: cigamit Date: Fri, 28 Apr 2017 04:45:13 -0500 Subject: [PATCH 09/20] Add new field for graph templates to form actions Increase the minimum import level for new templates, insure that new templates imported with this column are saved properly, include duplicate graph functionality, change field to a char(2) --- cacti.sql | 2 +- graph_templates.php | 7 ++++--- graphs_new.php | 4 ++-- include/global_arrays.php | 2 +- include/global_form.php | 33 ++++++++++++++++++++++++++++----- install/1_1_5_to_1_1_6.php | 4 ++-- lib/api_graph.php | 31 ++++++++++++++++++++++++------- lib/import.php | 4 ++++ 8 files changed, 66 insertions(+), 21 deletions(-) diff --git a/cacti.sql b/cacti.sql index f6f465dbd8..fdc2460e27 100644 --- a/cacti.sql +++ b/cacti.sql @@ -1576,7 +1576,7 @@ CREATE TABLE graph_templates ( `id` mediumint(8) unsigned NOT NULL auto_increment, `hash` char(32) NOT NULL default '', `name` char(255) NOT NULL default '', - `multiple` tinyint(1) unsigned NULL default '0', + `multiple` char(2) NOT NULL default '', PRIMARY KEY (`id`), KEY `multiple_name` (`multiple`, `name`) ) ENGINE=InnoDB COMMENT='Contains each graph template name.'; diff --git a/graph_templates.php b/graph_templates.php index 1b793c6742..2a1fe513b8 100644 --- a/graph_templates.php +++ b/graph_templates.php @@ -100,9 +100,10 @@ function form_save() { get_filter_request_var('graph_template_graph_id'); /* ==================================================== */ - $save1['id'] = $graph_template_id; - $save1['hash'] = get_hash_graph_template($graph_template_id); - $save1['name'] = form_input_validate(get_nfilter_request_var('name'), 'name', '', false, 3); + $save1['id'] = $graph_template_id; + $save1['hash'] = get_hash_graph_template($graph_template_id); + $save1['name'] = form_input_validate(get_nfilter_request_var('name'), 'name', '', false, 3); + $save1['multiple'] = isset_request_var('multiple') ? 'on':''; $save2['id'] = get_nfilter_request_var('graph_template_graph_id'); $save2['local_graph_template_graph_id'] = 0; diff --git a/graphs_new.php b/graphs_new.php index 90c63e237b..0ca5f700aa 100644 --- a/graphs_new.php +++ b/graphs_new.php @@ -681,9 +681,9 @@ function graphs() { ON snmp_query_graph.graph_template_id = graph_templates.id WHERE snmp_query_graph.name IS NULL AND graph_templates.id NOT IN (SELECT graph_template_id FROM host_graph WHERE host_id = ?) - AND graph_templates.multiple = 0 + AND graph_templates.multiple = "" ) UNION ( - SELECT id, name FROM graph_templates WHERE multiple = 1 + SELECT id, name FROM graph_templates WHERE multiple = "on" ) ORDER BY name', array(get_request_var('host_id')) diff --git a/include/global_arrays.php b/include/global_arrays.php index 99f51e647d..d5fc366dcd 100644 --- a/include/global_arrays.php +++ b/include/global_arrays.php @@ -965,7 +965,7 @@ $hash_version_codes = array( '1.1.3' => '0100', '1.1.4' => '0100', '1.1.5' => '0100', - '1.1.6' => '0100', + '1.1.6' => '0101', ); $hash_type_names = array( diff --git a/include/global_form.php b/include/global_form.php index 3f5c157805..6deb78e5e8 100644 --- a/include/global_form.php +++ b/include/global_form.php @@ -933,6 +933,14 @@ $fields_graph_template_template_edit = array( 'max_length' => '150', 'size' => '80' ), + 'multiple' => array( + 'method' => 'checkbox', + 'friendly_name' => __('Multiple Instances'), + 'description' => __('Check this checkbox if there can be more than one Graph of this type per Device.'), + 'value' => '|arg1:multiple|', + 'default' => '', + 'form_id' => false + ), 'graph_template_id' => array( 'method' => 'hidden_zero', 'value' => '|arg2:graph_template_id|' @@ -1531,6 +1539,11 @@ $fields_user_user_edit_host = array( ); $export_types = array( + 'host_template' => array( + 'name' => __('Device Template'), + 'title_sql' => 'SELECT name FROM host_template WHERE id=|id|', + 'dropdown_sql' => 'SELECT id,name FROM host_template ORDER BY name' + ), 'graph_template' => array( 'name' => __('Graph Template'), 'title_sql' => 'SELECT name FROM graph_templates WHERE id=|id|', @@ -1541,15 +1554,25 @@ $export_types = array( 'title_sql' => 'SELECT name FROM data_template WHERE id=|id|', 'dropdown_sql' => 'SELECT id,name FROM data_template ORDER BY name' ), - 'host_template' => array( - 'name' => __('Device Template'), - 'title_sql' => 'SELECT name FROM host_template WHERE id=|id|', - 'dropdown_sql' => 'SELECT id,name FROM host_template ORDER BY name' - ), 'data_query' => array( 'name' => __('Data Query'), 'title_sql' => 'SELECT name FROM snmp_query WHERE id=|id|', 'dropdown_sql' => 'SELECT id,name FROM snmp_query ORDER BY name' + ), + 'automation_devices' => array( + 'name' => __('Discovery Rules'), + 'title_sql' => 'SELECT CONCAT(ht.name, " (", at.sysDescr, ")") AS name FROM automation_templates AS at INNER JOIN host_template AS ht ON ht.id=at.host_template WHERE at.id=|id|', + 'dropdown_sql' => 'SELECT at.id, CONCAT(ht.name, " (", at.sysDescr, ")") AS name FROM automation_templates AS at INNER JOIN host_template AS ht ON ht.id=at.host_template ORDER BY name' + ), + 'automation_graphs' => array( + 'name' => __('Graph Rules'), + 'title_sql' => 'SELECT name FROM automation_graph_rules WHERE id=|id|', + 'dropdown_sql' => 'SELECT id, name FROM automation_graph_rules ORDER BY name' + ), + 'automation_trees' => array( + 'name' => __('Tree Rules'), + 'title_sql' => 'SELECT name FROM automation_tree_rules WHERE id=|id|', + 'dropdown_sql' => 'SELECT id, name FROM automation_tree_rules ORDER BY name' ) ); diff --git a/install/1_1_5_to_1_1_6.php b/install/1_1_5_to_1_1_6.php index ef84c835d5..94758bd13d 100644 --- a/install/1_1_5_to_1_1_6.php +++ b/install/1_1_5_to_1_1_6.php @@ -36,13 +36,13 @@ function upgrade_to_1_1_6() { if (!db_index_exists('graph_templates', 'multiple_name')) { db_install_execute( "ALTER TABLE `graph_templates` - ADD `multiple` TINYINT(1) UNSIGNED NULL DEFAULT '0' AFTER `name`, + ADD `multiple` CHAR(2) NOT NULL DEFAULT '' AFTER `name`, ADD KEY `multiple_name` (`multiple`, `name`)" ); } db_execute_prepared("UPDATE graph_templates - SET multiple = 1 + SET multiple = 'on' WHERE hash = '010b90500e1fc6a05abfd542940584d0'" ); } diff --git a/lib/api_graph.php b/lib/api_graph.php index acff351663..f4ac36fcac 100644 --- a/lib/api_graph.php +++ b/lib/api_graph.php @@ -190,16 +190,33 @@ function api_duplicate_graph($_local_graph_id, $_graph_template_id, $graph_title $graph_template_graph['title'] = str_replace('', $graph_template_graph['title'], $graph_title); }elseif (!empty($_graph_template_id)) { - $graph_template = db_fetch_row_prepared('SELECT * FROM graph_templates WHERE id = ?', array($_graph_template_id)); - $graph_template_graph = db_fetch_row_prepared('SELECT * FROM graph_templates_graph WHERE graph_template_id = ? AND local_graph_id=0', array($_graph_template_id)); + $graph_template = db_fetch_row_prepared('SELECT * + FROM graph_templates + WHERE id = ?', + array($_graph_template_id)); - $graph_template_items = db_fetch_assoc_prepared('SELECT * FROM graph_templates_item WHERE graph_template_id = ? AND local_graph_id=0', array($_graph_template_id)); - $graph_template_inputs = db_fetch_assoc_prepared('SELECT * FROM graph_template_input WHERE graph_template_id = ?', array($_graph_template_id)); + $graph_template_graph = db_fetch_row_prepared('SELECT * + FROM graph_templates_graph + WHERE graph_template_id = ? + AND local_graph_id=0', + array($_graph_template_id)); + + $graph_template_items = db_fetch_assoc_prepared('SELECT * + FROM graph_templates_item + WHERE graph_template_id = ? + AND local_graph_id=0', + array($_graph_template_id)); + + $graph_template_inputs = db_fetch_assoc_prepared('SELECT * + FROM graph_template_input + WHERE graph_template_id = ?', + array($_graph_template_id)); /* create new entry: graph_templates */ - $save['id'] = 0; - $save['hash'] = get_hash_graph_template(0); - $save['name'] = str_replace('', $graph_template['name'], $graph_title); + $save['id'] = 0; + $save['hash'] = get_hash_graph_template(0); + $save['name'] = str_replace('', $graph_template['name'], $graph_title); + $save['multiple'] = $graph_template['multiple']; $graph_template_id = sql_save($save, 'graph_templates'); } diff --git a/lib/import.php b/lib/import.php index 9df6a89d7f..2bdc5bf0ec 100644 --- a/lib/import.php +++ b/lib/import.php @@ -282,6 +282,10 @@ function xml_to_graph_template($hash, &$xml_array, &$hash_cache, $hash_version, $save['hash'] = $hash; $save['name'] = $xml_array['name']; + if (isset($xml_array['multiple'])) { + $save['multiple'] = $xml_array['multiple']; + } + /* check for status changes */ $status += compare_data($save, $previous_data, 'graph_templates'); From 336888ebf2f5e82257327a5e4130433ea95fa89a Mon Sep 17 00:00:00 2001 From: Patrick Date: Fri, 28 Apr 2017 16:47:04 +0200 Subject: [PATCH 10/20] Optimisations for lib/data_query.php --- lib/data_query.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/data_query.php b/lib/data_query.php index f22cefda62..428bfb8ddb 100644 --- a/lib/data_query.php +++ b/lib/data_query.php @@ -1385,8 +1385,10 @@ function update_snmp_index_order($data_query) { data_input_fields.id, data_input_fields.type_code FROM snmp_query - INNER JOIN data_input ON snmp_query.data_input_id = data_input.id - INNER JOIN data_input_fields ON data_input.id = data_input_fields.data_input_id + INNER JOIN data_input + ON snmp_query.data_input_id = data_input.id + INNER JOIN data_input_fields + ON data_input.id = data_input_fields.data_input_id WHERE data_input_fields.type_code IN('index_type', 'index_value', 'output_type') AND snmp_query.id = ?", array($data_query['snmp_query_id'])), 'type_code', 'id'); From bda405dc3585cdacd0ec940203ff0833019da17c Mon Sep 17 00:00:00 2001 From: Patrick Date: Fri, 28 Apr 2017 17:00:56 +0200 Subject: [PATCH 11/20] Optimisations for lib/utility.php --- lib/utility.php | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/lib/utility.php b/lib/utility.php index e7f7a14a8d..67415340e0 100644 --- a/lib/utility.php +++ b/lib/utility.php @@ -390,7 +390,7 @@ function update_poller_cache($data_source, $commit = false) { } function push_out_data_input_method($data_input_id) { - $data_sources = db_fetch_assoc_prepared('SELECT ' . SQL_NO_CACHE . ' * + $data_sources = db_fetch_assoc_prepared('SELECT ' . SQL_NO_CACHE . ' data_local.* FROM data_local INNER JOIN ( SELECT DISTINCT local_data_id @@ -467,9 +467,11 @@ function poller_update_poller_cache_from_buffer($local_data_ids, &$poller_items) $buffer = ''; if (sizeof($poller_items)) { - foreach($poller_items AS $record) { + foreach($poller_items as $record) { /* take care of invalid entries */ - if (strlen($record) == 0) continue; + if (strlen($record) == 0) { + continue; + } if ($buf_count == 0) { $delim = ' '; @@ -481,7 +483,7 @@ function poller_update_poller_cache_from_buffer($local_data_ids, &$poller_items) $buf_len += strlen($record); - if (($overhead + $buf_len) > ($max_packet - 1024)) { + if ($overhead + $buf_len > $max_packet - 1024) { db_execute($sql_prefix . $buffer . $sql_suffix); $buffer = ''; @@ -576,9 +578,11 @@ function push_out_host($host_id, $local_data_id = 0, $data_template_id = 0) { - the field is set to 'templated' */ if (sizeof($template_fields{$data_source['local_data_template_data_id']})) { foreach ($template_fields[$data_source['local_data_template_data_id']] as $template_field) { - if ((preg_match('/^' . VALID_HOST_FIELDS . '$/i', $template_field['type_code'])) && ($template_field['value'] == '') && ($template_field['t_value'] == '')) { + if (preg_match('/^' . VALID_HOST_FIELDS . '$/i', $template_field['type_code']) && $template_field['value'] == '' && $template_field['t_value'] == '') { // handle special case type_code - if ($template_field['type_code'] == 'host_id') $template_field['type_code'] = 'id'; + if ($template_field['type_code'] == 'host_id') { + $template_field['type_code'] = 'id'; + } db_execute_prepared('REPLACE INTO data_input_data (data_input_field_id, data_template_data_id, value) From b154c3e89ed78000924cd2079fc3c87528c229d5 Mon Sep 17 00:00:00 2001 From: Patrick Date: Fri, 28 Apr 2017 18:16:46 +0200 Subject: [PATCH 12/20] Optimisations for tree view lib/auth.php: - is_device_allowed() - removed unused parameter $user - get_allowed_tree_level() - removed unused parameter $user - get_allowed_tree_content() - removed unused paramters $sql_where, $order_by, $limit, $total_rows and $user - refactored the code to apply for these unused parameters - get_allowed_tree_header_graphs() - removed unused parameters $order_by, $limit, $total_rows and $user - refactored the code to apply for these unused parameters - get_allowed_trees() - removed unused parameters $edit, $sql_where, $limit, $total_rows and $user - refactored the code to apply for these unused parameters lib/functions.php: - removed get_graph_tree_array() because it's unused after refactor lib/html_tree.php - draw_dhtml_tree_level(): - removed unused parameter $graphing - removed unused global $config - create_dhtml_tree() - removed unused global $config - refactored get_graph_tree_array() to alias: get_allowed_trees() auth_profile.php: - refactored get_graph_tree_array(true) to alias: get_allowed_trees(true) --- auth_profile.php | 2 +- lib/auth.php | 239 ++++++++++++++-------------------------------- lib/functions.php | 10 -- lib/html_tree.php | 12 +-- 4 files changed, 76 insertions(+), 187 deletions(-) diff --git a/auth_profile.php b/auth_profile.php index 6eb05122db..99dca9136c 100644 --- a/auth_profile.php +++ b/auth_profile.php @@ -233,7 +233,7 @@ function settings() { if (is_view_allowed('graph_settings') == true) { if (read_config_option('auth_method') != 0) { - $settings_user['tree']['default_tree_id']['sql'] = get_graph_tree_array(true); + $settings_user['tree']['default_tree_id']['sql'] = get_allowed_trees(true); } html_start_box( __('User Settings'), '100%', '', '3', 'center', ''); diff --git a/lib/auth.php b/lib/auth.php index 01e0a23b86..58c6cffce5 100644 --- a/lib/auth.php +++ b/lib/auth.php @@ -471,9 +471,9 @@ function is_tree_allowed($tree_id, $user = 0) { /* is_device_allowed - determines whether the current user is allowed to view a certain device @arg $host_id - (int) the ID of the device to check permissions for @returns - (bool) whether the current user is allowed the view the specified device or not */ -function is_device_allowed($host_id, $user = 0) { +function is_device_allowed($host_id) { $total_rows = 0; - get_allowed_devices('', '', '', $total_rows, $user, $host_id); + get_allowed_devices('', '', '', $total_rows, 0, $host_id); return ($total_rows > 0); } @@ -621,7 +621,7 @@ function is_realm_allowed($realm) { } } -function get_allowed_tree_level($tree_id, $parent_id, $user = 0) { +function get_allowed_tree_level($tree_id, $parent_id) { $items = db_fetch_assoc_prepared('SELECT gti.id, gti.title, gti.host_id, gti.local_graph_id, gti.host_grouping_type, h.description AS hostname FROM graph_tree_items AS gti @@ -638,11 +638,11 @@ function get_allowed_tree_level($tree_id, $parent_id, $user = 0) { if (sizeof($items)) { foreach($items as $item) { if ($item['host_id'] > 0) { - if (!is_device_allowed($item['host_id'], $user)) { + if (!is_device_allowed($item['host_id'])) { unset($items[$i]); } } elseif($item['local_graph_id'] > 0) { - if (!is_graph_allowed($item['local_graph_id'], $user)) { + if (!is_graph_allowed($item['local_graph_id'])) { unset($items[$i]); } } @@ -654,27 +654,15 @@ function get_allowed_tree_level($tree_id, $parent_id, $user = 0) { return $items; } -function get_allowed_tree_content($tree_id, $parent = 0, $sql_where = '', $order_by = '', $limit = '', &$total_rows = 0, $user = 0) { - if ($limit != '') { - $limit = "LIMIT $limit"; - } +function get_allowed_tree_content($tree_id, $parent = 0) { + $sql_where = "WHERE gti.local_graph_id=0 AND gti.parent=$parent AND gti.graph_tree_id=$tree_id"; - if ($order_by != '') { - $order_by = "ORDER BY $order_by"; - } - - if ($sql_where != '') { - $sql_where = "WHERE gti.local_graph_id=0 AND gti.parent=$parent AND gti.graph_tree_id=$tree_id AND (" . $sql_where . ')'; - }else{ - $sql_where = "WHERE gti.local_graph_id=0 AND gti.parent=$parent AND gti.graph_tree_id=$tree_id"; - } + $trees = array_rekey( + get_allowed_trees(false, ''), + 'id', 'name' + ); if ($tree_id > 0) { - $trees = array_rekey( - get_allowed_trees(false, false, '', '', '', $total_rows, $user), - 'id', 'name' - ); - if (sizeof($trees)) { $sql_where .= ' AND gt.id IN (' . implode(', ', array_keys($trees)) . ')'; } @@ -688,21 +676,13 @@ function get_allowed_tree_content($tree_id, $parent = 0, $sql_where = '', $order ON h.id = gti.host_id $sql_where ORDER BY gti.position"); - }else{ - $trees = array_rekey( - get_allowed_trees(false, false, '', '', '', $total_rows, $user), - 'id', 'name' - ); - - if (sizeof($trees)) { - $heirarchy = db_fetch_assoc("SELECT gt.id AS tree_id, '0' AS id, gt.name AS title, '0' AS host_id, - '0' AS local_graph_id, '1' AS host_grouping_type, '' AS hostname - FROM graph_tree AS gt - WHERE enabled='on' - AND gt.id IN (" . implode(', ', array_keys($trees)) . ") - ORDER BY gt.sequence"); - }else{ - } + } elseif (sizeof($trees)) { + $heirarchy = db_fetch_assoc("SELECT gt.id AS tree_id, '0' AS id, gt.name AS title, '0' AS host_id, + '0' AS local_graph_id, '1' AS host_grouping_type, '' AS hostname + FROM graph_tree AS gt + WHERE enabled='on' + AND gt.id IN (" . implode(', ', array_keys($trees)) . ") + ORDER BY gt.sequence"); } if (read_config_option('auth_method') != 0) { @@ -713,62 +693,43 @@ function get_allowed_tree_content($tree_id, $parent = 0, $sql_where = '', $order if (is_device_allowed($h['host_id'])) { $new_heirarchy[] = $h; } - }elseif ($h['id'] == 0) { + } elseif ($h['id'] == 0) { if (!is_tree_branch_empty($h['tree_id'], $h['id'])) { if (is_tree_allowed($h['tree_id'])) { $new_heirarchy[] = $h; } } - }elseif (!is_tree_branch_empty($h['tree_id'], $h['id'])) { + } elseif (!is_tree_branch_empty($h['tree_id'], $h['id'])) { $new_heirarchy[] = $h; } } } return $new_heirarchy; - }else{ + } else { return $heirarchy; } } -function get_allowed_tree_header_graphs($tree_id, $leaf_id = 0, $sql_where = '', $order_by = 'gti.position', $limit = '', &$total_rows = 0, $user = 0) { - if ($limit != '') { - $limit = "LIMIT $limit"; - } - - if ($order_by != '') { - $order_by = "ORDER BY $order_by"; - } - - if (strlen($sql_where)) { +function get_allowed_tree_header_graphs($tree_id, $leaf_id = 0, $sql_where = '') { + if ($sql_where != '') { $sql_where = " AND ($sql_where)"; } + $order_by = 'ORDER BY gti.position'; + $sql_where = "WHERE (gti.graph_tree_id=$tree_id AND gti.parent=$leaf_id)" . $sql_where; - $i = 0; - $sql_having = ''; - $sql_select = ''; - $sql_join = ''; - - if ($user == -1) { - $auth_method = 0; - }else{ - $auth_method = read_config_option('auth_method'); - } - - if ($auth_method != 0) { - if ($user == 0) { - if (isset($_SESSION['sess_user_id'])) { - $user = $_SESSION['sess_user_id']; - }else{ - return array(); - } + if (read_config_option('auth_method') != 0) { + if (isset($_SESSION['sess_user_id'])) { + $user = $_SESSION['sess_user_id']; + } else { + return array(); } if (read_config_option('graph_auth_method') == 1) { $sql_operator = 'OR'; - }else{ + } else { $sql_operator = 'AND'; } @@ -789,42 +750,47 @@ function get_allowed_tree_header_graphs($tree_id, $leaf_id = 0, $sql_where = '', WHERE id = ?", array($user) ); - + + $i = 0; + $sql_having = ''; + $sql_select = ''; + $sql_join = ''; + foreach($policies as $policy) { if ($policy['policy_graphs'] == 1) { - $sql_having .= (strlen($sql_having) ? ' OR ':'') . "(user$i IS NULL"; - }else{ - $sql_having .= (strlen($sql_having) ? ' OR ':'') . "(user$i IS NOT NULL"; + $sql_having .= ($sql_having != '' ? ' OR ':'') . "(user$i IS NULL"; + } else { + $sql_having .= ($sql_having != '' ? ' OR ':'') . "(user$i IS NOT NULL"; } $sql_join .= 'LEFT JOIN user_auth_' . ($policy['type'] == 'user' ? '':'group_') . "perms AS uap$i ON (gl.id=uap$i.item_id AND uap$i.type=1 AND uap$i." . $policy['type'] . "_id=" . $policy['id'] . ") "; - $sql_select .= (strlen($sql_select) ? ', ':'') . "uap$i." . $policy['type'] . "_id AS user$i"; + $sql_select .= ($sql_select != '' ? ', ':'') . "uap$i." . $policy['type'] . "_id AS user$i"; $i++; if ($policy['policy_hosts'] == 1) { $sql_having .= " OR (user$i IS NULL"; - }else{ + } else { $sql_having .= " OR (user$i IS NOT NULL"; } $sql_join .= 'LEFT JOIN user_auth_' . ($policy['type'] == 'user' ? '':'group_') . "perms AS uap$i ON (gl.host_id=uap$i.item_id AND uap$i.type=3 AND uap$i." . $policy['type'] . "_id=" . $policy['id'] . ") "; - $sql_select .= (strlen($sql_select) ? ', ':'') . "uap$i." . $policy['type'] . "_id AS user$i"; + $sql_select .= ($sql_select != '' ? ', ':'') . "uap$i." . $policy['type'] . "_id AS user$i"; $i++; if ($policy['policy_graph_templates'] == 1) { $sql_having .= " $sql_operator user$i IS NULL))"; - }else{ + } else { $sql_having .= " $sql_operator user$i IS NOT NULL))"; } $sql_join .= 'LEFT JOIN user_auth_' . ($policy['type'] == 'user' ? '':'group_') . "perms AS uap$i ON (gl.graph_template_id=uap$i.item_id AND uap$i.type=4 AND uap$i." . $policy['type'] . "_id=" . $policy['id'] . ") "; - $sql_select .= (strlen($sql_select) ? ', ':'') . "uap$i." . $policy['type'] . "_id AS user$i"; + $sql_select .= ($sql_select != '' ? ', ':'') . "uap$i." . $policy['type'] . "_id AS user$i"; $i++; } $sql_having = "HAVING $sql_having"; - $graphs = db_fetch_assoc("SELECT gti.id, gti.title, gtg.local_graph_id, + return db_fetch_assoc("SELECT gti.id, gti.title, gtg.local_graph_id, h.description, gt.name AS template_name, gtg.title_cache, gtg.width, gtg.height, gl.snmp_index, gl.snmp_query_id, $sql_select @@ -840,27 +806,9 @@ function get_allowed_tree_header_graphs($tree_id, $leaf_id = 0, $sql_where = '', $sql_join $sql_where $sql_having - $order_by - $limit"); - - $total_rows = db_fetch_cell("SELECT COUNT(*) - FROM ( - SELECT $sql_select - FROM graph_templates_graph AS gtg - INNER JOIN graph_local AS gl - ON gl.id = gtg.local_graph_id - INNER JOIN graph_tree_items AS gti - ON gti.local_graph_id = gl.id - LEFT JOIN graph_templates AS gt - ON gt.id = gl.graph_template_id - LEFT JOIN host AS h - ON h.id = gl.host_id - $sql_join - $sql_where - $sql_having - ) AS rower"); - }else{ - $graphs = db_fetch_assoc("SELECT + $order_by"); + } else { + return db_fetch_assoc("SELECT gti.id, gti.title, gtg.local_graph_id, h.description, @@ -880,23 +828,8 @@ function get_allowed_tree_header_graphs($tree_id, $leaf_id = 0, $sql_where = '', LEFT JOIN host AS h ON h.id = gl.host_id $sql_where - $order_by - $limit"); - - $total_rows = db_fetch_cell("SELECT COUNT(*) - FROM graph_templates_graph AS gtg - INNER JOIN graph_local AS gl - ON gl.id=gtg.local_graph_id - INNER JOIN graph_tree_items AS gti - ON gti.local_graph_id=gl.id - LEFT JOIN graph_templates AS gt - ON gt.id=gl.graph_template_id - LEFT JOIN host AS h - ON h.id=gl.host_id - $sql_where"); + $order_by"); } - - return $graphs; } function get_allowed_graphs($sql_where = '', $order_by = 'gtg.title_cache', $limit = '', &$total_rows = 0, $user = 0, $graph_id = 0) { @@ -1212,33 +1145,16 @@ function get_allowed_graph_templates($sql_where = '', $order_by = 'name', $limit return $graphs; } -function get_allowed_trees($edit = false, $return_sql = false, $sql_where = '', $order_by = 'name', $limit = '', &$total_rows = 0, $user = 0) { - if ($limit != '') { - $limit = "LIMIT $limit"; - } - +function get_allowed_trees($return_sql = false, $order_by = 'name') { if ($order_by != '') { $order_by = "ORDER BY $order_by"; } - $i = 0; - $sql_where1 = ''; - $sql_select = ''; - $sql_join = ''; - - if ($user == -1) { - $auth_method = 0; - }else{ - $auth_method = read_config_option('auth_method'); - } - - if ($auth_method != 0) { - if ($user == 0) { - if (isset($_SESSION['sess_user_id'])) { - $user = $_SESSION['sess_user_id']; - }else{ - return array(); - } + if (read_config_option('auth_method') != 0) { + if (isset($_SESSION['sess_user_id'])) { + $user = $_SESSION['sess_user_id']; + } else { + return array(); } /* get policies for all groups and user */ @@ -1248,11 +1164,15 @@ function get_allowed_trees($edit = false, $return_sql = false, $sql_where = '', WHERE uag.enabled = 'on' AND uagm.user_id = ?", array($user)); $policies[] = db_fetch_row_prepared("SELECT id, 'user' as type, policy_trees FROM user_auth WHERE id = ?", array($user)); + $i = 0; + $sql_where1 = ''; + $sql_join = ''; + foreach($policies as $policy) { if ($policy['policy_trees'] == '1') { - $sql_where1 .= (strlen($sql_where1) ? ' OR':'') . " uap$i." . $policy['type'] . "_id IS NULL"; - }elseif ($policy['policy_trees'] == '2') { - $sql_where1 .= (strlen($sql_where1) ? ' OR':'') . " uap$i." . $policy['type'] . "_id IS NOT NULL"; + $sql_where1 .= ($sql_where1 != '' ? ' OR':'') . " uap$i." . $policy['type'] . "_id IS NULL"; + } elseif ($policy['policy_trees'] == '2') { + $sql_where1 .= ($sql_where1 != '' ? ' OR':'') . " uap$i." . $policy['type'] . "_id IS NOT NULL"; } $sql_join .= 'LEFT JOIN user_auth_' . ($policy['type'] == 'group' ? 'group_':'') . "perms AS uap$i @@ -1261,45 +1181,28 @@ function get_allowed_trees($edit = false, $return_sql = false, $sql_where = '', $i++; } - if (strlen($sql_where)) { - $sql_where = 'WHERE ' . ($edit == false ? '(gt.enabled="on") AND ':'') . '(' . $sql_where . ') AND (' . $sql_where1 . ')'; - }else{ - $sql_where = 'WHERE ' . ($edit == false ? '(gt.enabled="on") AND ':'') . '(gt.enabled="on") AND (' . $sql_where1 . ')'; - } + $sql_where = 'WHERE gt.enabled="on" AND (' . $sql_where1 . ')'; $sql = "SELECT id, name FROM graph_tree AS gt $sql_join $sql_where - $order_by - $limit"; + $order_by"; if ($return_sql) { return $sql; - }else{ - $trees = db_fetch_assoc($sql); - - $total_rows = db_fetch_cell("SELECT COUNT(gt.id) - FROM graph_tree AS gt - $sql_join - $sql_where"); - } - }else{ - if (strlen($sql_where)) { - $sql_where = "WHERE enabled='on' AND $sql_where"; - }else{ - $sql_where = "WHERE enabled='on'"; + } else { + return db_fetch_assoc($sql); } + } else { + $sql_where = "WHERE enabled='on'"; if ($return_sql) { return "SELECT id, name FROM graph_tree $sql_where $order_by"; - }else{ - $trees = db_fetch_assoc("SELECT id, name FROM graph_tree AS gt $sql_where $order_by"); - $total_rows = db_fetch_cell("SELECT COUNT(*) FROM graph_tree AS gt $sql_where"); + } else { + return db_fetch_assoc("SELECT id, name FROM graph_tree AS gt $sql_where $order_by"); } } - - return $trees; } function get_allowed_devices($sql_where = '', $order_by = 'description', $limit = '', &$total_rows = 0, $user = 0, $host_id = 0) { diff --git a/lib/functions.php b/lib/functions.php index 0fe12e0e78..9145e7021d 100644 --- a/lib/functions.php +++ b/lib/functions.php @@ -1768,16 +1768,6 @@ function get_web_browser() { } } -/* get_graph_tree_array - returns a list of graph trees taking permissions into account if - necessary - @arg $return_sql - (bool) Whether to return the SQL to create the dropdown rather than an array - @arg $force_refresh - (bool) Force the refresh of the array from the database - @arg $edit - (bool) Shows the content even though the graph may not be published - @returns - (array) an array containing a list of graph trees */ -function get_graph_tree_array($return_sql = false, $force_refresh = false, $edit = false) { - return get_allowed_trees($edit, $return_sql); -} - /* draw_login_status - provides a consistent login status page for all pages that use it */ function draw_login_status($using_guest_account = false) { global $config; diff --git a/lib/html_tree.php b/lib/html_tree.php index 4a61343156..8f7a20bf94 100644 --- a/lib/html_tree.php +++ b/lib/html_tree.php @@ -337,9 +337,7 @@ function get_tree_path() { } } -function draw_dhtml_tree_level($tree_id, $parent = 0, $graphing = false) { - global $config; - +function draw_dhtml_tree_level($tree_id, $parent = 0) { $dhtml_tree = array(); $heirarchy = get_allowed_tree_level($tree_id, $parent); @@ -349,9 +347,9 @@ function draw_dhtml_tree_level($tree_id, $parent = 0, $graphing = false) { foreach ($heirarchy as $leaf) { if ($leaf['host_id'] > 0) { //It's a host $dhtml_tree[] = "\t\t\t\t
  • Device: " . htmlspecialchars($leaf['hostname']) . "
  • \n"; - }elseif ($leaf['local_graph_id'] > 0) { + } elseif ($leaf['local_graph_id'] > 0) { $dhtml_tree[] = "\t\t\t\t
  • Graph: " . htmlspecialchars(get_graph_title($leaf['local_graph_id'])) . "
  • \n"; - }else{ //It's not a host + } else { //It's not a host $dhtml_tree[] = "\t\t\t\t
  • " . htmlspecialchars($leaf['title']) . "
  • \n"; } } @@ -466,11 +464,9 @@ function draw_dhtml_tree_level_graphing($tree_id, $parent = 0) { } function create_dhtml_tree() { - global $config; - $dhtml_tree = array(); - $tree_list = get_graph_tree_array(); + $tree_list = get_allowed_trees(); if (sizeof($tree_list)) { foreach ($tree_list as $tree) { From 1ca2ec43bf007d732f1c87c8bcf368dfa717d219 Mon Sep 17 00:00:00 2001 From: patrick Date: Fri, 28 Apr 2017 22:43:02 +0200 Subject: [PATCH 13/20] Removed unnecessary lines en applied some small optimisation and layout changes --- lib/data_query.php | 11 +++-- lib/html_utility.php | 111 +++++++++++++++++++------------------------ 2 files changed, 55 insertions(+), 67 deletions(-) diff --git a/lib/data_query.php b/lib/data_query.php index 428bfb8ddb..a5e1a7326d 100644 --- a/lib/data_query.php +++ b/lib/data_query.php @@ -107,10 +107,13 @@ function run_data_query($host_id, $snmp_query_id) { dl.snmp_index, dtd.local_data_id, dtd.data_input_id, did.data_template_data_id, did.data_input_field_id, did.value FROM data_local AS dl - INNER JOIN data_template_data AS dtd ON dl.id = dtd.local_data_id - INNER JOIN data_input_fields AS dif ON dtd.data_input_id = dif.data_input_id - LEFT JOIN data_input_data AS did ON dtd.id = did.data_template_data_id - AND dif.id = did.data_input_field_id + INNER JOIN data_template_data AS dtd + ON dl.id = dtd.local_data_id + INNER JOIN data_input_fields AS dif + ON dtd.data_input_id = dif.data_input_id + LEFT JOIN data_input_data AS did + ON dtd.id = did.data_template_data_id + AND dif.id = did.data_input_field_id WHERE dif.type_code = "output_type" AND dl.snmp_query_id = ? AND dl.host_id = ?', diff --git a/lib/html_utility.php b/lib/html_utility.php index 1c80abc1e9..5135582687 100644 --- a/lib/html_utility.php +++ b/lib/html_utility.php @@ -42,42 +42,42 @@ function inject_form_variables(&$form_array, $arg1 = array(), $arg2 = array(), $ /* loop through each available field */ if (sizeof($form_array)) { - foreach ($form_array as $field_name => $field_array) { - /* loop through each sub-field that we are going to check for variables */ - foreach ($check_fields as $field_to_check) { - if (isset($field_array[$field_to_check]) && (is_array($form_array[$field_name][$field_to_check]))) { - /* if the field/sub-field combination is an array, resolve it recursively */ - $form_array[$field_name][$field_to_check] = inject_form_variables($form_array[$field_name][$field_to_check], $arg1); - }elseif (isset($field_array[$field_to_check]) && (!is_array($field_array[$field_to_check])) && (preg_match('/\|(arg[123]):([a-zA-Z0-9_]*)\|/', $field_array[$field_to_check], $matches))) { - $string = $field_array[$field_to_check]; - while ( 1 ) { - /* an empty field name in the variable means don't treat this as an array */ - if ($matches[2] == '') { - if (is_array(${$matches[1]})) { - /* the existing value is already an array, leave it alone */ - $form_array[$field_name][$field_to_check] = ${$matches[1]}; - break; - }else{ - /* the existing value is probably a single variable */ - $form_array[$field_name][$field_to_check] = str_replace($matches[0], ${$matches[1]}, $field_array[$field_to_check]); - break; - } - }else{ - /* copy the value down from the array/key specified in the variable */ - $string = str_replace($matches[0], ((isset(${$matches[1]}{$matches[2]})) ? ${$matches[1]}{$matches[2]} : ''), $string); + foreach ($form_array as $field_name => $field_array) { + /* loop through each sub-field that we are going to check for variables */ + foreach ($check_fields as $field_to_check) { + if (isset($field_array[$field_to_check]) && is_array($form_array[$field_name][$field_to_check])) { + /* if the field/sub-field combination is an array, resolve it recursively */ + $form_array[$field_name][$field_to_check] = inject_form_variables($form_array[$field_name][$field_to_check], $arg1); + } elseif (isset($field_array[$field_to_check]) && !is_array($field_array[$field_to_check]) && preg_match('/\|(arg[123]):([a-zA-Z0-9_]*)\|/', $field_array[$field_to_check], $matches)) { + $string = $field_array[$field_to_check]; + while ( 1 ) { + /* an empty field name in the variable means don't treat this as an array */ + if ($matches[2] == '') { + if (is_array(${$matches[1]})) { + /* the existing value is already an array, leave it alone */ + $form_array[$field_name][$field_to_check] = ${$matches[1]}; + break; + } else { + /* the existing value is probably a single variable */ + $form_array[$field_name][$field_to_check] = str_replace($matches[0], ${$matches[1]}, $field_array[$field_to_check]); + break; + } + } else { + /* copy the value down from the array/key specified in the variable */ + $string = str_replace($matches[0], (isset(${$matches[1]}{$matches[2]}) ? ${$matches[1]}{$matches[2]} : ''), $string); - $matches = array(); - preg_match('/\|(arg[123]):([a-zA-Z0-9_]*)\|/', $string, $matches); - if (!sizeof($matches)) { - $form_array[$field_name][$field_to_check] = $string; - break; + $matches = array(); + preg_match('/\|(arg[123]):([a-zA-Z0-9_]*)\|/', $string, $matches); + if (!sizeof($matches)) { + $form_array[$field_name][$field_to_check] = $string; + break; + } } } } } } } - } return $form_array; } @@ -90,21 +90,21 @@ function inject_form_variables(&$form_array, $arg1 = array(), $arg2 = array(), $ @arg $row_id - used to allow js and ajax actions on this object @returns - the background color used for this particular row */ function form_alternate_row_color($row_color1, $row_color2, $row_value, $row_id = '') { - if (($row_value % 2) == 1) { + if ($row_value % 2 == 1) { $class='odd'; $current_color = $row_color1; - }else{ + } else { if ($row_color2 == '' || $row_color2 == 'E5E5E5') { $class = 'even'; - }else{ + } else { $class = 'even-alternate'; } $current_color = $row_color1; } - if (strlen($row_id)) { + if ($row_id != '') { print "\n"; - }else{ + } else { print "\n"; } @@ -118,25 +118,23 @@ function form_alternate_row_color($row_color1, $row_color2, $row_value, $row_id function form_alternate_row($row_id = '', $light = false, $disabled = false) { static $i = 1; - if (($i % 2) == 1) { + if ($i % 2 == 1) { $class = 'odd'; - }else{ - if ($light) { - $class = 'even-alternate'; - }else{ - $class = 'even'; - } + } elseif ($light) { + $class = 'even-alternate'; + } else { + $class = 'even'; } $i++; - if (strlen($row_id) && substr($row_id,0,4) != 'row_' && !$disabled) { + if ($row_id != '' && !$disabled && substr($row_id, 0, 4) != 'row_') { print "\n"; - }elseif (substr($row_id,0,4) == 'row_') { + } elseif (substr($row_id, 0, 4) == 'row_') { print "\n"; - }elseif (strlen($row_id)) { + } elseif ($row_id != '') { print "\n"; - }else{ + } else { print "\n"; } } @@ -206,11 +204,7 @@ function form_confim_buttons($post_variable, $item_array, $save_message, $return @arg $html_boolean - the value of the HTML checkbox @returns - true or false based on the value of the HTML checkbox */ function html_boolean($html_boolean) { - if ($html_boolean == "on") { - return true; - }else{ - return false; - } + return ($html_boolean == "on"); } /* html_boolean_friendly - returns the natural language equivalent of an HTML @@ -221,7 +215,7 @@ function html_boolean($html_boolean) { function html_boolean_friendly($html_boolean) { if ($html_boolean == "on") { return "Selected"; - }else{ + } else { return "Not Selected"; } } @@ -238,11 +232,9 @@ function get_checkbox_style() { @arg $default - The default action is not set @returns - null */ function set_default_action($default = '') { - global $_CACTI_REQUEST; - - if (!isset_request_var('action')) { + if (!isset_request_var('action')) { set_request_var('action', $default); - }else{ + } else { set_request_var('action', $_REQUEST['action']); } } @@ -791,16 +783,9 @@ function load_current_session_value($request_var_name, $session_var_name, $defau @arg $status - the status type of the device as defined in global_constants.php @returns - a string containing html that represents the device's current status */ function get_colored_device_status($disabled, $status) { - $status_colors = array( - HOST_DOWN => 'deviceDown', - HOST_ERROR => 'deviceError', - HOST_RECOVERING => 'deviceRecovering', - HOST_UP => 'deviceUp' - ); - if ($disabled) { return "" . __('Disabled') . ""; - }else{ + } else { switch ($status) { case HOST_DOWN: return "" . __('Down') . ""; From f98e6541b5cf6460fa53e3dcd3d9184c539f94cf Mon Sep 17 00:00:00 2001 From: patrick Date: Sat, 29 Apr 2017 00:31:28 +0200 Subject: [PATCH 14/20] Reverting changes because $user is required. --- auth_profile.php | 2 +- lib/auth.php | 152 +++++++++++++++++++++++++++++++++++++---------- 2 files changed, 121 insertions(+), 33 deletions(-) diff --git a/auth_profile.php b/auth_profile.php index 99dca9136c..1a2829a367 100644 --- a/auth_profile.php +++ b/auth_profile.php @@ -233,7 +233,7 @@ function settings() { if (is_view_allowed('graph_settings') == true) { if (read_config_option('auth_method') != 0) { - $settings_user['tree']['default_tree_id']['sql'] = get_allowed_trees(true); + $settings_user['tree']['default_tree_id']['sql'] = get_allowed_trees(false, true); } html_start_box( __('User Settings'), '100%', '', '3', 'center', ''); diff --git a/lib/auth.php b/lib/auth.php index 58c6cffce5..52cbe4f813 100644 --- a/lib/auth.php +++ b/lib/auth.php @@ -471,9 +471,9 @@ function is_tree_allowed($tree_id, $user = 0) { /* is_device_allowed - determines whether the current user is allowed to view a certain device @arg $host_id - (int) the ID of the device to check permissions for @returns - (bool) whether the current user is allowed the view the specified device or not */ -function is_device_allowed($host_id) { +function is_device_allowed($host_id, $user = 0) { $total_rows = 0; - get_allowed_devices('', '', '', $total_rows, 0, $host_id); + get_allowed_devices('', '', '', $total_rows, $user, $host_id); return ($total_rows > 0); } @@ -621,7 +621,7 @@ function is_realm_allowed($realm) { } } -function get_allowed_tree_level($tree_id, $parent_id) { +function get_allowed_tree_level($tree_id, $parent_id, $user = 0) { $items = db_fetch_assoc_prepared('SELECT gti.id, gti.title, gti.host_id, gti.local_graph_id, gti.host_grouping_type, h.description AS hostname FROM graph_tree_items AS gti @@ -638,11 +638,11 @@ function get_allowed_tree_level($tree_id, $parent_id) { if (sizeof($items)) { foreach($items as $item) { if ($item['host_id'] > 0) { - if (!is_device_allowed($item['host_id'])) { + if (!is_device_allowed($item['host_id'], $user)) { unset($items[$i]); } } elseif($item['local_graph_id'] > 0) { - if (!is_graph_allowed($item['local_graph_id'])) { + if (!is_graph_allowed($item['local_graph_id'], $user)) { unset($items[$i]); } } @@ -654,11 +654,23 @@ function get_allowed_tree_level($tree_id, $parent_id) { return $items; } -function get_allowed_tree_content($tree_id, $parent = 0) { - $sql_where = "WHERE gti.local_graph_id=0 AND gti.parent=$parent AND gti.graph_tree_id=$tree_id"; +function get_allowed_tree_content($tree_id, $parent = 0, $sql_where = '', $order_by = '', $limit = '', &$total_rows = 0, $user = 0) { + if ($limit != '') { + $limit = "LIMIT $limit"; + } + + if ($order_by != '') { + $order_by = "ORDER BY $order_by"; + } + + if ($sql_where != '') { + $sql_where = "WHERE gti.local_graph_id=0 AND gti.parent=$parent AND gti.graph_tree_id=$tree_id AND (" . $sql_where . ')'; + } else { + $sql_where = "WHERE gti.local_graph_id=0 AND gti.parent=$parent AND gti.graph_tree_id=$tree_id"; + } $trees = array_rekey( - get_allowed_trees(false, ''), + get_allowed_trees(false, false, '', '', '', $total_rows, $user), 'id', 'name' ); @@ -711,20 +723,34 @@ function get_allowed_tree_content($tree_id, $parent = 0) { } } -function get_allowed_tree_header_graphs($tree_id, $leaf_id = 0, $sql_where = '') { +function get_allowed_tree_header_graphs($tree_id, $leaf_id = 0, $sql_where = '', $order_by = 'gti.position', $limit = '', &$total_rows = 0, $user = 0) { + if ($limit != '') { + $limit = "LIMIT $limit"; + } + + if ($order_by != '') { + $order_by = "ORDER BY $order_by"; + } + if ($sql_where != '') { $sql_where = " AND ($sql_where)"; } - $order_by = 'ORDER BY gti.position'; - $sql_where = "WHERE (gti.graph_tree_id=$tree_id AND gti.parent=$leaf_id)" . $sql_where; - if (read_config_option('auth_method') != 0) { - if (isset($_SESSION['sess_user_id'])) { - $user = $_SESSION['sess_user_id']; - } else { - return array(); + if ($user == -1) { + $auth_method = 0; + } else { + $auth_method = read_config_option('auth_method'); + } + + if ($auth_method != 0) { + if ($user == 0) { + if (isset($_SESSION['sess_user_id'])) { + $user = $_SESSION['sess_user_id']; + } else { + return array(); + } } if (read_config_option('graph_auth_method') == 1) { @@ -790,7 +816,7 @@ function get_allowed_tree_header_graphs($tree_id, $leaf_id = 0, $sql_where = '') $sql_having = "HAVING $sql_having"; - return db_fetch_assoc("SELECT gti.id, gti.title, gtg.local_graph_id, + $graphs = db_fetch_assoc("SELECT gti.id, gti.title, gtg.local_graph_id, h.description, gt.name AS template_name, gtg.title_cache, gtg.width, gtg.height, gl.snmp_index, gl.snmp_query_id, $sql_select @@ -806,9 +832,27 @@ function get_allowed_tree_header_graphs($tree_id, $leaf_id = 0, $sql_where = '') $sql_join $sql_where $sql_having - $order_by"); - } else { - return db_fetch_assoc("SELECT + $order_by + $limit"); + + $total_rows = db_fetch_cell("SELECT COUNT(*) + FROM ( + SELECT $sql_select + FROM graph_templates_graph AS gtg + INNER JOIN graph_local AS gl + ON gl.id = gtg.local_graph_id + INNER JOIN graph_tree_items AS gti + ON gti.local_graph_id = gl.id + LEFT JOIN graph_templates AS gt + ON gt.id = gl.graph_template_id + LEFT JOIN host AS h + ON h.id = gl.host_id + $sql_join + $sql_where + $sql_having + ) AS rower"); + }else{ + $graphs = db_fetch_assoc("SELECT gti.id, gti.title, gtg.local_graph_id, h.description, @@ -828,8 +872,23 @@ function get_allowed_tree_header_graphs($tree_id, $leaf_id = 0, $sql_where = '') LEFT JOIN host AS h ON h.id = gl.host_id $sql_where - $order_by"); + $order_by + $limit"); + + $total_rows = db_fetch_cell("SELECT COUNT(*) + FROM graph_templates_graph AS gtg + INNER JOIN graph_local AS gl + ON gl.id=gtg.local_graph_id + INNER JOIN graph_tree_items AS gti + ON gti.local_graph_id=gl.id + LEFT JOIN graph_templates AS gt + ON gt.id=gl.graph_template_id + LEFT JOIN host AS h + ON h.id=gl.host_id + $sql_where"); } + + return $graphs; } function get_allowed_graphs($sql_where = '', $order_by = 'gtg.title_cache', $limit = '', &$total_rows = 0, $user = 0, $graph_id = 0) { @@ -1145,16 +1204,28 @@ function get_allowed_graph_templates($sql_where = '', $order_by = 'name', $limit return $graphs; } -function get_allowed_trees($return_sql = false, $order_by = 'name') { +function get_allowed_trees($edit = false, $return_sql = false, $sql_where = '', $order_by = 'name', $limit = '', &$total_rows = 0, $user = 0) { + if ($limit != '') { + $limit = "LIMIT $limit"; + } + if ($order_by != '') { $order_by = "ORDER BY $order_by"; } - if (read_config_option('auth_method') != 0) { - if (isset($_SESSION['sess_user_id'])) { - $user = $_SESSION['sess_user_id']; - } else { - return array(); + if ($user == -1) { + $auth_method = 0; + } else { + $auth_method = read_config_option('auth_method'); + } + + if ($auth_method != 0) { + if ($user == 0) { + if (isset($_SESSION['sess_user_id'])) { + $user = $_SESSION['sess_user_id']; + }else{ + return array(); + } } /* get policies for all groups and user */ @@ -1181,28 +1252,45 @@ function get_allowed_trees($return_sql = false, $order_by = 'name') { $i++; } - $sql_where = 'WHERE gt.enabled="on" AND (' . $sql_where1 . ')'; + if ($sql_where != '') { + $sql_where = 'WHERE ' . ($edit == false ? '(gt.enabled="on") AND ':'') . '(' . $sql_where . ') AND (' . $sql_where1 . ')'; + } else { + $sql_where = 'WHERE ' . ($edit == false ? '(gt.enabled="on") AND ':'') . '(gt.enabled="on") AND (' . $sql_where1 . ')'; + } $sql = "SELECT id, name FROM graph_tree AS gt $sql_join $sql_where - $order_by"; + $order_by + $limit"; if ($return_sql) { return $sql; } else { - return db_fetch_assoc($sql); + $trees = db_fetch_assoc($sql); + + $total_rows = db_fetch_cell("SELECT COUNT(gt.id) + FROM graph_tree AS gt + $sql_join + $sql_where"); } } else { - $sql_where = "WHERE enabled='on'"; + if ($sql_where != '') { + $sql_where = "WHERE enabled='on' AND $sql_where"; + } else { + $sql_where = "WHERE enabled='on'"; + } if ($return_sql) { return "SELECT id, name FROM graph_tree $sql_where $order_by"; } else { - return db_fetch_assoc("SELECT id, name FROM graph_tree AS gt $sql_where $order_by"); + $trees = db_fetch_assoc("SELECT id, name FROM graph_tree AS gt $sql_where $order_by"); + $total_rows = db_fetch_cell("SELECT COUNT(*) FROM graph_tree AS gt $sql_where"); } } + + return $trees; } function get_allowed_devices($sql_where = '', $order_by = 'description', $limit = '', &$total_rows = 0, $user = 0, $host_id = 0) { From c7e128d8eeffbef454c734427ca521529fd6647f Mon Sep 17 00:00:00 2001 From: cigamit Date: Fri, 28 Apr 2017 20:27:26 -0500 Subject: [PATCH 15/20] Resolving Issue #636 Erro when saving change to data template --- data_templates.php | 2 +- docs/CHANGELOG | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/data_templates.php b/data_templates.php index 318cef74c8..8546b448ca 100644 --- a/data_templates.php +++ b/data_templates.php @@ -247,7 +247,7 @@ function form_save() { /* push out field mappings for the data collector */ /* its important to delete first due to the possibility that * the field names were changed */ - db_execute('DELETE FROM poller_data_template_field_mappings + db_execute_prepared('DELETE FROM poller_data_template_field_mappings WHERE data_template_id = ?', array($data_template_id)); diff --git a/docs/CHANGELOG b/docs/CHANGELOG index e07eaf5fd4..a6a6d43392 100644 --- a/docs/CHANGELOG +++ b/docs/CHANGELOG @@ -18,6 +18,7 @@ Cacti CHANGELOG -issue#613: Network Automation, now requires a site or your are unable to save rules -issue#615: Data Input field length too short for longer scripts -issue#619: Export logging option in settings no longer used +-issue#635: Error when saving change to data template 1.1.4 -issue#524: Reporting not working when Tree branch is device From 235f080dbf7dd834df402c206133e673ffbe87f9 Mon Sep 17 00:00:00 2001 From: cigamit Date: Fri, 28 Apr 2017 20:53:44 -0500 Subject: [PATCH 16/20] Resolving Issue #637 When displaying tree graphs, use the same layout as preview mode --- docs/CHANGELOG | 1 + lib/html.php | 83 +++++--------------------------------------------- 2 files changed, 8 insertions(+), 76 deletions(-) diff --git a/docs/CHANGELOG b/docs/CHANGELOG index a6a6d43392..e3e05c1ea9 100644 --- a/docs/CHANGELOG +++ b/docs/CHANGELOG @@ -19,6 +19,7 @@ Cacti CHANGELOG -issue#615: Data Input field length too short for longer scripts -issue#619: Export logging option in settings no longer used -issue#635: Error when saving change to data template +-issue#637: When displaying tree graphs, use the same layout as preview mode 1.1.4 -issue#524: Reporting not working when Tree branch is device diff --git a/lib/html.php b/lib/html.php index 2ae3793772..4160d19d09 100644 --- a/lib/html.php +++ b/lib/html.php @@ -107,73 +107,9 @@ function html_graph_area(&$graph_array, $no_graphs_message = '', $extra_url_args print $header; } - $start = true; foreach ($graph_array as $graph) { - if (isset($graph['graph_template_name'])) { - if (isset($prev_graph_template_name)) { - if ($prev_graph_template_name != $graph['graph_template_name']) { - $print = true; - $prev_graph_template_name = $graph['graph_template_name']; - }else{ - $print = false; - } - }else{ - $print = true; - $prev_graph_template_name = $graph['graph_template_name']; - } - - if ($print) { - print " - - " . __('Graph Template:') . ' ' . htmlspecialchars($graph['graph_template_name']) . " - - \n"; - $i = 0; - } - }elseif (isset($graph['data_query_name'])) { - if (isset($prev_data_query_name)) { - if ($prev_data_query_name != $graph['data_query_name']) { - $print = true; - $prev_data_query_name = $graph['data_query_name']; - }else{ - $print = false; - } - }else{ - $print = true; - $prev_data_query_name = $graph['data_query_name']; - } - - if ($print) { - if (!$start) { - while(($i % $columns) != 0) { - print "\n"; - $i++; - } - - print "\n"; - } - - print " - " . __('Data Query:') . ' ' . $graph['data_query_name'] . " - \n"; - $i = 0; - } - - if (!isset($prev_sort_field_value) || $prev_sort_field_value != $graph['sort_field_value']){ - $prev_sort_field_value = $graph['sort_field_value']; - print " - - " . $graph['sort_field_value'] . " - - \n"; - $i = 0; - $j = 0; - } - } - if ($i == 0) { print "\n"; - $start = false; } ?> @@ -195,24 +131,19 @@ function html_graph_area(&$graph_array, $no_graphs_message = '', $extra_url_args \n"; - $start = true; } } - if (!$start) { - while(($i % $columns) != 0) { - print ""; - $i++; - } - - print "\n"; + while(($i % $columns) != 0) { + print ""; + $i++; } + + print "\n"; }else{ if ($no_graphs_message != '') { print "$no_graphs_message"; From ce8564d16cb746f765ba4cb1e6572197b1e3b16e Mon Sep 17 00:00:00 2001 From: Tony Roman Date: Sat, 29 Apr 2017 08:39:04 -0400 Subject: [PATCH 17/20] Remove unneeded varible from rrdcleaner code --- rrdcleaner.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rrdcleaner.php b/rrdcleaner.php index 58bc78a85f..b15e7c03cb 100644 --- a/rrdcleaner.php +++ b/rrdcleaner.php @@ -241,7 +241,7 @@ function get_files() { * Display all rrd file entries */ function list_rrd() { - global $config, $item_rows, $ds_actions, $rra_path, $hash_version_codes; + global $config, $item_rows, $ds_actions, $rra_path; /* suppress warnings */ error_reporting(0); From 33d2e4f6f3c5a7a78761f10323ca0b48ca246ec2 Mon Sep 17 00:00:00 2001 From: Tony Roman Date: Sat, 29 Apr 2017 09:10:45 -0400 Subject: [PATCH 18/20] Fix up upgrade code - moved exec called script into function for calling --- install/0_8_8h_to_1_0_0.php | 5 ++--- install/functions.php | 29 +++++++++++++++++++++++++++++ install/import_colors.php | 24 ------------------------ 3 files changed, 31 insertions(+), 27 deletions(-) delete mode 100644 install/import_colors.php diff --git a/install/0_8_8h_to_1_0_0.php b/install/0_8_8h_to_1_0_0.php index fb282d2a7d..68f8eb738b 100644 --- a/install/0_8_8h_to_1_0_0.php +++ b/install/0_8_8h_to_1_0_0.php @@ -1251,9 +1251,8 @@ function upgrade_to_1_0_0() { db_install_add_column ('colors', array('name' => 'name', 'type' => 'varchar(40)', 'default' => '', 'after' => 'id')); db_install_add_column ('colors', array('name' => 'read_only', 'type' => 'char(2)', 'default' => '', 'after' => 'hex')); - if (file_exists(dirname(__FILE__) . '/import_colors.php')) { - shell_exec('php -q ' . dirname(__FILE__) . '/import_colors.php'); - } + // import remaining colors into database + import_colors(); db_install_execute("ALTER TABLE settings MODIFY COLUMN value varchar(2048) NOT NULL default ''"); if (db_table_exists('settings_graphs', false)) { diff --git a/install/functions.php b/install/functions.php index 860511e846..f2a68507d9 100644 --- a/install/functions.php +++ b/install/functions.php @@ -522,3 +522,32 @@ function remote_update_config_file() { return $written; } + +function import_colors() { + global $config; + + if (! file_exists(dirname(__FILE__) . '/color.csv')) { + return false; + } + + $contents = file(dirname(__FILE__) . '/colors.csv'); + + if (count($contents)) { + foreach($contents as $line) { + $line = trim($line); + $parts = explode(',',$line); + $natural = $parts[0]; + $hex = $parts[1]; + $name = $parts[2]; + + $id = db_fetch_cell("SELECT hex FROM colors WHERE hex='$hex'"); + + if (!empty($id)) { + db_execute("UPDATE colors SET name='$name', read_only='on' WHERE hex='$hex'"); + }else{ + db_execute("INSERT INTO colors (name, hex, read_only) VALUES ('$name', '$hex', 'on')"); + } + } + } + return true; +} diff --git a/install/import_colors.php b/install/import_colors.php deleted file mode 100644 index 26b194728c..0000000000 --- a/install/import_colors.php +++ /dev/null @@ -1,24 +0,0 @@ - Date: Sat, 29 Apr 2017 12:17:02 -0500 Subject: [PATCH 19/20] Modifying html.php function in preparation for responsive forms --- lib/html.php | 85 ++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 60 insertions(+), 25 deletions(-) diff --git a/lib/html.php b/lib/html.php index 4160d19d09..8aa7917236 100644 --- a/lib/html.php +++ b/lib/html.php @@ -109,7 +109,7 @@ function html_graph_area(&$graph_array, $no_graphs_message = '', $extra_url_args foreach ($graph_array as $graph) { if ($i == 0) { - print "\n"; + print "\n"; } ?> @@ -224,7 +224,7 @@ function html_graph_thumbnail_area(&$graph_array, $no_graphs_message = '', $extr } if ($i == 0) { - print "\n"; + print "\n"; $start = false; } @@ -390,6 +390,13 @@ function html_header_sort($header_items, $sort_column, $sort_direction, $last_it $i = 1; foreach ($header_items as $db_column => $display_array) { + $isSort = ''; + if (isset($display_array['nohide'])) { + $nohide = 'nohide'; + }else{ + $nohide = ''; + } + if (array_key_exists('display', $display_array)) { $display_text = $display_array['display']; if ($sort_column == $db_column) { @@ -422,8 +429,6 @@ function html_header_sort($header_items, $sort_column, $sort_direction, $last_it }else{ $direction = 'ASC'; } - - $isSort = false; } } @@ -470,7 +475,6 @@ function html_header_sort($header_items, $sort_column, $sort_direction, $last_it } $display_text = $display_array[0]; - $isSort = false; } $align = 'left'; @@ -486,9 +490,9 @@ function html_header_sort($header_items, $sort_column, $sort_direction, $last_it } if (($db_column == '') || (substr_count($db_column, 'nosort'))) { - print '' . $display_text . "\n"; + print '' . $display_text . "\n"; }else{ - print '"; + print '"; print "
    " . $display_text . "
    \n"; } @@ -546,7 +550,14 @@ function html_header_sort_checkbox($header_items, $sort_column, $sort_direction, print "\n"; foreach($header_items as $db_column => $display_array) { - $icon = ''; + $isSort = ''; + if (isset($display_array['nohide'])) { + $nohide = 'nohide'; + }else{ + $nohide = ''; + } + + $icon = ''; if (array_key_exists('display', $display_array)) { $display_text = $display_array['display']; if ($sort_column == $db_column) { @@ -573,8 +584,7 @@ function html_header_sort_checkbox($header_items, $sort_column, $sort_direction, $isSort = 'secondarySort'; } }else{ - $icon = ''; - $isSort = false; + $icon = ''; if (isset($display_array['sort'])) { $direction = $display_array['sort']; }else{ @@ -621,9 +631,7 @@ function html_header_sort_checkbox($header_items, $sort_column, $sort_direction, $isSort = 'secondarySort'; } }else{ - $icon = ''; - $isSort = false; - + $icon = ''; $direction = $display_array[1]; } @@ -643,9 +651,9 @@ function html_header_sort_checkbox($header_items, $sort_column, $sort_direction, } if (($db_column == '') || (substr_count($db_column, 'nosort'))) { - print '" . $display_text . "\n"; + print '" . $display_text . "\n"; }else{ - print '"; + print '"; print "
    " . $display_text . "
    \n"; } } @@ -663,12 +671,27 @@ function html_header_sort_checkbox($header_items, $sort_column, $sort_direction, function html_header($header_items, $last_item_colspan = 1) { print "\n"; - for ($i=0; $i" . $header_items[$i]['display'] . "\n"; + $i = 0; + foreach($header_items as $item) { + if (is_array($item)) { + if (isset($item['nohide'])) { + $nohide = 'nohide'; + }else{ + $nohide = ''; + } + + if (isset($item['align'])) { + $align = $item['align']; + }else{ + $align = 'left'; + } + + print "" . $item['display'] . "\n"; }else{ - print "" . $header_items[$i] . "\n"; + print "" . $item . "\n"; } + + $i++; } print "\n"; @@ -702,11 +725,23 @@ function html_header_checkbox($header_items, $include_form = true, $form_action print "\n"; - for ($i=0; $i" . $header_items[$i]['display'] . ""; + foreach($header_items as $item) { + if (is_array($item)) { + if (isset($item['nohide'])) { + $nohide = 'nohide'; + } else { + $nohide = ''; + } + + if (isset($item['align'])) { + $align = $item['align']; + } else { + $align = 'left'; + } + + print "" . $item['display'] . ""; }else{ - print "" . $header_items[$i] . "\n"; + print "" . $item . "\n"; } } @@ -838,9 +873,9 @@ function draw_graph_items_list($item_list, $filename, $url_data, $disable_contro /* alternating row color */ if ($use_custom_class == false) { - print "\n"; + print "\n"; }else{ - print ""; + print ""; } print ''; From 494eb5bf6006308e732c99c1e3d939067d5a0bfb Mon Sep 17 00:00:00 2001 From: cigamit Date: Sat, 29 Apr 2017 16:06:10 -0500 Subject: [PATCH 20/20] More responsive work 1) Make forms responsive. Work on mobile 2) Add a new header option to not hide specific columns 3) Resize textareas and text during resize to match window size 4) Change the responsive viewport media size for going responve 5) Make classic more responvie 6) Hide tabs fully in responive mode: todo: Generalized Elipsis --- include/layout.js | 68 ++++++++-- include/themes/classic/main.css | 165 ++++++++++++++++++++++- include/themes/dark/main.css | 147 ++++++++++++++++++++- include/themes/dark/main.js | 9 +- include/themes/modern/main.css | 196 +++++++++++++++++++++++++--- include/themes/modern/main.js | 9 +- include/themes/paper-plane/main.css | 156 +++++++++++++++++++--- include/themes/paw/jquery-ui.css | 1 + include/themes/paw/main.css | 147 +++++++++++++++++++-- lib/html.php | 10 +- lib/html_form.php | 74 +++++++---- lib/html_utility.php | 12 +- 12 files changed, 881 insertions(+), 113 deletions(-) diff --git a/include/layout.js b/include/layout.js index 64bba41063..166c56b237 100644 --- a/include/layout.js +++ b/include/layout.js @@ -44,6 +44,9 @@ var columnsHidden = 0; var lastColumnsHidden = {}; var lastWidth = {}; var lastMain = 0; +var resizeDelta = 100; +var resizeTime = 0; +var resizeTimeout = false; var isMobile = { Android: function() { @@ -589,7 +592,7 @@ function applySkin() { }); $.when.apply(this, showPage).done(function() { - responsiveMenu(null); + responsiveUI(null); }); } @@ -621,15 +624,33 @@ function setupResponsiveMenuAndTabs() { }); $(window).resize(function(event) { - responsiveMenu(event); + resizeTime = new Date(); + myEvent = event; + if (resizeTimeout === false) { + resizeTimeout = true; + setTimeout(function() { + responsiveUI(myEvent); + }, resizeDelta); + } }); $(window).on('orientationchange', function() { - responsiveMenu(null); + responsiveUI(null); }); } -function responsiveMenu(event) { +function responsiveUI(event) { + if (new Date() - resizeTime < resizeDelta) { + myEvent = event; + setTimeout(function() { + responsiveUI(myEvent); + }, resizeDelta); + + return false; + } else { + resizeTimeout = false; + } + if ($('.cactiTreeNavigationArea').length > 0) { tree = true; }else{ @@ -646,7 +667,7 @@ function responsiveMenu(event) { mainWidth = $('#main').width(); } - if ($(window).width() < 780) { + if ($(window).width() < 640) { menuHide(tree); menuHideResponsive = true; }else if (menuHideResponsive == true) { @@ -662,6 +683,33 @@ function responsiveMenu(event) { menuShow(tree); } + mainWidth = $('#main').width(); + + /* change textbox and textarea widths */ + if (event != null) { + $('input[type="text"], textarea').each(function() { + //console.log('Main:'+mainWidth+', Element:'+$(this).attr('id')+', Width:'+$(this).width()); + + if ($(this).attr('type') == 'text') { + offset = 20; + }else{ + offset = 5; + } + + if (mainWidth != 100) { + if ($(this).width() > mainWidth) { + $(this).css('max-width', (mainWidth - offset)+'px'); + }else{ + $(this).css('max-width', ''); + } + + if ($(this).width() > mainWidth) { + $(this).css('max-width', (mainWidth - offset)+'px'); + } + } + }); + } + if (event != null && !$(event.target).hasClass('ui-resizable')) { height = Math.max(document.body.scrollHeight, $(window).height()); if (tree) { @@ -718,7 +766,7 @@ function tuneTable(object, width) { minColumns = 2; } - $($(object).find('th').get().reverse()).each(function() { + $($(object).find('th').not('.noHide').get().reverse()).each(function() { if (!$(this).hasClass('tableSubHeaderCheckbox') && $(this).is(':visible')) { reducedWidth += parseInt($(this).width()); $('#'+id+' th:nth-child('+column+')').hide(); @@ -991,13 +1039,13 @@ function setupCollapsible() { id=$(this).attr('id')+'_cs'; if ($(this).find('i').hasClass('fa-angle-double-up')) { $(this).addClass('collapsed'); - $(this).nextUntil('tr.spacer').slideUp('slow'); + $(this).nextUntil('div.spacer').slideUp('slow'); $(this).find('i').removeClass('fa-angle-double-up').addClass('fa-angle-double-down'); storage.set(id, 'hide'); }else{ $(this).removeClass('collapsed'); - $(this).nextUntil('tr.spacer').slideDown('slow'); - $(this).nextUntil('tr.spacer').each(function(data) { + $(this).nextUntil('div.spacer').slideDown('slow'); + $(this).nextUntil('div.spacer').each(function(data) { $(this).find('input, select').change(); }); $(this).find('i').removeClass('fa-angle-double-down').addClass('fa-angle-double-up'); @@ -1280,7 +1328,7 @@ $(function() { }); } - responsiveMenu(null); + responsiveUI(null); }); /* Graph related javascript functions */ diff --git a/include/themes/classic/main.css b/include/themes/classic/main.css index 3d1629b2a4..c605cd8405 100755 --- a/include/themes/classic/main.css +++ b/include/themes/classic/main.css @@ -11,6 +11,15 @@ body, table, tr, td, textarea { font-size: 10px; } +textarea { + padding: 5px; + width: 400px; + height: 100px; + -webkit-box-sizing: border-box; + -moz-box-sizing: border-box; + box-sizing: border-box; +} + body { background-color: #ffffff; background-repeat: repeat-y; @@ -23,7 +32,7 @@ table { } td, th, select { - padding: 2px; + padding: 0px; margin: 0px; } @@ -62,6 +71,17 @@ th .fa { height: 100%; } +input { + padding: 0.4em; + font-size: 12px; + max-width: 400px; +} + +select { + padding: 0.5em 0.5em 0.5em 0.5em; + font-size: 12px; +} + tr.selected { background-color: khaki; } @@ -84,6 +104,8 @@ label { .center { text-align:center !important; + margin-left:auto; + margin-right:auto; } .usermenudown { @@ -146,6 +168,10 @@ label { } .running { + color:orange; +} + +.errored { color:red; font-weight:bold; } @@ -646,6 +672,7 @@ ul#breadcrumbs { } .cactiContent { + clear: both; width: 100%; height: 100%; vertical-align: top; @@ -790,7 +817,7 @@ legend { float: right; margin-top: 1px; margin-left: 3px; - display: table-cell; + display: table-column; } .actionsDropdownArrow { @@ -999,7 +1026,7 @@ legend { text-align: left; padding: 2px 0px; height: 16px; - display: table-cell; + display: table-column; width: 90%; background-color: #00438c; } @@ -1008,7 +1035,7 @@ legend { float: right; padding: 2px 0px; height: 16px; - display: table-cell; + display: table-column; text-align: right; width: 10%; background-color: #00438c; @@ -1030,13 +1057,131 @@ legend { .filterTable td:first-child { width:55px; + min-width:55px; } -.formItemDescription { +.filterTable td { + padding: 2px; } -.formItemName { +.formRow { + display: table; + width: 100%; + line-height: 30px; +} + +.formColumn { + float: left; + display: table-column; +} + +.formColumnLeft { + float: left; + display: table-column; + padding-left: 4px; + width: 28%; +} + +.formColumnRight { + float: left; + display: table-column; + width: 70%; +} + +.formData { + display: inline-block; + float: left; +} + +.formFieldName { + display: inline-block; + color: #444; + float: left; + text-align: left; + white-space: nowrap; +} + +.formFieldDescription { + float: left; + text-align: left; +} + +.formTooltip { + display: inline-block; + padding-left: 4px; +} + +.formHeader { + float: left; + width: 100%; + text-align: left; + line-height: 20px; + color: #ffffff; font-weight:bold; + cursor: pointer; + vertical-align:middle; + text-align:left; + border-right: 1px groove #efefef; + font-size:11px; + background-color: #6d88ad !important; +} + +.formHeaderText { + padding-left: 3px; +} + +.formHeaderAnchor { + float:right; + padding-right:4px; +} + +.hostInfoHeader { + width: 100%; +} + +@media screen and (max-width: 640px) { + .formRow { + display: table; + width: 100%; + line-height: 30px; + } + + .formColumn { + float: left; + display: table-row; + } + + .formColumnLeft { + float: left; + display: table-row; + width: 100%; + } + + .formColumnRight { + float: left; + display: table-row; + width: 100%; +} + + .formFieldName { + color: #444; + float: left; + text-align: left; + white-space: nowrap; + } + + .formData { + float: left; + } + + .hostInfoHeader { + overflow: hidden; + } + + .queryAdd, .templateAdd, .navBar, #ping_results { + display: none; +} + } .graphItem { @@ -1106,6 +1251,7 @@ legend { vertical-align:middle; text-align:left; cursor:pointer; + padding-left: 3px; } .graphSubHeaderColumn { @@ -1318,7 +1464,7 @@ legend { float:left !important; padding:5px 4px; text-decoration:none; - font-size: 11px; + font-size: 9px; border-color: #999 #666 !important; border-style: solid solid none; border-width: 1px 1px medium; @@ -1329,6 +1475,9 @@ div#tabs { padding-bottom: 0px; float: left; vertical-align: bottom; + height: 38px; + overflow: hidden; + width: 60%; } td#tabs { @@ -1347,6 +1496,8 @@ div#gtabs { padding-bottom: 0px; vertical-align: bottom; float:right; + height: 38px; + overflow: hidden; } .tabs { diff --git a/include/themes/dark/main.css b/include/themes/dark/main.css index dd0e102706..a45b818f26 100644 --- a/include/themes/dark/main.css +++ b/include/themes/dark/main.css @@ -19,12 +19,12 @@ html, body { height: 100%; width: 100%; margin: 0px; + font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; } body { background: #161616 none repeat scroll 0 0; color: #bbbfc2; - font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 12px; } @@ -40,6 +40,11 @@ textarea { font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 1.0em; padding: 5px; + width: 400px; + height: 100px; + -webkit-box-sizing: border-box; + -moz-box-sizing: border-box; + box-sizing: border-box; } table { @@ -49,7 +54,7 @@ table { } td, th { - padding: 2px; + padding: 0px; margin: 0px; } @@ -96,7 +101,13 @@ th i.fa { z-index: 3; } -input, select { +input { + padding: 0.5em 0.5em 0.5em 0.5em; + font-size: 12px; + max-width: 400px; +} + +select { padding: 0.5em 0.5em 0.5em 0.5em; font-size: 12px; } @@ -1131,6 +1142,7 @@ legend { color: snow; font-weight: normal; padding: 2px; + white-space: nowrap; } .cactiTable { @@ -1156,6 +1168,10 @@ legend { background: linear-gradient(to bottom, #252426 0%, #0C0D0D 100%); } +.cactiTableTitle span { + padding-left: 3px; +} + .cactiTableButton { float: right; padding: 5px 0px; @@ -1184,11 +1200,119 @@ legend { min-width:55px; } -.formItemDescription { +.filterTable td { + padding: 2px; } -.formItemName { - color:snow; +.formRow { + display: table; + width: 100%; + line-height: 35px; +} + +.formColumn { + float: left; + display: table-column; +} + +.formColumnLeft { + float: left; + display: table-column; + width: 30%; +} + +.formColumnRight { + float: left; + display: table-column; + width: 70%; +} + +.formData { + display: inline-block; + float: left; +} + +.formFieldName { + display: inline-block; + color: snow; + float: left; + text-align: left; + white-space: nowrap; + padding-left: 3px; +} + +.formFieldDescription { + float: left; + text-align: left; +} + +.formTooltip { + display: inline-block; +} + +.formHeader { + float: left; + width: 100%; + text-align: left; + line-height: 25px; + background: -moz-linear-gradient(top, #45484d 0%, #000000 100%); /* FF3.6+ */ + background: -webkit-linear-gradient(top, #45484d 0%,#000000 100%); /* Chrome10+,Safari5.1+ */ + background: -o-linear-gradient(top, #45484d 0%,#000000 100%); /* Opera 11.10+ */ + background: -ms-linear-gradient(top, #45484d 0%,#000000 100%); /* IE10+ */ +} + +.formHeaderAnchor { + float:right; + padding-right:4px; +} + +.hostInfoHeader { + width: 100%; +} + +@media screen and (max-width: 640px) { + .formRow { + display: table; + width: 100%; + line-height: 30px; + } + + .formColumn { + float: left; + display: table-row; + } + + .formColumnLeft { + float: left; + display: table-row; + width: 100%; + } + + .formColumnRight { + float: left; + display: table-row; + width: 100%; + } + + .formFieldName { + color: snow; + float: left; + text-align: left; + white-space: nowrap; + padding-left: 3px; + } + + .formData { + float: left; + } + + .hostInfoHeader { + overflow: hidden; + } + + .queryAdd, .templateAdd, .navBar, #ping_results { + display: none; + } } .graphItem { @@ -1271,6 +1395,7 @@ th.secondarySort { vertical-align:middle; text-align:left; cursor:pointer; + padding-left: 3px; } .graphSubHeaderColumn { @@ -1540,6 +1665,7 @@ div#tabs { vertical-align: bottom; position: fixed; top: 5px; + width: 70%; } td#tabs { @@ -1566,6 +1692,11 @@ div#gtabs { height: 30px; } +.maintabs { + overflow: hidden; + height: 25px; +} + .tabs a, .maintabs a { -moz-border-radius:5px 5px 0 0; border-radius:5px 5px 0 0; @@ -1764,6 +1895,10 @@ ul#nav { border: transparent; } +.ui-button-text-only .ui-button-text { + padding: 0.4em; +} + div.preformatted { color: snow !important; font-size: 11px !important; diff --git a/include/themes/dark/main.js b/include/themes/dark/main.js index 1666f92f52..de1dbb914c 100644 --- a/include/themes/dark/main.js +++ b/include/themes/dark/main.js @@ -82,6 +82,8 @@ function themeReady() { $('.import_text').html(fileText); } + maxWidth = 280; + $('select').each(function() { if ($(this).prop('multiple') != true) { $(this).selectmenu({ @@ -104,7 +106,12 @@ function themeReady() { }); minWidth+=80; - $('#'+id+'-button').css('min-width', minWidth+'px').css('max-width', '400px').css('width',''); + + if (minWidth > maxWidth) { + minWidth = maxWidth; + } + + $('#'+id+'-button').css('min-width', minWidth+'px').css('max-width', maxWidth+'px').css('width',''); $('#'+id+'-menu').css('max-height', '250px'); }); }else{ diff --git a/include/themes/modern/main.css b/include/themes/modern/main.css index 00f1255c85..f3c59b19d4 100755 --- a/include/themes/modern/main.css +++ b/include/themes/modern/main.css @@ -1,5 +1,20 @@ /* main styles */ +::-webkit-scrollbar { + width: 8px; +} + +::-webkit-scrollbar-track { + -webkit-box-shadow: inset 0 0 6px rgba(22,22,6,0.7); + border-radius: 6px; +} + +::-webkit-scrollbar-thumb { + border-radius: 6px; + background: rgba(49,68,43,0.8); + -webkit-box-shadow: inset 0 0 4px rgba(49,68,43,0.5); +} + html, body { height: 100%; width: 100%; @@ -14,6 +29,15 @@ body, table, tr, td, textarea { color: #000000; } +textarea { + padding: 5px; + width: 400px; + height: 100px; + -webkit-box-sizing: border-box; + -moz-box-sizing: border-box; + box-sizing: border-box; +} + body { background-color: snow; background-repeat: repeat-y; @@ -26,7 +50,7 @@ table { } td, th { - padding: 2px; + padding: 0px; margin: 0px; } @@ -35,6 +59,16 @@ img { vertical-align:middle; } +fieldset { + border: none; + padding: 0px; + margin: 0px; +} + +.reindex_methods span { + font-size: 9px; +} + /* links */ a, a:active, a:visited { @@ -62,8 +96,15 @@ th i.fa { z-index: 3; } -input, select { - padding: 0.4em 0.4em 0.4em 0.4em; +input { + padding: 0.4em; + font-size: 12px; + max-width: 400px; +} + +select { + padding: 0.5em 0.5em 0.5em 0.5em; + font-size: 12px; } *:focus { @@ -74,15 +115,6 @@ label { white-space:nowrap; } -fieldset { - border: none; - padding: 0px; - margin: 0px; -} - -.reindex_methods span { - font-size: 9px; -} .nowrap { white-space:nowrap; @@ -102,6 +134,8 @@ fieldset { .center { text-align:center !important; + margin-left:auto; + margin-right:auto; } .usermenudown { @@ -170,6 +204,10 @@ fieldset { } .running { + color:orange; +} + +.errored { color:red; } @@ -708,6 +746,7 @@ ul#breadcrumbs { } .cactiContent { + clear: both; width: 100%; vertical-align: top; padding-top: 56px; @@ -1080,7 +1119,6 @@ legend { background: -o-linear-gradient(top, rgba(76,76,76,1) 0%, rgba(89,89,89,1) 12%, rgba(102,102,102,1) 25%, rgba(71,71,71,1) 39%, rgba(44,44,44,1) 50%, rgba(0,0,0,1) 51%, rgba(17,17,17,1) 60%, rgba(43,43,43,1) 76%, rgba(28,28,28,1) 91%, rgba(19,19,19,1) 100%); background: -ms-linear-gradient(top, rgba(76,76,76,1) 0%, rgba(89,89,89,1) 12%, rgba(102,102,102,1) 25%, rgba(71,71,71,1) 39%, rgba(44,44,44,1) 50%, rgba(0,0,0,1) 51%, rgba(17,17,17,1) 60%, rgba(43,43,43,1) 76%, rgba(28,28,28,1) 91%, rgba(19,19,19,1) 100%); background: linear-gradient(to bottom, rgba(76,76,76,1) 0%, rgba(89,89,89,1) 12%, rgba(102,102,102,1) 25%, rgba(71,71,71,1) 39%, rgba(44,44,44,1) 50%, rgba(0,0,0,1) 51%, rgba(17,17,17,1) 60%, rgba(43,43,43,1) 76%, rgba(28,28,28,1) 91%, rgba(19,19,19,1) 100%); - filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#4c4c4c', endColorstr='#131313', GradientType=0 ); } .templateHeader td { @@ -1169,13 +1207,128 @@ legend { .filterTable td:first-child { width:55px; + min-width:55px; } -.formItemDescription { +.filterTable td { + padding: 2px; } -.formItemName { - font-weight:normal; +.formRow { + display: table; + width: 100%; + line-height: 30px; +} + +.formColumn { + float: left; + display: table-column; +} + +.formColumnLeft { + float: left; + display: table-column; + width: 30%; +} + +.formColumnRight { + float: left; + display: table-column; + width: 70%; +} + +.formData { + display: inline-block; + float: left; +} + +.formFieldName { + display: inline-block; + color: #444; + float: left; + text-align: left; + white-space: nowrap; + padding-left: 3px; +} + +.formFieldDescription { + float: left; + text-align: left; +} + +.formTooltip { + display: inline-block; + padding-left: 4px; +} + +.formHeader { + float: left; + width: 100%; + text-align: left; + line-height: 20px; + background: rgba(138,179,105,1); + background: -moz-linear-gradient(top, rgba(138,179,105,1) 0%, rgba(63,117,15,1) 100%); + background: -webkit-linear-gradient(top, rgba(138,179,105,1) 0%, rgba(63,117,15,1) 100%); + background: -o-linear-gradient(top, rgba(138,179,105,1) 0%, rgba(63,117,15,1) 100%); + background: -ms-linear-gradient(top, rgba(138,179,105,1) 0%, rgba(63,117,15,1) 100%); +} + +.formHeaderText { + padding-left: 3px; +} + +.formHeaderAnchor { + float:right; + padding-right:4px; +} + +.hostInfoHeader { + width: 100%; +} + +@media screen and (max-width: 640px) { + .formRow { + display: table; + width: 100%; + line-height: 30px; + } + + .formColumn { + float: left; + display: table-row; + } + + .formColumnLeft { + float: left; + display: table-row; + width: 100%; + } + + .formColumnRight { + float: left; + display: table-row; + width: 100%; + } + + .formFieldName { + color: #444; + float: left; + text-align: left; + white-space: nowrap; + padding-left: 3px; + } + + .formData { + float: left; + } + + .hostInfoHeader { + overflow: hidden; + } + + .queryAdd, .templateAdd, .navBar, #ping_results { + display: none; + } } .graphItem { @@ -1278,7 +1431,7 @@ th.secondarySort { background: linear-gradient(to bottom, rgba(138,179,105,1) 0%, rgba(63,117,15,1) 100%); } -.formRow { +.tableRow { line-height: 20px; } @@ -1567,6 +1720,11 @@ div#gtabs { height: 30px; } +.maintabs { + overflow: hidden; + height: 25px; +} + .tabs a, .maintabs a { -moz-border-radius:5px 5px 0 0; border-radius:5px 5px 0 0; @@ -1790,6 +1948,10 @@ ul#nav { border: transparent; } +.ui-button-text-only .ui-button-text { + padding: 0.4em; +} + div.preformatted { font-family: monospace; white-space: pre; diff --git a/include/themes/modern/main.js b/include/themes/modern/main.js index fda795a3e8..e8d0c5ba36 100644 --- a/include/themes/modern/main.js +++ b/include/themes/modern/main.js @@ -73,6 +73,8 @@ function themeReady() { $('.import_text').html(fileText); } + maxWidth = 280; + $('select').each(function() { if ($(this).prop('multiple') != true) { $(this).selectmenu({ @@ -95,7 +97,12 @@ function themeReady() { }); minWidth+=80; - $('#'+id+'-button').css('min-width', minWidth+'px').css('max-width', '400px').css('width',''); + + if (minWidth > maxWidth) { + minWidth = maxWidth; + } + + $('#'+id+'-button').css('min-width', minWidth+'px').css('max-width', maxWidth+'px').css('width',''); $('#'+id+'-menu').css('max-height', '250px'); }); }else{ diff --git a/include/themes/paper-plane/main.css b/include/themes/paper-plane/main.css index 49f5290ead..8daa92e201 100644 --- a/include/themes/paper-plane/main.css +++ b/include/themes/paper-plane/main.css @@ -36,6 +36,16 @@ img { vertical-align:middle; } +fieldset { + border: none; + padding: 0px; + margin: 0px; +} + +.reindex_methods span { + font-size: 9px; +} + /* links */ a, a:active, a:visited { @@ -91,15 +101,6 @@ label { white-space:nowrap; } -fieldset { - border: none; - padding: 0px; - margin: 0px; -} - -.reindex_methods span { - font-size: 9px; -} .nowrap { white-space:nowrap; @@ -502,7 +503,7 @@ fieldset { border: none; } -.odd.formRow{ +.odd.tableRow{ color: #000000; background: none repeat scroll 0 0 #fbfdff; } @@ -511,7 +512,7 @@ fieldset { border: none; } -.even.formRow{ +.even.tableRow{ color: #000000; background: none repeat scroll 0 0 #FFFFFF; } @@ -522,12 +523,12 @@ fieldset { #box-shadow: 0 0 1px rgba(0, 0, 0, 0.1); } -.even-alternate.formRow{ +.even-alternate.tableRow{ color: #000000; background: none repeat scroll 0 0 #FFFFFF; } -.formRow { +.tableRow { padding: 4px 5px !important; } @@ -996,11 +997,11 @@ legend { background: none !important; } -#graph_view_preview2 .formRow{ +#graph_view_preview2 .tableRow{ background: none !important; } -#graph_view_tree_content2 .formRow{ +#graph_view_tree_content2 .tableRow{ background: none !important; } @@ -1183,13 +1184,125 @@ table.cactiTable { .filterTable td:first-child { width:55px; + min-width:55px; } -.formItemDescription { +.filterTable td { + padding: 2px; } -.formItemName { - font-weight:bold; +.formRow { + display: table; + width: 100%; + line-height: 35px; +} + +.formColumn { + float: left; + display: table-column; +} + +.formColumnLeft { + float: left; + display: table-column; + width: 30%; +} + +.formColumnRight { + float: left; + display: table-column; + width: 70%; +} + +.formData { + display: inline-block; + float: left; +} + +.formFieldName { + display: inline-block; + color: snow; + float: left; + text-align: left; + white-space: nowrap; + padding-left: 3px; +} + +.formFieldDescription { + float: left; + text-align: left; +} + +.formTooltip { + display: inline-block; +} + +.formHeader { + float: left; + width: 100%; + text-align: left; + line-height: 25px; + text-transform: none; + background-image: -webkit-linear-gradient(top, #3a3b3c 0%, #100000 100%); + background-image: -moz-linear-gradient(top, #3a3b3c 0%, #100000 100%); + background-image: linear-gradient(to bottom, #3a3b3c 0%, #100000 100%); + background-repeat: repeat-x; + border-bottom: 1px solid #000; +} + +.formHeaderAnchor { + float:right; + padding-right:4px; +} + +.hostInfoHeader { + width: 100%; +} + +@media screen and (max-width: 640px) { + .formRow { + display: table; + width: 100%; + line-height: 30px; + } + + .formColumn { + float: left; + display: table-row; + } + + .formColumnLeft { + float: left; + display: table-row; + width: 100%; + } + + .formColumnRight { + float: left; + display: table-row; + width: 100%; + } + + .formFieldName { + color: snow; + color: #000000; + float: left; + text-align: left; + white-space: nowrap; + padding-left: 3px; + } + + .formData { + float: left; + } + + .hostInfoHeader { + overflow: hidden; + } + + .queryAdd, .templateAdd, .navBar, #ping_results { + display: none; + } } .graphItem { @@ -1593,8 +1706,9 @@ div#gtabs { .maintabs { line-height: 32px; float: left; - width:50%; - overflow:hidden; + width: 50%; + overflow: hidden; + height: 32px; } .maintabs a { @@ -2012,4 +2126,4 @@ tr#realtime td:first-child { .hostInfoHeader { background: none repeat scroll 0 0 #fbfdff; -} \ No newline at end of file +} diff --git a/include/themes/paw/jquery-ui.css b/include/themes/paw/jquery-ui.css index 275d9e1967..9df62f879c 100644 --- a/include/themes/paw/jquery-ui.css +++ b/include/themes/paw/jquery-ui.css @@ -637,6 +637,7 @@ button.ui-button::-moz-focus-inner { position: relative; text-decoration: none; cursor: pointer; + vertical-align: middle; } .ui-selectmenu-button span.ui-icon { right: 0.5em; diff --git a/include/themes/paw/main.css b/include/themes/paw/main.css index 6c913bdadc..5735712030 100644 --- a/include/themes/paw/main.css +++ b/include/themes/paw/main.css @@ -14,6 +14,17 @@ body { overflow: hidden; } +textarea { + font-family: 'Segoe UI', 'Segoe UI Web Regular', 'Segoe UI Symbol', 'Helvetica Neue', 'BBAlpha Sans', 'S60 Sans', Arial, sans-serif; + font-size: 1.0em; + padding: 5px; + width: 400px; + height: 100px; + -webkit-box-sizing: border-box; + -moz-box-sizing: border-box; + box-sizing: border-box; +} + table { border-collapse: collapse; border-spacing: 0; border: none; @@ -21,7 +32,7 @@ table { } td, th { - padding: 2px; + padding: 0px; margin: 0px; } @@ -34,6 +45,16 @@ img { vertical-align:middle; } +fieldset { + border: none; + padding: 0px; + margin: 0px; +} + +.reindex_methods span { + font-size: 9px; +} + /* links */ a, a:active, a:visited { @@ -69,15 +90,6 @@ label { white-space:nowrap; } -fieldset { - border: none; - padding: 0px; - margin: 0px; -} - -.reindex_methods span { - font-size: 9px; -} .nowrap { white-space:nowrap; @@ -1026,13 +1038,122 @@ legend { .filterTable td:first-child { width:55px; + min-width:55px; } -.formItemDescription { +.filterTable td { + padding: 2px; } -.formItemName { - font-weight:bold; +.formRow { + display: table; + width: 100%; + line-height: 40px; +} + +.formColumn { + float: left; + display: table-column; +} + +.formColumnLeft { + float: left; + display: table-column; + width: 30%; +} + +.formColumnRight { + float: left; + display: table-column; + width: 70%; +} + +.formData { + display: inline-block; + float: left; +} + +.formFieldName { + display: inline-block; + color: #000000; + float: left; + text-align: left; + white-space: nowrap; + padding-left: 3px; +} + +.formFieldDescription { + float: left; + text-align: left; +} + +.formTooltip { + display: inline-block; +} + +.formHeader { + float: left; + width: 100%; + text-align: left; + line-height: 25px; + +} + +.formHeaderAnchor { + float:right; + padding-right:4px; +} + +.hostInfoHeader { + width: 100%; +} + +@media screen and (max-width: 640px) { + .formRow { + display: table; + width: 100%; + line-height: 30px; + } + + .formColumn { + float: left; + display: table-row; + color: #000000; + } + + .formColumnLeft { + float: left; + display: table-row; + width: 100%; + color: #000000; + } + + .formColumnRight { + float: left; + display: table-row; + width: 100%; + color: #000000; + } + + .formFieldName { + color: snow; + float: left; + text-align: left; + white-space: nowrap; + padding-left: 3px; + } + + .formData { + float: left; +} + + .hostInfoHeader { + overflow: hidden; + } + + .queryAdd, .templateAdd, .navBar, #ping_results { + display: none; + } } .graphItem { diff --git a/lib/html.php b/lib/html.php index 8aa7917236..06028a7945 100644 --- a/lib/html.php +++ b/lib/html.php @@ -688,7 +688,7 @@ function html_header($header_items, $last_item_colspan = 1) { print "" . $item['display'] . "\n"; }else{ - print "" . $item . "\n"; + print "" . $item . "\n"; } $i++; @@ -1283,19 +1283,19 @@ function html_show_tabs_left() { if (get_selected_theme() == 'classic') { if ($show_console_tab == true) { - ?><?php print __('Console');?> href="index.php"><?php print __('Console');?> 1 && $config['connection'] != 'online') { // Don't show graphs tab when offline }else{ - ?>" . __("; + }else{ + print "" . __("; } - print ".gif";?>" alt="Graphs"> 0) { + if (!isset($config_array['no_form_tag'])) { + print "
    \n"; + } + + $i = 0; + $row_class = 'odd'; + foreach ($fields_array as $field_name => $field_array) { - if ($i == 0) { - if (!isset($config_array['no_form_tag'])) { - print "\n"; - } - } - if ($field_array['method'] == 'hidden') { + print ''; }elseif ($field_array['method'] == 'hidden_zero') { + print ''; }elseif ($field_array['method'] == 'spacer') { - if (isset($field_array['collapsible']) && $field_array['collapsible'] == 'true') { - $collapsible = true; - }else{ - $collapsible = false; + if ($i > 0) { + print ''; } - print "" . $field_array['friendly_name'] . ($collapsible ? "
    ":'') . "\n"; + $collapsible = (isset($field_array['collapsible']) && $field_array['collapsible'] == 'true'); + + print "
    " . $field_array['friendly_name'] . ($collapsible ? "
    ":'') . '
    '; }else{ + // Make a row using a div if (isset($config_array['force_row_color'])) { - print ""; + print "
    "; }else{ - form_alternate_row('row_' . $field_name); + print "
    "; + if ($row_class == 'even') { + $row_class = 'odd'; + }else{ + $row_class = 'even'; + } } - print "\n" . $field_array['friendly_name'] . "\n"; + // Make a form row + print "
    "; + + print "
    " . $field_array['friendly_name']; if (read_config_option('hide_form_description') == 'on') { - print '
    ' . ((isset($field_array['description'])) ? $field_array['description'] : '') . "
    \n"; + print '
    ' . ((isset($field_array['description'])) ? $field_array['description'] : '') . "\n"; }else{ + print '
    '; print display_tooltip((isset($field_array['description'])) ? $field_array['description'] : ''); + print '
    '; } + print '
    '; if (isset($field_array['sub_checkbox'])) { - print "
    \n"; + print '
    '; form_checkbox($field_array['sub_checkbox']['name'], $field_array['sub_checkbox']['value'], $field_array['sub_checkbox']['friendly_name'], @@ -88,11 +104,19 @@ function draw_edit_form($array) { ((isset($field_array['sub_checkbox']['on_change'])) ? $field_array['sub_checkbox']['on_change'] : '')); } - print "\n\n"; + // End form title column + print '
    '; + + // New form column for content + print '
    '; draw_edit_control($field_name, $field_array); - print "\n\n"; + // End content column + print '
    '; + + // End form row + print '
    '; } $i++; @@ -291,7 +315,7 @@ function draw_edit_control($field_name, &$field_array) { form_color_dropdown( $field_name, $field_array['value'], - 'None', + __('None'), ((isset($field_array['default'])) ? $field_array['default'] : ''), ((isset($field_array['class'])) ? $field_array['class'] : ''), ((isset($field_array['on_change'])) ? $field_array['on_change'] : '') @@ -387,7 +411,7 @@ function draw_edit_control($field_name, &$field_array) { break; default: - print '' . htmlspecialchars($field_array['value'],ENT_QUOTES) . ''; + print '' . htmlspecialchars($field_array['value'], ENT_QUOTES, 'UTF-8') . ''; form_hidden_box($field_name, $field_array['value'], '', true); @@ -401,7 +425,7 @@ function draw_edit_control($field_name, &$field_array) { @arg $title - the hover title for the button @arg $action - the onClick action for the button */ function form_button($form_name, $value, $title = '', $action = '') { - print "\n":''; - print "\n"; - print ($in_form) ? "\n":''; + print "
    "; } /* form_dropdown - draws a standard html dropdown box @@ -805,7 +827,7 @@ function form_radio_button($form_name, $form_previous_value, $form_current_value $css_id = $form_name . '_' . $form_current_value; - print "\n"; + print "\n"; } /* form_text_area - draws a standard html text area box diff --git a/lib/html_utility.php b/lib/html_utility.php index 5135582687..cd88e01c9d 100644 --- a/lib/html_utility.php +++ b/lib/html_utility.php @@ -103,9 +103,9 @@ function form_alternate_row_color($row_color1, $row_color2, $row_value, $row_id } if ($row_id != '') { - print "\n"; + print "\n"; } else { - print "\n"; + print "\n"; } return $current_color; @@ -129,13 +129,13 @@ function form_alternate_row($row_id = '', $light = false, $disabled = false) { $i++; if ($row_id != '' && !$disabled && substr($row_id, 0, 4) != 'row_') { - print "\n"; + print "\n"; } elseif (substr($row_id, 0, 4) == 'row_') { - print "\n"; + print "\n"; } elseif ($row_id != '') { - print "\n"; + print "\n"; } else { - print "\n"; + print "\n"; } }