Subversion Repositories ALCASAR

Rev

Rev 2558 | Rev 2609 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log

Rev 2558 Rev 2559
Line 1... Line 1...
1
<?php
1
<?php
2
# $Id: network.php 2558 2018-06-05 21:56:34Z rexy $
2
# $Id: network.php 2559 2018-06-10 12:56:39Z rexy $
3
 
3
 
4
// written by steweb57, Rexy & Tom HOUDAYER
4
// written by steweb57, Rexy & Tom HOUDAYER
5
 
5
 
6
/********************
6
/********************
7
*  READ CONF FILES  *
7
*  READ CONF FILES  *
Line 207... Line 207...
207
	case 'del_mac':
207
	case 'del_mac':
208
		foreach ($_POST as $key => $value) {
208
		foreach ($_POST as $key => $value) {
209
			if ($value == 'on') {
209
			if ($value == 'on') {
210
				$ether_file = ETHERS_FILE;
210
				$ether_file = ETHERS_FILE;
211
				$ether_file_info = ETHERS_INFO_FILE;
211
				$ether_file_info = ETHERS_INFO_FILE;
212
				exec("/bin/sed -i ".escapeshellarg("/^$key/d")." $ether_file"); 
212
				exec("/bin/sed -i ".escapeshellarg("/^$key/d")." $ether_file");
213
				exec("/bin/sed -i ".escapeshellarg("/^$key/d")." $ether_file_info"); 
213
				exec("/bin/sed -i ".escapeshellarg("/^$key/d")." $ether_file_info");
214
				exec('sudo /usr/bin/systemctl reload chilli');
214
				exec('sudo /usr/bin/systemctl reload chilli');
215
			}
215
			}
216
		}
216
		}
217
		break;
217
		break;
218
 
218
 
Line 221... Line 221...
221
		$add_ip   = trim($_POST['add_ip']);
221
		$add_ip   = trim($_POST['add_ip']);
222
		if (((!empty($add_host)) && (preg_match($reg_host, $add_host))) && ((!empty($add_ip)) && (preg_match($reg_ip, $add_ip)))) {
222
		if (((!empty($add_host)) && (preg_match($reg_host, $add_host))) && ((!empty($add_ip)) && (preg_match($reg_ip, $add_ip)))) {
223
			$tab = file(DNS_LOCAL_FILE);
223
			$tab = file(DNS_LOCAL_FILE);
224
			if ($tab) { // the file isn't empty
224
			if ($tab) { // the file isn't empty
225
				$insert = true;
225
				$insert = true;
226
				foreach ($tab as $line) { // verify that host or IP address doesn't already exist
226
				foreach ($tab as $line) { // verify that host or IP address doesn't exist
-
 
227
					if (preg_match('/^\d+/', $line)) {
227
					$field = explode('\t', $line);
228
						$field = preg_split("/\s+/",$line);
228
					$host_name = trim($field[1]);
229
						$ip_addr = $field[0];
229
					$ip_addr   = trim($field[2]);
230
						$host_name = trim($field[1]);
230
					if (strcasecmp($add_host, $host_name) === 0) {
231
						if (strcmp($add_ip, $ip_addr) === 0) {
231
						$insert = false;
232
							$insert = false;
232
						break;
233
							break;
233
					}
234
						}
234
					if (strcmp($add_ip, $ip_addr) === 0) {
235
						if (strcasecmp($add_host, $host_name) === 0) {
235
						$insert = false;
236
							$insert = false;
236
						break;
237
							break;
-
 
238
						}
237
					}
239
					}
238
			}
240
				}
239
				if ($insert) {
241
				if ($insert) {
240
					$line1 = $add_ip.'\t'.$add_host."\n";
-
 
241
					$pointeur=fopen(DNS_LOCAL_FILE, 'a');
-
 
242
					fwrite($pointeur, $line1);
-
 
243
					fclose($pointeur);
-
 
244
					exec('sudo /usr/bin/systemctl restart dnsmasq');
-
 
245
					exec('sudo /usr/bin/systemctl restart dnsmasq-blacklist');
-
 
246
					exec('sudo /usr/bin/systemctl restart dnsmasq-whitelist');
242
					exec("sudo /usr/local/bin/alcasar-dns-local.sh -add $add_ip $add_host");
247
				}
243
				}
248
			}
244
			}
249
		}
245
		}
250
		break;
246
		break;
251
	case 'del_host':
247
	case 'del_host':
252
		foreach ($_POST as $key => $value) {
248
		foreach ($_POST as $key => $value) {
253
			if ($value == 'on') {
249
			if ($value == 'on') {
254
				exec('/bin/sed -i '.escapeshellarg("\\@^address=/$key/@d;\\@^ptr-record=.*,$key\$@d").' '.DNS_LOCAL_FILE); 
-
 
255
				exec('sudo /usr/bin/systemctl restart dnsmasq');
250
				$del_host = explode ("|", $key);
256
				exec('sudo /usr/bin/systemctl restart dnsmasq-blacklist');
251
				$del_ip = str_replace("_",".",$del_host[0]);
257
				exec('sudo /usr/bin/systemctl restart dnsmasq-whitelist');
252
				exec("sudo /usr/local/bin/alcasar-dns-local.sh --del $del_ip $del_host[1]");
258
			}
253
			}
259
		}
254
		}
260
		break;
255
		break;
261
 
256
 
262
	case 'default_cert':	// Restore default certificate
257
	case 'default_cert':	// Restore default certificate
Line 705... Line 700...
705
<table width="100%" cellspacing="0" cellpadding="5" border="1">
700
<table width="100%" cellspacing="0" cellpadding="5" border="1">
706
<tr>
701
<tr>
707
	<td width="50%" align="center">
702
	<td width="50%" align="center">
708
		<form action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>" method="POST">
703
		<form action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>" method="POST">
709
		<table cellspacing="2" cellpadding="3" border="1">
704
		<table cellspacing="2" cellpadding="3" border="1">
710
		<tr><th><?= $l_host_name ?></th><th><?= $l_ip_address ?></th><th><?= $l_del ?></th></tr>
705
		<tr><th><?= $l_ip_address ?></th><th><?= $l_host_name ?></th><th><?= $l_del ?></th></tr>
711
		<?php
706
		<?php
712
		// Read the "dns_local" file
707
		// Read the "dns_local" file
713
		$line_exist = false;
708
		$line_exist = false;
714
		$tab = file(DNS_LOCAL_FILE);
709
		$tab = file(DNS_LOCAL_FILE);
715
		if ($tab) { // not empty
710
		if ($tab) { // not empty
716
			foreach ($tab as $line) {
711
			foreach ($tab as $line) {
717
				if (preg_match ('/^address/', $line)) {
712
				if (preg_match ('/^\d+/', $line)) { # begin with one or several digit
718
					$line_exist = true;
713
					$line_exist = true;
-
 
714
					$field = preg_split("/\s+/",$line); # split with one or several whitespace (or tab)
719
					$field = explode('/', $line);
715
					$ip_addr   = $field[0];
720
					$host_name = $field[1];
716
					$host_name = $field[1];
721
					$ip_addr   = $field[2];
717
					echo "<tr><td>$ip_addr</td>";
722
					echo "<tr><td>$host_name</td>";
718
					echo "<td>$host_name</td>";
-
 
719
					if (($ip_addr == "127.0.0.1")|($host_name == "alcasar")) {
723
					echo "<td>$ip_addr</td>";
720
						echo "<td>";}
-
 
721
					else {
724
					echo "<td><input type=\"checkbox\" name=\"$host_name\"></td>";
722
						echo "<td><input type=\"checkbox\" name=\"$ip_addr|$host_name\">";
-
 
723
					}
725
					echo "</tr>";
724
					echo "</td></tr>";
726
				}
725
				}
727
			}
726
			}
728
		}
727
		}
729
		if (!$line_exist) {
728
		if (!$line_exist) {
730
			echo '<tr><td colspan="3" style="text-align: center;font-style: italic;">'.$l_empty.'</td></tr>';
729
			echo '<tr><td colspan="3" style="text-align: center;font-style: italic;">'.$l_empty.'</td></tr>';
Line 739... Line 738...
739
	</td>
738
	</td>
740
	<td width="50%" valign="middle" align="center">
739
	<td width="50%" valign="middle" align="center">
741
		<form name="new_host" action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>" method="POST">
740
		<form name="new_host" action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>" method="POST">
742
		<table cellspacing="2" cellpadding="3" border="1">
741
		<table cellspacing="2" cellpadding="3" border="1">
743
		<tr>
742
		<tr>
744
			<th><?= $l_host_name ?></th><th><?= $l_ip_address ?></th><td></td>
743
			<th><?= $l_ip_address ?></th><th><?= $l_host_name ?></th><td></td>
745
		</tr>
744
		</tr>
746
		<tr>
745
		<tr>
747
			<td>Ex. : my_nas</td><td>Ex. : 192.168.182.10</td><td></td>
746
			<td>Ex. : 192.168.182.10</td><td>Ex. : my_nas</td><td></td>
748
		</tr>
747
		</tr>
749
		<tr>
748
		<tr>
750
			<td><input type="text" name="add_host" size="17"></td>
-
 
751
			<td><input type="text" name="add_ip" size="10"><input type="hidden" name="choix" value="new_host"></td>
749
			<td><input type="text" name="add_ip" size="10"><input type="hidden" name="choix" value="new_host"></td>
-
 
750
			<td><input type="text" name="add_host" size="17"></td>
752
			<td><input type=submit class=button value="<?= $l_add_to_list ?>"></td>
751
			<td><input type=submit class=button value="<?= $l_add_to_list ?>"></td>
753
		</tr>
752
		</tr>
754
		</table>
753
		</table>
755
		</form>
754
		</form>
756
	</td>
755
	</td>