15 from pyclearsilver
import handle_error
16 from auth
import db_auth, cookieauth
22 proxy_path = hdf.getValue(
"HTTP.Soap.Action",
"")
23 if proxy_path
and not config.gBaseURL.startswith(proxy_path):
24 config.gBaseURL = proxy_path + config.gBaseURL
25 config.gROSURL = proxy_path + config.gROSURL
27 hdf.setValue(
"Config.CompressionEnabled",
"1")
28 hdf.setValue(
"Config.WhiteSpaceStrip",
"1")
35 now = int(time.time())
36 today = time.localtime(now)
37 neo_cgi.exportDate(hdf,
"CGI.Today",
"US/Pacific", now)
41 via = hdf.getValue(
"HTTP.Via",
"")
46 hdf.setValue(
"CGI.Robot", config.get_robot_name())
47 hdf.setValue(
"CGI.robot_type", config.get_robot_type())
49 hostport_prefix = self.
http +
"%s%s" % (self.domain.split(
':')[0], config.gROSBridgePort)
50 hdf.setValue(
"CGI.hostport_prefix", hostport_prefix)
51 hdf.setValue(
"CGI.ros_bridge_uri", hostport_prefix + config.gROSURL)
53 hdf.setValue(
"CGI.home_server", config.gHomeServer)
59 request_uri = hdf.getValue(
"CGI.RequestURI",
"")
60 if request_uri.startswith(config.gBaseURL):
61 page_name = request_uri[len(config.gBaseURL):].split(
'?', 1)[0]
62 hdf.setValue(
"CGI.page_name", page_name)
65 useragent = hdf.getValue(
"HTTP.UserAgent",
"").lower()
66 if useragent.find(
"android") != -1
or useragent.find(
"iphone") != -1
or useragent.find(
"arora") != -1:
67 hdf.setValue(
"CGI.cur.device_style",
"style_phone.css")
71 hdfobj = hdf.getObj(
"Query.Action")
74 CSPage.handle_actions(self)
79 logincookie = cookieauth.parseLoginCookie(self.
ncgi)
85 hdf.setValue(
"CGI.Login", self.
username)
86 hdf.setValue(
"CGI.Login.issued_at", str(logincookie.issued_at))
92 requestURI = hdf.getValue(
"CGI.RequestURI",
"")
94 rurl = config.gBaseURL +
"login/signin0.py" 96 self.
authdb = db_auth.initSchema()
98 logincookie = cookieauth.parseLoginCookie(self.
ncgi)
100 self.
redirectUri(rurl +
"?q=1&request=%s" % neo_cgi.urlEscape(requestURI))
102 self.
username = logincookie.username
105 hdf.setValue(
"CGI.Role", self.userRec.role)
108 warn(
"invalid cookie", rurl +
"?q=1&request=%s" % neo_cgi.urlEscape(requestURI))
109 self.
redirectUri(rurl +
"?q=1&request=%s" % neo_cgi.urlEscape(requestURI))
112 persist = cookieauth.getPersistCookie(hdf)
115 if (time.time() - logincookie.issued_at) > config.REFRESH_COOKIE_TIMEOUT:
116 cookieauth.issueLoginCookie(self.
ncgi, self.
authdb, self.
username, self.userRec.pw_hash)
120 hdf.setValue(
"CGI.Login", self.
username)
121 hdf.setValue(
"CGI.Login.issued_at", str(logincookie.issued_at))
127 if time_since_activity > config.ACTIVE_USER_TIMEOUT:
132 os.utime(config.ACTIVE_USER_FILE,
None)
136 if self._pageparms.get(
"checkActive",
True):
137 if hdf.getValue(
"Cookie.inactive",
"0") !=
"1":
141 rurl = config.gBaseURL +
"active/active.py" 142 if requestURI.find(
"/active/") == -1:
143 self.
redirectUri(rurl +
"?q=1&request=%s" % neo_cgi.urlEscape(requestURI))
148 active_user = open(config.ACTIVE_USER_FILE,
"r").read().strip() 157 modified_time = os.path.getmtime(config.ACTIVE_USER_FILE)
158 time_since_mod = (time.time() - modified_time)
162 return time_since_mod
170 if not os.path.exists(config.ROS_VAR_DIR):
172 os.mkdir(config.ROS_VAR_DIR, 0777)
173 active_user = open(config.ACTIVE_USER_FILE,
"w")
177 if config.get_robot_type().startswith(
"texas"):
178 cookie = hdf.getValue(
"Query.cookie",
"")
180 cookie_file = open(config.VALID_USER_COOKIE_FILE,
"w")
181 cookie_file.write(cookie)
185 url = config.gLobby +
"/lobby/lobby/userrec.py" 187 postdata[
'Action.MakeActiveUser'] =
"1" 188 postdata[
'active_user'] = self.
username 189 postdata[
'robot'] = config.get_robot_name()
191 fp = urllib.urlopen(url, urllib.urlencode(postdata.items()))
197 if config.get_robot_type().startswith(
"texas"):
198 if os.path.exists(config.VALID_USER_COOKIE_FILE):
199 os.remove(config.VALID_USER_COOKIE_FILE)
201 if os.path.exists(config.ACTIVE_USER_FILE):
202 os.remove(config.ACTIVE_USER_FILE)
205 url = config.gLobby +
"/lobby/lobby/userrec.py" 207 postdata[
'Action.RemoveActiveUser'] =
"1" 208 postdata[
'robot'] = config.get_robot_name()
210 fp = urllib.urlopen(url, urllib.urlencode(postdata.items()))
217 return self.
http + self.ncgi.hdf.getValue(
"HTTP.Host",
"") + config.gBaseURL +
"%s/" % config.gDefaultModule
220 if hasattr(self,
"db")
and self.
db:
223 if hasattr(self,
"authdb")
and self.
authdb:
def get_active_user(self)
def setStyleSheet(self, hdf)
def make_active_user(self, hdf)
def redirectUri(self, redirectTo)
def handle_actions2(self)
def get_active_user_last_activity(self)
def remove_active_user(self)
def checkLoginCookie(self)
def default_app_path(self)