initial commit of file from CVS for smeserver-bandwidthd on Sat Sep 7 20:10:36 AEST 2024

This commit is contained in:
Trevor Batley
2024-09-07 20:10:36 +10:00
parent 39d69687d3
commit bd26bff825
36 changed files with 707 additions and 2 deletions

View File

@@ -0,0 +1 @@
5 5 * * 4 root /bin/sh /usr/share/doc/bandwidthd-2.0.1.1/phphtdocs/bd_mysql_purge.sh |mysql `/sbin/e-smith/db configuration getprop bandwidthd DbName`|grep -vE '(Msg_text|already up to date|status.*OK)'

View File

@@ -0,0 +1 @@
0 0 * * * root /bin/kill -HUP `cat /var/run/bandwidthd.pid`

View File

@@ -0,0 +1 @@
reserved

View File

@@ -0,0 +1 @@
bandwidthd

View File

@@ -0,0 +1 @@
bandwidthd

View File

@@ -0,0 +1 @@
bandwidthd

View File

@@ -0,0 +1 @@
enabled

View File

@@ -0,0 +1 @@
service

View File

@@ -0,0 +1 @@
private

View File

@@ -0,0 +1,16 @@
{
use MIME::Base64 qw(encode_base64);
my $rec = $DB->get('bandwidthd') || $DB->new_record('bandwidthd', {type => 'service'});
if (my $grapCutofff = $DB->get_prop_and_delete('bandwidthd', 'grapCutofff')) {
$rec->merge_props('grapCutoff', $grapCutofff);
}
my $pw = $rec->prop('DbPassword');
return "" if $pw;
$pw = MIME::Base64::encode(int( (1000000000000000) * rand() ));
chomp($pw);
$rec->set_prop('DbPassword', "$pw" );
}

View File

@@ -0,0 +1,2 @@
#/bin/sh
systemctl enable bandwidthd.service

View File

@@ -0,0 +1,2 @@
#!/bin/sh
systemctl start bandwidthd.service

View File

@@ -0,0 +1,3 @@
PERMS="0640"
UID="root"
GID="www"

View File

@@ -0,0 +1 @@
PERMS=0750

View File

@@ -0,0 +1,3 @@
PERMS="0640"
UID="admin"
GID="www"

View File

@@ -0,0 +1,7 @@
####################################################
# Bandwidthd.conf
#
# Commented out options are here to provide
# documentation and represent defaults

View File

@@ -0,0 +1,73 @@
# Subnets to collect statistics on. Traffic that
# matches none of these subnets will be ignored.
# Syntax is either IP Subnet Mask or CIDR
{
# here we add list of local networks
use esmith::NetworksDB;
my $ndb = esmith::NetworksDB->open_ro();
$localAccess = $ndb->local_access_spec();
$localAccess =~ s/ /,/g;
$localAccess =~ s:/: :g;
my @LocalAccess = split(/,/, $localAccess);
foreach $rec (@LocalAccess)
{
next if $rec eq "127.0.0.1";
$rec= ($rec=~ /[.\d]+ [.\d]+/ )? $rec : "$rec 255.255.255.255";
$OUT .= "subnet $rec \n";
}
#$OUT .= "subnet $localAccess \n";
# subnet for external access
my $validFrom = ${'httpd-admin'}{'ValidFrom'} || "disabled";
if ($validFrom ne "disabled")
{
#$validFrom =~ s/,/ /g;
$validFrom =~ s:/: :g;
#$externalSSLAccess = $validFrom;
my @externalSSLAccess = split(/,/, $validFrom);
foreach $rec (@externalSSLAccess)
{
$OUT .= "subnet $rec \n";
}
}
# subnet of external interface
my $externalNet = ${'ExternalInterface'}{'IPAddress'};
if (defined $externalNet )
{
#$externalNet =~ s/[0-9]+$)/0/g;
$OUT .= "subnet ". ${'ExternalInterface'}{'IPAddress'} ." ". ${'ExternalInterface'}{'Netmask'} ." \n";
}
# subnet of adsl peer if(bandwidthd=service|remotePeers|enabled)
# also manually added (bandwidthd=service|subnet|172.16.0.0/12,192.168.0.0/16)
my $subnet = $bandwidthd{'subnet'} || "disabled";
if ($subnet ne "disabled")
{
#$validFrom =~ s/,/ /g;
#$subnet =~ s:/: :g;# here we ask to have a syntax with /24 so keeping the /
#$externalSSLAccess = $validFrom;
@externalSSLAccess = split(/,/, $subnet);
foreach $rec (@externalSSLAccess)
{
$OUT .= "subnet $rec \n";
}
}
}

View File

@@ -0,0 +1,11 @@
# Device to listen on
# Bandwidthd listens on the first device it detects
# by default. Run "bandwidthd -l" for a list of
# devices.
#dev "eth0"
{
# dev "any" unless $device
my $device = $bandwidthd{'device'} ||"any";
$OUT .= "dev \"$device\"\n";
}

View File

@@ -0,0 +1,72 @@
###################################################
# Options that don't usually get changed
# An interval is 2.5 minutes, this is how many
# intervals to skip before doing a graphing run
#skip_intervals 0
{
my $interval = $bandwidthd{'skipInterval'} || "0";
$OUT .= "skip_intervals $interval\n"
}
# Graph cutoff is how many k must be transfered by an
# ip before we bother to graph it
#graph_cutoff 1024
{
my $cutoff = $bandwidthd{'grapCutoff'} || "1024";
$OUT .= "graph_cutoff $cutoff\n"
}
#Put interface in promiscuous mode to score to traffic
#that may not be routing through the host machine.
#promiscuous true
{
my $promiscuous = $bandwidthd{'promiscuous'} || "false";
$OUT .= "promiscuous $promiscuous\n"
}
#Log data to cdf file htdocs/log.cdf
#output_cdf false
{
my $output_cdf = $bandwidthd{'output_cdf'} || "false";
$OUT .= "output_cdf $output_cdf\n"
}
#Read back the cdf file on startup
#recover_cdf false
{
my $recover_cdf = $bandwidthd{'recover_cdf'} || "false";
$OUT .= "recover_cdf $recover_cdf\n"
}
#Libpcap format filter string used to control what bandwidthd see's
#Please always include "ip" in the string to avoid strange problems
#filter "ip"
### use a template custom for this one !
#Draw Graphs - This default to true to graph the traffic bandwidthd is recording
#Usually set this to false if you only want cdf output or
#you are using the database output option. Bandwidthd will use very little
#ram and cpu if this is set to false.
#graph true
{
my $graph = $bandwidthd{'graph'} || "true";
$OUT .= "graph $graph\n"
}
#Set META REFRESH seconds (default 150, use 0 to disable).
#meta_refresh 150
{
my $meta_refresh = $bandwidthd{'meta_refresh'} || "150";
$OUT .= "meta_refresh $meta_refresh\n"
}

View File

@@ -0,0 +1,8 @@
# Arbitrary sensor name, I recommend the sensors fully qualified domain
# name
#sensor_id "sensor1"
{
my $sensorname = "$SystemName.$DomainName";
my $sensorid = $bandwidthd{'sensor'} || $sensorname ;
$OUT .= "sensor_id \"$sensorid\"\n";
}

View File

@@ -0,0 +1,7 @@
# Database type, possible values, pgsql, mysql or none
#output_database mysql
{
my $dbtype = $bandwidthd{'DbType'} || "mysql";
$OUT .= "output_database $dbtype\n";
}

View File

@@ -0,0 +1,15 @@
# PostgreSQL
# Standard postgres connect string, just like php, see postgres docs for
# details
#pgsql_connect_string "user = someuser dbname = mydb host = databaseserver.com"
{
$OUT .="\n";
my $dbtype = $bandwidthd{'DbType'} || "mysql";
my $dbhost = $bandwidthd{'Dbhost'} || "localhost";
$OUT .= "pgsql_connect_string \"user = ".$bandwidthd{'DbUser'}." password = ". $bandwidthd{'DbPassword'} ." dbname = ".$bandwidthd{'DbName'}." host = $dbhost\";\n"
unless $dbtype eq "mysql";
}

View File

@@ -0,0 +1,12 @@
# SME Server Settings MYSQL DB
# MySQL
{
my $dbhost = $bandwidthd{'Dbhost'} || "localhost";
my $dbport = $bandwidthd{'Dbport'} || "0";
$OUT .= "mysql_host \"". $dbhost ."\"\n";
$OUT .= "mysql_dbname \"". $bandwidthd{'DbName'} ."\"\n";
$OUT .= "mysql_user \"". $bandwidthd{'DbUser'} ."\"\n";
$OUT .= "mysql_pass \"". $bandwidthd{'DbPassword'} ."\"\n";
$OUT .= "# Port 0 means, that the default port is used\n";
$OUT .= "mysql_port ". $dbport ."\n";
}

View File

@@ -0,0 +1,21 @@
{
my $db = $bandwidthd{DbName} || 'bandwidthd';
my $user = $bandwidthd{DbUser} || 'bandwidthd';
my $pass = $bandwidthd{DbPassword} || 'changemebandwidthd';
$OUT .= <<END
#! /bin/sh
if [ -d /var/lib/mysql/$db ]; then
exit
fi
/usr/bin/mysql <<EOF
CREATE DATABASE $db DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
use $db;
#Insert application specific command to create database structure
use mysql;
GRANT ALL PRIVILEGES ON $db.* TO $user\@localhost
IDENTIFIED BY '$pass';
flush privileges;
EOF
END
}

View File

@@ -0,0 +1,117 @@
{
my $status = $bandwidthd{'status'} || "disabled";
return " # bandwidthd is disabled in this VirtualHost"
unless $status eq 'enabled';
$OUT = "";
my $pass = 0;
my $allow = "ip $localAccess";
my $name = $bandwidthd{'Name'} || 'Application bandwidthd Login';
my $webinterface = $bandwidthd{'webinterface'} || 'both';
$version = "74"; #temp bjr 30nov2020
for ('exit-if-none')
{
if ($bandwidthd{'webaccess'})
{
if ($bandwidthd{'webaccess'} eq 'private')
{
$allow = "ip $localAccess $externalSSLAccess";
$pass = 1;
}
elsif ($bandwidthd{'webaccess'} eq 'local')
{
$allow = "ip $localAccess $externalSSLAccess";
$pass = 0;
}
elsif ($bandwidthd{'webaccess'} eq 'public')
{
$allow = 'all granted';
$pass = 1;
}
elsif ($bandwidthd{'webaccess'} eq 'global')
{
$allow = 'all granted';
$pass = 0;
}
}
if ($webinterface eq "both" || $webinterface eq "html")
{
$OUT .= "#------------------------------------------------------------\n";
$OUT .= "# bandwidthd HTML- $name\n";
$OUT .= "#------------------------------------------------------------\n";
if (exists $bandwidthd{'URL'} && $webinterface eq "html")
{ $OUT .= "Alias /$bandwidthd{'URL'} /var/www/bandwidthd/htdocs\n"; }
if ( $webinterface eq "html")
{
$OUT .= "Alias /bandwidthd /var/www/bandwidthd/htdocs\n";
}
$OUT .= "Alias /bandwidthd-static /var/www/bandwidthd/htdocs\n";
$OUT .= "\n";
$OUT .= "<Directory /var/www/bandwidthd/htdocs>\n";
$OUT .= " AddType application/x-httpd-php .php .conf\n";
$OUT .= "<FilesMatch \.php\$\>\n";
$OUT .= "SetHandler \"proxy:unix:/var/run/php-fpm/php$version.sock|fcgi://localhost\"\n";
$OUT .= "</FilesMatch>\n";
$OUT .= " Options None\n";
if ($pass)
{
$OUT .= " AuthName \"$name\"\n";
$OUT .= " AuthBasicProvider external\n";
$OUT .= " AuthType Basic\n";
$OUT .= " AuthExternal pwauth\n";
}
$OUT .= " <RequireAll>\n";
$OUT .= " require user admin\n" if ($pass);
$OUT .= " Require $allow\n";
$OUT .= " </RequireAll>\n";
$OUT .= "</Directory>\n";
}
if ($webinterface eq "both" || $webinterface eq "php")
{
$OUT .= "#------------------------------------------------------------\n";
$OUT .= "# bandwidthd PHP- $name\n";
$OUT .= "#------------------------------------------------------------\n";
if (exists $bandwidthd{'URL'} && $webinterface ne "html" )
{ $OUT .= "Alias /$bandwidthd{'URL'} /var/www/bandwidthd/phphtdocs\n"; }
$OUT .= "Alias /bandwidthd /var/www/bandwidthd/phphtdocs\n";
$OUT .= "Alias /bandwidthd-sql /var/www/bandwidthd/phphtdocs\n";
$OUT .= "\n";
$OUT .= "<Directory /var/www/bandwidthd/phphtdocs>\n";
$OUT .= "<FilesMatch \.php\$\>\n";
$OUT .= "SetHandler \"proxy:unix:/var/run/php-fpm/php$version.sock|fcgi://localhost\"\n";
$OUT .= "</FilesMatch>\n";
$OUT .= " SSLRequireSSL\n";
$OUT .= " Options None\n";
if ($pass)
{
$OUT .= " AuthName \"$name\"\n";
$OUT .= " AuthBasicProvider external\n";
$OUT .= " AuthType Basic\n";
$OUT .= " AuthExternal pwauth\n";
}
$OUT .= " <RequireAll>\n";
$OUT .= " require user admin\n" if ($pass);
$OUT .= " Require $allow\n";
$OUT .= " </RequireAll>\n";
$OUT .= "</Directory>\n";
}
}
}

View File

@@ -0,0 +1,16 @@
{
my $status = $bandwidthd{'status'} || "disabled";
return " # bandwidthd is disabled in this VirtualHost"
unless $status eq 'enabled';
$haveSSL = (exists ${modSSL}{status} and ${modSSL}{status} eq "enabled") ? 'yes' : 'no';
if (($port ne "443") && ($haveSSL eq 'yes') )
{
$OUT .= "RewriteEngine on\n";
$OUT .= " RewriteRule ^/bandwidthd(/.*|\$) https://%{HTTP_HOST}/bandwidthd\$1 [L,R]\n";
$OUT .= " RewriteRule ^/bandwidthd-php(/.*|\$) https://%{HTTP_HOST}/bandwidthd-php\$1 [L,R]\n";
$OUT .= " RewriteRule ^/bandwidthd-static(/.*|\$) https://%{HTTP_HOST}/bandwidthd-static\$1 [L,R]\n";
if (exists $bandwidthd{'URL'})
{ $OUT .= " RewriteRule ^/$bandwidthd{'URL'} https://%{HTTP_HOST}/$bandwidthd{'URL'}\$1 [L,R]\n"; }
}
}

View File

@@ -0,0 +1 @@
{ push( @list, 'bandwidthd'); $OUT ="";}

View File

@@ -0,0 +1,45 @@
{
my $width = $bandwidthd{'width'} || "900";
my $height = $bandwidthd{'height'} || "256";
my $interval = $bandwidthd{'interval'} || "INT_DAILY";
$OUT .= "define('DFLT_WIDTH', $width);\n";
$OUT .= "define('DFLT_HEIGHT', $height);\n";
$OUT .= "define('DFLT_INTERVAL', $interval);\n";
}
// Select type of database you are using
// Possible values are DB_PGSQL and DB_MYSQL
{
my $dbtype = $bandwidthd{'DbType'} || "mysql";
if ( $dbtype eq "mysql")
{$dbtype = "DB_MYSQL";}
else
{$dbtype = "DB_PGSQL";}
$OUT .= "\$dbtype = $dbtype;\n";
}
// Configuration for PostgreSQL
{
$OUT .= "\n";
my $dbtype = $bandwidthd{'DbType'} || "mysql";
my $dbhost = $bandwidthd{'Dbhost'} || "localhost";
$OUT .= "\$pgsql_connect_string = \"user = ".$bandwidthd{'DbUser'}." password = ". $bandwidthd{'DbPassword'} ." dbname = ".$bandwidthd{'DbName'}." host = $dbhost\";\n"
unless $dbtype eq "mysql";
}
// Configuration for MySQL
// You can specify port after semicolon, for example "localhost:4067"
{
my $dbhost = $bandwidthd{'Dbhost'} || "localhost";
$OUT .= "\$mysql_host = \"$dbhost\";\n";
$OUT .= "\$mysql_user = \"".$bandwidthd{'DbUser'}."\";\n";
$OUT .= "\$mysql_pass = \"". $bandwidthd{'DbPassword'} ."\";\n";
$OUT .= "\$mysql_dbname = \"".$bandwidthd{'DbName'}."\";\n";
}

View File

@@ -0,0 +1,31 @@
#!/usr/bin/perl
#----------------------------------------------------------------------
# heading : Administration
# description : Bandwidthd
# navigation : 4000 4200
#----------------------------------------------------------------------
use strict;
use CGI':all';
use CGI::Carp qw(fatalsToBrowser);
BEGIN
{
$ENV {'PATH'} = '/bin:/usr/bin:/sbin';
$ENV {'SHELL'} = '/bin/bash';
delete $ENV {'ENV'};
}
my $q = new CGI;
my $content="0; url=https://".$ENV {'HTTP_X_FORWARDED_HOST'}."/bandwidthd";
$q->default_dtd('-//W3C//DTD XHTML 1.0 Transitional//EN');
print $q->header ('text/html');
print $q->start_html (-head=>meta({-http_equiv=>'refresh', -content=>$content}));
print $q->end_html;