mirror of
https://github.com/billz/raspap-webgui.git
synced 2025-03-01 10:31:47 +00:00
@@ -11,6 +11,7 @@ define('RASPI_WIFI_CLIENT_INTERFACE', 'wlan0');
|
||||
define('RASPI_DNSMASQ_CONFIG', '/etc/dnsmasq.conf');
|
||||
define('RASPI_DNSMASQ_LEASES', '/var/lib/misc/dnsmasq.leases');
|
||||
define('RASPI_HOSTAPD_CONFIG', '/etc/hostapd/hostapd.conf');
|
||||
define('RASPI_DHCPCD_CONFIG', '/etc/dhcpcd.conf');
|
||||
define('RASPI_WPA_SUPPLICANT_CONFIG', '/etc/wpa_supplicant/wpa_supplicant.conf');
|
||||
define('RASPI_HOSTAPD_CTRL_INTERFACE', '/var/run/hostapd');
|
||||
define('RASPI_WPA_CTRL_INTERFACE', '/var/run/wpa_supplicant');
|
||||
|
@@ -27,7 +27,11 @@ function DisplayHostAPDConfig()
|
||||
} elseif( isset($_POST['StartHotspot']) ) {
|
||||
if (CSRFValidate()) {
|
||||
$status->addMessage('Attempting to start hotspot', 'info');
|
||||
exec( 'sudo /etc/init.d/hostapd start', $return );
|
||||
if ($arrHostapdConf['WifiAPEnable'] == 1) {
|
||||
exec('sudo /etc/raspap/hostapd/servicestart.sh --interface uap0 --seconds 5', $return );
|
||||
} else {
|
||||
exec( 'sudo /etc/raspap/hostapd/servicestart.sh --seconds 5', $return );
|
||||
}
|
||||
foreach( $return as $line ) {
|
||||
$status->addMessage($line, 'info');
|
||||
}
|
||||
@@ -80,7 +84,7 @@ function DisplayHostAPDConfig()
|
||||
<li class="active"><a href="#basic" data-toggle="tab"><?php echo _("Basic"); ?></a></li>
|
||||
<li><a href="#security" data-toggle="tab"><?php echo _("Security"); ?></a></li>
|
||||
<li><a href="#advanced" data-toggle="tab"><?php echo _("Advanced"); ?></a></li>
|
||||
<li><a href="#logoutput" data-toggle="tab"><?php echo _("Logfile output"); ?></a></li>
|
||||
<li><a href="#logoutput" data-toggle="tab"><?php echo _("Logfile"); ?></a></li>
|
||||
</ul>
|
||||
|
||||
<!-- Tab panes -->
|
||||
@@ -180,33 +184,46 @@ if (in_array($arrConfig['country_code'], $countries_max11channels)) {
|
||||
</div>
|
||||
</div>
|
||||
<div class="tab-pane fade" id="advanced">
|
||||
<h4><?php echo _("Advanced settings"); ?></h4>
|
||||
<h4><?php echo _("Advanced settings"); ?></h4>
|
||||
<div class="row">
|
||||
<div class="col-md-4">
|
||||
<div class="form-check">
|
||||
<label class="form-check-label" for="chxlogenable"><?php echo _("Enable logging");
|
||||
$checkedLogEnabled = '';
|
||||
if ($arrHostapdConf['LogEnable'] == 1) {
|
||||
$checkedLogEnabled = ' checked="checked"';
|
||||
<div class="checkbox">
|
||||
<?php
|
||||
$checkedWifiAPEnabled = '';
|
||||
if ($arrHostapdConf['WifiAPEnable'] == 1) {
|
||||
$checkedWifiAPEnabled = ' checked="checked"';
|
||||
}
|
||||
|
||||
?>
|
||||
</label>
|
||||
<input id="chxlogenable" name="logEnable" type="checkbox" class="form-check-input" value="1"<?php echo $checkedLogEnabled; ?> />
|
||||
<input id="chxwificlientap" name="wifiAPEnable" type="checkbox" class="form-check-input" data-toggle="toggle" data-on="Enabled" data-off="Disabled" data-width="100" value="1"<?php echo $checkedWifiAPEnabled; ?> />
|
||||
<label class="form-check-label" for="chxwificlientap"><?php echo _("WiFi client AP mode"); ?></label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-md-4">
|
||||
<div class="form-check">
|
||||
<label class="form-check-label" for="chxhiddenssid"><?php echo _("Hide SSID in broadcast");
|
||||
<div class="checkbox">
|
||||
<?php
|
||||
$checkedLogEnabled = '';
|
||||
if ($arrHostapdConf['LogEnable'] == 1) {
|
||||
$checkedLogEnabled = ' checked="checked"';
|
||||
}
|
||||
?>
|
||||
<input id="chxlogenable" name="logEnable" type="checkbox" class="form-check-input" data-toggle="toggle" data-on="Enabled" data-off="Disabled" data-width="100" value="1"<?php echo $checkedLogEnabled; ?> />
|
||||
<label class="form-check-label" for="chxlogenable"><?php echo _("Logfile output"); ?></label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-md-4">
|
||||
<div class="checkbox">
|
||||
<?php
|
||||
$checkedHiddenSSID = '';
|
||||
if ($arrConfig['ignore_broadcast_ssid'] == 1 || $arrConfig['ignore_broadcast_ssid'] == 2) {
|
||||
$checkedHiddenSSID = ' checked="checked"';
|
||||
}
|
||||
|
||||
?> </label>
|
||||
<input id="chxhiddenssid" name="hiddenSSID" type="checkbox" class="form-check-input" value="1"<?php echo $checkedHiddenSSID; ?> />
|
||||
?>
|
||||
<input id="chxhiddenssid" name="hiddenSSID" type="checkbox" class="form-check-input" data-toggle="toggle" data-on="Enabled" data-off="Disabled" data-width="100" value="1"<?php echo $checkedHiddenSSID; ?> />
|
||||
<label class="form-check-label" for="chxhiddenssid"><?php echo _("Hide SSID in broadcast"); ?></label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -517,27 +534,40 @@ function SaveHostAPDConfig($wpa_array, $enc_types, $modes, $interfaces, $status)
|
||||
}
|
||||
|
||||
$good_input = true;
|
||||
|
||||
// Check for WiFi client AP mode checkbox
|
||||
$wifiAPEnable = 0;
|
||||
if($arrHostapdConf['WifiAPEnable'] == 0) {
|
||||
if(isset($_POST['wifiAPEnable'])) {
|
||||
$wifiAPEnable = 1;
|
||||
}
|
||||
} else {
|
||||
if(isset($_POST['wifiAPEnable'])) {
|
||||
$wifiAPEnable = 1;
|
||||
}
|
||||
}
|
||||
|
||||
// Check for Logging Checkbox
|
||||
$logEnable = 0;
|
||||
if($arrHostapdConf['LogEnable'] == 0) {
|
||||
if(isset($_POST['logEnable'])) {
|
||||
// Need code to enable logfile logging here
|
||||
$logEnable = 1;
|
||||
exec('sudo /etc/raspap/hostapd/enablelog.sh');
|
||||
} else {
|
||||
exec('sudo /etc/raspap/hostapd/disablelog.sh');
|
||||
}
|
||||
} else {
|
||||
if(isset($_POST['logEnable'])) {
|
||||
$logEnable = 1;
|
||||
exec('sudo /etc/raspap/hostapd/enablelog.sh');
|
||||
} else {
|
||||
exec('sudo /etc/raspap/hostapd/disablelog.sh');
|
||||
}
|
||||
}
|
||||
|
||||
write_php_ini(["LogEnable" => $logEnable],'/etc/raspap/hostapd.ini');
|
||||
// Check for Logfile output checkbox
|
||||
$logEnable = 0;
|
||||
if($arrHostapdConf['LogEnable'] == 0) {
|
||||
if(isset($_POST['logEnable'])) {
|
||||
$logEnable = 1;
|
||||
exec('sudo /etc/raspap/hostapd/enablelog.sh');
|
||||
} else {
|
||||
exec('sudo /etc/raspap/hostapd/disablelog.sh');
|
||||
}
|
||||
} else {
|
||||
if(isset($_POST['logEnable'])) {
|
||||
$logEnable = 1;
|
||||
exec('sudo /etc/raspap/hostapd/enablelog.sh');
|
||||
} else {
|
||||
exec('sudo /etc/raspap/hostapd/disablelog.sh');
|
||||
}
|
||||
}
|
||||
$cfg = [];
|
||||
$cfg['LogEnable'] = $logEnable;
|
||||
$cfg['WifiAPEnable'] = $wifiAPEnable;
|
||||
write_php_ini($cfg,'/etc/raspap/hostapd.ini');
|
||||
|
||||
// Verify input
|
||||
if (empty($_POST['ssid']) || strlen($_POST['ssid']) > 32) {
|
||||
@@ -579,45 +609,91 @@ function SaveHostAPDConfig($wpa_array, $enc_types, $modes, $interfaces, $status)
|
||||
}
|
||||
|
||||
if ($good_input) {
|
||||
if ($tmp_file = fopen('/tmp/hostapddata', 'w')) {
|
||||
// Fixed values
|
||||
fwrite($tmp_file, 'driver=nl80211'.PHP_EOL);
|
||||
fwrite($tmp_file, 'ctrl_interface='.RASPI_HOSTAPD_CTRL_INTERFACE.PHP_EOL);
|
||||
fwrite($tmp_file, 'ctrl_interface_group=0'.PHP_EOL);
|
||||
fwrite($tmp_file, 'auth_algs=1'.PHP_EOL);
|
||||
fwrite($tmp_file, 'wpa_key_mgmt=WPA-PSK'.PHP_EOL);
|
||||
fwrite($tmp_file, 'beacon_int=100'.PHP_EOL);
|
||||
// Fixed values
|
||||
$config = 'driver=nl80211'.PHP_EOL;
|
||||
$config.= 'ctrl_interface='.RASPI_HOSTAPD_CTRL_INTERFACE.PHP_EOL;
|
||||
$config.= 'ctrl_interface_group=0'.PHP_EOL;
|
||||
$config.= 'auth_algs=1'.PHP_EOL;
|
||||
$config.= 'wpa_key_mgmt=WPA-PSK'.PHP_EOL;
|
||||
$config.= 'beacon_int=100'.PHP_EOL;
|
||||
$config.= 'ssid='.$_POST['ssid'].PHP_EOL;
|
||||
$config.= 'channel='.$_POST['channel'].PHP_EOL;
|
||||
if ($_POST['hw_mode'] === 'n') {
|
||||
$config.= 'hw_mode=g'.PHP_EOL;
|
||||
$config.= 'ieee80211n=1'.PHP_EOL;
|
||||
// Enable basic Quality of service
|
||||
$config.= 'wme_enabled=1'.PHP_EOL;
|
||||
} else {
|
||||
$config.= 'hw_mode='.$_POST['hw_mode'].PHP_EOL;
|
||||
$config.= 'ieee80211n=0'.PHP_EOL;
|
||||
}
|
||||
$config.= 'wpa_passphrase='.$_POST['wpa_passphrase'].PHP_EOL;
|
||||
if ($wifiAPEnable == 1) {
|
||||
$config.= 'interface=uap0'.PHP_EOL;
|
||||
} else {
|
||||
$config.= 'interface='.$_POST['interface'].PHP_EOL;
|
||||
}
|
||||
$config.= 'wpa='.$_POST['wpa'].PHP_EOL;
|
||||
$config.= 'wpa_pairwise='.$_POST['wpa_pairwise'].PHP_EOL;
|
||||
$config.= 'country_code='.$_POST['country_code'].PHP_EOL;
|
||||
$config.= 'ignore_broadcast_ssid='.$ignore_broadcast_ssid.PHP_EOL;
|
||||
|
||||
fwrite($tmp_file, 'ssid='.$_POST['ssid'].PHP_EOL);
|
||||
fwrite($tmp_file, 'channel='.$_POST['channel'].PHP_EOL);
|
||||
if ($_POST['hw_mode'] === 'n') {
|
||||
fwrite($tmp_file, 'hw_mode=g'.PHP_EOL);
|
||||
fwrite($tmp_file, 'ieee80211n=1'.PHP_EOL);
|
||||
// Enable basic Quality of service
|
||||
fwrite($tmp_file, 'wme_enabled=1'.PHP_EOL);
|
||||
} else {
|
||||
fwrite($tmp_file, 'hw_mode='.$_POST['hw_mode'].PHP_EOL);
|
||||
fwrite($tmp_file, 'ieee80211n=0'.PHP_EOL);
|
||||
}
|
||||
exec('echo "'.$config.'" > /tmp/hostapddata', $temp);
|
||||
system( "sudo cp /tmp/hostapddata " . RASPI_HOSTAPD_CONFIG, $return );
|
||||
|
||||
fwrite($tmp_file, 'wpa_passphrase='.$_POST['wpa_passphrase'].PHP_EOL);
|
||||
fwrite($tmp_file, 'interface='.$_POST['interface'].PHP_EOL);
|
||||
fwrite($tmp_file, 'wpa='.$_POST['wpa'].PHP_EOL);
|
||||
fwrite($tmp_file, 'wpa_pairwise='.$_POST['wpa_pairwise'].PHP_EOL);
|
||||
fwrite($tmp_file, 'country_code='.$_POST['country_code'].PHP_EOL);
|
||||
fwrite($tmp_file, 'ignore_broadcast_ssid='.$ignore_broadcast_ssid.PHP_EOL);
|
||||
fclose($tmp_file);
|
||||
if ($wifiAPEnable == 1) {
|
||||
// Enable uap0 configuration in dnsmasq for Wifi client AP mode
|
||||
$config = 'interface=lo,uap0 # Enable uap0 interface for wireless client AP mode'.PHP_EOL;
|
||||
$config.= 'bind-interfaces # Bind to the interfaces'.PHP_EOL;
|
||||
$config.= 'server=8.8.8.8 # Forward DNS requests to Google DNS'.PHP_EOL;
|
||||
$config.= 'domain-needed # Don\'t forward short names'.PHP_EOL;
|
||||
$config.= 'bogus-priv # Never forward addresses in the non-routed address spaces'.PHP_EOL;
|
||||
$config.= 'dhcp-range=192.168.50.50,192.168.50.150,12h'.PHP_EOL;
|
||||
} else {
|
||||
// Fallback to default config
|
||||
$config = 'domain-needed'.PHP_EOL;
|
||||
$config.= 'interface='.$_POST['interface'].PHP_EOL;
|
||||
$config.= 'dhcp-range=10.3.141.50,10.3.141.255,255.255.255.0,12h'.PHP_EOL;
|
||||
}
|
||||
exec('echo "'.$config.'" > /tmp/dhcpddata', $temp);
|
||||
system('sudo cp /tmp/dhcpddata '.RASPI_DNSMASQ_CONFIG, $return);
|
||||
|
||||
system( "sudo cp /tmp/hostapddata " . RASPI_HOSTAPD_CONFIG, $return );
|
||||
if( $return == 0 ) {
|
||||
$status->addMessage('Wifi Hotspot settings saved', 'success');
|
||||
} else {
|
||||
$status->addMessage('Unable to save wifi hotspot settings', 'danger');
|
||||
}
|
||||
if ($wifiAPEnable == 1) {
|
||||
// Enable uap0 configuration in dhcpcd for Wifi client AP mode
|
||||
$config = PHP_EOL.'# RaspAP uap0 configuration'.PHP_EOL;
|
||||
$config.= 'interface uap0'.PHP_EOL;
|
||||
$config.= 'static ip_address=192.168.50.1/24'.PHP_EOL;
|
||||
$config.= 'nohook wpa_supplicant'.PHP_EOL;
|
||||
} else {
|
||||
// Default config
|
||||
$config = '# RaspAP wlan0 configuration'.PHP_EOL;
|
||||
$config.= 'hostname'.PHP_EOL;
|
||||
$config.= 'clientid'.PHP_EOL;
|
||||
$config.= 'persistent'.PHP_EOL;
|
||||
$config.= 'option rapid_commit'.PHP_EOL;
|
||||
$config.= 'option domain_name_servers, domain_name, domain_search, host_name'.PHP_EOL;
|
||||
$config.= 'option classless_static_routes'.PHP_EOL;
|
||||
$config.= 'option ntp_servers'.PHP_EOL;
|
||||
$config.= 'require dhcp_server_identifier'.PHP_EOL;
|
||||
$config.= 'slaac private'.PHP_EOL;
|
||||
$config.= 'nohook lookup-hostname'.PHP_EOL;
|
||||
$config.= 'interface '.RASPI_WIFI_CLIENT_INTERFACE.PHP_EOL;
|
||||
$config.= 'static ip_address=10.3.141.1/24'.PHP_EOL;
|
||||
$config.= 'static routers=10.3.141.1'.PHP_EOL;
|
||||
$config.= 'static domain_name_server=1.1.1.1 8.8.8.8'.PHP_EOL;
|
||||
}
|
||||
exec('echo "'.$config.'" > /tmp/dhcpddata', $temp);
|
||||
system('sudo cp /tmp/dhcpddata '.RASPI_DHCPCD_CONFIG, $return);
|
||||
|
||||
|
||||
if( $return == 0 ) {
|
||||
$status->addMessage('Wifi Hotspot settings saved', 'success');
|
||||
} else {
|
||||
$status->addMessage('Unable to save wifi hotspot settings', 'danger');
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
$status->addMessage('Unable to save wifi hotspot settings', 'danger');
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
Reference in New Issue
Block a user