OpenVPN Simple Payment System

From NAT, 6 Years ago, written in Bash, viewed 606 times.
URL https://code.nat.moe/view/9669d5b9 Embed
Download Paste or View Raw
  1. #!/bin/bash
  2.  
  3. rate='1.2'       # 1.2 CNY/Gb
  4. orig_rate='0.72' # Server Traffic: 0.72 CNY/g
  5. pay_req='40.80'  # Server Fee: 40.80 CNY/mo
  6. unit='CNY'
  7.  
  8. function report {
  9.         total_get=$(echo "scale=5; $(stat | awk -F" " '{print $11}' | tr '\n' '+')0" | bc)
  10.         total_pay=$(echo "($(cat paid.log usage.log | awk -F ":| " '{print $11}' | tr '\n' '+')0)/1024/1024/1024*$orig_rate+$pay_req"|bc)
  11.         echo "Income  : $total_get $unit"
  12.         echo "Cost    : $total_pay $unit"
  13.         echo "Revenue : $(echo "scale=5; $total_get-$total_pay"|bc) $unit"
  14. }
  15.  
  16. function stat {
  17.         users=$1
  18.         [[ -z $1 ]] && users="$(cat usage.log | awk -F" " '{print $1}' | sort | uniq )"
  19.  
  20.         for user in $users
  21.         do
  22.                 bytes=$(echo $(cat usage.log | grep $user | awk -F ":| " '{print $11}' | tr '\n' '+')0 | bc)
  23.                 kbytes=$(echo "scale=5; $bytes/1024" | bc)
  24.                 mbytes=$(echo "scale=5; $kbytes/1024" | bc)
  25.                 gbytes=$(echo "scale=5; $mbytes/1024" | bc)
  26.                 fee=$(echo "scale=5; $gbytes*$rate" | bc)
  27.                 echo "User $user, traffic $bytes bytes ($mbytes Mb, $gbytes Gb), fee $fee $unit."
  28.         done
  29. }
  30.  
  31. function pay {
  32.         [[ -z $1 ]] && return 1
  33.         stat $1
  34.         read -p "User $1 paied? (yes/no)" yn
  35.         [[ $yn == 'yes' ]] && {
  36.                 echo "Removed all records for $1. Backup can be found in paid.log and usage.log.bak."
  37.                 cat usage.log | grep $1 >> paid.log
  38.                 cp usage.log usage.log.bak
  39.                 cat usage.log.bak | grep -v $1 > usage.log
  40.         } || echo "Aborting."
  41. }
  42. $*

Replies to OpenVPN Simple Payment System rss

Title Name Language When
OpenVPN Simple Payment System - Version 2 NAT bash 6 Years ago.

Reply to "OpenVPN Simple Payment System"

Here you can reply to the paste above

captcha