1#!/usr/bin/env php
2<?php
3/*
4 +-------------------------------------------------------------------------+
5 | Copyright (C) 2004-2021 The Cacti Group                                 |
6 |                                                                         |
7 | This program is free software; you can redistribute it and/or           |
8 | modify it under the terms of the GNU General Public License             |
9 | as published by the Free Software Foundation; either version 2          |
10 | of the License, or (at your option) any later version.                  |
11 |                                                                         |
12 | This program is distributed in the hope that it will be useful,         |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of          |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           |
15 | GNU General Public License for more details.                            |
16 +-------------------------------------------------------------------------+
17 | Cacti: The Complete RRDtool-based Graphing Solution                     |
18 +-------------------------------------------------------------------------+
19 | This code is designed, written, and maintained by the Cacti Group. See  |
20 | about.php and/or the AUTHORS file for specific developer information.   |
21 +-------------------------------------------------------------------------+
22 | http://www.cacti.net/                                                   |
23 +-------------------------------------------------------------------------+
24*/
25
26error_reporting(0);
27
28if (!isset($called_by_script_server)) {
29	include_once(dirname(__FILE__) . '/../include/cli_check.php');
30
31	array_shift($_SERVER['argv']);
32
33	print call_user_func_array('ss_webseer', $_SERVER['argv']);
34}
35
36function ss_webseer($cmd, $arg1 = '', $arg2 = '') {
37	if ($cmd == 'index') {
38		if (db_table_exists('plugin_webseer_urls')) {
39			$exports = db_fetch_assoc('SELECT id FROM plugin_webseer_urls ORDER BY id');
40
41			if (cacti_sizeof($exports)) {
42				foreach ($exports as $export) {
43					print $export['id'] . PHP_EOL;
44				}
45			}
46		}
47	} elseif ($cmd == 'query') {
48		$arg = $arg1;
49
50		if (db_table_exists('plugin_webseer_urls')) {
51			if ($arg == 'webseerId') {
52				$arr = db_fetch_assoc('SELECT id FROM plugin_webseer_urls ORDER BY id');
53
54				if (cacti_sizeof($arr)) {
55					foreach ($arr as $item) {
56						print $item['id'] . '!' . $item['id'] . PHP_EOL;
57					}
58				}
59			} elseif ($arg == 'webseerName') {
60				$arr = db_fetch_assoc('SELECT id, display_name AS name FROM plugin_webseer_urls ORDER BY id');
61
62				if (cacti_sizeof($arr)) {
63					foreach ($arr as $item) {
64						print $item['id'] . '!' . $item['name'] . PHP_EOL;
65					}
66				}
67			}
68		}
69	} elseif ($cmd == 'get') {
70		$arg   = $arg1;
71		$index = $arg2;
72		$value = '0';
73
74		if (db_table_exists('plugin_webseer_urls')) {
75			switch($arg) {
76				case 'lookupTime':
77					$value = db_fetch_cell_prepared('SELECT namelookup_time
78						FROM plugin_webseer_urls
79						WHERE id = ?',
80						array($index));
81
82					break;
83				case 'connectTime':
84					$value = db_fetch_cell_prepared('SELECT connect_time
85						FROM plugin_webseer_urls
86						WHERE id = ?',
87						array($index));
88
89					break;
90				case 'redirectTime':
91					$value = db_fetch_cell_prepared('SELECT redirect_time
92						FROM plugin_webseer_urls
93						WHERE id = ?',
94						array($index));
95
96					break;
97				case 'totalTime':
98					$value = db_fetch_cell_prepared('SELECT total_time
99						FROM plugin_webseer_urls
100						WHERE id = ?',
101						array($index));
102
103					break;
104				case 'downloadSpeed':
105					$value = db_fetch_cell_prepared('SELECT speed_download
106						FROM plugin_webseer_urls
107						WHERE id = ?',
108						array($index));
109
110					break;
111				case 'downloadSize':
112					$value = db_fetch_cell_prepared('SELECT size_download
113						FROM plugin_webseer_urls
114						WHERE id = ?',
115						array($index));
116
117					break;
118				case 'checkStatus':
119					$value = db_fetch_cell_prepared('SELECT result
120						FROM plugin_webseer_urls
121						WHERE id = ?',
122						array($index));
123
124					break;
125			}
126		}
127
128		return (empty($value) ? '0' : $value);
129	}
130}
131
132