Skip to content

Instantly share code, notes, and snippets.

@IJMacD
Created June 7, 2023 07:03
Show Gist options
  • Save IJMacD/bc0ae83fdbc6eb828d5a427909794ca1 to your computer and use it in GitHub Desktop.
Save IJMacD/bc0ae83fdbc6eb828d5a427909794ca1 to your computer and use it in GitHub Desktop.
Docker version of vnstat-php-frontend

vnstat-php-frontend Docker Image

This docker file uses a modern version of PHP (8.2.6) and a recent version of vnstat (2.6).

Updates to vnstat-php-frontend to support vnstat v2.0+ were done by @Baton34 (https://github.com/Baton34/vnstat-php-frontend)

Getting Started

  1. Copy Dockerfile and config.php to a local directory.

  2. Edit config.php to suit your interfaces and language etc.

  3. Build docker image. e.g.

    docker build --pull --rm -f "Dockerfile" -t vnstatphp:latest "."
    
  4. Run new container. e.g.

    docker run --rm -d -v /mnt/share/vnstat:/var/lib/vnstat -p 80:80 --name vnstatphp vnstatphp
    
<?php
//
// vnStat PHP frontend (c)2006-2010 Bjorge Dijkstra (bjd@jooz.net)
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
//
// see file COPYING or at http://www.gnu.org/licenses/gpl.html
// for more information.
//
// error_reporting(E_ALL | E_NOTICE);
// Error reporting must be turned off since there are lots of notices/warnings generated
// in newer versions of PHP. But check all constants etc. that vnstat-php-frontend expects
// have been defined before disabling error reporting.
error_reporting(0);
//
// configuration parameters
//
// edit these to reflect your particular situation
//
$locale = 'en_US.UTF-8';
$language = 'nl';
// Set local timezone
date_default_timezone_set("Europe/Amsterdam");
// list of network interfaces monitored by vnStat
$iface_list = array('eth0', 'sixxs');
//
// optional names for interfaces
// if there's no name set for an interface then the interface identifier
// will be displayed instead
//
$iface_title['eth0'] = 'Internal';
$iface_title['sixxs'] = 'SixXS IPv6';
//
// There are two possible sources for vnstat data. If the $vnstat_bin
// variable is set then vnstat is called directly from the PHP script
// to get the interface data.
//
// The other option is to periodically dump the vnstat interface data to
// a file (e.g. by a cronjob). In that case the $vnstat_bin variable
// must be cleared and set $data_dir to the location where the dumps
// are stored. Dumps must be named 'vnstat_dump_$iface'.
//
// You can generate vnstat dumps with the command:
// vnstat --dumpdb -i $iface > /path/to/data_dir/vnstat_dump_$iface
//
$vnstat_bin = '/usr/bin/vnstat';
$data_dir = './dumps';
// graphics format to use: svg or png
$graph_format='svg';
// preferred byte notation. null auto chooses. otherwise use one of
// 'TB','GB','MB','KB'
$byte_notation = null;
// Font to use for PNG graphs
define('GRAPH_FONT',dirname(__FILE__).'/VeraBd.ttf');
// Font to use for SVG graphs
define('SVG_FONT', 'Verdana');
// Default theme
define('DEFAULT_COLORSCHEME', 'light');
// SVG Depth scaling factor
define('SVG_DEPTH_SCALING', 1);
?>
FROM php:8.2.6-apache
WORKDIR /src
RUN apt-get update && apt-get install wget unzip vnstat -y && \
wget https://github.com/Baton34/vnstat-php-frontend/archive/refs/heads/master.zip && \
unzip master.zip && \
cp -r vnstat-php-frontend-master/* /var/www/html
COPY config.php /var/www/html
VOLUME [ "/var/lib/vnstat" ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment