]>
git.ipfire.org Git - ipfire.org.git/blob - src/web/people.py
11 from . import ui_modules
13 class IndexHandler(auth
.CacheMixin
, base
.BaseHandler
):
14 @tornado.web
.authenticated
16 self
.render("people/index.html")
19 class AvatarHandler(base
.BaseHandler
):
21 # Get the desired size of the avatar file
22 size
= self
.get_argument("size", 0)
26 except (TypeError, ValueError):
29 logging
.debug("Querying for avatar of %s" % uid
)
32 account
= self
.backend
.accounts
.get_by_uid(uid
)
34 raise tornado
.web
.HTTPError(404, "Could not find account %s" % uid
)
36 # Allow downstream to cache this for 60 minutes
37 self
.set_expires(3600)
40 avatar
= account
.get_avatar(size
)
42 # If there is no avatar, we serve a default image
44 logging
.debug("No avatar uploaded for %s" % account
)
46 return self
.redirect(self
.static_url("img/default-avatar.jpg"))
48 # Set headers about content
49 self
.set_header("Content-Disposition", "inline; filename=\"%s.jpg\"" % account
.uid
)
50 self
.set_header("Content-Type", "image/jpeg")
56 class CallsHandler(auth
.CacheMixin
, base
.BaseHandler
):
57 @tornado.web
.authenticated
58 def get(self
, uid
, date
=None):
59 account
= self
.backend
.accounts
.get_by_uid(uid
)
61 raise tornado
.web
.HTTPError(404, "Could not find account %s" % uid
)
65 date
= datetime
.datetime
.strptime(date
, "%Y-%m-%d").date()
67 raise tornado
.web
.HTTPError(400, "Invalid date: %s" % date
)
69 date
= datetime
.date
.today()
71 self
.render("people/calls.html", account
=account
, date
=date
)
74 class CallHandler(auth
.CacheMixin
, base
.BaseHandler
):
75 @tornado.web
.authenticated
76 def get(self
, uid
, uuid
):
77 account
= self
.backend
.accounts
.get_by_uid(uid
)
79 raise tornado
.web
.HTTPError(404, "Could not find account %s" % uid
)
81 call
= self
.backend
.talk
.freeswitch
.get_call_by_uuid(uuid
)
83 raise tornado
.web
.HTTPError(404, "Could not find call %s" % uuid
)
87 self
.render("people/call.html", account
=account
, call
=call
)
90 class ConferencesHandler(auth
.CacheMixin
, base
.BaseHandler
):
91 @tornado.web
.authenticated
93 self
.render("people/conferences.html", conferences
=self
.backend
.talk
.conferences
)
96 class SearchHandler(auth
.CacheMixin
, base
.BaseHandler
):
97 @tornado.web
.authenticated
99 q
= self
.get_argument("q")
102 accounts
= self
.backend
.accounts
.search(q
)
104 # Redirect when only one result was found
105 if len(accounts
) == 1:
106 self
.redirect("/users/%s" % accounts
[0].uid
)
109 self
.render("people/search.html", q
=q
, accounts
=accounts
)
112 class SSHKeysIndexHandler(auth
.CacheMixin
, base
.BaseHandler
):
113 @tornado.web
.authenticated
115 account
= self
.backend
.accounts
.get_by_uid(uid
)
117 raise tornado
.web
.HTTPError(404, "Could not find account %s" % uid
)
119 self
.render("people/ssh-keys/index.html", account
=account
)
122 class SSHKeysDownloadHandler(auth
.CacheMixin
, base
.BaseHandler
):
123 @tornado.web
.authenticated
124 def get(self
, uid
, hash_sha256
):
125 account
= self
.backend
.accounts
.get_by_uid(uid
)
127 raise tornado
.web
.HTTPError(404, "Could not find account %s" % uid
)
130 key
= account
.get_ssh_key_by_hash_sha256(hash_sha256
)
132 raise tornado
.web
.HTTPError(404, "Could not find key: %s" % hash_sha256
)
135 self
.add_header("Content-Type", "text/plain")
137 self
.finish(key
.keydata
)
140 class SSHKeysUploadHandler(auth
.CacheMixin
, base
.BaseHandler
):
141 @tornado.web
.authenticated
143 account
= self
.backend
.accounts
.get_by_uid(uid
)
145 raise tornado
.web
.HTTPError(404, "Could not find account %s" % uid
)
147 # Check for permissions
148 if not account
.can_be_managed_by(self
.current_user
):
149 raise tornado
.web
.HTTPError(403, "%s cannot manage %s" % (self
.current_user
, account
))
151 self
.render("people/ssh-keys/upload.html", account
=account
)
153 @tornado.web
.authenticated
155 account
= self
.backend
.accounts
.get_by_uid(uid
)
157 raise tornado
.web
.HTTPError(404, "Could not find account %s" % uid
)
159 # Check for permissions
160 if not account
.can_be_managed_by(self
.current_user
):
161 raise tornado
.web
.HTTPError(403, "%s cannot manage %s" % (self
.current_user
, account
))
163 key
= self
.get_argument("key")
166 password
= self
.get_argument("password")
167 if not account
.check_password(password
):
168 raise tornado
.web
.HTTPError(403, "Incorrect password for %s" % account
)
170 # Try to add new SSH key
172 account
.add_ssh_key(key
)
174 except sshpubkeys
.InvalidKeyException
as e
:
175 self
.render("people/ssh-keys/error-invalid-key.html", account
=account
, exception
=e
)
178 self
.redirect("/users/%s/ssh-keys" % account
.uid
)
181 class SSHKeysDeleteHandler(auth
.CacheMixin
, base
.BaseHandler
):
182 @tornado.web
.authenticated
183 def get(self
, uid
, hash_sha256
):
184 account
= self
.backend
.accounts
.get_by_uid(uid
)
186 raise tornado
.web
.HTTPError(404, "Could not find account %s" % uid
)
189 key
= account
.get_ssh_key_by_hash_sha256(hash_sha256
)
191 raise tornado
.web
.HTTPError(404, "Could not find key: %s" % hash_sha256
)
193 self
.render("people/ssh-keys/delete.html", account
=account
, key
=key
)
195 @tornado.web
.authenticated
196 def post(self
, uid
, hash_sha256
):
197 account
= self
.backend
.accounts
.get_by_uid(uid
)
199 raise tornado
.web
.HTTPError(404, "Could not find account %s" % uid
)
202 key
= account
.get_ssh_key_by_hash_sha256(hash_sha256
)
204 raise tornado
.web
.HTTPError(404, "Could not find key: %s" % hash_sha256
)
207 password
= self
.get_argument("password")
208 if not account
.check_password(password
):
209 raise tornado
.web
.HTTPError(403, "Incorrect password for %s" % account
)
212 account
.delete_ssh_key(key
.keydata
)
214 self
.redirect("/users/%s/ssh-keys" % account
.uid
)
217 class SIPHandler(auth
.CacheMixin
, base
.BaseHandler
):
218 @tornado.web
.authenticated
220 account
= self
.backend
.accounts
.get_by_uid(uid
)
222 raise tornado
.web
.HTTPError(404, "Could not find account %s" % uid
)
224 # Check for permissions
225 if not account
.can_be_managed_by(self
.current_user
):
226 raise tornado
.web
.HTTPError(403, "%s cannot manage %s" % (self
.current_user
, account
))
228 self
.render("people/sip.html", account
=account
)
231 class UsersHandler(auth
.CacheMixin
, base
.BaseHandler
):
232 @tornado.web
.authenticated
234 self
.render("people/users.html")
237 class UserHandler(auth
.CacheMixin
, base
.BaseHandler
):
238 @tornado.web
.authenticated
240 account
= self
.backend
.accounts
.get_by_uid(uid
)
242 raise tornado
.web
.HTTPError(404, "Could not find account %s" % uid
)
244 self
.render("people/user.html", account
=account
)
247 class UserEditHandler(auth
.CacheMixin
, base
.BaseHandler
):
248 @tornado.web
.authenticated
250 account
= self
.backend
.accounts
.get_by_uid(uid
)
252 raise tornado
.web
.HTTPError(404, "Could not find account %s" % uid
)
254 # Check for permissions
255 if not account
.can_be_managed_by(self
.current_user
):
256 raise tornado
.web
.HTTPError(403, "%s cannot manage %s" % (self
.current_user
, account
))
258 self
.render("people/user-edit.html", account
=account
)
260 @tornado.web
.authenticated
262 account
= self
.backend
.accounts
.get_by_uid(uid
)
264 raise tornado
.web
.HTTPError(404, "Could not find account %s" % uid
)
266 # Check for permissions
267 if not account
.can_be_managed_by(self
.current_user
):
268 raise tornado
.web
.HTTPError(403, "%s cannot manage %s" % (self
.current_user
, account
))
270 # Unfortunately this cannot be wrapped into a transaction
272 account
.first_name
= self
.get_argument("first_name")
273 account
.last_name
= self
.get_argument("last_name")
274 account
.address
= self
.get_argument("address")
278 filename
, data
, mimetype
= self
.get_file("avatar")
280 if not mimetype
.startswith("image/"):
281 raise tornado
.web
.HTTPError(400, "Avatar is not an image file: %s" % mimetype
)
283 account
.upload_avatar(data
)
288 account
.mail_routing_address
= self
.get_argument("mail_routing_address", None)
291 account
.phone_numbers
= self
.get_argument("phone_numbers", "").splitlines()
292 account
.sip_routing_address
= self
.get_argument("sip_routing_address", None)
293 except ldap
.STRONG_AUTH_REQUIRED
as e
:
294 raise tornado
.web
.HTTPError(403, "%s" % e
) from e
296 # Redirect back to user page
297 self
.redirect("/users/%s" % account
.uid
)
300 class UserPasswdHandler(auth
.CacheMixin
, base
.BaseHandler
):
301 @tornado.web
.authenticated
303 account
= self
.backend
.accounts
.get_by_uid(uid
)
305 raise tornado
.web
.HTTPError(404, "Could not find account %s" % uid
)
307 # Check for permissions
308 if not account
.can_be_managed_by(self
.current_user
):
309 raise tornado
.web
.HTTPError(403, "%s cannot manage %s" % (self
.current_user
, account
))
311 self
.render("people/passwd.html", account
=account
)
313 @tornado.web
.authenticated
315 account
= self
.backend
.accounts
.get_by_uid(uid
)
317 raise tornado
.web
.HTTPError(404, "Could not find account %s" % uid
)
319 # Check for permissions
320 if not account
.can_be_managed_by(self
.current_user
):
321 raise tornado
.web
.HTTPError(403, "%s cannot manage %s" % (self
.current_user
, account
))
323 # Get current password
324 password
= self
.get_argument("password")
327 password1
= self
.get_argument("password1")
328 password2
= self
.get_argument("password2")
330 # Passwords must match
331 if not password1
== password2
:
332 raise tornado
.web
.HTTPError(400, "Passwords do not match")
334 # XXX Check password complexity
336 # Check if old password matches
337 if not account
.check_password(password
):
338 raise tornado
.web
.HTTPError(403, "Incorrect password for %s" % account
)
341 account
.passwd(password1
)
343 # Redirect back to user's page
344 self
.redirect("/users/%s" % account
.uid
)
347 class AccountsListModule(ui_modules
.UIModule
):
348 def render(self
, accounts
=None):
350 accounts
= self
.backend
.accounts
352 return self
.render_string("people/modules/accounts-list.html", accounts
=accounts
)
355 class CDRModule(ui_modules
.UIModule
):
356 def render(self
, account
, date
=None, limit
=None):
357 cdr
= account
.get_cdr(date
=date
, limit
=limit
)
359 return self
.render_string("people/modules/cdr.html", account
=account
, cdr
=cdr
)
362 class ChannelsModule(ui_modules
.UIModule
):
363 def render(self
, account
):
364 return self
.render_string("people/modules/channels.html",
365 account
=account
, channels
=account
.sip_channels
)
368 class MOSModule(ui_modules
.UIModule
):
369 def render(self
, call
):
370 return self
.render_string("people/modules/mos.html", call
=call
)
373 class PasswordModule(ui_modules
.UIModule
):
374 def render(self
, account
):
375 return self
.render_string("people/modules/password.html", account
=account
)
377 def javascript_files(self
):
378 return "js/zxcvbn.js"
380 def embedded_javascript(self
):
381 return self
.render_string("people/modules/password.js")
384 class RegistrationsModule(ui_modules
.UIModule
):
385 def render(self
, account
):
386 return self
.render_string("people/modules/registrations.html", account
=account
)
389 class SIPStatusModule(ui_modules
.UIModule
):
390 def render(self
, account
):
391 return self
.render_string("people/modules/sip-status.html", account
=account
)