Ejemplo n.º 1
0
    def __init__(self):
        self.repeater = None
        self.tap = None
        self.tick = 0

        self.platform = dplatform.get_platform()
        self.config = self.load_config()
Ejemplo n.º 2
0
    def but_export(self, widget, data=None):
        try:
            (list, iter) = self.view.get_selection().get_selected()
            (filename, _id) = list.get(iter, self.col_file, self.col_id)
        except:
            return

        p = dplatform.get_platform()
        fn = p.gui_save_file(default_name="%s.xml" % _id)
        if fn:
            shutil.copy(filename, fn)
Ejemplo n.º 3
0
    def but_import(self, widget, data=None):
        p = dplatform.get_platform()
        fn = p.gui_open_file()
        if not fn:
            return

        try:
            form_id = self.add_form(fn)
        except Exception as e:
            d = gtk.MessageDialog(buttons=gtk.BUTTONS_OK)
            d.set_markup("<big><b>Unable to add form</b></big>")
            d.format_secondary_text(str(e))
            d.run()
            d.destroy()

        shutil.copy(fn, os.path.join(self.dir, "%s.xml" % form_id))
Ejemplo n.º 4
0
    def auth_user(self, pipe):
        host, port = pipe._socket.getpeername()

        if not self.reqauth:
            pipe.write("100 Authentication not required\r\n")
            return True
        elif self.trustlocal and host == "127.0.0.1":
            pipe.write("100 Authentication not required for localhost\r\n")
            return True

        auth_fn = dplatform.get_platform().config_file("users.txt")
        try:
            auth = file(auth_fn)
            lines = auth.readlines()
            auth.close()
        except Exception, e:
            print("Failed to open %s: %s" % (auth_fn, e))
Ejemplo n.º 5
0
    def auth_user(self, pipe):
        host, port = pipe._socket.getpeername()

        if not self.reqauth:
            pipe.write("100 Authentication not required\r\n")
            return True
        elif self.trustlocal and host == "127.0.0.1":
            pipe.write("100 Authentication not required for localhost\r\n")
            return True

        auth_fn = dplatform.get_platform().config_file("users.txt")
        try:
            auth = open(auth_fn)
            lines = auth.readlines()
            auth.close()
        except Exception as e:
            printlog("Repeater  : Failed to open %s: %s" % (auth_fn, e))

        pipe.write("101 Authorization required\r\n")
        username, password = self.auth_exchange(pipe)

        lno = 1
        for line in lines:
            line = line.strip()
            try:
                u, p = line.split(" ", 1)
                u = u.upper()
            except Exception as e:
                printlog(
                    "Repeater  : Failed to parse line %i in users.txt: %s" %
                    (lno, line))
                continue

            if u == username and p == password:
                printlog(("Authorized user %s" % u))
                pipe.write("200 Authorized\r\n")
                return True

        printlog("Repeater  : User %s failed to authenticate" % username)
        pipe.write("500 Not authorized\r\n")
        return False
Ejemplo n.º 6
0
def run_lzhuf(cmd, data):
    p = dplatform.get_platform()

    cwd = tempfile.mkdtemp()

    f = open(os.path.join(cwd, "input"), "wb")
    f.write(data)
    f.close()

    kwargs = {}
    if subprocess.mswindows:
        su = subprocess.STARTUPINFO()
        su.dwFlags |= subprocess.STARTF_USESHOWWINDOW
        su.wShowWindow = subprocess.SW_HIDE
        kwargs["startupinfo"] = su

    if os.name == "nt":
        lzhuf = "LZHUF_1.EXE"
    elif os.name == "darwin":
        raise Exception("Not supported on MacOS")
    else:
        lzhuf = "lzhuf"

    lzhuf_path = os.path.abspath(os.path.join(p.source_dir(), "libexec",
                                              lzhuf))
    shutil.copy(os.path.abspath(lzhuf_path), cwd)
    run = [lzhuf_path, cmd, "input", "output"]

    printlog(("wl2k       : Running %s in %s" % (run, cwd)))

    ret = subprocess.call(run, cwd=cwd, **kwargs)
    printlog(("wl2k       : LZHUF returned %s" % ret))
    if ret:
        return None

    f = open(os.path.join(cwd, "output"), "rb")
    data = f.read()
    f.close()

    return data
Ejemplo n.º 7
0
 def ping_data(self):
     p = dplatform.get_platform()
     return _("Running") + " D-RATS %s (%s)" % (DRATS_VERSION,
                                                p.os_version_string())
Ejemplo n.º 8
0
                 "--config",
                 dest="config",
                 help="Use alternate configuration directory")
    o.add_option("-p",
                 "--profile",
                 dest="profile",
                 action="store_true",
                 help="Enable profiling")
    (opts, args) = o.parse_args()

    # import the platform module - this will setup all the proper parameters for the different OSs
    from d_rats import dplatform

    if opts.config:
        print("D-Rats     : re-config option found -- Reconfigure D-rats")
        dplatform.get_platform(opts.config)

    # import the D-Rats main application
    from d_rats import mainapp

    #stores away the value of sys.excepthook
    install_excepthook()

    import libxml2
    libxml2.debugMemory(1)

    # create the mainapp with the basic options
    app = mainapp.MainApp(safe=opts.safe)

    # finally let's open the default application triggering it differently if we
    # want to profile it (which is running the app under profile control to see what happens)
Ejemplo n.º 9
0
 def do_edit_users(but):
     p = dplatform.get_platform()
     p.open_text_file(p.config_file("users.txt"))