Esempio n. 1
0
    def do_browse(self, _, dir):
        if self.filename.get_text():
            start = os.path.dirname(self.filename.get_text())
        else:
            start = None

        if dir:
            fn = platform.get_platform().gui_select_dir(start)
        else:
            fn = platform.get_platform().gui_save_file(start)
        if fn:
            self.filename.set_text(fn)
Esempio n. 2
0
    def _refresh_lang(self):
        locales = {
            "English": "en",
            "German": "de",
            "Italiano": "it",
            "Dutch": "nl",
        }
        locale = locales.get(self.config.get("prefs", "language"), "English")
        print(f"Loading locale `{locale}'")

        localedir = os.path.join(platform.get_platform().source_dir(),
                                 "locale")
        print(f"Locale dir is: {localedir}")

        if not os.environ.has_key("LANGUAGE"):
            os.environ["LANGUAGE"] = locale

        try:
            lang = gettext.translation("D-RATS",
                                       localedir=localedir,
                                       languages=[locale])
            lang.install()
            gtk.glade.bindtextdomain("D-RATS", localedir)
            gtk.glade.textdomain("D-RATS")
        except LookupError:
            print(f"Unable to load language `{locale}'")
            gettext.install("D-RATS")
        except IOError as e:
            print(f"Unable to load translation for {locale}: {e}")
            gettext.install("D-RATS")
    def __init__(self):
        self.repeater = None
        self.tap = None
        self.tick = 0

        self.platform = platform.get_platform()
        self.config = self.load_config()
Esempio n. 4
0
def main():
    from optparse import OptionParser

    o = OptionParser()
    o.add_option("-c", "--config",
                 dest="config",
                 help="Use alternate configuration directory")
    o.add_option("-d", "--debug",
                 dest="debug",
                 action="store_true",
                 help="Show debug messages on stdout")
    o.add_option("-C", "--console",
                 dest="console",
                 action="store_true",
                 help="Run in console mode only")
    (opts, args) = o.parse_args()

    if opts.config:
        platform.get_platform(opts.config)
Esempio n. 5
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 = platform.get_platform()
        fn = p.gui_save_file(default_name="%s.xml" % _id)
        if fn:
            shutil.copy(filename, fn)
Esempio n. 6
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 = platform.get_platform()
        fn = p.gui_save_file(default_name="%s.xml" % _id)
        if fn:
            shutil.copy(filename, fn)
Esempio n. 7
0
    def but_import(self, widget, data=None):
        p = platform.get_platform()
        fn = p.gui_open_file()
        if not fn:
            return

        try:
            form_id = self.add_form(fn)
        except Exception, 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()
Esempio n. 8
0
    def but_import(self, widget, data=None):
        p = platform.get_platform()
        fn = p.gui_open_file()
        if not fn:
            return

        try:
            form_id = self.add_form(fn)
        except Exception, 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()
Esempio n. 9
0
def main():
    o = OptionParser()
    o.add_option("-s", "--safe",
                 dest="safe",
                 action="store_true",
                 help="Safe mode (ignore configuration)")
    o.add_option("-c", "--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()

    from d_rats import platform

    if opts.config:
        platform.get_platform(opts.config)

    from d_rats import mainapp

    install_excepthook()

    import libxml2

    libxml2.debugMemory(1)

    app = mainapp.MainApp(safe=opts.safe)
    if opts.profile:
        import cProfile
        cProfile.run('app.main()')
    else:
        rc = app.main()
        uninstall_excepthook()
        libxml2.dumpMemory()
        sys.exit(rc)
    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 = platform.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)
Esempio n. 11
0
def run_lzhuf(cmd, data):
    p = platform.get_platform()

    cwd = tempfile.mkdtemp()

    f = file(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"]

    print(("Running %s in %s" % (run, cwd)))

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

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

    return data
Esempio n. 12
0
def run_lzhuf(cmd, data):
    p = platform.get_platform()

    cwd = tempfile.mkdtemp()

    f = file(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"]
    
    print "Running %s in %s" % (run, cwd)

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

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

    return data
Esempio n. 13
0
 def _announce_self(self):
     print(("-" * 75))
     print(f"D-RATS v{version.DRATS_VERSION} starting at {time.asctime()}")
     print(platform.get_platform())
     print(("-" * 75))
Esempio n. 14
0
    def main(self):
        # Copy default forms before we start

        distdir = platform.get_platform().source_dir()
        userdir = self.config.form_source_dir()
        dist_forms = glob.glob(os.path.join(distdir, "forms", "*.x?l"))
        for form in dist_forms:
            fname = os.path.basename(form)
            user_fname = os.path.join(userdir, fname)

            try:
                needupd = \
                    (os.path.getmtime(form) > os.path.getmtime(user_fname))
            except Exception:
                needupd = True
            if not os.path.exists(user_fname) or needupd:
                print(f"Installing dist form {fname} -> {user_fname}")
                try:
                    shutil.copyfile(form, user_fname)
                except Exception as e:
                    print(f"FAILED: {s}")

        self.clear_all_msg_locks()

        if len(self.config.options("ports")) == 0 and \
                self.config.has_option("settings", "port"):
            print("Migrating single-port config to multi-port")

            port = self.config.get("settings", "port")
            rate = self.config.get("settings", "rate")
            snif = self.config.getboolean("settings", "sniff_packets")
            comp = self.config.getboolean("settings", "compatmode")

            self.config.set(
                "ports", "port_0", "%s,%s,%s,%s,%s,%s" %
                (True, port, rate, snif, comp, "DEFAULT"))
            for i in ["port", "rate", "sniff_packets", "compatmode"]:
                self.config.remove_option("settings", i)

        try:
            self.plugsrv = pluginsrv.DRatsPluginServer()
            self.__connect_object(self.plugsrv.get_proxy())
            self.plugsrv.serve_background()
        except Exception as e:
            print(f"Unable to start plugin server: {e}")
            self.plugsrv = None

        self.load_static_routes()

        try:
            self.msgrouter = msgrouting.MessageRouter(self.config)
            self.__connect_object(self.msgrouter)
            self.msgrouter.start()
        except Exception as e:
            log_exception()
            self.msgrouter = None

        try:
            gtk.main()
        except KeyboardInterrupt:
            pass
        except Exception as e:
            print(f"Got exception on close: {e}")

        print("Saving config...")
        self.config.save()

        if self.config.getboolean("prefs", "dosignoff") and self.sm:
            msg = self.config.get("prefs", "signoff")
            status = station_status.STATUS_OFFLINE
            for port in self.sm.keys():
                self.chat_session(port).advertise_status(status, msg)

            time.sleep(0.5)  # HACK
Esempio n. 15
0
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

import sys
# Name collision with python standard module
import d_rats.platform as platform
import os

debug_path = platform.get_platform().config_file("debug.log")
# Fixme - 3 lines have been commented out for debugging purposes
if sys.platform == "win32" or not os.isatty(0):
    #    sys.stdout = file(debug_path, "w", 0)
    #    sys.stdout = open(debug_path, "w")
    #    sys.stderr = sys.stdout
    print("Enabled debug log")
else:
    try:
        os.unlink(debug_path)
    except OSError:
        pass

import gettext
gettext.install("D-RATS")
Esempio n. 16
0
    o.add_option("-c", "--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 platform

    if opts.config:
        print "D-Rats: re-config option found -- Reconfigure D-rats"
        platform.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)

 def do_edit_users(but):
     p = platform.get_platform()
     p.open_text_file(p.config_file("users.txt"))
Esempio n. 18
0
                 help="Safe mode (ignore configuration)")
    o.add_option("-c",
                 "--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()

    from d_rats import platform

    if opts.config:
        platform.get_platform(opts.config)

    from d_rats import mainapp

    install_excepthook()

    import libxml2

    libxml2.debugMemory(1)

    app = mainapp.MainApp(safe=opts.safe)
    if opts.profile:
        import cProfile
        cProfile.run('app.main()')
    else:
        rc = app.main()
Esempio n. 19
0
 def ping_data(self):
     p = platform.get_platform()
     return _("Running") + " D-RATS %s (%s)" % (DRATS_VERSION,
                                                p.os_version_string())
Esempio n. 20
0
        self.repeater.repeat()

        while True:
            try:
                time.sleep(0.25)
            except KeyboardInterrupt:
                self.repeater.stop()
                break
       

if __name__=="__main__":
    import sys


    if not opts.debug:
        p = platform.get_platform()
        f = file(p.config_file("repeater.log"), "w", 0)
        if f:
            sys.stdout = f
            sys.stderr = f
        else:
            print "Failed to open log"

    if opts.console:
        r = RepeaterConsole()
        r.main()
    else:
        import gtk
        import gobject
        from d_rats.miscwidgets import make_choice
        from d_rats import miscwidgets