Project

General

Profile

« Previous | Next » 

Revision 3dfa6a52

Added by Scott Ullrich over 16 years ago

Add ajax mojo to gateway status widget

View differences:

usr/local/www/includes/functions.inc.php
6 6

  
7 7
require_once("config.inc");
8 8

  
9

  
10 9
function get_stats() {
11 10
	$stats['cpu'] = cpu_usage();
12 11
	$stats['mem'] = mem_usage();
......
16 15
	$stats['datetime'] = update_date_time();
17 16
	$stats['interfacestatistics'] = get_interfacestats();
18 17
	$stats['interfacestatus'] = get_interfacestatus();
19

  
18
	$stats['gateways'] = get_gatewaystats();
20 19
	$stats = join("|", $stats);
21

  
22 20
	return $stats;
23 21
}
24 22

  
23
function get_gatewaystats() {
24
	$gateways_status = array();
25
	$gateways_status = return_gateways_status();
26
	$data = "";
27
	$isfirst = true;
28
	foreach($gateways_status as $gw) {
29
		if(!$isfirst) 
30
			$data .= ",";
31
		$isfirst = false;
32
		$data .= $gw['name'] . ",";
33
		$data .= $gw['gateway'] . ",";
34
		$data .= $gw['delay'] . ",";
35
		$data .= $gw['loss'] . ",";
36
        switch($gw['status']) {
37
			case "None":
38
				$online = "Online";
39
				$bgcolor = "lightgreen";
40
				break;
41
			case "\"down\"":
42
				$online = "Offline";
43
				$bgcolor = "lightcoral";
44
				break;
45
			case "\"delay\"":
46
				$online = "Warning, Latency";
47
				$bgcolor = "khaki";
48
				break;
49
			case "\"loss\"":
50
				$online = "Warning, Packetloss";
51
				$bgcolor = "khaki";
52
				break;
53
			default:
54
				$online = "No data";
55
		}
56
		$data .= "<tr><td id=\"gateway{$counter}\" bgcolor=\"$bgcolor\" > $online </td>";
57
	}
58
	return $data;
59
}
25 60

  
26 61
function get_uptime() {
27 62
	$boottime = "";
usr/local/www/includes/javascript.inc.php
10 10
	$top_javascript_files = array();
11 11
	$bottom_javascript_files = array();
12 12

  
13

  
14 13
	$top_javascript_files['firewall_rules_edit.php'][] = 'autosuggest.js';
15 14
	$top_javascript_files['firewall_rules_edit.php'][] = 'suggestions.js';
16 15
	$top_javascript_files['firewall_rules_edit.php'][] = 'firewall_rules_edit.js';
usr/local/www/includes/sajax.class.php
261 261
} // End sajax class
262 262

  
263 263

  
264
?>
264
?>
usr/local/www/javascript/index/sajax.js
27 27
	updateDateTime(values[5]);
28 28
	updateInterfaceStats(values[6]);
29 29
	updateInterfaces(values[7]);
30
	
30
	updateGatewayStats(values[8]);
31

  
31 32
}
32 33

  
33 34
function updateMemory(x)
......
81 82
		document.getElementById("pfstate").value = x;
82 83
}
83 84

  
85
function updateGatewayStats(x){
86
	if (widgetActive("gateways")){
87
		gateways_split = x.split(",");
88
		var counter = 1;
89
		for (var y=0; y<gateways_split.length-1; y++){
90
			document.getElementById('gateway' + counter).innerHTML = gateways_split[y];
91
			counter++;	
92
		}
93
	}
94
}
95

  
84 96
function updateInterfaceStats(x){
85 97
	if (widgetActive("interface_statistics")){
86 98
		statistics_split = x.split(",");
usr/local/www/sajax/index.sajax.php
11 11
	$oSajax = new sajax();
12 12
	$oSajax->sajax_export("get_stats");
13 13
	$oSajax->sajax_handle_client_request();
14
?>
14
?>
usr/local/www/widgets/include/interface_statistics.inc
2 2
//set variable for custom title
3 3
$interface_statistics_title = "Interface Statistics";
4 4
$interface_statistics_title_link = "status_interfaces.php";
5

  
6

  
7 5
?>
usr/local/www/widgets/widgets/gateways.widget.php
35 35
$gateways_status = array();
36 36
$gateways_status = return_gateways_status();
37 37

  
38
$counter = 1;
39

  
38 40
?>
39 41
         <table bgcolor="#990000" width="100%" border="0" cellspacing="0" cellpadding="0">
40 42
                <tr>
......
52 54
						}
53 55
			 ?>
54 56
                <tr>
55
                  <td class="listlr">
57
                  <td class="listlr" id="gateway<?= $counter; ?>">
56 58
                                <?=$gateway['name'];?>
59
								<?php $counter++; ?>
57 60
                  </td>
58
                  <td class="listr" align="center" >
61
                  <td class="listr" align="center" id="gateway<?= $counter; ?>">
59 62
                                <?=$gateway['gateway'];?>
63
								<?php $counter++; ?>
60 64
                  </td>
61
                  <td class="listr" align="center" >
65
                  <td class="listr" align="center" id="gateway<?= $counter; ?>">
62 66
								<?=$gateways_status[$monitor]['delay'];?>
67
								<?php $counter++; ?>
63 68
				  </td>
64
                  <td class="listr" align="center" >
69
                  <td class="listr" align="center" id="gateway<?= $counter; ?>">
65 70
								<?=$gateways_status[$monitor]['loss'];?>
71
								<?php $counter++; ?>
66 72
				  </td>
67 73
                  <td class="listr" >
68 74
                        <table border="0" cellpadding="0" cellspacing="2">
......
91 97
										default:
92 98
											$online = "No data";
93 99
								}
94
								echo "<tr><td bgcolor=\"$bgcolor\" > $online </td>";
100
								echo "<tr><td id=\"gateway{$counter}\" bgcolor=\"$bgcolor\" > $online </td>";
101
								$counter++;
95 102
                        ?>
96 103
                        </table>
97 104
                  </td>

Also available in: Unified diff