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

Reset button - factory reset #172

Open
wants to merge 26 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
59a99ee
Mobile friendly page
njkeng Feb 27, 2018
21d2e75
Merge remote-tracking branch 'refs/remotes/origin/Mobile'
njkeng Feb 27, 2018
3b038f8
Merge remote-tracking branch 'refs/remotes/billz/master'
njkeng Mar 11, 2018
f9259b8
Added reset script
njkeng Mar 11, 2018
5f1589a
Properly substitute forward slashes in directory names
njkeng Mar 12, 2018
f7c9b4e
Add script to handle button pressses
njkeng Mar 12, 2018
a6f3764
Resolve global variable issues
njkeng Mar 13, 2018
d8fa4ed
Merge branch 'master' into reset-button
billz Mar 19, 2018
034e8b8
Allow use of User settings for factory reset
njkeng Mar 20, 2018
129281f
Merge remote-tracking branch 'origin/reset-button' into reset-button
njkeng Mar 20, 2018
5e0dfbb
Avoid escaping directory structures in sed regex
njkeng Mar 20, 2018
fe90c27
Fix quotation of strings
njkeng Mar 20, 2018
a7a6477
Temporary changes to test quick installer
njkeng Mar 21, 2018
668bb66
Merge remote-tracking branch 'refs/remotes/billz/master' into reset-b…
njkeng Mar 21, 2018
8369fe4
Adjust file permissions for reset.ini
njkeng Mar 21, 2018
7108563
Move temporary file into /etc/raspap/hostapd
njkeng Mar 21, 2018
2182973
Modify scripts to work with python3
njkeng Mar 21, 2018
7997895
Changing file permissions
njkeng Mar 21, 2018
9c34169
Fix regex issues
njkeng Mar 21, 2018
767f2b4
Fix handling of default wpa_supplicant files
njkeng Mar 30, 2018
f1aec92
Fix saving of user settings
njkeng Mar 31, 2018
e726432
Fix dashboard control issues
njkeng Mar 31, 2018
afb9625
Merge remote-tracking branch 'refs/remotes/billz/master' into reset-b…
njkeng Mar 31, 2018
c1b6a9b
Fix intitialisation of reset.ini
njkeng Apr 2, 2018
dfa0b11
Update to include reset button
njkeng Apr 8, 2018
d1bf003
Undo changes used for testing
njkeng Apr 8, 2018
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
56 changes: 56 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ We'd be curious to hear about how you use this with your own Pi-powered access p
- [Prerequisites](#prerequisites)
- [Quick installer](#quick-installer)
- [Manual installation](#manual-installation)
- [Optional reset button](#optional-reset-button)
- [Optional services](#optional-services)
- [How to contribute](#how-to-contribute)
- [License](#license)
Expand Down Expand Up @@ -114,6 +115,61 @@ sudo reboot

The default username is 'admin' and the default password is 'secret'.

## Optional reset button

#### About
The RaspAP software monitors a GPIO pin which can be used to activate several reset functions. When held for different lengths of time, this one pin can activate reboot, power down and factory reset functions. You can connect a push button to this GPIO pin to make these functions available to the user. RaspAP also drives a GPIO output pin to indicate which function will be activated. You can wire an LED to this pin so that you can clearly see which function will be activated. The LED is not necessary to use the reset functions but it is nice to have.

This functionality is included in RaspAP. All you need to do is add the button and the LED.

#### Reset functions

The following functions can all be accessed by using the reset button

- Reboot. The Pi will power down and power back up again.
- Shutdown. The Pi will shut down. You need to cycle power to re-start the Pi.
- Factory reset. See [below](#factory-reset-function) for details about how this works.

#### Function selection

To activate the reset functions, hold the reset button down. Different hold times select the reset function that will be performed.
If you have connected an LED, the LED flash timing shows which of the reset functions will be activated when the button is released.

The reset function hold times and the LED flash codes are:

Reset function | Button held for | Recommended hold time | LED flash rate
-------------- | --------------- | --------------------- | ---------------
Device reboot | Between 1sec and 6 sec | 3 seconds | 1 per second (slow)
Device shutdown | Between 6 sec and 15 sec | 8 seconds | 2 per second (medium)
Factory reset | Longer than 15 seconds | 20 seconds | 5 per second (fast)

If the button has not been pressed, the LED will simply be ON. This indicates that RaspAP is operating normally.

Video showing how to use the button to activate the reset modes
https://youtu.be/7N_r_Cffa58

#### Factory reset function

The factory reset function restores RaspAP settings to a pre-defined state. Without changing any settings, the factory reset restores the default RaspAP settings, as would be used for a new installation.

You can configure the factory reset function to use settings that you have saved. The System -> Defaults menu has functions to set this up. There is a control that will save the current RaspAP configuration. You can also select whether the user saved settings or the RaspAP default settings will be used upon factory reset.

#### Adding the button and the LED

The button must be connected so that it shorts the pin GPIO 21 to ground. There is a ground pin directly adjacent to GPIO21 that will be convenient for most applications. Any normally open button will work.
The LED is connected from pin GPIO 20 to ground via a resistor. Using a resistor is **critical**. Leaving it out will definitely fry the GPIO pin and if you're unlucky it will take out the whole processor too. 330 ohms is a safe value to choose for the resistor.

Fritzing diagram showing which Pi pins to use and which way around the LED needs to be.
![](https://i.imgur.com/m7pT25C.png)

Photo of a button and LED installed on a Raspberry Pi Zero W.
![](https://i.imgur.com/X95yb6S.png)

Reference GPIO pinouts
![](https://pinout.xyz/resources/raspberry-pi-pinout.png)
Image courtesy of [pinout.xyz](https://pinout.xyz/)


## Optional services
OpenVPN and TOR are two additional services that run perfectly well on the RPi, and are a nice way to extend the usefulness of your WiFi router. I've started on interfaces to administer these services. Not everyone will need them, so for the moment they are disabled by default. You can enable them by changing these options in `index.php`:

Expand Down
125 changes: 66 additions & 59 deletions includes/configure_client.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,70 +163,77 @@ function DisplayWPAConfig(){
<!-- /.panel-heading -->
<div class="panel-body">
<p><?php $status->showMessages(); ?></p>
<h4>Client settings for interface <?php echo RASPI_WIFI_CLIENT_INTERFACE ?></h4>
<div class="btn-group btn-block">
<a href=".?<?php echo $_SERVER['QUERY_STRING']; ?>" style="padding:10px;float: right;display: block;position: relative;margin-top: -55px;" class="col-md-2 btn btn-info" id="update">Rescan</a>
</div>
<form method="POST" action="?page=wpa_conf" name="wpa_conf_form">
<?php CSRFToken() ?>
<input type="hidden" name="client_settings" ?>
<table class="table table-responsive table-striped">
<tr>
<th></th>
<th>SSID</th>
<th>Channel</th>
<th>Security</th>
<th>Passphrase</th>
<th></th>
</tr>
<?php $index = 0; ?>
<?php foreach ($networks as $ssid => $network) { ?>
<tr>
<td>
<?php if ($network['configured']) { ?>
<i class="fa fa-check-circle fa-fw"></i>
<?php } ?>
<?php if (array_key_exists('connected', $network) && $network['connected']) { ?>
<i class="fa fa-exchange fa-fw"></i>
<?php } ?>
</td>
<td>
<input type="hidden" name="ssid<?php echo $index ?>" value="<?php echo htmlentities($ssid) ?>" />
<?php echo $ssid ?>
</td>
<?php if (array_key_exists('visible', $network) && $network['visible']) { ?>
<td><?php echo $network['channel'] ?></td>
<?php } else { ?>
<td><span class="label label-warning">X</span></td>
<?php } ?>
<td>
<?php if (array_key_exists('priority', $network)) { ?>
<input type="hidden" name="priority<?php echo $index ?>" value="<?php echo $network['priority'] ?>" />
<?php } ?>
<input type="hidden" name="protocol<?php echo $index ?>" value="<?php echo $network['protocol'] ?>" /><?php echo $network['protocol'] ?>
</td>
<?php if ($network['protocol'] === 'Open') { ?>
<td><input type="hidden" name="passphrase<?php echo $index ?>" value="" />---</td>
<?php } else { ?>
<td><input type="text" class="form-control" name="passphrase<?php echo $index ?>" value="<?php echo $network['passphrase'] ?>" onKeyUp="CheckPSK(this, 'update<?php echo $index?>')" />
<?php } ?>
<td>
<div class="btn-group btn-block">
<h4>Interface <?php echo RASPI_WIFI_CLIENT_INTERFACE ?></h4>

<div class="btn-group btn-block">
<a href=".?<?php echo $_SERVER['QUERY_STRING']; ?>" style="padding:10px;float: right;display: block;position: relative;margin-top: -55px;" class="col-md-2 btn btn-info" id="update">Rescan</a>
</div>

<form method="POST" action="?page=wpa_conf" name="wpa_conf_form">
<?php CSRFToken() ?>
<input type="hidden" name="client_settings" ?>

<?php $index = 0; ?>
<?php foreach ($networks as $ssid => $network) { ?>

<div class="col-md-6">
<div class="panel panel-default">
<div class="panel-body">

<input type="hidden" name="ssid<?php echo $index ?>" value="<?php echo htmlentities($ssid) ?>" />
<!-- <div class="info-item">SSID</div> -->
<h4><?php echo $ssid ?></h4>
<br>

<div class="info-item">Status</div>
<?php if ($network['configured']) { ?>
<input type="submit" class="col-md-6 btn btn-warning" value="Update" id="update<?php echo $index ?>" name="update<?php echo $index ?>"<?php echo ($network['protocol'] === 'Open' ? ' disabled' : '')?> />
<?php } else { ?>
<input type="submit" class="col-md-6 btn btn-info" value="Add" id="update<?php echo $index ?>" name="update<?php echo $index ?>" <?php echo ($network['protocol'] === 'Open' ? '' : ' disabled')?> />
<i class="fa fa-check-circle fa-fw"></i>
<?php } ?>
<?php if ($network['connected']) { ?>
<i class="fa fa-exchange fa-fw"></i>
<?php } ?>
<input type="submit" class="col-md-6 btn btn-danger" value="Delete" name="delete<?php echo $index ?>"<?php echo ($network['configured'] ? '' : ' disabled')?> />
</div>
</td>
</tr>
<?php $index += 1; ?>
<br>

<div class="info-item">Channel</div>
<?php if ($network['visible']) { ?>
<?php echo $network['channel'] ?>
<?php } else { ?>
<span class="label label-warning"> X </span>
<?php } ?>
<br>

<input type="hidden" name="protocol<?php echo $index ?>" value="<?php echo $network['protocol'] ?>" />
<div class="info-item">Security</div> <?php echo $network['protocol'] ?>
<br>

<div class="info-item">Passphrase</div>
<?php if ($network['protocol'] === 'Open') { ?>
<input type="hidden" name="passphrase<?php echo $index ?>" value="" />---
<?php } else { ?>
<input type="text" class="form-control" name="passphrase<?php echo $index ?>" value="<?php echo $network['passphrase'] ?>" onKeyUp="CheckPSK(this, 'update<?php echo $index?>')" />
<?php } ?>
<br>

<div class="btn-group btn-block">
<?php if ($network['configured']) { ?>
<input type="submit" class="col-md-6 btn btn-warning" value="Update" id="update<?php echo $index ?>" name="update<?php echo $index ?>"<?php echo ($network['protocol'] === 'Open' ? ' disabled' : '')?> />
<?php } else { ?>
<input type="submit" class="col-md-6 btn btn-info" value="Add" id="update<?php echo $index ?>" name="update<?php echo $index ?>" <?php echo ($network['protocol'] === 'Open' ? '' : ' disabled')?> />
<?php } ?>
<input type="submit" class="col-md-6 btn btn-danger" value="Delete" name="delete<?php echo $index ?>"<?php echo ($network['configured'] ? '' : ' disabled')?> />
</div><!-- /.btn-group -->

</div><!-- /.panel-body -->
</div><!-- /.panel-default -->
</div><!-- /.col-md-6 -->


<?php $index += 1; ?>
<?php } ?>
</table>

</form>
</div><!-- ./ Panel body -->
<div class="panel-footer"><strong>Note,</strong> WEP access points appear as 'Open'. RaspAP does not currently support connecting to WEP.</div>
<div class="panel-footer"><strong>Note:</strong> WEP access points appear as 'Open'. RaspAP does not currently support connecting to WEP.</div>
</div><!-- /.panel-primary -->
</div><!-- /.col-lg-12 -->
</div><!-- /.row -->
Expand Down
35 changes: 23 additions & 12 deletions includes/dashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,26 +51,37 @@ function DisplayDashboard(){
$strFrequency = $result[1];

if(strpos( $strWlan0, "UP" ) !== false) {
$status->addMessage('Interface is up', 'success');
$wlan0up = true;
} else {
$status->addMessage('Interface is down', 'warning');
}

if( isset($_POST['ifdown_wlan0']) ) {
exec( 'ifconfig ' . RASPI_WIFI_CLIENT_INTERFACE . ' | grep -i running | wc -l',$test );
if($test[0] == 1) {
if( $wlan0up ) {
if( isset($_POST['ifdown_wlan0']) ) {
exec( 'sudo ip link set ' . RASPI_WIFI_CLIENT_INTERFACE . ' down',$return );
$status->addMessage('Stopping the interface. Wait for the page to refresh', 'warning');
?>
<script type="text/JavaScript">
setTimeout("location.href = 'index.php?page=wlan0_info';",2000);
</script>
<?php
} elseif( isset($_POST['ifup_wlan0']) ) {
$status->addMessage('Interface is already up', 'warning');
} else {
echo 'Interface already down';
$status->addMessage('Interface is up', 'success');
}
} elseif( isset($_POST['ifup_wlan0']) ) {
exec( 'ifconfig ' . RASPI_WIFI_CLIENT_INTERFACE . ' | grep -i running | wc -l',$test );
if($test[0] == 0) {
} else {
if( isset($_POST['ifup_wlan0']) ) {
exec( 'sudo ip link set ' . RASPI_WIFI_CLIENT_INTERFACE . ' up',$return );
exec( 'sudo ip -s a f label ' . RASPI_WIFI_CLIENT_INTERFACE,$return);
$status->addMessage('Starting the interface. Wait for the page to refresh', 'warning');
?>
<script type="text/JavaScript">
setTimeout("location.href = 'index.php?page=wlan0_info';",2000);
</script>
<?php
} elseif( isset($_POST['ifdown_wlan0']) ) {
$status->addMessage('Interface is already down', 'warning');
} else {
echo 'Interface already up';
$status->addMessage('Interface is down', 'warning');
}
}
?>
Expand Down Expand Up @@ -131,7 +142,7 @@ function DisplayDashboard(){
echo '<input type="submit" class="btn btn-warning" value="Stop ' . RASPI_WIFI_CLIENT_INTERFACE . '" name="ifdown_wlan0" />';
}
?>
<input type="button" class="btn btn-outline btn-primary" value="Refresh" onclick="document.location.reload(true)" />
<a href="index.php?page=wlan0_info" class="btn btn-outline btn-primary" id="btnSummaryRefresh"><i class="fa fa-refresh"></i> Refresh</a>
</form>
</div>
</div>
Expand Down
Loading