def NewConnection(self, path, fd, properties): self.fd = fd.take() server_sock = socket.fromfd(self.fd, socket.AF_UNIX, socket.SOCK_STREAM) server_sock.setblocking(1) # Sends Version print("hooks.init() ->") hooks.init(server_sock) print("hooks.init() <-") try: # Wait for request print("Read from socket (Pre Loop):") data = server_sock.recv(1024) print("Read: %s" % data) print("while ->") while (data != "CLOSE"): if data == "GET_DATA": print("Send the data to phone in loop") hooks.sendtophone(server_sock) elif data == "CHECK_DATA": print("Check for available data:") if os.path.isfile("/home/root/data/dataOut"): server_sock.send("1") else: server_sock.send("-1") print("Read from socket (In Loop):") data = server_sock.recv(1024) print("Read from socket: %s" % data) except IOError: pass hooks.close(server_sock) server_sock.close()
def main(): with open("config.json", "r") as config_file: cfg = json.load(config_file) ioloop = tornado.ioloop.IOLoop.instance() crypto_core = CryptoCore() local_store = database.Database(cfg["database_url"]) lookup_core = dns_discovery.DNSCore(cfg["number_of_workers"]) lookup_core.callback_dispatcher = lambda cb, r: ioloop.add_callback(cb, r) if hooks: hooks_state = hooks.init(cfg, local_store) else: hooks_state = None # an interesting object structure address_ctr = {ACTION_PUBLISH: {"counter": Counter(), "clear_date": defaultdict(lambda: 0)}} LOGGER.info("API public key: {0}".format(crypto_core.public_key)) LOGGER.info("Record sign key: {0}".format(crypto_core.verify_key)) templates_dir = "_".join(("templates", cfg["templates"])) handlers = [("/api", _make_handler_for_api_method), ("/pk", PublicKey), (r"/barcode/(.+)\.svg$", CreateQR), (r"/u/(.+)?$", LookupAndOpenUser), (r"^/$", LookupAndOpenUser) ] if cfg["findfriends_enabled"]: handlers.append((r"/friends/([0-9]+)$", FindFriends)) handlers.append((r"/add_ui", AddKeyWeb)) handlers.append((r"/edit_ui", EditKeyWeb)) app = tornado.web.Application( handlers, template_path=os.path.join(os.path.dirname(__file__), templates_dir), static_path=os.path.join(os.path.dirname(__file__), "static"), crypto_core=crypto_core, local_store=local_store, lookup_core=lookup_core, address_ctr=address_ctr, hooks_state=hooks_state, home=cfg["registration_domain"], ) server = tornado.httpserver.HTTPServer(app, **{ "ssl_options": cfg.get("ssl_options"), "xheaders": cfg.get("is_proxied") }) server.listen(cfg["server_port"], cfg["server_addr"]) if cfg.get("enable_dns_server", 0): server = dns_serve.server(crypto_core, local_store, cfg) server.start_thread() LOGGER.info("DNS server activated.") if "suid" in cfg: LOGGER.info("Descending...") if os.getuid() == 0: if ":" not in cfg["suid"]: user = cfg["suid"] group = None else: user, group = cfg["suid"].split(":", 1) uid = pwd.getpwnam(user).pw_uid if group: gid = grp.getgrnam(group).gr_gid else: gid = pwd.getpwnam(user).pw_gid os.setgid(gid) os.setuid(uid) LOGGER.info("Continuing.") else: LOGGER.info("suid key exists in config, but not running as root. " "Exiting.") sys.exit() local_store.late_init() if "pid_file" in cfg: with open(cfg["pid_file"], "w") as pid: pid.write(str(os.getpid())) LOGGER.info("Notice: listening on {0}:{1}".format( cfg["server_addr"], cfg["server_port"] )) try: ioloop.start() finally: os.remove(cfg["pid_file"])
def main(): with open("config.json", "r") as config_file: cfg = json.load(config_file) ioloop = tornado.ioloop.IOLoop.instance() crypto_core = CryptoCore() local_store = database.Database(cfg["database_url"]) lookup_core = dns_discovery.DNSCore(cfg["number_of_workers"]) lookup_core.callback_dispatcher = lambda cb, r: ioloop.add_callback(cb, r) if hooks: hooks_state = hooks.init(cfg, local_store) else: hooks_state = None # an interesting object structure if cfg["sandbox"] == 0: address_ctr = { ACTION_PUBLISH: { "counter": Counter(), "clear_date": defaultdict(lambda: 0) } } else: LOGGER.info("Running in sandbox mode, limits are disabled.") address_ctr = None LOGGER.info("API public key: {0}".format(crypto_core.public_key)) LOGGER.info("Record sign key: {0}".format(crypto_core.verify_key)) templates_dir = "_".join(("templates", cfg["templates"])) handlers = [("/api", _make_handler_for_api_method), ("/pk", PublicKey), (r"/barcode/(.+)\.svg$", CreateQR), (r"/u/(.+)?$", LookupAndOpenUser), (r"^/$", LookupAndOpenUser)] if cfg["findfriends_enabled"]: handlers.append((r"/friends/([0-9]+)$", FindFriends)) handlers.append((r"/add_ui", AddKeyWeb)) handlers.append((r"/edit_ui", EditKeyWeb)) app = tornado.web.Application( handlers, template_path=os.path.join(os.path.dirname(__file__), templates_dir), static_path=os.path.join(os.path.dirname(__file__), "static"), crypto_core=crypto_core, local_store=local_store, lookup_core=lookup_core, address_ctr=address_ctr, hooks_state=hooks_state, app_startup=int(time.time()), home=cfg["registration_domain"], ) server = tornado.httpserver.HTTPServer( app, **{ "ssl_options": cfg.get("ssl_options"), "xheaders": cfg.get("is_proxied") }) server.listen(cfg["server_port"], cfg["server_addr"]) if cfg.get("enable_dns_server", 0): server = dns_serve.server(crypto_core, local_store, cfg) server.start_thread() LOGGER.info("DNS server activated.") if "suid" in cfg: LOGGER.info("Descending...") if os.getuid() == 0: if ":" not in cfg["suid"]: user = cfg["suid"] group = None else: user, group = cfg["suid"].split(":", 1) uid = pwd.getpwnam(user).pw_uid if group: gid = grp.getgrnam(group).gr_gid else: gid = pwd.getpwnam(user).pw_gid os.setgid(gid) os.setuid(uid) LOGGER.info("Continuing.") else: LOGGER.info("suid key exists in config, but not running as root. " "Exiting.") sys.exit() local_store.late_init() if "pid_file" in cfg: with open(cfg["pid_file"], "w") as pid: pid.write(str(os.getpid())) LOGGER.info("Notice: listening on {0}:{1}".format(cfg["server_addr"], cfg["server_port"])) try: ioloop.start() finally: os.remove(cfg["pid_file"])
#!/usr/bin/env python3 """ * tool_resigner.py * Author: stal, stqism; April 2014 * Copyright (c) 2014 Zodiac Labs. * Further licensing information: see LICENSE. """ import yuu import database import hooks import json with open("config.json", "r") as config_file: cfg = json.load(config_file) crypto_core = yuu.CryptoCore() local_store = database.Database(cfg["database_url"]) hooks_state = hooks.init(cfg, local_store) for record in local_store.iterate_all_users(mutates=1): print("Signing record for {0}.".format(record.name)) record.sig = crypto_core.sign(record) hooks.did_update_record(hooks_state, record)