Exemple #1
0
def jobstatus(request):
    # if request.method != 'POST':
    #     raise Http404()

    if job_lock.acquire(False):
        try:
            # set to "done" if queue is empty (enables "close" button for modal dialog on client-side)
            # set to "processing" otherwise
            status = "done" if jobs.check_jobs_finished() else "processing"
            if jobs.check_jobs_failed():
                status = "failed"

            # add your new messages here
            newmessages = jobs.get_messages()
            newmessages.extend([
                entry for entry in jobs.get_failed_messages()
                if entry['status'] == "error"
            ])

            for i in range(len(newmessages)):
                newmessages[i]['message'] = ugettext(newmessages[i]['message'])

        finally:
            job_lock.release()

        return JsonResponse({'status': status, 'message': newmessages})

    else:
        return HttpResponse(status=503)
Exemple #2
0
def vpn_generate(request):
    context = RequestContext(request)

    form = VpnProfileForm(request.POST)

    if form.is_valid():
        profilename = form.cleaned_data.get('profilename')
        dyndomain = form.cleaned_data.get('dyndomain')

        logger.info("generating profile %s" % profilename)
        profile = VpnProfile(profilename=profilename, dyndomain=dyndomain)
        profile.config = "# upri.box OVPN config for %s\nfoo bar baz bar OpenVPN config goes here" % profilename
        profile.save()
        if not (settings.IGNORE_MISSING_UPRICONFIG
                and not exists('/usr/local/bin/upri-config.py')):
            jobs.queue_job(vpnjobs.generate_profile, (str(profile.id), ))
            context.push({'message': True})
        else:
            context.push({'message': False})

        context.push({'form': VpnProfileForm()})

    else:
        context.push({'form': VpnProfileForm(request.POST)})

    context.push({
        'messagestore': jobs.get_messages(),
        'profiles': VpnProfile.objects.all()
    })

    return render_to_response("vpn.html", context)
Exemple #3
0
def vpn_config(request):
    context = {
        'messagestore': jobs.get_messages(),
        'profiles': VpnProfile.objects.all(),
        'form': VpnProfileForm()
    }
    return render(request, "vpn.html", context)
Exemple #4
0
def ninja(request):
    context = RequestContext(request)

    if request.method == 'POST':

        form = WlanForm(utils.get_fact('wlan', 'ninja', 'ssid'), request.POST)

        if form.is_valid():
            password = form.cleaned_data['password2']
            ssid = form.cleaned_data['ssid']
            jobs.queue_job(wlanjobs.reconfigure_tor, (ssid, password))
            context.push({'message': True, 'ninja_ssid':ssid})
        else:
            logger.error("tor form validation failed for %s" % request.path)

    else:
        form = WlanForm(utils.get_fact('wlan','ninja','ssid'))

    model_info = ModelInfo()
    pi3 = model_info.runs_on_pi3()

    context.push({
        'form': form,
        'messagestore': jobs.get_messages(),
        'pi3': pi3})

    return render_to_response("ninja.html", context)
Exemple #5
0
def ninja(request):
    context = {}

    if request.method == 'POST':

        form = WlanForm(utils.get_fact('wlan', 'ninja', 'ssid'), request.POST)

        if form.is_valid():
            password = form.cleaned_data['password2']
            ssid = form.cleaned_data['ssid']
            jobs.queue_job(wlanjobs.reconfigure_tor, (ssid, password))
            context.update({'message': True, 'ninja_ssid': ssid})
        else:
            logger.error("tor form validation failed for %s" % request.path)

    else:
        form = WlanForm(utils.get_fact('wlan', 'ninja', 'ssid'))

    model_info = ModelInfo()
    pi3 = model_info.runs_on_pi3() and not model_info.uses_external_wifi()

    context.update({
        'form': form,
        'messagestore': jobs.get_messages(),
        'pi3': pi3})

    return render(request, "ninja.html", context)
Exemple #6
0
def jobcounter(request):
    # if request.method != 'POST':
    #     raise Http404()

    if job_lock.acquire(False):
        count = 0
        errors = 0
        try:
            if jobs.check_jobs_finished():
                jobs.clear_jobs()
            count = len(jobs.get_messages())

            errors = len(jobs.get_failed_messages())

        finally:
            job_lock.release()

        response = {'count': count}

        if errors:
            response.update({'errorcount': errors})

        return JsonResponse(response)

    else:
        return HttpResponse(status=503)
Exemple #7
0
def vpn_generate(request):
    context = RequestContext(request)

    form = VpnProfileForm(request.POST)

    if form.is_valid():
        profilename = form.cleaned_data.get('profilename')
        dyndomain = form.cleaned_data.get('dyndomain')

        logger.info("generating profile %s" % profilename )
        profile = VpnProfile(profilename=profilename, dyndomain=dyndomain)
        profile.config = "# upri.box OVPN config for %s\nfoo bar baz bar OpenVPN config goes here" % profilename
        profile.save()
        if not (settings.IGNORE_MISSING_UPRICONFIG and not exists('/usr/local/bin/upri-config.py')):
            jobs.queue_job(vpnjobs.generate_profile, (str(profile.id),))
            context.push({'message': True})
        else:
            context.push({'message': False})

        context.push({'form': VpnProfileForm()})

    else:
        context.push({'form': VpnProfileForm(request.POST)})

    context.push({
            'messagestore': jobs.get_messages(),
            'profiles': VpnProfile.objects.all()})

    return render_to_response("vpn.html", context)
Exemple #8
0
def vpn_config(request):
    context = RequestContext(request)

    context.push({
        'messagestore': jobs.get_messages(),
        'profiles': VpnProfile.objects.all(),
        'form': VpnProfileForm()})
    return render_to_response("vpn.html", context)
Exemple #9
0
def more_static(request, enable=None, dhcpd=None):
    context = {}

    net_info = utils.get_system_network_config()
    ip_form = StaticIPForm(
        net_info['ip'],
        net_info['netmask'],
        net_info['gateway'],
        net_info['dns_servers'][0],
        utils.get_fact('dhcpd', 'general', 'enabled'),
    )

    if request.method == 'POST':

        ip_form = StaticIPForm(net_info['ip'], net_info['netmask'],
                               net_info['gateway'], net_info['dns_servers'][0],
                               utils.get_fact('dhcpd', 'general',
                                              'enabled'), request.POST)
        if ip_form.is_valid():
            ip = ip_form.cleaned_data['ip_address']
            netmask = ip_form.cleaned_data['ip_netmask']
            gateway = ip_form.cleaned_data['gateway']
            dns = ip_form.cleaned_data['dns_server']
            # dhcp = ip_form.cleaned_data['dhcp_server']

            jobs.queue_job(sshjobs.reconfigure_network,
                           (ip, netmask, gateway, dns, enable))
            jobs.queue_job(sshjobs.toggle_dhcpd, ("yes" if dhcpd else "no", ))

            context.update({
                'message': True,
                "refresh_url":
                reverse('upri_config'
                        ),  # request.path,  # reverse('upri_config_static'),
                'messagestore': jobs.get_messages()
            })

    context.update({
        'ip_form': ip_form,
        'messagestore': jobs.get_messages(),
        'href': request.path,
        "refresh_url": reverse('upri_config'),
    })

    return render(request, "static.html", context)
Exemple #10
0
def vpn_config(request):
    context = RequestContext(request)

    context.push({
        'messagestore': jobs.get_messages(),
        'profiles': VpnProfile.objects.all(),
        'form': VpnProfileForm()
    })
    return render_to_response("vpn.html", context)
Exemple #11
0
def device_entry(request):
    return render(
        request, "device_entry.html", {
            'messagestore': jobs.get_messages(),
            'devices': {
                'mode': None,
                'slug': "",
                'changing': ''
            },
        })
Exemple #12
0
def more_config(request):
    context = RequestContext(request)

    if request.method == 'POST':

        form = AdminForm(request, request.POST)

        if form.is_valid():
            new_password = form.cleaned_data['password2']
            new_username = form.cleaned_data['username']

            old_password = form.cleaned_data['oldpassword']
            old_username = request.user.username

            logger.info("updating user %s..." % old_username)
            u = User.objects.get(username=old_username)

            #sanity check, this should never happen
            if not u:
                logger.error("unexpected error: user %s does not exist" %
                             old_username)
                return HttpResponse(status=500)

            u.set_password(new_password)
            u.username = new_username
            u.save()
            logger.info(
                "user %s updated to %s (password changed: %s)" %
                (old_username, new_username, new_password != old_password))
            context.push({'message': True})

        else:
            logger.error("admin form validation failed")

    else:
        form = AdminForm(request)

    update_status = UpdateStatus()

    context.push({
        'form': form,
        'messagestore': jobs.get_messages(),
        'update_time': update_status.update_utc_time,
        'version': update_status.get_version()
    })

    return render_to_response("more.html", context)
Exemple #13
0
def more_config(request):
    context = RequestContext(request)

    if request.method == 'POST':

        form = AdminForm(request, request.POST)

        if form.is_valid():
            new_password = form.cleaned_data['password2']
            new_username = form.cleaned_data['username']

            old_password = form.cleaned_data['oldpassword']
            old_username = request.user.username

            logger.info("updating user %s..." % old_username)
            u = User.objects.get(username=old_username)

            #sanity check, this should never happen
            if not u:
                logger.error("unexpected error: user %s does not exist" % old_username)
                return HttpResponse(status=500)

            u.set_password(new_password)
            u.username = new_username
            u.save()
            logger.info("user %s updated to %s (password changed: %s)" % (old_username, new_username, new_password != old_password) )
            context.push({'message': True})

        else:
            logger.error("admin form validation failed")

    else:
        form = AdminForm(request)

    update_status = UpdateStatus()

    context.push({
        'form': form,
        'messagestore': jobs.get_messages(),
        'update_time': update_status.update_utc_time,
        'version': update_status.get_version()
    })

    return render_to_response("more.html", context)
Exemple #14
0
def silent(request):
    context = {}

    if request.method == 'POST':

        form = WlanForm(utils.get_fact('wlan', 'upri', 'ssid'), request.POST)
        if form.is_valid():
            password = form.cleaned_data['password2']
            ssid = form.cleaned_data['ssid']
            jobs.queue_job(wlanjobs.reconfigure_wlan, (ssid, password))
            context.update({'message': True, 'upri_ssid': ssid})
        else:
            logger.error("form validation failed for %s" % request.path)

    else:
        form = WlanForm(utils.get_fact('wlan', 'upri', 'ssid'))

    context.update({'form': form, 'messagestore': jobs.get_messages()})
    return render(request, "silent.html", context)
Exemple #15
0
def silent(request):
    context = RequestContext(request)

    if request.method == 'POST':

        form = WlanForm(utils.get_fact('wlan', 'upri', 'ssid'), request.POST)
        if form.is_valid():
            password = form.cleaned_data['password2']
            ssid = form.cleaned_data['ssid']
            jobs.queue_job(wlanjobs.reconfigure_wlan, (ssid, password))
            context.push({'message': True, 'upri_ssid': ssid})
        else:
            logger.error("form validation failed for %s" % request.path)

    else:
        form = WlanForm(utils.get_fact('wlan', 'upri', 'ssid'))

    context.push({'form': form})
    context.push({'messagestore': jobs.get_messages()})
    return render_to_response("silent.html", context)
Exemple #16
0
def jobstatus(request):
    if request.method != 'POST':
        raise Http404()

    if job_lock.acquire(False):
        try:
            # set to "done" if queue is empty (enables "close" button for modal dialog on client-side)
            # set to "processing" otherwise
            status = "done" if jobs.check_jobs_finished() else "processing"

             # add your new messages here
            newmessages = jobs.get_messages()


            for i in range(len(newmessages)):
                newmessages[i] = ugettext(newmessages[i])

        finally:
            job_lock.release()

        return JsonResponse({'status': status, 'message': newmessages})

    else:
        return HttpResponse(status=503)
Exemple #17
0
def get_statistics(request):
    return render_to_response("statistics.html", {
        "request": request,
        'messagestore': jobs.get_messages()
    })
Exemple #18
0
def get_statistics(request):
    return render_to_response("statistics.html", {
        "request": request,
        'messagestore': jobs.get_messages()
    })
Exemple #19
0
def faq(request):
    return render_to_response("faq.html", {
        "request": request,
        'messagestore': jobs.get_messages()
    })
Exemple #20
0
def faq(request):
    return render_to_response("faq.html", {
        "request": request,
        'messagestore': jobs.get_messages()
    })
Exemple #21
0
def get_statistics(request):
    return render(request, "statistics.html",
                  {'messagestore': jobs.get_messages()})
Exemple #22
0
def more_config(request, save_form):
    context = {}

    form = AdminForm(request)
    net_info = utils.get_system_network_config()
    ip_form = StaticIPForm(net_info['ip'], net_info['netmask'],
                           net_info['gateway'], net_info['dns_servers'][0],
                           utils.get_fact('dhcpd', 'general', 'enabled'))

    if request.method == 'POST':

        if save_form == "user":
            form = AdminForm(request, request.POST)
            if form.is_valid():
                new_password = form.cleaned_data['password2']
                new_username = form.cleaned_data['username']

                old_password = form.cleaned_data['oldpassword']
                old_username = request.user.username

                logger.info("updating user %s..." % old_username)
                u = User.objects.get(username=old_username)

                # sanity check, this should never happen
                if not u:
                    logger.error("unexpected error: user %s does not exist" %
                                 old_username)
                    return HttpResponse(status=500)

                u.set_password(new_password)
                u.username = new_username
                u.save()
                logger.info(
                    "user %s updated to %s (password changed: %s)" %
                    (old_username, new_username, new_password != old_password))
                context.update({'message': True})

            else:
                logger.error("admin form validation failed")
        elif save_form == "static_ip":
            ip_form = StaticIPForm(
                net_info['ip'], net_info['netmask'], net_info['gateway'],
                net_info['dns_servers'][0],
                utils.get_fact('dhcpd', 'general', 'enabled'), request.POST)
            if ip_form.is_valid():
                ip = ip_form.cleaned_data['ip_address']
                netmask = ip_form.cleaned_data['ip_netmask']
                gateway = ip_form.cleaned_data['gateway']
                dns = ip_form.cleaned_data['dns_server']
                dhcp = ip_form.cleaned_data['dhcp_server']
                jobs.queue_job(sshjobs.reconfigure_network,
                               (ip, netmask, gateway, dns, dhcp))
                context.update({
                    'message': True,
                    "refresh_url": reverse('upri_more'),
                    'messagestore': jobs.get_messages()
                })

    update_status = UpdateStatus()

    context.update({
        'form': form,
        'ip_form': ip_form,
        'messagestore': jobs.get_messages(),
        'update_time': update_status.update_utc_time,
        'version': update_status.get_version()
    })

    return render(request, "more.html", context)
Exemple #23
0
def get_devices(request):
    return render(request, "devices.html", {
        'messagestore': jobs.get_messages(),
        'devices': get_entries(),
    })
Exemple #24
0
def faq(request):
    return render(request, "faq.html", {
        "request": request,
        'messagestore': jobs.get_messages()
    })