diff options
author | Renato Botelho <renato@netgate.com> | 2015-08-25 08:08:24 -0300 |
---|---|---|
committer | Renato Botelho <renato@netgate.com> | 2015-08-25 14:49:54 -0300 |
commit | 46bc6e545a17e77202aaf01ec0cd8d5a46567525 (patch) | |
tree | 32d18dda436ec739c67c489ceb771e8629cd926f /src/usr/local/bin | |
parent | 4d9801c2dbd2b3e54a39578ee62b93af66607227 (diff) | |
download | pfsense-46bc6e545a17e77202aaf01ec0cd8d5a46567525.zip pfsense-46bc6e545a17e77202aaf01ec0cd8d5a46567525.tar.gz |
Move main pfSense content to src/
Diffstat (limited to 'src/usr/local/bin')
-rwxr-xr-x | src/usr/local/bin/3gstats.php | 83 | ||||
-rwxr-xr-x | src/usr/local/bin/beep.sh | 43 | ||||
-rw-r--r-- | src/usr/local/bin/captiveportal_gather_stats.php | 115 | ||||
-rwxr-xr-x | src/usr/local/bin/easyrule | 147 | ||||
-rwxr-xr-x | src/usr/local/bin/filterparser.php | 58 | ||||
-rwxr-xr-x | src/usr/local/bin/mail.php | 25 | ||||
-rwxr-xr-x | src/usr/local/bin/ping_hosts.sh | 134 | ||||
-rwxr-xr-x | src/usr/local/bin/runmsntp.sh | 12 | ||||
-rwxr-xr-x | src/usr/local/bin/slowdownpipe.sh | 9 | ||||
-rwxr-xr-x | src/usr/local/bin/viconfig | 3 |
10 files changed, 629 insertions, 0 deletions
diff --git a/src/usr/local/bin/3gstats.php b/src/usr/local/bin/3gstats.php new file mode 100755 index 0000000..cc385fc --- /dev/null +++ b/src/usr/local/bin/3gstats.php @@ -0,0 +1,83 @@ +#!/usr/local/bin/php-cgi -f +<?php + +ini_set("max_execution_time", "0"); + +if(empty($argv[1])) { + echo "No modem device given \n"; + exit(0); +} + +/* Huawei example */ +$device = "/dev/{$argv[1]}"; +$statfile = "/tmp/3gstats.{$argv[2]}"; +/* mode is a comma separated value, thus submode is born */ +$header = "#seconds,rssi,mode,submode,upstream,downstream,sentbytes,receivedbyts,bwupstream,bwdownstream,simstate,service\n"; + +$i = 0; + +$record = array(); +$handle = fopen($device, "r"); +if(! $handle) { + echo "Can not open modem stats device\n"; + exit(1); +} + +$record['time'] = 0; +$record['rssi'] = 0; +$record['mode'] = "0,0"; +$record['upstream'] = 0; +$record['downstream'] = 0; +$record['sent'] = 0; +$record['received'] = 0; +$record['bwupstream'] = 0; +$record['bwdownstream'] = 0; +$record['simstate'] = 0; +$record['service'] = 0; + +while (true) { + $string = ""; + $string = fgets($handle, 256); + + $elements = array(); + $elements = explode(':', $string); + $elements[0] = trim($elements[0]); + $elements[1] = trim($elements[1]); + + switch ($elements[0]) { + case "^MODE": + $record['mode'] = $elements[1]; + break; + case "^SRVST": + $record['service'] = $elements[1]; + break; + case "^SIMST": + $record['simstate'] = $elements[1]; + break; + case "^RSSI": + $record['rssi'] = $elements[1]; + break; + case "^DSFLOWRPT": + $items = array(); + $items = explode(',', $elements[1]); + $record['time'] = hexdec($items[0]); + $record['upstream'] = round((floatval(hexdec($items[1])) * 8) /1024); + $record['downstream'] = round((floatval(hexdec($items[2])) * 8) /1024); + $record['sent'] = hexdec($items[3]); + $record['received'] = hexdec($items[4]); + $record['bwupstream'] = round((floatval(hexdec($items[5])) * 8) /1024); + $record['bwdownstream'] = round((floatval(hexdec($items[6])) * 8) /1024); + break; + } + + if ($i > 10) { + $csv = $header; + $csv .= implode(",", $record); + $csv .= "\n"; + file_put_contents($statfile, $csv); + $i = 0; + } + $i++; +} +fclose($handle); +?> diff --git a/src/usr/local/bin/beep.sh b/src/usr/local/bin/beep.sh new file mode 100755 index 0000000..ed9382d --- /dev/null +++ b/src/usr/local/bin/beep.sh @@ -0,0 +1,43 @@ +#!/bin/sh + + +BEEP=`/usr/bin/grep -c disablebeep /conf/config.xml` +if [ $BEEP -gt 0 ]; then + exit; +fi + +# Standard note length +NOTELENGTH="25" + +# this is super annoying in VMware, exit if in VMware +if [ -f /var/log/dmesg.boot ]; then + VMWCOUNT=`/usr/bin/grep -c VMware /var/log/dmesg.boot` + if [ $VMWCOUNT -gt 0 ]; then + exit; + fi +fi + +# Check for different HZ +if [ -f /boot/loader.conf ]; then + HZ=`/usr/bin/grep -c kern.hz /boot/loader.conf` + if [ "$HZ" = "1" ]; then + NOTELENGTH="10" + fi +fi + +if [ -c "/dev/speaker" ]; then + if [ "$1" = "start" ]; then + /usr/local/bin/beep -p 500 $NOTELENGTH + /usr/local/bin/beep -p 400 $NOTELENGTH + /usr/local/bin/beep -p 600 $NOTELENGTH + /usr/local/bin/beep -p 800 $NOTELENGTH + /usr/local/bin/beep -p 800 $NOTELENGTH + fi + if [ "$1" = "stop" ]; then + /usr/local/bin/beep -p 600 $NOTELENGTH + /usr/local/bin/beep -p 800 $NOTELENGTH + /usr/local/bin/beep -p 500 $NOTELENGTH + /usr/local/bin/beep -p 400 $NOTELENGTH + /usr/local/bin/beep -p 400 $NOTELENGTH + fi +fi diff --git a/src/usr/local/bin/captiveportal_gather_stats.php b/src/usr/local/bin/captiveportal_gather_stats.php new file mode 100644 index 0000000..23d6b5d --- /dev/null +++ b/src/usr/local/bin/captiveportal_gather_stats.php @@ -0,0 +1,115 @@ +#!/usr/local/bin/php-cgi -q +<?php +/* $Id$ */ +/* + captiveportal_gather_stats.php + Copyright (C) 2011 Warren Baker + Copyright (C) 2013-2015 Electric Sheep Fencing, LP + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, + OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + POSSIBILITY OF SUCH DAMAGE. +*/ + +require_once("functions.inc"); +require_once("captiveportal.inc"); +require_once("util.inc"); + +global $cpzone; + +$cpzone = $argv[1]; +$type = $argv[2]; + +/* read in captive portal db */ +$cpdb = captiveportal_read_db(); + +/* determine number of logged in users */ +$no_users = count($cpdb); +$concurrent_users = $no_users; + +/* set initial user count to zero */ +$current_user_count = 0; + +/* tmp file to use to store old data (per interface)*/ +$tmpfile = "{$g['vardb_path']}/captiveportal_online_users"; + +if (empty($type)) { + exit; +} + +/* echo the rrd required syntax */ +echo "N:"; +$result = "NaN"; + +if ($type == "loggedin") { + + /* Find out the previous user timestamp + * so we can determine the difference between the current + * and previous user count. If the file is empty return a 0. + */ + $fd = @fopen($tmpfile, "r"); + if ($fd) { + while (!feof($fd)) { + $line = trim(fgets($fd)); + if ($line) { + $previous_user_timestamp = $line; + } else { + $previous_user_timestamp = 0; + } + } + } else { + $previous_user_timestamp = 0; + } + @fclose($fd); + + foreach ($cpdb as $user) { + $user_ip = $user[2]; + // Record the timestamp + $timestamp = $user[0]; + if ($timestamp > $previous_user_timestamp) { + $current_user_count = $current_user_count + 1; + } + } + + // Write out the latest timestamp but not if it is empty + if (!empty($timestamp)) { + $fd = @fopen($tmpfile, "w"); + if ($fd) { + fwrite($fd, $timestamp); + } + @fclose($fd); + } + + /* If $timestamp is less than or equal to previous_user_timestamp return 0, + * as we only want the 'X' number of users logged in since last RRD poll. + */ + if ($timestamp <= $previous_user_timestamp) { + $result = 0; + } else { + $result = $current_user_count; + } +} elseif ($type == "concurrent") { + $result = $no_users; +} + +echo "$result"; + +?> diff --git a/src/usr/local/bin/easyrule b/src/usr/local/bin/easyrule new file mode 100755 index 0000000..8461a7a --- /dev/null +++ b/src/usr/local/bin/easyrule @@ -0,0 +1,147 @@ +#!/usr/local/bin/php-cgi -q +<?php +/* + easyrule CLI Program + + Copyright (C) 2010 Jim Pingle (jpingle@gmail.com) + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, + OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + POSSIBILITY OF SUCH DAMAGE. +*/ + +require_once("pfsense-utils.inc"); +require_once("easyrule.inc"); +require_once("filter.inc"); +require_once("shaper.inc"); + +$message = ""; +$specialsrcdst = explode(" ", "any pptp pppoe l2tp openvpn"); +$ifdisp = get_configured_interface_with_descr(); +foreach ($ifdisp as $kif => $kdescr) { + $specialsrcdst[] = "{$kif}"; + $specialsrcdst[] = "{$kif}ip"; +} + +/* Borrow this function from guiconfig.inc since we can't include it for use at the CLI + + - Maybe these need to be moved to util.inc or pfsense-utils.inc? + +*/ +function pconfig_to_address(&$adr, $padr, $pmask, $pnot=false, $pbeginport=0, $pendport=0) { + + $adr = array(); + + if ($padr == "any") { + $adr['any'] = true; + } else if (is_specialnet($padr)) { + $adr['network'] = $padr; + } else { + $adr['address'] = $padr; + if ($pmask != 32) { + $adr['address'] .= "/" . $pmask; + } + } + + if ($pnot) { + $adr['not'] = true; + } else { + unset($adr['not']); + } + + if (($pbeginport != 0) && ($pbeginport != "any")) { + if ($pbeginport != $pendport) { + $adr['port'] = $pbeginport . "-" . $pendport; + } else { + $adr['port'] = $pbeginport; + } + } + + if (is_alias($pbeginport)) { + $adr['port'] = $pbeginport; + } +} + +/* Borrow this one from guiconfig.inc also */ +function is_specialnet($net) { + global $specialsrcdst; + + if (!$net) { + return false; + } + if (in_array($net, $specialsrcdst)) { + return true; + } else { + return false; + } +} + + +if (($argc > 1) && !empty($argv[1])) { + + /* Automagically derive an alternate alias name from the scripts name + * This allows for using alternate alias lists with just a symlink */ + if (($alias = basename($argv[0])) != 'easyrule') { + $blockaliasname = ucfirst($alias).'Rules'; + } + + $message = ""; + switch ($argv[1]) { + case 'block': + $message = easyrule_parse_block($argv[2], $argv[3]); + break; + case 'unblock': + $message = easyrule_parse_unblock($argv[2], $argv[3]); + break; + case 'showblock': + $message = easyrule_parse_getblock($argv[2]); + break; + case 'pass': + $message = easyrule_parse_pass($argv[2], $argv[3], $argv[4], $argv[5], $argv[6]); + break; + } + echo $message . "\n"; +} else { + // Print usage: + echo "usage:\n"; + echo " Blocking only requires an IP to block, block rules can be shown with showblock and revoked using unblock\n"; + echo " " . basename($argv[0]) . " block <interface> <source IP>\n"; + echo "\n"; + echo " Passing requires more detail, as it must be as specific as possible. The destination port is optional if you're using a protocol without a port (e.g. ICMP, OSPF, etc).\n"; + echo " " . basename($argv[0]) . " pass <interface> <protocol> <source IP> <destination ip> [destination port]\n"; + echo "\n"; + echo " Block example:\n"; + echo " " . basename($argv[0]) . " block wan 1.2.3.4\n"; + echo "\n"; + echo " Show active blocks example:\n"; + echo " " . basename($argv[0]) . " showblock wan\n"; + echo "\n"; + echo " Unblock example:\n"; + echo " " . basename($argv[0]) . " unblock wan 1.2.3.4\n"; + echo "\n"; + echo " Pass example (protocol with port):\n"; + echo " " . basename($argv[0]) . " pass wan tcp 1.2.3.4 192.168.0.4 80\n"; + echo "\n"; + echo " Pass example (protocol without port):\n"; + echo " " . basename($argv[0]) . " pass wan icmp 1.2.3.4 192.168.0.4\n"; + echo "\n"; +} +?> diff --git a/src/usr/local/bin/filterparser.php b/src/usr/local/bin/filterparser.php new file mode 100755 index 0000000..fa60262 --- /dev/null +++ b/src/usr/local/bin/filterparser.php @@ -0,0 +1,58 @@ +#!/usr/local/bin/php-cgi -q +<?php +/* $Id$ */ +/* + filterparser.php + part of pfSesne by Scott Ullrich + originally based on m0n0wall (http://m0n0.ch/wall) + + Copyright (C) 2009 Jim Pingle <myfirstname>@<mylastname>.org + Copyright (C) 2013-2015 Electric Sheep Fencing, LP + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, + OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + POSSIBILITY OF SUCH DAMAGE. + + A quick CLI log parser. + Examples: + clog /var/log/filter.log | tail -50 | /usr/local/www/filterparser.php + clog -f /var/log/filter.log | /usr/local/www/filterparser.php +*/ +/* + pfSense_MODULE: logs +*/ + +include_once("functions.inc"); +include_once("filter_log.inc"); + +$log = fopen("php://stdin", "r"); +$lastline = ""; +while (!feof($log)) { + $line = fgets($log); + $line = rtrim($line); + $flent = parse_filter_line(trim($line)); + if ($flent != "") { + $flags = (($flent['proto'] == "TCP") && !empty($flent['tcpflags'])) ? ":" . $flent['tcpflags'] : ""; + echo "{$flent['time']} {$flent['act']} {$flent['realint']} {$flent['proto']}{$flags} {$flent['src']} {$flent['dst']}\n"; + $flent = ""; + } +} +fclose($log); ?> diff --git a/src/usr/local/bin/mail.php b/src/usr/local/bin/mail.php new file mode 100755 index 0000000..130d9e0 --- /dev/null +++ b/src/usr/local/bin/mail.php @@ -0,0 +1,25 @@ +#!/usr/local/bin/php-cgi -q +<?php +require_once("config.inc"); +require_once("globals.inc"); +require_once("notices.inc"); +$options = getopt("s::"); + +$message = ""; + +if ($options['s'] <> "") { + $subject = $options['s']; +} + + +$in = file("php://stdin"); +foreach ($in as $line){ + $message .= "$line"; +} + +if (!empty($subject)) { + send_smtp_message($message, $subject); +} else { + send_smtp_message($message); +} +?> diff --git a/src/usr/local/bin/ping_hosts.sh b/src/usr/local/bin/ping_hosts.sh new file mode 100755 index 0000000..eef64f3 --- /dev/null +++ b/src/usr/local/bin/ping_hosts.sh @@ -0,0 +1,134 @@ +#!/bin/sh + +# pfSense ping helper +# written by Scott Ullrich +# (C)2006 Scott Ullrich +# All rights reserved. + +# Format of file should be delimited by | +# Field 1: Source IP +# Field 2: Destination IP +# Field 3: Ping count +# Field 4: Script to run when service is down +# Field 5: Script to run once service is restored +# Field 6: Ping time threshold +# Field 7: Wan ping time threshold +# Field 8: Address family + +# Read in ipsec ping hosts and check the CARP status +if [ -f /var/db/ipsecpinghosts ]; then + IPSECHOSTS="/var/db/ipsecpinghosts" + CURRENTIPSECHOSTS="/var/db/currentipsecpinghosts" + IFVPNSTATE=`ifconfig $IFVPN | grep "carp: BACKUP vhid" | wc -l` + if [ $IFVPNSTATE -gt 1 ]; then + echo -e "CARP interface in BACKUP (not pinging ipsec hosts)" + rm -f $CURRENTIPSECHOSTS + touch $CURRENTIPSECHOSTS + else + echo -e "CARP interface is MASTER or non CARP (pinging ipsec hosts)" + cat < $IPSECHOSTS > $CURRENTIPSECHOSTS + fi +fi + +# General file meant for user consumption +if [ -f /var/db/hosts ]; then + HOSTS="/var/db/hosts" +fi + +# Package specific ping requests +if [ -f /var/db/pkgpinghosts ]; then + PKGHOSTS="/var/db/pkgpinghosts" +fi + +cat $PKGHOSTS $HOSTS $CURRENTIPSECHOSTS >/tmp/tmpHOSTS + +if [ ! -d /var/db/pingstatus ]; then + /bin/mkdir -p /var/db/pingstatus +fi + +if [ ! -d /var/db/pingmsstatus ]; then + /bin/mkdir -p /var/db/pingmsstatus +fi + +PINGHOSTS=`cat /tmp/tmpHOSTS` + +PINGHOSTCOUNT=`cat /tmp/tmpHOSTS | wc -l` + +if [ "$PINGHOSTCOUNT" -lt "1" ]; then + exit +fi + +for TOPING in $PINGHOSTS ; do + echo "PROCESSING $TOPING" + SRCIP=`echo $TOPING | cut -d"|" -f1` + DSTIP=`echo $TOPING | cut -d"|" -f2` + COUNT=`echo $TOPING | cut -d"|" -f3` + FAILURESCRIPT=`echo $TOPING | cut -d"|" -f4` + SERVICERESTOREDSCRIPT=`echo $TOPING | cut -d"|" -f5` + THRESHOLD=`echo $TOPING | cut -d"|" -f6` + WANTHRESHOLD=`echo $TOPING | cut -d"|" -f7` + AF=`echo $TOPING | cut -d"|" -f8` + if [ "$AF" == "inet6" ]; then + PINGCMD=ping6 + else + PINGCMD=ping + fi + echo Processing $DSTIP + # Look for a service being down + # Read in previous status + PREVIOUSSTATUS="" + if [ -f "/var/db/pingstatus/${DSTIP}" ]; then + PREVIOUSSTATUS=`cat /var/db/pingstatus/$DSTIP` + fi + $PINGCMD -c $COUNT -S $SRCIP $DSTIP + if [ $? -eq 0 ]; then + # Host is up + if [ "$PREVIOUSSTATUS" != "UP" ]; then + # Service restored + echo "UP" > /var/db/pingstatus/$DSTIP + if [ "$SERVICERESTOREDSCRIPT" != "" ]; then + echo "$DSTIP is UP, previous state was DOWN .. Running $SERVICERESTOREDSCRIPT" + echo "$DSTIP is UP, previous state was DOWN .. Running $SERVICERESTOREDSCRIPT" | logger -p daemon.info -i -t PingMonitor + sh -c $SERVICERESTOREDSCRIPT + fi + fi + else + # Host is down + if [ "$PREVIOUSSTATUS" != "DOWN" ]; then + # Service is down + echo "DOWN" > /var/db/pingstatus/$DSTIP + if [ "$FAILURESCRIPT" != "" ]; then + echo "$DSTIP is DOWN, previous state was UP .. Running $FAILURESCRIPT" + echo "$DSTIP is DOWN, previous state was UP .. Running $FAILURESCRIPT" | logger -p daemon.info -i -t PingMonitor + sh -c $FAILURESCRIPT + fi + fi + fi + echo "Checking ping time $DSTIP" + # Look at ping values themselves + PINGTIME=`$PINGCMD -c 1 -S $SRCIP $DSTIP | awk '{ print $7 }' | grep time | cut -d "=" -f2` + echo "Ping returned $?" + echo $PINGTIME > /var/db/pingmsstatus/$DSTIP + if [ "$THRESHOLD" != "" ]; then + if [ $(echo "${PINGTIME} > ${THRESHOLD}" | /usr/bin/bc) -eq 1 ]; then + echo "$DSTIP has exceeded ping threshold $PINGTIME / $THRESHOLD .. Running $FAILURESCRIPT" + echo "$DSTIP has exceeded ping threshold $PINGTIME / $THRESHOLD .. Running $FAILURESCRIPT" | logger -p daemon.info -i -t PingMonitor + sh -c $FAILURESCRIPT + fi + fi + # Wan ping time threshold + #WANTIME=`rrdtool fetch /var/db/rrd/wan-quality.rrd AVERAGE -r 120 -s -1min -e -1min | grep ":" | cut -f3 -d" " | cut -d"e" -f1` + echo "Checking wan ping time $WANTIME" + echo $WANTIME > /var/db/wanaverage + if [ "$WANTHRESHOLD" != "" -a "$WANTIME" != "" ]; then + if [ $(echo "${WANTIME} > ${WANTHRESHOLD}" | /usr/bin/bc) -eq 1 ]; then + echo "$DSTIP has exceeded wan ping threshold $WANTIME / $WANTHRESHOLD .. Running $FAILURESCRIPT" + echo "$DSTIP has exceeded wan ping threshold $WANTIME / $WANTHRESHOLD .. Running $FAILURESCRIPT" | logger -p daemon.info -i -t PingMonitor + sh -c $FAILURESCRIPT + fi + fi + sleep 1 +done + +exit 0 + diff --git a/src/usr/local/bin/runmsntp.sh b/src/usr/local/bin/runmsntp.sh new file mode 100755 index 0000000..d770632 --- /dev/null +++ b/src/usr/local/bin/runmsntp.sh @@ -0,0 +1,12 @@ +#!/bin/sh + +# write our PID to file +echo $$ > $1 + +# execute msntp in endless loop; restart if it +# exits (wait 1 second to avoid restarting too fast in case +# the network is not yet setup) +while true; do + /usr/local/bin/msntp -v -r -P no -l $2 -x $3 $4 2>&1 | logger -p daemon.info -i -t msntp + sleep 60 +done diff --git a/src/usr/local/bin/slowdownpipe.sh b/src/usr/local/bin/slowdownpipe.sh new file mode 100755 index 0000000..13b9e8d --- /dev/null +++ b/src/usr/local/bin/slowdownpipe.sh @@ -0,0 +1,9 @@ +#!/bin/sh +# Illustrates use of a while loop to read a file + +cat - | \ +while read line +do + echo "$line" + sleep 0.01 +done diff --git a/src/usr/local/bin/viconfig b/src/usr/local/bin/viconfig new file mode 100755 index 0000000..93618f2 --- /dev/null +++ b/src/usr/local/bin/viconfig @@ -0,0 +1,3 @@ +#!/bin/sh +vi /cf/conf/config.xml +rm /tmp/config.cache
\ No newline at end of file |