]> git.pld-linux.org Git - projects/pld-ftp-admin.git/blob - modules/cmds.py
- 'public' (from www iface) connections must try to log in before doing
[projects/pld-ftp-admin.git] / modules / cmds.py
1 # vi: encoding=utf-8 ts=8 sts=4 sw=4 et
2
3 import os
4 import time
5
6 BailOut="BailOut"
7
8 def parse(con):
9     if '\0' not in con.data:
10         return
11     cmds=con.data.split('\0')[:-1]
12
13     for cmd in cmds:
14         con.data=con.data[len(cmd)+1:]
15         cmdname=cmd[:4]
16         if not con.authorized and not (cmdname=='linp' or cmdname=='linc'):
17             raise BailOut
18             # TODO: log unauthorized access
19         if cmdname in cmdlist:
20             cmdlist[cmdname](con, cmd[5:])
21         else:
22             raise BailOut
23             # TODO: log this
24
25 locks={}
26
27 def lock(con, arg, hard):
28     if arg not in locks:
29         locks[arg]=hard
30         con.sock.send("OK")
31     elif locks[arg]:
32         con.sock.send("HARD") # Hard lock - you can go get a cup of tea
33     else:
34         con.sock.send("SOFT") # Soft lock - try in a second or two
35         
36     
37 def cmd_unlock(con, arg):
38     if arg in locks:
39         del locks[arg]
40
41 def cmd_lock_soft(con, arg):
42     lock(con, arg, False)
43
44 def cmd_lock_hard(con, arg):
45     lock(con, arg, True)
46
47 logfile=open(os.environ['HOME']+'/pld-ftp-admin/var/log', 'a')
48
49 def cmd_log(con, msg):
50     logfile.write('%s [%s] -- %s\n' % (time.strftime('%Y-%m-%d %H:%M:%S'), 
51                                        con.name, msg))
52     logfile.flush()
53
54 def cmd_name(con, name):
55     con.name=name
56
57 cmdlist={'lcks':cmd_lock_soft, 'lckh':cmd_lock_hard, 'ulck':cmd_unlock,
58          'log1':cmd_log, 'name':cmd_name}
59
This page took 0.048572 seconds and 3 git commands to generate.