2016-07-09 00:26:13 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
include_once( 'includes/status_messages.php' );
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* Manage DHCP configuration
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
function DisplayDHCPConfig() {
|
|
|
|
|
|
|
|
$status = new StatusMessages();
|
|
|
|
if( isset( $_POST['savedhcpdsettings'] ) ) {
|
|
|
|
if (CSRFValidate()) {
|
|
|
|
$config = 'interface='.$_POST['interface'].PHP_EOL
|
|
|
|
.'dhcp-range='.$_POST['RangeStart'].','.$_POST['RangeEnd'].',255.255.255.0,'.$_POST['RangeLeaseTime'].''.$_POST['RangeLeaseTimeUnits'];
|
|
|
|
exec( 'echo "'.$config.'" > /tmp/dhcpddata',$temp );
|
|
|
|
system( 'sudo cp /tmp/dhcpddata '. RASPI_DNSMASQ_CONFIG, $return );
|
|
|
|
|
|
|
|
if( $return == 0 ) {
|
|
|
|
$status->addMessage('Dnsmasq configuration updated successfully', 'success');
|
|
|
|
} else {
|
|
|
|
$status->addMessage('Dnsmasq configuration failed to be updated', 'danger');
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
error_log('CSRF violation');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
exec( 'pidof dnsmasq | wc -l',$dnsmasq );
|
|
|
|
$dnsmasq_state = ($dnsmasq[0] > 0);
|
|
|
|
|
|
|
|
if( isset( $_POST['startdhcpd'] ) ) {
|
|
|
|
if (CSRFValidate()) {
|
|
|
|
if ($dnsmasq_state) {
|
|
|
|
$status->addMessage('dnsmasq already running', 'info');
|
|
|
|
} else {
|
2016-07-09 02:46:21 +00:00
|
|
|
exec('sudo /etc/init.d/dnsmasq start', $dnsmasq, $return);
|
|
|
|
if ($return == 0) {
|
2016-07-09 00:26:13 +00:00
|
|
|
$status->addMessage('Successfully started dnsmasq', 'success');
|
2016-07-09 02:34:48 +00:00
|
|
|
$dnsmasq_state = true;
|
2016-07-09 02:46:21 +00:00
|
|
|
} else {
|
|
|
|
$status->addMessage('Failed to start dnsmasq', 'danger');
|
2016-07-09 00:26:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
error_log('CSRF violation');
|
|
|
|
}
|
|
|
|
} elseif( isset($_POST['stopdhcpd'] ) ) {
|
|
|
|
if (CSRFValidate()) {
|
|
|
|
if ($dnsmasq_state) {
|
2016-07-09 02:46:21 +00:00
|
|
|
exec('sudo /etc/init.d/dnsmasq stop', $dnsmasq, $return);
|
|
|
|
if ($return == 0) {
|
2016-07-09 00:26:13 +00:00
|
|
|
$status->addMessage('Successfully stopped dnsmasq', 'success');
|
2016-07-09 02:34:48 +00:00
|
|
|
$dnsmasq_state = false;
|
2016-07-09 00:26:13 +00:00
|
|
|
} else {
|
|
|
|
$status->addMessage('Failed to stop dnsmasq', 'danger');
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$status->addMessage('dnsmasq already stopped', 'info');
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
error_log('CSRF violation');
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if( $dnsmasq_state ) {
|
|
|
|
$status->addMessage('Dnsmasq is running', 'success');
|
|
|
|
} else {
|
|
|
|
$status->addMessage('Dnsmasq is not running', 'warning');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
exec( 'cat '. RASPI_DNSMASQ_CONFIG, $return );
|
|
|
|
$conf = ParseConfig($return);
|
|
|
|
$arrRange = explode( ",", $conf['dhcp-range'] );
|
|
|
|
$RangeStart = $arrRange[0];
|
|
|
|
$RangeEnd = $arrRange[1];
|
|
|
|
$RangeMask = $arrRange[2];
|
|
|
|
preg_match( '/([0-9]*)([a-z])/i', $arrRange[3], $arrRangeLeaseTime );
|
|
|
|
|
2017-10-01 19:10:04 +00:00
|
|
|
$hselected = '';
|
|
|
|
$mselected = '';
|
|
|
|
$dselected = '';
|
|
|
|
|
2016-07-09 00:26:13 +00:00
|
|
|
switch( $arrRangeLeaseTime[2] ) {
|
|
|
|
case "h":
|
|
|
|
$hselected = " selected";
|
|
|
|
break;
|
|
|
|
case "m":
|
|
|
|
$mselected = " selected";
|
|
|
|
break;
|
|
|
|
case "d":
|
|
|
|
$dselected = " selected";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|
|
|
|
<div class="row">
|
|
|
|
<div class="col-lg-12">
|
|
|
|
<div class="panel panel-primary">
|
2017-10-23 19:51:34 +00:00
|
|
|
<div class="panel-heading"><i class="fa fa-exchange fa-fw"></i> <?php echo _("Configure DHCP"); ?></div>
|
2016-07-09 00:26:13 +00:00
|
|
|
<!-- /.panel-heading -->
|
|
|
|
<div class="panel-body">
|
|
|
|
<p><?php $status->showMessages(); ?></p>
|
|
|
|
<!-- Nav tabs -->
|
|
|
|
<ul class="nav nav-tabs">
|
2017-10-23 19:51:34 +00:00
|
|
|
<li class="active"><a href="#server-settings" data-toggle="tab"><?php echo _("Server settings"); ?></a>
|
2016-07-09 00:26:13 +00:00
|
|
|
</li>
|
2017-10-23 19:51:34 +00:00
|
|
|
<li><a href="#client-list" data-toggle="tab"><?php echo _("Client list"); ?></a>
|
2016-07-09 00:26:13 +00:00
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
<!-- Tab panes -->
|
|
|
|
<div class="tab-content">
|
|
|
|
<div class="tab-pane fade in active" id="server-settings">
|
|
|
|
<h4>DHCP server settings</h4>
|
|
|
|
<form method="POST" action="?page=dhcpd_conf">
|
|
|
|
<?php CSRFToken() ?>
|
|
|
|
<div class="row">
|
|
|
|
<div class="form-group col-md-4">
|
|
|
|
<label for="code">Interface</label>
|
|
|
|
<select class="form-control" name="interface">
|
|
|
|
<?php
|
|
|
|
exec("ip -o link show | awk -F': ' '{print $2}'", $interfaces);
|
|
|
|
|
|
|
|
foreach( $interfaces as $int ) {
|
|
|
|
$select = '';
|
|
|
|
if( $int == $conf['interface'] ) {
|
|
|
|
$select = " selected";
|
|
|
|
}
|
|
|
|
echo '<option value="'.$int.'"'.$select.'>'.$int.'</option>';
|
|
|
|
}
|
|
|
|
?>
|
|
|
|
</select>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="row">
|
|
|
|
<div class="form-group col-md-4">
|
2017-10-23 19:51:34 +00:00
|
|
|
<label for="code"><?php echo _("Starting IP Address"); ?></label>
|
2016-07-09 00:26:13 +00:00
|
|
|
<input type="text" class="form-control"name="RangeStart" value="<?php echo $RangeStart; ?>" />
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="row">
|
|
|
|
<div class="form-group col-md-4">
|
2017-10-23 19:51:34 +00:00
|
|
|
<label for="code"><?php echo _("Ending IP Address"); ?></label>
|
2016-07-09 00:26:13 +00:00
|
|
|
<input type="text" class="form-control" name="RangeEnd" value="<?php echo $RangeEnd; ?>" />
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="row">
|
|
|
|
<div class="form-group col-xs-2 col-sm-2">
|
2017-10-23 19:51:34 +00:00
|
|
|
<label for="code"><?php echo _("Lease Time"); ?></label>
|
2016-07-09 00:26:13 +00:00
|
|
|
<input type="text" class="form-control" name="RangeLeaseTime" value="<?php echo $arrRangeLeaseTime[1]; ?>" />
|
|
|
|
</div>
|
|
|
|
<div class="col-xs-2 col-sm-2">
|
2017-10-23 19:51:34 +00:00
|
|
|
<label for="code"><?php echo _("Interval"); ?></label>
|
2017-03-17 17:40:41 +00:00
|
|
|
<select name="RangeLeaseTimeUnits" class="form-control" ><option value="m" <?php echo $mselected; ?>>Minute(s)</option><option value="h" <?php echo $hselected; ?>>Hour(s)</option><option value="d" <?php echo $dselected; ?>>Day(s)</option><option value="infinite">Infinite</option></select>
|
2016-07-09 00:26:13 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
2017-10-23 19:51:34 +00:00
|
|
|
<input type="submit" class="btn btn-outline btn-primary" value="<?php echo _("Save settings"); ?>" name="savedhcpdsettings" />
|
2016-07-09 00:26:13 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
if ( $dnsmasq_state ) {
|
2017-10-23 19:51:34 +00:00
|
|
|
echo '<input type="submit" class="btn btn-warning" value="' . _("Stop dnsmasq") . '" name="stopdhcpd" />';
|
2016-07-09 00:26:13 +00:00
|
|
|
} else {
|
2017-10-23 19:51:34 +00:00
|
|
|
echo'<input type="submit" class="btn btn-success" value="' . _("Start dnsmasq") . '" name="startdhcpd" />';
|
2016-07-09 00:26:13 +00:00
|
|
|
}
|
|
|
|
?>
|
|
|
|
</form>
|
|
|
|
</div><!-- /.tab-pane -->
|
|
|
|
|
|
|
|
<div class="tab-pane fade in" id="client-list">
|
|
|
|
<h4>Client list</h4>
|
|
|
|
<div class="col-lg-12">
|
|
|
|
<div class="panel panel-default">
|
2017-10-23 19:51:34 +00:00
|
|
|
<div class="panel-heading"><?php echo _("Active DHCP leases"); ?></div>
|
2016-07-09 00:26:13 +00:00
|
|
|
<!-- /.panel-heading -->
|
|
|
|
<div class="panel-body">
|
|
|
|
<div class="table-responsive">
|
|
|
|
<table class="table table-hover">
|
|
|
|
<thead>
|
|
|
|
<tr>
|
2017-10-23 19:51:34 +00:00
|
|
|
<th><?php echo _("Expire time"); ?></th>
|
|
|
|
<th><?php echo _("MAC Address"); ?></th>
|
|
|
|
<th><?php echo _("IP Address"); ?></th>
|
|
|
|
<th><?php echo _("Host name"); ?></th>
|
|
|
|
<th><?php echo _("Client ID"); ?></th>
|
2016-07-09 00:26:13 +00:00
|
|
|
</tr>
|
|
|
|
</thead>
|
|
|
|
<tbody>
|
|
|
|
<tr>
|
|
|
|
<?php
|
|
|
|
exec( 'cat ' . RASPI_DNSMASQ_LEASES, $leases );
|
|
|
|
foreach( $leases as $lease ) {
|
|
|
|
$lease_items = explode(' ', $lease);
|
|
|
|
foreach( $lease_items as $lease_item ) {
|
|
|
|
echo '<td>' . $lease_item . '</td>';
|
|
|
|
}
|
|
|
|
echo '</tr>';
|
|
|
|
};
|
|
|
|
?>
|
|
|
|
</tr>
|
|
|
|
</tbody>
|
|
|
|
</table>
|
|
|
|
</div><!-- /.table-responsive -->
|
|
|
|
</div><!-- /.panel-body -->
|
|
|
|
</div><!-- /.panel -->
|
|
|
|
</div><!-- /.col-lg-6 -->
|
|
|
|
</div><!-- /.tab-pane -->
|
|
|
|
</div><!-- /.tab-content -->
|
|
|
|
</div><!-- ./ Panel body -->
|
2017-10-23 19:51:34 +00:00
|
|
|
<div class="panel-footer"> <?php echo _("Information provided by Dnsmasq");?></div>
|
2016-07-09 00:26:13 +00:00
|
|
|
</div><!-- /.panel-primary -->
|
|
|
|
</div><!-- /.col-lg-12 -->
|
|
|
|
</div><!-- /.row -->
|
|
|
|
<?php
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|
|
|
|
|