def Adm_account(): # 获取json if request.method == 'GET': # 处理GET请求 rev_json = request.args cur_account = session.get('admin_login') cur_admin = Administrator.query.filter( Administrator.account == cur_account).first() cur_org = cur_admin.org res = account_list_GET(rev_json, cur_org) if type(res) == list: # 成功返回数据 return jsonify(code=0, data=res) elif type(res) == tuple: # 失败,返回提示信息 code, tip = res return jsonify(code=code, data={'tip': tip}) elif request.method == 'POST': # 处理POST请求 rev_json = request.get_json(silent=True) if rev_json is None: # json为空 return jsonify(code=-101, data=None) admin = Administrator() code, tip = admin_add(admin, rev_json) if code == -101: # 缺少必需参数 return jsonify(code=code, data={'tip': tip}) # 根据发起本次操作的管理的org来决定本次添加的管理员的org opr_admin = Administrator.query.get(session.get('admin_login')) admin.org = opr_admin.org db.session.add(admin) try: db.session.commit() except: db.session.rollback() return jsonify(code=101, data={'error': '数据库异常'}) return jsonify(code=code, data={'tip': tip}) # 返回成功
def assign(): data = json.loads(request.get_data()) if data['uemail'] in session: db.session.add(Administrator(data['uid'], data['wid'])) db.session.commit() return jsonify({'status': 1, 'message': 'Assign Success!'}) else: return jsonify({'status': 0, 'message': 'User haven\'t login yet!'})
def handle_login(): form = LoginForm() if form.validate_on_submit(): user = Administrator.objects(username=form.username.data).first() if validate_login(user, form): login_user(user) flash('Logged in', category='success') return redirect(url_for('admin.index')) else: flash('Wrong username or password', category='danger') return render_template('login.html', form=form)
def registerManager(request): if request.method == 'POST': objs = json.loads(request.body) company = objs['company'].lower() password = objs['password'] email = objs['email'] userQS = User.objects.filter(username=company) userList = list(userQS[:1]) if userList: print 'Paila ya existe el man' return HttpResponse(status=400) userModel = User.objects.create_user(username=company, password=password) userModel.first_name=company userModel.last_name=company userModel.email=email userModel.save() print 'Se crea el usuario' ''' userQS = User.objects.filter(username=company) userList = list(userQS[:1]) userObject = userList[0] ''' manager = Administrator() manager.email=email manager.company=company manager.user=userModel manager.save() myUrl = request.get_raw_uri().replace('register', manager.company + '/' + str(manager.id)) manager.url = myUrl manager.save() print 'Se crea el manager' return JsonResponse({'url':myUrl})
def login(user_id, pin_number, user_role): if user_role == ROLES.get("admin"): administrator = Administrator.get_or_none(Administrator.user_id == user_id) if administrator and (administrator.pin_number == pin_number): session['user_id'] = administrator.id return True elif user_role == ROLES.get("moderator"): moderator = Moderator.get_or_none(Moderator.user_id == user_id) if moderator and (moderator.pin_number == pin_number): session['user_id'] = moderator.id return True elif user_role == ROLES.get("faculty"): faculty = Faculty.get_or_none(Faculty.user_id == user_id) if faculty and(faculty.pin_number == pin_number): session['user_id'] = faculty.id return True else: return False
def create(self, validated_data): admin = Administrator() admin.profile = validated_data.get('profile', None) admin.name = validated_data.get('name', None) admin.email = validated_data.get('email', None) admin.save() magazines = validated_data.get('magazines', []) for index, element in enumerate(magazines): try: magazine = Magazine.objects.get(id=element.get('id', 0)) admin.magazines.add(magazine) except Magazine.DoesNotExist: logger.warn('Magazine related to user was not found. This value will be ignored.') return admin
def load_user(user_id): return Administrator.objects(id=user_id).first()
def loadLoginPage(request): try: userID = request.session['userID'] admin = Administrator.objects.get(pk=userID) cpuRamDisk = SystemInformation.cpuRamDisk() finaData = { "type": admin.type, 'ramUsage': cpuRamDisk['ramUsage'], 'cpuUsage': cpuRamDisk['cpuUsage'], 'diskUsage': cpuRamDisk['diskUsage'] } return render(request, 'baseTemplate/homePage.html', finaData) except KeyError: numberOfAdministrator = Administrator.objects.count() password = hashPassword.hash_password('1234567') if numberOfAdministrator == 0: email = '*****@*****.**' admin = Administrator(userName="******", password=password, type=1, email=email, firstName="Cyber", lastName="Panel") admin.save() vers = version(currentVersion="1.6", build=4) vers.save() package = Package(admin=admin, packageName="Default", diskSpace=1000, bandwidth=1000, ftpAccounts=1000, dataBases=1000, emailAccounts=1000, allowedDomains=20) package.save() newFWRule = FirewallRules(name="panel", proto="tcp", port="8090") newFWRule.save() newFWRule = FirewallRules(name="http", proto="tcp", port="80") newFWRule.save() newFWRule = FirewallRules(name="https", proto="tcp", port="443") newFWRule.save() newFWRule = FirewallRules(name="ftp", proto="tcp", port="21") newFWRule.save() newFWRule = FirewallRules(name="smtp", proto="tcp", port="25") newFWRule.save() newFWRule = FirewallRules(name="smtps", proto="tcp", port="587") newFWRule.save() newFWRule = FirewallRules(name="ssmtp", proto="tcp", port="465") newFWRule.save() newFWRule = FirewallRules(name="pop3", proto="tcp", port="110") newFWRule.save() newFWRule = FirewallRules(name="imap", proto="tcp", port="143") newFWRule.save() newFWRule = FirewallRules(name="simap", proto="tcp", port="993") newFWRule.save() newFWRule = FirewallRules(name="dns", proto="udp", port="53") newFWRule.save() newFWRule = FirewallRules(name="dnstcp", proto="tcp", port="53") newFWRule.save() newFWRule = FirewallRules(name="ftptls", proto="tcp", port="40110-40210") newFWRule.save() return render(request, 'loginSystem/login.html', {}) else: return render(request, 'loginSystem/login.html', {})
def loadLoginPage(request): try: userID = request.session['userID'] admin = Administrator.objects.get(pk=userID) cpuRamDisk = SystemInformation.cpuRamDisk() finaData = {"type": admin.type, 'ramUsage': cpuRamDisk['ramUsage'], 'cpuUsage': cpuRamDisk['cpuUsage'], 'diskUsage': cpuRamDisk['diskUsage']} return render(request, 'baseTemplate/homePage.html', finaData) except KeyError: numberOfAdministrator = Administrator.objects.count() password = hashPassword.hash_password('1234567') if numberOfAdministrator == 0: email = '*****@*****.**' admin = Administrator(userName="******", password=password, type=1,email=email, firstName="Cyber",lastName="Panel") admin.save() vers = version(currentVersion="1.6",build=0) vers.save() package = Package(admin=admin, packageName="Default", diskSpace=1000, bandwidth=1000, ftpAccounts=1000, dataBases=1000, emailAccounts=1000,allowedDomains=20) package.save() newFWRule = FirewallRules(name="panel", proto="tcp", port="8090") newFWRule.save() newFWRule = FirewallRules(name="http", proto="tcp", port="80") newFWRule.save() newFWRule = FirewallRules(name="https", proto="tcp", port="443") newFWRule.save() newFWRule = FirewallRules(name="ftp", proto="tcp", port="21") newFWRule.save() newFWRule = FirewallRules(name="smtp", proto="tcp", port="25") newFWRule.save() newFWRule = FirewallRules(name="smtps", proto="tcp", port="587") newFWRule.save() newFWRule = FirewallRules(name="ssmtp", proto="tcp", port="465") newFWRule.save() newFWRule = FirewallRules(name="pop3", proto="tcp", port="110") newFWRule.save() newFWRule = FirewallRules(name="imap", proto="tcp", port="143") newFWRule.save() newFWRule = FirewallRules(name="simap", proto="tcp", port="993") newFWRule.save() newFWRule = FirewallRules(name="dns", proto="udp", port="53") newFWRule.save() newFWRule = FirewallRules(name="dnstcp", proto="tcp", port="53") newFWRule.save() newFWRule = FirewallRules(name="ftptls", proto="tcp", port="40110-40210") newFWRule.save() return render(request, 'loginSystem/login.html', {}) else: return render(request, 'loginSystem/login.html', {})
def loadLoginPage(request): try: userID = request.session['userID'] currentACL = ACLManager.loadedACL(userID) cpuRamDisk = SystemInformation.cpuRamDisk() if currentACL['admin'] == 1: admin = 1 else: admin = 0 finaData = { "admin": admin, 'ramUsage': cpuRamDisk['ramUsage'], 'cpuUsage': cpuRamDisk['cpuUsage'], 'diskUsage': cpuRamDisk['diskUsage'] } return render(request, 'baseTemplate/homePage.html', finaData) except KeyError: numberOfAdministrator = Administrator.objects.count() password = hashPassword.hash_password('1234567') noOfRules = FirewallRules.objects.count() if noOfRules == 0: newFWRule = FirewallRules(name="panel", proto="tcp", port="8090") newFWRule.save() newFWRule = FirewallRules(name="http", proto="tcp", port="80") newFWRule.save() newFWRule = FirewallRules(name="https", proto="tcp", port="443") newFWRule.save() newFWRule = FirewallRules(name="ftp", proto="tcp", port="21") newFWRule.save() newFWRule = FirewallRules(name="smtp", proto="tcp", port="25") newFWRule.save() newFWRule = FirewallRules(name="smtps", proto="tcp", port="587") newFWRule.save() newFWRule = FirewallRules(name="ssmtp", proto="tcp", port="465") newFWRule.save() newFWRule = FirewallRules(name="pop3", proto="tcp", port="110") newFWRule.save() newFWRule = FirewallRules(name="imap", proto="tcp", port="143") newFWRule.save() newFWRule = FirewallRules(name="simap", proto="tcp", port="993") newFWRule.save() newFWRule = FirewallRules(name="dns", proto="udp", port="53") newFWRule.save() newFWRule = FirewallRules(name="dnstcp", proto="tcp", port="53") newFWRule.save() newFWRule = FirewallRules(name="ftptls", proto="tcp", port="40110-40210") newFWRule.save() newFWRule = FirewallRules(name="quic", proto="udp", port="443") newFWRule.save() if numberOfAdministrator == 0: ACLManager.createDefaultACLs() acl = ACL.objects.get(name='admin') token = hashPassword.generateToken('admin', '1234567') email = '*****@*****.**' admin = Administrator(userName="******", password=password, type=1, email=email, firstName="Cyber", lastName="Panel", acl=acl, token=token) admin.save() vers = version(currentVersion="1.9", build=1) vers.save() package = Package(admin=admin, packageName="Default", diskSpace=1000, bandwidth=1000, ftpAccounts=1000, dataBases=1000, emailAccounts=1000, allowedDomains=20) package.save() return render(request, 'loginSystem/login.html', {}) else: return render(request, 'loginSystem/login.html', {})
from models import Administrator from run import init_app init_app() admin = Administrator() admin.username = input("Введите логин для входа в админпанель: ") admin.password = input("Введите пароль: ") admin.save()