Skip to content

Commit

Permalink
Compatibility updates.
Browse files Browse the repository at this point in the history
Changed from windows .vbs script to .bat script for VboxWebSrv startup.

git-svn-id: http://vboxweb.googlecode.com/svn/trunk@104 729376a8-6c6b-11de-afdd-bb9f892af8c1
  • Loading branch information
Ian Moore committed Nov 12, 2010
1 parent 9d5801c commit 618b927
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 28 deletions.
12 changes: 6 additions & 6 deletions VBoxWebSrv.py
Expand Up @@ -18,15 +18,13 @@
import re
import StringIO
import types
import md5
import random
import uuid
import gc
from email.utils import parsedate_tz

# Enable garbage collection
gc.enable()
gc.set_debug(gc.DEBUG_UNCOLLECTABLE)

if sys.platform == 'win32':
try:
Expand All @@ -48,9 +46,11 @@
else:
import vboxapi # Main VirtualBox API

from vboxapi.VirtualBox_constants import VirtualBoxReflectionInfo

# VBoxWeb modules
sys.path.insert(0,'lib')
sys.path.insert(0,'languages')
sys.path.insert(0,os.path.abspath(os.path.dirname(__file__))+'/lib')
sys.path.insert(0,os.path.abspath(os.path.dirname(__file__))+'/languages')

# Load vbox connector
import vboxactions
Expand Down Expand Up @@ -240,7 +240,7 @@ def __init__(self, ctx):
self.ctx['progressOps'] = {'get':progressObjGet,'store':progressObjStore,'delete':progressObjDel}

# generate session_cookie name. Not very secure, but better than a static / predictable key.
self.session_cookie = md5.md5(os.path.abspath(os.path.dirname(__file__))).hexdigest()
self.session_cookie = hashlib.md5(os.path.abspath(os.path.dirname(__file__))).hexdigest()


"""
Expand Down Expand Up @@ -801,7 +801,7 @@ def main(argv = sys.argv):
'tools.staticdir.root': os.path.abspath(os.path.dirname(__file__))
})

ctx = {'global':g_vboxManager,'vbox':None}
ctx = {'global':g_vboxManager,'vbox':None, 'vboxTypes':VirtualBoxReflectionInfo(True)}

cherrypy.engine.subscribe('stop', onShutdown)

Expand Down
16 changes: 0 additions & 16 deletions VBoxWebSrv.vbs

This file was deleted.

100 changes: 100 additions & 0 deletions VboxWebSrv.bat
@@ -0,0 +1,100 @@
@Echo off
echo.
echo VBoxWebSrv Windows
echo.

::
:: reset vars
::
set act=%1
set puname=%2
set pwset1=%3
set pwset2=%3
set arg1=%1
set arg2=%2
set arg3=%3

:: Search the registry tree for the required values
IF NOT EXIST "%PYTHON%" (
FOR /F "skip=2 tokens=3" %%A IN ('REG QUERY "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\Python.exe"') DO (
IF EXIST "%%A" SET PYTHON=%%A
)
)
if NOT EXIST "%PYTHON%" GOTO NOPYTHON

:PROMPTACT
echo.
echo Commands: start, adduser, deluser
echo.
if "%act%" == "" set /p act= Enter a command to run:

if "%act%" == "start" (
echo Starting...
GOTO RUNPYTHON
)
if "%act%" == "adduser" GOTO PROMPTUSER
if "%act%" == "deluser" GOTO PROMPTUSER
echo %act% not understood.
set act=
GOTO PROMPTACT

:PROMPTUSER
if "%act%" == "deluser" (
if "%puname%" == "" set /p puname= Enter a user to remove:
)
if "%act%" == "adduser" (
if "%puname%" == "" set /p puname= Enter a user to add:
)
if "%puname%" == "" goto PROMPTUSER
if "%act%" == "deluser" goto DELUSER
if "%act%" == "adduser" goto PROMPTPW

GOTO RUNPYTHON

::
:: Prompt for password
::
:PROMPTPW
if "%pwset1%" == "" set /p pwset1= Enter password:
if "%pwset1%" == "" GOTO PROMPTPW
if "%pwset2%" == "" set /p pwset2= Again:
if "%pwset1%" == "%pwset2%" GOTO ADDUSER
echo Passwords do not match.
set pwset1=
set pwset2=
GOTO PROMPTPW

::
:: Add a user
::
:ADDUSER
set arg1="adduser"
set arg2=%puname%
set arg3="%pwset1%"
GOTO RUNPYTHON

::
:: Python not found
::
:NOPYTHON
echo Unable to find python.exe. Please set the PYTHON environment variable.
pause
GOTO :END

::
:: Delete a user
::
:DELUSER
set arg1="deluser"
set arg2=%puname%
set arg3=
GOTO RUNPYTHON

::
:: Start server
::
:RUNPYTHON
%PYTHON% %~dp0VBoxWebSrv.py %arg1% %arg2% %arg3%
pause

:END
2 changes: 2 additions & 0 deletions lib/VirtualBox_wrappers.py
Expand Up @@ -18,12 +18,14 @@
#
# This file is autogenerated from VirtualBox.xidl, DO NOT EDIT!
#
"""
from VirtualBox_services import *
try:
from VirtualBox_client import *
except:
pass
"""

class ManagedManager:
def __init__(self):
Expand Down
13 changes: 9 additions & 4 deletions lib/vboxactions.py
Expand Up @@ -12,7 +12,7 @@
import time
import types
import traceback
import md5
import hashlib
import os
from VBoxWebSrv import trans
from vboxapi import VirtualBoxManager
Expand Down Expand Up @@ -115,10 +115,10 @@ def __init__(self, ctx):
self.cache.prefix = 'vbwc-'

if self.settings.get('location'):
self.cache.prefix = self.cache.prefix + str(md5.md5(self.settings.get('location')).hexdigest())
self.cache.prefix = self.cache.prefix + str(hashlib.md5(self.settings.get('location')).hexdigest())
else:
# Handle both Win* And *nix
self.cache.prefix = self.cache.prefix + str(md5.md5(str(os.environ.get('USERNAME',''))+str(os.environ.get('USER',''))).hexdigest())
self.cache.prefix = self.cache.prefix + str(hashlib.md5(str(os.environ.get('USERNAME',''))+str(os.environ.get('USER',''))).hexdigest())

# Progress operation handling
self.progressOps = ctx['progressOps']
Expand Down Expand Up @@ -196,7 +196,12 @@ def vboxType(self,vbtype,conv):
Return vbox type for setting values
"""
def vboxTypeSet(self,vbtype,conv):
return int(self.vboxType(vbtype,conv))
i = 0
try:
i = self.vboxType(vbtype,conv)
except:
pass
return int(i)

"""
Return array of vbox items
Expand Down
4 changes: 2 additions & 2 deletions www/js/utils.js
Expand Up @@ -716,10 +716,10 @@ function vboxParseCookies() {
/* Check version against supported versions */
function vboxVersionCheck(ver) {

var supported = {'3':{'2':1}};
var supported = {'4':{'0':1}};

// No ver passed?
if(ver && !supported[ver.major][ver.minor]) {
if(ver && !(supported[ver.major] && supported[ver.major][ver.minor])) {

vboxParseCookies();

Expand Down

0 comments on commit 618b927

Please sign in to comment.