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

Add internet connectivity information to network UI #620

Merged
merged 16 commits into from Jun 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions config/config.php
Expand Up @@ -23,6 +23,8 @@
define('RASPI_OPENVPN_SERVER_CONFIG', '/etc/openvpn/server/server.conf');
define('RASPI_TORPROXY_CONFIG', '/etc/tor/torrc');
define('RASPI_LIGHTTPD_CONFIG', '/etc/lighttpd/lighttpd.conf');
define('RASPI_ACCESS_CHECK_IP', '1.1.1.1');
define('RASPI_ACCESS_CHECK_DNS', 'one.one.one.one');

// Constant for the 5GHz wireless regulatory domain
define('RASPI_5GHZ_ISO_ALPHA2', array('US'));
Expand Down
2 changes: 2 additions & 0 deletions includes/defaults.php
Expand Up @@ -27,6 +27,8 @@
'RASPI_OPENVPN_SERVER_CONFIG' => '/etc/openvpn/server/server.conf',
'RASPI_TORPROXY_CONFIG' => '/etc/tor/torrc',
'RASPI_LIGHTTPD_CONFIG' => '/etc/lighttpd/lighttpd.conf',
'RASPI_ACCESS_CHECK_IP' => '1.1.1.1',
'RASPI_ACCESS_CHECK_DNS' => 'one.one.one.one',

// Optional services, set to true to enable.
'RASPI_WIFICLIENT_ENABLED' => true,
Expand Down
30 changes: 30 additions & 0 deletions includes/internetRoute.php
@@ -0,0 +1,30 @@
<?php

$rInfo=array();
// get all default routes
exec('ip route list | sed -rn "s/default via (([0-9]{1,3}\.){3}[0-9]{1,3}).*dev (\w*).*src (([0-9]{1,3}\.){3}[0-9]{1,3}).*/\3 \4 \1/p"', $routes);
if (!empty($routes) ) {
foreach ($routes as $i => $route) {
$prop=explode(' ', $route);
$rInfo[$i]["interface"]=$prop[0];
$rInfo[$i]["ip-address"]=$prop[1];
$rInfo[$i]["gateway"]=$prop[2];
// resolve the name of the gateway (if possible)
unset($host);
exec('host '.$prop[2].' | sed -rn "s/.*domain name pointer (.*)\./\1/p" | head -n 1', $host);
$rInfo[$i]["gw-name"] = empty($host) ? "*" : $host[0];
if (isset($checkAccess) && $checkAccess) {
// check internet connectivity w/ and w/o DNS resolution
unset($okip);
exec('ping -W1 -c 1 -I '.$prop[0].' '.RASPI_ACCESS_CHECK_IP.' | sed -rn "s/.*icmp_seq=1.*time=.*/OK/p"',$okip);
$rInfo[$i]["access-ip"] = empty($okip) ? false : true;
unset($okdns);
exec('ping -W1 -c 1 -I '.$prop[0].' '.RASPI_ACCESS_CHECK_DNS.' | sed -rn "s/.*icmp_seq=1.*time=.*/OK/p"',$okdns);
$rInfo[$i]["access-dns"] = empty($okdns) ? false : true;
}
}
} else {
$rInfo = array("error"=>"No route to the internet found");
}
$rInfo_json = json_encode($rInfo);
?>
3 changes: 3 additions & 0 deletions locale/en_US/LC_MESSAGES/messages.po
Expand Up @@ -451,6 +451,9 @@ msgstr "Configures the max_num_sta option of hostapd. The default and maximum is
msgid "Summary"
msgstr "Summary"

msgid "Internet connection"
msgstr "Internet connection"

msgid "Current settings"
msgstr "Current settings"

Expand Down
63 changes: 52 additions & 11 deletions templates/networking.php
Expand Up @@ -17,21 +17,62 @@
$arrHostapdConf = parse_ini_file('/etc/raspap/hostapd.ini');
// defaults to false
$bridgedEnabled = $arrHostapdConf['BridgedEnable'];
?>
<?php if (!$bridgedEnabled): // no interface details when bridged ?>
<?php foreach ($interfaces as $if): ?>
<?php $if_quoted = htmlspecialchars($if, ENT_QUOTES) ?>
?>
<?php if (!$bridgedEnabled) : // no interface details when bridged ?>
<?php foreach ($interfaces as $if): ?>
<?php $if_quoted = htmlspecialchars($if, ENT_QUOTES) ?>
<li role="presentation" class="nav-item"><a class="nav-link" href="#<?php echo $if_quoted ?>" aria-controls="<?php echo $if_quoted ?>" role="tab" data-toggle="tab"><?php echo $if_quoted ?></a></li>
<?php endforeach ?>
<?php endforeach ?>
<?php endif ?>
</ul>
<div class="tab-content">

<div role="tabpanel" class="tab-pane active" id="summary">
<h4 class="mt-3"><?php echo _("Internet connection"); ?></h4>
<div class="row">
<div class="col-sm-12"">
<div class="card ">
<div class="card-body">
<div class="table-responsive">
<table class="table table-hover">
<thead>
<tr>
<th><?php echo _("Interface"); ?></th>
<th><?php echo _("IP Address"); ?></th>
<th><?php echo _("Gateway"); ?></th>
<th colspan="2"><?php echo _("Internet Access"); ?></th>
</tr>
</thead>
<tbody>
<?php
$checkAccess=true;
require "includes/internetRoute.php";
if (isset($rInfo["error"]) || empty($rInfo)) {
echo "<tr><td colspan=5>No route to the internet found</td></tr>";
} else {
foreach($rInfo as $route) {
echo "<tr>";
echo "<td>".$route["interface"]."</td>";
echo "<td>".$route["ip-address"]."</td>";
echo "<td>".$route["gateway"]."<br>".$route["gw-name"]."</td>";
$checkok = $route["access-ip"] ? "&check;" : "failed";
echo "<td>".$checkok."<br>".RASPI_ACCESS_CHECK_IP."</td>";
$checkok = $route["access-dns"] ? "&check;" : "failed";
echo "<td>".$checkok."<br>".RASPI_ACCESS_CHECK_DNS."</td>";
echo "</tr>";
}
}
?>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
<h4 class="mt-3"><?php echo _("Current settings") ?></h4>
<div class="row">
<?php foreach ($interfaces as $if): ?>
<?php $if_quoted = htmlspecialchars($if, ENT_QUOTES) ?>
<?php $if_quoted = htmlspecialchars($if, ENT_QUOTES) ?>
<div class="col-md-6 mb-3">
<div class="card">
<div class="card-header"><?php echo $if_quoted ?></div>
Expand All @@ -50,7 +91,7 @@
</div><!-- /.tab-pane -->

<?php foreach ($interfaces as $if): ?>
<?php $if_quoted = htmlspecialchars($if, ENT_QUOTES) ?>
<?php $if_quoted = htmlspecialchars($if, ENT_QUOTES) ?>
<div role="tabpanel" class="tab-pane fade in" id="<?php echo $if_quoted ?>">
<div class="row">
<div class="col-lg-6">
Expand Down Expand Up @@ -100,10 +141,10 @@
<div class="form-group">
<label for="<?php echo $if_quoted ?>-dnssvralt"><?php echo _("Alternate DNS Server") ?></label>
<input type="text" class="form-control" id="<?php echo $if_quoted ?>-dnssvralt" placeholder="0.0.0.0">
</div>
<?php if (!RASPI_MONITOR_ENABLED): ?>
</div>
<?php if (!RASPI_MONITOR_ENABLED) : ?>
<a href="#" class="btn btn-outline btn-primary intsave" data-int="<?php echo $if_quoted ?>"><?php echo _("Save settings") ?></a>
<a href="#" class="btn btn-warning intapply" data-int="<?php echo $if_quoted ?>"><?php echo _("Apply settings") ?></a>
<a href="#" class="btn btn-warning intapply" data-int="<?php echo $if_quoted ?>"><?php echo _("Apply settings") ?></a>
<?php endif ?>
</form>

Expand Down