Ejemplo n.º 1
0
def restart_closed_job(request):
    if request.method == 'GET':
        did = request.GET.get('d')
        dash = validate_dashboard(did, request.user, request.RSL_ID)
        if not dash:
            return send_error(request, _('no such item'))
        dash.done_date = None
        dash.is_done = False
        dash.last_state = 0
        dash.save()
        uw = UserWorkHistory()
        uw.dashboard = dash
        g = request.user.groups.first()
        if not g:
            g = dash.group_id
        else:
            g = g.pk
        uw.group_id = g
        uw.start_date = now()
        uw.state = 2
        uw.user = request.user
        uw.message = _('job restarted')
        uw.save()
        return HttpResponse('200')
    return send_error(request, _('invalid method'))
Ejemplo n.º 2
0
def forget_password(request):
    res = get_user_name_from_ip(request)
    if res is None:
        res = ''
    if request.method == 'GET':
        return render(request, 'login/ForgetPassword.html', {'username': res})
    elif request.method == 'POST':
        try:
            data = request.POST.get('u')
            res = User.objects.filter(Q(username=data) | Q(fk_user_profile_user__mobile=data))
            if res.count() > 1:
                return send_error(request, _('the data you provided is not valid'))
            u = res.first()
            if not u:
                return send_error(request, _('invalid user'))
        except Exception as e:
            logger.error(e.message or e.args)
            return send_error(request, _('system error'))
        r = ''.join(random.choice(string.lowercase) for i in range(5))
        u.set_password(r)
        u.save()
        # fire_event(4026, u, None, u.pk)
        PasswordChangedNotification().send(user_id=u.pk, password=r, change_type='crm')
        # send_from_template.delay(u.pk, 4, cp=r)
        return HttpResponse('200')
    else:
        return render(request, 'errors/AccessDenied.html')
Ejemplo n.º 3
0
def create_internet_account(request):
    if request.method == 'GET':
        uid = request.GET.get('u')
        if not validate_integer(uid):
            return send_error(request, _('no user selected'))
        if not User.objects.filter(pk=uid).exists():
            return redirect('/')
        ibs = IBSManager()
        rnd = ''.join(random.choice(string.lowercase) for i in range(5))
        u = User.objects.get(pk=uid)
        u.is_active = True
        if not ibs.add_new_user(u.username, rnd, 0):
            return send_error(request, _('unable to create ibs user'))
        u.set_password(rnd)
        u.save()
        ib_id = ibs.get_user_id_by_username(u.username)
        ibi = IBSUserInfo()
        ibi.ibs_uid = int(ib_id)
        ibi.user = u
        ibi.save()
        u.groups.add(Group.objects.get(pk=int(read_config('groups_customer', 1))))
        update_ibs_user_from_crm(u.pk)
        fire_event(4537, u, None, request.user.pk)
        return redirect('/user/nav/?uid=%s' % uid)
    else:
        return redirect('/')
Ejemplo n.º 4
0
def add_partner_to_job(request):
    dash = validate_dashboard(request.POST.get('d'), request.user)
    tu = validate_user(request.POST.get('t'))
    cmd = get_integer(request.POST.get('c'))
    max_users = int(read_config('dashboard_max_partner', 5))
    if not dash:
        return send_error(request, _('invalid dashboard'))
    if not tu:
        return send_error(request, _('invalid user'))
    if not cmd:
        return send_error(request, _('invalid item'))
    if cmd == 1:
        if TicketTeam.objects.filter(dashboard=dash.pk, user=tu.pk).exists():
            return send_error(request, _('this user has been selected before'))
        if TicketTeam.objects.filter(dashboard=dash.pk).count() >= max_users:
            return send_error(request, _('max users selected'))
        tt = TicketTeam()
        tt.user = tu
        tt.dashboard = dash
        tt.save()
        msg = '%s : %s' % (_('user added to job'), tu.first_name)
        add_work_history_outbox(dash, request.user, msg)
    elif cmd == 2:
        if not TicketTeam.objects.filter(dashboard=dash.pk,
                                         user=tu.pk).exists():
            return HttpResponse('200')
        TicketTeam.objects.get(dashboard=dash.pk, user=tu.pk).delete()
        msg = '%s : %s' % (_('user removed from job'), tu.first_name)
        add_work_history_outbox(dash, request.user, msg)
    return HttpResponse('200')
Ejemplo n.º 5
0
def get_user_debit_json(request):
    if request.method == 'GET':
        uid = request.GET.get('u')
        user = validate_user(uid)
        if not user:
            return send_error(request, _('invalid user'))
        res = {
            'username': user.username,
            'name': user.first_name,
            'debit': 0,
            'last_debit': 0,
            'comment': '',
            'subject': '',
            'pk': uid
        }
        if UserDebit.objects.for_reseller(
                request.RSL_ID).filter(user_id=uid).exists():
            d = UserDebit.objects.get(user_id=uid)
        else:
            return HttpResponse(json.dumps(res))
        res['username'] = user.username
        res['debit'] = d.amount
        res['last_debit'] = d.last_amount
        res['comment'] = d.description
        res['subject'] = d.subject.name
        return HttpResponse(json.dumps(res))
    return send_error(request, _('invalid method'))
Ejemplo n.º 6
0
def add_equipment_group(request):
    name = get_string(request.POST.get('n'))
    des = get_string(request.POST.get('d'))
    eq_type = get_equipment_type_ext(request.POST.get('t'))
    old = get_equipment_group(request.POST.get('pk'))
    code = get_equipment_code(request.POST.get('c'))
    if not name:
        return send_error(request, _('please enter name'))
    if not code:
        return send_error(request, _('please select a code'))
    if not des:
        des = '--'
    if not eq_type:
        return send_error(request, _('please select a group'))
    if old:
        eq = old
    else:
        if EquipmentGroup.objects.filter(name__iexact=name).exists():
            return send_error(request, _('item exists'))
        eq = EquipmentGroup()
    eq.name = name
    eq.description = des
    eq.equipment_type = eq_type
    eq.code = code
    eq.save()
    return HttpResponse(eq.pk)
Ejemplo n.º 7
0
def config_management(request):
    if request.method == 'GET':
        reload_from_cache = request.GET.get('relocate', '0') == 'YES!PLEASE!'
        conf = get_config()
        data = {}
        sections = conf.sections()
        for s in sections:
            opt = {}
            ox = conf.options(s)
            for o in ox:
                if reload_from_cache:
                    new_config = read_config('%s_%s' % (s, o))
                    set_config(s, o, new_config)
                    dx = {o: new_config}
                else:
                    dx = {o: conf.get(s, o)}
                opt.update(dx)
            data.update({s: opt})
        return render(request, 'configuration/ConfigManagement.html', {'data': data})
    elif request.method == 'POST':
        name = get_string(request.POST.get('name'))
        value = get_string(request.POST.get('value'))
        if not name:
            return send_error(request, _('invalid item'))
        if not value:
            return send_error(request, _('invalid value'))
        section = name.split('__')
        if len(section) < 2:
            return send_error(request, _('invalid value'))
        set_config(section[0], section[1], value)
        load_config(True)
        return HttpResponse('200')
    else:
        return send_error(request, _('invalid method'))
Ejemplo n.º 8
0
def edit_debit_subjects(request):
    if request.method == 'GET':
        sid = request.GET.get('s')
        subject = validate_debit_subject(sid)
        if not subject:
            return send_error(request, _('not found'))
        return HttpResponse(
            json.dumps({
                'pk': subject.pk,
                'name': subject.name,
                'des': subject.description
            }))
    elif request.method == 'POST':
        sid = request.POST.get('s')
        subject = validate_debit_subject(sid)
        if not subject:
            subject = DebitSubject()
        name = request.POST.get('n')
        des = request.POST.get('d')

        if not validate_empty_str(name):
            return send_error(request, _('please enter name'))
        if not validate_empty_str(des):
            return send_error(request, _('please enter description'))
        subject.name = name
        subject.description = des
        subject.save()
        return HttpResponse('200')
    return send_error(request, _('invalid method'))
Ejemplo n.º 9
0
def view_public_dedicated_profit(request):
    if request.method == 'GET':
        return render(request, 'public/ResellerProfit.html')
    elif request.method == 'POST':
        # base_price = 240000
        action = request.POST.get('a')
        if action == '1':
            sell = get_integer(request.POST.get('s').replace(',', ''))
            res = {
                'internet': int(sell * 1.5),
                'once': int(sell),
                'monthly': int(sell * 0.10)
            }
            return HttpResponse(json.dumps(res))
        elif action == '2':
            is_special = 'cSP' in request.POST
            bw = get_integer(request.POST.get('b'))
            sell = get_integer(request.POST.get('sd').replace(',', ''))
            if is_special:
                min_price = read_config('visitor_special_min', 240000)
                if sell < min_price:
                    return send_error(
                        request,
                        _('min price value is') + ' ' + str(min_price))
            else:
                min_price = read_config('visitor_normal_min', 170000)
                if sell < min_price:
                    return send_error(
                        request,
                        _('min price value is') + ' ' + str(min_price))
            co_profit = (sell - min_price) * bw  # B9
            if is_special:
                one_time = co_profit * 2.2
                monthly = co_profit * 0.3
            else:
                one_time = co_profit * 2.2
                monthly = co_profit * 0.3
            res = {'once': int(one_time), 'monthly': int(monthly)}
            return HttpResponse(json.dumps(res))
        elif action == '3':
            bw = get_integer(request.POST.get('bi'))
            sell = get_integer(request.POST.get('si').replace(',', ''))
            base_price = read_config('visitor_intranet_base_price', 30000)
            if sell < base_price:
                return send_error(
                    request,
                    _('min price value is') + ' ' + str(base_price))
            co_profit = (sell - base_price) * bw
            one_time = co_profit * 2.2
            monthly = co_profit * 0.3
            return HttpResponse(
                json.dumps({
                    'once': int(one_time),
                    'monthly': int(monthly)
                }))
        else:
            logger.warning('invalid action requested %s' % action)
            return send_error(request, _('unknown request'))
Ejemplo n.º 10
0
def get_tower_description(request):
    if request.method == 'GET':
        tid = request.GET.get('t')
        v_res = validate_single_tower(tid)
        if not v_res[0]:
            return send_error(request, v_res[1])
        tower = v_res[1]
        return HttpResponse(tower.description)
    return send_error(request, _('invalid tower'))
Ejemplo n.º 11
0
def reject_equipment_order_item(request):
    order = get_equipment_order_item_ext(request.POST.get('pk'))
    reason = get_string(request.POST.get('r'))
    if not order:
        return send_error(request, _('invalid order'))
    if not reason:
        return send_error(request, _('please enter reject reason'))
    order.reject(reason)
    return HttpResponse(order.ext)
Ejemplo n.º 12
0
def remove_transport_for_job(request):
    dash = validate_dashboard(request.GET.get('d'))
    if not dash:
        return send_error(request, _('invalid dashboard'))
    if not TicketTransportation.objects.filter(dashboard=dash.pk).exists():
        return send_error(request, _('invalid item'))
    TicketTransportation.objects.get(dashboard=dash.pk).delete()
    add_work_history_outbox(dash, request.user, _('transport removed'))
    return HttpResponse('200')
Ejemplo n.º 13
0
def edit_user_basics(request):
    u = request.user
    granted = False
    if u.is_staff or u.is_superuser:
        granted = True
    if request.method == 'GET':
        if granted:
            uid = request.GET.get('u')
        else:
            uid = u.pk
        try:
            user = User.objects.get(pk=uid)
            profile = UserProfile.objects.filter(user=uid).first()
            if not profile:
                profile = UserProfile()
            history = profile.history.all().order_by('-pk')[:5]
            return render(request, 'user/EditUserBasics.html', {
                'u': user,
                'profile': profile,
                'history': history,
            })
        except Exception as e:
            logger.error(e.message or e.args)
            return send_error(request, _('system error'))
    elif request.method == 'POST':
        um = UserManager(request)
        try:
            um.set_post()
            uid = um.create_profile().user_id
            if um.is_normal_user:
                update_ibs_user_from_crm(uid)
            elif um.is_company:
                um.set_company()
            if um.is_dedicate:
                um.set_dedicate()
            if request.user.is_superuser:
                if um.is_personnel:
                    um.unset_superuser()
                    um.set_personnel()
                elif um.is_superuser:
                    um.set_superuser()
            if um.is_personnel:
                if um.is_reseller:
                    um.create_reseller()
                else:
                    um.remove_reseller()
                if um.is_visitor:
                    um.create_visitor()
        except RequestProcessException as e:
            return e.get_response()
        except Exception as e:
            logger.error(e.message or e.args)
            return send_error(request, _('system error'))
        return HttpResponse('200')
    else:
        return render(request, 'errors/AccessDenied.html')
Ejemplo n.º 14
0
def delete_working_time(request):
    pk = get_integer(request.GET.get('w'), True)
    if not pk.is_success():
        return send_error(request, _('invalid week day'))
    work = get_working_time_by_pk(pk.value())
    if not work:
        return send_error(request, _('invalid week day'))
    work.is_deleted = True
    work.save()
    return HttpResponse('200')
Ejemplo n.º 15
0
def remove_transport(request):
    t = get_uuid(request.GET.get('t'))
    if not t:
        return send_error(request, _('invalid item'))
    if not Transportation.objects.filter(pk=t, is_deleted=False).exists():
        return send_error(request, _('invalid item'))
    i = Transportation.objects.get(external=t)
    i.is_deleted = True
    i.save()
    return HttpResponse('200')
Ejemplo n.º 16
0
def user_switcher_switch(request):
    try:
        um = UserManager(request)
        if um.switch_user():
            return redirect('/')
        else:
            return send_error(request, _('you can not switch this user'))
    except Exception as e:
        logger.error(e.message or e.args)
        return send_error(request, _('server error'))
Ejemplo n.º 17
0
def create_debit_package_invoice(request):
    pack = get_charge_package_ext(request.GET.get('pk'))
    if not pack:
        return send_error(request, _('invalid item'))
    x = InvoiceGen(service=pack, uid=request.user.pk, service_type=4)
    x.calculate()
    if x.get_is_done():
        i = x.get_invoice()
        i.save()
        return HttpResponse(i.pk)
    return send_error(request, _('system error'))
Ejemplo n.º 18
0
def get_config_state(request):
    command = get_integer(request.GET.get('c'))
    if not command:
        return send_error(request, _('invalid command'))
    if command == 1:
        load_config(True)
        return HttpResponse(get_state())
    elif command == 2:
        return HttpResponse(get_state())
    else:
        return send_error(request, _('invalid command'))
Ejemplo n.º 19
0
def add_new_transport_type(request):
    name = get_string(request.POST.get('n'))
    if not name:
        return send_error(request, _('please enter name'))
    if TransportType.objects.filter(name__iexact=name,
                                    is_deleted=False).exists():
        return send_error(request, _('this name is exists'))
    t = TransportType()
    t.name = name
    t.save()
    return HttpResponse('200')
Ejemplo n.º 20
0
def service_kill_current_user(request):
    try:
        sm = BasicServiceManager(request)
        x = sm.get_target_user(False)
        if x.is_anonymous():
            return send_error(request, _('unable to complete disconnect'))
        Utils.kill_user_by_request(x.pk, request)
        return HttpResponse('200')
    except Exception as e:
        logger.error(e.message or e.args)
        return send_error(request, _('system error'))
Ejemplo n.º 21
0
def add_new_equipment_type(request):
    name = get_string(request.POST.get('n'))
    tx = get_equipment_type_ext(request.POST.get('pk'))
    if not name:
        return send_error(request, _('please enter name'))
    if not tx:
        if EquipmentType.objects.filter(is_deleted=False, name__iexact=name).exists():
            return send_error(request, _('item exists'))
        tx = EquipmentType()
    tx.name = name
    tx.save()
    return HttpResponse(tx.ext)
Ejemplo n.º 22
0
def frm_login(request):
    # if request.META.get('HTTP_HOST') not in read_config('login_base_address', 'http://payment.gen-co.com/'):
    #     return redirect(read_config('login_base_address', 'http://payment.gen-co.com/'))
    if request.user.is_authenticated():
        return redirect('/')
    if request.method == 'GET':
        if not request.GET.get('skip'):
            if settings.IPL_DEBUG and get_client_ip(
                    request) == settings.IPL_DEBUG_HOST:
                res = settings.IPL_DEBUG_USER
            else:
                res = get_user_name_from_ip(request)
            if res:
                if User.objects.filter(username=res).exists():
                    requested_user = User.objects.get(username=res)
                    if not requested_user.is_staff:  # bug fix for personnel login fom home!
                        uid = requested_user.pk
                        request.session['cui'] = uid
                        LoginWithIPEventHandler().fire(
                            User.objects.get(pk=uid), None, uid)
                        return redirect('/user/nav/?uid=%s' % uid)
        return render(request, 'login/Login.html')
    elif request.method == 'POST':
        u_name = request.POST.get('u', -1)
        u_pass = request.POST.get('p', -1)
        if u_name is -1 or u_pass is -1:
            return send_error(request, _('invalid username or password'))
        user = authenticate(username=u_name, password=u_pass)
        ll = LoginLogs()
        if user is None:
            if User.objects.filter(username=u_name).exists():
                ll.user = User.objects.get(username=u_name)
                ll.ip_address = get_client_ip(request)
                ll.state = False
                ll.save()
            return send_error(request, _('invalid username or password'))

        try:
            ll.user = user
            ll.state = True
            ll.ip_address = get_client_ip(request)
            ll.save()
            if not user.is_active:
                InactiveAccountLoginEventHandler().fire(user, None, user.pk)
                return send_error(request, _('your account has been locked'))
            login(request, user)
            return HttpResponse('200')
        except Exception as e:
            print e.message or e.args
            return HttpResponseBadRequest('unknown error')
    else:
        return render(request, 'errors/AccessDenied.html')
Ejemplo n.º 23
0
def add_pop_site(request):
    name = request.POST.get('n')
    description = request.POST.get('d')
    if not name:
        return send_error(request, _('please enter name'))
    if not description:
        return send_error(request, _('please enter description'))
    if PopSite.objects.filter(name__iexact=name).exists():
        return send_error(request, _('item exists'))
    p = PopSite()
    p.name = name
    p.description = description
    p.save()
    fire_event(6010001, p, None, request.user.pk)
    return HttpResponse('%s' % p.pk)
Ejemplo n.º 24
0
def deliver_equipment_order(request):
    order = get_equipment_order_main_ext(request.POST.get('pk'))
    user = validate_user(request.POST.get('u'))
    if not order:
        return send_error(request, _('invalid item'))
    if not user:
        return send_error(request, _('please select a user'))
    if order.receiver_id is not None:
        return send_error(request, _('this order is closed'))
    if not user.is_staff and not user.is_active:
        return send_error(request, _('invalid user selected'))
    order.receiver = user
    order.receive_date = now()
    order.save()
    return HttpResponse(order.ext)
Ejemplo n.º 25
0
def undo_delete_dedicate(request):
    if request.method == 'GET':
        service_id = request.GET.get('s')
        if not validate_integer(service_id):
            return send_error(request, _('invalid service'))
        if not DedicatedUserService.objects.filter(pk=service_id).exists():
            return send_error(request, _('no such service'))
        s = DedicatedUserService.objects.get(pk=service_id)
        s.is_deleted = False
        s.save()
        if check_ajax(request):
            return HttpResponse('200')
        return redirect(
            reverse(view_dedicated_user_service) + '?u=%s' % s.user_id)
    return send_error(request, _('invalid method'))
Ejemplo n.º 26
0
def add_charge_package(request):
    name = get_string(request.POST.get('n'))
    amount = get_integer(request.POST.get('a'))
    if not name:
        return send_error(request, _('please enter name'))
    if not amount:
        return send_error(request, _('please enter amount'))
    if PricePackage.objects.filter(name__iexact=name,
                                   is_deleted=False).exists():
        return send_error(request, _('item exist'))
    p = PricePackage()
    p.name = name
    p.amount = amount
    p.save()
    return HttpResponse(p.ext)
Ejemplo n.º 27
0
def get_equipment_group_data(request):
    g = get_equipment_group(request.GET.get('pk'))
    if not g:
        return send_error(request, _('invalid item'))
    return HttpResponse(json.dumps({'name': g.name, 'ext': g.ext, 'description': g.description,
                                    'type_id': g.equipment_type.ext, 'remain': g.remain_items,
                                    'used_remain': g.used_remain_items, 'code': g.code_id}))
Ejemplo n.º 28
0
def change_equipment_order_process_state(request):
    order = get_equipment_order_main_ext(request.GET.get('pk'))
    if not order:
        return send_error(request, _('invalid order'))
    order.is_processing = True
    order.save()
    return HttpResponse(order.pk)
Ejemplo n.º 29
0
def view_equipment_order_detail(request):
    parent = get_equipment_order_main_ext(request.GET.get('pk'))
    order = get_order_detail_ext(request.GET.get('pk'))
    if not order:
        # return HttpResponse('')
        return send_error(request, _('invalid item'))
    res = order.values('pk', 'ext', 'is_accepted',
                       'is_rejected',
                       'change_date', 'reason',
                       'equipment__name',
                       'equipment__ext',
                       'order__ext',
                       'is_used',
                       'reason',
                       'fk_equipment_order_detail_order_item__equipment__serial',
                       'fk_equipment_order_detail_order_item__equipment__ext',
                       'fk_equipment_order_detail_order_item__fk_equipment_installed_order_detail__is_installed',
                       'fk_equipment_order_detail_order_item__fk_equipment_installed_order_detail__checkout_date',
                       'fk_equipment_order_detail_order_item__fk_equipment_installed_order_detail__comment',
                       'fk_equipment_order_detail_order_item__fk_equipment_borrow_order__property_number'
                       ).distinct().order_by(
        '-change_date')
    can_start = request.user.has_perm('CRM.change_equipmentorder') and not parent.is_processing
    can_deliver = request.user.has_perm("CRM.change_equipmentorder") and parent.is_processing and not parent.receiver
    # can_commit = request.user.has_perm('CRM.add_') and not parent.fk_equipment_in_use_order.exists()
    can_install = request.user.has_perm('CRM.add_equipmentinstalled')
    can_return = request.user.has_perm('CRM.add_equipmentreturn')
    can_checkout = request.user.has_perm('CRM.equipment_checkout')
    xx = {'data': list(res), 'can_start': can_start, 'can_deliver': can_deliver, 'can_install': can_install,
          'can_return': can_return,
          'main_order': request.GET.get('pk'), 'can_checkout': can_checkout,
          'can_accept': request.user.has_perm('CRM.change_equipmentorder')}
    return HttpResponse(json.dumps(xx, default=date_handler))
Ejemplo n.º 30
0
def add_new_equipment_state_list(request):
    name = get_string(request.POST.get('n'))
    description = get_string(request.POST.get('d'))
    state = get_equipment_state_list_ext(request.POST.get('pk'))
    if not name:
        return send_error(request, _('please enter name'))
    if not description:
        return send_error(request, _('please enter description'))
    if not state:
        if EquipmentStateList.objects.filter(name__iexact=name).exists():
            return send_error(request, _('item exists'))
        state = EquipmentStateList()
    state.name = name
    state.description = description
    state.save()
    return HttpResponse(state.pk)