forked from ajenti/ajenti
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ajenti-ipc
executable file
·40 lines (31 loc) · 1 KB
/
ajenti-ipc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/env python
import httplib
import socket
import sys
class UHTTPConnection (httplib.HTTPConnection):
def __init__(self, path):
httplib.HTTPConnection.__init__(self, 'localhost')
self.path = path
def connect(self):
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
try:
sock.connect(self.path)
except socket.error, e:
if e.errno == 13:
sys.stderr.write('Permission denied\n')
sys.exit(4)
sys.stderr.write('Could not connect: %s\n' % e)
sys.exit(3)
self.sock = sock
if len(sys.argv) < 2:
print 'Usage: ajenti-ipc <endpoint> [arguments]'
sys.exit(1)
conn = UHTTPConnection('/var/run/ajenti-ipc.sock')
conn.request(
'GET',
sys.argv[1] + '/' + '\n'.join(sys.argv[2:]).encode('base64').strip(),
)
resp = conn.getresponse()
sys.stdout.write(resp.read())
sys.stderr.write('%s %s\n' % (resp.status, resp.reason))
sys.exit(0 if resp.status == '200' else 2)