]> git.pld-linux.org Git - projects/pld-ftp-admin.git/blobdiff - modules/cmds.py
Fix exception handling syntax (python3 compat)
[projects/pld-ftp-admin.git] / modules / cmds.py
index 76a413bad65ccb6a49c0e1abe8508e33d3abddbd..d82b35aa2d30c5e37e5eeb4ff2e2ab1a31ca7dbe 100644 (file)
@@ -17,7 +17,7 @@ def parse(con):
         con.data=con.data[len(cmd)+1:]
         cmdname=cmd[:4]
         if not con.authorized and cmdname not in ('linp', 'linc', 'name'):
-            raise BailOut
+            raise BailOut()
             # TODO: log unauthorized access
         if cmdname in cmdlist_noargs:
             if len(cmd)==4:
@@ -32,10 +32,9 @@ def parse(con):
                 pass
                 # TODO: log malicious msg
         else:
-            raise BailOut
+            raise BailOut()
             # TODO: log this
 
-
 def lock(con, arg, hard):
     if arg not in locks:
         locks[arg]={'hard': hard, 'name': con.name, 'time': int(time.time())}
@@ -44,8 +43,7 @@ def lock(con, arg, hard):
         con.sock.send("HARD") # Hard lock - you can go get a cup of tea
     else:
         con.sock.send("SOFT") # Soft lock - try in a second or two
-        
-    
+
 def cmd_unlock(con, arg):
     if arg in locks:
         del locks[arg]
@@ -62,16 +60,21 @@ def cmd_lock_hard(con, arg):
 def cmd_show_locks(con):
     cmd_log(con, "Dumping locks data:");
     if len(locks):
-        for lockdata in locks.iteritems():
+        res = ""
+        for lockdata in locks.items():
             tree, data = lockdata
-            cmd_log(con, "Tree: %s, Conn name: %s, Hard Lock: %s, Time: %s"
-                    % (tree, data['name'], data['hard'], time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(data['time']))))
+            msg = "Tree: %s, Conn name: %s, Hard Lock: %s, Time: %s" % (
+                    tree, data['name'], data['hard'], time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(data['time'])))
+            cmd_log(con, msg)
+            res = res + msg
+#        con.sock.send("BLOB:%d" % len(res))
+        con.sock.send(res)
     else:
         cmd_log(con, "No locks found.");
+        con.sock.send("NLCK");
 
 def cmd_log(con, msg):
-    logfile.write('%s [%s] -- %s\n' % (time.strftime('%Y-%m-%d %H:%M:%S'), 
-                                       con.name, msg))
+    logfile.write('%s [%s] -- %s\n' % (time.strftime('%Y-%m-%d %H:%M:%S'), con.name, msg))
     logfile.flush()
 
 def cmd_name(con, name):
@@ -109,7 +112,7 @@ def write_cookies():
 def cmd_login_passwd(con, data):
     tmp=data.split('\n')
     if len(tmp)!=2:
-        raise BailOut
+        raise BailOut()
     login=tmp[0]
     passwd=tmp[1]
     md5pass=md5.new(passwd).hexdigest()
@@ -123,7 +126,7 @@ def cmd_login_passwd(con, data):
     else:
         # TODO: log this
         con.sock.send('FAIL')
-        raise BailOut
+        raise BailOut()
 
 def cmd_login_cookie(con, cookie):
     if cookie in cookies:
This page took 0.040493 seconds and 4 git commands to generate.