def stop(request):
    xvfb_key, xvfb_secret = utils.get_xvfb_oauth_creds()

    url = utils.get_rpc_url(request)
    trans = OAuthTransport(url, key=xvfb_key,
        secret=xvfb_secret)
    server = jsonrpclib.Server(url, transport=trans)
    auth = server.plugins.is_authenticated(request.COOKIES.get("sessionid", ""))
    jail = json.loads(server.plugins.jail.info())[0]
    assert auth

    try:
        xvfb = models.Xvfb.objects.order_by('-id')[0]
        xvfb.enable = False
        xvfb.save()
    except IndexError:
        xvfb = models.Xvfb.objects.create(enable=False)

    try:
        form = forms.XvfbForm(xvfb.__dict__, instance=xvfb, jail=jail)
        form.is_valid()
        form.save()
    except ValueError:
        pass

    cmd = "%s onestop" % utils.xvfb_control
    pipe = Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE,
        shell=True, close_fds=True)

    out = pipe.communicate()[0]
    return HttpResponse(simplejson.dumps({
        'error': False,
        'message': out,
        }))
def start(request):
    xvfb_key, xvfb_secret = utils.get_xvfb_oauth_creds()

    url = utils.get_rpc_url(request)
    trans = OAuthTransport(url, key=xvfb_key, secret=xvfb_secret)
    server = jsonrpclib.Server(url, transport=trans)
    auth = server.plugins.is_authenticated(request.COOKIES.get(
        "sessionid", ""))
    jail = json.loads(server.plugins.jail.info())[0]
    assert auth

    try:
        xvfb = models.Xvfb.objects.order_by('-id')[0]
        xvfb.enable = True
        xvfb.save()
    except IndexError:
        xvfb = models.Xvfb.objects.create(enable=True)

    try:
        form = forms.XvfbForm(xvfb.__dict__, instance=xvfb, jail=jail)
        form.is_valid()
        form.save()
    except ValueError:
        return HttpResponse(simplejson.dumps({
            'error':
            True,
            'message':
            'Xvfb data did not validate, please configure it first.',
        }),
                            content_type='application/json')

    libc = ctypes.cdll.LoadLibrary("libc.so.7")
    omask = (ctypes.c_uint32 * 4)(0, 0, 0, 0)
    mask = (ctypes.c_uint32 * 4)(0, 0, 0, 0)
    pmask = ctypes.pointer(mask)
    pomask = ctypes.pointer(omask)
    libc.sigprocmask(signal.SIGQUIT, pmask, pomask)
    cmd = "%s onestart" % utils.xvfb_control
    _popen = os.popen(cmd)
    #pipe = Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE,
    #    shell=True)

    out = ''
    time.sleep(3)
    libc.sigprocmask(signal.SIGQUIT, pomask, None)
    return HttpResponse(simplejson.dumps({
        'error': False,
        'message': out,
    }))
def start(request):
    xvfb_key, xvfb_secret = utils.get_xvfb_oauth_creds()

    url = utils.get_rpc_url(request)
    trans = OAuthTransport(url, key=xvfb_key,
        secret=xvfb_secret)
    server = jsonrpclib.Server(url, transport=trans)
    auth = server.plugins.is_authenticated(request.COOKIES.get("sessionid", ""))
    jail = json.loads(server.plugins.jail.info())[0]
    assert auth

    try:
        xvfb = models.Xvfb.objects.order_by('-id')[0]
        xvfb.enable = True
        xvfb.save()
    except IndexError:
        xvfb = models.Xvfb.objects.create(enable=True)

    try:
        form = forms.XvfbForm(xvfb.__dict__, instance=xvfb, jail=jail)
        form.is_valid()
        form.save()
    except ValueError:
        return HttpResponse(simplejson.dumps({
            'error': True,
            'message': 'Xvfb data did not validate, please configure it first.',
            }), content_type='application/json')


    libc = ctypes.cdll.LoadLibrary("libc.so.7")
    omask = (ctypes.c_uint32 * 4)(0, 0, 0, 0)
    mask = (ctypes.c_uint32 * 4)(0, 0, 0, 0)
    pmask = ctypes.pointer(mask)
    pomask = ctypes.pointer(omask)
    libc.sigprocmask(signal.SIGQUIT, pmask, pomask)
    cmd = "%s onestart" % utils.xvfb_control
    _popen = os.popen(cmd)
    #pipe = Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE,
    #    shell=True)


    out = ''
    time.sleep(3)
    libc.sigprocmask(signal.SIGQUIT, pomask, None)
    return HttpResponse(simplejson.dumps({
        'error': False,
        'message': out,
        }))
def edit(request):
    xvfb_key, xvfb_secret = utils.get_xvfb_oauth_creds()

    url = utils.get_rpc_url(request)
    trans = OAuthTransport(url, key=xvfb_key, secret=xvfb_secret)
    """
    Get the Xvfb object
    If it does not exist create a new entry
    """
    try:
        xvfb = models.Xvfb.objects.order_by('-id')[0]
    except IndexError:
        xvfb = models.Xvfb.objects.create()

    try:
        server = jsonrpclib.Server(url, transport=trans)
        jail = json.loads(server.plugins.jail.info())[0]
        auth = server.plugins.is_authenticated(
            request.COOKIES.get("sessionid", ""))
        assert auth
    except Exception, e:
        raise
def stop(request):
    xvfb_key, xvfb_secret = utils.get_xvfb_oauth_creds()

    url = utils.get_rpc_url(request)
    trans = OAuthTransport(url, key=xvfb_key, secret=xvfb_secret)
    server = jsonrpclib.Server(url, transport=trans)
    auth = server.plugins.is_authenticated(request.COOKIES.get(
        "sessionid", ""))
    jail = json.loads(server.plugins.jail.info())[0]
    assert auth

    try:
        xvfb = models.Xvfb.objects.order_by('-id')[0]
        xvfb.enable = False
        xvfb.save()
    except IndexError:
        xvfb = models.Xvfb.objects.create(enable=False)

    try:
        form = forms.XvfbForm(xvfb.__dict__, instance=xvfb, jail=jail)
        form.is_valid()
        form.save()
    except ValueError:
        pass

    cmd = "%s onestop" % utils.xvfb_control
    pipe = Popen(cmd,
                 stdin=PIPE,
                 stdout=PIPE,
                 stderr=PIPE,
                 shell=True,
                 close_fds=True)

    out = pipe.communicate()[0]
    return HttpResponse(simplejson.dumps({
        'error': False,
        'message': out,
    }))
def edit(request):
    xvfb_key, xvfb_secret = utils.get_xvfb_oauth_creds()

    url = utils.get_rpc_url(request)
    trans = OAuthTransport(url, key=xvfb_key,
        secret=xvfb_secret)

    """
    Get the Xvfb object
    If it does not exist create a new entry
    """
    try:
        xvfb = models.Xvfb.objects.order_by('-id')[0]
    except IndexError:
        xvfb = models.Xvfb.objects.create()

    try:
        server = jsonrpclib.Server(url, transport=trans)
        jail = json.loads(server.plugins.jail.info())[0]
        auth = server.plugins.is_authenticated(request.COOKIES.get("sessionid", ""))
        assert auth
    except Exception, e:
        raise