def term_reconnect(self, host_settings):
        global Widget_server
        if self.host_settings and self.host_settings != host_settings:
            logging.error("ERROR: Host settings mismatch: %s vs. %s" % (self.host_settings, host_settings))

        self.host_settings = host_settings

        if self.connection_id != gterm.LOCAL_HOST and not self.log_filename and (self.host_settings["logging"] or Options.logging):
            self.log_filename = os.path.join(gterm.App_dir, "gtermhost.log")
            gterm.setup_logging(logging.WARNING, self.log_filename, logging.INFO)
            logging.warning("*************************Logging to file %s", self.log_filename)

        if self.host_settings["widget_port"] > 0:
            self.widget_port = widget_port
        elif self.host_settings["widget_port"] < 0:
            self.widget_port = gterm.DEFAULT_HTTP_PORT-2 if self.connection_id == gterm.LOCAL_HOST else gterm.WIDGET_BASE_PORT+os.getuid()
        else:
            self.widget_port = 0
        
        if self.host_settings["blob_host"] == "wildcard":
            self.blob_server = ("https" if self.host_settings["https"] else "http") + "://*." + self.host + ":" + str(self.port+1)
        elif self.host_settings["blob_host"]:
            self.blob_server = ("https" if self.host_settings["https"] else "http") + "://" + self.host_settings["blob_host"] + ":" + str(self.port+1)
        else:
            self.blob_server = ""

        if self.widget_port and not Widget_server:
            Widget_server = WidgetServer()
            Widget_server.listen(self.widget_port, address="localhost")
            logging.warning("GraphTerm widgets listening on %s:%s", "localhost", self.widget_port)
def main():
    global Options
    from optparse import OptionParser
    usage = "usage: gtermhost [-h ... options] <hostname>"
    parser = OptionParser(usage=usage)

    parser.add_option("", "--server_addr", dest="server_addr", default="localhost",
                      help="Server hostname (or IP address) (default: localhost)")
    parser.add_option("", "--server_port", dest="server_port", default=0,
                      help="Server port (default: %d)" % gterm.DEFAULT_HOST_PORT, type="int")
    parser.add_option("", "--external_host", dest="external_host", default="",
                      help="external host name (or IP address), if different from server_addr")
    parser.add_option("", "--remote_port", dest="remote_port", default=0,
                      help="actual remote port, if different from server_port", type="int")
    parser.add_option("", "--auth_file", dest="auth_file", default="",
                      help="Server auth file")

    parser.add_option("", "--oshell", dest="oshell", action="store_true",
                      help="Activate otrace/oshell")
    parser.add_option("", "--oshell_input", dest="oshell_input", action="store_true",
                      help="Allow stdin input otrace/oshell")
    parser.add_option("", "--internal_certfile", dest="internal_certfile", default="",
                      help="Internal SSL certfile")
    parser.add_option("", "--logging", dest="logging", action="store_true",
                      help="Log to ~/.graphterm/gtermhost.log")
    parser.add_option("", "--lterm_logfile", dest="lterm_logfile", default="",
                      help="Lineterm logfile")

    parser.add_option("", "--daemon", dest="daemon", default="",
                      help="daemon=start/stop/restart/status")

    (Options, args) = parser.parse_args()
    if len(args) != 1 and Options.daemon != "stop":
        print >> sys.stderr, usage
        sys.exit(1)

    if not args or not HOST_RE.match(args[0]):
        print >> sys.stderr, "Invalid/missing host name"
        sys.exit(1)

    gterm.setup_logging(logging.ERROR)

    if not Options.daemon:
        run_host(Options, args)
    else:
        from daemon import ServerDaemon
        host_name = args[0]
        pidfile = "/tmp/gtermhost."+host_name+".pid"
        daemon = ServerDaemon(pidfile, functools.partial(run_host, Options, args))
        daemon.daemon_run(Options.daemon)
Beispiel #3
0
    def term_reconnect(self, host_settings):
        global Widget_server
        if self.host_settings and self.host_settings != host_settings:
            logging.error("ERROR: Host settings mismatch: %s vs. %s" %
                          (self.host_settings, host_settings))

        self.host_settings = host_settings

        if self.connection_id != gterm.LOCAL_HOST and not self.log_filename and (
                self.host_settings["logging"] or Options.logging):
            self.log_filename = os.path.join(gterm.App_dir, "gtermhost.log")
            gterm.setup_logging(logging.WARNING, self.log_filename,
                                logging.INFO)
            logging.warning("*************************Logging to file %s",
                            self.log_filename)

        if self.host_settings["widget_port"] > 0:
            self.widget_port = widget_port
        elif self.host_settings["widget_port"] < 0:
            self.widget_port = gterm.DEFAULT_HTTP_PORT - 2 if self.connection_id == gterm.LOCAL_HOST else gterm.WIDGET_BASE_PORT + os.getuid(
            )
        else:
            self.widget_port = 0

        if self.host_settings["blob_host"] == "wildcard":
            self.blob_server = (
                "https" if self.host_settings["https"] else
                "http") + "://*." + self.host + ":" + str(self.port + 1)
        elif self.host_settings["blob_host"]:
            self.blob_server = (
                "https" if self.host_settings["https"] else "http"
            ) + "://" + self.host_settings["blob_host"] + ":" + str(self.port +
                                                                    1)
        else:
            self.blob_server = ""

        if self.widget_port and not Widget_server:
            Widget_server = WidgetServer()
            Widget_server.listen(self.widget_port, address="localhost")
            logging.warning("GraphTerm widgets listening on %s:%s",
                            "localhost", self.widget_port)
Beispiel #4
0
def main():
    global Options
    from optparse import OptionParser
    usage = "usage: gtermhost [-h ... options] <hostname>"
    parser = OptionParser(usage=usage)

    parser.add_option(
        "",
        "--server_addr",
        dest="server_addr",
        default="localhost",
        help="Server hostname (or IP address) (default: localhost)")
    parser.add_option("",
                      "--server_port",
                      dest="server_port",
                      default=0,
                      help="Server port (default: %d)" %
                      gterm.DEFAULT_HOST_PORT,
                      type="int")
    parser.add_option(
        "",
        "--external_host",
        dest="external_host",
        default="",
        help="external host name (or IP address), if different from server_addr"
    )
    parser.add_option("",
                      "--remote_port",
                      dest="remote_port",
                      default=0,
                      help="actual remote port, if different from server_port",
                      type="int")
    parser.add_option("",
                      "--auth_file",
                      dest="auth_file",
                      default="",
                      help="Server auth file")

    parser.add_option("",
                      "--oshell",
                      dest="oshell",
                      action="store_true",
                      help="Activate otrace/oshell")
    parser.add_option("",
                      "--oshell_input",
                      dest="oshell_input",
                      action="store_true",
                      help="Allow stdin input otrace/oshell")
    parser.add_option("",
                      "--internal_certfile",
                      dest="internal_certfile",
                      default="",
                      help="Internal SSL certfile")
    parser.add_option("",
                      "--logging",
                      dest="logging",
                      action="store_true",
                      help="Log to ~/.graphterm/gtermhost.log")
    parser.add_option("",
                      "--lterm_logfile",
                      dest="lterm_logfile",
                      default="",
                      help="Lineterm logfile")

    parser.add_option("",
                      "--daemon",
                      dest="daemon",
                      default="",
                      help="daemon=start/stop/restart/status")

    (Options, args) = parser.parse_args()
    if len(args) != 1 and Options.daemon != "stop":
        print >> sys.stderr, usage
        sys.exit(1)

    if not args or not HOST_RE.match(args[0]):
        print >> sys.stderr, "Invalid/missing host name"
        sys.exit(1)

    gterm.setup_logging(logging.ERROR)

    if not Options.daemon:
        run_host(Options, args)
    else:
        from daemon import ServerDaemon
        host_name = args[0]
        pidfile = "/tmp/gtermhost." + host_name + ".pid"
        daemon = ServerDaemon(pidfile,
                              functools.partial(run_host, Options, args))
        daemon.daemon_run(Options.daemon)