]> git.pld-linux.org Git - projects/pld-ftp-admin.git/blobdiff - modules/cmds.py
- minor internal reorganization finished
[projects/pld-ftp-admin.git] / modules / cmds.py
index 10e3072f4a58b3e5c3c87c61de80052870e07b61..b46047bfda27827c6184abc187a6177e7fcc311e 100644 (file)
@@ -5,6 +5,7 @@ import time
 import config
 import common
 import md5
+import ftptree
 
 
 def parse(con):
@@ -15,7 +16,7 @@ def parse(con):
     for cmd in cmds:
         con.data=con.data[len(cmd)+1:]
         cmdname=cmd[:4]
-        if not con.authorized and not (cmdname=='linp' or cmdname=='linc'):
+        if not con.authorized and cmdname not in ('linp', 'linc', 'name'):
             raise BailOut
             # TODO: log unauthorized access
         if cmdname in cmdlist_noargs:
@@ -105,6 +106,7 @@ def cmd_login_passwd(con, data):
         cookie=`time.time()`.split('.')[0]+'_'+md5.new(md5pass+salt).hexdigest()
         cookies[cookie]=login
         write_cookies()
+        con.username=login
         con.authorized=True
         con.sock.send('OK '+cookie)
     else:
@@ -116,6 +118,7 @@ def cmd_login_cookie(con, cookie):
     if cookie in cookies:
         con.cookie=cookie
         con.authorized=True
+        con.username=cookies[cookie]
         con.sock.send('OK '+cookies[cookie])
     else:
         # TODO: log this (or not)
@@ -125,13 +128,40 @@ def cmd_logout(con):
     if con.cookie in cookies:
         del cookies[con.cookie]
         write_cookies()
-    pass
+
+def reloadftptree():
+    global srctree, pkglist
+    srctree=ftptree.FtpTree(config.value['default_to'], loadall=True)
+    pkglist=srctree.keys()
+    pkglist.sort()
+
+def cmd_gettree(con):
+    buf=''
+    for pkgnvr in pkglist:
+        # TODO: show only user's own pkgs
+        pkg=srctree[pkgnvr]
+        line=pkgnvr
+        if pkg.marked4moving:
+            line=line+'\n1'
+        else:
+            line=line+'\n0'
+        if pkg.marked4removal:
+            line=line+'\n1'
+        else:
+            line=line+'\n0'
+        buf=buf+'\0'+line
+    if buf:
+        con.sock.send('%.6d' % (len(buf)-1))
+        con.sock.send(buf[1:])
+    else:
+        con.sock.send('000000')
+
 
 cmdlist_args={'lcks':cmd_lock_soft, 'lckh':cmd_lock_hard, 'ulck':cmd_unlock,
          'log1':cmd_log, 'name':cmd_name, 'linp':cmd_login_passwd,
          'linc':cmd_login_cookie}
 
-cmdlist_noargs={'lout':cmd_logout}
+cmdlist_noargs={'lout':cmd_logout, 'gett':cmd_gettree}
 
 # Global stuff and initializations
 
@@ -139,5 +169,6 @@ BailOut="BailOut"
 locks={}
 logfile=open(common.ftpadmdir+'var/log', 'a')
 load_creds()
+reloadftptree()
 salt=md5.new(`time.time()`).hexdigest()
 
This page took 0.027594 seconds and 4 git commands to generate.