예제 #1
0
파일: service.py 프로젝트: yorickvP/kninfra
 def UpdateSiteAgenda(self, request, context):
     with self.operation_lock:
         ret = update_site_agenda()
         if 'success' not in ret:
             context.set_code(grpc.StatusCode.UNKNOWN)
             context.set_details(ret['error'])
     return common_pb2.Empty()
예제 #2
0
파일: __init__.py 프로젝트: thundur/kninfra
 def handle(self, d):
     with self.operation_lock:
         if d['type'] == 'sync':
             return self.sync()
         elif d['type'] == 'setpass':
             u = Es.by_name(d['user'])
             if u is None:
                 return {'error': 'no such user'}
             u = u.as_user()
             if not u.check_password(d['oldpass']):
                 return {'error': 'wrong old password'}
             u.set_password(d['newpass'])
             d2 = {'type': 'setpass',
                   'user': d['user'],
                   'pass': d['newpass']}
             self.daan.send(d2)
             self.cilia.send(d2)
             return {'success': True}
         elif d['type'] == 'set-villanet-password':
             u = Es.by_name(d['user'])
             if u is None:
                 return {'error': 'no such user'}
             u = u.as_user()
             if not u.check_password(d['oldpass']):
                 return {'error': 'wrong current password'}
             pc = Es.PushChange({'system': 'villanet',
                 'action': 'changeUser', 'data': {
                     'username': d['user'],
                     'password': self.villanet_encrypt_password(d['newpass'])
                         }})
             pc.save()
             self.push_changes_event.set()
             return {'success': True}
         elif d['type'] == 'fotoadmin-move-fotos':
             # TODO should this block Giedo?
             ret = self.daan.send(d)
             if 'success' not in ret:
                 return ret
             return self.cilia.send({
                 'type': 'fotoadmin-remove-moved-fotos',
                 'user': d['user'],
                 'dir': d['dir']})
         elif d['type'] == 'openvpn_create':
             # XXX hoeft niet onder de operation_lock
             u = Es.by_name(d['user'])
             if u is None:
                 return {'error': 'no such user'}
             u = u.as_user()
             if d['want'] == 'exe':
                 create_openvpn_installer(self, u)
             else:
                 create_openvpn_zip(self, u)
         elif d['type'] == 'update-site-agenda':
             return update_site_agenda(self)
         elif d['type'] in ['update-knsite', 'update-knfotos',
                 'fotoadmin-create-event']:
             return self.daan.send(d)
         else:
             logging.warn("Unknown command: %s" % d['type'])
예제 #3
0
 def handle(self, d):
     with self.operation_lock:
         if d["type"] == "sync":
             return self.sync()
         elif d["type"] == "setpass":
             u = Es.by_name(d["user"])
             if u is None:
                 return {"error": "no such user"}
             u = u.as_user()
             if not u.check_password(d["oldpass"]):
                 return {"error": "wrong old password"}
             u.set_password(d["newpass"])
             d2 = {"type": "setpass", "user": d["user"], "pass": d["newpass"]}
             self.daan.send(d2)
             self.cilia.send(d2)
             return {"success": True}
         elif d["type"] == "fotoadmin-move-fotos":
             # TODO should this block Giedo?
             ret = self.daan.send(d)
             if "success" not in ret:
                 return ret
             return self.cilia.send({"type": "fotoadmin-remove-moved-fotos", "user": d["user"], "dir": d["dir"]})
         elif d["type"] == "openvpn_create":
             # XXX hoeft niet onder de operation_lock
             u = Es.by_name(d["user"])
             if u is None:
                 return {"error": "no such user"}
             u = u.as_user()
             if d["want"] == "exe":
                 create_openvpn_installer(self, u)
             else:
                 create_openvpn_zip(self, u)
         elif d["type"] == "update-site-agenda":
             return update_site_agenda(self)
         elif d["type"] in ["update-knsite", "update-knfotos", "fotoadmin-create-event"]:
             return self.daan.send(d)
         else:
             print "Unknown command: %s" % d["type"]
예제 #4
0
 def handle(self, d):
     if d['type'] == 'sync':
         with self.operation_lock:
             return self.sync()
     elif d['type'] == 'setpass':
         with self.operation_lock:
             u = Es.by_name(d['user'])
             if u is None:
                 return {'error': 'no such user'}
             u = u.as_user()
             if not u.check_password(d['oldpass']):
                 return {'error': 'wrong old password'}
             u.set_password(d['newpass'])
             d2 = {'type': 'setpass',
                   'user': d['user'],
                   'pass': d['newpass']}
             self.daan.send(d2)
             self.cilia.send(d2)
             return {'success': True}
     elif d['type'] == 'ping':
         return {'pong': True}
     elif d['type'] == 'fotoadmin-scan-userdirs':
         return self.cilia.send(d)
     elif d['type'] == 'fotoadmin-move-fotos':
         with self.operation_lock:
             ret = self.daan.send(d)
             if 'success' not in ret:
                 return ret
             ret = scan_fotos()
             if 'success' not in ret:
                 return ret
             return self.cilia.send({
                 'type': 'fotoadmin-remove-moved-fotos',
                 'store': d['store'],
                 'user': d['user'],
                 'dir': d['dir']})
     elif d['type'] == 'fotoadmin-scan-fotos':
         with self.operation_lock:
             return scan_fotos()
     elif d['type'] == 'update-site-agenda':
         with self.operation_lock:
             return update_site_agenda(self)
     elif d['type'] in ['fotoadmin-create-event']:
         with self.operation_lock:
             return self.daan.send(d)
     elif d['type'] == 'last-synced?':
         return self.last_sync_ts
     elif d['type'] in ('fin-get-account',
                        'fin-get-debitors',
                        'fin-check-names',
                        'fin-get-gnucash-object',
                        'fin-get-years',
                        'fin-get-errors'):
         try:
             return self.moniek.send(d)
         except IOError as e:
             return {'error': 'IOError: ' + e.args[0]}
     elif d['type'] in ('maillist-get-moderated-lists',
                        'maillist-activate-moderation',
                        'maillist-get-moderator-cookie',
                        'maillist-deactivate-moderation'):
         return self.hans.send(d)
     else:
         logging.warn("Unknown command: %s" % d['type'])
예제 #5
0
파일: __init__.py 프로젝트: Jille/kninfra
 def handle(self, d):
     if d['type'] == 'sync':
         with self.operation_lock:
             return self.sync()
     elif d['type'] == 'setpass':
         with self.operation_lock:
             u = Es.by_name(d['user'])
             if u is None:
                 return {'error': 'no such user'}
             u = u.as_user()
             if not u.check_password(d['oldpass']):
                 return {'error': 'wrong old password'}
             u.set_password(d['newpass'])
             d2 = {
                 'type': 'setpass',
                 'user': d['user'],
                 'pass': d['newpass']
             }
             self.daan.send(d2)
             self.cilia.send(d2)
             return {'success': True}
     elif d['type'] == 'set-villanet-password':
         with self.operation_lock:
             u = Es.by_name(d['user'])
             if u is None:
                 return {'error': 'no such user'}
             u = u.as_user()
             if not u.check_password(d['oldpass']):
                 return {'error': 'wrong current password'}
             pc = Es.PushChange({
                 'system': 'villanet',
                 'action': 'changeUser',
                 'data': {
                     'username': d['user'],
                     'password':
                     self.villanet_encrypt_password(d['newpass'])
                 }
             })
             pc.save()
             self.push_changes_event.set()
             return {'success': True}
     elif d['type'] == 'fotoadmin-move-fotos':
         with self.operation_lock:
             # TODO should this block Giedo?
             ret = self.daan.send(d)
             if 'success' not in ret:
                 return ret
             return self.cilia.send({
                 'type': 'fotoadmin-remove-moved-fotos',
                 'user': d['user'],
                 'dir': d['dir']
             })
     elif d['type'] == 'openvpn_create':
         with self.operation_lock:
             # XXX hoeft niet onder de operation_lock?
             u = Es.by_name(d['user'])
             if u is None:
                 return {'error': 'no such user'}
             u = u.as_user()
             if d['want'] == 'exe':
                 create_openvpn_installer(self, u)
             else:
                 create_openvpn_zip(self, u)
     elif d['type'] == 'update-site-agenda':
         with self.operation_lock:
             return update_site_agenda(self)
     elif d['type'] in [
             'update-knsite', 'update-knfotos', 'fotoadmin-create-event'
     ]:
         with self.operation_lock:
             return self.daan.send(d)
     elif d['type'] == 'last-synced?':
         return self.last_sync_ts
     else:
         logging.warn("Unknown command: %s" % d['type'])
예제 #6
0
 def handle(self, d):
     if d['type'] == 'sync':
         with self.operation_lock:
             return self.sync()
     elif d['type'] == 'setpass':
         with self.operation_lock:
             u = Es.by_name(d['user'])
             if u is None:
                 return {'error': 'no such user'}
             u = u.as_user()
             if not u.check_password(d['oldpass']):
                 return {'error': 'wrong old password'}
             u.set_password(d['newpass'])
             d2 = {
                 'type': 'setpass',
                 'user': d['user'],
                 'pass': d['newpass']
             }
             self.daan.send(d2)
             self.cilia.send(d2)
             return {'success': True}
     elif d['type'] == 'ping':
         return {'pong': True}
     elif d['type'] == 'fotoadmin-scan-userdirs':
         return self.cilia.send(d)
     elif d['type'] == 'fotoadmin-move-fotos':
         with self.operation_lock:
             ret = self.daan.send(d)
             if 'success' not in ret:
                 return ret
             ret = scan_fotos()
             if 'success' not in ret:
                 return ret
             return self.cilia.send({
                 'type': 'fotoadmin-remove-moved-fotos',
                 'store': d['store'],
                 'user': d['user'],
                 'dir': d['dir']
             })
     elif d['type'] == 'fotoadmin-scan-fotos':
         with self.operation_lock:
             return scan_fotos()
     elif d['type'] == 'update-site-agenda':
         with self.operation_lock:
             return update_site_agenda(self)
     elif d['type'] in ['fotoadmin-create-event']:
         with self.operation_lock:
             return self.daan.send(d)
     elif d['type'] == 'last-synced?':
         return self.last_sync_ts
     elif d['type'] in ('fin-get-account', 'fin-get-debitors',
                        'fin-check-names', 'fin-get-gnucash-object',
                        'fin-get-years', 'fin-get-errors'):
         try:
             return self.moniek.send(d)
         except IOError as e:
             return {'error': 'IOError: ' + e.args[0]}
     elif d['type'] in ('maillist-get-moderated-lists',
                        'maillist-activate-moderation',
                        'maillist-get-moderator-cookie',
                        'maillist-deactivate-moderation'):
         return self.hans.send(d)
     else:
         logging.warn("Unknown command: %s" % d['type'])