1
2 """
3 Plugin for our configuring the OMERO.web installation
4
5 Copyright 2009 University of Dundee. All rights reserved.
6 Use is subject to license terms supplied in LICENSE.txt
7
8 """
9
10 from exceptions import Exception
11 from omero.cli import Arguments, BaseControl, VERSION
12 import omero.java
13 import time
14
15 HELP=""" omero web [settings|superuser|syncdb]
16
17 OMERO.web tools:
18
19 settings - Configuration for web
20 superuser - Creates a superuser for managing OMERO.web local database
21 syncdb - Local database synchronisation
22
23 """
25
26 - def help(self, args = None):
28
30
31 root_pass = self._ask_for_password(" for OMERO.web administrator")
32
33 import sha, random
34 algo = 'sha1'
35 salt = sha.new(str(random.random())).hexdigest()[:5]
36 hsh = sha.new(salt+root_pass).hexdigest()
37 value = '%s$%s$%s' % (algo, salt, hsh)
38 return value.strip()
39
41 while not username or len(username) < 1:
42 username = self.ctx.input("Please enter Username for OMERO.web administrator: ")
43 if username == None or username == "":
44 self.ctx.err("Username cannot be empty")
45 continue
46 break
47 while not email or len(email) < 1:
48 email = self.ctx.input("Please enter Email address: ")
49 if email == None or email == "":
50 self.ctx.err("Email cannot be empty")
51 continue
52 break
53 return {"username":username, "email":email}
54
56 location = self.ctx.dir / "lib" / "python" / "omeroweb" / "initial_data.json"
57 output = open(location, 'w')
58 print "Saving to " + location
59
60 try:
61 output.write("""[
62 {
63 "pk": 1,
64 "model": "auth.user",
65 "fields": {
66 "username": "%s",
67 "first_name": "",
68 "last_name": "",
69 "is_active": true,
70 "is_superuser": true,
71 "is_staff": true,
72 "last_login": "%s",
73 "groups": [],
74 "user_permissions": [],
75 "password": "%s",
76 "email": "%s",
77 "date_joined": "%s"
78 }
79 },
80 {
81 "pk": 1,
82 "model": "webadmin.gateway",
83 "fields": {
84 "server": "omero",
85 "host": "localhost",
86 "port": 4063
87 }
88 },
89 {
90 "pk": 1,
91 "model": "feedback.emailtemplate",
92 "fields": {
93 "content_html": "%%s",
94 "template": "error_message",
95 "content_txt": "%%s"
96 }
97 },
98 {
99 "pk": 2,
100 "model": "feedback.emailtemplate",
101 "fields": {
102 "content_html": "<p>Hi,</p><p>I would like to share some of my data with you.<br/>Please find it on the <a href='%%swebclient/share/view/%%i/?server=%%i'>%%swebclient/share/view/%%i/?server=%%i</a>.</p><p>-- %%s</p>",
103 "template": "create_share",
104 "content_txt": "Hi, I would like to share some of my data with you. Please find it on the %%swebclient/share/view/%%i/?server=%%i. /n -- %%s"
105 }
106 },
107 {
108 "pk": 3,
109 "model": "feedback.emailtemplate",
110 "fields": {
111 "content_html": "<p>Hi,</p><p>I would like to share some of my data with you.<br/>Please find it on the <a href='%%swebclient/share/view/%%i/?server=%%i'>%%swebclient/share/view/%%i/?server=%%i</a>.</p><p>-- %%s</p>",
112 "template": "add_member_to_share",
113 "content_txt": "Hi, I would like to share some of my data with you. Please find it on the %%swebclient/share/view/%%i/?server=%%i. /n -- %%s"
114 }
115 },
116 {
117 "pk": 4,
118 "model": "feedback.emailtemplate",
119 "fields": {
120 "content_html": "<p>You were removed from the share <a href='%%swebclient/share/view/%%i/?server=%%i'>%%swebclient/share/view/%%i/?server=%%i</a>. This share is no longer available for you.</p>",
121 "template": "remove_member_from_share",
122 "content_txt": "You were removed from the share %%swebclient/share/view/%%i/?server=%%i. This share is no longer available for you."
123 }
124 },
125 {
126 "pk": 5,
127 "model": "feedback.emailtemplate",
128 "fields": {
129 "content_html": "<p>New comment is available on share <a href='%%swebclient/share/view/%%i/?server=%%i'>%%swebclient/share/view/%%i/?server=%%i</a>.</p>",
130 "template": "add_comment_to_share",
131 "content_txt": "New comment is available on share %%swebclient/share/view/%%i/?server=%%i."
132 }
133 }
134 ]""" % (username, time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()), passwd, email, time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())))
135 finally:
136 output.flush()
137 output.close()
138
144
145 - def _setup_server(self, location, email_server=None, app_host=None, sender_address=None, smtp_server=None):
146 settings = dict()
147
148 if location.exists():
149 self.ctx.out("Reconfiguring OMERO.web...")
150 else:
151 self.ctx.out("You just installed OMERO, which means you didn't have settings configured in OMERO.web.")
152 while not app_host or len(app_host) < 1:
153 app_host = self.ctx.input("Please enter the domain you want to run OMERO.web on (http://www.domain.com:8000/):")
154 if app_host == None or app_host == "":
155 self.ctx.err("Domain cannot be empty")
156 continue
157 settings["APPLICATION_HOST"] = app_host
158 break
159
160 while not sender_address or len(sender_address) < 1 :
161 sender_address = self.ctx.input("Please enter the Email address you want to send from (omero_admin@example.com): ")
162 if sender_address == None or sender_address == "":
163 self.ctx.err("Email cannot be empty")
164 continue
165
166 while not smtp_server or len(smtp_server) < 1 :
167 smtp_server = self.ctx.input("Please enter the SMTP server host you want to send from (smtp.example.com): ")
168 if smtp_server == None or smtp_server == "":
169 self.ctx.err("SMTP server host cannot be empty")
170 continue
171
172 smtp_port = self.ctx.input("Optional: please enter the SMTP server port (default 25): ")
173 smtp_user = self.ctx.input("Optional: Please enter the SMTP server username: ")
174 smtp_password = self.ctx.input("Optional: Password: ", hidden=True)
175 smtp_tls = self.ctx.input("Optional: TSL? (yes/no): ")
176 if smtp_tls == "yes":
177 smtp_tls = True
178 else:
179 smtp_tls = False
180 break
181
182 settings["SERVER_EMAIL"] = sender_address
183 settings["EMAIL_HOST"] = smtp_server
184
185 if smtp_port:
186 settings["EMAIL_PORT"] = smtp_port
187 if smtp_user:
188 settings["EMAIL_HOST_USER"] = smtp_user
189 if smtp_password:
190 settings["EMAIL_HOST_PASSWORD"] = smtp_password
191 if smtp_tls:
192 settings["EMAIL_USE_TLS"] = smtp_tls
193
194 return settings
195
197 output = open(location, 'w')
198 print "Saving to " + location
199
200 try:
201 output.write("""#!/usr/bin/env python
202 #
203 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
204 # # Django custom settings for OMERO.web project. # #
205 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
206 #
207 #
208 # Copyright (c) 2009 University of Dundee.
209 #
210 # This program is free software: you can redistribute it and/or modify
211 # it under the terms of the GNU Affero General Public License as
212 # published by the Free Software Foundation, either version 3 of the
213 # License, or (at your option) any later version.
214 #
215 # This program is distributed in the hope that it will be useful,
216 # but WITHOUT ANY WARRANTY; without even the implied warranty of
217 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
218 # GNU Affero General Public License for more details.
219 #
220 # You should have received a copy of the GNU Affero General Public License
221 # along with this program. If not, see <http://www.gnu.org/licenses/>.
222 #
223 # Author: Aleksandra Tarkowska <A(dot)Tarkowska(at)dundee(dot)ac(dot)uk>, 2008.
224 #
225 # Version: 1.0
226
227 # Notification
228 # Application allows to notify user about new shares
229 """)
230 if settings.has_key('SERVER_EMAIL'):
231 output.write("""SERVER_EMAIL = '%s'
232 """ % settings["SERVER_EMAIL"])
233 if settings.has_key('EMAIL_HOST'):
234 output.write("""EMAIL_HOST = '%s'
235 """ % settings["EMAIL_HOST"])
236 if settings.has_key('EMAIL_PORT'):
237 output.write("""EMAIL_PORT = %s
238 """ % settings["EMAIL_PORT"])
239 if settings.has_key('EMAIL_HOST_USER'):
240 output.write("""EMAIL_HOST_USER = '%s'
241 """ % settings["EMAIL_HOST_USER"])
242 if settings.has_key('EMAIL_HOST_PASSWORD'):
243 output.write("""EMAIL_HOST_PASSWORD = '%s'
244 """ % settings["EMAIL_HOST_PASSWORD"])
245 if settings.has_key('EMAIL_USE_TLS'):
246 if settings["EMAIL_USE_TLS"]:
247 output.write("""EMAIL_USE_TLS = 'True'
248 """)
249 else:
250 output.write("""EMAIL_USE_TLS = 'False'
251 """)
252
253 output.write("""
254 APPLICATION_HOST='%s'
255 """ % settings["APPLICATION_HOST"])
256 finally:
257 output.flush()
258 output.close()
259
264
266 sys.stderr.write("Database synchronization... \n")
267 omero_web = self.ctx.dir / "lib" / "python" / "omeroweb"
268 subprocess.call(["python","manage.py","syncdb","--noinput"], cwd=str(omero_web), env = os.environ)
269 sys.stderr.write("OMERO.web was prepared. Please start the application.\n")
270
271 try:
272 register("web", WebControl)
273 except NameError:
274 WebControl()._main()
275