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

darkstat - Hardcode to HTTP, add optional custom hostname/IP address configuration #285

Merged
merged 7 commits into from
Feb 2, 2017
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion net-mgmt/pfSense-pkg-darkstat/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

PORTNAME= pfSense-pkg-darkstat
PORTVERSION= 3.1.3
PORTREVISION= 2
PORTREVISION= 3
CATEGORIES= net-mgmt
MASTER_SITES= # empty
DISTFILES= # empty
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

require_once('config.inc');
require_once('interfaces.inc');
require_once('pfsense-utils.inc');
require_once('services.inc');
require_once('service-utils.inc');
require_once('util.inc');
Expand Down Expand Up @@ -165,6 +166,14 @@ function validate_input_darkstat($post, &$input_errors) {
$input_errors[] = gettext("The value for 'Web Interface Port' must not be the same port where pfSense WebGUI is running ($webgui_port).");
}
}
/* Validate Web Interface Hostname or IP */
if ($post['host']) {
if (!is_ipaddrv4($post['host']) && !is_hostname($post['host']) && !is_domain($post['host'])) {
$input_errors[] = gettext("The value for 'Web Interface Hostname' must be a valid IPv4 address, hostname or domain");
} elseif (is_ipaddrv4($post['host']) && !is_ipaddr_configured($post['host'])) {
$input_errors[] = gettext("Web Interface IP must be a valid, locally configured IPv4 address");
}
}
/* Validate Maximum Hosts Count */
if ($post['hostsmax']) {
if ($post['hostsmax'] < 1 || !is_numericint($post['hostsmax'])) {
Expand Down
30 changes: 30 additions & 0 deletions net-mgmt/pfSense-pkg-darkstat/files/usr/local/pkg/darkstat.xml
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,36 @@
<size>5</size>
<default_value>666</default_value>
</field>
<field>
<fielddescr>Web Interface Hostname or IP Address (Optional)</fielddescr>
<fieldname>host</fieldname>
<description>
<![CDATA[
Darkstat web interface can use HTTP only; HTTPS protocol is not supported.
If pfSense is <a href="/system_advanced_admin.php">configured to use HTTPS for webConfigurator</a>, it will force HTTPS via HSTS header.
That will make it impossible to use the webConfigurator FQDN to access darkstat web interface via HTTP.<br/>
Configure a custom hostname here for use with darkstat web interface to work around this limitation.<br />
<strong><span class="text-info">Hint: </span></strong>Use the IPv4 address of one of the 'Web Interface Binding' interfaces selected above
if you do not want want to deal with DNS configuration.<br/>
Click Info for details.
<div class="infoblock">
<strong><span class="text-danger">Important:</span></strong><br />
- You need to set up a 'Host Override' in <a href="/services_unbound.php">Services &gt; DNS Resolver</a>
or <a href="/services_dnsmasq.php">Services &gt; DNS Forwarder</a> (depending on which of these you are using)
in order to make use of the 'Web Interface Hostname' configured here.<br/>
- If your clients are not using the DNS server on pfSense for DNS resolution, you need to set up such 'Host Override' (A record or CNAME pointing to pfSense)
on the DNS server that the clients are using, or locally on the clients (using hosts file or similar) for 'Web Interface Hostname' to work for such clients.<br/><br/>
<strong><span class="text-info">Hint:</span></strong><br />
As an alternative, you may want to put the darkstat web interface behind haproxy.
You can use the <a href="https://doc.pfsense.org/index.php/Haproxy_package" target="_blank">haproxy package</a> for this purpose.
In that way, you can continue using HTTPS <em>and</em> the pfSense webConfigurator FQDN to aceess darkstat, and can even make it accessible via IPv6.<br/>
See the <a href="https://github.com/PiBa-NL/pfsense-haproxy-package-doc/wiki" target="_blank">HAProxy pfSense Package Howto</a> for usage instructions.
</div>
]]>
</description>
<type>input</type>
<size>30</size>
</field>
<field>
<fielddescr>Local Network Traffic</fielddescr>
<fieldname>localnetworkenable</fieldname>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,32 @@
require_once("config.inc");
global $config;

// Protocol and port
$proto = $config['system']['webgui']['protocol'];
// Port
if (is_array($config['installedpackages']['darkstat'])) {
$darkstat_config = $config['installedpackages']['darkstat']['config'][0];
} else {
$darkstat_config = array();
}
$port= $darkstat_config['port'] ?: '666';
$port = $darkstat_config['port'] ?: '666';
$host = $darkstat_config['host'] ?: '';

// Hostname
$httphost = getenv("HTTP_HOST");
$colonpos = strpos($httphost, ":");
if ($colonpos) {
$baseurl = substr($httphost, 0, $colonpos);
if (empty($host)) {
// Get hostname automagically
$httphost = getenv("HTTP_HOST");
$colonpos = strpos($httphost, ":");
if ($colonpos) {
$baseurl = substr($httphost, 0, $colonpos);
} else {
$baseurl = $httphost;
}
} else {
$baseurl = $httphost;
// Use the configured 'Web Interface Hostname'
$baseurl = $host;
}

// Final redirect URL
$url = "{$proto}://{$baseurl}:{$port}";
$url = "http://{$baseurl}:{$port}";
header("Location: {$url}");
exit;

?>