Projet

Général

Profil

Télécharger (5,16 ko) Statistiques
| Branche: | Tag: | Révision:

univnautes / usr / local / www / widgets / widgets / dyn_dns_status.widget.php @ 56898132

1
<?php
2
/*
3
    Original status page code from: services_dyndns.php
4
    Copyright (C) 2008 Ermal Luci
5
    Edits to convert it to a widget: dyn_dns_status.widget.php
6
    Copyright (C) 2013 Stanley P. Miller \ stan-qaz
7
    All rights reserved.
8

    
9
    Redistribution and use in source and binary forms, with or without
10
    modification, are permitted provided that the following conditions are met:
11

    
12
    1. Redistributions of source code must retain the above copyright notice,
13
       this list of conditions and the following disclaimer.
14

    
15
    2. Redistributions in binary form must reproduce the above copyright
16
       notice, this list of conditions and the following disclaimer in the
17
       documentation and/or other materials provided with the distribution.
18

    
19
    THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
20
    INClUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
21
    AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
22
    AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
23
    OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24
    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25
    INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26
    CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27
    ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28
    POSSIBILITY OF SUCH DAMAGE.
29
*/
30
/*
31
	pfSense_BUILDER_BINARIES:	/usr/bin/host
32
	pfSense_MODULE:	dyndns
33
*/
34

    
35
$nocsrf = true;
36

    
37
require_once("guiconfig.inc");
38
require_once("pfsense-utils.inc");
39
require_once("functions.inc");
40
require_once("/usr/local/www/widgets/include/dyn_dns_status.inc");
41

    
42
if (!is_array($config['dyndnses']['dyndns']))
43
	$config['dyndnses']['dyndns'] = array();
44

    
45
$a_dyndns = &$config['dyndnses']['dyndns'];
46

    
47
if($_REQUEST['getdyndnsstatus']) {
48
	$first_entry = true;
49
	foreach ($a_dyndns as $dyndns) {
50
		if ($first_entry)
51
			$first_entry = false;
52
		else
53
			// Put a vertical bar delimiter between the echoed HTML for each entry processed.
54
			echo "|";
55

    
56
		$filename = "{$g['conf_path']}/dyndns_{$dyndns['interface']}{$dyndns['type']}" . escapeshellarg($dyndns['host']) . "{$dyndns['id']}.cache";
57
		if (file_exists($filename)) {
58
			$ipaddr = dyndnsCheckIP($dyndns['interface']);
59
			$cached_ip_s = split(":", file_get_contents($filename));
60
			$cached_ip = $cached_ip_s[0];
61
			if ($ipaddr <> $cached_ip)
62
				echo "<font color='red'>";
63
			else
64
				echo "<font color='green'>";
65
			echo htmlspecialchars($cached_ip);
66
			echo "</font>";
67
		} else {
68
			echo "N/A " . date("H:i:s");
69
		}
70
	}
71
	exit;
72
}
73

    
74
?>
75

    
76
<table width="100%" border="0" cellpadding="0" cellspacing="0">
77
	<tr>
78
		<td width="5%"  class="listhdrr"><?=gettext("Int.");?></td>
79
		<td width="15%" class="listhdrr"><?=gettext("Service");?></td>
80
		<td width="20%" class="listhdrr"><?=gettext("Hostname");?></td>
81
		<td width="20%" class="listhdrr"><?=gettext("Cached IP");?></td>
82
	</tr>
83
	<?php $i = 0; foreach ($a_dyndns as $dyndns): ?>
84
	<tr ondblclick="document.location='services_dyndns_edit.php?id=<?=$i;?>'">
85
		<td class="listlr">
86
		<?php $iflist = get_configured_interface_with_descr();
87
		foreach ($iflist as $if => $ifdesc) {
88
			if ($dyndns['interface'] == $if) {
89
				if (!isset($dyndns['enable']))
90
					echo "<span class=\"gray\">{$ifdesc}</span>";
91
				else
92
					echo "{$ifdesc}";
93
				break;
94
			}
95
		}
96
		$groupslist = return_gateway_groups_array();
97
		foreach ($groupslist as $if => $group) {
98
			if ($dyndns['interface'] == $if) {
99
				if (!isset($dyndns['enable']))
100
					echo "<span class=\"gray\">{$if}</span>";
101
				else
102
					echo "{$if}";
103
				break;
104
			}
105
		}
106
		?>
107
		</td>
108
		<td class="listr">
109
		<?php
110
		$types = explode(",", DYNDNS_PROVIDER_DESCRIPTIONS);
111
		$vals = explode(" ", DYNDNS_PROVIDER_VALUES);
112
		for ($j = 0; $j < count($vals); $j++)
113
			if ($vals[$j] == $dyndns['type']) {
114
				if (!isset($dyndns['enable']))
115
					echo "<span class=\"gray\">".htmlspecialchars($types[$j])."</span>";
116
				else
117
					echo htmlspecialchars($types[$j]);
118
				break;
119
			}
120
		?>
121
		</td>
122
		<td class="listr">
123
		<?php
124
		if (!isset($dyndns['enable']))
125
			echo "<span class=\"gray\">".htmlspecialchars($dyndns['host'])."</span>";
126
		else
127
			echo htmlspecialchars($dyndns['host']);
128
		?>
129
		</td>
130
		<td class="listr">
131
		<div id='dyndnsstatus<?php echo $i; ?>'><?php echo gettext("Checking ..."); ?></div>
132
		</td>
133
	</tr>
134
	<?php $i++; endforeach; ?>
135
</table>
136
<script type="text/javascript">
137
//<![CDATA[
138
	function dyndns_getstatus() {
139
		scroll(0,0);
140
		var url = "/widgets/widgets/dyn_dns_status.widget.php";
141
		var pars = 'getdyndnsstatus=yes';
142
		jQuery.ajax(
143
			url,
144
			{
145
				type: 'get',
146
				data: pars,
147
				complete: dyndnscallback
148
			});
149
		// Refresh the status every 5 minutes
150
		setTimeout('dyndns_getstatus()', 5*60*1000);
151
	}
152
	function dyndnscallback(transport) {
153
		// The server returns a string of statuses separated by vertical bars
154
		var responseStrings = transport.responseText.split("|");
155
		for (var count=0; count<responseStrings.length; count++)
156
		{
157
			var divlabel = '#dyndnsstatus' + count;
158
			jQuery(divlabel).prop('innerHTML',responseStrings[count]);
159
		}
160
	}
161
	// Do the first status check 2 seconds after the dashboard opens
162
	setTimeout('dyndns_getstatus()', 2000);
163
//]]>
164
</script>
(3-3/21)