︙ | | | ︙ | |
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
import datetime
import signal
import socket
import tempfile
import random
import string
import platform
from fileutils import abspath, write_file
from settings import global_settings
from admin import add_path_first, create_missing_folders, create_missing_app_folders
from globals import current
from custom_import import custom_import_install
from contrib.simplejson import dumps
|
|
|
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
import datetime
import signal
import socket
import tempfile
import random
import string
import platform
from fileutils import abspath, write_file, parse_version
from settings import global_settings
from admin import add_path_first, create_missing_folders, create_missing_app_folders
from globals import current
from custom_import import custom_import_install
from contrib.simplejson import dumps
|
︙ | | | ︙ | |
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
|
# Security Checks: validate URL and session_id here,
# accept_language is validated in languages
# pattern used to validate client address
regex_client = re.compile('[\w\-:]+(\.[\w\-]+)*\.?') # ## to account for IPV6
version_info = open(abspath('VERSION', gluon=True), 'r')
web2py_version = version_info.read()
version_info.close()
try:
import rocket
except:
if not global_settings.web2py_runtime_gae:
logger.warn('unable to import Rocket')
|
|
>
|
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
|
# Security Checks: validate URL and session_id here,
# accept_language is validated in languages
# pattern used to validate client address
regex_client = re.compile('[\w\-:]+(\.[\w\-]+)*\.?') # ## to account for IPV6
version_info = open(abspath('VERSION', gluon=True), 'r')
web2py_version = parse_version(version_info.read().strip())
version_info.close()
global_settings.web2py_version = web2py_version
try:
import rocket
except:
if not global_settings.web2py_runtime_gae:
logger.warn('unable to import Rocket')
|
︙ | | | ︙ | |
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
|
# ##################################################
if not os.path.exists(request.folder):
if request.application == rewrite.thread.routes.default_application and request.application != 'welcome':
request.application = 'welcome'
redirect(Url(r=request))
elif rewrite.thread.routes.error_handler:
redirect(Url(rewrite.thread.routes.error_handler['application'],
rewrite.thread.routes.error_handler['controller'],
rewrite.thread.routes.error_handler['function'],
args=request.application))
else:
raise HTTP(404,
rewrite.thread.routes.error_message % 'invalid request',
web2py_error='invalid application')
request.url = Url(r=request, args=request.args,
extension=request.raw_extension)
# ##################################################
# build missing folders
# ##################################################
|
|
>
|
|
|
|
|
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
|
# ##################################################
if not os.path.exists(request.folder):
if request.application == rewrite.thread.routes.default_application and request.application != 'welcome':
request.application = 'welcome'
redirect(Url(r=request))
elif rewrite.thread.routes.error_handler:
_handler = rewrite.thread.routes.error_handler
redirect(Url(_handler['application'],
_handler['controller'],
_handler['function'],
args=request.application))
else:
raise HTTP(404, rewrite.thread.routes.error_message \
% 'invalid request',
web2py_error='invalid application')
request.url = Url(r=request, args=request.args,
extension=request.raw_extension)
# ##################################################
# build missing folders
# ##################################################
|
︙ | | | ︙ | |
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
|
parse_get_post_vars(request, environ)
# ##################################################
# expose wsgi hooks for convenience
# ##################################################
request.wsgi.environ = environ_aux(environ,request)
request.wsgi.start_response = lambda status='200', headers=[], \
exec_info=None, response=response: \
start_response_aux(status, headers, exec_info, response)
request.wsgi.middleware = lambda *a: middleware_aux(request,response,*a)
# ##################################################
# load cookies
# ##################################################
if request.env.http_cookie:
try:
|
|
>
|
>
|
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
|
parse_get_post_vars(request, environ)
# ##################################################
# expose wsgi hooks for convenience
# ##################################################
request.wsgi.environ = environ_aux(environ,request)
request.wsgi.start_response = \
lambda status='200', headers=[], \
exec_info=None, response=response: \
start_response_aux(status, headers, exec_info, response)
request.wsgi.middleware = \
lambda *a: middleware_aux(request,response,*a)
# ##################################################
# load cookies
# ##################################################
if request.env.http_cookie:
try:
|
︙ | | | ︙ | |
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
|
session.connect(request, response)
# ##################################################
# set no-cache headers
# ##################################################
response.headers['Content-Type'] = contenttype('.'+request.extension)
response.headers['Cache-Control'] = \
'no-store, no-cache, must-revalidate, post-check=0, pre-check=0'
response.headers['Expires'] = \
time.strftime('%a, %d %b %Y %H:%M:%S GMT', time.gmtime())
response.headers['Pragma'] = 'no-cache'
# ##################################################
|
|
>
|
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
|
session.connect(request, response)
# ##################################################
# set no-cache headers
# ##################################################
response.headers['Content-Type'] = \
contenttype('.'+request.extension)
response.headers['Cache-Control'] = \
'no-store, no-cache, must-revalidate, post-check=0, pre-check=0'
response.headers['Expires'] = \
time.strftime('%a, %d %b %Y %H:%M:%S GMT', time.gmtime())
response.headers['Pragma'] = 'no-cache'
# ##################################################
|
︙ | | | ︙ | |
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
|
ticket = e.log(request) or 'unknown'
if response._custom_rollback:
response._custom_rollback()
else:
BaseAdapter.close_all_instances('rollback')
http_response = \
HTTP(500,
rewrite.thread.routes.error_message_ticket % dict(ticket=ticket),
web2py_error='ticket %s' % ticket)
except:
if request.body:
request.body.close()
|
|
|
|
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
|
ticket = e.log(request) or 'unknown'
if response._custom_rollback:
response._custom_rollback()
else:
BaseAdapter.close_all_instances('rollback')
http_response = \
HTTP(500, rewrite.thread.routes.error_message_ticket % \
dict(ticket=ticket),
web2py_error='ticket %s' % ticket)
except:
if request.body:
request.body.close()
|
︙ | | | ︙ | |
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
|
else:
BaseAdapter.close_all_instances('rollback')
except:
pass
e = RestrictedError('Framework', '', '', locals())
ticket = e.log(request) or 'unrecoverable'
http_response = \
HTTP(500,
rewrite.thread.routes.error_message_ticket % dict(ticket=ticket),
web2py_error='ticket %s' % ticket)
finally:
if response and hasattr(response, 'session_file') and response.session_file:
response.session_file.close()
# if global_settings.debugging:
# import gluon.debug
# gluon.debug.stop_trace()
session._unlock(response)
http_response, new_environ = rewrite.try_rewrite_on_error(
http_response, request, environ, ticket)
if not http_response:
return wsgibase(new_environ,responder)
if global_settings.web2py_crontype == 'soft':
newcron.softcron(global_settings.applications_parent).start()
return http_response.to(responder)
def save_password(password, port):
"""
used by main() to save the password in the parameters_port.py file.
"""
password_file = abspath('parameters_%i.py' % port)
|
|
|
|
>
|
|
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
|
else:
BaseAdapter.close_all_instances('rollback')
except:
pass
e = RestrictedError('Framework', '', '', locals())
ticket = e.log(request) or 'unrecoverable'
http_response = \
HTTP(500, rewrite.thread.routes.error_message_ticket \
% dict(ticket=ticket),
web2py_error='ticket %s' % ticket)
finally:
if response and hasattr(response, 'session_file') \
and response.session_file:
response.session_file.close()
# if global_settings.debugging:
# import gluon.debug
# gluon.debug.stop_trace()
session._unlock(response)
http_response, new_environ = rewrite.try_rewrite_on_error(
http_response, request, environ, ticket)
if not http_response:
return wsgibase(new_environ,responder)
if global_settings.web2py_crontype == 'soft':
newcron.softcron(global_settings.applications_parent).start()
return http_response.to(responder)
def save_password(password, port):
"""
used by main() to save the password in the parameters_port.py file.
"""
password_file = abspath('parameters_%i.py' % port)
|
︙ | | | ︙ | |
714
715
716
717
718
719
720
721
722
723
724
725
726
727
|
port=8000,
password='',
pid_filename='httpserver.pid',
log_filename='httpserver.log',
profiler_filename=None,
ssl_certificate=None,
ssl_private_key=None,
min_threads=None,
max_threads=None,
server_name=None,
request_queue_size=5,
timeout=10,
shutdown_timeout=None, # Rocket does not use a shutdown timeout
path=None,
|
>
|
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
|
port=8000,
password='',
pid_filename='httpserver.pid',
log_filename='httpserver.log',
profiler_filename=None,
ssl_certificate=None,
ssl_private_key=None,
ssl_ca_certificate=None,
min_threads=None,
max_threads=None,
server_name=None,
request_queue_size=5,
timeout=10,
shutdown_timeout=None, # Rocket does not use a shutdown timeout
path=None,
|
︙ | | | ︙ | |
765
766
767
768
769
770
771
772
773
774
775
776
777
778
|
logger.warning('Python "ssl" module unavailable. SSL is OFF')
elif not os.path.exists(ssl_certificate):
logger.warning('unable to open SSL certificate. SSL is OFF')
elif not os.path.exists(ssl_private_key):
logger.warning('unable to open SSL private key. SSL is OFF')
else:
sock_list.extend([ssl_private_key, ssl_certificate])
logger.info('SSL is ON')
app_info = {'wsgi_app': appfactory(wsgibase,
log_filename,
profiler_filename) }
self.server = rocket.Rocket(interfaces or tuple(sock_list),
method='wsgi',
|
>
>
>
|
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
|
logger.warning('Python "ssl" module unavailable. SSL is OFF')
elif not os.path.exists(ssl_certificate):
logger.warning('unable to open SSL certificate. SSL is OFF')
elif not os.path.exists(ssl_private_key):
logger.warning('unable to open SSL private key. SSL is OFF')
else:
sock_list.extend([ssl_private_key, ssl_certificate])
if ssl_ca_certificate:
sock_list.append(ssl_ca_certificate)
logger.info('SSL is ON')
app_info = {'wsgi_app': appfactory(wsgibase,
log_filename,
profiler_filename) }
self.server = rocket.Rocket(interfaces or tuple(sock_list),
method='wsgi',
|
︙ | | | ︙ | |
803
804
805
806
807
808
809
810
|
"""
newcron.stopcron()
self.server.stop(stoplogging)
try:
os.unlink(self.pid_filename)
except:
pass
|
>
>
|
813
814
815
816
817
818
819
820
821
822
|
"""
newcron.stopcron()
self.server.stop(stoplogging)
try:
os.unlink(self.pid_filename)
except:
pass
|