/** * RemoteApacheTool constructor * * @param string $host SSH Host * @param string $port SSH port * @param string $username SSH login * @param string $password SSH password */ function __construct ($host, $port, $authinfo) { parent::__construct(); $this->Authinfo = $authinfo; // SSH2 $this->SSH2 = new SSH2(); if ($this->Authinfo["type"] == "password") $this->SSH2->AddPassword($this->Authinfo["login"], $this->Authinfo["password"]); elseif ($this->Authinfo["type"] == "pubkey") $this->SSH2->AddPubkey($this->Authinfo["login"], $this->Authinfo["pubkey_path"], $this->Authinfo["privkey_path"], $this->Authinfo["key_pass"]); if (!$this->SSH2->Connect($host, $port, $username, $password)) Core::RaiseWarning("RemoteApacheTool: SSH2 connection failed"); /* $this->conf = $this->SSH2->Exec("/bin/cat {$this->ConfPath}"); if (!$this->conf || !strlen($this->conf)>0) { $this->RaiseError("Cannot open HTTPD conf!"); return false; } */ }
function testApacheTool() { $ApacheTool = new ApacheTool(); $ApacheTool->DeleteVHost("127.0.0.1", "cptest.com"); $ApacheTool->DeleteVHost("127.0.0.3", "cptest.com"); $ApacheTool->DeleteVHost("127.0.0.5", "cptest-ssl.com", true); // // Add VHost // $ApacheTool->AddVHost("127.0.0.1", "cptest.com", "alex", "http://webta.net/company.html"); $retval = $ApacheTool->VHostExists("127.0.0.1", "cptest.com"); $this->assertTrue($retval, "Recently created vhost exists"); // // Edit vhost // $retval = $ApacheTool->EditVHost("cptest.com", "127.0.0.1", "127.0.0.3", "bob2", "*****@*****.**"); $retval = $ApacheTool->VHostExists("127.0.0.3", "cptest.com"); $this->assertTrue($retval, "Recently changed vhost exists"); // // List VHosts // $retval = $ApacheTool->ListVHosts(); $this->assertTrue(is_array($retval) && count($retval) > 0, "VHosts listed ok"); // // Delete VHost // $ApacheTool->DeleteVHost("127.0.0.3", "cptest.com"); $retval = $ApacheTool->VHostExists("127.0.0.3", "cptest.com"); $this->assertFalse($retval, "VHost deleted succesfully"); //////////////////////////////////// //SSL //////////////////////////////////// // // Add SSL VHost // $ApacheTool->AddVHost("127.0.0.5", "cptest-ssl.com", "alexssl", "*****@*****.**", true); $retval = $ApacheTool->VHostExists("127.0.0.5", "cptest-ssl.com"); foreach ($ApacheTool->ListVHosts() as $f) { if ($f[2]) { $retval2 = true; } } $this->assertTrue($retval && $retval2, "Recently created SSL vhost exists"); // // Edit SSL Vhost // $retval = $ApacheTool->EditVHost("cptest-ssl.com", "127.0.0.5", "127.0.0.6", "bob2_ssl", "*****@*****.**"); $retval = $ApacheTool->VHostExists("127.0.0.6", "cptest-ssl.com"); $this->assertTrue($retval, "Recently edited SSL vhost exists"); // // Delete SSL Vhost // $ApacheTool->DeleteVHost("127.0.0.6", "cptest-ssl.com", true); $retval = $ApacheTool->VHostExists("127.0.0.6", "cptest-ssl.com"); $this->assertfalse($retval, "Recently deleted SSL vhost does not exist"); }