Exemple #1
0
def main():
    usage = "usage: %prog [-a admin_username] username"
    parser = OptionParser(usage=usage)
    parser.add_option("-a", "--admin", dest="admin", default="",
                      help="Admin username")
    parser.add_option("-s", "--server", dest="server", default="localhost",
                      help="External server name (default: localhost)")
    parser.add_option("-w", "--write",
                      action="store_true", dest="write", default=False,
                      help="Write authentication file for user (for superuser use)")

    (options, args) = parser.parse_args()

    if not args:
        print >> sys.stderr, parser.get_usage()
        sys.exit(1)

    user = args[0]

    if options.admin:
        admin_dir = os.path.join(os.path.expanduser("~"+options.admin), gterm.APP_DIRNAME)
    else:
        admin_dir = gterm.App_dir

    auth_code, port = gterm.read_auth_code(appdir=admin_dir, server=options.server)
    user_code = gterm.user_hmac(auth_code, user, key_version="1")
    if not options.write:
        print gterm.dashify(user_code)
    else:
        user_dir = os.path.join(os.path.expanduser("~"+user), gterm.APP_DIRNAME)
        gterm.create_app_directory(appdir=user_dir)
        gterm.write_auth_code(user_code, appdir=user_dir, user=user, server=options.server)
Exemple #2
0
def main():
    usage = "usage: %prog [-h ... ] username"
    parser = gterm.FormParser(usage=usage, title="Display graphterm authentication code for user: "******"gauth")
    parser.add_argument(label="", help="Username")
    parser.add_option("admin", "ubuntu", short="a", help="Admin username (default: ubuntu)")
    parser.add_option("head", "", help="Head portion of message")
    parser.add_option("mail", False, short="m", help="Display info for mailing etc.")
    parser.add_option("notebook", False, short="n", help="Display notebook URL")
    parser.add_option("group", False, short="g", help="Display group code")
    parser.add_option("subject", "GraphTerm remote access", help="Email subject line")
    parser.add_option("server", "", short="s", help="External server name")
    parser.add_option("tail", "", help="Tail portion of message")
    parser.add_option("write", False, short="w", help="Write authentication file for user (for superuser use)")

    (options, args) = parser.parse_args()

    if not args and not options.group:
        sys.exit(parser.get_usage())

    server = options.server or gterm.Server

    user = "" if options.group else args[0]

    if options.admin:
        admin_dir = os.path.join(os.path.expanduser("~"+options.admin), gterm.APP_DIRNAME)
    else:
        admin_dir = gterm.App_dir

    auth_code, port = gterm.read_auth_code(appdir=admin_dir, server=server)
    user_code = gterm.user_hmac(auth_code, "", key_version="grp") if options.group else gterm.user_hmac(auth_code, user, key_version="1")

    if options.mail:
        mail_body = options.head+"\n" if options.head else ""
        mail_body += "\nUser: "******"\n" if user else "\nGroup "
        mail_body += "Code: "+gterm.dashify(user_code)+"\n"
        mail_body += "URL: "+gterm.URL+"\n"
        email_addr = ""
        if user:
            if options.notebook:
                prefix, sep, suffix = gterm.URL.rpartition(":")
                mail_body += "Notebook URL: %s:%d\n" % (prefix if suffix.isdigit() else gterm.URL, gterm.NB_BASE_PORT+pwd.getpwnam(user).pw_uid)
            try:
                with open(os.path.join(os.path.expanduser("~"+user), gterm.APP_DIRNAME, gterm.APP_EMAIL_FILENAME), "r") as f:
                    email_addr = f.read().strip()
            except Exception, excp:
                pass
        mail_body += "\n"+options.tail+"\n" if options.tail else ""
        mail_url = 'mailto:'+email_addr+'?subject='+urllib.quote(options.subject)+'&body='+urllib.quote(mail_body)
        if gterm.Lterm_cookie:
            gterm.wrap_write(mail_body.replace("\n","<br>")+'<p>Click <a href="'+mail_url+'">here</a> to email it')
        else:
            print mail_body
Exemple #3
0
def main():
    usage = "usage: %prog [-a admin_username] username"
    parser = OptionParser(usage=usage)
    parser.add_option("-a",
                      "--admin",
                      dest="admin",
                      default="",
                      help="Admin username")
    parser.add_option("-s",
                      "--server",
                      dest="server",
                      default="localhost",
                      help="External server name (default: localhost)")
    parser.add_option(
        "-w",
        "--write",
        action="store_true",
        dest="write",
        default=False,
        help="Write authentication file for user (for superuser use)")

    (options, args) = parser.parse_args()

    if not args:
        print >> sys.stderr, parser.get_usage()
        sys.exit(1)

    user = args[0]

    if options.admin:
        admin_dir = os.path.join(os.path.expanduser("~" + options.admin),
                                 gterm.APP_DIRNAME)
    else:
        admin_dir = gterm.App_dir

    auth_code, port = gterm.read_auth_code(appdir=admin_dir,
                                           server=options.server)
    user_code = gterm.user_hmac(auth_code, user, key_version="1")
    if not options.write:
        print gterm.dashify(user_code)
    else:
        user_dir = os.path.join(os.path.expanduser("~" + user),
                                gterm.APP_DIRNAME)
        gterm.create_app_directory(appdir=user_dir)
        gterm.write_auth_code(user_code,
                              appdir=user_dir,
                              user=user,
                              server=options.server)
Exemple #4
0
            if not port:
                port = 443 if protocol == "https" else 80
            path = comps[2][1:]

    if not server and gterm.Cookie:
        # Open new terminal window from within graphterm window
        path = path or (gterm.Host + "/" + "new")
        url = gterm.URL + "/" + path
        target = "_blank" if url.endswith("/new") else path
        gterm.open_url(url, target=target)
        return

    if options.noauth:
        auth_code = "none"
    else:
        auth_code, tem_port = gterm.read_auth_code(user=options.user, server=server)
        port = port or tem_port

    Http_addr = server or "localhost"
    Http_port = options.port or port or gterm.DEFAULT_HTTP_PORT

    client_nonce = "1%018d" % random.randrange(0, 10**18)   # 1 prefix to keep leading zeros when stringified

    resp = auth_request(Http_addr, Http_port, client_nonce, user=options.user, protocol=protocol)
    if not resp:
        print >> sys.stderr, "\ngterm: Authentication request to GraphTerm server %s:%s failed" % (Http_addr, Http_port)
        print >> sys.stderr, "gterm: Server may not be running; use 'gtermserver' command to start it."
        sys.exit(1)

    server_nonce, received_token = resp.split(":")
    client_token, server_token = gterm.auth_token(auth_code, "graphterm", Http_addr, Http_port, client_nonce, server_nonce)
Exemple #5
0
def main():
    global Http_addr, Http_port
    from optparse import OptionParser
    usage = "usage: gterm [-h ... options] [[host/]session]"
    parser = OptionParser(usage=usage)

    parser.add_option("", "--https", dest="https", action="store_true",
                      help="Use SSL (TLS) connections for security")
    parser.add_option("-n", "--noauth", dest="noauth", action="store_true",
                      help="No authentication required")
    parser.add_option("-b", "--browser", dest="browser", default="",
                      help="Browser application name (OS X only)")
    parser.add_option("-u", "--user", dest="user", default="",
                      help="User name")
    parser.add_option("-s", "--server", dest="server", default="",
                      help="Remote server domain name")
    parser.add_option("-p", "--port", dest="port", default=0,
                      help="Remote server port", type="int")
    parser.add_option("", "--client_cert", dest="client_cert", default="",
                      help="Path to client CA cert (or '.')")
    #parser.add_option("", "--term_type", dest="term_type", default="",
    #                  help="Terminal type (linux/screen/xterm) NOT YET IMPLEMENTED")

    (options, args) = parser.parse_args()
    protocol = "https" if options.https else "http"

    path = ""
    if args:
        if "/" in args[0]:
            path = args[0]
        else:
            path = (gterm.Host or "local") + "/" + args[0]

    if not options.server and gterm.Lterm_cookie:
        # Open new terminal window from within graphterm window
        path = path or (gterm.Host + "/" + "new")
        url = gterm.URL + "/" + path
        target = "_blank" if url.endswith("/new") else path
        gterm.open_url(url, target=target)
        return

    if options.noauth:
        auth_code = "none"
        port = None
    else:
        auth_code, port = gterm.read_auth_code(user=options.user, server=options.server)

    Http_addr = options.server or "localhost"
    Http_port = options.port or port or gterm.DEFAULT_HTTP_PORT

    client_nonce = "1%018d" % random.randrange(0, 10**18)   # 1 prefix to keep leading zeros when stringified

    resp = auth_request(Http_addr, Http_port, client_nonce, user=options.user, protocol=protocol)
    if not resp:
        print >> sys.stderr, "\ngterm: Authentication request to GraphTerm server %s:%s failed" % (Http_addr, Http_port)
        print >> sys.stderr, "gterm: Server may not be running; use 'gtermserver' command to start it."
        sys.exit(1)

    server_nonce, received_token = resp.split(":")
    client_token, server_token = gterm.auth_token(auth_code, "graphterm", Http_addr, Http_port, client_nonce, server_nonce)
    if received_token != client_token:
        print >> sys.stderr, "gterm: GraphTerm server %s:%s failed to authenticate itself (Check port number, if necessary)" % (Http_addr, Http_port)
        sys.exit(1)

    ##print >> sys.stderr, "**********snonce", server_nonce, client_token, server_token

    # Open graphterm window using browser
    url = "%s://%s:%d" % (protocol, Http_addr, Http_port)
    if path:
        url += "/" + path
    code = gterm.compute_hmac(auth_code, server_nonce)
    url += "/?cauth="+server_nonce+"&code="+code
    if options.user:
        url += "&user="******"gterm: ERROR in opening browser window '%s' - %s\n Check if server is running. If not, start it with 'gtermserver' command." % (" ".join(command_args), std_err)
        sys.exit(1)
Exemple #6
0
def main():
    username = getpass.getuser()
    usage = "usage: %prog [-h ... ] username"
    parser = gterm.FormParser(
        usage=usage,
        title="Display graphterm authentication code for user: "******"gauth")
    parser.add_argument(label="", help="Username")
    parser.add_option("admin",
                      username,
                      short="a",
                      help="Admin username (default: %s)" % username)
    parser.add_option("head", "", help="Head portion of message")
    parser.add_option("mail",
                      False,
                      short="m",
                      help="Display info for mailing etc.")
    parser.add_option("notebook",
                      False,
                      short="n",
                      help="Display notebook URL")
    parser.add_option("group", False, short="g", help="Display group code")
    parser.add_option("subject",
                      "GraphTerm remote access",
                      help="Email subject line")
    parser.add_option("server", "", short="s", help="External server name")
    parser.add_option("tail", "", help="Tail portion of message")
    parser.add_option(
        "write",
        False,
        short="w",
        help="Write authentication file for user (for superuser use)")

    (options, args) = parser.parse_args()

    if not args and not options.group:
        sys.exit(parser.get_usage())

    server = options.server or gterm.Server

    user = "" if options.group else args[0]

    if options.admin:
        admin_dir = os.path.join(os.path.expanduser("~" + options.admin),
                                 gterm.APP_DIRNAME)
    else:
        admin_dir = gterm.App_dir

    if options.group:
        user_code = gterm.read_param_file(gterm.APP_GROUPCODE_FILENAME) or ""
    else:
        auth_code, port = gterm.read_auth_code(appdir=admin_dir, server=server)
        user_code = gterm.dashify(
            gterm.user_hmac(auth_code, user, key_version="1"))

    if options.mail:
        mail_body = options.head + "\n" if options.head else ""
        mail_body += "\nUser: "******"\n" if user else "\nGroup "
        mail_body += "Code: " + user_code + "\n"
        mail_body += "URL: " + gterm.URL + "\n"
        email_addr = ""
        if user:
            if options.notebook:
                prefix, sep, suffix = gterm.URL.rpartition(":")
                mail_body += "Notebook URL: %s:%d\n" % (
                    prefix if suffix.isdigit() else gterm.URL,
                    gterm.NB_BASE_PORT + pwd.getpwnam(user).pw_uid)
            try:
                with open(
                        os.path.join(os.path.expanduser("~" + user),
                                     gterm.APP_DIRNAME,
                                     gterm.APP_EMAIL_FILENAME), "r") as f:
                    email_addr = f.read().strip()
            except Exception as excp:
                pass
        mail_body += "\n" + options.tail + "\n" if options.tail else ""
        mail_url = 'mailto:' + email_addr + '?subject=' + quote(
            options.subject) + '&body=' + quote(mail_body)
        if gterm.Cookie:
            gterm.wrap_write(
                mail_body.replace("\n", "<br>") + '<p>Click <a href="' +
                mail_url + '">here</a> to email it')
        else:
            print(mail_body)
    elif options.write and not options.group and user_code:
        user_dir = os.path.join(os.path.expanduser("~" + user),
                                gterm.APP_DIRNAME)
        gterm.create_app_directory(appdir=user_dir)
        gterm.write_auth_code(user_code,
                              appdir=user_dir,
                              user=user,
                              server=server)
    else:
        print(user_code)
Exemple #7
0
def main():
    global Http_addr, Http_port
    from optparse import OptionParser
    usage = "usage: gterm [-h ... options] [[host/]session]"
    parser = OptionParser(usage=usage)

    parser.add_option("",
                      "--https",
                      dest="https",
                      action="store_true",
                      help="Use SSL (TLS) connections for security")
    parser.add_option("-n",
                      "--noauth",
                      dest="noauth",
                      action="store_true",
                      help="No authentication required")
    parser.add_option("-b",
                      "--browser",
                      dest="browser",
                      default="",
                      help="Browser application name (OS X only)")
    parser.add_option("-u",
                      "--user",
                      dest="user",
                      default="",
                      help="User name")
    parser.add_option("-s",
                      "--server",
                      dest="server",
                      default="",
                      help="Remote server domain name")
    parser.add_option("-p",
                      "--port",
                      dest="port",
                      default=0,
                      help="Remote server port",
                      type="int")
    parser.add_option("",
                      "--client_cert",
                      dest="client_cert",
                      default="",
                      help="Path to client CA cert (or '.')")
    #parser.add_option("", "--term_type", dest="term_type", default="",
    #                  help="Terminal type (linux/screen/xterm) NOT YET IMPLEMENTED")

    (options, args) = parser.parse_args()
    protocol = "https" if options.https else "http"

    path = ""
    if args:
        if "/" in args[0]:
            path = args[0]
        else:
            path = (gterm.Host or "local") + "/" + args[0]

    if not options.server and gterm.Lterm_cookie:
        # Open new terminal window from within graphterm window
        path = path or (gterm.Host + "/" + "new")
        url = gterm.URL + "/" + path
        target = "_blank" if url.endswith("/new") else path
        gterm.open_url(url, target=target)
        return

    if options.noauth:
        auth_code = "none"
        port = None
    else:
        auth_code, port = gterm.read_auth_code(user=options.user,
                                               server=options.server)

    Http_addr = options.server or "localhost"
    Http_port = options.port or port or gterm.DEFAULT_HTTP_PORT

    client_nonce = "1%018d" % random.randrange(
        0, 10**18)  # 1 prefix to keep leading zeros when stringified

    resp = auth_request(Http_addr,
                        Http_port,
                        client_nonce,
                        user=options.user,
                        protocol=protocol)
    if not resp:
        print >> sys.stderr, "\ngterm: Authentication request to GraphTerm server %s:%s failed" % (
            Http_addr, Http_port)
        print >> sys.stderr, "gterm: Server may not be running; use 'gtermserver' command to start it."
        sys.exit(1)

    server_nonce, received_token = resp.split(":")
    client_token, server_token = gterm.auth_token(auth_code, "graphterm",
                                                  Http_addr, Http_port,
                                                  client_nonce, server_nonce)
    if received_token != client_token:
        print >> sys.stderr, "gterm: GraphTerm server %s:%s failed to authenticate itself (Check port number, if necessary)" % (
            Http_addr, Http_port)
        sys.exit(1)

    ##print >> sys.stderr, "**********snonce", server_nonce, client_token, server_token

    # Open graphterm window using browser
    url = "%s://%s:%d" % (protocol, Http_addr, Http_port)
    if path:
        url += "/" + path
    code = gterm.compute_hmac(auth_code, server_nonce)
    url += "/?cauth=" + server_nonce + "&code=" + code
    if options.user:
        url += "&user="******"gterm: ERROR in opening browser window '%s' - %s\n Check if server is running. If not, start it with 'gtermserver' command." % (
            " ".join(command_args), std_err)
        sys.exit(1)