| 240 | |
| 241 | # session过期处理 |
| 242 | def sess_expire(self): |
| 243 | self.sess_expire_sql() |
| 244 | try: |
| 245 | sess_path = os.path.join(PANEL_PATH, 'data/session') |
| 246 | if not os.path.exists(sess_path): |
| 247 | return |
| 248 | s_time = time.time() |
| 249 | f_list = os.listdir(sess_path) |
| 250 | f_num = len(f_list) |
| 251 | sess_out_path = '{}/data/session_timeout.pl'.format(PANEL_PATH) |
| 252 | session_timeout = 86400 |
| 253 | if os.path.exists(sess_out_path): |
| 254 | try: |
| 255 | session_timeout = int(public.readFile(sess_out_path)) |
| 256 | except: |
| 257 | pass |
| 258 | for fname in f_list: |
| 259 | filename = os.path.join(sess_path, fname) |
| 260 | fstat = os.stat(filename) |
| 261 | f_time = s_time - fstat.st_mtime |
| 262 | if f_time > session_timeout: |
| 263 | os.remove(filename) |
| 264 | continue |
| 265 | if fstat.st_size < 256 and len(fname) == 32: |
| 266 | if f_time > 60 or f_num > 30: |
| 267 | os.remove(filename) |
| 268 | continue |
| 269 | del f_list |
| 270 | except Exception as ex: |
| 271 | self.write_log(str(ex)) |
| 272 | |
| 273 | def sess_expire_sql(self): |
| 274 | try: |