= IFNAMSIZ) { $errors .= _('Invalid interface name.').'
'.PHP_EOL; } if (!preg_match('/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\z/', $_POST['RangeStart']) && !empty($_POST['RangeStart'])) { // allow ''/null ? $errors .= _('Invalid DHCP range start.').'
'.PHP_EOL; } if (!preg_match('/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\z/', $_POST['RangeEnd']) && !empty($_POST['RangeEnd'])) { // allow ''/null ? $errors .= _('Invalid DHCP range end.').'
'.PHP_EOL; } if (!ctype_digit($_POST['RangeLeaseTime'])) { $errors .= _('Invalid DHCP lease time, not a number.').'
'.PHP_EOL; } if (!in_array($_POST['RangeLeaseTimeUnits'], array('m', 'h', 'd', 'infinite'))) { $errors .= _('Unknown DHCP lease time unit.').'
'.PHP_EOL; } $return = 1; if (empty($errors)) { $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); } else { $status->addMessage($errors, 'danger'); } 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 { exec('sudo /etc/init.d/dnsmasq start', $dnsmasq, $return); if ($return == 0) { $status->addMessage('Successfully started dnsmasq', 'success'); $dnsmasq_state = true; } else { $status->addMessage('Failed to start dnsmasq', 'danger'); } } } else { error_log('CSRF violation'); } } elseif( isset($_POST['stopdhcpd'] ) ) { if (CSRFValidate()) { if ($dnsmasq_state) { exec('sudo /etc/init.d/dnsmasq stop', $dnsmasq, $return); if ($return == 0) { $status->addMessage('Successfully stopped dnsmasq', 'success'); $dnsmasq_state = false; } 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 ); $hselected = ''; $mselected = ''; $dselected = ''; switch( $arrRangeLeaseTime[2] ) { case 'h': $hselected = ' selected="selected"'; break; case 'm': $mselected = ' selected="selected"'; break; case 'd': $dselected = ' selected="selected"'; break; } ?>

showMessages(); ?>

DHCP server settings

" name="savedhcpdsettings" /> '; } else { echo''; } ?>

Client list

'.htmlspecialchars($lease_item, ENT_QUOTES).''.PHP_EOL; } echo ' '.PHP_EOL; }; ?>