def main(argv, stdout, environ): progname = argv[0] optlist, args = getopt.getopt(argv[1:], "", ["help"]) testflag = 0 if len(args) < 2: usage(progname) return for (field, val) in optlist: if field == "--help": usage(progname) return db = db_auth.initSchema() username = args[0] cmd = args[1] user = db.users.lookup(username=username) if cmd == "add": for taskid in args[1:]: user.add_favorite_app(taskid) elif cmd == "list": for app in user.favorite_apps_list(): print app elif cmd == "del": for taskid in args[1:]: user.remove_favorite_app(taskid)
def checkLoginCookie(self): hdf = self.ncgi.hdf requestURI = hdf.getValue("CGI.RequestURI", "") rurl = config.gBaseURL + "login/signin0.py" self.authdb = db_auth.initSchema() logincookie = cookieauth.parseLoginCookie(self.ncgi) if not logincookie: self.redirectUri(rurl + "?q=1&request=%s" % neo_cgi.urlEscape(requestURI)) self.username = logincookie.username self.userRec = self.authdb.users.lookup(self.username) if self.userRec: hdf.setValue("CGI.Role", self.userRec.role) if self.userRec is None or cookieauth.checkLoginCookie(self.ncgi, logincookie, self.authdb, self.username, self.userRec) == 0: warn("invalid cookie", rurl + "?q=1&request=%s" % neo_cgi.urlEscape(requestURI)) self.redirectUri(rurl + "?q=1&request=%s" % neo_cgi.urlEscape(requestURI)) # ----- the cookie is valid!!!! ------- persist = cookieauth.getPersistCookie(hdf) if persist == 0: # reissue a new cookie with an updated timeout if (time.time() - logincookie.issued_at) > config.REFRESH_COOKIE_TIMEOUT: cookieauth.issueLoginCookie(self.ncgi, self.authdb, self.username, self.userRec.pw_hash) self.login = self.username hdf.setValue("CGI.Login", self.username) hdf.setValue("CGI.Login.issued_at", str(logincookie.issued_at)) active_user = self.get_active_user() time_since_activity = self.get_active_user_last_activity() # seconds since they did something if active_user: if time_since_activity > config.ACTIVE_USER_TIMEOUT: # time out after one hour? self.remove_active_user() else: # touch the active user file os.utime(config.ACTIVE_USER_FILE, None) hdf.setValue("CGI.active_user", self.get_active_user()) if self._pageparms.get("checkActive", True): if hdf.getValue("Cookie.inactive", "0") != "1": if self.get_active_user() == "": self.make_active_user(hdf) elif not self.is_active_user(): rurl = config.gBaseURL + "active/active.py" if requestURI.find("/active/") == -1: self.redirectUri(rurl + "?q=1&request=%s" % neo_cgi.urlEscape(requestURI))
def subclassinit(self): hdf = self.ncgi.hdf proxy_path = hdf.getValue("HTTP.Soap.Action", "") if proxy_path and not config.gBaseURL.startswith(proxy_path): config.gBaseURL = proxy_path + config.gBaseURL config.gROSURL = proxy_path + config.gROSURL hdf.setValue("Config.CompressionEnabled","1") hdf.setValue("Config.WhiteSpaceStrip","1") self.login = None self.username = None self.db = None self.userRec = None now = int(time.time()) today = time.localtime(now) neo_cgi.exportDate(hdf, "CGI.Today", "US/Pacific", now) self.authdb = db_auth.initSchema() via = hdf.getValue("HTTP.Via", "") if via: #if via.find(":443") != -1: self.http = "https://" hdf.setValue("CGI.Robot", config.get_robot_name()) hdf.setValue("CGI.robot_type", config.get_robot_type()) hostport_prefix = self.http + "%s%s" % (self.domain.split(':')[0], config.gROSBridgePort) hdf.setValue("CGI.hostport_prefix", hostport_prefix) hdf.setValue("CGI.ros_bridge_uri", hostport_prefix + config.gROSURL) hdf.setValue("CGI.home_server", config.gHomeServer) self.getUsername() self.setStyleSheet(hdf) hdf.setValue("CGI.home_page", self.default_app_path()) request_uri = hdf.getValue("CGI.RequestURI", "") if request_uri.startswith(config.gBaseURL): page_name = request_uri[len(config.gBaseURL):].split('?', 1)[0] hdf.setValue("CGI.page_name", page_name)
def checkLoginCookie(self): hdf = self.ncgi.hdf requestURI = hdf.getValue("CGI.RequestURI", "") rurl = config.gBaseURL + "login/signin0.py" self.authdb = db_auth.initSchema() logincookie = cookieauth.parseLoginCookie(self.ncgi) if not logincookie: self.redirectUri(rurl + "?q=1&request=%s" % neo_cgi.urlEscape(requestURI)) self.username = logincookie.username userRec = self.authdb.users.lookup(self.username) if userRec is None or cookieauth.checkLoginCookie( self.ncgi, logincookie, self.authdb, self.username, userRec) == 0: warn("invalid cookie", rurl + "?q=1&request=%s" % neo_cgi.urlEscape(requestURI)) self.redirectUri(rurl + "?q=1&request=%s" % neo_cgi.urlEscape(requestURI)) # ----- the cookie is valid!!!! ------- persist = cookieauth.getPersistCookie(hdf) if persist == 0: # reissue a new cookie with an updated timeout if (time.time() - logincookie.issued_at) > config.REFRESH_COOKIE_TIMEOUT: cookieauth.issueLoginCookie(self.ncgi, self.authdb, self.username, userRec.pw_hash) self.login = self.username hdf.setValue("CGI.Login", self.username) hdf.setValue("CGI.Login.issued_at", str(logincookie.issued_at))
def Action_changePassword(self): hdf = self.ncgi.hdf q_pw0 = hdf.getValue("Query.pw0","") q_pw1 = hdf.getValue("Query.pw1","") q_pw2 = hdf.getValue("Query.pw2","") requestURI = hdf.getValue("Query.request", "") if not requestURI: requestURI = config.gBaseURL + self.login + "/mail/prefs.py" if not self.login: self.redirectUri(self.requestURI) if not q_pw0: self.error("Old password is not complete.") if not q_pw1 or (q_pw1 != q_pw2): self.error("New passwords do not match.") authdb = db_auth.initSchema() userRec = authdb.users.lookup(self.login) if not userRec.checkPassword(q_pw0): self.error("Old password is invalid.") userRec.setPassword(q_pw1) cookieauth.issueLoginCookie(self.ncgi, authdb, self.login, userRec.pw_hash) # self.issueLoginCookie(self.login, self.MB.getOption("pw_hash")) warn("redirecting to", repr(self.requestURI)) self.redirectUri(self.requestURI)
def Action_changePassword(self): hdf = self.ncgi.hdf q_pw0 = hdf.getValue("Query.pw0","") q_pw1 = hdf.getValue("Query.pw1","") q_pw2 = hdf.getValue("Query.pw2","") requestURI = hdf.getValue("Query.request", "%swebui" % config.gBaseURL) if not requestURI: requestURI = config.gBaseURL + self.login + "/mail/prefs.py" if not self.login: self.redirectUri(self.requestURI) if not q_pw0: self.error("Old password is not complete.") if not q_pw1 or (q_pw1 != q_pw2): self.error("New passwords do not match.") authdb = db_auth.initSchema() userRec = authdb.users.lookup(self.login) if not userRec.checkPassword(q_pw0): self.error("Old password is invalid.") userRec.setPassword(q_pw1) cookieauth.issueLoginCookie(self.ncgi, authdb, self.login, userRec.pw_hash) # self.issueLoginCookie(self.login, self.MB.getOption("pw_hash")) warn("redirecting to", repr(self.requestURI)) self.redirectUri(self.requestURI)
def subclassinit(self): # self._pageparms["nologin"] = 1 hdf = self.ncgi.hdf # self.setPaths([config.gTemplatePath]) # hdf.setValue("Query.debug", "1") # hdf.setValue("Config.DebugPassword","1") hdf.setValue("Config.CompressionEnabled", "1") hdf.setValue("Config.WhiteSpaceStrip", "1") self.login = None self.username = None self.db = None self.userRec = None now = int(time.time()) today = time.localtime(now) neo_cgi.exportDate(hdf, "CGI.Today", "US/Pacific", now) self.authdb = db_auth.initSchema() self.getUsername() self.setStyleSheet(hdf)
def setup(self, hdf): self.db = db_webui.initSchema() self.auth_db = db_auth.initSchema()
def setup(self, hdf): self.requestURI = hdf.getValue("Query.request", "") self.authdb = db_auth.initSchema()