Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wifi client AP mode #297

Merged
merged 47 commits into from
Apr 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
2d21830
Added uap0 config
billz Mar 5, 2019
bf8b47e
Added uap0 config to support wireless client AP mode
billz Mar 5, 2019
bf4f61d
Added support for wireless client AP mode
billz Mar 5, 2019
f9f0924
Initial commit
billz Mar 5, 2019
ef20f3d
Minor, edit comments
billz Mar 6, 2019
18d60ee
Updated dependencies
billz Mar 6, 2019
61a3434
Added bootstrap-toggle
billz Mar 6, 2019
6b0373d
Added bootstrap-toggle css+js
billz Mar 6, 2019
0dbfa71
WIP: Advanced options
billz Mar 6, 2019
7fcf22e
Update create_hostapd_scripts, sudoers
billz Mar 6, 2019
66a3944
Minor, updated for rename
billz Mar 6, 2019
d6bd7d2
WIP: WifiAPEnable handling
billz Mar 6, 2019
9e95863
Persist WifiAPEnable to ini, enable uap0 interface in dnsmasq.conf
billz Mar 6, 2019
b9ed8c4
Service renamed
billz Mar 6, 2019
5bb5498
Minor: move service control script
billz Mar 6, 2019
39e9037
Renamed
billz Mar 6, 2019
c8b2737
Renamed
billz Mar 6, 2019
cd3ac06
Renamed
billz Mar 6, 2019
521088b
Merge branch 'wificlient-ap' of https://github.com/billz/raspap-webgu…
billz Mar 6, 2019
94ad1f7
Delete servicesstart.sh
billz Mar 6, 2019
667e594
Delete hostapdstart.sh
billz Mar 6, 2019
b851f5d
Delete services.sh
billz Mar 6, 2019
12a0675
Merge branch 'wificlient-ap' of https://github.com/billz/raspap-webgu…
billz Mar 6, 2019
8a41731
Added todo for restarting hostapd
billz Mar 6, 2019
b022777
Merge branch 'wificlient-ap' of https://github.com/billz/raspap-webgu…
billz Mar 7, 2019
1df86a7
Updated with paramaterized servicestart
billz Mar 7, 2019
a2829dc
Added iptables nat rules for uap0 config
billz Mar 7, 2019
47a2b7c
Paramaterized service start, handles both uap0 and default
billz Mar 7, 2019
192a849
Update default dnsmasq settings
billz Mar 7, 2019
6cf96fd
Increased sleep value
billz Mar 7, 2019
bdc5958
Cleanup, typo fix
billz Mar 7, 2019
9abf79b
Merge branch 'master' into wificlient-ap
billz Mar 9, 2019
e30fb10
Added /bin/cp /etc/dhcpcd.conf to sudoers
billz Mar 11, 2019
96ffbf8
Added constant for dhcpcd.conf
billz Mar 11, 2019
113f3bf
WIP, config rewriting
billz Mar 11, 2019
a9cc4a0
Removed servicesdisable.sh from sudoers
billz Mar 12, 2019
7d98d12
WIP, rewite configs
billz Mar 12, 2019
b012bae
bugfix
billz Mar 12, 2019
8267c9b
Bugfix
billz Mar 12, 2019
d55f83c
Deleted servicesdisable.sh
billz Mar 12, 2019
be19291
Bugfix, patch sudoers
billz Mar 14, 2019
10be910
Bugfix: replaced wlan0 with constant
billz Mar 17, 2019
c83f288
bugfix: added slashes to iptables rules
billz Apr 6, 2019
cc6fe6f
Added restart rc-local.service
billz Apr 6, 2019
4d2d79b
Conditional prompt for reboot
billz Apr 7, 2019
ffbeb68
Updated messages
billz Apr 8, 2019
2a78918
Update & recompile messages
billz Apr 8, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
],
"dependencies": {
"bootstrap": "~3.3.7",
"bootstrap-toggle": "~2.2.0",
"datatables": "~1.10.4",
"datatables-plugins": "~1.0.1",
"flot": "~0.8.3",
Expand Down
7 changes: 6 additions & 1 deletion config/dhcpcd.conf
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,13 @@ require dhcp_server_identifier
slaac private
nohook lookup-hostname

# RaspAP-WebGui wireless configuration
# RaspAP wlan0 configuration
interface wlan0
static ip_address=10.3.141.1/24
static routers=10.3.141.1
static domain_name_server=1.1.1.1 8.8.8.8

# RaspAP uap0 configuration
interface uap0
static ip_address=192.168.50.1/24
nohook wpa_supplicant
11 changes: 10 additions & 1 deletion config/dnsmasq.conf
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
domain-needed
# RaspAP wlan0 configuration for wired (ethernet) AP mode
interface=wlan0
dhcp-range=10.3.141.50,10.3.141.255,255.255.255.0,12h

# RaspAP uap0 configuration for wireless client AP mode
#interface=lo,uap0 # Use interfaces lo and uap0
#bind-interfaces # Bind to the interfaces
#server=8.8.8.8 # Forward DNS requests to Google DNS
#domain-needed # Don't forward short names
#bogus-priv # Never forward addresses in the non-routed address spaces
#dhcp-range=192.168.50.50,192.168.50.150,12h

3 changes: 3 additions & 0 deletions config/hostapd.conf
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,6 @@ country_code=
#ieee80211n=1 # 802.11n support (Raspberry Pi 3)
#wmm_enabled=1 # QoS support (Raspberry Pi 3)
#ht_capab=[HT40][SHORT-GI-20][DSSS_CCK-40] # (Raspberry Pi 3)

## RaspAP wireless client AP mode
#interface=uap0
1 change: 1 addition & 0 deletions includes/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
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');
Expand Down
214 changes: 145 additions & 69 deletions includes/hostapd.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
Expand Down Expand Up @@ -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 -->
Expand Down Expand Up @@ -180,33 +184,46 @@ function DisplayHostAPDConfig()
</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");
<div class="checkbox">
<?php
$checkedWifiAPEnabled = '';
if ($arrHostapdConf['WifiAPEnable'] == 1) {
$checkedWifiAPEnabled = ' checked="checked"';
}
?>
<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="checkbox">
<?php
$checkedLogEnabled = '';
if ($arrHostapdConf['LogEnable'] == 1) {
$checkedLogEnabled = ' checked="checked"';
}

?>
</label>
<input id="chxlogenable" name="logEnable" type="checkbox" class="form-check-input" value="1"<?php echo $checkedLogEnabled; ?> />
<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="form-check">
<label class="form-check-label" for="chxhiddenssid"><?php echo _("Hide SSID in broadcast");
<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>
Expand Down Expand Up @@ -517,27 +534,40 @@ function SaveHostAPDConfig($wpa_array, $enc_types, $modes, $interfaces, $status)
}

$good_input = true;

// 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 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 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) {
Expand Down Expand Up @@ -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);

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);
}
// 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;

exec('echo "'.$config.'" > /tmp/hostapddata', $temp);
system( "sudo cp /tmp/hostapddata " . RASPI_HOSTAPD_CONFIG, $return );

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);

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);

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);

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( $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;
Expand Down
6 changes: 6 additions & 0 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@
<!-- Bootstrap Core CSS -->
<link href="vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">

<!-- Bootstrap Toggle CSS -->
<link href="vendor/bootstrap-toggle/css/bootstrap-toggle.min.css" rel="stylesheet">

<!-- MetisMenu CSS -->
<link href="vendor/metisMenu/metisMenu.min.css" rel="stylesheet">

Expand Down Expand Up @@ -239,6 +242,9 @@
<!-- Bootstrap Core JavaScript -->
<script src="vendor/bootstrap/js/bootstrap.min.js"></script>

<!-- Bootstrap Toggle JavaScript -->
<script src="vendor/bootstrap-toggle/js/bootstrap-toggle.min.js"></script>

<!-- Metis Menu Plugin JavaScript -->
<script src="vendor/metisMenu/metisMenu.min.js"></script>

Expand Down
Loading