Project

General

Profile

Feature #1258 » services_dyndns.php.txt

Chris Goundry, 02/06/2011 02:23 PM

 
1
<?php
2
/* $Id$ */
3
/*
4
	Copyright (C) 2008 Ermal Lu�i
5
	All rights reserved.
6

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

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

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

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

    
33
##|+PRIV
34
##|*IDENT=page-services-dynamicdnsclients
35
##|*NAME=Services: Dynamic DNS clients page
36
##|*DESCR=Allow access to the 'Services: Dynamic DNS clients' page.
37
##|*MATCH=services_dyndns.php*
38
##|-PRIV
39

    
40
require("guiconfig.inc");
41

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

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

    
47
if ($_GET['act'] == "del") {
48
		unset($a_dyndns[$_GET['id']]);
49

    
50
		write_config();
51

    
52
		header("Location: services_dyndns.php");
53
		exit;
54
}
55

    
56
function dyndnsCheckIP($int) {
57

    
58
	$ip_address = get_interface_ip($int);
59
	if (is_private_ip($ip_address)) {
60
		$hosttocheck = "checkip.dyndns.org";
61
		$checkip = gethostbyname($hosttocheck);
62
		$ip_ch = curl_init("http://{$checkip}");
63
		curl_setopt($ip_ch, CURLOPT_RETURNTRANSFER, 1);
64
		curl_setopt($ip_ch, CURLOPT_SSL_VERIFYPEER, FALSE);
65
		curl_setopt($ip_ch, CURLOPT_INTERFACE, $ip_address);
66
		$ip_result_page = curl_exec($ip_ch);
67
		curl_close($ip_ch);
68
		$ip_result_decoded = urldecode($ip_result_page);
69
		preg_match('=Current IP Address: (.*)</body>=siU', $ip_result_decoded, $matches);
70
		$ip_address = trim($matches[1]);
71
	}
72

    
73
	return $ip_address;
74
}
75

    
76
$pgtitle = array(gettext("Services"), gettext("Dynamic DNS clients"));
77
include("head.inc");
78

    
79
?>
80

    
81
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
82
<?php include("fbegin.inc"); ?>
83
<form action="services_dyndns.php" method="post" name="iform" id="iform">
84
<?php if ($input_errors) print_input_errors($input_errors); ?>
85
<table width="100%" border="0" cellpadding="0" cellspacing="0">
86
  <tr><td>
87
<?php
88
	$tab_array = array();
89
	$tab_array[] = array(gettext("DynDns"), true, "services_dyndns.php");
90
	$tab_array[] = array(gettext("RFC 2136"), false, "services_rfc2136.php");
91
	display_top_tabs($tab_array);
92
?>
93
  </td></tr>
94
  <tr>
95
    <td>
96
	<div id="mainarea">
97
	<table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0">
98
                <tr>
99
		  <td width="5%"  class="listhdrr"></td>
100
		  <td width="15%" class="listhdrr"><?=gettext("Service");?></td>
101
                  <td width="20%" class="listhdrr"><?=gettext("Hostname");?></td>
102
                  <td width="20%" class="listhdrr"><?=gettext("Cached IP");?></td>
103
                  <td width="50%" class="listhdr"><?=gettext("Description");?></td>
104
                  <td width="10%" class="list"></td>
105
		</tr>
106
		  <?php $i = 0; foreach ($a_dyndns as $dyndns): ?>
107
                <tr  ondblclick="document.location='services_dyndns_edit.php?id=<?=$i;?>'">
108
		  <td class="listlr">
109
		  <?php $iflist = get_configured_interface_with_descr();
110
	  		foreach ($iflist as $if => $ifdesc):
111
				if ($dyndns['interface'] == $if): ?>
112
					<?=$ifdesc; break;?>
113
		  <?php endif; endforeach; ?>
114
		  </td>
115
                  <td class="listlr">
116
				  <?php
117
					$types = explode(",", "DNS-O-Matic, DynDNS (dynamic),DynDNS (static),DynDNS (custom),DHS,DyNS,easyDNS,No-IP,ODS.org,ZoneEdit,Loopia,DNSMadeEasy,freeDNS, DNSexit, OpenDNS, Namecheap");
118
					$vals = explode(" ", "dnsomatic dyndns dyndns-static dyndns-custom dhs dyns easydns noip ods zoneedit loopia dnsmadeeasy freedns dnsexit opendns namecheap");
119
					$j = 0; for ($j = 0; $j < count($vals); $j++) 
120
                      			if ($vals[$j] == $dyndns['type']) { 
121
                      				echo htmlspecialchars($types[$j]);
122
							break;
123
					}
124
				?>
125
                  </td>
126
                  <td class="listr">
127
					<?=htmlspecialchars($dyndns['host']);?>
128
                  </td>
129
                  <td class="listlr">
130
			<?php
131
				$filename = "{$g['conf_path']}/dyndns_{$if}{$dyndns['type']}" . escapeshellarg($dyndns['host']) . ".cache";
132
				$ipaddr = dyndnsCheckIP($if);
133
				if(file_exists($filename)) {
134
					$cached_ip_s = split(":", file_get_contents($filename));
135
					$cached_ip = $cached_ip_s[0];
136
					if($ipaddr <> $cached_ip) 
137
						echo "<font color='red'>";
138
					else 
139
						echo "<font color='green'>";
140
						echo htmlspecialchars($cached_ip);
141
						echo "</font>";
142
				} else {
143
					echo "N/A";
144
				}
145
			?>
146
		  </td>
147
                  <td class="listbg">
148
                    <?=htmlspecialchars($dyndns['descr']);?>&nbsp;
149
                  </td>
150
                  <td valign="middle" nowrap class="list"> <a href="services_dyndns_edit.php?id=<?=$i;?>"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_e.gif" width="17" height="17" border="0"></a>
151
                     &nbsp;<a href="services_dyndns.php?act=del&id=<?=$i;?>" onclick="return confirm('<?=gettext("Do you really want to delete this entry?");?>')"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_x.gif" width="17" height="17" border="0"></a></td>
152
				</tr>
153
			  <?php $i++; endforeach; ?>
154
                <tr>
155
                  <td class="list" colspan="5"></td>
156
                  <td class="list"> <a href="services_dyndns_edit.php"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" width="17" height="17" border="0"></a></td>
157
				</tr>
158
				<tr>
159
				<td colspan="3" class="list"><p class="vexpl"><span class="red"><strong>
160
				  <?=gettext("Note:");?><br>
161
				  </strong></span>
162
				  <?=gettext("IP addresses appearing in green are up to date with Dynamic DNS provider.");?>
163
				  </td>
164
				<td class="list">&nbsp;</td>
165
				</tr>
166
              </table>
167
	      </div>
168
	</td>
169
	</tr>
170
</table>
171
</form>
172
<?php include("fend.inc"); ?>
173
</body>
174
</html>
(2-2/3)