Templatized Tor proxy config

This commit is contained in:
billz 2019-11-12 21:05:21 +00:00
parent ef2286152a
commit 25d1ddeed6
4 changed files with 191 additions and 178 deletions

View file

@ -266,184 +266,6 @@ function ConvertToSecurity($security)
}
}
/**
*
*
*/
function DisplayTorProxyConfig()
{
exec('cat '. RASPI_TORPROXY_CONFIG, $return);
exec('pidof tor | wc -l', $torproxystatus);
if ($torproxystatus[0] == 0) {
$status = '<div class="alert alert-warning alert-dismissable">TOR is not running
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button></div>';
} else {
$status = '<div class="alert alert-success alert-dismissable">TOR is running
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button></div>';
}
$arrConfig = array();
foreach ($return as $a) {
if ($a[0] != "#") {
$arrLine = explode(" ", $a) ;
$arrConfig[$arrLine[0]]=$arrLine[1];
}
}
?>
<div class="row">
<div class="col-lg-12">
<div class="card">
<div class="card-header"><i class="fa fa-eye-slash fa-fw"></i> Configure TOR proxy</div>
<div class="card-body">
<!-- Nav tabs -->
<ul class="nav nav-tabs">
<li class="nav-item"><a class="nav-link active" href="#basic" data-toggle="tab">Basic</a></li>
<li class="nav-item"><a class="nav-link" href="#relay" data-toggle="tab">Relay</a>
</li>
</ul>
<!-- Tab panes -->
<div class="tab-content">
<p><?php echo $status; ?></p>
<div class="tab-pane active" id="basic">
<h4>Basic settings</h4>
<form role="form" action="?page=save_hostapd_conf" method="POST">
<?php echo CSRFTokenFieldTag() ?>
<div class="row">
<div class="form-group col-md-6">
<label for="code">VirtualAddrNetwork</label>
<input type="text" class="form-control" name="virtualaddrnetwork" value="<?php echo htmlspecialchars($arrConfig['VirtualAddrNetwork'], ENT_QUOTES); ?>" />
</div>
</div>
<div class="row">
<div class="form-group col-md-6">
<label for="code">AutomapHostsSuffixes</label>
<input type="text" class="form-control" name="automaphostssuffixes" value="<?php echo htmlspecialchars($arrConfig['AutomapHostsSuffixes'], ENT_QUOTES); ?>" />
</div>
</div>
<div class="row">
<div class="form-group col-md-6">
<label for="code">AutomapHostsOnResolve</label>
<input type="text" class="form-control" name="automaphostsonresolve" value="<?php echo htmlspecialchars($arrConfig['AutomapHostsOnResolve'], ENT_QUOTES); ?>" />
</div>
</div>
<div class="row">
<div class="form-group col-md-6">
<label for="code">TransListenAddress</label>
<input type="text" class="form-control" name="translistenaddress" value="<?php echo htmlspecialchars($arrConfig['TransListenAddress'], ENT_QUOTES); ?>" />
</div>
</div>
<div class="row">
<div class="form-group col-md-6">
<label for="code">DNSPort</label>
<input type="text" class="form-control" name="dnsport" value="<?php echo htmlspecialchars($arrConfig['DNSPort'], ENT_QUOTES); ?>" />
</div>
</div>
<div class="row">
<div class="form-group col-md-6">
<label for="code">DNSListenAddress</label>
<input type="text" class="form-control" name="dnslistenaddress" value="<?php echo htmlspecialchars($arrConfig['DNSListenAddress'], ENT_QUOTES); ?>" />
</div>
</div>
</div>
<div class="tab-pane fade" id="relay">
<h4>Relay settings</h4>
<div class="row">
<div class="form-group col-md-6">
<label for="code">ORPort</label>
<input type="text" class="form-control" name="orport" value="<?php echo htmlspecialchars($arrConfig['ORPort'], ENT_QUOTES); ?>" />
</div>
</div>
<div class="row">
<div class="form-group col-md-6">
<label for="code">ORListenAddress</label>
<input type="text" class="form-control" name="orlistenaddress" value="<?php echo htmlspecialchars($arrConfig['ORListenAddress'], ENT_QUOTES); ?>" />
</div>
</div>
<div class="row">
<div class="form-group col-md-6">
<label for="code">Nickname</label>
<input type="text" class="form-control" name="nickname" value="<?php echo htmlspecialchars($arrConfig['Nickname'], ENT_QUOTES); ?>" />
</div>
</div>
<div class="row">
<div class="form-group col-md-6">
<label for="code">Address</label>
<input type="text" class="form-control" name="address" value="<?php echo htmlspecialchars($arrConfig['Address'], ENT_QUOTES); ?>" />
</div>
</div>
<div class="row">
<div class="form-group col-md-6">
<label for="code">RelayBandwidthRate</label>
<input type="text" class="form-control" name="relaybandwidthrate" value="<?php echo htmlspecialchars($arrConfig['RelayBandwidthRate'], ENT_QUOTES); ?>" />
</div>
</div>
<div class="row">
<div class="form-group col-md-6">
<label for="code">RelayBandwidthBurst</label>
<input type="text" class="form-control" name="relaybandwidthburst" value="<?php echo htmlspecialchars($arrConfig['RelayBandwidthBurst'], ENT_QUOTES); ?>" />
</div>
</div>
</div>
<input type="submit" class="btn btn-outline btn-primary" name="SaveTORProxySettings" value="Save settings" />
<?php
if ($torproxystatus[0] == 0) {
echo '<input type="submit" class="btn btn-success" name="StartTOR" value="Start TOR" />' , PHP_EOL;
} else {
echo '<input type="submit" class="btn btn-warning" name="StopTOR" value="Stop TOR" />' , PHP_EOL;
};
?>
</form>
</div><!-- /.tab-content -->
</div><!-- /.card-body -->
<div class="card-footer"> Information provided by tor</div>
</div><!-- /.col-lg-12 -->
</div><!-- /.row -->
<?php
}
/**
*
*
*/
function SaveTORAndVPNConfig()
{
if (isset($_POST['SaveOpenVPNSettings'])) {
// TODO
} elseif (isset($_POST['SaveTORProxySettings'])) {
// TODO
} elseif (isset($_POST['StartOpenVPN'])) {
echo "Attempting to start openvpn";
exec('sudo /etc/init.d/openvpn start', $return);
foreach ($return as $line) {
echo htmlspecialchars($line, ENT_QUOTES).'<br />' , PHP_EOL;
}
} elseif (isset($_POST['StopOpenVPN'])) {
echo "Attempting to stop openvpn";
exec('sudo /etc/init.d/openvpn stop', $return);
foreach ($return as $line) {
echo htmlspecialchars($line, ENT_QUOTES).'<br />' , PHP_EOL;
}
} elseif (isset($_POST['StartTOR'])) {
echo "Attempting to start TOR";
exec('sudo /etc/init.d/tor start', $return);
foreach ($return as $line) {
echo htmlspecialchars($line, ENT_QUOTES).'<br />' , PHP_EOL;
}
} elseif (isset($_POST['StopTOR'])) {
echo "Attempting to stop TOR";
exec('sudo /etc/init.d/tor stop', $return);
foreach ($return as $line) {
echo htmlspecialchars($line, ENT_QUOTES).'<br />' , PHP_EOL;
}
}
}
/**
* Renders a simple PHP template
*/

View file

@ -33,5 +33,32 @@ function DisplayOpenVPNConfig()
"status",
"openvpnStatus"
));
}
/**
*
*
*/
function SaveOpenVPNConfig()
{
if (isset($_POST['SaveOpenVPNSettings'])) {
// TODO
} elseif (isset($_POST['StartOpenVPN'])) {
echo "Attempting to start openvpn";
exec('sudo systemctl start openvpn.service', $return);
foreach ($return as $line) {
$status->addMessage($line, 'info');
}
} elseif (isset($_POST['StopOpenVPN'])) {
echo "Attempting to stop openvpn";
exec('sudo systemctl stop openvpn.service', $return);
foreach ($return as $line) {
$status->addMessage($line, 'info');
}
}
}
?>

52
includes/torproxy.php Normal file
View file

@ -0,0 +1,52 @@
<?php
include_once('includes/status_messages.php');
/**
*
* Manage Tor Proxy configuration
*
*/
function DisplayTorProxyConfig()
{
exec('cat '. RASPI_TORPROXY_CONFIG, $return);
exec('pidof tor | wc -l', $torproxystatus);
$arrConfig = array();
foreach ($return as $a) {
if ($a[0] != "#") {
$arrLine = explode(" ", $a) ;
$arrConfig[$arrLine[0]]=$arrLine[1];
}
}
echo renderTemplate("torproxy", compact(
"status",
"torproxystatus"
));
}
/**
*
*
*/
function SaveTORAndVPNConfig()
{
if (isset($_POST['SaveTORProxySettings'])) {
// TODO
} elseif (isset($_POST['StartTOR'])) {
echo "Attempting to start TOR";
exec('sudo systemctl start tor.service', $return);
foreach ($return as $line) {
$status->addMessage($line, 'info');
}
} elseif (isset($_POST['StopTOR'])) {
echo "Attempting to stop TOR";
exec('sudo systemctl stop tor.service', $return);
foreach ($return as $line) {
$status->addMessage($line, 'info');
}
}
}
?>

112
templates/torproxy.php Normal file
View file

@ -0,0 +1,112 @@
<div class="row">
<div class="col-lg-12">
<div class="card">
<div class="card-header"><i class="fa fa-eye-slash fa-fw"></i> Configure TOR proxy</div>
<div class="card-body">
<!-- Nav tabs -->
<ul class="nav nav-tabs">
<li class="nav-item"><a class="nav-link active" href="#basic" data-toggle="tab">Basic</a></li>
<li class="nav-item"><a class="nav-link" href="#relay" data-toggle="tab">Relay</a>
</li>
</ul>
<!-- Tab panes -->
<div class="tab-content">
<p><?php echo $status; ?></p>
<div class="tab-pane active" id="basic">
<h4>Basic settings</h4>
<form role="form" action="?page=save_hostapd_conf" method="POST">
<?php echo CSRFTokenFieldTag() ?>
<div class="row">
<div class="form-group col-md-6">
<label for="code">VirtualAddrNetwork</label>
<input type="text" class="form-control" name="virtualaddrnetwork" value="<?php echo htmlspecialchars($arrConfig['VirtualAddrNetwork'], ENT_QUOTES); ?>" />
</div>
</div>
<div class="row">
<div class="form-group col-md-6">
<label for="code">AutomapHostsSuffixes</label>
<input type="text" class="form-control" name="automaphostssuffixes" value="<?php echo htmlspecialchars($arrConfig['AutomapHostsSuffixes'], ENT_QUOTES); ?>" />
</div>
</div>
<div class="row">
<div class="form-group col-md-6">
<label for="code">AutomapHostsOnResolve</label>
<input type="text" class="form-control" name="automaphostsonresolve" value="<?php echo htmlspecialchars($arrConfig['AutomapHostsOnResolve'], ENT_QUOTES); ?>" />
</div>
</div>
<div class="row">
<div class="form-group col-md-6">
<label for="code">TransListenAddress</label>
<input type="text" class="form-control" name="translistenaddress" value="<?php echo htmlspecialchars($arrConfig['TransListenAddress'], ENT_QUOTES); ?>" />
</div>
</div>
<div class="row">
<div class="form-group col-md-6">
<label for="code">DNSPort</label>
<input type="text" class="form-control" name="dnsport" value="<?php echo htmlspecialchars($arrConfig['DNSPort'], ENT_QUOTES); ?>" />
</div>
</div>
<div class="row">
<div class="form-group col-md-6">
<label for="code">DNSListenAddress</label>
<input type="text" class="form-control" name="dnslistenaddress" value="<?php echo htmlspecialchars($arrConfig['DNSListenAddress'], ENT_QUOTES); ?>" />
</div>
</div>
</div>
<div class="tab-pane fade" id="relay">
<h4>Relay settings</h4>
<div class="row">
<div class="form-group col-md-6">
<label for="code">ORPort</label>
<input type="text" class="form-control" name="orport" value="<?php echo htmlspecialchars($arrConfig['ORPort'], ENT_QUOTES); ?>" />
</div>
</div>
<div class="row">
<div class="form-group col-md-6">
<label for="code">ORListenAddress</label>
<input type="text" class="form-control" name="orlistenaddress" value="<?php echo htmlspecialchars($arrConfig['ORListenAddress'], ENT_QUOTES); ?>" />
</div>
</div>
<div class="row">
<div class="form-group col-md-6">
<label for="code">Nickname</label>
<input type="text" class="form-control" name="nickname" value="<?php echo htmlspecialchars($arrConfig['Nickname'], ENT_QUOTES); ?>" />
</div>
</div>
<div class="row">
<div class="form-group col-md-6">
<label for="code">Address</label>
<input type="text" class="form-control" name="address" value="<?php echo htmlspecialchars($arrConfig['Address'], ENT_QUOTES); ?>" />
</div>
</div>
<div class="row">
<div class="form-group col-md-6">
<label for="code">RelayBandwidthRate</label>
<input type="text" class="form-control" name="relaybandwidthrate" value="<?php echo htmlspecialchars($arrConfig['RelayBandwidthRate'], ENT_QUOTES); ?>" />
</div>
</div>
<div class="row">
<div class="form-group col-md-6">
<label for="code">RelayBandwidthBurst</label>
<input type="text" class="form-control" name="relaybandwidthburst" value="<?php echo htmlspecialchars($arrConfig['RelayBandwidthBurst'], ENT_QUOTES); ?>" />
</div>
</div>
</div>
<input type="submit" class="btn btn-outline btn-primary" name="SaveTORProxySettings" value="Save settings" />
<?php
if ($torproxystatus[0] == 0) {
echo '<input type="submit" class="btn btn-success" name="StartTOR" value="Start TOR" />' , PHP_EOL;
} else {
echo '<input type="submit" class="btn btn-warning" name="StopTOR" value="Stop TOR" />' , PHP_EOL;
};
?>
</form>
</div><!-- /.tab-content -->
</div><!-- /.card-body -->
<div class="card-footer"> Information provided by tor</div>
</div><!-- /.col-lg-12 -->
</div><!-- /.row -->