witten
/
luminotes
Archived
1
0
Fork 0

Setting permissions on log files to 600 for privacy reasons. Also naming log files to include username on Linux.

This commit is contained in:
Dan Helfman 2008-08-26 14:58:04 -07:00
parent 9e1ae2abb6
commit c0d512920e
2 changed files with 33 additions and 8 deletions

View File

@ -4,6 +4,10 @@ import cherrypy
from tempfile import gettempdir
username_postfix = os.environ.get( "USER" )
username_postfix = username_postfix and "_%s" % username_postfix or ""
settings = {
"global": {
"server.thread_pool": 4,
@ -11,8 +15,8 @@ settings = {
"session_filter.timeout": 60 * 24 * 365, # one year
"static_filter.root": os.getcwd(),
"server.log_to_screen": False,
"server.log_file": os.path.join( gettempdir(), "luminotes_error.log" ),
"server.log_access_file": os.path.join( gettempdir(), "luminotes.log" ),
"server.log_file": os.path.join( gettempdir(), "luminotes_error%s.log" % username_postfix ),
"server.log_access_file": os.path.join( gettempdir(), "luminotes%s.log" % username_postfix ),
"server.log_tracebacks": True,
"luminotes.launch_browser": True,
"luminotes.db_host": None, # use local SQLite database

View File

@ -2,6 +2,7 @@
import os
import sys
import stat
import socket
import os.path
import urllib2 as urllib
@ -77,11 +78,16 @@ def main( args ):
# remove the existing log files, if any
try:
os.remove( cherrypy.config.configMap[ u"global" ].get( u"server.log_access_file" ) )
log_access_file = cherrypy.config.configMap[ u"global" ].get( u"server.log_access_file" )
if log_access_file:
os.remove( log_access_file )
except OSError:
pass
try:
os.remove( cherrypy.config.configMap[ u"global" ].get( u"server.log_file" ) )
log_file = cherrypy.config.configMap[ u"global" ].get( u"server.log_file" )
if log_file:
os.remove( log_file )
except OSError:
pass
@ -96,10 +102,25 @@ def main( args ):
root = Root( database, cherrypy.config.configMap )
cherrypy.root = root
if launch_browser is True:
cherrypy.server.start_with_callback( webbrowser.open_new, ( server_url, ) )
else:
cherrypy.server.start()
cherrypy.server.start_with_callback( callback, ( log_access_file, log_file, server_url, launch_browser ) )
def callback( log_access_file, log_file, server_url, launch_browser = False ):
# this causes cherrypy to create the access log
if log_access_file:
try:
urllib.urlopen( "%sping" % server_url )
except urllib.URLError:
pass
# give the cherrypy log files appropriate permissions
if log_access_file and os.path.exists( log_access_file ):
os.chmod( log_access_file, stat.S_IRUSR | stat.S_IWUSR )
if log_file and os.path.exists( log_file ):
os.chmod( log_file, stat.S_IRUSR | stat.S_IWUSR )
if launch_browser:
webbrowser.open_new( server_url )
if __name__ == "__main__":