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

[RFC] Add custom configuration parameter handling layer #390

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
12 changes: 12 additions & 0 deletions includes/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
define('RASPI_OPENVPN_CLIENT_CONFIG', '/etc/openvpn/client.conf');
define('RASPI_OPENVPN_SERVER_CONFIG', '/etc/openvpn/server.conf');
define('RASPI_TORPROXY_CONFIG', '/etc/tor/torrc');
define('RASPI_CUSTOM_CONFIG', '/etc/raspap/custom.ini');

// Optional services, set to true to enable.
define('RASPI_WIFICLIENT_ENABLED', true);
Expand All @@ -30,7 +31,18 @@
define('RASPI_CONFAUTH_ENABLED', true);
define('RASPI_CHANGETHEME_ENABLED', true);
define('RASPI_VNSTAT_ENABLED', true);
define('RASPI_CUSTOM_ENABLED', true);

// Locale settings
define('LOCALE_ROOT', 'locale');
define('LOCALE_DOMAIN', 'messages');


// Custom Configuration Parameters
define('RASPI_CUSTOM_FIELDS', array(
'Network Proxy Configuration' => array(
'host' => 'Network Proxy Host',
'port' => 'Network Proxy Port',
'user' => 'Network Proxy User',
'pass' => 'Network Proxy Pass'),
));
58 changes: 58 additions & 0 deletions includes/custom.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

include_once('includes/config.php');
include_once('includes/functions.php');
include_once('includes/status_messages.php');


function DisplayCustomConfig()
{
$status = new StatusMessages();
$data = parse_ini_file(RASPI_CUSTOM_CONFIG, true);

foreach (RASPI_CUSTOM_FIELDS as $title => $params){
$titlecode = str_replace(' ', '', $title);
if (isset($_POST[$titlecode])) {
foreach($params as $key => $desc){
$data[$titlecode][$key] = $_POST[$key];
}
write_php_ini($data, RASPI_CUSTOM_CONFIG);
}
}

foreach (RASPI_CUSTOM_FIELDS as $title => $params)
{
$titlecode = str_replace(' ', '', $title);
?>

<div class="row">
<div class="col-lg-12">
<div class="panel panel-primary">
<div class="panel-heading"><i class="fa fa-lock fa-fw"></i><?php echo _("$title"); ?></div>
<div class="panel-body">
<p><?php $status->showMessages(); ?></p>
<form role="form" action="?page=custom_conf" method="POST">
<?php echo CSRFTokenFieldTag() ?>

<?php foreach ($params as $key => $desc){ ?>
<div class="row">
<div class="form-group col-md-4">
<label for="$key"><?php echo _($desc); ?></label>
<input type="text" class="form-control" name="<?php echo _($key); ?>" value="<?php echo _($data[$titlecode][$key]); ?>"/>
</div>
</div>
<?php } ?>

<input type="submit" class="btn btn-outline btn-primary" name="<?php echo _($titlecode); ?>" value="<?php echo _("Save settings"); ?>" />
</form>
</div><!-- /.panel-body -->
</div><!-- /.panel-default -->
</div><!-- /.col-lg-12 -->
</div><!-- /.row -->

<?php
}
}
?>
s

9 changes: 9 additions & 0 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
include_once('includes/system.php');
include_once('includes/configure_client.php');
include_once('includes/networking.php');
include_once('includes/custom.php');
include_once('includes/themes.php');
include_once('includes/data_usage.php');
include_once('includes/about.php');
Expand Down Expand Up @@ -152,6 +153,11 @@
<?php if (RASPI_TORPROXY_ENABLED) : ?>
<li>
<a href="index.php?page=torproxy_conf"><i class="fa fa-eye-slash fa-fw"></i> <?php echo _("Configure TOR proxy"); ?></a>
</li>
<?php endif; ?>
<?php if (RASPI_CUSTOM_ENABLED) : ?>
<li>
<a href="index.php?page=custom_conf"><i class="fa fa-wrench fa-fw"></i> <?php echo _("Additional Configuration"); ?></a>
</li>
<?php endif; ?>
<?php if (RASPI_CONFAUTH_ENABLED) : ?>
Expand Down Expand Up @@ -216,6 +222,9 @@
case "torproxy_conf":
DisplayTorProxyConfig();
break;
case "custom_conf":
DisplayCustomConfig();
break;
case "auth_conf":
DisplayAuthConfig($config['admin_user'], $config['admin_pass']);
break;
Expand Down