Project

General

Profile

« Previous | Next » 

Revision cabbaf7a

Added by Steve Beaver almost 8 years ago

ipsec widget converted to JSON formatted refresh

View differences:

src/usr/local/www/widgets/widgets/ipsec.widget.php
121 121
		unset($ikenum);
122 122
	}
123 123

  
124
	// Only generate the data for the tab that is currently being viewed
125
	switch ($_REQUEST['tab']) {
126
		case "Overview" :
127
			print("	<tr>\n");
128
			print(		"<td>" . $activecounter . "</td>\n");
129
			print(		"<td>" . $inactivecounter . "</td>\n");
130
			print(		"<td>" . (is_array($mobile['pool']) ? htmlspecialchars($mobile['pool'][0]['usage']) : '0') . "</td>\n");
131
			print(	"</tr>\n");
132
		break;
133

  
134
		case "tunnel" :
135
			foreach ($ipsec_detail_array as $ipsec) {
136
				print("	<tr>\n");
137
				print(		"<td>" . htmlspecialchars($ipsec['src']) . "</td>\n");
138
				print(		"<td>" . $ipsec['remote-subnet'] . "<br />(" . htmlspecialchars($ipsec['dest']) . ")</td>\n");
139
				print(		"<td>" . htmlspecialchars($ipsec['descr']) . "</td>\n");
140

  
141
				if ($ipsec['status'] == "true") {
142
					print('<td><i class="fa fa-arrow-up text-success"></i></td>' . "\n");
143
				} else {
144
					print('<td><i class="fa fa-arrow-down text-danger"></i></td>' . "\n");
145
				}
124
	// Generate JSON formatted data for the widget to update from
125
	$jsondata = "{";
126

  
127
	$jsondata .= "\"overview\":\"";
128
	$jsondata .= "<tr>";
129
	$jsondata .= "<td>" . $activecounter . "</td>";
130
	$jsondata .= "<td>" . $inactivecounter . "</td>";
131
	$jsondata .= "<td>" . (is_array($mobile['pool']) ? htmlspecialchars($mobile['pool'][0]['usage']) : '0') . "</td>";
132
	$jsondata .= "</tr>";
133
	$jsondata .= "\",\n";
134

  
135
	$jsondata .= "\"tunnel\":\"";
136
	foreach ($ipsec_detail_array as $ipsec) {
137
		$jsondata .= "<tr>";
138
		$jsondata .= "<td>" . htmlspecialchars($ipsec['src']) . "</td>";
139
		$jsondata .= "<td>" . $ipsec['remote-subnet'] . "<br />(" . htmlspecialchars($ipsec['dest']) . ")</td>";
140
		$jsondata .= "<td>" . htmlspecialchars($ipsec['descr']) . "</td>";
141

  
142
		if ($ipsec['status'] == "true") {
143
			$jsondata .= '<td><i class=\"fa fa-arrow-up text-success\"></i></td>';
144
		} else {
145
			$jsondata .= '<td><i class=\"fa fa-arrow-down text-danger\"></i></td>';
146
		}
146 147

  
147
				print(	"</tr>\n");
148
			}
149
		break;
148
		$jsondata .= "</tr>";
149
	}
150

  
151
	$jsondata .= "\",\n";
150 152

  
151
		case "mobile" :
152
			if (!is_array($mobile['pool'])) {
153
				break;
153

  
154
	$jsondata .= "\"mobile\":\"";
155

  
156
	if (is_array($mobile['pool'])) {
157
		foreach ($mobile['pool'] as $pool) {
158
			if (!is_array($pool['lease'])) {
159
				continue;
154 160
			}
155
			foreach ($mobile['pool'] as $pool) {
156
				if (!is_array($pool['lease'])) {
157
					continue;
158
				}
159 161

  
160
				foreach ($pool['lease'] as $muser) {
161
					print("	<tr>\n");
162
					print(		"<td>" . htmlspecialchars($muser['id']) . "</td>\n");
163
					print(		"<td>" . htmlspecialchars($muser['host']) . "</td>\n");
164
					print(		"<td>" . htmlspecialchars($muser['status']) . "</td>\n");
165
					print("	</tr>\n");
166
				}
162
			foreach ($pool['lease'] as $muser) {
163
				$jsondata .= "<tr>";
164
				$jsondata .= "<td>" . htmlspecialchars($muser['id']) . "</td>";
165
				$jsondata .= "<td>" . htmlspecialchars($muser['host']) . "</td>";
166
				$jsondata .= "<td>" . htmlspecialchars($muser['status']) . "</td>";
167
				$jsondata .= "</tr>";
167 168
			}
168
		break;
169
		}
170
	} else {
171
		$jsondata .= "\"}";
169 172
	}
170 173

  
174
	print($jsondata);
171 175
	exit;
172 176
}
173 177

  
......
296 300

  
297 301
	// Callback function called by refresh system when data is retrieved
298 302
	function ipsec_callback(s) {
299
		$('tbody', '#<?=$widgetkey_nodash?>-' + curtab).html(s);
303
		var obj = JSON.parse(s);
304

  
305
		$('tbody', '#<?=$widgetkey_nodash?>-Overview').html(obj.overview);
306
		$('tbody', '#<?=$widgetkey_nodash?>-tunnel').html(obj.tunnel);
307
		$('tbody', '#<?=$widgetkey_nodash?>-mobile').html(obj.mobile);
300 308
	}
301 309

  
302 310
	// POST data to send via AJAX
303 311
	var postdata = {
304
		ajax: "ajax",
305
	 	tab : curtab
312
		ajax: "ajax"
306 313
	 };
307 314

  
308 315
	// Create an object defining the widget refresh AJAX call

Also available in: Unified diff