mirror of
https://github.com/billz/raspap-webgui.git
synced 2023-10-10 13:37:24 +02:00
Updated sudoers to accomodate restarting dhcpcd to apply network settings.
Updated installer to insert new lines Created files to generate / modify / save dhcpcd files and networking configuration
This commit is contained in:
parent
db8e201624
commit
8d77295fd3
42
ajax/networking/gen_int_config.php
Normal file
42
ajax/networking/gen_int_config.php
Normal file
@ -0,0 +1,42 @@
|
||||
<?php
|
||||
session_start();
|
||||
include_once('../../includes/config.php');
|
||||
include_once('../../includes/functions.php');
|
||||
|
||||
if(isset($_POST['generate']) && isset($_POST['csrf_token']) && CSRFValidate()) {
|
||||
$cnfNetworking = array_diff(scandir(RASPI_CONFIG_NETWORKING, 1),array('..','.'));
|
||||
$cnfNetworking = array_combine($cnfNetworking,$cnfNetworking);
|
||||
$strConfFile = "";
|
||||
foreach($cnfNetworking as $index=>$file) {
|
||||
if($index != "defaults") {
|
||||
$cnfFile = parse_ini_file(RASPI_CONFIG_NETWORKING.'/'.$file);
|
||||
if($cnfFile['static'] === 'true') {
|
||||
$strConfFile .= "interface ".$cnfFile['interface']."\n";
|
||||
$strConfFile .= "static ip_address=".$cnfFile['ip_address']."\n";
|
||||
$strConfFile .= "static routers=".$cnfFile['routers']."\n";
|
||||
$strConfFile .= "static domain_name_servers=".$cnfFile['domain_name_server']."\n";
|
||||
} elseif($cnfFile['static'] === 'false' && $cnfFile['failover'] === 'true') {
|
||||
$strConfFile .= "profile static_".$cnfFile['interface']."\n";
|
||||
$strConfFile .= "static ip_address=".$cnfFile['ip_address']."\n";
|
||||
$strConfFile .= "static routers=".$cnfFile['routers']."\n";
|
||||
$strConfFile .= "static domain_name_servers=".$cnfFile['domain_name_server']."\n\n";
|
||||
$strConfFile .= "interface ".$cnfFile['interface']."\n";
|
||||
$strConfFile .= "fallback static_".$cnfFile['interface']."\n\n";
|
||||
} else {
|
||||
$strConfFile .= "#DHCP configured for ".$cnfFile['interface']."\n\n";
|
||||
}
|
||||
} else {
|
||||
$strConfFile .= file_get_contents(RASPI_CONFIG_NETWORKING.'/'.$index)."\n\n";
|
||||
}
|
||||
}
|
||||
|
||||
if(file_put_contents(RASPI_CONFIG_NETWORKING.'/dhcpcd.conf',$strConfFile)) {
|
||||
exec('sudo /bin/cp /etc/raspap/networking/dhcpcd.conf /etc/dhcpcd.conf');
|
||||
$output = ['return'=>0,'output'=>'Settings successfully applied'];
|
||||
} else {
|
||||
$output = ['return'=>2,'output'=>'Unable to write to apply settings'];
|
||||
}
|
||||
echo json_encode($output);
|
||||
}
|
||||
|
||||
?>
|
@ -6,19 +6,16 @@ include_once('../../includes/functions.php');
|
||||
|
||||
if(isset($_POST['interface']) && isset($_POST['csrf_token']) && CSRFValidate()) {
|
||||
$int = $_POST['interface'];
|
||||
if(!file_exists(RASPI_CONFIG_NETWORKING.'/DHCP-'.$int)) {
|
||||
touch(RASPI_CONFIG_NETWORKING.'/DHCP-'.$int.'.ini');
|
||||
if(!file_exists(RASPI_CONFIG_NETWORKING.'/'.$int.'.ini')) {
|
||||
touch(RASPI_CONFIG_NETWORKING.'/'.$int.'.ini');
|
||||
}
|
||||
|
||||
if(!file_exists(RASPI_CONFIG_NETWORKING.'/STATIC-'.$int)) {
|
||||
touch(RASPI_CONFIG_NETWORKING.'/STATIC-'.$int.'.ini');
|
||||
}
|
||||
|
||||
$intDHCPConfig = parse_ini_file(RASPI_CONFIG_NETWORKING.'/DHCP-'.$int.'.ini');
|
||||
$intStaticConfig = parse_ini_file(RASPI_CONFIG_NETWORKING.'/STATIC-'.$int.'.ini');
|
||||
$jsonData = ['return'=>1,'output'=>['DHCPConfig'=>$intDHCPConfig,'StaticConfig'=>$intStaticConfig]];
|
||||
$intConfig = parse_ini_file(RASPI_CONFIG_NETWORKING.'/'.$int.'.ini');
|
||||
$jsonData = ['return'=>1,'output'=>['intConfig'=>$intConfig]];
|
||||
echo json_encode($jsonData);
|
||||
|
||||
// Todo - get dhcp lease information from `dhcpcd -U eth0` ? maybe ?
|
||||
|
||||
} else {
|
||||
$jsonData = ['return'=>2,'output'=>['Error getting data']];
|
||||
echo json_encode($jsonData);
|
||||
|
@ -45,31 +45,30 @@ function safefilerewrite($fileName, $dataToSave) {
|
||||
session_start();
|
||||
include_once('../../includes/config.php');
|
||||
include_once('../../includes/functions.php');
|
||||
var_dump($_POST);
|
||||
if(isset($_POST['interface']) && isset($_POST['csrf_token']) && CSRFValidate()) {
|
||||
$int = $_POST['interface'];
|
||||
$cfg = [];
|
||||
if($_POST[$int.'-static'] == 'true') {
|
||||
$file = "STATIC-".$int.".ini";
|
||||
$ip = $_POST[$int.'-ipaddress'];
|
||||
$netmask = mask2cidr($_POST[$int.'-netmask']);
|
||||
$dns1 = $_POST[$int.'-dnssvr'];
|
||||
$dns2 = $_POST[$int.'-dnssvralt'];
|
||||
$file = $int.".ini";
|
||||
$ip = $_POST[$int.'-ipaddress'];
|
||||
$netmask = mask2cidr($_POST[$int.'-netmask']);
|
||||
$dns1 = $_POST[$int.'-dnssvr'];
|
||||
$dns2 = $_POST[$int.'-dnssvralt'];
|
||||
|
||||
$cfg['static'] = $_POST[$int.'-static'];
|
||||
$cfg['interface'] = $int;
|
||||
$cfg['routers'] = $_POST[$int.'-gateway'];
|
||||
$cfg['ip_address'] = $ip."/".$netmask;
|
||||
$cfg['domain_name_server'] = $dns1." ".$dns2;
|
||||
|
||||
if(write_php_ini($cfg,RASPI_CONFIG_NETWORKING.'/'.$file)) {
|
||||
$jsonData = ['return'=>0,'output'=>['Successfully Updated Network Configuration']];
|
||||
} else {
|
||||
$jsonData = ['return'=>1,'output'=>['Error saving network configuration']];
|
||||
}
|
||||
$cfg['interface'] = $int;
|
||||
$cfg['routers'] = $_POST[$int.'-gateway'];
|
||||
$cfg['ip_address'] = $ip."/".$netmask;
|
||||
$cfg['domain_name_server'] = $dns1." ".$dns2;
|
||||
$cfg['static'] = $_POST[$int.'-static'];
|
||||
$cfg['failover'] = $_POST[$int.'-failover'];
|
||||
|
||||
if(write_php_ini($cfg,RASPI_CONFIG_NETWORKING.'/'.$file)) {
|
||||
$jsonData = ['return'=>0,'output'=>['Successfully Updated Network Configuration']];
|
||||
} else {
|
||||
$jsonData = ['return'=>1,'output'=>['Error saving network configuration to file']];
|
||||
}
|
||||
} else {
|
||||
$jsonData = ['return'=>2,'output'=>['Error saving network configuration']];
|
||||
$jsonData = ['return'=>2,'output'=>'Unable to detect interface'];
|
||||
}
|
||||
echo json_encode($jsonData);
|
||||
?>
|
||||
|
@ -26,6 +26,7 @@ function DisplayNetworkingConfig(){
|
||||
<i class="fa fa-sitemap fa-fw"></i> Configure Networking
|
||||
</div>
|
||||
<div class="panel panel-body">
|
||||
<div id="msgNetworking"></div>
|
||||
<ul class="nav nav-tabs">
|
||||
<li role="presentation" class="active"><a href="#summary" aria-controls="summary" role="tab" data-toggle="tab">Summary</a></li>
|
||||
<?php
|
||||
|
14
index.php
14
index.php
@ -121,13 +121,13 @@ $theme_url = 'dist/css/' . $theme;
|
||||
<li>
|
||||
<a href="index.php?page=hostapd_conf"><i class="fa fa-dot-circle-o fa-fw"></i> Configure Hotspot</a>
|
||||
</li>
|
||||
<li class="dropdown">
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Networking <span class="caret"></span></a>
|
||||
<ul class="dropdown-menu">
|
||||
<li>
|
||||
<a href="index.php?page=network_conf"><i class="fa fa-sitemap fa-fw"></i> Configure Networking</a>
|
||||
</li>
|
||||
</ul>
|
||||
<li>
|
||||
<a href="#" aria-expanded="false"><i class="fa fa-sitemap fa-fw"></i> Networking <span class="fa arrow"></span></a>
|
||||
<ul class="nav nav-second-level collapse" aria-expanded="false">
|
||||
<li>
|
||||
<a href="index.php?page=network_conf"><i class="fa fa-sitemap fa-fw"></i> Basic Networking</a>
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
<li>
|
||||
<a href="index.php?page=dhcpd_conf"><i class="fa fa-exchange fa-fw"></i> Configure DHCP Server</a>
|
||||
|
@ -222,6 +222,7 @@ function patch_system_files() {
|
||||
'/sbin/ip link set wlan0 down'
|
||||
'/sbin/ip link set wlan0 up'
|
||||
'/sbin/ip -s a f label wlan0'
|
||||
'/bin/cp /etc/raspap/networking/dhcpcd.conf /etc/dhcpcd.conf'
|
||||
)
|
||||
|
||||
# Check if sudoers needs patchin
|
||||
|
63
js/custom.js
63
js/custom.js
@ -1,3 +1,13 @@
|
||||
function msgShow(retcode,msg) {
|
||||
if(retcode == 0) {
|
||||
var alertType = 'success';
|
||||
} else if(retcode == 2 || retcode == 1) {
|
||||
var alertType = 'danger';
|
||||
}
|
||||
var htmlMsg = '<div class="alert alert-'+alertType+' alert-dismissible" role="alert"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>'+msg+'</div>';
|
||||
return htmlMsg;
|
||||
}
|
||||
|
||||
function createNetmaskAddr(bitCount) {
|
||||
var mask=[];
|
||||
for(i=0;i<4;i++) {
|
||||
@ -23,7 +33,9 @@ function loadSummary(strInterface) {
|
||||
function getAllInterfaces() {
|
||||
$.get('/ajax/networking/get_all_interfaces.php',function(data){
|
||||
jsonData = JSON.parse(data);
|
||||
$.each(jsonData,function(ind,value){loadSummary(value)});
|
||||
$.each(jsonData,function(ind,value){
|
||||
loadSummary(value)
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@ -40,20 +52,24 @@ function setupTabs() {
|
||||
function loadCurrentSettings(strInterface) {
|
||||
$.post('/ajax/networking/get_int_config.php',{interface:strInterface,csrf_token:csrf},function(data){
|
||||
jsonData = JSON.parse(data);
|
||||
//console.log(data);
|
||||
$.each(jsonData['output'],function(i,v) {
|
||||
//console.log(i);
|
||||
var int = v['interface'];
|
||||
//console.log('interface : '+int);
|
||||
$.each(v,function(i2,v2) {
|
||||
//console.log(i2+":"+v2);
|
||||
switch(i2) {
|
||||
case "static":
|
||||
if(v2 == 'true') {
|
||||
$('#'+int+'-static').click();
|
||||
$('#'+int+'-nofailover').click();
|
||||
} else {
|
||||
$('#'+int+'-dhcp').click();
|
||||
}
|
||||
break;
|
||||
case "interface":
|
||||
case "failover":
|
||||
if(v2 === 'true') {
|
||||
$('#'+int+'-failover').click();
|
||||
} else {
|
||||
$('#'+int+'-nofailover').click();
|
||||
}
|
||||
break;
|
||||
case "ip_address":
|
||||
var arrIPNetmask = v2.split('/');
|
||||
@ -74,10 +90,8 @@ function loadCurrentSettings(strInterface) {
|
||||
});
|
||||
}
|
||||
|
||||
function setupBtns() {
|
||||
$('#btnSummaryRefresh').click(function(){getAllInterfaces();});
|
||||
$('.intsave').click(function(){
|
||||
var int = $(this).data('int');
|
||||
function saveNetworkSettings(int) {
|
||||
|
||||
var frmInt = $('#frm-'+int).find(':input');
|
||||
var arrFormData = {};
|
||||
$.each(frmInt,function(i3,v3){
|
||||
@ -90,8 +104,34 @@ function setupBtns() {
|
||||
arrFormData['interface'] = int;
|
||||
arrFormData['csrf_token'] = csrf;
|
||||
$.post('/ajax/networking/save_int_config.php',arrFormData,function(data){
|
||||
console.log(data);
|
||||
//console.log(data);
|
||||
var jsonData = JSON.parse(data);
|
||||
$('#msgNetworking').html(msgShow(jsonData['return'],jsonData['output']));
|
||||
});
|
||||
}
|
||||
|
||||
function applyNetworkSettings() {
|
||||
var int = $(this).data('int');
|
||||
arrFormData = {};
|
||||
arrFormData['csrf_token'] = csrf;
|
||||
arrFormData['generate'] = '';
|
||||
$.post('/ajax/networking/gen_int_config.php',arrFormData,function(data){
|
||||
console.log(data);
|
||||
var jsonData = JSON.parse(data);
|
||||
$('#msgNetworking').html(msgShow(jsonData['return'],jsonData['output']));
|
||||
});
|
||||
}
|
||||
|
||||
function setupBtns() {
|
||||
$('#btnSummaryRefresh').click(function(){getAllInterfaces();});
|
||||
|
||||
$('.intsave').click(function(){
|
||||
var int = $(this).data('int');
|
||||
saveNetworkSettings(int);
|
||||
});
|
||||
|
||||
$('.intapply').click(function(){
|
||||
applyNetworkSettings();
|
||||
});
|
||||
}
|
||||
|
||||
@ -99,6 +139,7 @@ $().ready(function(){
|
||||
csrf = $('#csrf_token').val();
|
||||
pageCurrent = window.location.href.split("?")[1].split("=")[1];
|
||||
pageCurrent = pageCurrent.replace("#","");
|
||||
$('#side-menu').metisMenu();
|
||||
switch(pageCurrent) {
|
||||
case "network_conf":
|
||||
getAllInterfaces();
|
||||
|
Loading…
Reference in New Issue
Block a user