Line 1... |
Line 1... |
1 |
<?php
|
1 |
<?php
|
2 |
# $Id: network.php 2379 2017-08-17 13:03:03Z tom.houdayer $
|
2 |
# $Id: network.php 2380 2017-08-17 15:59:54Z tom.houdayer $
|
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 76... |
Line 76... |
76 |
$l_yes = "Oui";
|
76 |
$l_yes = "Oui";
|
77 |
$l_no = "Non";
|
77 |
$l_no = "Non";
|
78 |
$l_allow_unsecured_login = "Autoriser les utilisateurs à se connecter de manière non sécurisée (HTTP) :";
|
78 |
$l_allow_unsecured_login = "Autoriser les utilisateurs à se connecter de manière non sécurisée (HTTP) :";
|
79 |
$l_unsecured_login_warning = "/!\\ Les identifiants de connexion seront envoyés en clair.";
|
79 |
$l_unsecured_login_warning = "/!\\ Les identifiants de connexion seront envoyés en clair.";
|
80 |
$l_cert_expiration = "Date d'expiration :";
|
80 |
$l_cert_expiration = "Date d'expiration :";
|
81 |
$l_cert_commonname = "Nom commun:";
|
81 |
$l_cert_commonname = "Nom commun :";
|
82 |
$l_cert_organization = "Organisation:";
|
82 |
$l_cert_organization = "Organisation :";
|
83 |
$l_upload_certificate = "Importer un certificat";
|
83 |
$l_upload_certificate = "Importer un certificat";
|
84 |
$l_le_integration = "Intégration Let's Encrypt";
|
84 |
$l_le_integration = "Intégration Let's Encrypt";
|
85 |
$l_le_status = "Status :";
|
85 |
$l_le_status = "Status :";
|
86 |
$l_disabled = "Inactif";
|
86 |
$l_disabled = "Inactif";
|
87 |
$l_pending_validation = "En attente de validation";
|
87 |
$l_pending_validation = "En attente de validation";
|
Line 155... |
Line 155... |
155 |
$l_renew_force = "Renew (force)";
|
155 |
$l_renew_force = "Renew (force)";
|
156 |
}
|
156 |
}
|
157 |
|
157 |
|
158 |
$reg_ip = '/^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$/';
|
158 |
$reg_ip = '/^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$/';
|
159 |
$reg_ip_cidr = '/^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])(\/([0-9]|[1-2][0-9]|3[0-2]))$/';
|
159 |
$reg_ip_cidr = '/^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])(\/([0-9]|[1-2][0-9]|3[0-2]))$/';
|
- |
|
160 |
$reg_mac = '/^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$/';
|
- |
|
161 |
$reg_host = '/^[a-zA-Z0-9-_]+$/';
|
160 |
|
162 |
|
161 |
$choix = (isset($_POST['choix'])) ? $_POST['choix'] : '';
|
163 |
$choix = (isset($_POST['choix'])) ? $_POST['choix'] : '';
|
162 |
|
164 |
|
163 |
switch ($choix) {
|
165 |
switch ($choix) {
|
164 |
case 'DHCP_On':
|
166 |
case 'DHCP_On':
|
Line 167... |
Line 169... |
167 |
case 'DHCP_Off':
|
169 |
case 'DHCP_Off':
|
168 |
exec('sudo /usr/local/bin/alcasar-dhcp.sh -off');
|
170 |
exec('sudo /usr/local/bin/alcasar-dhcp.sh -off');
|
169 |
break;
|
171 |
break;
|
170 |
|
172 |
|
171 |
case 'new_mac':
|
173 |
case 'new_mac':
|
- |
|
174 |
$new_mac_addr = trim($_POST['add_mac']);
|
172 |
if ((!empty(trim($_POST['add_mac']))) && (!empty(trim($_POST['add_ip'])))) {
|
175 |
$new_ip_addr = trim($_POST['add_ip']);
|
- |
|
176 |
if (((!empty($new_mac_addr)) && (preg_match($reg_mac, $new_mac_addr))) && ((!empty($new_ip_addr)) && (preg_match($reg_ip, $new_ip_addr)))) {
|
173 |
$tab = file(ETHERS_FILE);
|
177 |
$tab = file(ETHERS_FILE);
|
174 |
if ($tab) { // the file isn't empty
|
178 |
if ($tab) { // the file isn't empty
|
175 |
$insert = true;
|
179 |
$insert = true;
|
176 |
$new_mac_addr = trim($_POST['add_mac'], "\x00..\x20");
|
- |
|
177 |
$new_ip_addr = trim($_POST['add_ip'], "\x00..\x20");
|
- |
|
178 |
foreach ($tab as $line) { // verify that MAC or IP address doesn't exist
|
180 |
foreach ($tab as $line) { // verify that MAC or IP address doesn't exist
|
179 |
$field = explode(' ', $line);
|
181 |
$field = explode(' ', $line);
|
180 |
$mac_addr = trim($field[0]);
|
182 |
$mac_addr = trim($field[0]);
|
181 |
$ip_addr = trim($field[1]);
|
183 |
$ip_addr = trim($field[1]);
|
182 |
if (strcasecmp($new_mac_addr, $mac_addr) === 0) {
|
184 |
if (strcasecmp($new_mac_addr, $mac_addr) === 0) {
|
Line 213... |
Line 215... |
213 |
}
|
215 |
}
|
214 |
}
|
216 |
}
|
215 |
break;
|
217 |
break;
|
216 |
|
218 |
|
217 |
case 'new_host':
|
219 |
case 'new_host':
|
- |
|
220 |
$add_host = trim($_POST['add_host']);
|
- |
|
221 |
$add_ip = trim($_POST['add_ip']);
|
218 |
if ((!empty(trim($_POST['add_host']))) and (!empty(trim($_POST['add_ip'])))) {
|
222 |
if (((!empty($add_host)) && (preg_match($reg_host, $add_host))) && ((!empty($add_ip)) && (preg_match($reg_ip, $add_ip)))) {
|
219 |
$tab = file(DNS_LOCAL_FILE);
|
223 |
$tab = file(DNS_LOCAL_FILE);
|
220 |
if ($tab) { // the file isn't empty
|
224 |
if ($tab) { // the file isn't empty
|
221 |
$insert = true;
|
225 |
$insert = true;
|
222 |
foreach ($tab as $line) { // verify that host or IP address doesn't exist
|
226 |
foreach ($tab as $line) { // verify that host or IP address doesn't exist
|
223 |
if (preg_match('/^address/', $line)) {
|
227 |
if (preg_match('/^address/', $line)) {
|
224 |
$field = explode('/', $line);
|
228 |
$field = explode('/', $line);
|
225 |
$host_name = trim($field[1]);
|
229 |
$host_name = trim($field[1]);
|
226 |
$ip_addr = trim($field[2]);
|
230 |
$ip_addr = trim($field[2]);
|
227 |
if (strcasecmp(trim($_POST['add_host']), trim($host_name)) === 0) {
|
231 |
if (strcasecmp($add_host, $host_name) === 0) {
|
228 |
$insert = false;
|
232 |
$insert = false;
|
229 |
break;
|
233 |
break;
|
230 |
}
|
234 |
}
|
231 |
if (strcasecmp(trim($_POST['add_ip']), trim($ip_addr)) === 0) {
|
235 |
if (strcmp($add_ip, $ip_addr) === 0) {
|
232 |
$insert = false;
|
236 |
$insert = false;
|
233 |
break;
|
237 |
break;
|
234 |
}
|
238 |
}
|
235 |
}
|
239 |
}
|
236 |
}
|
240 |
}
|
237 |
if ($insert) {
|
241 |
if ($insert) {
|
238 |
$line1 = 'address=/'.trim($_POST['add_host']).'/'.trim($_POST['add_ip'])."\n";
|
242 |
$line1 = 'address=/'.$add_host.'/'.$add_ip."\n";
|
239 |
$explode_ip = explode('.', trim($_POST['add_ip']));
|
243 |
$explode_ip = explode('.', $add_ip);
|
240 |
$reverse_ip = implode('.', array_reverse($explode_ip));
|
244 |
$reverse_ip = implode('.', array_reverse($explode_ip));
|
241 |
$line2 = 'ptr-record='.$reverse_ip.'.in-addr.arpa,'.trim($_POST['add_host'])."\n";
|
245 |
$line2 = 'ptr-record='.$reverse_ip.'.in-addr.arpa,'.$add_host."\n";
|
242 |
$pointeur=fopen(DNS_LOCAL_FILE, 'a');
|
246 |
$pointeur=fopen(DNS_LOCAL_FILE, 'a');
|
243 |
fwrite($pointeur, $line1);
|
247 |
fwrite($pointeur, $line1);
|
244 |
fwrite($pointeur, $line2);
|
248 |
fwrite($pointeur, $line2);
|
245 |
fclose($pointeur);
|
249 |
fclose($pointeur);
|
246 |
exec('sudo /usr/bin/systemctl restart dnsmasq');
|
250 |
exec('sudo /usr/bin/systemctl restart dnsmasq');
|
247 |
exec('sudo /usr/bin/systemctl restart dnsmasq-blacklist');
|
251 |
exec('sudo /usr/bin/systemctl restart dnsmasq-blacklist');
|
248 |
exec('sudo /usr/bin/systemctl restart dnsmasq-whitelist');
|
252 |
exec('sudo /usr/bin/systemctl restart dnsmasq-whitelist');
|
249 |
}
|
- |
|
250 |
}
|
253 |
}
|
251 |
}
|
254 |
}
|
- |
|
255 |
}
|
252 |
break;
|
256 |
break;
|
253 |
case 'del_host':
|
257 |
case 'del_host':
|
254 |
foreach ($_POST as $key => $value) {
|
258 |
foreach ($_POST as $key => $value) {
|
255 |
if ($value == 'on') {
|
259 |
if ($value == 'on') {
|
256 |
$dns_local_file = DNS_LOCAL_FILE;
|
- |
|
257 |
exec("/bin/sed -i ".escapeshellarg("/$key/d")." $dns_local_file");
|
260 |
exec('/bin/sed -i '.escapeshellarg("\\@^address=/$key/@d;\\@^ptr-record=.*,$key\$@d").' '.DNS_LOCAL_FILE);
|
258 |
exec('sudo /usr/bin/systemctl restart dnsmasq');
|
261 |
exec('sudo /usr/bin/systemctl restart dnsmasq');
|
259 |
exec('sudo /usr/bin/systemctl restart dnsmasq-blacklist');
|
262 |
exec('sudo /usr/bin/systemctl restart dnsmasq-blacklist');
|
260 |
exec('sudo /usr/bin/systemctl restart dnsmasq-whitelist');
|
263 |
exec('sudo /usr/bin/systemctl restart dnsmasq-whitelist');
|
261 |
}
|
264 |
}
|
262 |
}
|
265 |
}
|
Line 269... |
Line 272... |
269 |
case 'import_cert': // Import certificate
|
272 |
case 'import_cert': // Import certificate
|
270 |
if (isset($_FILES['key']) && isset($_FILES['crt']) && ($_FILES['key']['error'] == 0) && ($_FILES['crt']['error'] == 0)) {
|
273 |
if (isset($_FILES['key']) && isset($_FILES['crt']) && ($_FILES['key']['error'] == 0) && ($_FILES['crt']['error'] == 0)) {
|
271 |
if ($_FILES['key']['size'] <= $maxsize && $_FILES['crt']['size'] <= $maxsize) {
|
274 |
if ($_FILES['key']['size'] <= $maxsize && $_FILES['crt']['size'] <= $maxsize) {
|
272 |
if (pathinfo($_FILES['key']['name'])['extension'] == 'key' && pathinfo($_FILES['crt']['name'])['extension'] == 'crt') {
|
275 |
if (pathinfo($_FILES['key']['name'])['extension'] == 'key' && pathinfo($_FILES['crt']['name'])['extension'] == 'crt') {
|
273 |
$dest = '/tmp/';
|
276 |
$dest = '/tmp/';
|
274 |
$scpath = "";
|
277 |
$scpath = '';
|
275 |
if (isset($_FILES['sc']) && (pathinfo($_FILES['sc']['name'])['extension'] == 'crt')) {
|
278 |
if (isset($_FILES['sc']) && (pathinfo($_FILES['sc']['name'])['extension'] == 'crt')) {
|
276 |
$scpath = $dest.'server-chain.crt';
|
279 |
$scpath = $dest.'server-chain.crt';
|
277 |
move_uploaded_file($_FILES['sc']['tmp_name'], $scpath);
|
280 |
move_uploaded_file($_FILES['sc']['tmp_name'], $scpath);
|
278 |
}
|
281 |
}
|
279 |
$keypath = $dest."alcasar.key";
|
282 |
$keypath = $dest.'alcasar.key';
|
280 |
$crtpath = $dest."alcasar.crt";
|
283 |
$crtpath = $dest.'alcasar.crt';
|
281 |
move_uploaded_file($_FILES['key']['tmp_name'], $keypath);
|
284 |
move_uploaded_file($_FILES['key']['tmp_name'], $keypath);
|
282 |
move_uploaded_file($_FILES['crt']['tmp_name'], $crtpath);
|
285 |
move_uploaded_file($_FILES['crt']['tmp_name'], $crtpath);
|
283 |
exec("sudo alcasar-importcert.sh -i $crtpath -k $keypath -c $scpath");
|
286 |
exec("sudo alcasar-importcert.sh -i $crtpath -k $keypath -c $scpath");
|
284 |
if (file_exists($crtpath)) unlink($crtpath);
|
287 |
if (file_exists($crtpath)) unlink($crtpath);
|
285 |
if (file_exists($keypath)) unlink($keypath);
|
288 |
if (file_exists($keypath)) unlink($keypath);
|