Esempio n. 1
0
def main():
    """Main."""
    winutils.exit_if_admin()

    script_name = os.path.basename(sys.argv[0])  # in case it is full path
    script_name_no_ext = os.path.splitext(script_name)[0]

    log_filename = "%s.log" % (script_name_no_ext, )
    format = ("%(asctime)s %(name)s %(levelname)s : %(message)s")

    logging.basicConfig(format=format,
                        filename=log_filename,
                        filemode='w',
                        level=logging.DEBUG)

    c = wmi.WMI()
    for iface in c.Win32_NetworkAdapterConfiguration(IPEnabled=True):
        print("Local IP address: %s DNS %r" %
              (iface.IPAddress, iface.DNSDomain))

    print("Starting PTS ...")
    pts = PyPTSWithXmlRpcCallback()
    print("OK")

    print("Serving on port {} ...".format(SERVER_PORT))

    server = xmlrpc.server.SimpleXMLRPCServer(("", SERVER_PORT),
                                              allow_none=True)
    server.register_instance(pts)
    server.register_introspection_functions()
    server.serve_forever()
def run_xmlrpcserver(pipe_conn, port):
    server = xmlrpc.server.SimpleXMLRPCServer(('', port),
                                              requestHandler=_RequestHandler,
                                              allow_none=True)
    server.register_introspection_functions()
    server.register_instance(XMLRPCServer(pipe_conn))
    server.serve_forever()
Esempio n. 3
0
def main():

    yara_object = YaraObject("yaraconnector")

    yara_object.set_feed_info(name="Yara",
                     summary="Scan binaries collected by Carbon Black with Yara.",
                     tech_data="There are no requirements to share any data with Carbon Black to use this feed.",
                     provider_url="http://plusvic.github.io/yara/",
                     icon_path="yara-logo.png",
                     display_name="Yara")

    yara_object.start()
    #rpc interface to the rpcinterface in cbrprcinterface.py
    server = SimpleXMLRPCServer(('0.0.0.0', 9002),
                            requestHandler=RequestHandler)
    server.register_introspection_functions()
    server.register_instance(yara_object)

    try:
            # Run the server's main loop
        server.serve_forever()
    except BaseException as bae:
        logger.debug("Yara eror {}".format(str(e)))
    finally:
        yara_object.stop()
Esempio n. 4
0
def main():
    """Main."""
    winutils.exit_if_admin()

    script_name = os.path.basename(sys.argv[0])  # in case it is full path
    script_name_no_ext = os.path.splitext(script_name)[0]

    log_filename = "%s.log" % (script_name_no_ext,)
    format = ("%(asctime)s %(name)s %(levelname)s : %(message)s")

    logging.basicConfig(format=format,
                        filename=log_filename,
                        filemode='w',
                        level=logging.DEBUG)

    print("Starting PTS ...")
    pts = PyPTSWithXmlRpcCallback()
    print("OK")

    print("Serving on port {} ...".format(SERVER_PORT))

    server = xmlrpc.server.SimpleXMLRPCServer(("", SERVER_PORT), allow_none=True)
    server.register_instance(pts)
    server.register_introspection_functions()
    server.serve_forever()
Esempio n. 5
0
def start_service(host, port, bv):
    info("Starting service on {}:{}".format(host, port))
    server = xmlrpc.server.SimpleXMLRPCServer(
        (host, port),
        requestHandler=BinjaGefRequestHandler,
        logRequests=False,
        allow_none=True)
    server.register_introspection_functions()
    server.register_instance(Gef(server, bv))
    dbg("Registered {} functions.".format(len(server.system_listMethods())))
    while True:
        if hasattr(server, "shutdown") and server.shutdown == True: break
        server.handle_request()
    return
Esempio n. 6
0
def main():
    # FIXME: that needs to be determined properly
    host = '127.0.0.1'
    port = 8081

    server = xmlrpc.server.SimpleXMLRPCServer((host, port))

    server.register_instance(GameServer('Nowhere'))

    logging.info("MUD serving at enpoint http://{0}:{1}/".format(host, port))
    logging.info("Press Ctrl-C to stop")

    try:
        server.serve_forever()
    except KeyboardInterrupt:
        logging.info("Stopped")
Esempio n. 7
0
 def main():

    """Main program; parse options and go."""

    try:

        opts, args = getopt.getopt(sys.argv[1:], 'hd:p:o:')

    except getopt.error as msg:

        usage(2, msg)

    options = Options.options

    for opt, arg in opts:

        if opt == '-h':

            usage(0)

        elif opt == '-o':

            options.set_from_cmdline(arg, sys.stderr)

    dbname, usedb = storage.database_type(opts)

    if len(args) != 1:

        usage(2, "IP:PORT not specified")

    ip, port = args[0].split(":")

    port = int(port)

    bayes = storage.open_storage(dbname, usedb)

    h = XMLHammie(bayes)

    server = ReusableSimpleXMLRPCServer(
        (ip, port),
        xmlrpc.server.SimpleXMLRPCRequestHandler)

    server.register_instance(h)

    server.serve_forever()
Esempio n. 8
0
def main():
    global master_host
    global master_port
    global zk
    global group_infos
    print("INFO: I am the primary master now!")
    master_setup()
    get_servers()
    with ThreadXMLRPCServer((master_host, master_port)) as server:
        server.register_multicall_functions()
        server.register_instance(masterRPC())
        print("INFO: Master booted on http://{}:{}".format(
            master_host, master_port))
        try:
            server.serve_forever()
        except KeyboardInterrupt:
            zk.stop()
            print("\nKeyboard interrupt received, exiting.")
            exit(0)

class LocatorService:
    def __init__(self, car_num):
        self.car_num = car_num

    def locate_cars(self):
        result = []
        for car_id in range(self.car_num):
            log_entries = log_parser.parse_log(f'logs/client{car_id}.log')
            log_entry = next(log_entry for log_entry in reversed(log_entries)
                             if isinstance(log_entry, log_parser.ArriveEntry)
                             or isinstance(log_entry, log_parser.MoveEntry))
            if isinstance(log_entry, log_parser.ArriveEntry):
                result.append([log_entry.pos])
            else:
                result.append([log_entry.from_pos, log_entry.to_pos])
        return result


if __name__ == '__main__':
    config = json.load(open('config.json', 'r'))
    locator_addr = config['locator_addr']
    car_num = len(config['car_tasks'])

    service = LocatorService(car_num)
    server = xmlrpc.server.SimpleXMLRPCServer(
        (locator_addr['host'], locator_addr['port']))
    server.register_instance(service)
    server.serve_forever()
Esempio n. 10
0
def run_xmlrpcserver(pipe_conn, port):
    server = xmlrpc.server.SimpleXMLRPCServer(
        ('', port), requestHandler=_RequestHandler, allow_none=True)
    server.register_introspection_functions()
    server.register_instance(XMLRPCServer(pipe_conn))
    server.serve_forever()
Esempio n. 11
0
        else:
            string2 = string2.zfill(len(string1))

        place = 0
        carry = 0
        products = []
        for val2 in reversed(string2):
            curr_product = ['0' for _ in range(place)]
            for val1 in reversed(string1):
                product = int(val1) * int(val2) + carry
                curr_product.append(str(product % 10))
                carry = product // 10
            curr_product.append(str(carry))
            products.append(''.join(curr_product)[::-1])
            place += 1

        final_product = '0'
        for product in products:
            final_product = adder_server.network_add(final_product, product)

        return final_product


if __name__ == '__main__':
    server = xmlrpc.server.SimpleXMLRPCServer(("0.0.0.0", 8001),
                                              allow_none=True)
    server.register_instance(Multiplier())
    server.register_function(Multiplier.network_multiply)
    server.register_function(Multiplier.set_adder_server)
    server.serve_forever()
Esempio n. 12
0
                      help="server GroupId")
    parser.add_option("--ServerId",
                      metavar="ServerId",
                      type="int",
                      help="server ServerId in the group")
    parser.add_option("--weight",
                      metavar="weight",
                      type="int",
                      help="weight for load balance")
    (options, args) = parser.parse_args()
    GroupId = options.GroupId
    ServerId = options.ServerId
    host = options.host
    port = options.port
    model = Model(GroupId, ServerId)
    print('SERVER: {}'.format(options))
    zk.get_children("/GroupMember", watch=get_peers)
    with ThreadXMLRPCServer((options.host, options.port)) as server:
        server.register_multicall_functions()
        server.register_instance(serverRPC())
        print("SERVER: Server {}-{} booted on http://{}:{}".format(
            options.GroupId, options.ServerId, options.host, options.port))
        register_zookeeper(options)
        get_peers()
        try:
            server.serve_forever()
        except KeyboardInterrupt:
            zk.stop()
            print("\nKeyboard interrupt received, exiting.")
            exit(0)
Esempio n. 13
0
import xmlrpc.server


class Adder:
    @staticmethod
    def network_add(string1, string2):
        if len(string1) <= len(string2):
            string1 = string1.zfill(len(string2))
        else:
            string2 = string2.zfill(len(string1))

        zipped = zip(reversed(string1), reversed(string2))
        carry = 0
        final_sum = []

        for val1, val2 in zipped:
            curr_sum = int(val1) + int(val2) + carry
            final_sum.append(str(curr_sum % 10))
            carry = curr_sum // 10
        final_sum.append(str(carry))

        return ''.join(final_sum)[::-1].lstrip('0')


if __name__ == '__main__':
    server = xmlrpc.server.SimpleXMLRPCServer(("0.0.0.0", 8000))
    server.register_instance(Adder())
    server.register_function(Adder.network_add)
    server.serve_forever()
Esempio n. 14
0
def xmlrpc_get_object_size(serialized_file):
    img_bgr = get_img_bgr(serialized_file)
    return object_size.get_size(img_bgr)


def xmlrpc_is_paper_present(serialized_file):
    img_bgr = get_img_bgr(serialized_file)
    return paper_detection.is_paper(img_bgr)


class PersistentService:
    def __init__(self):
        self.x = 0

    def getX(self):
        self.x += 1
        return self.x


with xmlrpc.server.SimpleXMLRPCServer(('localhost', PORT)) as server:
    print("serving at port", PORT)
    server.register_introspection_functions()
    server.register_function(xmlrpc_get_object_size, "getObjectSize")
    server.register_function(xmlrpc_is_paper_present, "isPaperPresent")
    server.register_instance(PersistentService())
    server.register_multicall_functions()
    try:
        server.serve_forever()
    finally:
        server.server_close()