servermgr2 init...

This commit is contained in:
최준흠 2023-07-20 13:56:55 +09:00
parent e711ffbda5
commit e22871a002
8 changed files with 73 additions and 94 deletions

View File

@ -85,9 +85,9 @@ $routes->group('admin', ['namespace' => 'App\Controllers\Admin', 'filter' => 'au
$routes->get('delete/(:num)', 'HPILOController::delete/$1', ['filter' => 'authFilter:master']);
$routes->get('toggle/(:num)/(:hash)', 'HPILOController::toggle/$1/$2', ['filter' => 'authFilter:master,director']);
$routes->post('batchjob', 'HPILOController::batchjob', ['filter' => 'authFilter:master']);
$routes->post('console/(:num)', 'HPILOController::console/$1', ['filter' => 'authFilter:master']);
$routes->post('reset/(:num)/(:alpha)', 'HPILOController::reset/$1/$2', ['filter' => 'authFilter:master']);
$routes->post('reload/(:num)', 'HPILOController::reload/$1', ['filter' => 'authFilter:master']);
$routes->get('console/(:num)', 'HPILOController::console/$1', ['filter' => 'authFilter:master']);
$routes->get('reset/(:num)/(:alpha)', 'HPILOController::reset/$1/$2', ['filter' => 'authFilter:master']);
$routes->get('reload/(:num)', 'HPILOController::reload/$1', ['filter' => 'authFilter:master']);
});
});
/*

View File

@ -65,8 +65,10 @@ class HPILOController extends \App\Controllers\Admin\AdminController
private function getAdapter(HPILOEntity $entity)
{
if (is_null($this->_adapter)) {
$adapterClass = getenv('hpilo.api.adapter') ? getenv('hpilo.api.adapter') : "\App\Libraries\Log\GuzzleAdapter";
$this->_adapter = new $adapterClass($entity, getenv('hpilo.api.debug') ? getenv('hpilo.api.debug') : false);
$adapterClass = getenv('hpilo.api.adapter') ?: "\App\Libraries\Adapter\API\GuzzleAdapter";
$this->_adapter = new $adapterClass(getenv('hpilo.api.debug') ?: false);
$this->_adapter->setServerInfo($entity->getIP(), $entity->getPort());
$this->_adapter->setAccountInfo($entity->getID(), $entity->getPassword());
}
return $this->_adapter;
}
@ -131,6 +133,28 @@ class HPILOController extends \App\Controllers\Admin\AdminController
$this->_viewDatas['entity'] = $entity;
return view($this->_viewPath . '/console_iframe', $this->_viewDatas);
}
final public function reset(int $uid, string $type)
{
try {
$entity = $this->_model->getEntity($uid);
if (!in_array($type, ["On", "Off", "Restart"])) {
throw new \Exception(__FUNCTION__ . "에서 {$type}은 기능은 없습니다.");
}
$ilo = new HPILO4($this->getAdapter($entity));
$results = $ilo->reset($type);
Log::add("warning", var_export($results, true));
$message = "{$entity->getTitle()} " . __FUNCTION__ . " 완료하였습니다.";
Log::save("{$this->_viewDatas['title']} {$message}");
return alert_CommonHelper($message, $this->_session->get(SESSION_NAMES['RETURN_URL']));
} catch (\Exception $e) {
$message = "{$entity->getTitle()} " . __FUNCTION__ . " 실패하였습니다.";
Log::add("warning", $message . "<br>\n{$e->getMessage()}");
Log::save("{$this->_viewDatas['title']} {$message}", false);
return alert_CommonHelper($message, 'back');
}
}
private function refresh(HPILO4 $ilo, HPILOEntity $entity)
{
$entity = $ilo->refresh($entity);
@ -143,28 +167,6 @@ class HPILOController extends \App\Controllers\Admin\AdminController
}
return $entity;
}
final public function reset(int $uid, string $type)
{
try {
$entity = $this->_model->getEntity($uid);
if (!in_array($type, ["On", "Off", "Restart"])) {
throw new \Exception(__FUNCTION__ . "에서 {$type}은 기능은 없습니다.");
}
$ilo = new HPILO4($this->getAdapter($entity));
$results = $ilo->reset($type);
Log::add("warning", var_export($results, true));
// sleep(DEFAULT_RERESH_WAITTIME);
// $entity = $this->refresh($ilo, $entity);
$message = "{$entity->getTitle()} " . __FUNCTION__ . " 완료하였습니다.";
Log::save("{$this->_viewDatas['title']} {$message}");
return alert_CommonHelper($message, $this->_session->get(SESSION_NAMES['RETURN_URL']));
} catch (\Exception $e) {
$message = "{$entity->getTitle()} " . __FUNCTION__ . " 실패하였습니다.";
Log::add("warning", $message . "<br>\n{$e->getMessage()}");
Log::save("{$this->_viewDatas['title']} {$message}", false);
return alert_CommonHelper($message, 'back');
}
}
final public function reload(int $uid)
{
try {

View File

@ -22,4 +22,21 @@ class HPILOEntity extends CommonEntity
{
return "uid:{$this->attributes['uid']}|{$this->attributes['customer']}|{$this->attributes['model']}";
}
public function getIP()
{
return $this->attributes['ip'];
}
public function getPort()
{
return $this->attributes['port'];
}
public function getID()
{
return $this->attributes['id'];
}
public function getPassword()
{
return $this->attributes['passwd'];
}
}

View File

@ -2,45 +2,49 @@
namespace App\Libraries\Adapter\API;
use \App\Entities\HPILOEntity;
// 참고:https://github.com/SyntaxPhoenix/iloclient
abstract class Adapter
{
private $_entity = null;
protected $_client = null;
protected $_serverInfo = array();
protected $_accountInfo = array();
protected $_debug = false;
protected function __construct($entity, $debug = false)
protected function __construct($debug = false)
{
$this->_entity = $entity;
$this->_debug = $debug;
}
abstract protected function getClient();
abstract protected function requestURL(string $url, string $method, array $datas = []): object;
final protected function getEntity()
final public function setServerInfo(string $ip, int $port)
{
return $this->_entity;
$this->_serverInfo['ip'] = $ip;
$this->_serverInfo['port'] = $port;
}
protected function getServerInfo($scheme = "https://", $delimeter = ":"): string
final protected function getServerInfo($scheme = "https://", $delimeter = ":"): string
{
return $scheme . $this->getEntity()->getIP() . $delimeter . $this->getEntity()->getPort();
return $scheme . $this->_serverInfo['ip'] . $delimeter . $this->_serverInfo['port'];
}
protected function getAccountInfo($type = 'basic'): array
final public function setAccountInfo(string $id, int $password)
{
$this->_serverInfo['id'] = $id;
$this->_serverInfo['password'] = $password;
}
final protected function getAccountInfo($authType = 'basic'): array
{
//type: basic , digest
return array($this->getEntity()->getID(), $this->getEntity()->getPassword(), $type);
return array($this->_serverInfo['id'], $this->_serverInfo['password'], $authType);
}
protected function isSSLVerifiy(): bool
{
return getenv('hpilo.ssl') == 'true' ? true : false;
return getenv('api.ssl') == 'true' ? true : false;
}
protected function getCookieFile()
{
return PATHS['API'] . getenv('api.cookie') ? getenv('api.cookie') : "api-cookie_" . date("Ymd") . ".log";
return PATHS['API'] . getenv('api.cookie.file') ?: "api-cookie_" . date("Ymd") . ".log";
}
protected function getDebugFile()
{
return PATHS['API'] . getenv('api.debug') ? getenv('api.debug') : "api-debug_" . date("Ymd") . ".log";
return PATHS['API'] . getenv('api.debug.file') ?: "api-debug_" . date("Ymd") . ".log";
}
final public function get(string $url): object

View File

@ -7,9 +7,9 @@ namespace App\Libraries\Adapter\API;
// https://github.com/SyntaxPhoenix/iloclient
class CurlAdapter extends Adapter
{
public function __construct($entity, $debug = false)
public function __construct($debug = false)
{
parent::__construct($entity, $debug);
parent::__construct($debug);
}
private function debugging($response, array $datas = array())
{

View File

@ -8,9 +8,9 @@ use GuzzleHttp\Exception\ClientException;
class GuzzleAdapter extends Adapter
{
private $_jar = null;
public function __construct($entity, $debug = false)
public function __construct($debug = false)
{
parent::__construct($entity, $debug);
parent::__construct($debug);
}
private function getCookieJar(): \GuzzleHttp\Cookie\CookieJar
{

View File

@ -4,9 +4,9 @@ namespace App\Libraries\Adapter\API;
class LocalAdapter extends Adapter
{
public function __construct($entity, $debug = false)
public function __construct($debug = false)
{
parent::__construct($entity, $debug);
parent::__construct($debug);
}
protected function getClient() //Codeigniter4 Service의 curlrequest이용시
@ -21,7 +21,7 @@ class LocalAdapter extends Adapter
'cookie' => $this->getCookieFile(),
];
if ($this->_debug) {
$options['debug'] = PATHS['API'] . getenv('api.adapter.debug') ? getenv('api.adapter.debug') : "api-debug_" . date("Ymd");
$options['debug'] = $this->getDebugFile();
}
$this->_client = \Config\Services::curlrequest($options);
}

View File

@ -16,52 +16,8 @@
<div class="accordion-item">
<h2><a href="/admin/logger"><i class="fa fa-recycle"></i>Log 관리</a></h2>
</div>
<!-- <div class="accordion-item">
<h2 class="accordion-header" id="panelsStayOpen-headingOne">
<button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#panelsStayOpen-collapseOne" aria-expanded="false" aria-controls="panelsStayOpen-collapseOne"><b>상점관리</b></button>
</h2>
<div id="panelsStayOpen-collapseOne" class="accordion-collapse collapse show" aria-labelledby="panelsStayOpen-headingOne">
<div class="accordion-item">
<h2><a href="/admin/ecommerce/product"><i class="fa fa-user-secret"></i>상품 관리</a></h2>
</div>
<div class="accordion-item">
<h2><a href="/admin/ecommerce/cart"><i class="fa fa-share-alt"></i>장바구니 관리</a></h2>
</div>
<div class="accordion-item">
<h2><a href="/admin/ecommerce/order"><i class="fa fa-cubes"></i>주문 관리</a></h2>
</div>
<div class="accordion-item">
<h2><a href="/admin/ecommerce/billing"><i class="fa fa-cube"></i>결제 관리</a></h2>
</div>
</div>
</div>
<div class="accordion-item">
<h2 class="accordion-header" id="panelsStayOpen-headingTwo">
<button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#panelsStayOpen-collapseTwo" aria-expanded="false" aria-controls="panelsStayOpen-collapseTwo"><b>Magic Transit</b></button>
</h2>
<div id="panelsStayOpen-collapseTwo" class="accordion-collapse collapse" aria-labelledby="panelsStayOpen-headingTwo">
<div class="accordion-item">
<h2><a href="/admin/magictransit/auth"><i class="fa fa-user-secret"></i>Auth관리</a></h2>
</div>
<div class="accordion-item">
<h2><a href="/admin/magictransit/account"><i class="fa fa-share-alt"></i>Account관리</a></h2>
</div>
<div class="accordion-item">
<h2><a href="/admin/magictransit/allowlist"><i class="fa fa-area-chart"></i>Allowlist관리</a></h2>
</div>
<div class="accordion-item">
<h2><a href="/admin/magictransit/syn_protection/rules"><i class="fa fa-line-chart"></i>SynProtection Rules관리</a></h2>
</div>
<div class="accordion-item">
<h2><a href="/admin/magictransit/syn_protection/filters"><i class="fa fa-line-chart"></i>SynProtection Filters관리</a></h2>
</div>
<div class="accordion-item">
<h2><a href="/admin/magictransit/out_of_state/rules"><i class="fa fa-pie-chart"></i>Out-Of-State Ruless관리</a></h2>
</div>
<div class="accordion-item">
<h2><a href="/admin/magictransit/out_of_state/filters"><i class="fa fa-pie-chart"></i>Out-Of-State Filters관리</a></h2>
</div>
</div>
</div> -->
<h2><a href="/admin/hpilo"><i class="fa fa-recycle"></i>HP Server 관리</a></h2>
</div>
</div>
</div>