OpenVPN Simple Payment System
#!/bin/bash
rate='1.2' # 1.2 CNY/Gb
orig_rate='0.72' # Server Traffic: 0.72 CNY/g
pay_req='40.80' # Server Fee: 40.80 CNY/mo
unit='CNY'
function report {
total_get=$(echo "scale=5; $(stat | awk -F" " '{print $11}' | tr '\n' '+')0" | bc)
total_pay=$(echo "($(cat paid.log usage.log | awk -F ":| " '{print $11}' | tr '\n' '+')0)/1024/1024/1024*$orig_rate+$pay_req"|bc)
echo "Income : $total_get $unit"
echo "Cost : $total_pay $unit"
echo "Revenue : $(echo "scale=5; $total_get-$total_pay"|bc) $unit"
}
function stat {
users=$1
[[ -z $1 ]] && users="$(cat usage.log | awk -F" " '{print $1}' | sort | uniq )"
for user in $users
do
bytes=$(echo $(cat usage.log | grep $user | awk -F ":| " '{print $11}' | tr '\n' '+')0 | bc)
kbytes=$(echo "scale=5; $bytes/1024" | bc)
mbytes=$(echo "scale=5; $kbytes/1024" | bc)
gbytes=$(echo "scale=5; $mbytes/1024" | bc)
fee=$(echo "scale=5; $gbytes*$rate" | bc)
echo "User $user, traffic $bytes bytes ($mbytes Mb, $gbytes Gb), fee $fee $unit."
done
}
function pay {
[[ -z $1 ]] && return 1
stat $1
read -p "User $1 paied? (yes/no)" yn
[[ $yn == 'yes' ]] && {
echo "Removed all records for $1. Backup can be found in paid.log and usage.log.bak."
cat usage.log | grep $1 >> paid.log
cp usage.log usage.log.bak
cat usage.log.bak | grep -v $1 > usage.log
} || echo "Aborting."
}
$*
Replies to OpenVPN Simple Payment System 
{"html5":"htmlmixed","css":"css","javascript":"javascript","php":"php","python":"python","ruby":"ruby","lua":"text\/x-lua","bash":"text\/x-sh","go":"go","c":"text\/x-csrc","cpp":"text\/x-c++src","diff":"diff","latex":"stex","sql":"sql","xml":"xml","apl":"apl","asterisk":"asterisk","c_loadrunner":"text\/x-csrc","c_mac":"text\/x-csrc","coffeescript":"text\/x-coffeescript","csharp":"text\/x-csharp","d":"d","ecmascript":"javascript","erlang":"erlang","groovy":"text\/x-groovy","haskell":"text\/x-haskell","haxe":"text\/x-haxe","html4strict":"htmlmixed","java":"text\/x-java","java5":"text\/x-java","jquery":"javascript","mirc":"mirc","mysql":"sql","ocaml":"text\/x-ocaml","pascal":"text\/x-pascal","perl":"perl","perl6":"perl","plsql":"sql","properties":"text\/x-properties","q":"text\/x-q","scala":"scala","scheme":"text\/x-scheme","tcl":"text\/x-tcl","vb":"text\/x-vb","verilog":"text\/x-verilog","yaml":"text\/x-yaml","z80":"text\/x-z80"}