Beispiel #1
0
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})  # 返回成功
Beispiel #2
0
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!'})
Beispiel #3
0
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', {})
Beispiel #4
0
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', {})
Beispiel #5
0
from models import Administrator
from run import init_app

init_app()

admin = Administrator()
admin.username = input("Введите логин для входа в админпанель: ")
admin.password = input("Введите пароль: ")
admin.save()