]> git.pld-linux.org Git - projects/pld-ftp-admin.git/blame - modules/cons.py
- also log script's name (if given)
[projects/pld-ftp-admin.git] / modules / cons.py
CommitLineData
e3aced8e
MM
1# vi: encoding=utf-8 ts=8 sts=4 sw=4 et
2
3import socket
4import os
5import select
6from common import fileexists
7import ftpio
8import cmds
9
10class Connection:
11 def __init__(self, sock, authorized):
12 sock.setblocking(False)
13 self.sock=sock
14 self.authorized=authorized
15 self.fileno=sock.fileno
b55905f2 16 self.name=""
e3aced8e
MM
17 self.data=""
18 def destroy(self):
19 self.sock.close()
20 rm(self)
21 def handleinput(self):
22 newdata=self.sock.recv(8192)
23 if not newdata:
24 self.destroy()
25 self.data=self.data+newdata
26 try:
27 cmds.parse(self)
28 except cmds.CmdError:
29 self.destroy()
30
31def add(con):
32 cons.append(con)
33
34def rm(con):
35 cons.remove(con)
36
37def readables():
38 lst=cons[:]
39 lst.append(privlistener)
40 lst.append(publistener)
41 inlst,outlst,errlst = select.select(lst, [], [], 0)
42 return inlst
43
44def createlistener(path):
45 if fileexists(path):
46 os.remove(path)
47
48 s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
49 s.setblocking(False)
50 s.bind(path)
51 if path==ftpio.pubsock:
52 os.chmod(path, 0606)
53 else:
54 os.chmod(path, 0600)
55 s.listen(3)
56 return s
57
58cons=[]
59
60privlistener=createlistener(ftpio.privsock)
61publistener=createlistener(ftpio.pubsock)
62
63
64
This page took 0.060142 seconds and 4 git commands to generate.