diff --git a/.github/copilot-instructions.md b/.github/copilot-instructions.md new file mode 100644 index 0000000..63de8ee --- /dev/null +++ b/.github/copilot-instructions.md @@ -0,0 +1,23 @@ +# Cacti webseer Plugin AI Instructions + +## Project Overview +This is a Cacti plugin. It integrates with the Cacti monitoring platform via the plugin hook architecture. + +## Technology Stack +- PHP 7.4+ (targeting Cacti 1.2.x compatibility) +- MySQL/MariaDB via Cacti's DB abstraction layer +- PSR-12 coding standards + +## Key Rules +- Use prepared statements (db_execute_prepared, db_fetch_row_prepared, etc.) for ALL queries with variables +- Use get_request_var() / get_filter_request_var() for ALL user input, never raw $_REQUEST/$_GET/$_POST +- Use html_escape() / htmlspecialchars() for ALL output of DB/user values in HTML context +- Use cacti_escapeshellarg() for ALL shell command arguments +- No PHP 8.0+ features (str_contains, match, union types, named args) - target PHP 7.4 +- Use ?? and ??= operators (PHP 7.4) instead of isset() ternary patterns +- All unserialize() calls must use allowed_classes => false + +## Testing +- Tests in tests/ directory +- Use Pest PHP or PHPUnit +- php -l lint check required before commit diff --git a/.github/workflows/plugin-ci-workflow.yml b/.github/workflows/plugin-ci-workflow.yml new file mode 100644 index 0000000..0d12eb6 --- /dev/null +++ b/.github/workflows/plugin-ci-workflow.yml @@ -0,0 +1,225 @@ +# +-------------------------------------------------------------------------+ +# | Copyright (C) 2004-2026 The Cacti Group | +# | | +# | This program is free software; you can redistribute it and/or | +# | modify it under the terms of the GNU General Public License | +# | as published by the Free Software Foundation; either version 2 | +# | of the License, or (at your option) any later version. | +# | | +# | This program is distributed in the hope that it will be useful, | +# | but WITHOUT ANY WARRANTY; without even the implied warranty of | +# | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | +# | GNU General Public License for more details. | +# +-------------------------------------------------------------------------+ +# | Cacti: The Complete RRDtool-based Graphing Solution | +# +-------------------------------------------------------------------------+ +# | This code is designed, written, and maintained by the Cacti Group. See | +# | about.php and/or the AUTHORS file for specific developer information. | +# +-------------------------------------------------------------------------+ +# | http://www.cacti.net/ | +# +-------------------------------------------------------------------------+ + +name: Plugin Integration Tests + +on: + push: + branches: + - main + - develop + pull_request: + branches: + - main + - develop + +jobs: + integration-test: + runs-on: ${{ matrix.os }} + + strategy: + fail-fast: false + matrix: + php: ['8.1', '8.2', '8.3', '8.4'] + os: [ubuntu-latest] + + services: + mariadb: + image: mariadb:10.6 + env: + MYSQL_ROOT_PASSWORD: cactiroot + MYSQL_DATABASE: cacti + MYSQL_USER: cactiuser + MYSQL_PASSWORD: cactiuser + ports: + - 3306:3306 + options: >- + --health-cmd="mysqladmin ping" + --health-interval=10s + --health-timeout=5s + --health-retries=3 + + name: PHP ${{ matrix.php }} Integration Test on ${{ matrix.os }} + + steps: + - name: Checkout Cacti + uses: actions/checkout@v4 + with: + repository: Cacti/cacti + path: cacti + + - name: Checkout webseer Plugin + uses: actions/checkout@v4 + with: + path: cacti/plugins/webseer + + - name: Install PHP ${{ matrix.php }} + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + extensions: intl, mysql, gd, ldap, gmp, xml, curl, json, mbstring + ini-values: "post_max_size=256M, max_execution_time=60, date.timezone=America/New_York" + + - name: Check PHP version + run: php -v + + - name: Run apt-get update + run: sudo apt-get update + + - name: Install System Dependencies + run: sudo apt-get install -y apache2 snmp snmpd rrdtool fping + + - name: Start SNMPD Agent and Test + run: | + sudo systemctl start snmpd + sudo snmpwalk -c public -v2c -On localhost .1.3.6.1.2.1.1 + + - name: Setup Permissions + run: | + sudo chown -R www-data:runner ${{ github.workspace }}/cacti + sudo find ${{ github.workspace }}/cacti -type d -exec chmod 775 {} \; + sudo find ${{ github.workspace }}/cacti -type f -exec chmod 664 {} \; + sudo chmod +x ${{ github.workspace }}/cacti/cmd.php + sudo chmod +x ${{ github.workspace }}/cacti/poller.php + + - name: Create MySQL Config + run: | + echo -e "[client]\nuser = root\npassword = cactiroot\nhost = 127.0.0.1\n" > ~/.my.cnf + cat ~/.my.cnf + + - name: Initialize Cacti Database + env: + MYSQL_AUTH_USR: '--defaults-file=~/.my.cnf' + run: | + mysql $MYSQL_AUTH_USR -e 'CREATE DATABASE IF NOT EXISTS cacti;' + mysql $MYSQL_AUTH_USR -e "CREATE USER IF NOT EXISTS 'cactiuser'@'localhost' IDENTIFIED BY 'cactiuser';" + mysql $MYSQL_AUTH_USR -e "GRANT ALL PRIVILEGES ON cacti.* TO 'cactiuser'@'localhost';" + mysql $MYSQL_AUTH_USR -e "GRANT SELECT ON mysql.time_zone_name TO 'cactiuser'@'localhost';" + mysql $MYSQL_AUTH_USR -e "FLUSH PRIVILEGES;" + mysql $MYSQL_AUTH_USR cacti < ${{ github.workspace }}/cacti/cacti.sql + mysql $MYSQL_AUTH_USR -e "INSERT INTO settings (name, value) VALUES ('path_php_binary', '/usr/bin/php')" cacti + + - name: Validate composer files + run: | + cd ${{ github.workspace }}/cacti + if [ -f composer.json ]; then + composer validate --strict || true + fi + + - name: Install Composer Dependencies + run: | + cd ${{ github.workspace }}/cacti + if [ -f composer.json ]; then + sudo composer install --prefer-dist --no-progress + fi + + - name: Create Cacti config.php + run: | + cat ${{ github.workspace }}/cacti/include/config.php.dist | \ + sed -r "s/localhost/127.0.0.1/g" | \ + sed -r "s/'cacti'/'cacti'/g" | \ + sed -r "s/'cactiuser'/'cactiuser'/g" | \ + sed -r "s/'cactiuser'/'cactiuser'/g" > ${{ github.workspace }}/cacti/include/config.php + sudo chmod 664 ${{ github.workspace }}/cacti/include/config.php + + - name: Configure Apache + run: | + cat << 'EOF' | sed 's#GITHUB_WORKSPACE#${{ github.workspace }}#g' > /tmp/cacti.conf + + ServerAdmin webmaster@localhost + DocumentRoot GITHUB_WORKSPACE/cacti + + + Options Indexes FollowSymLinks + AllowOverride All + Require all granted + + + ErrorLog ${APACHE_LOG_DIR}/error.log + CustomLog ${APACHE_LOG_DIR}/access.log combined + + EOF + sudo cp /tmp/cacti.conf /etc/apache2/sites-available/000-default.conf + sudo systemctl restart apache2 + + - name: Install Cacti via CLI + run: | + cd ${{ github.workspace }}/cacti + sudo php cli/install_cacti.php --accept-eula --install --force + + - name: Install webseer Plugin + run: | + cd ${{ github.workspace }}/cacti + sudo php cli/plugin_manage.php --plugin=webseer --install --enable + +# - name: import webseer Plugin Sample Data +# run: | +# cd ${{ github.workspace }}/cacti/plugins/webseer +# sudo php cli_import.php --filename=.github/workflows/webseer_sample_data.xml +# if [ $? -ne 0 ]; then +# echo "Failed to import Thold sample data" +# exit 1 +# fi + + - name: Check PHP Syntax for Plugin + run: | + cd ${{ github.workspace }}/cacti/plugins/webseer + if find . -name '*.php' -exec php -l {} 2>&1 \; | grep -iv 'no syntax errors detected'; then + echo "Syntax errors found!" + exit 1 + fi + + - name: Remove the plugins directory exclusion from the .phpstan.neon + run: sed '/plugins/d' -i .phpstan.neon + working-directory: ${{ github.workspace }}/cacti + + - name: Mark composer scripts executable + run: sudo chmod +x ${{ github.workspace }}/cacti/include/vendor/bin/* + + - name: Run Linter on base code + run: composer run-script lint ${{ github.workspace }}/cacti/plugins/webseer + working-directory: ${{ github.workspace }}/cacti + + - name: Checking coding standards on base code + run: composer run-script phpcsfixer ${{ github.workspace }}/cacti/plugins/webseer + working-directory: ${{ github.workspace }}/cacti + +# - name: Run PHPStan at Level 6 on base code outside of Composer due to technical issues +# run: ./include/vendor/bin/phpstan analyze --level 6 ${{ github.workspace }}/cacti/plugins/webseer +# working-directory: ${{ github.workspace }}/cacti + + - name: Run Cacti Poller + run: | + cd ${{ github.workspace }}/cacti + sudo php poller.php --poller=1 --force --debug + if ! grep -q "SYSTEM STATS" log/cacti.log; then + echo "Cacti poller did not finish successfully" + cat log/cacti.log + exit 1 + fi + + - name: View Cacti Logs + if: always() + run: | + if [ -f ${{ github.workspace }}/cacti/log/cacti.log ]; then + echo "=== Cacti Log ===" + sudo cat ${{ github.workspace }}/cacti/log/cacti.log + fi diff --git a/classes/cURL.php b/classes/cURL.php index d263e71..74a002c 100644 --- a/classes/cURL.php +++ b/classes/cURL.php @@ -57,7 +57,7 @@ function __construct($cookies = true, $cookie = 'cookies.txt', $compression = WE $this->cookies = $cookies; $this->debug = $debug; - if ($this->cookies === true){ + if ($this->cookies === true) { $this->cookie($cookie); } @@ -67,7 +67,7 @@ function __construct($cookies = true, $cookie = 'cookies.txt', $compression = WE $this->compression = 0; } - $this->results = array('result' => 0, 'time' => time(), 'error' => ''); + $this->results = ['result' => 0, 'time' => time(), 'error' => '']; $this->bundle = $config['base_path'] . '/plugins/webseer/ca-bundle.crt'; } @@ -78,36 +78,37 @@ function cookie($cookie_file) { $this->cookie_file = $cookie_file; } elseif (is_writable($cookie_file)) { $this->cookie_file = $cookie_file; - }else{ + } else { $this->results['error'] = 'The cookie file could not be opened. Make sure this directory has the correct permissions'; } } - function post($url, $data = array()) { + function post($url, $data = []) { global $httpcompressions; $this->debug('Executing Post Request'); - $process = curl_init($url); + $process = curl_init($url); $this->headers[] = 'Content-type: application/x-www-form-urlencoded;charset=UTF-8'; - $d = array(); + $d = []; + foreach ($data as $i => $j) { $d[] = "$i=$j"; } $data = implode('&', $d); - $options = array( - CURLOPT_HTTPHEADER => $this->headers, - CURLOPT_HEADER => true, - CURLOPT_USERAGENT => $this->user_agent, - CURLOPT_TIMEOUT => 4, - CURLOPT_POSTFIELDS => $data, + $options = [ + CURLOPT_HTTPHEADER => $this->headers, + CURLOPT_HEADER => true, + CURLOPT_USERAGENT => $this->user_agent, + CURLOPT_TIMEOUT => 4, + CURLOPT_POSTFIELDS => $data, CURLOPT_RETURNTRANSFER => true, CURLOPT_FOLLOWLOCATION => true, - CURLOPT_POST => true, - ); + CURLOPT_POST => true, + ]; if (!empty($this->compression)) { $options[CURLOPT_ENCODING] = $httpcompressions[$this->compression]; @@ -135,7 +136,7 @@ function get() { $process = curl_init($url); - $options = array( + $options = [ CURLOPT_HEADER => true, CURLOPT_USERAGENT => $this->user_agent, CURLOPT_RETURNTRANSFER => true, @@ -143,7 +144,7 @@ function get() { CURLOPT_MAXREDIRS => 4, CURLOPT_TIMEOUT => $this->host['timeout_trigger'], CURLOPT_FAILONERROR => ($this->host['requiresauth'] == '' ? true : false), - ); + ]; if (!empty($this->compression)) { $options[CURLOPT_ENCODING] = $httpcompressions[$this->compression]; @@ -152,50 +153,50 @@ function get() { // CURLOPT_ENCODING => $this->compression, // CURLOPT_VERBOSE => 1, - // if ($this->cookies == TRUE) CURLOPT_COOKIEFILE => $this->cookie_file, // if ($this->cookies == TRUE) CURLOPT_COOKIEJAR => $this->cookie_file, - // CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_0, // CURLOPT_SSLVERSION => 3, // FORCE SSL v3 if ($this->proxy_hostname != '') { $port_http = intval($this->proxy_http_port); + if ($port_http < 0 || $port_http > 65535) { - $port_http = 80; + $port_http = 80; $this->proxy_http_port = $port_http; } $port_https = intval($this->proxy_https_port); + if ($port_https < 0 || $port_https > 65535) { - $port_https = 443; + $port_https = 443; $this->proxy_https_port = $port_http; } $is_https = (substr(strtolower($url), 0, 5) == 'https'); - $proxy_opts = array( + $proxy_opts = [ CURLOPT_UNRESTRICTED_AUTH => true, CURLOPT_PROXY => $this->proxy_hostname, CURLOPT_PROXYPORT => $is_https ? $port_https : $port_http, - ); + ]; if ($this->proxy_username != '') { $proxy_opts[CURLOPT_PROXYUSERPWD] = $this->proxy_username . ':' . $this->proxy_password; } } else { - $proxy_opts = array(); + $proxy_opts = []; } // Disable Cert checking for now if ($this->host['checkcert'] == '') { - $cert_opts = array( - CURLOPT_SSL_VERIFYPEER => FALSE, - CURLOPT_SSL_VERIFYHOST => FALSE, - ); + $cert_opts = [ + CURLOPT_SSL_VERIFYPEER => false, + CURLOPT_SSL_VERIFYHOST => false, + ]; } else { - $cert_opts = array(); + $cert_opts = []; } $options += $proxy_opts; @@ -206,14 +207,15 @@ function get() { $data = curl_exec($process); - $this->data = str_replace(array("'", "\\"), array(''), $data); + $this->data = str_replace(["'", '\\'], [''], $data); - $this->results['options'] = curl_getinfo($process); + $this->results['options'] = curl_getinfo($process); $this->results['options']['compression'] = $this->compression; $errnum = curl_errno($process); $this->debug('cURL errno: ' . $errnum); + if ($errnum) { $this->debug('cURL error: ' . curl_error($process)); } @@ -222,7 +224,7 @@ function get() { case 0: break; default: - $this->results['error'] = 'HTTP ERROR: ' . str_replace(array('"', "'"), '', (curl_error($process))); + $this->results['error'] = 'HTTP ERROR: ' . str_replace(['"', "'"], '', (curl_error($process))); break; } @@ -236,10 +238,10 @@ function get() { if (strpos($data, $this->host['search_failed']) !== false) { $this->results['error'] = 'Failure Search string found!'; } else { - $this->results['error'] = ''; + $this->results['error'] = ''; $this->results['result'] = 1; } - }elseif ($errnum == 0) { + } elseif ($errnum == 0) { $this->debug('Processing search'); if ($this->host['search'] != '') { diff --git a/classes/index.php b/classes/index.php index 9a6d459..a16f0e6 100644 --- a/classes/index.php +++ b/classes/index.php @@ -23,4 +23,3 @@ */ header('Location: ../index.php'); - diff --git a/classes/mxlookup.php b/classes/mxlookup.php index 52182b3..490d9b6 100644 --- a/classes/mxlookup.php +++ b/classes/mxlookup.php @@ -23,12 +23,12 @@ */ class mxlookup { - var $dns_socket = NULL; + var $dns_socket = null; var $QNAME = ''; - var $dns_packet = NULL; + var $dns_packet = null; var $ANCOUNT = 0; var $cIx = 0; - var $arrMX = array(); + var $arrMX = []; var $dns_repl_domain; function __construct($domain, $dns = '4.2.2.1') { @@ -55,6 +55,7 @@ function __construct($domain, $dns = '4.2.2.1') { for ($ic = 1; $ic <= $this->ANCOUNT; $ic++) { $QTYPE = ord($this->gdi($this->cIx)); + if ($QTYPE !== 1) { print('[Record not returned]'); die(); @@ -62,13 +63,13 @@ function __construct($domain, $dns = '4.2.2.1') { $this->cIx += 8; - $ip = ord($this->gdi($this->cIx)) . '.' . ord($this->gdi($this->cIx)) . '.' . ord($this->gdi($this->cIx)) . '.' . ord($this->gdi($this->cIx)); + $ip = ord($this->gdi($this->cIx)) . '.' . ord($this->gdi($this->cIx)) . '.' . ord($this->gdi($this->cIx)) . '.' . ord($this->gdi($this->cIx)); $this->arrMX[] = $ip; - //$mxPref = ord($this->gdi($this->cIx)); - //$this->parse_data($curmx); - //$this->arrMX[] = array('MX_Pref' => $mxPref, 'MX' => $curmx); - //$this->cIx += 3; + // $mxPref = ord($this->gdi($this->cIx)); + // $this->parse_data($curmx); + // $this->arrMX[] = array('MX_Pref' => $mxPref, 'MX' => $curmx); + // $this->cIx += 3; } } @@ -77,24 +78,25 @@ function __destruct() { } function parse_data(&$retval) { - $arName = array(); + $arName = []; $byte = ord($this->gdi($this->cIx)); - while($byte !== 0) { - if ($byte == 192) { //compressed - $tmpIx = $this->cIx; + while ($byte !== 0) { + if ($byte == 192) { // compressed + $tmpIx = $this->cIx; $this->cIx = ord($this->gdi($cIx)); - $tmpName = $retval; + $tmpName = $retval; $this->parse_data($tmpName); - $retval=$retval . '.' . $tmpName; - $this->cIx = $tmpIx+1; + $retval = $retval . '.' . $tmpName; + $this->cIx = $tmpIx + 1; + return; } - $retval=''; + $retval = ''; $bCount = $byte; - for($b=0;$b<$bCount;$b++) { + for ($b = 0; $b < $bCount; $b++) { $retval .= $this->gdi($this->cIx); } @@ -105,29 +107,29 @@ function parse_data(&$retval) { $retval = join('.',$arName); } - function gdi(&$cIx,$bytes=1) { + function gdi(&$cIx,$bytes = 1) { $this->cIx++; - return(substr($this->dns_reply, $this->cIx-1, $bytes)); + return (substr($this->dns_reply, $this->cIx - 1, $bytes)); } function QNAME($domain) { $dot_pos = 0; $temp = ''; - while($dot_pos = strpos($domain, '.')) { + while ($dot_pos = strpos($domain, '.')) { $temp = substr($domain, 0, $dot_pos); $domain = substr($domain, $dot_pos + 1); $this->QNAME .= chr(strlen($temp)) . $temp; } - $this->QNAME .= chr(strlen($domain)) . $domain.chr(0); + $this->QNAME .= chr(strlen($domain)) . $domain . chr(0); } function gord($ln = 1) { $reply = ''; - for($i = 0; $i < $ln; $i++){ + for ($i = 0; $i < $ln; $i++) { $reply .= ord(substr($this->dns_reply, $this->cIx, 1)); $this->cIx++; } @@ -137,14 +139,14 @@ function gord($ln = 1) { function pack_dns_packet() { $this->dns_packet = - chr(0).chr(1). - chr(1).chr(0). - chr(0).chr(1). - chr(0).chr(0). - chr(0).chr(0). - chr(0).chr(0). + chr(0) . chr(1) . + chr(1) . chr(0) . + chr(0) . chr(1) . + chr(0) . chr(0) . + chr(0) . chr(0) . + chr(0) . chr(0) . $this->QNAME . - chr(0).chr(1). - chr(0).chr(1); + chr(0) . chr(1) . + chr(0) . chr(1); } } diff --git a/includes/arrays.php b/includes/arrays.php index ce451fd..f87223d 100644 --- a/includes/arrays.php +++ b/includes/arrays.php @@ -24,12 +24,12 @@ include_once(__DIR__ . '/constants.php'); -global $webseer_actions_proxy, $webseer_actions_url, $webseer_actions_server, - $webseer_proxy_fields, $webseer_server_fields, $webseer_url_fields, - $webseer_notify_accounts, $httperrors, $httpcompressions, $webseer_seconds, - $webseer_minutes; +global $webseer_actions_proxy, $webseer_actions_url, $webseer_actions_server, +$webseer_proxy_fields, $webseer_server_fields, $webseer_url_fields, +$webseer_notify_accounts, $httperrors, $httpcompressions, $webseer_seconds, +$webseer_minutes; -$httperrors = array( +$httperrors = [ 0 => 'Unable to Connect', 100 => 'Continue', 101 => 'Switching Protocols', @@ -72,9 +72,9 @@ 503 => 'Service Unavailable', 504 => 'Gateway Timeout', 505 => 'HTTP Version Not Supported', -); +]; -$httpcompressions = array( +$httpcompressions = [ 0 => '', 1 => 'aes128gcm', 2 => 'br', @@ -87,9 +87,9 @@ 9 => 'x-compress', 10 => 'x-gzip', 11 => 'zstd', -); +]; -$webseer_minutes = array( +$webseer_minutes = [ 1 => __('%d Minute', 1, 'webseer'), 2 => __('%d Minutes', 2, 'webseer'), 3 => __('%d Minutes', 3, 'webseer'), @@ -100,9 +100,9 @@ 8 => __('%d Minutes', 8, 'webseer'), 9 => __('%d Minutes', 9, 'webseer'), 10 => __('%d Minutes', 10, 'webseer'), -); +]; -$webseer_seconds = array( +$webseer_seconds = [ 3 => __('%d Seconds', 3, 'webseer'), 4 => __('%d Seconds', 4, 'webseer'), 5 => __('%d Seconds', 5, 'webseer'), @@ -111,12 +111,12 @@ 8 => __('%d Seconds', 8, 'webseer'), 9 => __('%d Seconds', 9, 'webseer'), 10 => __('%d Seconds', 10, 'webseer'), -); +]; -$webseer_notify_formats = array( +$webseer_notify_formats = [ WEBSEER_FORMAT_HTML => 'html', WEBSEER_FORMAT_PLAIN => 'plain', -); +]; if (db_table_exists('plugin_webseer_contacts')) { $webseer_contact_users = db_fetch_assoc("SELECT pwc.id, pwc.data, pwc.type, ua.full_name @@ -125,316 +125,317 @@ ON ua.id=pwc.user_id WHERE pwc.data != ''"); } else { - $webseer_contact_users = array(); + $webseer_contact_users = []; } -$webseer_notify_accounts = array(); +$webseer_notify_accounts = []; + if (!empty($webseer_contact_users)) { foreach ($webseer_contact_users as $webseer_contact_user) { $webseer_notify_accounts[$webseer_contact_user['id']] = $webseer_contact_user['full_name'] . ' - ' . ucfirst($webseer_contact_user['type']); } } -/**** Actions ****/ +// Actions -$webseer_actions_proxy = array( +$webseer_actions_proxy = [ WEBSEER_ACTION_PROXY_DELETE => __('Delete', 'webseer'), -); +]; -$webseer_actions_url = array( +$webseer_actions_url = [ WEBSEER_ACTION_URL_DELETE => __('Delete', 'webseer'), WEBSEER_ACTION_URL_DISABLE => __('Disable', 'webseer'), WEBSEER_ACTION_URL_ENABLE => __('Enable', 'webseer'), WEBSEER_ACTION_URL_DUPLICATE => __('Duplicate', 'webseer'), -); +]; -$webseer_actions_server = array( +$webseer_actions_server = [ WEBSEER_ACTION_SERVER_DELETE => __('Delete', 'webseer'), WEBSEER_ACTION_SERVER_DISABLE => __('Disable', 'webseer'), WEBSEER_ACTION_SERVER_ENABLE => __('Enable', 'webseer'), -); +]; -/**** Form Fields ****/ +// Form Fields -$webseer_proxy_fields = array( - 'name' => array( - 'method' => 'textbox', +$webseer_proxy_fields = [ + 'name' => [ + 'method' => 'textbox', 'friendly_name' => __('Name'), - 'description' => __('A Useful Name for this Proxy.'), - 'value' => '|arg1:name|', - 'max_length' => '40', - 'size' => '40', - 'default' => __('New Proxy') - ), - 'hostname' => array( - 'method' => 'textbox', + 'description' => __('A Useful Name for this Proxy.'), + 'value' => '|arg1:name|', + 'max_length' => '40', + 'size' => '40', + 'default' => __('New Proxy') + ], + 'hostname' => [ + 'method' => 'textbox', 'friendly_name' => __('Hostname'), - 'description' => __('The Proxy Hostname.'), - 'value' => '|arg1:hostname|', - 'max_length' => '64', - 'size' => '40', - 'default' => '' - ), - 'http_port' => array( - 'method' => 'textbox', + 'description' => __('The Proxy Hostname.'), + 'value' => '|arg1:hostname|', + 'max_length' => '64', + 'size' => '40', + 'default' => '' + ], + 'http_port' => [ + 'method' => 'textbox', 'friendly_name' => __('HTTP Port'), - 'description' => __('The HTTP Proxy Port.'), - 'value' => '|arg1:http_port|', - 'max_length' => '5', - 'size' => '5', - 'default' => '80' - ), - 'https_port' => array( - 'method' => 'textbox', + 'description' => __('The HTTP Proxy Port.'), + 'value' => '|arg1:http_port|', + 'max_length' => '5', + 'size' => '5', + 'default' => '80' + ], + 'https_port' => [ + 'method' => 'textbox', 'friendly_name' => __('HTTPS Port'), - 'description' => __('The HTTPS Proxy Port.'), - 'value' => '|arg1:https_port|', - 'max_length' => '5', - 'size' => '5', - 'default' => '443' - ), - 'username' => array( - 'method' => 'textbox', + 'description' => __('The HTTPS Proxy Port.'), + 'value' => '|arg1:https_port|', + 'max_length' => '5', + 'size' => '5', + 'default' => '443' + ], + 'username' => [ + 'method' => 'textbox', 'friendly_name' => __('User Name'), - 'description' => __('The user to use to authenticate with the Proxy if any.'), - 'value' => '|arg1:username|', - 'max_length' => '64', - 'size' => '40', - 'default' => '' - ), - 'password' => array( - 'method' => 'textbox_password', + 'description' => __('The user to use to authenticate with the Proxy if any.'), + 'value' => '|arg1:username|', + 'max_length' => '64', + 'size' => '40', + 'default' => '' + ], + 'password' => [ + 'method' => 'textbox_password', 'friendly_name' => __('Password'), - 'description' => __('The user password to use to authenticate with the Proxy if any.'), - 'value' => '|arg1:password|', - 'max_length' => '40', - 'size' => '40', - 'default' => '' - ), - 'id' => array( + 'description' => __('The user password to use to authenticate with the Proxy if any.'), + 'value' => '|arg1:password|', + 'max_length' => '40', + 'size' => '40', + 'default' => '' + ], + 'id' => [ 'method' => 'hidden_zero', - 'value' => '|arg1:id|' - ), - 'save_component_proxy' => array( + 'value' => '|arg1:id|' + ], + 'save_component_proxy' => [ 'method' => 'hidden', - 'value' => '1' - ) -); + 'value' => '1' + ] +]; -$webseer_server_fields = array( - 'general_spacer' => array( - 'method' => 'spacer', +$webseer_server_fields = [ + 'general_spacer' => [ + 'method' => 'spacer', 'friendly_name' => __('General Settings', 'webseer') - ), - 'name' => array( - 'method' => 'textbox', + ], + 'name' => [ + 'method' => 'textbox', 'friendly_name' => __('Name', 'webseer'), - 'description' => __('Display Name of this server', 'webseer'), - 'value' => '|arg1:name|', - 'max_length' => '256', - ), - 'enabled' => array( - 'method' => 'checkbox', + 'description' => __('Display Name of this server', 'webseer'), + 'value' => '|arg1:name|', + 'max_length' => '256', + ], + 'enabled' => [ + 'method' => 'checkbox', 'friendly_name' => __('Enable Server', 'webseer'), - 'description' => __('Uncheck this box to disabled this server from checking urls.', 'webseer'), - 'value' => '|arg1:enabled|', - 'default' => '', - ), - 'isme' => array( - 'method' => 'checkbox', + 'description' => __('Uncheck this box to disabled this server from checking urls.', 'webseer'), + 'value' => '|arg1:enabled|', + 'default' => '', + ], + 'isme' => [ + 'method' => 'checkbox', 'friendly_name' => __('Is this server the local server?', 'webseer'), - 'description' => __('Check this box if the current server you are connected to is this entry.', 'webseer'), - 'value' => '|arg1:isme|', - 'default' => '', - ), - 'master' => array( - 'method' => 'checkbox', + 'description' => __('Check this box if the current server you are connected to is this entry.', 'webseer'), + 'value' => '|arg1:isme|', + 'default' => '', + ], + 'master' => [ + 'method' => 'checkbox', 'friendly_name' => __('Master Server', 'webseer'), - 'description' => __('Sets this server to the Master server. The Master server handles all Email operations', 'webseer'), - 'value' => '|arg1:master|', - 'default' => '', - ), - 'ip' => array( - 'method' => 'textbox', + 'description' => __('Sets this server to the Master server. The Master server handles all Email operations', 'webseer'), + 'value' => '|arg1:master|', + 'default' => '', + ], + 'ip' => [ + 'method' => 'textbox', 'friendly_name' => __('IP Address', 'webseer'), - 'description' => __('IP Address to connect to this server', 'webseer'), - 'value' => '|arg1:ip|', - 'max_length' => '256', - ), - 'url' => array( - 'method' => 'textbox', + 'description' => __('IP Address to connect to this server', 'webseer'), + 'value' => '|arg1:ip|', + 'max_length' => '256', + ], + 'url' => [ + 'method' => 'textbox', 'friendly_name' => __('URL', 'webseer'), - 'description' => __('This is the URL to connect to remote.php on this server.', 'webseer'), - 'value' => '|arg1:url|', - 'max_length' => '256', - ), - 'location' => array( - 'method' => 'textbox', + 'description' => __('This is the URL to connect to remote.php on this server.', 'webseer'), + 'value' => '|arg1:url|', + 'max_length' => '256', + ], + 'location' => [ + 'method' => 'textbox', 'friendly_name' => __('Location', 'webseer'), - 'description' => __('Location of this server', 'webseer'), - 'value' => '|arg1:location|', - 'max_length' => '256', - ), - 'id' => array( + 'description' => __('Location of this server', 'webseer'), + 'value' => '|arg1:location|', + 'max_length' => '256', + ], + 'id' => [ 'method' => 'hidden_zero', - 'value' => '|arg1:id|' - ), -); + 'value' => '|arg1:id|' + ], +]; -$webseer_url_fields = array( - 'general_spacer' => array( - 'method' => 'spacer', +$webseer_url_fields = [ + 'general_spacer' => [ + 'method' => 'spacer', 'friendly_name' => __('General Settings', 'webseer') - ), - 'display_name' => array( - 'method' => 'textbox', + ], + 'display_name' => [ + 'method' => 'textbox', 'friendly_name' => __('Service Check Name', 'webseer'), - 'description' => __('The name that is displayed for this Service Check, and is included in any Alert notifications.', 'webseer'), - 'value' => '|arg1:display_name|', - 'max_length' => '256', - ), - 'enabled' => array( - 'method' => 'checkbox', + 'description' => __('The name that is displayed for this Service Check, and is included in any Alert notifications.', 'webseer'), + 'value' => '|arg1:display_name|', + 'max_length' => '256', + ], + 'enabled' => [ + 'method' => 'checkbox', 'friendly_name' => __('Enable Service Check', 'webseer'), - 'description' => __('Uncheck this box to disabled this url from being checked.', 'webseer'), - 'value' => '|arg1:enabled|', - 'default' => 'on', - ), - 'url' => array( - 'method' => 'textarea', + 'description' => __('Uncheck this box to disabled this url from being checked.', 'webseer'), + 'value' => '|arg1:enabled|', + 'default' => 'on', + ], + 'url' => [ + 'method' => 'textarea', 'friendly_name' => __('URL', 'webseer'), - 'description' => __('The URL to Monitor', 'webseer'), - 'value' => '|arg1:url|', + 'description' => __('The URL to Monitor', 'webseer'), + 'value' => '|arg1:url|', 'textarea_rows' => '3', 'textarea_cols' => '80', - ), - 'ip' => array( - 'method' => 'textbox', + ], + 'ip' => [ + 'method' => 'textbox', 'friendly_name' => __('IP Address', 'webseer'), - 'description' => __('Enter an IP address to connect to. Leaving blank will use DNS Resolution instead.', 'webseer'), - 'value' => '|arg1:ip|', - 'max_length' => '40', - 'size' => '30' - ), - 'proxy_server' => array( - 'method' => 'drop_sql', + 'description' => __('Enter an IP address to connect to. Leaving blank will use DNS Resolution instead.', 'webseer'), + 'value' => '|arg1:ip|', + 'max_length' => '40', + 'size' => '30' + ], + 'proxy_server' => [ + 'method' => 'drop_sql', 'friendly_name' => __('Proxy Server', 'webseer'), - 'description' => __('If this connection text requires a proxy, select it here. Otherwise choose \'None\'.', 'webseer'), - 'value' => '|arg1:proxy_server|', - 'none_value' => __('None', 'webseer'), - 'default' => '0', - 'sql' => 'SELECT id, name FROM plugin_webseer_proxies ORDER by name' - ), - 'compression' => array( + 'description' => __('If this connection text requires a proxy, select it here. Otherwise choose \'None\'.', 'webseer'), + 'value' => '|arg1:proxy_server|', + 'none_value' => __('None', 'webseer'), + 'default' => '0', + 'sql' => 'SELECT id, name FROM plugin_webseer_proxies ORDER by name' + ], + 'compression' => [ 'friendly_name' => __('Compression', 'webseer'), - 'method' => 'drop_array', - 'array' => $httpcompressions, - 'default' => 0, - 'description' => __('What compression does the server require? Most servers should not need this, but some will not redirect properly without it.', 'webseer'), - 'value' => '|arg1:compression|', - ), - 'checks_spacer' => array( - 'method' => 'spacer', + 'method' => 'drop_array', + 'array' => $httpcompressions, + 'default' => 0, + 'description' => __('What compression does the server require? Most servers should not need this, but some will not redirect properly without it.', 'webseer'), + 'value' => '|arg1:compression|', + ], + 'checks_spacer' => [ + 'method' => 'spacer', 'friendly_name' => __('Available Checks', 'webseer') - ), - 'requiresauth' => array( - 'method' => 'checkbox', + ], + 'requiresauth' => [ + 'method' => 'checkbox', 'friendly_name' => __('Requires Authentication', 'webseer'), - 'description' => __('Check this box if the site will normally return a 401 Error as it requires a username and password.', 'webseer'), - 'value' => '|arg1:requiresauth|', - 'default' => '', - ), - 'checkcert' => array( - 'method' => 'checkbox', + 'description' => __('Check this box if the site will normally return a 401 Error as it requires a username and password.', 'webseer'), + 'value' => '|arg1:requiresauth|', + 'default' => '', + ], + 'checkcert' => [ + 'method' => 'checkbox', 'friendly_name' => __('Check Certificate', 'webseer'), - 'description' => __('If using SSL, check this box if you want to validate the certificate. Default on, turn off if you the site uses a self-signed certificate.', 'webseer'), - 'value' => '|arg1:checkcert|', - 'default' => '', - ), - 'timings_spacer' => array( - 'method' => 'spacer', + 'description' => __('If using SSL, check this box if you want to validate the certificate. Default on, turn off if you the site uses a self-signed certificate.', 'webseer'), + 'value' => '|arg1:checkcert|', + 'default' => '', + ], + 'timings_spacer' => [ + 'method' => 'spacer', 'friendly_name' => __('Notification Timing', 'webseer') - ), - 'downtrigger' => array( + ], + 'downtrigger' => [ 'friendly_name' => __('Trigger', 'webseer'), - 'method' => 'drop_array', - 'array' => $webseer_minutes, - 'default' => 3, - 'description' => __('How many minutes the URL must be down before it will send an alert. After an alert is sent, in order for a \'Site Recovering\' Email to be send, it must also be up this number of minutes.', 'webseer'), - 'value' => '|arg1:downtrigger|', - ), - 'timeout_trigger' => array( + 'method' => 'drop_array', + 'array' => $webseer_minutes, + 'default' => 3, + 'description' => __('How many minutes the URL must be down before it will send an alert. After an alert is sent, in order for a \'Site Recovering\' Email to be send, it must also be up this number of minutes.', 'webseer'), + 'value' => '|arg1:downtrigger|', + ], + 'timeout_trigger' => [ 'friendly_name' => __('Time Out', 'webseer'), - 'method' => 'drop_array', - 'array' => $webseer_seconds, - 'default' => 4, - 'description' => __('How many seconds to allow the page to timeout before reporting it as down.', 'webseer'), - 'value' => '|arg1:timeout_trigger|', - ), - 'verifications_spacer' => array( - 'method' => 'spacer', + 'method' => 'drop_array', + 'array' => $webseer_seconds, + 'default' => 4, + 'description' => __('How many seconds to allow the page to timeout before reporting it as down.', 'webseer'), + 'value' => '|arg1:timeout_trigger|', + ], + 'verifications_spacer' => [ + 'method' => 'spacer', 'friendly_name' => __('Verification Strings', 'webseer') - ), - 'search' => array( - 'method' => 'textarea', + ], + 'search' => [ + 'method' => 'textarea', 'friendly_name' => __('Response Search String', 'webseer'), - 'description' => __('This is the string to search for in the URL response for a live and working Web Service.', 'webseer'), - 'value' => '|arg1:search|', + 'description' => __('This is the string to search for in the URL response for a live and working Web Service.', 'webseer'), + 'value' => '|arg1:search|', 'textarea_rows' => '3', 'textarea_cols' => '80', - ), - 'search_maint' => array( - 'method' => 'textarea', + ], + 'search_maint' => [ + 'method' => 'textarea', 'friendly_name' => __('Response Search String - Maintenance Page', 'webseer'), - 'description' => __('This is the string to search for on the Maintenance Page. The Service Check will check for this string if the above string is not found. If found, it means that the Web Service is under maintenance.', 'webseer'), - 'value' => '|arg1:search_maint|', + 'description' => __('This is the string to search for on the Maintenance Page. The Service Check will check for this string if the above string is not found. If found, it means that the Web Service is under maintenance.', 'webseer'), + 'value' => '|arg1:search_maint|', 'textarea_rows' => '3', 'textarea_cols' => '80', - ), - 'search_failed' => array( - 'method' => 'textarea', + ], + 'search_failed' => [ + 'method' => 'textarea', 'friendly_name' => __('Response Search String - Failed', 'webseer'), - 'description' => __('This is the string to search for a known failure in the Web Service response. The Service Check will only alert if this string is found, ignoring any timeout issues and the search strings above.', 'webseer'), - 'value' => '|arg1:search_failed|', + 'description' => __('This is the string to search for a known failure in the Web Service response. The Service Check will only alert if this string is found, ignoring any timeout issues and the search strings above.', 'webseer'), + 'value' => '|arg1:search_failed|', 'textarea_rows' => '3', 'textarea_cols' => '80', - ), - 'notification_spacer' => array( - 'method' => 'spacer', + ], + 'notification_spacer' => [ + 'method' => 'spacer', 'friendly_name' => __('Notification Settings', 'webseer') - ), - 'notify_format' => array( + ], + 'notify_format' => [ 'friendly_name' => __('Notify Format', 'webseer'), - 'method' => 'drop_array', - 'description' => __('This is the format to use when sending the notification email', 'webseer'), - 'array' => $webseer_notify_formats, - 'value' => '|arg1:notify_format|', - ), - 'notify_list' => array( + 'method' => 'drop_array', + 'description' => __('This is the format to use when sending the notification email', 'webseer'), + 'array' => $webseer_notify_formats, + 'value' => '|arg1:notify_format|', + ], + 'notify_list' => [ 'friendly_name' => __('Notification List', 'webseer'), - 'method' => 'drop_sql', - 'description' => __('Use this Notification List for those to be notified when this website goes down.', 'webseer'), - 'sql' => 'SELECT id, name FROM plugin_notification_lists ORDER BY name', - 'value' => '|arg1:notify_list|', - 'none_value' => __('None', 'webseer') - ), - 'notify_accounts' => array( + 'method' => 'drop_sql', + 'description' => __('Use this Notification List for those to be notified when this website goes down.', 'webseer'), + 'sql' => 'SELECT id, name FROM plugin_notification_lists ORDER BY name', + 'value' => '|arg1:notify_list|', + 'none_value' => __('None', 'webseer') + ], + 'notify_accounts' => [ 'friendly_name' => __('Notify Accounts', 'webseer'), - 'method' => 'drop_multi', - 'description' => __('This is a listing of accounts that will be notified when this website goes down.', 'webseer'), - 'array' => $webseer_notify_accounts, - 'value' => '|arg1:notify_accounts|', - ), - 'notify_extra' => array( + 'method' => 'drop_multi', + 'description' => __('This is a listing of accounts that will be notified when this website goes down.', 'webseer'), + 'array' => $webseer_notify_accounts, + 'value' => '|arg1:notify_accounts|', + ], + 'notify_extra' => [ 'friendly_name' => __('Extra Alert Emails', 'webseer'), - 'method' => 'textarea', + 'method' => 'textarea', 'textarea_rows' => 3, 'textarea_cols' => 50, - 'description' => __('You may specify here extra Emails to receive alerts for this URL (comma separated)', 'webseer'), - 'value' => '|arg1:notify_extra|', - ), - 'id' => array( + 'description' => __('You may specify here extra Emails to receive alerts for this URL (comma separated)', 'webseer'), + 'value' => '|arg1:notify_extra|', + ], + 'id' => [ 'method' => 'hidden_zero', - 'value' => '|arg1:id|' - ), -); + 'value' => '|arg1:id|' + ], +]; diff --git a/includes/functions.php b/includes/functions.php index f8dd2ed..92a5085 100644 --- a/includes/functions.php +++ b/includes/functions.php @@ -30,18 +30,18 @@ function webseer_show_tab($current_tab) { global $config; - $tabs = array( + $tabs = [ 'webseer.php' => __('Checks', 'webseer'), 'webseer_servers.php' => __('Servers', 'webseer'), 'webseer_proxies.php' => __('Proxies', 'webseer') - ); + ]; if (get_request_var('action') == 'history') { if ($current_tab == 'webseer.php') { - $current_tab = 'webseer.php?action=history&id=' . get_filter_request_var('id'); + $current_tab = 'webseer.php?action=history&id=' . get_filter_request_var('id'); $tabs[$current_tab] = __('Log History', 'webeer'); } else { - $current_tab = 'webseer_servers.php?action=history&id=' . get_filter_request_var('id'); + $current_tab = 'webseer_servers.php?action=history&id=' . get_filter_request_var('id'); $tabs[$current_tab] = __('Log History', 'webeer'); } } @@ -50,7 +50,7 @@ function webseer_show_tab($current_tab) { if (cacti_sizeof($tabs)) { foreach ($tabs as $url => $name) { - print "
  • $name
  • "; } } @@ -59,11 +59,11 @@ function webseer_show_tab($current_tab) { } function plugin_webseer_refresh_servers() { - $server = db_fetch_row('SELECT * FROM plugin_webseer_servers WHERE master = 1'); + $server = db_fetch_row('SELECT * FROM plugin_webseer_servers WHERE master = 1'); $server['debug_type'] = 'Server'; $cc = new cURL(true, 'cookies.txt', 'gzip', '', $server); - $data = array(); + $data = []; $data['action'] = 'GETSERVERS'; $results = $cc->post($server['url'], $data); @@ -72,15 +72,17 @@ function plugin_webseer_refresh_servers() { foreach ($results as $r) { if (substr($r, 0, 8) == 'SERVERS=') { $servers = substr($r, 8); - $servers = unserialize(base64_decode($servers)); + $servers = unserialize(base64_decode($servers, true), ['allowed_classes' => false]); + if (isset($servers[0]['id'])) { db_execute('TRUNCATE TABLE plugin_webseer_servers'); + foreach ($servers as $save) { db_execute_prepared('REPLACE INTO plugin_webseer_servers (id, enabled, master, name, url, ip, location) VALUES (?,?,?,?,?,?,?)', - array( - $save['id'], $save['enabled'], $save['master'], $save['name'], $save['url'], $save['ip'] , $save['location'] - ) + [ + $save['id'], $save['enabled'], $save['master'], $save['name'], $save['url'], $save['ip'], $save['location'] + ] ); } } @@ -90,13 +92,13 @@ function plugin_webseer_refresh_servers() { } } -function plugin_webseer_refresh_urls () { +function plugin_webseer_refresh_urls() { $server = db_fetch_row('SELECT * FROM plugin_webseer_servers WHERE master = 1'); $server['debug_type'] = 'Server'; $cc = new cURL(true, 'cookies.txt', 'gzip', '', $server); - $data = array(); + $data = []; $data['action'] = 'GETURLS'; $results = $cc->post($server['url'], $data); $results = explode("\n", $results); @@ -104,7 +106,7 @@ function plugin_webseer_refresh_urls () { foreach ($results as $r) { if (substr($r, 0, 5) == 'URLS=') { $urls = substr($r, 5); - $urls = unserialize(base64_decode($urls)); + $urls = unserialize(base64_decode($urls, true), ['allowed_classes' => false]); if (isset($urls[0]['id'])) { db_execute('TRUNCATE TABLE plugin_webseer_urls'); @@ -113,12 +115,12 @@ function plugin_webseer_refresh_urls () { db_execute_prepared('REPLACE INTO plugin_webseer_urls (id, enabled, requiresauth, checkcert, ip, display_name, notify_list, notify_accounts, url, search, search_maint, search_failed, notify_extra, downtrigger) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', - array( + [ $save['id'], $save['enabled'], $save['requiresauth'], $save['checkcert'], $save['ip'], $save['display_name'], $save['notify_list'], $save['notify_accounts'], $save['url'], $save['search'], $save['search_maint'], $save['search_failed'], $save['notify_extra'], $save['downtrigger'] - ) + ] ); } } @@ -128,10 +130,10 @@ function plugin_webseer_refresh_urls () { } } -function plugin_webseer_remove_old_users () { +function plugin_webseer_remove_old_users() { $users = db_fetch_assoc('SELECT id FROM user_auth'); - $u = array(); + $u = []; foreach ($users as $user) { $u[] = $user['id']; @@ -140,17 +142,17 @@ function plugin_webseer_remove_old_users () { $contacts = db_fetch_assoc('SELECT DISTINCT user_id FROM plugin_webseer_contacts'); foreach ($contacts as $c) { - if (!in_array($c['user_id'], $u)) { - db_execute_prepared('DELETE FROM plugin_webseer_contacts WHERE user_id = ?', array($c['user_id'])); + if (!in_array($c['user_id'], $u, true)) { + db_execute_prepared('DELETE FROM plugin_webseer_contacts WHERE user_id = ?', [$c['user_id']]); } } } -function plugin_webseer_check_dns ($host) { +function plugin_webseer_check_dns($host) { $results = false; if (cacti_sizeof($host)) { - $results = array(); + $results = []; $results['result'] = 0; $results['options']['http_code'] = 0; $results['error'] = ''; @@ -163,14 +165,16 @@ function plugin_webseer_check_dns ($host) { $results['options']['speed_download'] = 0; $results['time'] = time(); - $s = microtime(true); - $a = new mxlookup($host['search'], $host['url']); - $t = microtime(true) - $s; + $s = microtime(true); + $a = new mxlookup($host['search'], $host['url']); + $t = microtime(true) - $s; $results['options']['connect_time'] = $results['options']['total_time'] = $results['options']['namelookup_time'] = round($t, 4); $results['data'] = ''; + foreach ($a->arrMX as $m) { $results['data'] .= "A RECORD: $m\n"; + if ($m == $host['search_maint']) { $results['result'] = 1; } @@ -180,51 +184,51 @@ function plugin_webseer_check_dns ($host) { return $results; } -function plugin_webseer_set_remote_masters ($ip) { +function plugin_webseer_set_remote_masters($ip) { $servers = db_fetch_assoc('SELECT * FROM plugin_webseer_servers WHERE isme = 0'); foreach ($servers as $server) { $server['debug_type'] = 'Server'; - plugin_webseer_set_remote_master ($server['url'], $ip); + plugin_webseer_set_remote_master($server['url'], $ip); } db_execute('UPDATE plugin_webseer_servers set master = 0'); - db_execute_prepared('UPDATE plugin_webseer_servers set master = 1 WHERE ip = ?', array($ip)); + db_execute_prepared('UPDATE plugin_webseer_servers set master = 1 WHERE ip = ?', [$ip]); } -function plugin_webseer_set_remote_master ($url, $ip) { +function plugin_webseer_set_remote_master($url, $ip) { $cc = new cURL(true, 'cookies.txt', 'gzip', '', $url); - $data = array(); + $data = []; $data['action'] = 'SETMASTER'; $data['ip'] = $ip; $results = $cc->post($url['url'], $data); } -function plugin_webseer_enable_remote_hosts ($id, $value = true) { +function plugin_webseer_enable_remote_hosts($id, $value = true) { $servers = db_fetch_assoc('SELECT * FROM plugin_webseer_servers WHERE isme = 0'); foreach ($servers as $server) { $cc = new cURL(true, 'cookies.txt', 'gzip', '', $server); - $data = array(); + $data = []; $data['action'] = ($value ? 'ENABLEURL' : 'DISABLEURL'); $data['id'] = $id; $results = $cc->post($server['url'], $data); } } -function plugin_webseer_delete_remote_hosts ($id) { +function plugin_webseer_delete_remote_hosts($id) { $servers = db_fetch_assoc('SELECT * FROM plugin_webseer_servers WHERE isme = 0'); foreach ($servers as $server) { $cc = new cURL(true, 'cookies.txt', 'gzip', '', $server); - $data = array(); + $data = []; $data['action'] = 'DELETEURL'; $data['id'] = $id; $results = $cc->post($server['url'], $data); } } -function plugin_webseer_add_remote_hosts ($id, $save) { +function plugin_webseer_add_remote_hosts($id, $save) { $servers = db_fetch_assoc('SELECT * FROM plugin_webseer_servers WHERE isme = 0'); foreach ($servers as $server) { @@ -237,32 +241,32 @@ function plugin_webseer_add_remote_hosts ($id, $save) { } } -function plugin_webseer_update_remote_hosts ($save) { +function plugin_webseer_update_remote_hosts($save) { $servers = db_fetch_assoc('SELECT * FROM plugin_webseer_servers WHERE isme = 0'); foreach ($servers as $server) { $server['debug_type'] = 'Server'; - $cc = new cURL(true, 'cookies.txt', 'gzip', '', $server); + $cc = new cURL(true, 'cookies.txt', 'gzip', '', $server); $save['action'] = 'UPDATEURL'; - $results = $cc->post($server['url'], $save); + $results = $cc->post($server['url'], $save); } } -function plugin_webseer_add_remote_server ($id, $save) { +function plugin_webseer_add_remote_server($id, $save) { $servers = db_fetch_assoc('SELECT * FROM plugin_webseer_servers WHERE isme = 0'); foreach ($servers as $server) { $server['debug_type'] = 'Server'; - $cc = new cURL(true, 'cookies.txt', 'gzip', '', $server); + $cc = new cURL(true, 'cookies.txt', 'gzip', '', $server); $save['action'] = 'ADDSERVER'; - $save['id'] = $id; - $results = $cc->post($server['url'], $save); + $save['id'] = $id; + $results = $cc->post($server['url'], $save); } } -function plugin_webseer_update_remote_server ($save) { +function plugin_webseer_update_remote_server($save) { $servers = db_fetch_assoc('SELECT * FROM plugin_webseer_servers WHERE isme = 0'); foreach ($servers as $server) { @@ -274,35 +278,35 @@ function plugin_webseer_update_remote_server ($save) { } } -function plugin_webseer_enable_remote_server ($id, $value = true) { +function plugin_webseer_enable_remote_server($id, $value = true) { $servers = db_fetch_assoc('SELECT * FROM plugin_webseer_servers WHERE isme = 0'); foreach ($servers as $server) { $server['debug_type'] = 'Server'; $cc = new cURL(true, 'cookies.txt', 'gzip', '', $server); - $data = array(); + $data = []; $data['action'] = ($value ? 'ENABLESERVER' : 'DISABLESERVER'); $data['id'] = $id; $results = $cc->post($server['url'], $data); } } -function plugin_webseer_delete_remote_server ($id) { +function plugin_webseer_delete_remote_server($id) { $servers = db_fetch_assoc('SELECT * FROM plugin_webseer_servers WHERE isme = 0'); foreach ($servers as $server) { $server['debug_type'] = 'Server'; $cc = new cURL(true, 'cookies.txt', 'gzip', '', $server); - $data = array(); + $data = []; $data['action'] = 'DELETESERVER'; $data['id'] = $id; $results = $cc->post($server['url'], $data); } } -function plugin_webseer_down_remote_hosts ($save) { +function plugin_webseer_down_remote_hosts($save) { $servers = db_fetch_assoc('SELECT * FROM plugin_webseer_servers WHERE isme = 0'); foreach ($servers as $server) { @@ -314,14 +318,21 @@ function plugin_webseer_down_remote_hosts ($save) { function plugin_webseer_update_contacts() { $users = db_fetch_assoc("SELECT id, 'email' AS type, email_address FROM user_auth WHERE email_address!=''"); + if (cacti_sizeof($users)) { - foreach($users as $u) { - $cid = db_fetch_cell('SELECT id FROM plugin_webseer_contacts WHERE type="email" AND user_id=' . $u['id']); + foreach ($users as $u) { + $cid = db_fetch_cell_prepared('SELECT id FROM plugin_webseer_contacts WHERE type="email" AND user_id=?', [$u['id']]); if ($cid) { - db_execute("REPLACE INTO plugin_webseer_contacts (id, user_id, type, data) VALUES ($cid, " . $u['id'] . ", 'email', '" . $u['email_address'] . "')"); + db_execute_prepared( + 'REPLACE INTO plugin_webseer_contacts (id, user_id, type, data) VALUES (?, ?, \'email\', ?)', + [$cid, $u['id'], $u['email_address']] + ); } else { - db_execute("REPLACE INTO plugin_webseer_contacts (user_id, type, data) VALUES (" . $u['id'] . ", 'email', '" . $u['email_address'] . "')"); + db_execute_prepared( + 'REPLACE INTO plugin_webseer_contacts (user_id, type, data) VALUES (?, \'email\', ?)', + [$u['id'], $u['email_address']] + ); } } } @@ -329,23 +340,25 @@ function plugin_webseer_update_contacts() { function plugin_webseer_check_debug() { global $debug; + if (!$debug) { $plugin_debug = read_config_option('selective_plugin_debug'); + if (preg_match('/(^|[, ]+)(webseer)($|[, ]+)/', $plugin_debug, $matches)) { $debug = (cacti_sizeof($matches) == 4 && $matches[2] == 'webseer'); } } } -function plugin_webseer_debug($message='', $host=array()) { +function plugin_webseer_debug($message = '', $host = []) { global $debug; + if ($debug) { - $prefix = (empty($host['id']) && empty($host['debug_type'])) ? '' : '['; - $suffix = (empty($host['id']) && empty($host['debug_type'])) ? '' : '] '; - $spacer = (empty($host['id']) || empty($host['debug_type'])) ? '' : ' '; + $prefix = (empty($host['id']) && empty($host['debug_type'])) ? '' : '['; + $suffix = (empty($host['id']) && empty($host['debug_type'])) ? '' : '] '; + $spacer = (empty($host['id']) || empty($host['debug_type'])) ? '' : ' '; $host_id = (empty($host['id'])) ? '' : $host['id']; $host_dt = (empty($host['debug_type'])) ? '' : $host['debug_type']; cacti_log('DEBUG: ' . $prefix . $host_dt . $spacer . $host_id . $suffix . trim($message), true, 'WEBSEER'); } } - diff --git a/poller_webseer.php b/poller_webseer.php index 2efc9fc..3dbe7df 100644 --- a/poller_webseer.php +++ b/poller_webseer.php @@ -22,10 +22,10 @@ +-------------------------------------------------------------------------+ */ -/* let PHP run just as long as it has to */ +// let PHP run just as long as it has to ini_set('max_execution_time', '55'); -$dir = dirname(__FILE__); +$dir = __DIR__; chdir($dir); if (strpos($dir, 'plugins') !== false) { @@ -36,7 +36,7 @@ include_once($config['base_path'] . '/plugins/webseer/includes/functions.php'); include_once($config['base_path'] . '/lib/poller.php'); -/* process calling arguments */ +// process calling arguments $parms = $_SERVER['argv']; array_shift($parms); @@ -47,11 +47,11 @@ $poller_id = $config['poller_id']; if (cacti_sizeof($parms)) { - foreach($parms as $parameter) { + foreach ($parms as $parameter) { if (strpos($parameter, '=')) { - list($arg, $value) = explode('=', $parameter); + [$arg, $value] = explode('=', $parameter); } else { - $arg = $parameter; + $arg = $parameter; $value = ''; } @@ -59,10 +59,12 @@ case '-f': case '--force': $force = true; + break; case '-d': case '--debug': $debug = true; + break; case '--version': case '-V': @@ -75,7 +77,7 @@ display_help(); exit; default: - print "ERROR: Invalid Parameter " . $parameter . "\n\n"; + print 'ERROR: Invalid Parameter ' . $parameter . "\n\n"; display_help(); exit; } @@ -83,7 +85,7 @@ } if (!function_exists('curl_init')) { - print "FATAL: You must install php-curl to use this Plugin" . PHP_EOL; + print 'FATAL: You must install php-curl to use this Plugin' . PHP_EOL; } plugin_webseer_check_debug(); @@ -98,27 +100,27 @@ if ($poller_id == 1) { db_execute_prepared('DELETE FROM plugin_webseer_urls_log WHERE lastcheck < FROM_UNIXTIME(?)', - array($t)); + [$t]); db_execute_prepared('DELETE FROM plugin_webseer_processes WHERE time < FROM_UNIXTIME(?)', - array(time() - 15)); + [time() - 15]); } $urls = db_fetch_assoc_prepared('SELECT * FROM plugin_webseer_urls WHERE enabled = "on" AND poller_id = ?', - array($poller_id)); + [$poller_id]); $max = 12; if (cacti_sizeof($urls)) { - foreach($urls as $url) { + foreach ($urls as $url) { $total = db_fetch_cell_prepared('SELECT COUNT(id) FROM plugin_webseer_processes WHERE poller_id = ?', - array($poller_id)); + [$poller_id]); if ($max - $total > 0) { $url['debug_type'] = 'Url'; @@ -126,7 +128,7 @@ plugin_webseer_debug('Launching Service Check ' . $url['url'], $url); $command_string = read_config_option('path_php_binary'); - $extra_args = '-q "' . $config['base_path'] . '/plugins/webseer/webseer_process.php" --id=' . $url['id'] . ($debug ? ' --debug':''); + $extra_args = '-q "' . $config['base_path'] . '/plugins/webseer/webseer_process.php" --id=' . $url['id'] . ($debug ? ' --debug' : ''); exec_background($command_string, $extra_args); usleep(10000); @@ -136,21 +138,21 @@ db_execute_prepared('DELETE FROM plugin_webseer_processes WHERE time < FROM_UNIXTIME(?) AND poller_id = ?', - array(time() - 15, $poller_id)); + [time() - 15, $poller_id]); } } } -while(true) { +while (true) { db_execute_prepared('DELETE FROM plugin_webseer_processes WHERE time < FROM_UNIXTIME(?) AND poller_id = ?', - array(time() - 15, $poller_id)); + [time() - 15, $poller_id]); $running = db_fetch_cell_prepared('SELECT COUNT(*) FROM plugin_webseer_processes WHERE poller_id = ?', - array($poller_id)); + [$poller_id]); if ($running == 0) { break; @@ -190,15 +192,15 @@ function plugin_webseer_register_server() { $found = db_fetch_cell_prepared('SELECT id FROM plugin_webseer_servers WHERE ip = ?', - array($ipaddress)); + [$ipaddress]); if (!$found) { - $found = array(); + $found = []; $found['debug_type'] = 'Server'; plugin_webseer_debug('Registering Server ' . $ipaddress, $found); - $save = array(); + $save = []; $save['enabled'] = 'on'; $save['isme'] = 1; $save['lastcheck'] = $lastcheck; @@ -219,7 +221,7 @@ function plugin_webseer_register_server() { } if (isset($config['url_path'])) { - $save['url'] = (read_config_option('force_https') == 'on' ? 'https://':'http://') . $urlhost . $config['url_path'] . 'index.php'; + $save['url'] = (read_config_option('force_https') == 'on' ? 'https://' : 'http://') . $urlhost . $config['url_path'] . 'index.php'; } else { $save['url'] = 'http://' . $urlhost; } @@ -238,11 +240,11 @@ function plugin_webseer_update_servers() { foreach ($servers as $server) { $server['debug_type'] = 'Server'; - $cc = new cURL(true, 'cookies.txt', $server['compression'], '', $server);; + $cc = new cURL(true, 'cookies.txt', $server['compression'], '', $server); - $data = array(); + $data = []; $data['action'] = 'HEARTBEAT'; - $results = $cc->post($server['url'], $data); + $results = $cc->post($server['url'], $data); } } @@ -259,20 +261,19 @@ function display_version() { include_once($config['base_path'] . '/plugins/webseer/setup.php'); } - $info = plugin_webseer_version(); + $info = plugin_webseer_version(); - print "Cacti Service Check Master Process, Version " . $info['version'] . ", " . COPYRIGHT_YEARS . "\n"; + print 'Cacti Service Check Master Process, Version ' . $info['version'] . ', ' . COPYRIGHT_YEARS . "\n"; } /** * display_help - displays the usage of the function */ -function display_help () { - display_version(); +function display_help() { + display_version(); - print "\nusage: poller_webseer.php [--debug] [--force]\n\n"; + print "\nusage: poller_webseer.php [--debug] [--force]\n\n"; print "This binary will exec all the Web Service check child processes.\n\n"; - print "--force - Force all the service checks to run now\n"; - print "--debug - Display verbose output during execution\n\n"; + print "--force - Force all the service checks to run now\n"; + print "--debug - Display verbose output during execution\n\n"; } - diff --git a/remote.php b/remote.php index ab3aff6..64bd5ac 100644 --- a/remote.php +++ b/remote.php @@ -40,7 +40,7 @@ $servers = db_fetch_assoc('SELECT * FROM plugin_webseer_servers'); -$s = array(); +$s = []; foreach ($servers as $server) { if ($server['ip'] == $remoteip) { @@ -50,7 +50,7 @@ case 'HEARTBEAT': db_execute_prepared('UPDATE plugin_webseer_servers SET lastcheck = ? WHERE ip = ?', - array(time(), $remoteip)); + [time(), $remoteip]); break; case 'HOSTDOWN': @@ -59,14 +59,14 @@ (url_id, server, lastcheck, result, http_code, error, total_time, namelookup_time, connect_time, redirect_time, redirect_count, size_download, speed_download) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)', - array( + [ get_nfilter_request_var('url_id'), get_nfilter_request_var('server'), get_nfilter_request_var('lastcheck'), get_nfilter_request_var('result'), get_nfilter_request_var('http_code'), get_nfilter_request_var('error'), get_nfilter_request_var('total_time'), get_nfilter_request_var('namelookup_time'), get_nfilter_request_var('connect_time'), get_nfilter_request_var('redirect_time'), get_nfilter_request_var('redirect_count'), get_nfilter_request_var('size_download'), get_nfilter_request_var('speed_download') - ) + ] ); } @@ -76,7 +76,7 @@ $id = get_filter_request_var('id'); db_execute_prepared('UPDATE plugin_webseer_urls SET enabled = ? WHERE id = ?', - array(($action == 'ENABLEURL' ? 'on' : ''), $id)); + [($action == 'ENABLEURL' ? 'on' : ''), $id]); } break; @@ -84,12 +84,12 @@ case 'ADDURL': if (isset($_POST['id'])) { get_filter_request_var('id', FILTER_VALIDATE_INT); - get_filter_request_var('url', FILTER_VALIDATE_REGEXP, array('options' => array('regexp' => '/^([\w:/\.?=&-+]+)$/'))); + get_filter_request_var('url', FILTER_VALIDATE_REGEXP, ['options' => ['regexp' => '/^([\w:/\.?=&-+]+)$/']]); get_filter_request_var('notify_list', FILTER_VALIDATE_INT); - get_filter_request_var('notify_extra', FILTER_VALIDATE_REGEXP, array('options' => array('regexp' => '/^([a-zA-Z0-9_@,\.\+]+)$/'))); + get_filter_request_var('notify_extra', FILTER_VALIDATE_REGEXP, ['options' => ['regexp' => '/^([a-zA-Z0-9_@,\.\+]+)$/']]); get_filter_request_var('downtrigger', FILTER_VALIDATE_INT); - get_filter_request_var('ip', FILTER_VALIDATE_REGEXP, array('options' => array('regexp' => '/^([\d]{1,3}\.[\d]{1,3}\.[\d]{1,3}\.[\d]{1,3})$/'))); - get_filter_request_var('display_name', FILTER_VALIDATE_REGEXP, array('options' => array('regexp' => '/^([\w,\s]+)$/'))); + get_filter_request_var('ip', FILTER_VALIDATE_REGEXP, ['options' => ['regexp' => '/^([\d]{1,3}\.[\d]{1,3}\.[\d]{1,3}\.[\d]{1,3})$/']]); + get_filter_request_var('display_name', FILTER_VALIDATE_REGEXP, ['options' => ['regexp' => '/^([\w,\s]+)$/']]); $save['id'] = get_filter_request_var('id'); $save['enabled'] = get_nfilter_request_var('enabled', ''); @@ -114,12 +114,12 @@ (id, enabled, requiresauth, proxy_server, checkcert, ip, display_name, notify_list, notify_accounts, url, search, search_maint, search_failed, notify_extra, downtrigger) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', - array( + [ $save['id'], $save['enabled'], $save['requiresauth'], $save['proxy_server'], $save['checkcert'], $save['ip'], $save['display_name'], $save['notify_list'], $save['notify_accounts'], $save['url'], $save['search'], $save['search_maint'], $save['search_failed'], $save['notify_extra'], $save['downtrigger'] - ) + ] ); } } @@ -132,7 +132,7 @@ db_execute_prepared('UPDATE plugin_webseer_servers SET enabled = ? WHERE id = ?', - array(($action == 'ENABLESERVER' ? 1 : 0), $id)); + [($action == 'ENABLESERVER' ? 1 : 0), $id]); } break; @@ -141,7 +141,7 @@ if (isset($_POST['id'])) { $save['id'] = get_filter_request_var('id'); $save['enabled'] = (isset($_POST['enabled']) ? '1' : '0'); - $save['master'] = (isset($_POST['master']) ? '1' : '0'); + $save['master'] = (isset($_POST['master']) ? '1' : '0'); $save['name'] = get_nfilter_request_var('name'); $save['url'] = get_nfilter_request_var('url'); $save['ip'] = get_nfilter_request_var('ip'); @@ -153,10 +153,10 @@ db_execute_prepared('REPLACE INTO plugin_webseer_servers (id, enabled, master, name, url, ip, location) VALUES (?,?,?,?,?,?,?)', - array( + [ $save['id'], $save['enabled'], $save['master'], $save['name'], $save['url'], $save['ip'], $save['location'] - ) + ] ); } } @@ -165,31 +165,36 @@ case 'DELETEURL': if (isset($_POST['id'])) { $id = intval(get_filter_request_var('id')); - db_execute_prepared('DELETE FROM plugin_webseer_urls WHERE id = ?', array($id)); - db_execute_prepared('DELETE FROM plugin_webseer_urls_log WHERE url_id = ?', array($id)); + db_execute_prepared('DELETE FROM plugin_webseer_urls WHERE id = ?', [$id]); + db_execute_prepared('DELETE FROM plugin_webseer_urls_log WHERE url_id = ?', [$id]); } + break; case 'SETMASTER': if (isset($_POST['ip'])) { - $ip = str_replace(array("'", '\\'), '', $_POST['ip']); - $row = db_fetch_row("SELECT * FROM plugin_webseer_servers WHERE ip = '$ip'"); + $ip = str_replace(["'", '\\'], '', $_POST['ip']); + $row = db_fetch_row_prepared('SELECT * FROM plugin_webseer_servers WHERE ip = ?', [$ip]); + if (isset($row['id'])) { db_execute('UPDATE plugin_webseer_servers set master = 0'); - db_execute_prepared('UPDATE plugin_webseer_servers set master = 1 WHERE ip = ?', array($ip)); + db_execute_prepared('UPDATE plugin_webseer_servers set master = 1 WHERE ip = ?', [$ip]); } } + break; case 'GETSERVERS': print 'SERVERS=' . base64_encode(serialize($servers)); + break; case 'GETURLS': $urls = db_fetch_assoc('SELECT * FROM plugin_webseer_urls'); + foreach ($urls as $id => $u) { $urls[$id]['debug'] = ''; } print 'URLS=' . base64_encode(serialize($urls)); + break; } } } - diff --git a/setup.php b/setup.php index df042f4..7f3d55d 100644 --- a/setup.php +++ b/setup.php @@ -25,7 +25,7 @@ include_once(__DIR__ . '/includes/constants.php'); include_once(__DIR__ . '/includes/arrays.php'); -function plugin_webseer_install () { +function plugin_webseer_install() { api_plugin_register_hook('webseer', 'draw_navigation_text', 'plugin_webseer_draw_navigation_text', 'setup.php'); api_plugin_register_hook('webseer', 'config_arrays', 'plugin_webseer_config_arrays', 'setup.php'); api_plugin_register_hook('webseer', 'poller_bottom', 'plugin_webseer_poller_bottom', 'setup.php'); @@ -36,7 +36,7 @@ function plugin_webseer_install () { plugin_webseer_setup_table(); } -function plugin_webseer_uninstall () { +function plugin_webseer_uninstall() { db_execute('DROP TABLE IF EXISTS plugin_webseer_servers'); db_execute('DROP TABLE IF EXISTS plugin_webseer_servers_log'); db_execute('DROP TABLE IF EXISTS plugin_webseer_urls'); @@ -46,9 +46,10 @@ function plugin_webseer_uninstall () { db_execute('DROP TABLE IF EXISTS plugin_webseer_contacts'); } -function plugin_webseer_check_config () { +function plugin_webseer_check_config() { // Here we will check to ensure everything is configured plugin_webseer_upgrade(); + return true; } @@ -124,24 +125,24 @@ function plugin_webseer_upgrade() { db_execute_prepared('UPDATE plugin_config SET version = ? WHERE directory = "webseer"', - array($new)); + [$new]); - db_execute_prepared("UPDATE plugin_config SET + db_execute_prepared('UPDATE plugin_config SET version = ?, name = ?, author = ?, webpage = ? - WHERE directory = ?", - array( + WHERE directory = ?', + [ $info['version'], $info['longname'], $info['author'], $info['homepage'], $info['name'] - ) + ] ); db_execute_prepared('UPDATE plugin_realms SET file = ? WHERE file LIKE "%webseer.php%"', - array('webseer.php,webseer_servers.php,webseer_proxies.php')); + ['webseer.php,webseer_servers.php,webseer_proxies.php']); api_plugin_register_hook('webseer', 'replicate_out', 'webseer_replicate_out', 'setup.php', '1'); } @@ -152,6 +153,7 @@ function plugin_webseer_upgrade() { function plugin_webseer_version() { global $config; $info = parse_ini_file($config['base_path'] . '/plugins/webseer/INFO', true); + return $info['info']; } @@ -309,8 +311,9 @@ function plugin_webseer_poller_bottom() { $command_string = trim(read_config_option('path_php_binary')); // If its not set, just assume its in the path - if (trim($command_string) == '') + if (trim($command_string) == '') { $command_string = 'php'; + } $extra_args = ' -q ' . $config['base_path'] . '/plugins/webseer/poller_webseer.php'; exec_background($command_string, $extra_args); @@ -321,75 +324,76 @@ function plugin_webseer_config_arrays() { $menu[__('Management')]['plugins/webseer/webseer.php'] = __('Service Checks', 'webseer'); - $files = array('index.php', 'plugins.php', 'webseer.php'); - if (in_array(get_current_page(), $files)) { + $files = ['index.php', 'plugins.php', 'webseer.php']; + + if (in_array(get_current_page(), $files, true)) { plugin_webseer_check_config(); } } function plugin_webseer_draw_navigation_text($nav) { - $nav['webseer.php:'] = array( - 'title' => __('WebSeer Service Checks', 'webseer'), + $nav['webseer.php:'] = [ + 'title' => __('WebSeer Service Checks', 'webseer'), 'mapping' => 'index.php:', - 'url' => 'webseer.php', - 'level' => '1' - ); + 'url' => 'webseer.php', + 'level' => '1' + ]; - $nav['webseer.php:edit'] = array( - 'title' => __('Service Check Edit', 'webseer'), + $nav['webseer.php:edit'] = [ + 'title' => __('Service Check Edit', 'webseer'), 'mapping' => 'index.php:', - 'url' => 'webseer.php', - 'level' => '1' - ); + 'url' => 'webseer.php', + 'level' => '1' + ]; - $nav['webseer.php:save'] = array( - 'title' => __('Service Check Save', 'webseer'), + $nav['webseer.php:save'] = [ + 'title' => __('Service Check Save', 'webseer'), 'mapping' => 'index.php:', - 'url' => 'webseer.php', - 'level' => '1' - ); + 'url' => 'webseer.php', + 'level' => '1' + ]; - $nav['webseer_servers.php:'] = array( - 'title' => __('WebSeer Servers', 'webseer'), + $nav['webseer_servers.php:'] = [ + 'title' => __('WebSeer Servers', 'webseer'), 'mapping' => 'index.php:', - 'url' => 'webseer_servers.php', - 'level' => '1' - ); + 'url' => 'webseer_servers.php', + 'level' => '1' + ]; - $nav['webseer_servers.php:edit'] = array( - 'title' => __('Server Edit', 'webseer'), + $nav['webseer_servers.php:edit'] = [ + 'title' => __('Server Edit', 'webseer'), 'mapping' => 'index.php:', - 'url' => 'webseer.php', - 'level' => '1' - ); + 'url' => 'webseer.php', + 'level' => '1' + ]; - $nav['webseer_servers.php:save'] = array( - 'title' => __('Save Server', 'webseer'), + $nav['webseer_servers.php:save'] = [ + 'title' => __('Save Server', 'webseer'), 'mapping' => 'index.php:', - 'url' => 'webseer.php', - 'level' => '1' - ); + 'url' => 'webseer.php', + 'level' => '1' + ]; - $nav['webseer_proxies.php:'] = array( - 'title' => __('WebSeer Proxies', 'webseer'), + $nav['webseer_proxies.php:'] = [ + 'title' => __('WebSeer Proxies', 'webseer'), 'mapping' => 'index.php:', - 'url' => 'webseer.php', - 'level' => '1' - ); + 'url' => 'webseer.php', + 'level' => '1' + ]; - $nav['webseer_proxies.php:edit'] = array( - 'title' => __('Proxie Edit', 'webseer'), + $nav['webseer_proxies.php:edit'] = [ + 'title' => __('Proxie Edit', 'webseer'), 'mapping' => 'index.php:', - 'url' => 'webseer.php', - 'level' => '1' - ); + 'url' => 'webseer.php', + 'level' => '1' + ]; - $nav['webseer_proxies.php:save'] = array( - 'title' => __('Save Proxy', 'webseer'), + $nav['webseer_proxies.php:save'] = [ + 'title' => __('Save Proxy', 'webseer'), 'mapping' => 'index.php:', - 'url' => 'webseer.php', - 'level' => '1' - ); + 'url' => 'webseer.php', + 'level' => '1' + ]; return $nav; } @@ -401,21 +405,19 @@ function webseer_replicate_out($data) { cacti_log('INFO: Replicating for the WebSeer Plugin', false, 'REPLICATE'); - $tables = array( + $tables = [ 'plugin_webseer_contacts', 'plugin_webseer_proxies', 'plugin_webseer_servers', 'plugin_webseer_urls' - ); + ]; if ($class == 'all') { - foreach($tables as $table) { + foreach ($tables as $table) { $tdata = db_fetch_assoc('SELECT * FROM ' . $table); replicate_out_table($rcnn_id, $tdata, $table, $remote_poller_id); } } - return $data; + return $data; } - - diff --git a/tests/e2e/test_webseer_no_raw_reuse_regression.php b/tests/e2e/test_webseer_no_raw_reuse_regression.php new file mode 100644 index 0000000..38460ec --- /dev/null +++ b/tests/e2e/test_webseer_no_raw_reuse_regression.php @@ -0,0 +1,35 @@ +", + "
  • ' . db_fetch_cell_prepared('SELECT name FROM plugin_webseer_proxies WHERE id = ?', array(\$matches[1])) . '
  • '", + "
  • ' . db_fetch_cell_prepared('SELECT display_name FROM plugin_webseer_urls WHERE id = ?', array(\$matches[1])) . '
  • '", + "
  • ' . db_fetch_cell_prepared('SELECT name FROM plugin_webseer_servers WHERE id = ?', array(\$matches[1])) . '
  • '", + ' name LIKE "%\' . get_request_var(\'filter\') . \'%" OR hostname LIKE "%\' . get_request_var(\'filter\') . \'%"', +]; + +foreach ($files as $file) { + $source = file_get_contents(dirname(__DIR__, 2) . '/' . $file); + + if ($source === false) { + fwrite(STDERR, "Unable to read $file\n"); + exit(1); + } + + foreach ($legacy_needles as $needle) { + if (strpos($source, $needle) !== false) { + fwrite(STDERR, "Found legacy insecure pattern in $file\n"); + exit(1); + } + } +} + +print "OK\n"; diff --git a/tests/integration/test_webseer_confirmation_and_sql_wiring.php b/tests/integration/test_webseer_confirmation_and_sql_wiring.php new file mode 100644 index 0000000..bd7156d --- /dev/null +++ b/tests/integration/test_webseer_confirmation_and_sql_wiring.php @@ -0,0 +1,23 @@ +\' . html_escape(db_fetch_cell_prepared(\'SELECT name FROM plugin_webseer_proxies WHERE id = ?\', array($matches[1]))) . \'') !== false, + $proxy_source !== false && strpos($proxy_source, "(name LIKE ' . db_qstr('%' . get_request_var('filter') . '%') . ' OR hostname LIKE ' . db_qstr('%' . get_request_var('filter') . '%') . ')") !== false, + $url_source !== false && strpos($url_source, '
  • \' . html_escape(db_fetch_cell_prepared(\'SELECT display_name FROM plugin_webseer_urls WHERE id = ?\', array($matches[1]))) . \'
  • ') !== false, + $server_source !== false && strpos($server_source, '
  • \' . html_escape(db_fetch_cell_prepared(\'SELECT name FROM plugin_webseer_servers WHERE id = ?\', array($matches[1]))) . \'
  • ') !== false, + $remote_source !== false && strpos($remote_source, "db_fetch_row_prepared('SELECT * FROM plugin_webseer_servers WHERE ip = ?', array(\$ip))") !== false, +]; + +foreach ($checks as $passed) { + if (!$passed) { + fwrite(STDERR, "Webseer security wiring check failed\n"); + exit(1); + } +} + +print "OK\n"; diff --git a/tests/unit/test_webseer_security_guards.php b/tests/unit/test_webseer_security_guards.php new file mode 100644 index 0000000..6a0fbe7 --- /dev/null +++ b/tests/unit/test_webseer_security_guards.php @@ -0,0 +1,38 @@ + [ + "html_escape(db_fetch_cell_prepared('SELECT name FROM plugin_webseer_proxies WHERE id = ?', array(\$matches[1])))", + "html_escape(get_nfilter_request_var('drp_action'))", + "(name LIKE ' . db_qstr('%' . get_request_var('filter') . '%') . ' OR hostname LIKE ' . db_qstr('%' . get_request_var('filter') . '%') . ')'", + ], + 'webseer.php' => [ + "html_escape(db_fetch_cell_prepared('SELECT display_name FROM plugin_webseer_urls WHERE id = ?', array(\$matches[1])))", + "html_escape(get_nfilter_request_var('drp_action'))", + ], + 'webseer_servers.php' => [ + "html_escape(db_fetch_cell_prepared('SELECT name FROM plugin_webseer_servers WHERE id = ?', array(\$matches[1])))", + "html_escape(get_nfilter_request_var('drp_action'))", + ], + 'remote.php' => [ + "db_fetch_row_prepared('SELECT * FROM plugin_webseer_servers WHERE ip = ?', array(\$ip))", + ], +]; + +foreach ($files as $file => $needles) { + $source = file_get_contents(dirname(__DIR__, 2) . '/' . $file); + + if ($source === false) { + fwrite(STDERR, "Unable to read $file\n"); + exit(1); + } + + foreach ($needles as $needle) { + if (strpos($source, $needle) === false) { + fwrite(STDERR, "Missing expected guard in $file\n"); + exit(1); + } + } +} + +print "OK\n"; diff --git a/webseer.php b/webseer.php index 767914c..48fcc56 100644 --- a/webseer.php +++ b/webseer.php @@ -31,63 +31,63 @@ set_default_action(); switch (get_request_var('action')) { -case 'save': - form_save(); + case 'save': + form_save(); - break; -case 'actions': - form_actions(); + break; + case 'actions': + form_actions(); - break; -case 'enable': - $id = get_filter_request_var('id'); + break; + case 'enable': + $id = get_filter_request_var('id'); - if ($id > 0) { - db_execute_prepared('UPDATE plugin_webseer_urls SET enabled = "on" WHERE id = ?', array($id)); - plugin_webseer_enable_remote_hosts($id, true); - } + if ($id > 0) { + db_execute_prepared('UPDATE plugin_webseer_urls SET enabled = "on" WHERE id = ?', [$id]); + plugin_webseer_enable_remote_hosts($id, true); + } - header('Location: webseer.php?header=false'); - exit; + header('Location: webseer.php?header=false'); + exit; - break; -case 'disable': - $id = get_filter_request_var('id'); + break; + case 'disable': + $id = get_filter_request_var('id'); - if ($id > 0) { - db_execute_prepared('UPDATE plugin_webseer_urls SET enabled = "" WHERE id = ?', array($id)); - plugin_webseer_enable_remote_hosts($id, false); - } + if ($id > 0) { + db_execute_prepared('UPDATE plugin_webseer_urls SET enabled = "" WHERE id = ?', [$id]); + plugin_webseer_enable_remote_hosts($id, false); + } - header('Location: webseer.php?header=false'); - exit; + header('Location: webseer.php?header=false'); + exit; - break; -case 'purge': - $id = get_filter_request_var('id'); + break; + case 'purge': + $id = get_filter_request_var('id'); - if ($id > 0) { - purge_log_events($id); - } + if ($id > 0) { + purge_log_events($id); + } - header('Location: webseer.php?header=false'); - exit; + header('Location: webseer.php?header=false'); + exit; - break; -case 'edit': - top_header(); - webseer_edit_url(); - bottom_footer(); + break; + case 'edit': + top_header(); + webseer_edit_url(); + bottom_footer(); - break; -case 'history': - webseer_show_history(); + break; + case 'history': + webseer_show_history(); - break; -default: - list_urls(); + break; + default: + list_urls(); - break; + break; } exit; @@ -95,14 +95,14 @@ function form_actions() { global $webseer_actions_url; - /* if we are to save this form, instead of display it */ + // if we are to save this form, instead of display it if (isset_request_var('selected_items')) { $selected_items = sanitize_unserialize_selected_items(get_nfilter_request_var('selected_items')); $action = get_nfilter_request_var('drp_action'); if ($selected_items != false) { if (cacti_sizeof($selected_items)) { - foreach($selected_items as $url) { + foreach ($selected_items as $url) { $urls[] = $url; } } @@ -110,26 +110,26 @@ function form_actions() { if (cacti_sizeof($urls)) { if ($action == WEBSEER_ACTION_URL_DELETE) { // delete foreach ($urls as $id) { - db_execute_prepared('DELETE FROM plugin_webseer_urls WHERE id = ?', array($id)); - db_execute_prepared('DELETE FROM plugin_webseer_urls_log WHERE url_id = ?', array($id)); + db_execute_prepared('DELETE FROM plugin_webseer_urls WHERE id = ?', [$id]); + db_execute_prepared('DELETE FROM plugin_webseer_urls_log WHERE url_id = ?', [$id]); plugin_webseer_delete_remote_hosts($id); } } elseif ($action == WEBSEER_ACTION_URL_DISABLE) { // disable foreach ($urls as $id) { - db_execute_prepared('UPDATE plugin_webseer_urls SET enabled = "" WHERE id = ?', array($id)); + db_execute_prepared('UPDATE plugin_webseer_urls SET enabled = "" WHERE id = ?', [$id]); plugin_webseer_enable_remote_hosts($id, false); } } elseif ($action == WEBSEER_ACTION_URL_ENABLE) { // enable foreach ($urls as $id) { - db_execute_prepared('UPDATE plugin_webseer_urls SET enabled = "on" WHERE id = ?', array($id)); + db_execute_prepared('UPDATE plugin_webseer_urls SET enabled = "on" WHERE id = ?', [$id]); plugin_webseer_enable_remote_hosts($id, true); } } elseif ($action == WEBSEER_ACTION_URL_DUPLICATE) { // duplicate - foreach($urls as $url) { + foreach ($urls as $url) { $newid = 1; foreach ($urls as $id) { - $save = db_fetch_row_prepared('SELECT * FROM plugin_webseer_urls WHERE id = ?', array($id)); + $save = db_fetch_row_prepared('SELECT * FROM plugin_webseer_urls WHERE id = ?', [$id]); $save['id'] = 0; $save['poller_id'] = 1; $save['display_name'] = 'New Service Check (' . $newid . ')'; @@ -163,18 +163,18 @@ function form_actions() { exit; } - /* setup some variables */ + // setup some variables $url_list = ''; - $url_array = array(); + $url_array = []; - /* loop through each of the graphs selected on the previous page and get more info about them */ + // loop through each of the graphs selected on the previous page and get more info about them foreach ($_POST as $var => $val) { if (preg_match('/^chk_([0-9]+)$/', $var, $matches)) { - /* ================= input validation ================= */ + // ================= input validation ================= input_validate_input_number($matches[1]); - /* ==================================================== */ + // ==================================================== - $url_list .= '
  • ' . db_fetch_cell_prepared('SELECT display_name FROM plugin_webseer_urls WHERE id = ?', array($matches[1])) . '
  • '; + $url_list .= '
  • ' . html_escape(db_fetch_cell_prepared('SELECT display_name FROM plugin_webseer_urls WHERE id = ?', [$matches[1]])) . '
  • '; $url_array[] = $matches[1]; } } @@ -235,7 +235,7 @@ function form_actions() { - + $save_html \n"; @@ -248,13 +248,13 @@ function form_actions() { } function form_save() { - /* ================= input validation ================= */ + // ================= input validation ================= get_filter_request_var('id'); get_filter_request_var('poller_id'); get_filter_request_var('downtrigger'); get_filter_request_var('timeout_trigger'); get_filter_request_var('compression'); - /* ==================================================== */ + // ==================================================== if (isset_request_var('id')) { $save['id'] = get_request_var('id'); @@ -338,9 +338,9 @@ function purge_log_events($id) { $name = db_fetch_cell_prepared('SELECT display_name FROM plugin_webseer_urls WHERE id = ?', - array($id)); + [$id]); - db_execute_prepared('DELETE FROM plugin_webseer_urls_log WHERE url_id = ?', array($id)); + db_execute_prepared('DELETE FROM plugin_webseer_urls_log WHERE url_id = ?', [$id]); raise_message('url_log_purged', __('The Service Check history was purged for %s', $name, 'webseer'), MESSAGE_LEVEL_INFO); } @@ -348,13 +348,14 @@ function purge_log_events($id) { function webseer_edit_url() { global $webseer_url_fields; - /* ================= input validation ================= */ + // ================= input validation ================= get_filter_request_var('id'); - /* ==================================================== */ + // ==================================================== + + $url = []; - $url = array(); if (!isempty_request_var('id')) { - $url = db_fetch_row_prepared('SELECT * FROM plugin_webseer_urls WHERE id = ?', array(get_request_var('id')), false); + $url = db_fetch_row_prepared('SELECT * FROM plugin_webseer_urls WHERE id = ?', [get_request_var('id')], false); $header_label = __('Query [edit: %s]', $url['url'], 'webseer'); } else { $header_label = __('Query [new]', 'webseer'); @@ -370,10 +371,10 @@ function webseer_edit_url() { html_start_box($header_label, '100%', '', '3', 'center', ''); draw_edit_form( - array( - 'config' => array('form_name' => 'chk'), + [ + 'config' => ['form_name' => 'chk'], 'fields' => inject_form_variables($webseer_url_fields, $url) - ) + ] ); html_end_box(); @@ -393,19 +394,19 @@ function webseer_edit_url() { }); $('#notify_accounts').hide().multiselect({ - noneSelectedText: '', + noneSelectedText: '', selectedText: function(numChecked, numTotal, checkedItems) { - myReturn = numChecked + ' '; + myReturn = numChecked + ' '; $.each(checkedItems, function(index, value) { if (value.value == '0') { - myReturn=''; + myReturn=''; return false; } }); return myReturn; }, - checkAllText: '', - uncheckAllText: '', + checkAllText: '', + uncheckAllText: '', uncheckall: function() { $(this).multiselect('widget').find(':checkbox:first').each(function() { $(this).prop('checked', true); @@ -438,7 +439,7 @@ function webseer_edit_url() { } } }).multiselectfilter({ - label: '', + label: '', width: msWidth }); }); @@ -451,88 +452,88 @@ function webseer_edit_url() { * This is a generic function for this page that makes sure that * we have a good request. We want to protect against people who * like to create issues with Cacti. -*/ + */ function webseer_request_validation() { - /* ================= input validation and session storage ================= */ - $filters = array( - 'rows' => array( - 'filter' => FILTER_VALIDATE_INT, + // ================= input validation and session storage ================= + $filters = [ + 'rows' => [ + 'filter' => FILTER_VALIDATE_INT, 'pageset' => true, 'default' => '-1' - ), - 'page' => array( - 'filter' => FILTER_VALIDATE_INT, + ], + 'page' => [ + 'filter' => FILTER_VALIDATE_INT, 'default' => '1' - ), - 'refresh' => array( - 'filter' => FILTER_VALIDATE_INT, + ], + 'refresh' => [ + 'filter' => FILTER_VALIDATE_INT, 'pageset' => true, 'default' => read_config_option('log_refresh_interval') - ), - 'rfilter' => array( - 'filter' => FILTER_VALIDATE_IS_REGEX, + ], + 'rfilter' => [ + 'filter' => FILTER_VALIDATE_IS_REGEX, 'default' => '', 'pageset' => true, - 'options' => array('options' => 'sanitize_search_string') - ), - 'sort_column' => array( - 'filter' => FILTER_CALLBACK, + 'options' => ['options' => 'sanitize_search_string'] + ], + 'sort_column' => [ + 'filter' => FILTER_CALLBACK, 'default' => 'display_name', - 'options' => array('options' => 'sanitize_search_string') - ), - 'sort_direction' => array( - 'filter' => FILTER_CALLBACK, + 'options' => ['options' => 'sanitize_search_string'] + ], + 'sort_direction' => [ + 'filter' => FILTER_CALLBACK, 'default' => 'ASC', - 'options' => array('options' => 'sanitize_search_string') - ), - 'state' => array( - 'filter' => FILTER_VALIDATE_INT, + 'options' => ['options' => 'sanitize_search_string'] + ], + 'state' => [ + 'filter' => FILTER_VALIDATE_INT, 'pageset' => true, 'default' => '-1' - ) - ); + ] + ]; validate_store_request_vars($filters, 'sess_webseerurl'); - /* ================= input validation ================= */ + // ================= input validation ================= } function webseer_log_request_validation() { global $title, $rows_selector, $config, $reset_multi; - /* ================= input validation and session storage ================= */ - $filters = array( - 'id' => array( - 'filter' => FILTER_VALIDATE_INT, + // ================= input validation and session storage ================= + $filters = [ + 'id' => [ + 'filter' => FILTER_VALIDATE_INT, 'default' => '-1' - ), - 'rows' => array( - 'filter' => FILTER_VALIDATE_INT, + ], + 'rows' => [ + 'filter' => FILTER_VALIDATE_INT, 'pageset' => true, 'default' => '-1' - ), - 'page' => array( - 'filter' => FILTER_VALIDATE_INT, + ], + 'page' => [ + 'filter' => FILTER_VALIDATE_INT, 'default' => '1' - ), - 'filter' => array( - 'filter' => FILTER_CALLBACK, + ], + 'filter' => [ + 'filter' => FILTER_CALLBACK, 'default' => '', - 'options' => array('options' => 'sanitize_search_string') - ), - 'sort_column' => array( - 'filter' => FILTER_CALLBACK, + 'options' => ['options' => 'sanitize_search_string'] + ], + 'sort_column' => [ + 'filter' => FILTER_CALLBACK, 'default' => 'lastcheck', - 'options' => array('options' => 'sanitize_search_string') - ), - 'sort_direction' => array( - 'filter' => FILTER_CALLBACK, + 'options' => ['options' => 'sanitize_search_string'] + ], + 'sort_direction' => [ + 'filter' => FILTER_CALLBACK, 'default' => 'DESC', - 'options' => array('options' => 'sanitize_search_string') - ), - ); + 'options' => ['options' => 'sanitize_search_string'] + ], + ]; validate_store_request_vars($filters, 'sess_webseer_log'); - /* ================= input validation ================= */ + // ================= input validation ================= } function webseer_show_history() { @@ -570,7 +571,7 @@ function webseer_show_history() { } $sql_order = get_order_string(); - $sql_limit = ' LIMIT ' . ($rows*(get_request_var('page')-1)) . ',' . $rows; + $sql_limit = ' LIMIT ' . ($rows * (get_request_var('page') - 1)) . ',' . $rows; $result = db_fetch_assoc_prepared("SELECT wl.*, wu.url FROM plugin_webseer_urls_log AS wl @@ -588,42 +589,42 @@ function webseer_show_history() { $sql_where", $sql_params); - $display_text = array( - 'lastcheck' => array( + $display_text = [ + 'lastcheck' => [ 'display' => __('Date', 'webseer') - ), - 'url' => array( + ], + 'url' => [ 'display' => __('URL', 'webseer'), - ), - 'result' => array( + ], + 'result' => [ 'display' => __('Error', 'webseer'), - ), - 'http_code' => array( + ], + 'http_code' => [ 'display' => __('HTTP Code', 'webseer'), 'align' => 'right', 'sort' => 'DESC' - ), - 'namelookup_time' => array( + ], + 'namelookup_time' => [ 'display' => __('DNS', 'webseer'), 'align' => 'right', 'sort' => 'DESC' - ), - 'connect_time' => array( + ], + 'connect_time' => [ 'display' => __('Connect', 'webseer'), 'align' => 'right', 'sort' => 'DESC' - ), - 'redirect_time' => array( + ], + 'redirect_time' => [ 'display' => __('Redirect', 'webseer'), 'align' => 'right', 'sort' => 'DESC' - ), - 'total_time' => array( + ], + 'total_time' => [ 'display' => __('Total', 'webseer'), 'align' => 'right', 'sort' => 'DESC' - ), - ); + ], + ]; $nav = html_nav_bar('webseer.php?action=history', MAX_DISPLAY_PAGES, get_request_var('page'), $rows, $total_rows, cacti_sizeof($display_text), __('Urls', 'webseer'), 'page', 'main'); @@ -640,9 +641,9 @@ function webseer_show_history() { if (count($result)) { foreach ($result as $row) { if ($row['result'] == 1) { - $style = "color:rgba(10,10,10,0.8);background-color:rgba(204, 255, 204, 0.6)"; + $style = 'color:rgba(10,10,10,0.8);background-color:rgba(204, 255, 204, 0.6)'; } else { - $style = "color:rgba(10,10,10,0.8);background-color:rgba(242, 25, 36, 0.6);"; + $style = 'color:rgba(10,10,10,0.8);background-color:rgba(242, 25, 36, 0.6);'; } print ""; @@ -651,10 +652,10 @@ function webseer_show_history() { form_selectable_cell("" . $row['url'] . '', $row['id']); form_selectable_cell(($row['result'] == 1 ? __('Service Restored', 'webseer') : __('Service Down', 'webseer')), $row['id']); form_selectable_cell($httperrors[$row['http_code']], $row['id'], '', 'right'); - form_selectable_cell(round($row['namelookup_time'], 4), $row['id'], '', ($row['namelookup_time'] > 4 ? 'background-color: red;text-align:right' : ($row['namelookup_time'] > 1 ? 'background-color: yellow;text-align:right':'text-align:right'))); - form_selectable_cell(round($row['connect_time'], 4), $row['id'], '', ($row['connect_time'] > 4 ? 'background-color: red;text-align:right' : ($row['connect_time'] > 1 ? 'background-color: yellow;text-align:right':'text-align:right'))); - form_selectable_cell(round($row['redirect_time'], 4), $row['id'], '', ($row['redirect_time'] > 4 ? 'background-color: red;text-align:right' : ($row['redirect_time'] > 1 ? 'background-color: yellow;text-align:right':'text-align:right'))); - form_selectable_cell(round($row['total_time'], 4), $row['id'], '', ($row['total_time'] > 4 ? 'background-color: red;text-align:right' : ($row['total_time'] > 1 ? 'background-color: yellow;text-align:right':'text-align:right'))); + form_selectable_cell(round($row['namelookup_time'], 4), $row['id'], '', ($row['namelookup_time'] > 4 ? 'background-color: red;text-align:right' : ($row['namelookup_time'] > 1 ? 'background-color: yellow;text-align:right' : 'text-align:right'))); + form_selectable_cell(round($row['connect_time'], 4), $row['id'], '', ($row['connect_time'] > 4 ? 'background-color: red;text-align:right' : ($row['connect_time'] > 1 ? 'background-color: yellow;text-align:right' : 'text-align:right'))); + form_selectable_cell(round($row['redirect_time'], 4), $row['id'], '', ($row['redirect_time'] > 4 ? 'background-color: red;text-align:right' : ($row['redirect_time'] > 1 ? 'background-color: yellow;text-align:right' : 'text-align:right'))); + form_selectable_cell(round($row['total_time'], 4), $row['id'], '', ($row['total_time'] > 4 ? 'background-color: red;text-align:right' : ($row['total_time'] > 1 ? 'background-color: yellow;text-align:right' : 'text-align:right'))); form_end_row(); } @@ -673,40 +674,41 @@ function webseer_show_history() { function list_urls() { global $webseer_actions_url, $httperrors, $config, $hostid, $refresh, $httpcompressions; - /* ================= input validation and session storage ================= */ - $filters = array( - 'rows' => array( - 'filter' => FILTER_VALIDATE_INT, + // ================= input validation and session storage ================= + $filters = [ + 'rows' => [ + 'filter' => FILTER_VALIDATE_INT, 'pageset' => true, 'default' => '-1' - ), - 'state' => array( - 'filter' => FILTER_VALIDATE_INT, + ], + 'state' => [ + 'filter' => FILTER_VALIDATE_INT, 'pageset' => true, 'default' => '-1' - ), - 'refresh' => array( - 'filter' => FILTER_VALIDATE_INT, + ], + 'refresh' => [ + 'filter' => FILTER_VALIDATE_INT, 'default' => read_config_option('log_refresh_interval') - ), - 'sort_column' => array( - 'filter' => FILTER_CALLBACK, + ], + 'sort_column' => [ + 'filter' => FILTER_CALLBACK, 'default' => 'display_name', - 'options' => array('options' => 'sanitize_search_string') - ), - 'sort_direction' => array( - 'filter' => FILTER_CALLBACK, + 'options' => ['options' => 'sanitize_search_string'] + ], + 'sort_direction' => [ + 'filter' => FILTER_CALLBACK, 'default' => 'ASC', - 'options' => array('options' => 'sanitize_search_string') - ) - ); + 'options' => ['options' => 'sanitize_search_string'] + ] + ]; validate_store_request_vars($filters, 'sess_wbsu'); - /* ================= input validation ================= */ + // ================= input validation ================= webseer_request_validation(); $statefilter = ''; + if (isset_request_var('state')) { if (get_request_var('state') == '-1') { $statefilter = ''; @@ -738,15 +740,16 @@ function list_urls() { } $sql_order = get_order_string(); - $sql_limit = ' LIMIT ' . ($rows*(get_request_var('page')-1)) . ',' . $rows; + $sql_limit = ' LIMIT ' . ($rows * (get_request_var('page') - 1)) . ',' . $rows; if (get_request_var('rfilter') != '') { + $rfilter = db_qstr(get_request_var('rfilter')); $sql_where .= ($sql_where == '' ? 'WHERE ' : ' AND ') . - 'display_name RLIKE \'' . get_request_var('rfilter') . '\' OR ' . - 'url RLIKE \'' . get_request_var('rfilter') . '\' OR ' . - 'search RLIKE \'' . get_request_var('rfilter') . '\' OR ' . - 'search_maint RLIKE \'' . get_request_var('rfilter') . '\' OR ' . - 'search_failed RLIKE \'' . get_request_var('rfilter') . '\''; + 'display_name RLIKE ' . $rfilter . ' OR ' . + 'url RLIKE ' . $rfilter . ' OR ' . + 'search RLIKE ' . $rfilter . ' OR ' . + 'search_maint RLIKE ' . $rfilter . ' OR ' . + 'search_failed RLIKE ' . $rfilter; } $result = db_fetch_assoc("SELECT * @@ -759,73 +762,73 @@ function list_urls() { FROM plugin_webseer_urls $sql_where"); - $display_text = array( - 'nosort' => array( + $display_text = [ + 'nosort' => [ 'display' => __('Actions', 'webseer'), 'sort' => '', 'align' => 'left' - ), - 'display_name' => array( + ], + 'display_name' => [ 'display' => __('Name', 'webseer'), 'sort' => 'ASC', 'align' => 'left' - ), - 'result' => array( + ], + 'result' => [ 'display' => __('Status', 'webseer'), 'sort' => 'ASC', 'align' => 'right' - ), - 'enabled' => array( + ], + 'enabled' => [ 'display' => __('Enabled', 'webseer'), 'sort' => 'ASC', 'align' => 'right' - ), - 'compression' => array( + ], + 'compression' => [ 'display' => __('Compression', 'webseer'), 'sort' => 'ASC', 'align' => 'right' - ), - 'http_code' => array( + ], + 'http_code' => [ 'display' => __('HTTP Code', 'webseer'), 'sort' => 'ASC', 'align' => 'right' - ), - 'requireauth' => array( + ], + 'requireauth' => [ 'display' => __('Auth', 'webseer'), 'sort' => 'ASC', 'align' => 'right' - ), - 'namelookup_time' => array( + ], + 'namelookup_time' => [ 'display' => __('DNS', 'webseer'), 'sort' => 'ASC', 'align' => 'right' - ), - 'connect_time' => array( + ], + 'connect_time' => [ 'display' => __('Connect', 'webseer'), 'sort' => 'ASC', 'align' => 'right' - ), - 'redirect_time' => array( + ], + 'redirect_time' => [ 'display' => __('Redirect', 'webseer'), 'sort' => 'ASC', 'align' => 'right' - ), - 'total_time' => array( + ], + 'total_time' => [ 'display' => __('Total', 'webseer'), 'sort' => 'ASC', 'align' => 'right' - ), - 'timeout_trigger' => array( + ], + 'timeout_trigger' => [ 'display' => __('Timeout', 'webseer'), 'sort' => 'ASC', 'align' => 'right' - ), - 'lastcheck' => array( + ], + 'lastcheck' => [ 'display' => __('Last Check', 'webseer'), 'sort' => 'ASC', 'align' => 'right' - ) - ); + ] + ]; $columns = cacti_sizeof($display_text); @@ -842,11 +845,11 @@ function list_urls() { if (cacti_sizeof($result)) { foreach ($result as $row) { if ($row['enabled'] == '') { - $style = "color:rgba(10,10,10,0.8);background-color:rgba(205, 207, 196, 0.6)"; + $style = 'color:rgba(10,10,10,0.8);background-color:rgba(205, 207, 196, 0.6)'; } elseif ($row['result'] == 0 && strtotime($row['lastcheck']) > 0) { - $style = "color:rgba(10,10,10,0.8);background-color:rgba(242, 25, 36, 0.6);"; + $style = 'color:rgba(10,10,10,0.8);background-color:rgba(242, 25, 36, 0.6);'; } else { - $style = "color:rgba(10,10,10,0.8);background-color:rgba(204, 255, 204, 0.6)"; + $style = 'color:rgba(10,10,10,0.8);background-color:rgba(204, 255, 204, 0.6)'; } print ""; @@ -872,9 +875,10 @@ function list_urls() { "; $url = ''; + if ($row['type'] == 'http') { $url = $row['url']; - } else if ($row['type'] == 'dns') { + } elseif ($row['type'] == 'dns') { $url = __('DNS: Server %s - A Record for %s', $row['url'], $row['search'], 'webseer'); } @@ -892,13 +896,13 @@ function list_urls() { form_selectable_cell(($row['enabled'] == 'on' ? __('Enabled', 'webseer') : __('Disabled', 'webseer')), $row['id'], '', 'right'); form_selectable_cell($httpcompressions[$row['compression']], $row['id'], '', 'right'); - form_selectable_cell(!empty($row['http_code']) ? $httperrors[$row['http_code']]:__('Error', 'webseer'), $row['id'], '', $row['error'] != '' ? 'deviceDown right':'right', $row['error']); - form_selectable_cell($row['requiresauth'] == '' ? __('Disabled', 'webseer'): __('Enabled', 'webseer'), $row['id'], '', 'right'); + form_selectable_cell(!empty($row['http_code']) ? $httperrors[$row['http_code']] : __('Error', 'webseer'), $row['id'], '', $row['error'] != '' ? 'deviceDown right' : 'right', $row['error']); + form_selectable_cell($row['requiresauth'] == '' ? __('Disabled', 'webseer') : __('Enabled', 'webseer'), $row['id'], '', 'right'); - form_selectable_cell(round(webseer_checknull($row['namelookup_time']), 4), $row['id'], '', ($row['namelookup_time'] > 4 ? 'deviceDown right' : ($row['namelookup_time'] > 1 ? 'deviceRecovering right':'right'))); - form_selectable_cell(round(webseer_checknull($row['connect_time']), 4), $row['id'], '', ($row['connect_time'] > 4 ? 'deviceDown right' : ($row['connect_time'] > 1 ? 'deviceRecovering right':'right'))); - form_selectable_cell(round(webseer_checknull($row['redirect_time']), 4), $row['id'], '', ($row['redirect_time'] > 4 ? 'deviceDown right' : ($row['redirect_time'] > 1 ? 'deviceRecovering right':'right'))); - form_selectable_cell(round(webseer_checknull($row['total_time']), 4), $row['id'], '', ($row['total_time'] > 4 ? 'deviceDown right' : ($row['total_time'] > 1 ? 'deviceRecovering right':'right'))); + form_selectable_cell(round(webseer_checknull($row['namelookup_time']), 4), $row['id'], '', ($row['namelookup_time'] > 4 ? 'deviceDown right' : ($row['namelookup_time'] > 1 ? 'deviceRecovering right' : 'right'))); + form_selectable_cell(round(webseer_checknull($row['connect_time']), 4), $row['id'], '', ($row['connect_time'] > 4 ? 'deviceDown right' : ($row['connect_time'] > 1 ? 'deviceRecovering right' : 'right'))); + form_selectable_cell(round(webseer_checknull($row['redirect_time']), 4), $row['id'], '', ($row['redirect_time'] > 4 ? 'deviceDown right' : ($row['redirect_time'] > 1 ? 'deviceRecovering right' : 'right'))); + form_selectable_cell(round(webseer_checknull($row['total_time']), 4), $row['id'], '', ($row['total_time'] > 4 ? 'deviceDown right' : ($row['total_time'] > 1 ? 'deviceRecovering right' : 'right'))); form_selectable_cell($row['timeout_trigger'], $row['id'], '', 'right'); form_selectable_cell((strtotime($row['lastcheck']) > 0 ? substr($row['lastcheck'],5) : ''), $row['id'], '', 'right'); @@ -941,7 +945,7 @@ function list_urls() { } function webseer_checknull($value) { - if ($value == NULL) { + if ($value == null) { return '0'; } else { return $value; @@ -1002,59 +1006,65 @@ function clearFilter() { @@ -1076,7 +1086,7 @@ function webseer_log_filter() { refreshMSeconds=99999999; function applyFilter() { - strURL = 'webseer.php?action=history&header=false&id='; + strURL = 'webseer.php?action=history&header=false&id='; strURL += '&filter=' + $('#filter').val(); strURL += '&rows=' + $('#rows').val(); refreshMSeconds=99999999; @@ -1089,7 +1099,7 @@ function clearFilter() { } function purgeEvents() { - strURL = 'webseer.php?action=purge&id='; + strURL = 'webseer.php?action=purge&id='; loadPageNoHeader(strURL); } @@ -1123,31 +1133,36 @@ function purgeEvents() {
    - + - '> + '> - + - + - + - '> - '> + '> + '>
    @@ -1158,4 +1173,3 @@ function purgeEvents() { proxy_hostname = $proxy['hostname']; + if ($url['type'] == 'http') { $cc->proxy_port = $proxy['http_port']; } else { @@ -154,11 +157,13 @@ } } - $results = $cc->get($url['url']); + $results = $cc->get($url['url']); $results['data'] = $cc->data; + break; case 'dns': $results = plugin_webseer_check_dns($url); + break; } @@ -174,13 +179,13 @@ // Do calculations for triggering $pi = read_config_option('poller_interval'); $t = time() - ($url['downtrigger'] * 60); - $lc = time() - ($pi*2); + $lc = time() - ($pi * 2); $ts = db_fetch_cell_prepared('SELECT count(id) FROM plugin_webseer_servers WHERE isme = 1 OR (isme = 0 AND UNIX_TIMESTAMP(lastcheck) > ?)', - array($lc)); + [$lc]); $tf = ($ts * ($url['downtrigger'] - 1)) + 1; @@ -188,11 +193,11 @@ FROM plugin_webseer_servers_log WHERE UNIX_TIMESTAMP(lastcheck) > ? AND url_id = ?', - array($t, $url['id'])); + [$t, $url['id']]); plugin_webseer_debug('pi:' . $pi . ', t:' . $t . ' (' . date('Y-m-d H:i:s', $t) . '), lc:' . $lc . ' (' . date('Y-m-d H:i:s', $lc) . '), ts:' . $ts . ', tf:' . $tf, $url); - plugin_webseer_debug('failures:'. $url['failures'] . ', triggered:' . $url['triggered'], $url); + plugin_webseer_debug('failures:' . $url['failures'] . ', triggered:' . $url['triggered'], $url); if (strtotime($url['lastcheck']) > 0 && (($url['result'] != '' && $url['result'] != $results['result']) || $url['failures'] > 0 || $url['triggered'] == 1)) { plugin_webseer_debug('Checking for trigger', $url); @@ -202,32 +207,32 @@ if ($results['result'] == 0) { $url['failures']++; - if ($url['failures'] >= ($url['downtrigger'] * 60)/$poller_interval && $url['triggered'] == 0) { - $sendemail = true; + if ($url['failures'] >= ($url['downtrigger'] * 60) / $poller_interval && $url['triggered'] == 0) { + $sendemail = true; $url['triggered'] = 1; } } if ($results['result'] == 1) { if ($url['failures'] == 0 && $url['triggered'] == 1) { - $sendemail = true; + $sendemail = true; $url['triggered'] = 0; } } - db_execute_prepared("INSERT INTO plugin_webseer_urls_log + db_execute_prepared('INSERT INTO plugin_webseer_urls_log (url_id, lastcheck, compression, result, http_code, error, total_time, namelookup_time, connect_time, redirect_time, redirect_count, size_download, speed_download) - VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", - array($url['id'], date('Y-m-d H:i:s', $results['time']), + VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', + [$url['id'], date('Y-m-d H:i:s', $results['time']), $results['options']['compression'], $results['result'], $results['options']['http_code'], $results['error'], $results['options']['total_time'], $results['options']['namelookup_time'], $results['options']['connect_time'], $results['options']['redirect_time'], $results['options']['redirect_count'], $results['options']['size_download'], $results['options']['speed_download'] - ) + ] ); if ($sendemail) { @@ -253,17 +258,17 @@ connect_time = ?, redirect_time = ?, redirect_count = ?, speed_download = ?, size_download = ?, debug = ? WHERE id = ?', - array($results['result'], $url['triggered'], $url['failures'], date('Y-m-d H:i:s', $results['time']), + [$results['result'], $url['triggered'], $url['failures'], date('Y-m-d H:i:s', $results['time']), $results['error'], $results['options']['http_code'], $results['options']['total_time'], $results['options']['namelookup_time'], $results['options']['connect_time'], $results['options']['redirect_time'], $results['options']['redirect_count'], $results['options']['speed_download'], $results['options']['size_download'], $results['data'], $url['id'] - ) + ] ); if ($results['result'] == 0) { - $save = array(); + $save = []; $save['url_id'] = $url['id']; $save['server'] = plugin_webseer_whoami(); $save['lastcheck'] = date('Y-m-d H:i:s', $results['time']); @@ -285,37 +290,37 @@ namelookup_time, connect_time, redirect_time, redirect_count, size_download, speed_download) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', - array($url['id'], plugin_webseer_whoami(), date('Y-m-d H:i:s', $results['time']), + [$url['id'], plugin_webseer_whoami(), date('Y-m-d H:i:s', $results['time']), $results['result'], $results['options']['http_code'], $results['error'], $results['options']['total_time'], $results['options']['namelookup_time'], $results['options']['connect_time'], $results['options']['redirect_time'], $results['options']['redirect_count'], $results['options']['size_download'], - $results['options']['speed_download']) + $results['options']['speed_download']] ); } db_execute_prepared('UPDATE plugin_webseer_servers SET lastcheck=NOW() WHERE id = ?', - array(plugin_webseer_whoami())); + [plugin_webseer_whoami()]); } -/* register process end */ +// register process end register_shutdown($url_id, $url['poller_id']); -/* purge old entries from the log */ +// purge old entries from the log db_execute_prepared('DELETE FROM plugin_webseer_servers_log WHERE lastcheck < FROM_UNIXTIME(?)', - array(time() - (86400 * 90))); + [time() - (86400 * 90)]); -/* exit */ +// exit function register_startup($url_id, $poller_id) { db_execute_prepared('INSERT INTO plugin_webseer_processes (url_id, poller_id, pid, time) VALUES(?, ?, ?, NOW())', - array($url_id, $poller_id, getmypid())); + [$url_id, $poller_id, getmypid()]); } function register_shutdown($url_id, $poller_id) { @@ -323,21 +328,23 @@ function register_shutdown($url_id, $poller_id) { WHERE url_id = ? AND poller_id = ? AND pid = ?', - array($url_id, $poller_id, getmypid()), false); + [$url_id, $poller_id, getmypid()], false); } function plugin_webseer_get_users($results, $url, $type) { global $httperrors; $users = ''; + if ($url['notify_accounts'] != '') { - $users = db_fetch_cell("SELECT GROUP_CONCAT(DISTINCT data) AS emails + $users = db_fetch_cell('SELECT GROUP_CONCAT(DISTINCT data) AS emails FROM plugin_webseer_contacts - WHERE id IN (" . $url['notify_accounts'] . ")"); + WHERE id IN (' . $url['notify_accounts'] . ')'); } if ($users == '' && isset($url['notify_extra']) && $url['notify_extra'] == '' && $url['notify_list'] <= 0) { cacti_log('ERROR: No users to send WEBSEER Notification for ' . $url['display_name'], false, 'WEBSEER'); + return; } @@ -348,17 +355,17 @@ function plugin_webseer_get_users($results, $url, $type) { } if ($url['notify_extra'] != '') { - $to .= ($to != '' ? ', ':'') . $url['notify_extra']; + $to .= ($to != '' ? ', ' : '') . $url['notify_extra']; } if ($url['notify_list'] > 0) { $emails = db_fetch_cell_prepared('SELECT emails FROM plugin_notification_lists WHERE id = ?', - array($url['notify_list'])); + [$url['notify_list']]); if ($emails != '') { - $to .= ($to != '' ? ', ':'') . $emails; + $to .= ($to != '' ? ', ' : '') . $emails; } } @@ -369,9 +376,9 @@ function plugin_webseer_get_users($results, $url, $type) { $subject = 'Site Recovered: ' . ($url['display_name'] != '' ? $url['display_name'] : $url['url']); } - $message = 'Site ' . ($results['result'] == 0 ? 'Down: ' : 'Recovering: ') . ($url['display_name'] != '' ? $url['display_name']:'') . "\n"; - $message .= 'URL: ' . $url['url'] . "\n"; - $message .= 'Error: ' . $results['error'] . "\n"; + $message = 'Site ' . ($results['result'] == 0 ? 'Down: ' : 'Recovering: ') . ($url['display_name'] != '' ? $url['display_name'] : '') . "\n"; + $message .= 'URL: ' . $url['url'] . "\n"; + $message .= 'Error: ' . $results['error'] . "\n"; $message .= 'Total Time: ' . $results['options']['total_time'] . "\n"; } else { if ($results['result'] == 0) { @@ -384,34 +391,35 @@ function plugin_webseer_get_users($results, $url, $type) { $message .= '
    '; $message .= "
    - + - '> + '> - + - '> - '> - '> + '> + '> + '>
    \n"; - $message .= "\n"; - $message .= "\n"; - $message .= "\n"; - $message .= "\n"; + $message .= '\n"; + $message .= '\n"; + $message .= '\n"; + $message .= '\n"; if ($results['error'] != '') { - $message .= "\n"; + $message .= '\n"; } $message .= "
    URL:" . $url['url'] . "
    Status:" . ($results['result'] == 0 ? 'Down' : 'Recovering') . "
    Date:" . date('F j, Y - h:i:s', $results['time']) . "
    HTTP Code:" . $httperrors[$results['options']['http_code']] . "
    URL:' . $url['url'] . "
    Status:' . ($results['result'] == 0 ? 'Down' : 'Recovering') . "
    Date:' . date('F j, Y - h:i:s', $results['time']) . "
    HTTP Code:' . $httperrors[$results['options']['http_code']] . "
    Error:" . $results['error'] . "
    Error:' . $results['error'] . "
    \n"; - $message .= "
    "; + $message .= '
    '; if ($results['error'] > 0) { $message .= "\n"; - $message .= "\n"; - $message .= "\n"; - $message .= "\n"; - $message .= "\n"; - $message .= "\n"; - $message .= "\n"; - $message .= "\n"; + $message .= '\n"; + $message .= '\n"; + $message .= '\n"; + $message .= '\n"; + $message .= '\n"; + $message .= '\n"; + $message .= '\n"; $message .= "
    Total Time: " . round($results['options']['total_time'],4) . "
    Connect Time: " . round($results['options']['connect_time'],4) . "
    DNS Time: " . round($results['options']['namelookup_time'],4) . "
    Redirect Time: " . round($results['options']['redirect_time'],4) . "
    Redirect Count: " . round($results['options']['redirect_count'],4) . "
    Download Size: " . round($results['options']['size_download'],4) . " Bytes" . "
    Download Speed: " . round($results['options']['speed_download'],4) . " Bps" . "
    Total Time: ' . round($results['options']['total_time'],4) . "
    Connect Time: ' . round($results['options']['connect_time'],4) . "
    DNS Time: ' . round($results['options']['namelookup_time'],4) . "
    Redirect Time: ' . round($results['options']['redirect_time'],4) . "
    Redirect Count: ' . round($results['options']['redirect_count'],4) . "
    Download Size: ' . round($results['options']['size_download'],4) . ' Bytes' . "
    Download Speed: ' . round($results['options']['speed_download'],4) . ' Bps' . "
    \n"; - $message .= "
    "; + $message .= '
    '; } } $users = explode(',', $to); + foreach ($users as $u) { plugin_webseer_send_email($u, $subject, $message); } @@ -430,7 +438,7 @@ function plugin_webseer_amimaster() { FROM plugin_webseer_servers WHERE ip = ? AND master = 1', - array($ipaddress)); + [$ipaddress]); if ($server) { return true; @@ -450,7 +458,7 @@ function plugin_webseer_whoami() { $server = db_fetch_cell_prepared('SELECT id FROM plugin_webseer_servers WHERE ip = ?', - array($ipaddress)); + [$ipaddress]); if ($server) { return $server; @@ -483,7 +491,7 @@ function plugin_webseer_send_email($to, $subject, $message) { mailer($from, $to, '', '', '', $subject, $message, $message_text, '', $headers); } -/* display_version - displays version information */ +// display_version - displays version information function display_version() { global $config; @@ -493,16 +501,16 @@ function display_version() { $info = plugin_webseer_version(); - print 'Cacti Web Service Check Processor, Version ' . $info['version'] . ', ' . COPYRIGHT_YEARS . PHP_EOL; + print 'Cacti Web Service Check Processor, Version ' . $info['version'] . ', ' . COPYRIGHT_YEARS . PHP_EOL; } -/* display_help - displays the usage of the function */ +// display_help - displays the usage of the function function display_help() { - display_version(); + display_version(); print PHP_EOL; - print 'usage: webseer_process.php --id=N [--debug]' . PHP_EOL . PHP_EOL; + print 'usage: webseer_process.php --id=N [--debug]' . PHP_EOL . PHP_EOL; print 'This binary will run the Web Service check for the WebSeer plugin.' . PHP_EOL . PHP_EOL; - print '--id=N - The url ID from the WebSeer database.' . PHP_EOL; - print '--debug - Display verbose output during execution' . PHP_EOL . PHP_EOL; + print '--id=N - The url ID from the WebSeer database.' . PHP_EOL; + print '--debug - Display verbose output during execution' . PHP_EOL . PHP_EOL; } diff --git a/webseer_proxies.php b/webseer_proxies.php index e0c68b1..c281538 100644 --- a/webseer_proxies.php +++ b/webseer_proxies.php @@ -29,36 +29,36 @@ set_default_action(); switch (get_request_var('action')) { -case 'save': - proxy_form_save(); - - break; -case 'actions': - proxy_form_actions(); - - break; -case 'edit': - top_header(); - proxy_edit(); - bottom_footer(); - - break; -default: - proxies(); + case 'save': + proxy_form_save(); + + break; + case 'actions': + proxy_form_actions(); + + break; + case 'edit': + top_header(); + proxy_edit(); + bottom_footer(); + + break; + default: + proxies(); } function proxy_form_actions() { global $webseer_actions_proxy; - /* if we are to save this form, instead of display it */ + // if we are to save this form, instead of display it if (isset_request_var('selected_items')) { $selected_items = sanitize_unserialize_selected_items(get_nfilter_request_var('selected_items')); if ($selected_items != false) { if (get_nfilter_request_var('drp_action') == WEBSEER_ACTION_PROXY_DELETE) { // delete - /* do a referential integrity check */ + // do a referential integrity check if (cacti_sizeof($selected_items)) { - foreach($selected_items as $proxy) { + foreach ($selected_items as $proxy) { $proxies[] = $proxy; } } @@ -74,18 +74,18 @@ function proxy_form_actions() { exit; } - /* setup some variables */ + // setup some variables $proxy_list = ''; - $proxy_array = array(); + $proxy_array = []; - /* loop through each of the graphs selected on the previous page and get more info about them */ + // loop through each of the graphs selected on the previous page and get more info about them foreach ($_POST as $var => $val) { if (preg_match('/^chk_([0-9]+)$/', $var, $matches)) { - /* ================= input validation ================= */ + // ================= input validation ================= input_validate_input_number($matches[1]); - /* ==================================================== */ + // ==================================================== - $proxy_list .= '
  • ' . db_fetch_cell_prepared('SELECT name FROM plugin_webseer_proxies WHERE id = ?', array($matches[1])) . '
  • '; + $proxy_list .= '
  • ' . html_escape(db_fetch_cell_prepared('SELECT name FROM plugin_webseer_proxies WHERE id = ?', [$matches[1]])) . '
  • '; $proxy_array[] = $matches[1]; } } @@ -117,7 +117,7 @@ function proxy_form_actions() { - + $save_html \n"; @@ -156,15 +156,15 @@ function proxy_form_save() { function proxy_edit() { global $webseer_proxy_fields; - /* ================= input validation ================= */ + // ================= input validation ================= get_filter_request_var('id'); - /* ==================================================== */ + // ==================================================== if (!isempty_request_var('id')) { $proxy = db_fetch_row_prepared('SELECT * FROM plugin_webseer_proxies WHERE id = ?', - array(get_request_var('id'))); + [get_request_var('id')]); $header_label = __('Proxy [edit: %s]', $proxy['name']); } else { @@ -178,10 +178,10 @@ function proxy_edit() { html_start_box($header_label, '100%', true, '3', 'center', ''); draw_edit_form( - array( - 'config' => array('no_form_tag' => true), - 'fields' => inject_form_variables($webseer_proxy_fields, (isset($proxy) ? $proxy : array())) - ) + [ + 'config' => ['no_form_tag' => true], + 'fields' => inject_form_variables($webseer_proxy_fields, ($proxy ?? [])) + ] ); html_end_box(true, true); @@ -193,43 +193,43 @@ function proxy_edit() { bottom_footer(); } -/* file: rra.php, action: edit */ +// file: rra.php, action: edit /** * This is a generic function for this page that makes sure that * we have a good request. We want to protect against people who * like to create issues with Cacti. -*/ + */ function request_validation() { - /* ================= input validation and session storage ================= */ - $filters = array( - 'rows' => array( - 'filter' => FILTER_VALIDATE_INT, + // ================= input validation and session storage ================= + $filters = [ + 'rows' => [ + 'filter' => FILTER_VALIDATE_INT, 'pageset' => true, 'default' => '-1' - ), - 'page' => array( - 'filter' => FILTER_VALIDATE_INT, + ], + 'page' => [ + 'filter' => FILTER_VALIDATE_INT, 'default' => '1' - ), - 'refresh' => array( - 'filter' => FILTER_VALIDATE_INT, + ], + 'refresh' => [ + 'filter' => FILTER_VALIDATE_INT, 'pageset' => true, 'default' => '20', - ), - 'sort_column' => array( - 'filter' => FILTER_CALLBACK, + ], + 'sort_column' => [ + 'filter' => FILTER_CALLBACK, 'default' => 'name', - 'options' => array('options' => 'sanitize_search_string') - ), - 'sort_direction' => array( - 'filter' => FILTER_CALLBACK, + 'options' => ['options' => 'sanitize_search_string'] + ], + 'sort_direction' => [ + 'filter' => FILTER_CALLBACK, 'default' => 'ASC', - 'options' => array('options' => 'sanitize_search_string') - ) - ); + 'options' => ['options' => 'sanitize_search_string'] + ] + ]; validate_store_request_vars($filters, 'sess_ws_proxy'); - /* ================= input validation ================= */ + // ================= input validation ================= } function proxies() { @@ -252,11 +252,11 @@ function proxies() { $sql_where = ''; if (get_request_var('filter') != '') { - $sql_where .= ($sql_where == '' ? 'WHERE ' : ' AND ') . ' name LIKE "%' . get_request_var('filter') . '%" OR hostname LIKE "%' . get_request_var('filter') . '%"'; + $sql_where .= ($sql_where == '' ? 'WHERE ' : ' AND ') . '(name LIKE ' . db_qstr('%' . get_request_var('filter') . '%') . ' OR hostname LIKE ' . db_qstr('%' . get_request_var('filter') . '%') . ')'; } $sql_order = get_order_string(); - $sql_limit = ' LIMIT ' . ($rows*(get_request_var('page')-1)) . ',' . $rows; + $sql_limit = ' LIMIT ' . ($rows * (get_request_var('page') - 1)) . ',' . $rows; $result = db_fetch_assoc("SELECT * FROM plugin_webseer_proxies @@ -268,24 +268,24 @@ function proxies() { FROM plugin_webseer_proxies $sql_where"); - $display_text = array( - 'name' => array( + $display_text = [ + 'name' => [ 'display' => __('Name', 'webseer'), 'sort' => 'ASC' - ), - 'hostname' => array( + ], + 'hostname' => [ 'display' => __('Hostname', 'webseer'), 'sort' => 'ASC' - ), - 'nosort1' => array( + ], + 'nosort1' => [ 'display' => __('Ports (http/https)', 'webseer'), 'sort' => 'ASC' - ), - 'username' => array( + ], + 'username' => [ 'display' => __('Username', 'webseer'), 'sort' => 'ASC' - ), - ); + ], + ]; $columns = cacti_sizeof($display_text); @@ -306,7 +306,7 @@ function proxies() { form_selectable_cell(filter_value($row['name'], get_request_var('filter'), 'webseer_proxies.php?header=false&action=edit&id=' . $row['id']), $row['id']); form_selectable_cell($row['hostname'], $row['id']); form_selectable_cell($row['http_port'] . '/' . $row['https_port'], $row['id']); - form_selectable_cell($row['username'] == '' ? __('Not Set', 'webseer'):$row['username'], $row['id']); + form_selectable_cell($row['username'] == '' ? __('Not Set', 'webseer') : $row['username'], $row['id']); form_checkbox_cell($row['name'], $row['id']); form_end_row(); @@ -340,30 +340,35 @@ function webseer_filter() { @@ -404,4 +409,3 @@ function clearFilter() { 0) { - db_execute_prepared('UPDATE plugin_webseer_servers SET enabled = "on" WHERE id = ?', array($id)); - plugin_webseer_enable_remote_hosts($id, true); - } + if ($id > 0) { + db_execute_prepared('UPDATE plugin_webseer_servers SET enabled = "on" WHERE id = ?', [$id]); + plugin_webseer_enable_remote_hosts($id, true); + } - header('Location: webseer_servers.php?header=false'); - exit; + header('Location: webseer_servers.php?header=false'); + exit; - break; -case 'disable': - $id = get_request_var('id'); + break; + case 'disable': + $id = get_request_var('id'); - if ($id > 0) { - db_execute_prepared('UPDATE plugin_webseer_servers SET enabled = "" WHERE id = ?', array($id)); - plugin_webseer_enable_remote_hosts($id, false); - } + if ($id > 0) { + db_execute_prepared('UPDATE plugin_webseer_servers SET enabled = "" WHERE id = ?', [$id]); + plugin_webseer_enable_remote_hosts($id, false); + } - header('Location: webseer_servers.php?header=false'); - exit; + header('Location: webseer_servers.php?header=false'); + exit; - break; -case 'history': - webseer_show_history(); + break; + case 'history': + webseer_show_history(); - break; -case 'edit': - top_header(); - webseer_edit_server(); - bottom_footer(); + break; + case 'edit': + top_header(); + webseer_edit_server(); + bottom_footer(); - break; -default: - list_servers(); + break; + default: + list_servers(); - break; + break; } exit(); @@ -82,34 +82,33 @@ function form_actions() { global $webseer_actions_server; - /* if we are to save this form, instead of display it */ + // if we are to save this form, instead of display it if (isset_request_var('selected_items')) { $selected_items = sanitize_unserialize_selected_items(get_nfilter_request_var('selected_items')); $action = get_nfilter_request_var('drp_action'); if ($selected_items != false) { if (cacti_sizeof($selected_items)) { - foreach($selected_items as $host) { + foreach ($selected_items as $host) { $hosts[] = $host; } } if (cacti_sizeof($hosts)) { - if ($action == WEBSEER_ACTION_SERVER_DELETE) { // delete foreach ($hosts as $host) { - db_execute_prepared('DELETE FROM plugin_webseer_servers WHERE id = ?', array($host)); - db_execute_prepared('DELETE FROM plugin_webseer_servers_log WHERE server= ?', array($host)); + db_execute_prepared('DELETE FROM plugin_webseer_servers WHERE id = ?', [$host]); + db_execute_prepared('DELETE FROM plugin_webseer_servers_log WHERE server= ?', [$host]); plugin_webseer_delete_remote_server($host); } } elseif ($action == WEBSEER_ACTION_SERVER_DISABLE) { // disable foreach ($hosts as $host) { - db_execute_prepared('UPDATE plugin_webseer_servers SET enabled = "" WHERE id = ?', array($host)); + db_execute_prepared('UPDATE plugin_webseer_servers SET enabled = "" WHERE id = ?', [$host]); plugin_webseer_enable_remote_hosts($host, false); } } elseif ($action == WEBSEER_ACTION_SERVER_ENABLE) { // enable foreach ($hosts as $host) { - db_execute_prepared('UPDATE plugin_webseer_servers SET enabled = "on" WHERE id = ?', array($host)); + db_execute_prepared('UPDATE plugin_webseer_servers SET enabled = "on" WHERE id = ?', [$host]); plugin_webseer_enable_remote_hosts($host, true); } } @@ -120,18 +119,18 @@ function form_actions() { exit; } - /* setup some variables */ + // setup some variables $server_list = ''; - $server_array = array(); + $server_array = []; - /* loop through each of the graphs selected on the previous page and get more info about them */ + // loop through each of the graphs selected on the previous page and get more info about them foreach ($_POST as $var => $val) { if (preg_match('/^chk_([0-9]+)$/', $var, $matches)) { - /* ================= input validation ================= */ + // ================= input validation ================= input_validate_input_number($matches[1]); - /* ==================================================== */ + // ==================================================== - $server_list .= '
  • ' . db_fetch_cell_prepared('SELECT name FROM plugin_webseer_servers WHERE id = ?', array($matches[1])) . '
  • '; + $server_list .= '
  • ' . html_escape(db_fetch_cell_prepared('SELECT name FROM plugin_webseer_servers WHERE id = ?', [$matches[1]])) . '
  • '; $server_array[] = $matches[1]; } } @@ -183,7 +182,7 @@ function form_actions() { "; @@ -196,7 +195,8 @@ function form_actions() { } function do_webseer() { - $hosts = array(); + $hosts = []; + foreach ($_REQUEST as $var => $val) { if (preg_match('/^chk_(.*)$/', $var, $matches)) { $host = $matches[1]; @@ -208,22 +208,22 @@ function do_webseer() { switch (get_nfilter_request_var('drp_action')) { case WEBSEER_ACTION_SERVER_DELETE: // Delete foreach ($hosts as $host) { - db_execute_prepared('DELETE FROM plugin_webseer_servers WHERE id = ?', array($host)); - db_execute_prepared('DELETE FROM plugin_webseer_servers_log WHERE server= ?', array($host)); + db_execute_prepared('DELETE FROM plugin_webseer_servers WHERE id = ?', [$host]); + db_execute_prepared('DELETE FROM plugin_webseer_servers_log WHERE server= ?', [$host]); plugin_webseer_delete_remote_server($host); } break; case WEBSEER_ACTION_SERVER_DISABLE: // Disabled foreach ($hosts as $host) { - db_execute_prepared("UPDATE plugin_webseer_servers SET enabled = '' WHERE id = ?", array($host)); + db_execute_prepared("UPDATE plugin_webseer_servers SET enabled = '' WHERE id = ?", [$host]); plugin_webseer_enable_remote_server($host, false); } break; case WEBSEER_ACTION_SERVER_ENABLE: // Enabled foreach ($hosts as $host) { - db_execute_prepared("UPDATE plugin_webseer_servers SET enabled = 'on' WHERE id = ?", array($host)); + db_execute_prepared("UPDATE plugin_webseer_servers SET enabled = 'on' WHERE id = ?", [$host]); plugin_webseer_enable_remote_server($host, true); } @@ -238,84 +238,84 @@ function do_webseer() { * This is a generic function for this page that makes sure that * we have a good request. We want to protect against people who * like to create issues with Cacti. -*/ + */ function webseer_request_validation() { global $title, $rows_selector, $config, $reset_multi; - /* ================= input validation and session storage ================= */ - $filters = array( - 'rows' => array( - 'filter' => FILTER_VALIDATE_INT, + // ================= input validation and session storage ================= + $filters = [ + 'rows' => [ + 'filter' => FILTER_VALIDATE_INT, 'pageset' => true, 'default' => '-1' - ), - 'page' => array( - 'filter' => FILTER_VALIDATE_INT, + ], + 'page' => [ + 'filter' => FILTER_VALIDATE_INT, 'default' => '1' - ), - 'refresh' => array( - 'filter' => FILTER_VALIDATE_INT, + ], + 'refresh' => [ + 'filter' => FILTER_VALIDATE_INT, 'pageset' => true, 'default' => '20', - ), - 'sort_column' => array( - 'filter' => FILTER_CALLBACK, + ], + 'sort_column' => [ + 'filter' => FILTER_CALLBACK, 'default' => 'name', - 'options' => array('options' => 'sanitize_search_string') - ), - 'sort_direction' => array( - 'filter' => FILTER_CALLBACK, + 'options' => ['options' => 'sanitize_search_string'] + ], + 'sort_direction' => [ + 'filter' => FILTER_CALLBACK, 'default' => 'ASC', - 'options' => array('options' => 'sanitize_search_string') - ), - 'state' => array( - 'filter' => FILTER_VALIDATE_INT, + 'options' => ['options' => 'sanitize_search_string'] + ], + 'state' => [ + 'filter' => FILTER_VALIDATE_INT, 'pageset' => true, 'default' => '-1' - ) - ); + ] + ]; validate_store_request_vars($filters, 'sess_webseer'); - /* ================= input validation ================= */ + // ================= input validation ================= } function webseer_log_request_validation() { global $title, $rows_selector, $config, $reset_multi; - /* ================= input validation and session storage ================= */ - $filters = array( - 'id' => array( - 'filter' => FILTER_VALIDATE_INT, + // ================= input validation and session storage ================= + $filters = [ + 'id' => [ + 'filter' => FILTER_VALIDATE_INT, 'default' => '-1' - ), - 'rows' => array( - 'filter' => FILTER_VALIDATE_INT, + ], + 'rows' => [ + 'filter' => FILTER_VALIDATE_INT, 'pageset' => true, 'default' => '-1' - ), - 'page' => array( - 'filter' => FILTER_VALIDATE_INT, + ], + 'page' => [ + 'filter' => FILTER_VALIDATE_INT, 'default' => '1' - ), - 'filter' => array( - 'filter' => FILTER_CALLBACK, + ], + 'filter' => [ + 'filter' => FILTER_CALLBACK, 'default' => '', - 'options' => array('options' => 'sanitize_search_string') - ), - 'sort_column' => array( - 'filter' => FILTER_CALLBACK, + 'options' => ['options' => 'sanitize_search_string'] + ], + 'sort_column' => [ + 'filter' => FILTER_CALLBACK, 'default' => 'lastcheck', - 'options' => array('options' => 'sanitize_search_string') - ), - 'sort_direction' => array( - 'filter' => FILTER_CALLBACK, + 'options' => ['options' => 'sanitize_search_string'] + ], + 'sort_direction' => [ + 'filter' => FILTER_CALLBACK, 'default' => 'DESC', - 'options' => array('options' => 'sanitize_search_string') - ), - ); + 'options' => ['options' => 'sanitize_search_string'] + ], + ]; validate_store_request_vars($filters, 'sess_weseer_server_log'); - /* ================= input validation ================= */ + // ================= input validation ================= } function webseer_show_history() { @@ -353,7 +353,7 @@ function webseer_show_history() { } $sql_order = get_order_string(); - $sql_limit = ' LIMIT ' . ($rows*(get_request_var('page')-1)) . ',' . $rows; + $sql_limit = ' LIMIT ' . ($rows * (get_request_var('page') - 1)) . ',' . $rows; $result = db_fetch_assoc_prepared("SELECT wl.*, wu.url FROM plugin_webseer_servers_log AS wl @@ -381,63 +381,63 @@ function webseer_show_history() { html_start_box('', '100%', '', '4', 'center', ''); - $display_text = array( - 'lastcheck' => array( + $display_text = [ + 'lastcheck' => [ 'display' => __('Date', 'webseer') - ), - 'url' => array( + ], + 'url' => [ 'display' => __('URL', 'webseer'), - ), - 'result' => array( + ], + 'result' => [ 'display' => __('Error', 'webseer'), - ), - 'http_code' => array( + ], + 'http_code' => [ 'display' => __('HTTP Code', 'webseer'), 'align' => 'right', 'sort' => 'DESC' - ), - 'namelookup_time' => array( + ], + 'namelookup_time' => [ 'display' => __('DNS', 'webseer'), 'align' => 'right', 'sort' => 'DESC' - ), - 'connect_time' => array( + ], + 'connect_time' => [ 'display' => __('Connect', 'webseer'), 'align' => 'right', 'sort' => 'DESC' - ), - 'redirect_time' => array( + ], + 'redirect_time' => [ 'display' => __('Redirect', 'webseer'), 'align' => 'right', 'sort' => 'DESC' - ), - 'total_time' => array( + ], + 'total_time' => [ 'display' => __('Total', 'webseer'), 'align' => 'right', 'sort' => 'DESC' - ), - ); + ], + ]; html_header_sort($display_text, get_request_var('sort_column'), get_request_var('sort_direction'), 1, 'webseer_servers.php?action=history&id=' . get_request_var('id'), 'main'); if (cacti_count($result)) { foreach ($result as $row) { - if ($row['result'] == 0) { - $style = "color:rgba(10,10,10,0.8);background-color:rgba(242, 25, 36, 0.6);"; - } else { - $style = "color:rgba(10,10,10,0.8);background-color:rgba(204, 255, 204, 0.6)"; - } + if ($row['result'] == 0) { + $style = 'color:rgba(10,10,10,0.8);background-color:rgba(242, 25, 36, 0.6);'; + } else { + $style = 'color:rgba(10,10,10,0.8);background-color:rgba(204, 255, 204, 0.6)'; + } - print ""; + print ""; form_selectable_cell($row['lastcheck'], $row['id']); form_selectable_cell("" . $row['url'] . '', $row['id']); form_selectable_cell(($row['result'] == 1 ? __('Up', 'webseer') : __('Down', 'webseer')), $row['id']); form_selectable_cell($httperrors[$row['http_code']], $row['id'], '', 'right'); - form_selectable_cell(round($row['namelookup_time'], 4), $row['id'], '', ($row['namelookup_time'] > 4 ? 'background-color: red;text-align:right;' : ($row['namelookup_time'] > 1 ? 'background-color: yellow;text-align:right;':'text-align:right'))); - form_selectable_cell(round($row['connect_time'], 4), $row['id'], '', ($row['connect_time'] > 4 ? 'background-color: red;text-align:right;' : ($row['connect_time'] > 1 ? 'background-color: yellow;text-align:right;':'text-align:right'))); - form_selectable_cell(round($row['redirect_time'], 4), $row['id'], '', ($row['redirect_time'] > 4 ? 'background-color: red;text-align:right;' : ($row['redirect_time'] > 1 ? 'background-color: yellow;text-align:right;':'text-align:right'))); - form_selectable_cell(round($row['total_time'], 4), $row['id'], '', ($row['total_time'] > 4 ? 'background-color: red;text-align:right' : ($row['total_time'] > 1 ? 'background-color: yellow;text-align:right;':'text-align:right'))); + form_selectable_cell(round($row['namelookup_time'], 4), $row['id'], '', ($row['namelookup_time'] > 4 ? 'background-color: red;text-align:right;' : ($row['namelookup_time'] > 1 ? 'background-color: yellow;text-align:right;' : 'text-align:right'))); + form_selectable_cell(round($row['connect_time'], 4), $row['id'], '', ($row['connect_time'] > 4 ? 'background-color: red;text-align:right;' : ($row['connect_time'] > 1 ? 'background-color: yellow;text-align:right;' : 'text-align:right'))); + form_selectable_cell(round($row['redirect_time'], 4), $row['id'], '', ($row['redirect_time'] > 4 ? 'background-color: red;text-align:right;' : ($row['redirect_time'] > 1 ? 'background-color: yellow;text-align:right;' : 'text-align:right'))); + form_selectable_cell(round($row['total_time'], 4), $row['id'], '', ($row['total_time'] > 4 ? 'background-color: red;text-align:right' : ($row['total_time'] > 1 ? 'background-color: yellow;text-align:right;' : 'text-align:right'))); form_end_row(); } } else { @@ -457,14 +457,23 @@ function list_servers() { webseer_request_validation(); - $statefilter=''; + $statefilter = ''; + if (isset_request_var('state')) { if (get_request_var('state') == '-1') { $statefilter = ''; } else { - if (get_request_var('state') == '2') { $statefilter = '(enabled="" OR enabled="0")'; } - if (get_request_var('state') == '1') { $statefilter = '(enabled="on" OR enabled="1")'; } - if (get_request_var('state') == '3') { $statefilter = 'result!=1'; } + if (get_request_var('state') == '2') { + $statefilter = '(enabled="" OR enabled="0")'; + } + + if (get_request_var('state') == '1') { + $statefilter = '(enabled="on" OR enabled="1")'; + } + + if (get_request_var('state') == '3') { + $statefilter = 'result!=1'; + } } } @@ -493,7 +502,7 @@ function list_servers() { } $sql_order = get_order_string(); - $sql_limit = ' LIMIT ' . ($rows*(get_request_var('page')-1)) . ',' . $rows; + $sql_limit = ' LIMIT ' . ($rows * (get_request_var('page') - 1)) . ',' . $rows; $result = db_fetch_assoc("SELECT * FROM plugin_webseer_servers @@ -511,30 +520,30 @@ function list_servers() { html_start_box('', '100%', '', '4', 'center', ''); - $display_text = array( - 'nosort' => array(__('Actions', 'webseer'), 'ASC'), - 'name' => array(__('Name', 'webseer'), 'ASC'), - 'ip' => array(__('IP Address', 'webseer'), 'ASC'), - 'enabled' => array(__('Enabled', 'webseer'), 'ASC'), - 'location' => array(__('Location', 'webseer'), 'ASC'), - 'lastcheck' => array(__('Last Check', 'webseer'), 'ASC'), - 'master' => array(__('Master', 'webseer'), 'ASC'), - 'isme' => array(__('This Host', 'webseer'), 'ASC') - ); + $display_text = [ + 'nosort' => [__('Actions', 'webseer'), 'ASC'], + 'name' => [__('Name', 'webseer'), 'ASC'], + 'ip' => [__('IP Address', 'webseer'), 'ASC'], + 'enabled' => [__('Enabled', 'webseer'), 'ASC'], + 'location' => [__('Location', 'webseer'), 'ASC'], + 'lastcheck' => [__('Last Check', 'webseer'), 'ASC'], + 'master' => [__('Master', 'webseer'), 'ASC'], + 'isme' => [__('This Host', 'webseer'), 'ASC'] + ]; html_header_sort_checkbox($display_text, get_request_var('sort_column'), get_request_var('sort_direction'), false); if (cacti_sizeof($result)) { foreach ($result as $row) { if ($row['enabled'] == '') { - $style = "color:rgba(10,10,10,0.8);background-color:rgba(205, 207, 196, 0.6)"; - } elseif ($row['isme'] == 0 && $row['lastcheck'] < time() - 10) { - $style = "color:rgba(10,10,10,0.8);background-color:rgba(242, 25, 36, 0.6);"; - } else { - $style = "color:rgba(10,10,10,0.8);background-color:rgba(204, 255, 204, 0.6)"; - } + $style = 'color:rgba(10,10,10,0.8);background-color:rgba(205, 207, 196, 0.6)'; + } elseif ($row['isme'] == 0 && $row['lastcheck'] < time() - 10) { + $style = 'color:rgba(10,10,10,0.8);background-color:rgba(242, 25, 36, 0.6);'; + } else { + $style = 'color:rgba(10,10,10,0.8);background-color:rgba(204, 255, 204, 0.6)'; + } - print ""; + print ""; print "
    - + - '> + '> - + - '> - '> + '> + '>
    - + $save_html
    @@ -558,11 +567,11 @@ function list_servers() { form_selectable_cell($row['name'], $row['id'], '', '', html_escape($row['url'])); form_selectable_cell($row['ip'], $row['id']); - form_selectable_cell($row['enabled'] == '' || $row['enabled'] == '0' ? __('No', 'webseer'): __('Yes', 'webseer'), $row['id']); + form_selectable_cell($row['enabled'] == '' || $row['enabled'] == '0' ? __('No', 'webseer') : __('Yes', 'webseer'), $row['id']); form_selectable_cell($row['location'], $row['id']); form_selectable_cell($row['lastcheck'], $row['id']); - form_selectable_cell($row['master'] == 1 ? __('Yes', 'webseer'):__('No', 'webseer'), $row['id']); - form_selectable_cell($row['isme'] == 1 ? __('Yes', 'webseer'):__('No', 'webseer'), $row['id']); + form_selectable_cell($row['master'] == 1 ? __('Yes', 'webseer') : __('No', 'webseer'), $row['id']); + form_selectable_cell($row['isme'] == 1 ? __('Yes', 'webseer') : __('No', 'webseer'), $row['id']); form_checkbox_cell($row['name'], $row['id']); form_end_row(); } @@ -602,9 +611,9 @@ function list_servers() { } function form_save() { - /* ================= input validation ================= */ + // ================= input validation ================= get_filter_request_var('id'); - /* ==================================================== */ + // ==================================================== if (isset_request_var('id')) { $save['id'] = get_request_var('id'); @@ -661,18 +670,19 @@ function form_save() { function webseer_edit_server() { global $webseer_server_fields; - /* ================= input validation ================= */ + // ================= input validation ================= get_filter_request_var('id'); - /* ==================================================== */ + // ==================================================== + + $server = []; - $server = array(); if (!isempty_request_var('id')) { - $server = db_fetch_row_prepared('SELECT * FROM plugin_webseer_servers WHERE id = ?', array(get_request_var('id')), false); + $server = db_fetch_row_prepared('SELECT * FROM plugin_webseer_servers WHERE id = ?', [get_request_var('id')], false); $header_label = __('Query [edit: %s]', $server['ip'], 'webseer'); } else { - $header_label = __('Query [new]', 'webseer'); - $server['isme'] = ''; - $server['master'] = ''; + $header_label = __('Query [new]', 'webseer'); + $server['isme'] = ''; + $server['master'] = ''; } $server['isme'] = $server['isme'] ? 'on' : ''; @@ -680,10 +690,10 @@ function webseer_edit_server() { form_start('webseer_servers.php'); html_start_box($header_label, '100%', '', '3', 'center', ''); - draw_edit_form(array( - 'config' => array('form_name' => 'chk'), + draw_edit_form([ + 'config' => ['form_name' => 'chk'], 'fields' => inject_form_variables($webseer_server_fields, $server) - ) + ] ); html_end_box(); @@ -735,48 +745,53 @@ function clearFilter() { @@ -798,7 +813,7 @@ function webseer_log_filter() { refreshMSeconds=99999999; function applyFilter() { - strURL = 'webseer_servers.php?action=history&header=false&id='; + strURL = 'webseer_servers.php?action=history&header=false&id='; strURL += '&filter=' + $('#filter').val(); strURL += '&rows=' + $('#rows').val(); refreshMSeconds=99999999; @@ -836,30 +851,35 @@ function clearFilter() {
    - + - + - + - '> + '>
    @@ -870,4 +890,3 @@ function clearFilter() {
    - + - '> + '> - + - '> - '> + '> + '>