Skip to content
This repository has been archived by the owner on Mar 2, 2019. It is now read-only.

Commit

Permalink
Backend implementation for fixing issue #13
Browse files Browse the repository at this point in the history
  • Loading branch information
micolous committed Apr 28, 2012
1 parent d9fa058 commit c8423f5
Showing 1 changed file with 32 additions and 3 deletions.
35 changes: 32 additions & 3 deletions tollgate/backend/iptables.py
Expand Up @@ -16,8 +16,8 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
from subprocess import call, Popen, PIPE
from os import system
from os.path import exists, join
from os import system, listdir
from os.path import exists, join, isfile
from sys import exit
from re import compile as re_compile
import dbus, dbus.service, dbus.glib, gobject
Expand Down Expand Up @@ -335,7 +335,36 @@ def get_quota(self, uid):
return (True, reset_quota2_amount(user_rule(uid)))
except:
return (False, 0)


@dbus.service.method(dbus_interface=DBUS_INTERFACE, in_signature='', out_signature='a(si)')
def get_all_users_quota_remaining(self):
"""
Gets all user's remaining quota.
Returns an array of a tuple formed as follows:
0: The user ID.
1: The amount of quota remaining.
"""

o = []
# list all items in the quota2 counter directory
for f in listdir(QUOTA2_PATH):
if not f.startswith(LIMIT_RULE_PREFIX):
continue

# add the counter
try:
quota = get_quota2_amount(f)
except:
# error reading, probably not a counter.
continue

# shove in the result

o.append((f[len(LIMIT_RULE_PREFIX):], q))

return o

@dbus.service.method(dbus_interface=DBUS_INTERFACE, in_signature='s', out_signature='')
def disable_user(self, uid):
"""Disables a user's internet access by removing all their quota."""
Expand Down

0 comments on commit c8423f5

Please sign in to comment.