Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Php manages virtual machines and connects through proxies

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

1. Enter the installation directory

Cd C:\ Program Files\ Oracle\ VirtualBox

Set the web authentication library to null:

VboxManagesetproperty websrvauthlibrary null

Then start the service.

Vboxwebsrv-- host 0.0.0.0

2. Enter http://127.0.0.1 18083 in the browser

In the attachment at the bottom of the blog, provide the vbox interface file

When writing a code implementation, vbox_oper manipulates the helper class

Include_once ('vboxServiceWrappers.php'); class Vbox_oper

{

Protected $serverIp

Protected $serverPort = "18083"

Protected $proxy_uname

Protected $proxy_password

Protected $proxy_host

Protected $proxy_port

Protected $item

Protected $connection

/ *

* Module name: get the connection

* Parameter description:

* author: csl

, /

Public function getConn ()

{

$url = "http://". $this- > serverIp. ":" $this- > serverPort. "/"

/ / $this- > connection = new SoapClient ("vboxwebService.wsdl", array ('location' = > $url,' connection_timeout' = > 5,))

$this- > connection = new SoapClient ("vboxwebService.wsdl", array ('location' = > $url,'connection_timeout'= > 5)

'proxy_host' = > $this- > proxy_host,' proxy_port' = > $this- > proxy_port

'proxy_login' = > $this- > proxy_uname,' proxy_password' = > $this- > proxy_password))

Return $this- > connection

}

/ *

* Module name: initialize agent information

* Parameter description:

* init_proxy contains: ip,port,username,password

* author: csl

, /

Public function init_proxy ($proxy) {

If (! empty ($proxy ['ip']))

$this- > proxy_host = $proxy ['ip']

If (! empty ($proxy ['port']))

$this- > proxy_port = (int) $proxy ['port']

If (! empty ($proxy ['username']))

$this- > proxy_uname = $proxy ['username']

If (! empty ($proxy ['password']))

$this- > proxy_password = $proxy ['password']

}

/ *

* Module name: initialize server information

* Parameter description:

* init_proxy contains: server_ip,sbmc

* author: csl

, /

Public function init_data ($item, $proxy = array ())

{

$this- > serverPort = "18083"

If (! empty ($item ['server_ip']))

$this- > serverIp = $item ['server_ip']

If (! empty ($item ['sbmc']))

$this- > name = $item ['sbmc']

If (! empty ($proxy)) {

$this- > init_proxy ($proxy)

}

}

/ *

* Module name: start the virtual machine

* Parameter description:

* author: csl

, /

Public function start ()

{

$this- > getConn ()

$websessionManager = new IWebsessionManager ($this- > connection)

$virtualbox = $websessionManager- > logon (",")

$machine = $virtualbox- > findMachine ($this- > name)

$session = $websessionManager- > getSessionObject ($virtualbox- > handle)

$state = (string) $machine- > state

If ($state! = 'Running' & & $state! =' Paused') {

$progress = $machine- > launchVMProcess ($session- > handle, "headless", "")

}

}

/ *

* Module name: shut down the virtual machine

* Parameter description:

* author: csl

, /

Public function stop ()

{

$this- > getConn ()

$websessionManager = new IWebsessionManager ($this- > connection)

$virtualbox = $websessionManager- > logon (",")

$machine = $virtualbox- > findMachine ($this- > name)

$session = $websessionManager- > getSessionObject ($virtualbox- > handle)

$state = (string) $machine- > state

If ($state = = 'Running' | | $state = =' Paused') {

$lockType = new LockType ($session, 'Shared')

$machine- > lockMachine ($session, $lockType- > NameMap [1])

$iconsole = $session- > getConsole ()

$progress = $iconsole- > powerDown ()

}

}

/ *

* Module name: restart the virtual machine

* Parameter description:

* author: csl

, /

Public function restart ()

{

$this- > getConn ()

$websessionManager = new IWebsessionManager ($this- > connection)

$virtualbox = $websessionManager- > logon (",")

$machine = $virtualbox- > findMachine ($this- > name)

$session = $websessionManager- > getSessionObject ($virtualbox- > handle)

$state = (string) $machine- > state

If ($state = = 'Running' | | $state = =' Paused') {

$lockType = new LockType ($session, 'Shared')

$machine- > lockMachine ($session, $lockType- > NameMap [1])

$iconsole = $session- > getConsole ()

$progress = $iconsole- > reset ()

} else if ($state = = 'PoweredOff') {

$progress = $machine- > launchVMProcess ($session- > handle, "headless", "")

}

}

/ *

* Module name: get all virtual machines in vbox

* Parameter description:

* author: csl

, /

Public function get_machines () {

$this- > getConn ()

$websessionManager = new IWebsessionManager ($this- > connection)

$virtualbox = $websessionManager- > logon (",")

$machines = $virtualbox- > machines

Return $machines

}

}

Attachment: http://down.51cto.com/data/2366921

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report