]> git.stg.codes - stg.git/blob - projects/stargazer/scripts/shaper/OnConnect
[NY Flight] Use common encryption/decryption functions.
[stg.git] / projects / stargazer / scripts / shaper / OnConnect
1 #!/bin/bash
2
3 int_iface=eth1
4
5 # Login
6 LOGIN=$1
7
8 #user IP
9 IP=$2
10
11 #cash
12 CASH=$3
13
14 #user ID
15 ID=$4
16
17 #Selected dirs to connect
18 DIRS=$5
19
20 default_speed=32kbit
21
22 # =========== shaping by tariff ===========
23 #tariff=$(grep -i "^tariff=" /var/stargazer/users/$LOGIN/conf | cut -f 2 -d"=")
24 #echo "tariff=$tariff" > /var/stargazer/users/$LOGIN/connect.log
25 #case $tariff in
26 #    minimum)  speedkb=128kbit;;  # 128 kbit
27 #    middle)   speedkb=256kbit;;  # 256 kbi
28 #    maximum)  speedkb=512kbit;;         # 512 kbit
29 #    *)        speedkb=$default_speed;;  # default speed
30 #esac
31 # ========= shaping by tariff end ========= 
32
33 # ========= shaping by userdata0 ==========
34 speedR=$(grep -i "^Userdata0=" /var/stargazer/users/$LOGIN/conf | cut -f 2 -d"=")
35 speed=$(echo $speedR | grep "^[0-9]*[0-9]$")
36
37 if [ -z "$speed" ] 
38 then
39     speedkb=$default_speed
40 else
41     speedkb="$speed"kbit
42 fi
43 # ======= shaping by userdata0 end ========
44
45 declare -i mark=$ID+10
46
47 echo "$mark" > /var/stargazer/users/$LOGIN/shaper_mark
48 echo "$speedkb" > /var/stargazer/users/$LOGIN/shaper_rate
49
50 iptables -t mangle -A FORWARD -d $IP -j MARK --set-mark $mark
51
52 tc class add dev $int_iface parent 1:1 classid 1:$mark htb rate $speedkb burst 40k
53 tc filter add dev $int_iface parent 1: protocol ip prio 3 handle $mark fw classid 1:$mark
54