def __init__(self):
        self.AllowIPs = ""
        self.IP = "0.0.0.0"

        self.CGIdata = CGIdata.CGI_data_Parser()
        self.EnvironData = CGIdata.environ_data_Parser()

        self.read_config()
        self.parse_request()
        self.do_request()
Example #2
0
def start_module(selfURL):
    if not CGIdata.has_key("file"):
        menu.Menu()  # HTML-Seite aufbauen
        error("no filename!")

    filename = urllib.unquote(CGIdata["file"])

    menu.cfg.title = "Viewer [%s]" % filename
    menu.Menu()  # HTML-Seite aufbauen

    if not os.path.isfile(filename):
        error("File [%s] does not exists!" % filename)

    print "<h3>%s</h3>" % filename

    print "<hr><pre>"

    f = file(filename, "r")
    while 1:
        line = f.readline()
        if line == "": break
        print line

    print "</pre><hr>"

    menu.print_footer()
Example #3
0
def start_module(selfURL):
    if not CGIdata.has_key("file"):
        menu.Menu()  # HTML-Seite aufbauen
        error("no filename!")

    filename = urllib.unquote(CGIdata["file"])

    menu.cfg.title = "Viewer [%s]" % filename
    menu.Menu()  # HTML-Seite aufbauen

    if not os.path.isfile(filename):
        error("File [%s] does not exists!" % filename)

    print "<h3>%s</h3>" % filename

    print "<hr><pre>"

    f = file(filename, "r")
    while 1:
        line = f.readline()
        if line == "":
            break
        print line

    print "</pre><hr>"

    menu.print_footer()
    def __init__(self):
        self.AllowIPs = ""
        self.IP = "0.0.0.0"

        self.CGIdata = CGIdata.CGI_data_Parser()
        self.EnvironData = CGIdata.environ_data_Parser()

        self.read_config()
        self.parse_request()
        self.do_request()
def start_module(selfURL):
    if CGIdata.has_key("cwd") and os.path.isdir(CGIdata["cwd"]):
        current_dir = CGIdata["cwd"]
    else:
        current_dir = "/"

    menu.cfg.css = "filebrowser.css"
    menu.cfg.title = "FileBrowser"
    menu.cfg.headings = head_script % {"current_dir": current_dir}
    menu.Menu()

    print html_start % {"current_dir": current_dir}

    #~ time.sleep(1) # Beim verwenden vom ThreadingServer wichtig!

    # Verz-Tabelle ausgeben
    FileBrowser(current_dir, selfURL)

    # Fussdaten ausgeben
    print html_end
def start_module( selfURL ):
    if CGIdata.has_key("cwd") and os.path.isdir( CGIdata["cwd"] ):
        current_dir = CGIdata["cwd"]
    else:
        current_dir = "/"

    menu.cfg.css        = "filebrowser.css"
    menu.cfg.title      = "FileBrowser"
    menu.cfg.headings   = head_script % { "current_dir" : current_dir }
    menu.Menu()

    print html_start % { "current_dir" : current_dir }

    #~ time.sleep(1) # Beim verwenden vom ThreadingServer wichtig!

    # Verz-Tabelle ausgeben
    FileBrowser( current_dir, selfURL )

    # Fussdaten ausgeben
    print html_end
    menu.Menu()

    print html_start % {"current_dir": current_dir}

    #~ time.sleep(1) # Beim verwenden vom ThreadingServer wichtig!

    # Verz-Tabelle ausgeben
    FileBrowser(current_dir, selfURL)

    # Fussdaten ausgeben
    print html_end


if __name__ == "__main__":
    selfURL = os.environ['SCRIPT_NAME']

    CGIdata = CGIdata.GetCGIdata()

    start_module(selfURL)


def inetd_start():
    "durch inetd-Server gestartet"
    selfURL = "FileBrowser"

    #~ print "FileBrowser!"
    #~ print "CGIdata:"
    #~ print CGIdata

    start_module(selfURL)
def start_module( selfURL ):

    print "Content-Type: text/html\n\n"

    ## Konfiguration lesen
    cfg = config.Parser()
    cfg.set_section("console")
    maxHistoryLines         = cfg.get( "maxHistoryLines", "int" )
    forceHTMLCompression    = cfg.get( "forceCompression" )

    # Breite der Eingabe Zeile
    input_size              = cfg.get( "input size", "int" )

    # Standartd Timeout in sek für jeden Befehl
    process_timeout         = cfg.get( "process timeout", "int" )

    # ZusatzInfornationen Anzeigen
    verbose                 = cfg.get( "verbose", "boolean" )



    #~ MyOut = CompressedOut.AutoCompressedOut( forceHTMLCompression )
    #~ print "<!-- Out-Compression:'%s' -->" % MyOut.get_mode()
    #~ for i in os.environ: print i,os.environ[i],"<br>"



    # HTML-Pre Ausgeben
    print htmlPre % {
        "charset"       : locale.getdefaultlocale()[1],
        "uname"         : os.uname()
    }




    if CGIdata.has_key("stdout"):
        # Alte Ausgaben wieder anzeigen
        txt = CGIdata["stdout"]
        compressLen = len( txt )
        txt = decompress( txt )  # Ausgaben dekomprimieren

        decompressLen = len( txt )
        MyOutConverter.put_data( txt )
        print txt.replace( "\n", "<br>\n" )
    else:
        compressLen = 0
        decompressLen = 0
        txt = ""


    ## Alte Verzeichnis wieder herstellen
    if CGIdata.has_key("current_dir") and os.path.isdir( CGIdata["current_dir"] ):
        current_dir = CGIdata["current_dir"]
        # Ins alte Verzeichnis wechseln
        os.chdir( current_dir )
    else:
        current_dir = os.getcwd()


    ## Process Timeout Lesen und Anzeigen
    if CGIdata.has_key("timeout"):
        process_timeout = int( CGIdata["timeout"] )


    ## Befehl Ausführen
    if CGIdata.has_key("cmd"):
        command = CGIdata["cmd"]
        # Prompt mit Befehl anzeigen
        prompt = "<p><strong>%s>%s</strong></p>\n" % (current_dir, command)
        print prompt
        # Prompt auch in die History speichern
        MyOutConverter.put_data( prompt )

        print "<p><small>Process Timeout: %dsec.</small></p>" % process_timeout

        if command.startswith("cd "):
            # Verzeichnis wechsel
            destination_dir = command[3:]
            destination_dir = os.path.join( current_dir, destination_dir )
            destination_dir = os.path.normpath( destination_dir )
            if os.path.isdir( destination_dir ):
                # Neuer Zielpfad existiert
                current_dir = destination_dir
            else:
                print "Directory [%s] does not exists<br>" % destination_dir
        else:
            # Befehl ausführen
            cmd( command, current_dir, process_timeout )

    # Neues, aktuelles Prompt anzeigen
    print "<strong>%s&gt;</strong>" % current_dir

    # Ausgaben kürzen und Komprimieren, damit der Client weniger Daten wieder zurück senden muß
    # Die Kompression zahlt sich nach zwei, drei Befehlen i.d.R. aus...
    stdout_raw = compress( cutLines( MyOutConverter.get_data(), maxHistoryLines ) )
    #~ stdout_raw = MyOutConverter.get_data()

    if verbose:
        print "<p><small>compress: %d  decompress: %d<br />" % (compressLen, decompressLen)
        print "(console - 'verbose mode')</small></p>"


    print htmlPost % {
        "self"              : selfURL,
        "stdout_raw"        : stdout_raw,
        "current_dir"       : current_dir,
        "input_size"        : input_size,
        "process_timeout"   : str( process_timeout )
        }
Example #9
0
def start_module( selfURL ):
    # HTML-Pre Ausgeben
    print htmlPre % {
        "charset"       : locale.getdefaultlocale()[1],
        "uname"         : os.uname()
    }

    if CGIdata.has_key("exit"):
        print "EXIT!"
        sys.exit()



    if CGIdata.has_key("edit_file"):
        file_name = CGIdata["edit_file"]
    else:
        file_name = ""



    file_content = ""
    if CGIdata.has_key("edit"):
        "Eine neue Datei soll editiert werden"
        if file_name == "":
            print "no file specified!"
            sys.exit()
        file_content = get_edit_file( CGIdata["edit_file"] )


    if CGIdata.has_key("save"):
        "Änderungen sollen abgespeichert werden"
        if file_name == "":
            print "no file specified!"
            sys.exit()

        if CGIdata.has_key("backup"):
            backup_oldfile = True
        else:
            backup_oldfile = False


        print "save [%s]<br>" % file_name
        print "Backup:", backup_oldfile
        print "<hr>"
        if not CGIdata.has_key("textfield"):
            print "error no textfield found!"
            sys.exit()

        new_content = CGIdata["textfield"].strip()
        print "<pre>%s</pre>" % new_content
        print "<hr>"
        save_new_content( file_name, new_content, backup_oldfile )



    print htmlPost % {
        "self"          : selfURL,
        "file_content"  : file_content,
        "file_name"     : file_name,
        "cwd"           : os.path.split( file_name )[0]
        }
Example #10
0
def start_module( selfURL ):
    menu.cfg.title = "console@" + str( os.uname() )
    menu.Menu()

    #~ # HTML-Pre Ausgeben
    #~ print htmlPre % {
        #~ "charset"       : locale.getdefaultlocale()[1],
        #~ "uname"         : os.uname()
    #~ }

    ## Konfiguration lesen
    cfg = config.Parser()
    cfg.set_section("console")
    maxHistoryLines         = cfg.get( "maxHistoryLines", "int" )
    forceHTMLCompression    = cfg.get( "forceCompression" )

    # Breite der Eingabe Zeile
    input_size              = cfg.get( "input size", "int" )

    # Standartd Timeout in sek für jeden Befehl
    process_timeout         = cfg.get( "process timeout", "int" )

    # ZusatzInfornationen Anzeigen
    verbose                 = cfg.get( "verbose", "boolean" )



    #~ MyOut = CompressedOut.AutoCompressedOut( forceHTMLCompression )
    #~ print "<!-- Out-Compression:'%s' -->" % MyOut.get_mode()
    #~ for i in os.environ: print i,os.environ[i],"<br>"



    if CGIdata.has_key("stdout"):
        # Alte Ausgaben wieder anzeigen
        txt = CGIdata["stdout"]
        compressLen = len( txt )
        txt = decompress( txt )  # Ausgaben dekomprimieren

        decompressLen = len( txt )
        MyOutConverter.put_data( txt )
        print txt.replace( "\n", "<br>\n" )
    else:
        compressLen = 0
        decompressLen = 0
        txt = ""


    ## Alte Verzeichnis wieder herstellen
    if CGIdata.has_key("current_dir") and os.path.isdir( CGIdata["current_dir"] ):
        current_dir = CGIdata["current_dir"]
        # Ins alte Verzeichnis wechseln
        os.chdir( current_dir )
    else:
        current_dir = os.getcwd()


    ## Process Timeout Lesen und Anzeigen
    if CGIdata.has_key("timeout"):
        process_timeout = int( CGIdata["timeout"] )


    ## Befehl Ausführen
    if CGIdata.has_key("cmd"):
        command = CGIdata["cmd"]
        # Prompt mit Befehl anzeigen
        prompt = "<p><strong>%s>%s</strong></p>\n" % (current_dir, command)
        print prompt
        # Prompt auch in die History speichern
        MyOutConverter.put_data( prompt )

        print "<p><small>Process Timeout: %dsec.</small></p>" % process_timeout

        if command.startswith("cd "):
            # Verzeichnis wechsel
            destination_dir = command[3:]
            destination_dir = os.path.join( current_dir, destination_dir )
            destination_dir = os.path.normpath( destination_dir )
            if os.path.isdir( destination_dir ):
                # Neuer Zielpfad existiert
                current_dir = destination_dir
            else:
                print "Directory [%s] does not exists<br>" % destination_dir
        else:
            # Befehl ausführen
            cmd( command, current_dir, process_timeout )

    # Neues, aktuelles Prompt anzeigen
    print "<strong>%s&gt;</strong>" % current_dir

    # Ausgaben kürzen und Komprimieren, damit der Client weniger Daten wieder zurück senden muß
    # Die Kompression zahlt sich nach zwei, drei Befehlen i.d.R. aus...
    stdout_raw = compress( cutLines( MyOutConverter.get_data(), maxHistoryLines ) )
    #~ stdout_raw = MyOutConverter.get_data()

    if verbose:
        print "<p><small>compress: %d  decompress: %d<br />" % (compressLen, decompressLen)
        print "(console - 'verbose mode')</small></p>"


    print console_form % {
        "self"              : selfURL,
        "stdout_raw"        : stdout_raw,
        "current_dir"       : current_dir,
        "input_size"        : input_size,
        "process_timeout"   : str( process_timeout )
        }

    menu.print_footer()





# HTML-Pre Ausgeben
print htmlPre % {
    "charset"       : locale.getdefaultlocale()[1],
    "uname"         : os.uname()
}




if CGIdata.has_key("stdout"):
    # Alte Ausgaben wieder anzeigen
    txt = CGIdata["stdout"]
    compressLen = len( txt )
    # Ausgaben dekomprimieren
    txt = decompress( txt )
    decompressLen = len( txt )
    MyOutConverter.put_data( txt )
    print txt.replace("\n","<br>\n")
else:
    compressLen = 0
    decompressLen = 0
    txt = ""


## Alte Verzeichnis wieder herstellen
def compress(txt):
    txt = bz2.compress(txt, 9)
    return base64.urlsafe_b64encode(txt).replace("\n", "")


def decompress(txt):
    txt = base64.urlsafe_b64decode(txt)
    return bz2.decompress(txt)


def cutLines(txt, maxLines):
    "Schneidet aus dem String >txt< >maxLines<-Anzahl Zeilen von unten ab"
    return '\n'.join(txt.splitlines()[-maxLines:])


CGIdata = CGIdata.GetCGIdata()


class OutConverter:
    def __init__(self):
        self.data = ""

    def write(self, txt):
        sys.stdout.write(txt)

    def flush(self):
        sys.stdout.flush()

    def readOutData(self, readObj):
        writer = ansi2html.Writer(MyOutConverter, ansi2html_normalColor)
        while 1: