def save(self, commit=True): instance = super(userForm, self).save(commit=False) try: User.objects.get(id=instance.id) if commit: instance.save() self.save_m2m() return instance, None except(User.DoesNotExist): instance.name = self.cleaned_data['name'] password = random_password() instance.info = {'name': instance.name or instance.user_id, 'password': make_password(password)} instance.institution = self.cleaned_data['institution'] if self.logged_user.superadmin_p: instance.management_p = self.cleaned_data.get('management_p') instance.admin_p = True instance.user_type = 'password' instance.superadmin_p = False instance.ecounting_account = False if commit: instance.save() self.save_m2m() return instance, password
def reset_password_confirmed(request): if request.method != 'POST': raise PermissionDenied uid = request.GET.get('uid') uid = sanitize_get_param(uid) logged_user = request.zeususer._user user = get_user(uid) if user: if can_do(logged_user, user): new_password = random_password() user.info['password'] = make_password(new_password) user.save() message = _("New password for user %(uid)s is " "%(new_pass)s") % { 'uid': user.user_id, 'new_pass': new_password } messages.info(request, message) else: message = _("You are not authorized to do this") messages.error(request, message) else: message = _("You didn't choose a user") messages.error(request, message) return redirect(reverse('list_users')) url = "%s?uid=%s" % (reverse('user_management'), str(user.id)) return redirect(url)
def create(username, domain, email, password=None): # domain = get_domain_top(domain) print(f'Creating {email}@{domain} for user {username}') if os.popen(f'grep {domain} /etc/apache2/sites-available/001-mail.conf').read().strip() == '': configure(username, domain) uid = get_uid(username) gid = get_gid(username) home = f'/home/{username}' if not password: password = random_password(12) password_hash = crypt.crypt(password, crypt.mksalt(crypt.METHOD_SHA256)) global emails emails = [] conn = sqlite3.connect('/etc/dovecot/authdb.sqlite') c = conn.cursor() c.execute('DELETE FROM users WHERE username = ? AND domain = ?;', (email, domain)) c.execute('INSERT INTO users (username, domain, password, home, uid, gid) VALUES (?, ?, ?, ?, ?, ?);', (email, domain, password_hash, home, uid, gid)) conn.commit() conn.close() print(f'\n\n\t\tNew password of {email}@{domain}: {password}') domain = get_domain_top(domain) print(f'\t\tPOP3 hostname: pop3.{domain}') print(f'\t\tSMTP hostname: smtp.{domain}\n\n') print('Restarting Dovecot...') os.system('service dovecot restart')
def save(self, commit=True): instance = super(userForm, self).save(commit=False) try: User.objects.get(id=instance.id) if commit: instance.save() self.save_m2m() return instance, None except (User.DoesNotExist): instance.name = self.cleaned_data['name'] password = random_password() instance.info = { 'name': instance.name or instance.user_id, 'password': make_password(password) } instance.institution = self.cleaned_data['institution'] if self.logged_user.superadmin_p: instance.management_p = self.cleaned_data.get('management_p') instance.admin_p = True instance.user_type = 'password' instance.superadmin_p = False instance.ecounting_account = False if commit: instance.save() self.save_m2m() return instance, password
def reset_user(self, mail): new_password = random_password() try: user = self.person_get(mail=mail) user.password = generate_password_hash(new_password) user.save() return new_password except DoesNotExist: abort(400, 'Email address not registered :(')
def reset_user(self, email): new_password = random_password() try: user = self.person_get(email=email) user.password = generate_password_hash(new_password) user.save() return new_password except DoesNotExist: abort(400, 'Email address not registered :(')
def _create_replicator(self, db_version): db_out = run("echo '\du replicator' | sudo su postgres -c 'psql'") if 'replicator' not in db_out: replicator_pass = random_password(12) c1 = ('CREATE USER replicator REPLICATION LOGIN ENCRYPTED ' 'PASSWORD \"\'%s\'\"' %replicator_pass) run("echo %s | sudo su postgres -c \'psql\'" %c1) history_file = os.path.join('/var', 'pgsql', '.psql_history') if exists(history_file): sudo('rm %s' %history_file) print "user replicator already exists, skipping creating user." env.config_object.set('db-server', env.config_object.REPLICATOR, 'replicator') env.config_object.set('db-server', env.config_object.REPLICATOR_PASS, replicator_pass) return replicator_pass
def reset_password_confirmed(request): uid = request.GET.get('uid') uid = sanitize_get_param(uid) logged_user = request.zeususer._user user = get_user(uid) if user: if can_do(logged_user, user): new_password = random_password() user.info['password'] = make_password(new_password) user.save() message = _("New password for user %(uid)s is " "%(new_pass)s") % {'uid': user.user_id, 'new_pass': new_password} messages.info(request, message) else: message = _("You are not authorized to do this") messages.error(request, message) else: message = _("You didn't choose a user") messages.error(request, message) return redirect(reverse('list_users')) url = "%s?uid=%s" % (reverse('user_management'), str(user.id)) return redirect(url)
""" SETTINGS This module holds the information for the new project. Most of them are paths or credentials. """ import sys from os import path from utils import get_project_directory, random_password, make_project_user __author__ = 'snake' ocean = sys.argv[1].lower() project_user = make_project_user(ocean) project_directory = get_project_directory() settings_directory = path.join(project_directory, ocean) secret_key = random_password() ssh_pass = random_password() db_pass = random_password()
def share_folder(self, fs_id): data_item: DataItem = DataDao.get_data_item_by_fs_id(fs_id) share_log: ShareLogs = DataDao.query_shared_log_by_fs_id(fs_id) need_create_share_file = True expired_at = arrow.get(data_item.dlink_updated_at).replace( tzinfo=self.default_tz).shift(hours=+DLINK_TIMEOUT).datetime if share_log: jsonrs = restapi.get_share_info(share_log.share_id, share_log.special_short_url(), share_log.randsk) # print('"shareid" in jsonrs and "uk" in jsonrs ? ', "shareid" in jsonrs and "uk" in jsonrs) if jsonrs and "shareid" in jsonrs and "uk" in jsonrs: if data_item.dlink and not share_log.dlink: pan_acc: PanAccounts = self.get_pan_account( data_item.panacc, data_item.account_id) if data_item.dlink: dlink = "%s&access_token=%s" % (data_item.dlink, pan_acc.access_token) share_log.dlink = dlink DataDao.update_share_log_by_pk(share_log.id, {'dlink': dlink}) dict_obj = ShareLogs.to_dict(share_log) dict_obj['expired_at'] = expired_at return dict_obj, share_log, data_item else: DataDao.del_share_log_by_pk(share_log.id) logger.info("need_create_share_file:{}, fs_id:{}".format( need_create_share_file, fs_id)) if need_create_share_file: pwd = random_password(4) period = 1 pan_acc: PanAccounts = self.get_pan_account( data_item.panacc, data_item.account_id) dlink = None if data_item.dlink: dlink = "%s&access_token=%s" % (data_item.dlink, pan_acc.access_token) share_log_id, share_log = DataDao.new_share_log( fs_id, data_item.filename, data_item.md5_val, dlink, pwd, period, data_item.account_id, pan_acc.id) logger.info("share_log_id:{}, fs_id:{}, pan_acc_id:{}".format( share_log_id, fs_id, pan_acc.id)) if share_log_id: jsonrs = restapi.share_folder(pan_acc.access_token, fs_id, pwd, period) logger.info("share_folder jsonrs:{}, fs_id:{}".format( jsonrs, fs_id)) if restapi.is_black_list_error(jsonrs): share_log.is_black = 1 err_msg = jsonrs.get('err_msg', '') if "show_msg" in jsonrs: err_msg = jsonrs['show_msg'] share_log.err = err_msg DataDao.update_share_log_by_pk(share_log_id, { "is_black": share_log.is_black, "err": share_log.err }) dict_obj = ShareLogs.to_dict(share_log) dict_obj['expired_at'] = expired_at return dict_obj, share_log, data_item if "shareid" in jsonrs and "shorturl" in jsonrs: _shareid = jsonrs["shareid"] if _shareid == -1: err_msg = jsonrs.get('err_msg', '') share_log.is_failed = 1 share_log.err = err_msg DataDao.update_share_log_by_pk(share_log_id, { "is_failed": share_log.is_failed, "err": share_log.err }) dict_obj = ShareLogs.to_dict(share_log) return dict_obj, share_log, data_item else: share_log.share_id = str(jsonrs["shareid"]) share_log.link = jsonrs["link"] share_log.shorturl = jsonrs["shorturl"] share_log.pin = 2 params = { "share_id": share_log.share_id, "link": share_log.link, "shorturl": share_log.shorturl, "pin": share_log.pin } DataDao.update_share_log_by_pk(share_log_id, params) jsonrs = restapi.get_share_randsk( share_log.share_id, share_log.password, share_log.common_short_url()) logger.info( "get_share_randsk jsonrs:{}, fs_id:{}".format( jsonrs, fs_id)) if "randsk" in jsonrs: share_log.randsk = jsonrs["randsk"] jsonrs = restapi.get_share_info( share_log.share_id, share_log.special_short_url(), share_log.randsk) if jsonrs and "shareid" in jsonrs and "uk" in jsonrs: share_log.uk = str(jsonrs["uk"]) share_log.pin = 3 params = { "randsk": share_log.randsk, "uk": share_log.uk, "pin": share_log.pin } DataDao.update_share_log_by_pk( share_log_id, params) dict_obj = ShareLogs.to_dict(share_log) dict_obj['expired_at'] = expired_at return dict_obj, share_log, data_item return {}, None, data_item