![](/img/trans.png)
[英]how to check ports 2082 and 2222 with php for detecting server's control panel
[英]how to detect server's control panel type with php?
如何檢測服務器控制面板類型,如 cpanel 和 directadmin 以使用它們的 api:如果它只檢測 cpanel、directadmin、kloxo 和 plesk,這對我來說就足夠了
$panel = ???????????;
switch($panel){
case 'cpanel':
$xmlapi = new xmlapi($ip);
//...
break;
case 'directadmin':
$sock = new HTTPSocket;
//...
break;
.
.
.
}
plesk端口為8443。如何使用plesk api http://download1.parallels.com/Plesk/Doc/en-US/online/plesk-api-rpc/
正如 hanky-panky 所說,對此沒有直接的解決方案,您需要實施自己的創意方法。 您可能需要檢測一個打開套接字的控制面板,而其他控制面板使用特定的文件存在(例如,Cpanel 將 api 文件放在 php 包含路徑上)或任何其他想法。
你可以為此目的使用這個類
namespace Model;
// usage:
//include 'detectControlPanel';
//$object = new \model\detectControlPanel();
//$result = $object->getDetect();
//var_dump($result);
class detectControlPanel
{
public $debug = false;
protected $detect = array();
public function getDetect()
{
return $this->detect;
}
public function __construct($debug = false)
{
$this->run();
$this->debug = $debug;
$this->debug($this->detect);
}
public function run()
{
$this->detect['cpanel'] = $this->isCpanel();
$this->detect['virtualmin'] = $this->isVirtualmin();
$this->detect['plesk'] = $this->isPlesk();
$this->detect['directadmin'] = $this->isDirectadmin();
return $this->detect;
}
private function isCpanel()
{
try {
$this->telnet('localhost', 2082);
return true;
} catch (\Exception $ex) {
$this->debug($ex);
return false;
}
}
private function isVirtualmin()
{
try {
$this->telnet('localhost', 10000);
return true;
} catch (\Exception $ex) {
$this->debug($ex);
return false;
}
}
private function isDirectadmin()
{
try {
$this->telnet('localhost', 2222);
return true;
} catch (\Exception $ex) {
$this->debug($ex);
return false;
}
}
private function isPlesk()
{
try {
$this->telnet('localhost', 8443);
return true;
} catch (\Exception $ex) {
$this->debug($ex);
return false;
}
}
private function debug($input)
{
if ($this->debug == true) {
if (gettype($input) == 'string') {
echo '<br>' . "\n";
echo $input;
echo '<br>' . "\n";
} elseif (gettype($input) == 'array') {
echo '<pre>' . "\n";
print_r($input);
echo '</pre>' . "\n";
} elseif (gettype($input) == 'object' && get_class($input) == 'Exception') {
echo '<pre>' . "\n";
echo $input->getMessage();
echo '</pre>' . "\n";
} else {
var_dump($input);
}
}
}
private function telnet($hostname, $port)
{
if (!$hostname)
throw new \Exception("empty host name");
if (!$port)
throw new \Exception("empty port number");
$ipAddress = gethostbyname($hostname);
$link = @fsockopen($ipAddress, $port, $errno, $error);
if ($error) {
throw new \Exception($error, $errno);
}
if ($link) {
return true;
}
return false;
}
}
如何使用 php 檢測虛擬主機控制面板類型
代碼 :
<?php
class detectControlPanel
{
protected $detect = null;
public function getDetect()
{
return $this->detect;
}
public function __construct()
{
if($this->isCpanel()){
$this->detect = 'cpanel';
} elseif($this->isVirtualmin()){
$this->detect = 'virtualmin';
} elseif($this->isPlesk()){
$this->detect = 'plesk';
} elseif($this->isDirectadmin()){
$this->detect = 'directadmin';
} elseif($this->isDirectadmin()){
$this->detect = 'nspanel';
}
}
private function isCpanel(){
if(is_dir('/usr/local/cpanel')){ return true; }else{ return false; }
}
private function isVirtualmin(){
if(is_dir('/usr/share/webmin')){ return true; }else{ return false; }
}
private function isPlesk(){
if(is_dir('/usr/local/psa')){ return true; }else{ return false; }
}
private function isDirectadmin(){
if(is_dir('/usr/local/directadmin')){ return true; }else{ return false; }
}
private function isNspanel(){
if(is_dir('/opt/neoistone') || is_dir('/etc/neoistone') || is_dir('/usr/local/neoistone')){ return true; }else{ return false; }
}
}
?>
代碼2:
<?php
$cont = new detectControlPanel();
print_r($cont->getDetect());
?>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.