1
0
mirror of https://github.com/billz/raspap-webgui.git synced 2023-10-10 13:37:24 +02:00
raspap-webgui/ajax/networking/get_netcfg.php

59 lines
2.6 KiB
PHP
Raw Normal View History

2020-11-16 19:18:51 +01:00
<?php
require '../../includes/csrf.php';
require_once '../../includes/config.php';
$interface = $_POST['iface'];
2020-11-16 19:18:51 +01:00
if (isset($interface)) {
2020-11-26 18:15:42 +01:00
// fetch dnsmasq.conf settings for interface
exec('cat '. RASPI_DNSMASQ_PREFIX.escapeshellarg($interface).'.conf', $return);
2020-11-16 19:18:51 +01:00
$conf = ParseConfig($return);
$dhcpdata['DHCPEnabled'] = empty($conf) ? false : true;
$arrRange = explode(",", $conf['dhcp-range']);
$dhcpdata['RangeStart'] = $arrRange[0];
$dhcpdata['RangeEnd'] = $arrRange[1];
$dhcpdata['RangeMask'] = $arrRange[2];
$dhcpdata['leaseTime'] = $arrRange[3];
$dhcpHost = $conf["dhcp-host"];
$dhcpHost = empty($dhcpHost) ? [] : $dhcpHost;
$dhcpdata['dhcpHost'] = is_array($dhcpHost) ? $dhcpHost : [ $dhcpHost ];
$upstreamServers = is_array($conf['server']) ? $conf['server'] : [ $conf['server'] ];
2020-11-17 12:18:10 +01:00
$dhcpdata['upstreamServersEnabled'] = empty($conf['server']) ? false: true;
2020-11-26 18:15:42 +01:00
$dhcpdata['upstreamServers'] = array_filter($upstreamServers);
2020-11-16 19:18:51 +01:00
preg_match('/([0-9]*)([a-z])/i', $dhcpdata['leaseTime'], $arrRangeLeaseTime);
$dhcpdata['leaseTime'] = $arrRangeLeaseTime[1];
$dhcpdata['leaseTimeInterval'] = $arrRangeLeaseTime[2];
if (isset($conf['dhcp-option'])) {
$arrDns = explode(",", $conf['dhcp-option']);
if ($arrDns[0] == '6') {
if (count($arrDns) > 1) {
$dhcpdata['DNS1'] = $arrDns[1];
}
if (count($arrDns) > 2) {
$dhcpdata['DNS2'] = $arrDns[2];
}
}
}
2020-11-26 18:15:42 +01:00
// fetch dhcpcd.conf settings for interface
$conf = file_get_contents(RASPI_DHCPCD_CONFIG);
2020-11-27 17:28:37 +01:00
preg_match('/^#\sRaspAP\s'.$interface.'\s.*?(?=\s*+$)/ms', $conf, $matched);
2020-11-26 18:15:42 +01:00
preg_match('/metric\s(\d*)/', $matched[0], $metric);
preg_match('/static\sip_address=(.*)/', $matched[0], $static_ip);
preg_match('/static\srouters=(.*)/', $matched[0], $static_routers);
2020-12-01 19:39:23 +01:00
preg_match('/static\sdomain_name_server=(.*)/', $matched[0], $static_dns);
2020-11-26 18:15:42 +01:00
preg_match('/fallback\sstatic_'.$interface.'/', $matched[0], $fallback);
preg_match('/(?:no)?gateway/', $matched[0], $gateway);
2020-11-26 18:15:42 +01:00
$dhcpdata['Metric'] = $metric[1];
2020-12-03 11:29:11 +01:00
$dhcpdata['StaticIP'] = strpos($static_ip[1],'/') ? substr($static_ip[1], 0, strpos($static_ip[1],'/')) : $static_ip[1];
2020-11-30 13:10:44 +01:00
$dhcpdata['SubnetMask'] = cidr2mask($static_ip[1]);
2020-11-26 18:15:42 +01:00
$dhcpdata['StaticRouters'] = $static_routers[1];
$dhcpdata['StaticDNS'] = $static_dns[1];
$dhcpdata['FallbackEnabled'] = empty($fallback) ? false: true;
$dhcpdata['DefaultRoute'] = empty($gateway) || $gateway[0] == "gateway";
2020-11-26 18:15:42 +01:00
2020-11-16 19:18:51 +01:00
echo json_encode($dhcpdata);
}