Skip to content
Browse files

Backend implementation for fixing issue #13

  • Loading branch information...
1 parent d9fa058 commit c8423f54e5465312536e11e4715a1c3e6e31d956 @micolous committed Apr 28, 2012
Showing with 32 additions and 3 deletions.
  1. +32 −3 tollgate/backend/iptables.py
View
35 tollgate/backend/iptables.py
@@ -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
@@ -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."""

0 comments on commit c8423f5

Please sign in to comment.
Something went wrong with that request. Please try again.