Page 1 of 1

Traffic volume limit for each user (for example, 50 GB for user a)

Posted: Tue Jul 25, 2023 4:05 pm
by persianboy
How to define a volume limit for each user? Is it possible for someone to give a simple and complete explanation? Or put its code in GitHub? How should I use the script that was asked in previous similar questions and where should I change its code?
Thank you for someone's help
(Why is the volume limit not added in the software?)

Re: Traffic volume limit for each user (for example, 50 GB for user a)

Posted: Thu Jul 27, 2023 11:56 am
by solo
persianboy wrote:
Tue Jul 25, 2023 4:05 pm
Is it possible for someone to give a simple and complete explanation? Or put its code in GitHub?
Since no one offers an explanation, here is a complex and incomplete solution. Firstly, there is some code on GitHub, ask for an update https://github.com/shakibamoshiri/secli

Meanwhile, a few pointers:
  • check traffic of eg user named "usr2"

Code: Select all

curl -s -k -H "X-VPNADMIN-PASSWORD: xxxxxx" --json "{\"jsonrpc\":\"2.0\",\"id\":\"rpc_call_id\",\"method\":\"GetUser\",\"params\":{\"HubName_str\":\"VPN\",\"Name_str\":\"usr2\"}}" https://localhost:5555/api/ | jq ".result.\"Recv.UnicastBytes_u64\""

86646
  • if in excess, EnumSession + DeleteSession (of "usr2") and...
  • SetUser ("usr2") "UsePolicy_bool": true //while "policy:Access_bool": false
Deploy on scheduler/cron with scripts.

Re: Traffic volume limit for each user (for example, 50 GB for user a)

Posted: Sat Jul 29, 2023 7:12 am
by shakibamoshiri
it is too simple but I added this functionality to a much bigger script which is not easy to be used by a non-technical person.
I think I should make one just for this purpose.

And I should mention to main issue is that SE server that does not have any hooks, making any extension for it wont be easy.

here is the approach (if you could code) using RPC-JSON api
1. get a user information
2. sum the income + outcome traffic
3. check if exceeded your threshold
4. if yes disable the user account
5. it may a user be connected at the moment so check if user is online (he is consuming traffic)
6. disconnect an online user session
7. notify yourself or the user

if SE had hooks, this could be done real simple, but since it does not have, it becomes complex and hard to manage
By the way you either have to run the script
- manually
- using a scheduler e.g crontab (Linux)
to check for users traffic every X minutes.

I have spent more five months and making two CLI to mange SE server and eventually gave up further development since it has not been designed for enterprise usage (= having users and sell VPNs) but it is super good for LAN-to-LAN, VPN router, etc.