forked from ikus060/rdiffweb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rdiff-web
executable file
·143 lines (129 loc) · 5.18 KB
/
rdiff-web
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#!/usr/bin/python
# rdiffWeb, A web interface to rdiff-backup repositories
# Copyright (C) 2012 rdiffWeb contributors
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import cherrypy
import getopt
import os
import sys
import threading
import rdiffWeb.rdw_config
import rdiffWeb.rdw_spider_repos
import rdiffWeb.email_notification
import rdiffWeb.page_error
import rdiffWeb.filter_authentication
import rdiffWeb.filter_setup
import rdiffWeb.page_admin
import rdiffWeb.page_browse
import rdiffWeb.page_history
import rdiffWeb.page_locations
import rdiffWeb.page_restore
import rdiffWeb.page_setup
import rdiffWeb.page_status
import rdiffWeb.page_prefs
if __name__ == "__main__":
# Parse command line options
verbose = True
debug = False
autoReload = False
pidFile = ""
logFile = ""
opts, extraparams = getopt.getopt(sys.argv[1:], 'vdr', ['debug', 'log-file=', 'pid-file=', 'background', 'autoreload'])
for option, value in opts:
if option in ['-d', '--debug']:
debug = True
if option in ['-r', '--autoreload']:
autoReload = True
elif option in ['--log-file']:
logFile = value
elif option in ['--pid-file']:
pidFile = value
elif option in ['--background']:
import rdiffWeb.rdw_helpers
rdiffWeb.rdw_helpers.daemonize()
verbose = False
# Wait to write out to the pidfile until after we've (possibly) been daemonized
if pidFile:
# Write our process id to specified file, so we can be killed later
open(pidFile, 'a').write(str(os.getpid()) + "\n")
serverPort = 8080
if rdiffWeb.rdw_config.getConfigSetting("ServerPort") != "":
serverPort = int(rdiffWeb.rdw_config.getConfigSetting("ServerPort"))
environment = "development"
if not debug:
environment = "production"
global_settings = {
'tools.encode.on': True,
'tools.encode.encoding': 'utf-8',
'tools.gzip.on': True,
'tools.sessions.on' : True,
'tools.authenticate.on' : True,
'autoreload.on' : autoReload,
'server.socket_host' : rdiffWeb.rdw_config.getConfigSetting("ServerHost"),
'server.socket_port' : serverPort,
'server.log_file' : logFile,
'server.ssl_certificate': rdiffWeb.rdw_config.getConfigSetting("SslCertificate"),
'server.ssl_private_key': rdiffWeb.rdw_config.getConfigSetting("SslPrivateKey"),
'log.screen': True,
'server.environment': environment,
}
page_settings = {
'/': {
'tools.authenticate.checkAuth' : rdiffWeb.page_locations.rdiffLocationsPage().checkAuthentication,
'tools.authenticate.on' : True,
'tools.setup.on': True,
},
'/status/feed': {
'tools.authenticate.authMethod' : 'HTTP Header'
},
'/static' : {
'tools.staticdir.on' : True,
'tools.staticdir.root': rdiffWeb.rdw_helpers.getStaticRootPath(),
'tools.staticdir.dir': "static",
'tools.authenticate.on' : False,
'tools.setup.on': False,
},
'/setup': {
'tools.setup.on': False,
'tools.authenticate.on' : False,
'tools.sessions.on' : False,
}
}
if rdiffWeb.rdw_config.getConfigSetting("SessionStorage").lower() == "disk":
sessionDir = rdiffWeb.rdw_config.getConfigSetting("SessionDir")
if os.path.exists(sessionDir) and os.path.isdir(sessionDir) and os.access(sessionDir, os.W_OK):
cherrypy.log("Setting session mode to disk in directory %s" % sessionDir)
global_settings['tools.sessions.on'] = True
global_settings['tools.sessions.storage_type'] = 'file'
global_settings['tools.sessions.storage_path'] = sessionDir
cherrypy.config.update(global_settings)
root = rdiffWeb.page_locations.rdiffLocationsPage()
root.setup = rdiffWeb.page_setup.rdiffSetupPage()
root.browse = rdiffWeb.page_browse.rdiffBrowsePage()
root.restore = rdiffWeb.page_restore.rdiffRestorePage()
root.history = rdiffWeb.page_history.rdiffHistoryPage()
root.status = rdiffWeb.page_status.rdiffStatusPage()
root.admin = rdiffWeb.page_admin.rdiffAdminPage()
root.prefs = rdiffWeb.page_prefs.rdiffPreferencesPage()
# Start repo spider thread
if not debug:
killEvent = threading.Event()
rdiffWeb.rdw_spider_repos.startRepoSpiderThread(killEvent)
rdiffWeb.email_notification.startEmailNotificationThread(killEvent)
if hasattr(cherrypy.engine, 'subscribe'): # CherryPy >= 3.1
cherrypy.engine.subscribe('stop', lambda: killEvent.set())
else:
cherrypy.engine.on_stop_engine_list.append(lambda: killEvent.set())
cherrypy.quickstart(root, config=page_settings)