[tor-commits] [flashproxy/master] facilitator-reg.

dcf at torproject.org dcf at torproject.org
Thu Mar 7 09:17:35 UTC 2013


commit dadfb7639c25415958d543e0a14c15248dbc38fd
Author: David Fifield <david at bamsoftware.com>
Date:   Thu Mar 7 00:01:55 2013 -0800

    facilitator-reg.
    
    This is the unprivileged program that feeds encoded registrations to
    facilitator-reg-daemon.
---
 facilitator/Makefile        |    2 +-
 facilitator/facilitator-reg |   59 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 60 insertions(+), 1 deletions(-)

diff --git a/facilitator/Makefile b/facilitator/Makefile
index d23a259..90855d2 100644
--- a/facilitator/Makefile
+++ b/facilitator/Makefile
@@ -6,7 +6,7 @@ all:
 
 install:
 	mkdir -p $(BINDIR)
-	cp -f facilitator facilitator-email-poller facilitator-reg-daemon facilitator.cgi fac.py $(BINDIR)
+	cp -f facilitator facilitator-email-poller facilitator-reg-daemon facilitator-reg facilitator.cgi fac.py $(BINDIR)
 	cp -f init.d/facilitator init.d/facilitator-email-poller init.d/facilitator-reg-daemon /etc/init.d/
 
 clean:
diff --git a/facilitator/facilitator-reg b/facilitator/facilitator-reg
new file mode 100755
index 0000000..c39eed5
--- /dev/null
+++ b/facilitator/facilitator-reg
@@ -0,0 +1,59 @@
+#!/usr/bin/env python
+
+import getopt
+import socket
+import sys
+
+CONNECT_ADDRESS = "127.0.0.1"
+DEFAULT_CONNECT_PORT = 9003
+
+class options(object):
+    connect_port = DEFAULT_CONNECT_PORT
+
+def usage(f = sys.stdout):
+    print >> f, """\
+Usage: %(progname)s
+Reads a base64-encoded encrypted client registration from stdin and
+feeds it to a local facilitator-reg-daemon process. Returns 0 if the
+registration was successful, 1 otherwise.
+
+  -h, --help              show this help.
+  -p, --port PORT         connect to PORT (by default %(port)d).\
+""" % {
+    "progname": sys.argv[0],
+    "port": DEFAULT_CONNECT_PORT,
+}
+
+def main():
+    opts, args = getopt.gnu_getopt(sys.argv[1:], "hp:", ["help", "port="])
+    for o, a in opts:
+        if o == "-h" or o == "--help":
+            usage()
+            sys.exit()
+        elif o == "-p" or o == "--pass":
+            options.connect_port = int(a)
+
+    if len(args) != 0:
+        usage(sys.stderr)
+        sys.exit(1)
+
+    addrinfo = socket.getaddrinfo(CONNECT_ADDRESS, options.connect_port, 0, socket.SOCK_STREAM, socket.IPPROTO_TCP)[0]
+
+    s = socket.socket(addrinfo[0], addrinfo[1], addrinfo[2])
+    s.connect(addrinfo[4])
+
+    while True:
+        data = sys.stdin.read(1024)
+        if data == "":
+            break
+        s.send(data)
+    s.shutdown(socket.SHUT_WR)
+    data = s.recv(1024)
+
+    if data.strip() == "OK":
+        sys.exit(0)
+    else:
+        sys.exit(1)
+
+if __name__ == "__main__":
+    main()





More information about the tor-commits mailing list