Esempio n. 1
0
def sql_input(request):
    db_configs = DbConfig.objects.all()
    # if request.method == "GET":
    #     pass
    try:
        sql = request.GET["context"]
        ID = request.GET["db_config"]
        the_db_config = DbConfig.objects.get(id=ID)
        the_auth = Auth.objects.get(id=the_db_config.auth)
        sql = "%s %s %s" % ("select", sql, "limit 100;")
        # print sql
        # mysql_cmd_task.delay(the_db_config.address,
        #                      the_auth.username,
        #                      the_auth.password,
        #                      sql,
        #                      request.user.username,
        #                      u'SQL语句执行')
        result = mysql_cmd(the_db_config.address, the_auth.username,
                           the_auth.password, sql)
        if not result:
            result = ({'result': 'success'}, )
        r = SQLResult(content=sql,
                      result=str(result),
                      user=request.user.username,
                      sql_name=u'SQL语句')
        r.save()
        return http_success(request, u'操作成功,请等待执行结果,在SQL执行结果查看.')
    except:
        return render_to_response('database/sql_input.html', locals(),
                                  RequestContext(request))
Esempio n. 2
0
def forget_password(request):
    form = ForgetPasswordForm()
    error = ''
    if request.method == 'POST':
        username = request.POST.get('username')
        email = request.POST.get('email')
        the_user = User.objects.get(username=username)
        if the_user.email == email:
            new_password = ''.join(
                    random.sample([chr(i) for i in range(97, 123)] + [chr(i) for i in range(65, 91)], 8)).replace(
                    ' ', '')
            the_user.set_password(new_password)
            the_user.save()
            # res = URL('%s/tasks/mail' % LOCAL_URL).get_async(subject='test',
            #                                            message='success',
            #                                            from_email=EMAIL_HOST_USER,
            #                                            recipient_list='[the_user.email]',
            #                                            fail_silently=False)
            #
            mail_task.delay(subject=u'用户 %s 密码找回' % the_user.username,
                            message=u'Hi %s:你的新密码为: %s ,请重新登录.' % (the_user.username, new_password),
                            from_email=EMAIL_HOST_USER, recipient_list=[the_user.email], fail_silently=False)
            return http_success(request, u'密码重置成功')
        else:
            error = u'用户名邮箱不匹配'
        return render_to_response('users/forget_password.html', locals(), RequestContext(request))
    else:
        return render_to_response('users/forget_password.html', locals(), RequestContext(request))
Esempio n. 3
0
def exec_rollback(request, ID):
    the_rollback = RollBack.objects.get(id=ID)
    if the_rollback.in_use:
        return http_error(request, u'正式环境为此版本')
    else:
        old_rollback = RollBack.objects.get(in_use=True)
        old_rollback.in_use = False
        old_rollback.save()
        the_project = Project.objects.get(name=the_rollback.project)
        ln_path = os.path.abspath(the_project.server_path)
        pro_server_path = os.path.abspath(
            the_project.server_path) + "_%s" % the_rollback.hash
        pro_host_list = list(eval(the_project.pro_host_list))
        host_list_str = ','.join(pro_host_list)
        salt = SaltApi(SALTAPI_URL, SALTAPI_USER, SALTAPI_PASSWORD)
        salt.login()
        salt.cmd(host_list_str, 'rm -f %s' % ln_path)
        salt.cmd(host_list_str, 'ln -s %s %s' % (pro_server_path, ln_path))
        salt.logout()
        the_rollback.in_use = True
        the_rollback.save()
        pro = ReleaseRecord(project=the_project.name,
                            branch=the_rollback.branch,
                            hash=the_rollback.hash,
                            release_user=request.user)
        pro.save()
        return http_success(request, u'版本回退成功')
Esempio n. 4
0
def sql_input(request):
    db_configs = DbConfig.objects.all()
    # if request.method == "GET":
    #     pass
    try:
        sql = request.GET["context"]
        ID = request.GET["db_config"]
        the_db_config = DbConfig.objects.get(id=ID)
        the_auth = Auth.objects.get(id=the_db_config.auth)
        sql = "%s %s %s" % ("select", sql, "limit 100;")
        # print sql
        # mysql_cmd_task.delay(the_db_config.address,
        #                      the_auth.username,
        #                      the_auth.password,
        #                      sql,
        #                      request.user.username,
        #                      u'SQL语句执行')
        result = mysql_cmd(the_db_config.address, the_auth.username, the_auth.password, sql)
        if not result:
            result = ({'result': 'success'},)
        r = SQLResult(content=sql, result=str(result), user=request.user.username, sql_name=u'SQL语句')
        r.save()
        return http_success(request, u'操作成功,请等待执行结果,在SQL执行结果查看.')
    except:
        return render_to_response('database/sql_input.html', locals(), RequestContext(request))
Esempio n. 5
0
def forget_password(request):
    form = ForgetPasswordForm()
    error = ''
    if request.method == 'POST':
        username = request.POST.get('username')
        email = request.POST.get('email')
        the_user = User.objects.get(username=username)
        if the_user.email == email:
            new_password = ''.join(
                random.sample([chr(i) for i in range(97, 123)] +
                              [chr(i) for i in range(65, 91)],
                              8)).replace(' ', '')
            the_user.set_password(new_password)
            the_user.save()
            # res = URL('%s/tasks/mail' % LOCAL_URL).get_async(subject='test',
            #                                            message='success',
            #                                            from_email=EMAIL_HOST_USER,
            #                                            recipient_list='[the_user.email]',
            #                                            fail_silently=False)
            #
            mail_task.delay(subject=u'用户 %s 密码找回' % the_user.username,
                            message=u'Hi %s:你的新密码为: %s ,请重新登录.' %
                            (the_user.username, new_password),
                            from_email=EMAIL_HOST_USER,
                            recipient_list=[the_user.email],
                            fail_silently=False)
            return http_success(request, u'密码重置成功')
        else:
            error = u'用户名邮箱不匹配'
        return render_to_response('users/forget_password.html', locals(),
                                  RequestContext(request))
    else:
        return render_to_response('users/forget_password.html', locals(),
                                  RequestContext(request))
Esempio n. 6
0
def exec_rollback(request, ID):
    the_rollback = RollBack.objects.get(id=ID)
    if the_rollback.in_use:
        return http_error(request, u'正式环境为此版本')
    else:
        old_rollback = RollBack.objects.get(in_use=True)
        old_rollback.in_use = False
        old_rollback.save()
        the_project = Project.objects.get(name=the_rollback.project)
        ln_path = os.path.abspath(the_project.server_path)
        pro_server_path = os.path.abspath(the_project.server_path) + "_%s" % the_rollback.hash
        pro_host_list = list(eval(the_project.pro_host_list))
        host_list_str = ','.join(pro_host_list)
        salt = SaltApi(SALTAPI_URL, SALTAPI_USER, SALTAPI_PASSWORD)
        salt.login()
        salt.cmd(host_list_str, 'rm -f %s' % ln_path)
        salt.cmd(host_list_str, 'ln -s %s %s' % (pro_server_path, ln_path))
        salt.logout()
        the_rollback.in_use = True
        the_rollback.save()
        pro = ReleaseRecord(project=the_project.name,
                            branch=the_rollback.branch,
                            hash=the_rollback.hash,
                            release_user=request.user)
        pro.save()
        return http_success(request, u'版本回退成功')
Esempio n. 7
0
def add_test(request):
    if request.method == "POST":
        form = TestForm(request.POST)
        if form.is_valid():
            form.save()
            git_co_task.delay(0)
            return http_success(request, u'测试例添加成功')
    else:
        form = TestForm()
    return render_to_response('release/add_test.html', locals(), RequestContext(request))
Esempio n. 8
0
def add_test(request):
    if request.method == "POST":
        form = TestForm(request.POST)
        if form.is_valid():
            form.save()
            git_co_task.delay(0)
            return http_success(request, u'测试例添加成功')
    else:
        form = TestForm()
    return render_to_response('release/add_test.html', locals(),
                              RequestContext(request))
Esempio n. 9
0
def edit_test(request, ID):
    the_test = Test.objects.get(id=ID)
    the_test.host_list = list(eval(the_test.host_list))
    if request.method == "POST":
        form = TestForm(request.POST, instance=the_test)
        if form.is_valid():
            form.save()
            git_co_task.delay(ID)
            return http_success(request, u'测试例修改成功')
    else:
        form = TestForm(instance=the_test)
    return render_to_response('release/edit_test.html', locals(), RequestContext(request))
Esempio n. 10
0
def edit_test(request, ID):
    the_test = Test.objects.get(id=ID)
    the_test.host_list = list(eval(the_test.host_list))
    if request.method == "POST":
        form = TestForm(request.POST, instance=the_test)
        if form.is_valid():
            form.save()
            git_co_task.delay(ID)
            return http_success(request, u'测试例修改成功')
    else:
        form = TestForm(instance=the_test)
    return render_to_response('release/edit_test.html', locals(),
                              RequestContext(request))
Esempio n. 11
0
def upload(request):
    if request.method == "POST":
        os.system('rm -rf %s/static/sql/*' % BASE_DIR)
        upload_files = request.FILES.getlist('file[]', None)
        for upload_file in upload_files:
            file_path = '%s/%s/%s' % (BASE_DIR, 'static/sql', upload_file.name)
            if os.path.exists(file_path):
                os.remove(file_path)
            if upload_file.name[-4:] == '.sql':
                with open(file_path, 'w') as f:
                    for chunk in upload_file.chunks():
                        f.write(chunk)
        return http_success(request, 'ok')
    return render_to_response('database/upload.html', locals(), RequestContext(request))
Esempio n. 12
0
def upload(request):
    if request.method == "POST":
        os.system('rm -rf %s/static/sql/*' % BASE_DIR)
        upload_files = request.FILES.getlist('file[]', None)
        for upload_file in upload_files:
            file_path = '%s/%s/%s' % (BASE_DIR, 'static/sql', upload_file.name)
            if os.path.exists(file_path):
                os.remove(file_path)
            if upload_file.name[-4:] == '.sql':
                with open(file_path, 'w') as f:
                    for chunk in upload_file.chunks():
                        f.write(chunk)
        return http_success(request, 'ok')
    return render_to_response('database/upload.html', locals(),
                              RequestContext(request))
Esempio n. 13
0
def del_rollback(request, ID):
    the_rollback = RollBack.objects.get(id=ID)
    if the_rollback.in_use:
        return http_error(request, u'不能删除正在使用的版本')
    else:
        the_project = Project.objects.get(name=the_rollback.project)
        pro_server_path = os.path.abspath(the_project.server_path) + "_%s" % the_rollback.hash
        pro_host_list = list(eval(the_project.pro_host_list))
        host_list_str = ','.join(pro_host_list)
        salt = SaltApi(SALTAPI_URL, SALTAPI_USER, SALTAPI_PASSWORD)
        salt.login()
        salt.cmd(host_list_str, 'rm -rf %s' % pro_server_path)
        salt.logout()
        the_rollback.delete()
        return http_success(request, u'版本删除成功')
Esempio n. 14
0
def del_rollback(request, ID):
    the_rollback = RollBack.objects.get(id=ID)
    if the_rollback.in_use:
        return http_error(request, u'不能删除正在使用的版本')
    else:
        the_project = Project.objects.get(name=the_rollback.project)
        pro_server_path = os.path.abspath(
            the_project.server_path) + "_%s" % the_rollback.hash
        pro_host_list = list(eval(the_project.pro_host_list))
        host_list_str = ','.join(pro_host_list)
        salt = SaltApi(SALTAPI_URL, SALTAPI_USER, SALTAPI_PASSWORD)
        salt.login()
        salt.cmd(host_list_str, 'rm -rf %s' % pro_server_path)
        salt.logout()
        the_rollback.delete()
        return http_success(request, u'版本删除成功')
Esempio n. 15
0
def exec_sql(request):
    file_name = request.GET["file_name"]
    ID = request.GET["db_config"]
    exec_method = request.GET["exec_method"]
    the_db_config = DbConfig.objects.get(id=ID)
    the_auth = Auth.objects.get(id=the_db_config.auth)
    f = open(os.path.join(SQL_DIRS, file_name))
    sql = f.read()
    if exec_method:
        script_mysql_task.delay(the_db_config.address, the_auth.username,
                                the_auth.password, sql, file_name,
                                request.user.username)
    else:
        mysql_cmd_task.delay(the_db_config.address, the_auth.username,
                             the_auth.password, sql, request.user.username,
                             file_name)
    return http_success(request, u'操作成功,请等待执行结果,在SQL执行结果查看.')
Esempio n. 16
0
def exec_sql(request):
    file_name = request.GET["file_name"]
    ID = request.GET["db_config"]
    exec_method = request.GET["exec_method"]
    the_db_config = DbConfig.objects.get(id=ID)
    the_auth = Auth.objects.get(id=the_db_config.auth)
    f = open(os.path.join(SQL_DIRS, file_name))
    sql = f.read()
    if exec_method:
        script_mysql_task.delay(the_db_config.address,
                                the_auth.username,
                                the_auth.password,
                                sql,
                                file_name,
                                request.user.username)
    else:
        mysql_cmd_task.delay(the_db_config.address,
                             the_auth.username,
                             the_auth.password,
                             sql,
                             request.user.username,
                             file_name)
    return http_success(request, u'操作成功,请等待执行结果,在SQL执行结果查看.')