예제 #1
0
def run_server(adr=net.address, port=CMD_PORT, password=""):
    password = crypt.shortstrhash(password)
    net.setup(adr)
    print("Starting command-issuing server at " + hex(net.address) + ":" +
          str(port))
    scon = net.NrlOpenPort(port)
    cons = []

    while True:
        for i in cons:
            if i.available():
                # update the connection because a packet is available
                packet = i.recv()
                try:
                    packet = crypt.decrypt1(packet, password)
                except:
                    continue
                timing = int.from_bytes(packet[:8], 'little')
                if timing < millis() and timing > millis() - 5000:
                    __cmdBcast(cons, packet[8:], password)
                try:
                    print(
                        hex(i.adr) + " : issued command: " +
                        packet[8:].decode())
                except:
                    print(hex(i.adr) + " : issued a binary command.")
        if scon.available():
            pk = scon.recv(0)
            remote_adr = pk[0]
            timing = int.from_bytes(pk[1][:8], 'little')
            if timing < millis() and timing > millis() - 5000:
                expected = crypt.sha512(hex(timing) + password)
                if expected == pk[1][8:]:
                    port = get_rand_port()
                    scon.send(pk[0], port.to_bytes(4, 'little'))
                    cons.append(net.NrlConnection(pk[0], port))
                    print("New connection from " + hex(pk[0]))
                else:
                    print("Connection failure from " + hex(pk[0]) +
                          ": bad cryptographic sequence.")
            else:
                print("Connection failure from " + hex(pk[0]) +
                      ": expired timing.")
        time.sleep(0.001)
예제 #2
0
def run_server(adr=net.address, port=MSG_PORT):
    net.setup(adr)
    print("Starting messaging server at " + hex(net.address) + ":" + str(port))
    scon = net.NrlOpenPort(port)
    cons = []

    messages = []

    users = {}

    while True:
        for i in cons:
            if i.available():
                # update the connection because a packet is available
                packet = i.recv()
                cmd = packet[0]
                packet = packet[1:]
                if cmd == CMD_WRITE_MSG:
                    messages.append(
                        __msgBcast(cons, users[i.adr] + b": " + packet))
                    print((users[i.adr] + b": " + packet).decode())
                elif cmd == CMD_READ_ALL:
                    for i2 in messages:
                        __sendMsgPkt(i, i2)
                else:
                    print("Invalid packet receieved from " +
                          users[i.adr].decode() + " : " + repr(packet))
        if scon.available():
            pk = scon.recv(0)
            if pk[1].startswith(b'MSG_CON') and pk[1][7] == 58:
                port = get_rand_port()
                scon.send(pk[0], port.to_bytes(4, 'little'))
                cons.append(net.NrlConnection(pk[0], port))
                user = pk[1][8:]
                print("New connection from " + hex(pk[0]) + " [" +
                      user.decode() + "]")
                users[pk[0]] = user
                messages.append(__msgBcast(cons, user + b' is now online.'))
        time.sleep(0.001)
예제 #3
0
import sys, os
sys.path.append(os.path.abspath('../'))

import neonet
import netlog as logging
import filebase, remote_control
import storage, _thread

if not os.path.isfile("cfg.txt"):
    storage.saveDict(
        "cfg.txt", {
            'adr': 0xC7860010,
            'key': 'default-key',
            'filebase-dir': './filebase/',
            'log_dir': './logs/'
        })
cfg = storage.loadDict("cfg.txt")
neonet.setup(cfg['adr'])

logging.add_log_file(os.path.join(cfg['log_dir'], '{}.txt'))

logging.log("Starting Filebase and Remote Control...")
_thread.start_new_thread(filebase.run, (cfg['key'], cfg['filebase-dir']))
_thread.start_new_thread(remote_control.run, (cfg['key'], ))
예제 #4
0
def start_server(address=0x10820000 | randint(0, 0xFFFF), password=None):
    print("Connecting to network...")
    net.setup(address)
    print("Starting server...")
    _thread.start_new_thread(server_code, (password, ))
예제 #5
0
        if data == None:
            return None
        elif data == b"FNF":
            return -1
        size = int.from_bytes(data, 'big')
        for i in range(size):
            buffer += self.con.recv()
        return buffer

    def write(self, fn, data):
        if type(data) == str:
            data = data.encode()
        self.con.send(b'WR' + fn.encode() + b';' + data)
        msg = self.con.recv()
        if msg != b"OK":
            if msg != None:
                msg = msg.decode()
            return msg


if __name__ == "__main__":
    add_log_file("logs/filebase/{}.txt")
    log("Starting NeoNet...")
    neonet.setup(0x880210)
    log("Starting filebase.py [default configuration]...")
    try:
        run("password", "filebase_default/")  # TODO: fix this somehow
    except Exception as e:
        log("ERROR: Server threw an exception: " + str(e))
        nope()
예제 #6
0
                if not s.startswith('0x'):
                    raise Exception()
                else:
                    adr = int(s[2:], 16)
            except:
                err("Error: -arg " + s +
                    " is not valid!  Please use a hex address.")
                errored = True
    if '-port' in args:
        # set port
        i = args.index('-port') + 1
        if i >= len(args):
            err("Error: -port directive given but no file specified!")
            errored = True
        else:
            try:
                s = args[i]
                port = int(s)
            except:
                err("Error: -port " + s +
                    " is not valid!  Please use an integer port.")
                errored = True
    if errored:
        err("There was/were error(s) starting the server!  Check your configuration."
            )
    else:
        print("Connecting to network...")
        net.setup(adr, routing_table=readRoutingTable(routing_table_text))
        cmd_api.run_server(port=port, password=args[0])
        err("Server quit.")