Skip to content

Commit

Permalink
Merge pull request pihome-shc#335 from twa127/master
Browse files Browse the repository at this point in the history
Network Settings Table and GUI
  • Loading branch information
pihome-shc authored Jul 19, 2020
2 parents 45d0e5e + 7708245 commit 23b216f
Show file tree
Hide file tree
Showing 6 changed files with 231 additions and 1 deletion.
23 changes: 23 additions & 0 deletions MySQL_Database/pihome_mysql_database.sql
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,29 @@ ENGINE=InnoDB;
/*!40000 ALTER TABLE `mqtt` DISABLE KEYS */;
/*!40000 ALTER TABLE `mqtt` ENABLE KEYS */;

-- Dumping structure for table pihome.network_settings
DROP TABLE IF EXISTS `network_settings`;
CREATE TABLE IF NOT EXISTS `network_settings` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`sync` tinyint(4) NOT NULL,
`purge` tinyint(4) NOT NULL COMMENT 'Mark For Deletion',
`primary_interface` tinyint(4),
`interface_num` tinyint(4),
`interface_type` char(50) COLLATE utf16_bin,
`mac_address` char(50) COLLATE utf16_bin,
`hostname` char(50) COLLATE utf16_bin,
`ip_address` char(50) COLLATE utf16_bin,
`gateway_address` char(50) COLLATE utf16_bin,
`net_mask` char(50) COLLATE utf16_bin,
`dns1_address` char(50) COLLATE utf16_bin,
`dns2_address` char(50) COLLATE utf16_bin,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf16 COLLATE=utf16_bin;

-- Dumping data for table pihome.network_settings: ~0 rows (approximately)
/*!40000 ALTER TABLE `system` DISABLE KEYS */;
/*!40000 ALTER TABLE `system` ENABLE KEYS */;

-- Dumping structure for table pihome.nodes
DROP TABLE IF EXISTS `nodes`;
CREATE TABLE IF NOT EXISTS `nodes` (
Expand Down
34 changes: 34 additions & 0 deletions db.php
Original file line number Diff line number Diff line change
Expand Up @@ -736,6 +736,40 @@
}


//network Settings
if($what=="setup_network"){
$n_primary = $_GET['n_primary'];
$n_int_num = $_GET['n_int_num'];
$n_int_type = $_GET['n_int_type'];
$n_mac = $_GET['n_mac'];
$n_hostname = $_GET['n_hostname'];
$n_ip = $_GET['n_ip'];
$n_gateway = $_GET['n_gateway'];
$n_net_mask = $_GET['n_net_mask'];
$n_dns1 = $_GET['n_dns1'];
$n_dns2 = $_GET['n_dns2'];

//Check interface already exists in table
$query = "SELECT * FROM `network_settings` WHERE `interface_num` = '".$n_int_num."' LIMIT 1;";
$result = $conn->query($query);
if (mysqli_num_rows($result)==0){
//No record, so add
$query = "INSERT INTO `network_settings`(`sync`, `purge`, `primary_interface`, `interface_num`, `interface_type`, `mac_address`, `hostname`, `ip_address`, `gateway_address`, `net_mask`, `dns1_address`, `dns2_address`) VALUES (0,0,'".$n_primary."','".$n_int_num."','".$n_int_type."','".$n_mac."','".$n_hostname."','".$n_ip."','".$n_gateway."','".$n_net_mask."','".$n_dns1."','".$n_dns2."');";
} else {
//Update
$query = "UPDATE `network_settings` SET primary_interface = '".$n_primary."', interface_type = '".$n_int_type."', mac_address = '".$n_mac."', hostname = '".$n_hostname."', ip_address = '".$n_ip."', gateway_address = '".$n_gateway."', net_mask = '".$n_net_mask."', dns1_address = '".$n_dns1."', dns2_address = '".$n_dns2."' where interface_num = '".$n_int_num."';";
}
if($conn->query($query)){
header('Content-type: application/json');
echo json_encode(array('Success'=>'Success','Query'=>$query));
return;
}else{
header('Content-type: application/json');
echo json_encode(array('Message'=>'Database query failed.\r\nQuery=' . $query));
return;
}
}

//Setup E-mail Setting
if($what=="setup_email"){
$status = $_GET['status'];
Expand Down
28 changes: 28 additions & 0 deletions js/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,34 @@ var idata="w=setup_gateway&o=update&status="+document.getElementById("checkbox1"
});
}

//update network settings
function setup_network(){
var idata="w=setup_network&o=update&n_primary="+document.getElementById("n_primary").value;
idata+="&n_int_num="+document.getElementById("n_int_num").value;
idata+="&n_int_type="+document.getElementById("n_int_type").value;
idata+="&n_mac="+document.getElementById("n_mac").value;
idata+="&n_hostname"+document.getElementById("n_hostname").value;
idata+="&n_ip="+document.getElementById("n_ip").value;
idata+="&n_gateway="+document.getElementById("n_gateway").value;
idata+="&n_net_mask="+document.getElementById("n_net_mask").value;
idata+="&n_dns1="+document.getElementById("n_dns1").value;
idata+="&n_dns2="+document.getElementById("n_dns2").value;
idata+="&wid=0";
$.get('db.php',idata)
.done(function(odata){
if(odata.Success)
reload_page();
else
console.log(odata.Message);
})
.fail(function( jqXHR, textStatus, errorThrown ){
if(jqXHR==401 || jqXHR==403) return;
console.log("setup_network: Error.\r\n\r\njqXHR: "+jqXHR+"\r\n\r\ntextStatus: "+textStatus+"\r\n\r\nerrorThrown:"+errorThrown);
})
.always(function() {
});
}

//update email
function setup_email(){
var idata="w=setup_email&o=update&status="+document.getElementById("checkbox3").checked;
Expand Down
12 changes: 12 additions & 0 deletions languages/en.php
Original file line number Diff line number Diff line change
Expand Up @@ -419,4 +419,16 @@
$lang['confirm_dell_active_zone'] = "You are about to DELETE an ACTIVE ZONE";
$lang['confirm_dell_de_active_zone'] = "You are about to DELETE a NONE active ZONE";

$lang['network'] = "Network";
$lang['network_settings'] = "Network Settings";
$lang['network_text'] = "Controller Network Configuration Parameters. ";
$lang['network_interface'] = "Controller Network Interface";
$lang['network_mac_address'] = "Controller MAC Address";
$lang['network_hostname'] = "Controller Hostname";
$lang['network_ip_address'] = "Controller IP Address";
$lang['network_gateway_address'] = "Controller Gateway Address";
$lang['network_net_mask'] = "Controller Net Mask";
$lang['network_dns1_address'] = "Controller DNS1 Address";
$lang['network_dns2_address'] = "Controller DNS2 Address";
$lang['network_primary'] = "Controller Primary Interface";
?>
126 changes: 126 additions & 0 deletions model.php
Original file line number Diff line number Diff line change
Expand Up @@ -988,6 +988,132 @@
<!-- /.modal fade -->
';

//network settings model
echo '
<div class="modal fade" id="network_setting" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">x</button>
<h5 class="modal-title">'.$lang['network_settings'].'</h5>
</div>
<div class="modal-body">';

$query = "SELECT * FROM `network_settings` ORDER BY `id` ASC;";
$result = $conn->query($query);

$rowArray = array();

while($row = mysqli_fetch_assoc($result)) {
$rowArray[] = $row;
}

echo '<p class="text-muted">'.$lang['network_text'].'</p>';
echo '
<form data-toggle="validator" role="form" method="post" action="settings.php" id="form-join">
<input class="form-control input-sm" type="hidden" id="n_int_type" name="n_int_type" value="'.$rowArray[0]['interface_type'].'"/>
<div class="form-group" class="control-label"><label>'.$lang['network_interface'].'</label>
<select class="form-control input-sm" type="text" id="n_int_num" name="n_int_num" onchange=change(this.options[this.selectedIndex].value)>
<option value=0>wlan0</option>
<option value=1>wlan1</option>
<option value=2>eth0</option>
<option value=3>eth1</option>
</select>
<div class="help-block with-errors">
</div>
</div>
<div class="form-group" class="control-label"><label>'.$lang['network_primary'].'</label>
<select class="form-control input-sm" type="text" id="n_primary" name="n_primary">
<option value=0>No</option>
<option selected value=1>Yes</option>
</select>
<div class="help-block with-errors">
</div>
</div>
echo '<div class="form-group" class="control-label"><label>'.$lang['network_mac_address'].'</label>
<input class="form-control input-sm" type="text" id="n_mac" name="n_mac" value="'.$rowArray[0]['mac_address'].'" placeholder="MAC Address">
<div class="help-block with-errors">
</div>
</div>
<div class="form-group" class="control-label"><label>'.$lang['network_hostname'].'</label>
<input class="form-control input-sm" type="text" id="n_hostname" name="n_hostname" value="'.$rowArray[0]['hostname'].'" placeholder="Hostname">
<div class="help-block with-errors">
</div>
</div>
<div class="form-group" class="control-label"><label>'.$lang['network_ip_address'].'</label>
<input class="form-control input-sm" type="text" id="n_ip" name="n_ip" value="'.$rowArray[0]['ip_address'].'" placeholder="IP Address">
<div class="help-block with-errors">
</div>
</div>
<div class="form-group" class="control-label"><label>'.$lang['network_gateway_address'].'</label>
<input class="form-control input-sm" type="text" id="n_gateway" name="n_gateway" value="'.$rowArray[0]['gateway_address'].'" placeholder="Gateway Address">
<div class="help-block with-errors">
</div>
</div>
<div class="form-group" class="control-label"><label>'.$lang['network_net_mask'].'</label>
<input class="form-control input-sm" type="text" id="n_net_mask" name="n_net_mask" value="'.$rowArray[0]['net_mask'].'" placeholder="Net Mask">
<div class="help-block with-errors">
</div>
</div>
<div class="form-group" class="control-label"><label>'.$lang['network_dns1_address'].'</label>
<input class="form-control input-sm" type="text" id="n_dns1" name="n_dns1" value="'.$rowArray[0]['dns1_address'].'" placeholder="DNS1 Address">
<div class="help-block with-errors">
</div>
</div>
<div class="form-group" class="control-label"><label>'.$lang['network_dns2_address'].'</label>
<input class="form-control input-sm" type="text" id="n_dns2" name="n_dns2" value="'.$rowArray[0]['dns2_address'].'" placeholder="DNS2 Address">
<div class="help-block with-errors">
</div>
</div>
</div>
<!-- /.modal-body -->
<div class="modal-footer">
<button type="button" class="btn btn-primary btn-sm" data-dismiss="modal">'.$lang['close'].'</button>
<input type="button" name="submit" value="Save" class="btn btn-default login btn-sm" onclick="setup_network()">
</div>
<!-- /.modal-footer -->
</div>
<!-- /.modal-content -->
</div>
<!-- /.modal-dialog -->
</div>
<!-- /.modal-fade -->
';
?>
<script>
function change(value){
var jArray = <?php echo json_encode($rowArray); ?>;
var valuetext = value;
document.getElementById("n_primary").value = jArray[value]['primary_interface'];
document.getElementById("n_mac").value = jArray[value]['mac_address'];
document.getElementById("n_hostname").value = jArray[value]['hostname'];
document.getElementById("n_ip").value = jArray[value]['ip_address'];
document.getElementById("n_gateway").value = jArray[value]['gateway_address'];
document.getElementById("n_net_mask").value = jArray[value]['net_mask'];
document.getElementById("n_dns1").value = jArray[value]['dns1_address'];
document.getElementById("n_dns2").value = jArray[value]['dns2_address'];
switch (value) {
case '0':
document.getElementById("n_int_type").value = 'wlan0';
break;
case '1':
document.getElementById("n_int_type").value = 'wlan1';
break;
case '2':
document.getElementById("n_int_type").value = 'eth0';
break;
case '3':
document.getElementById("n_int_type").value = 'eth1';
break;
default:
}
}
</script>
<?php

//email settings model
echo '
<div class="modal fade" id="email_setting" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
Expand Down
9 changes: 8 additions & 1 deletion settingslist.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,14 @@

<div id="collapse_system" class="panel-collapse collapse animated fadeIn">
<h4 class="pull-left"><?php echo $lang['system_configuration']; ?></h4><br>
<button class="btn btn-default btn-circle btn-xxl mainbtn animated fadeIn" data-href="edit_piconnect.php" data-toggle="modal" data-target="#piconnect">

<button class="btn btn-default btn-circle btn-xxl mainbtn animated fadeIn" data-href="#" data-toggle="modal" data-target="#network_setting">
<h3 class="buttontop"><small><?php echo $lang['network']; ?></small></h3>
<h3 class="degre" ><i class="ionicons ion-network blue"></i></h3>
<h3 class="status"></small></h3>
</button>

<button class="btn btn-default btn-circle btn-xxl mainbtn animated fadeIn" data-href="edit_piconnect.php" data-toggle="modal" data-target="#piconnect">
<h3 class="buttontop"><small>PiConnect</small></h3>
<h3 class="degre" ><i class="fa fa-plug green"></i></h3>
<h3 class="status"></small></h3>
Expand Down

0 comments on commit 23b216f

Please sign in to comment.