protected function run() { $reg = ResponseRegistery::getInstance(); $reg->weblog_id = $this->getWeblogId(); try { $service = new ServiceController($reg->service); $service->perform($reg->task); } catch (ReflectionException $e) { throw new EAccessDenied("service : {$reg->service} not found"); } }
public function process() { session_start(); $aclang = $this->getallheaders(); $this->log->Info("Serving request: " . implode(",", $aclang)); $pageId = $this->determinePage(); if ($pageId == "") { $this->log->Info("PageId is null, redirecting to entry.php?t=dashboard&type=duplicate"); header('Location: ' . $this->urlRewrite->r('entry.php?t=dashboard&type=duplicate')); } else { $this->log->Info("PageId " . $pageId); $lang = $this->determineLanguage(); $textResources = new TextResources($lang); $serverContext = str_replace('/entry.php', '', $_SERVER['SCRIPT_NAME']); $pageContext = new PageContext($pageId, $textResources, $lang, $serverContext); $twigVars = array('host' => "http://" . $_SERVER['HTTP_HOST'], 'textResources' => $textResources, 'pageContext' => $pageContext); $twigTemplate = $pageId; $render = true; $controller = null; switch ($pageId) { case 'login': $controller = new LoginController(); $twigTemplate = 'login'; break; case 'dashboard': $controller = new DashboardController(); $twigTemplate = 'dashboard'; break; case 'manageAlbums': $controller = new ManageAlbumsController(); $twigTemplate = 'manageAlbums'; break; case 'service': $controller = new ServiceController(); break; } if (isset($controller)) { $vars = $controller->process($this->urlRewrite); $render = $vars['render']; $twigVars = array_merge($twigVars, $vars); } $twigVars = array_merge($twigVars, array('config' => $GLOBALS['config'], 'userLoggedIn' => isset($_SESSION['user']))); if (isset($_SESSION['user'])) { $twigVars = array_merge($twigVars, array('user' => $_SESSION['user'])); } if ($render === true) { echo $this->twig->render('page/' . $twigTemplate . '.twig', $twigVars); } } }
protected function run() { fb(Session::getInstance()->site_id, 'site_id'); ResponseRegistery::getInstance()->site_id = Session::getInstance()->site_id; $reg = ResponseRegistery::getInstance(); //$reg->weblog_id = $this->getWeblogId(); try { $reg->sub_domain = $this->findWeblogAddress(); $service = new ServiceController($reg->service); $service->perform($reg->task); } catch (ReflectionException $e) { throw new EAccessDenied("service : {$reg->service} not found"); } }
private function retryOperation($node_id, $idc_list, $new_val, $op_user, $batch_type, $note = "") { //echo "$node_id, $idc_list, $new_val, $note, $op_user, $batch_type".PHP_EOL; $node_row = NodeServ::getNode($node_id); $node_whole = $node_row["node_whole"]; $main_buss_id = $node_row["main_buss_id"]; $sub_buss_id = $node_row["sub_buss_id"]; $MAX_RETRY_TIMES = 3; $failed_idcs = $idc_list; //outside loop for failed idcs $outside_retry_time = 0; while (count($failed_idcs) != 0 && $outside_retry_time < $MAX_RETRY_TIMES) { $tmp_list = $failed_idcs; $failed_idcs = array(); foreach ($tmp_list as $one_idc) { switch ($batch_type) { case InfoDescUtil::OP_TYPE_BATCH_MOD_VALUE: $ret = NodeController::modNodeValue($node_id, $one_idc, $node_whole, $main_buss_id, $sub_buss_id, $new_val, $note, $op_user); break; case InfoDescUtil::OP_TYPE_BATCH_ADD_SERV: $ret = ServiceController::addService($node_row, $one_idc, $new_val, $op_user); break; } if ($ret != 0) { array_push($failed_idcs, $one_idc); } } $outside_retry_time++; } return $failed_idcs; }
private function upOrOfflineService($op_type) { // 1.argument receive and preprocess $res = ""; $argus = self::commonArgusProcess($res); if ($argus === FALSE) { echo json_encode($res); return; } $user = $argus["user"]; $path = $argus["path"]; $idc = $argus["idc"]; $main_buss_id = $argus["main_buss_id"]; $sub_buss_id = $argus["sub_buss_id"]; $service_name = $this->getRequest("service_name", ""); if ($service_name === "") { $res = InfoDescUtil::getErrorMsg(InfoDescUtil::ERR_BAD_ARGS); QconfMgrLog::err(__FILE__, __LINE__, "paramter: 'service_name({$service_name})'is required!"); echo json_encode($res); return; } $service_list = preg_split("/[,]+/", trim($service_name, ",")); //validate for ip_port if (ArgsUtil::ipPortsValidation($service_list) === FALSE) { //failed to add any new services $res = InfoDescUtil::getErrorMsg(InfoDescUtil::ERR_BAD_ARGS); QconfMgrLog::err(__FILE__, __LINE__, "ilegal services : {$service_name} under {$path}!"); echo json_encode($res); return; } // 2. check node exist and is node father type $check_res = ServiceController::checkServFatherNode($path, $main_buss_id); if ($check_res != InfoDescUtil::QCONF_OK) { $res = InfoDescUtil::getErrorMsg($check_res); echo json_encode($res); return; } // 3. do up or offline $op_type_msg = $op_type === InfoDescUtil::OP_TYPE_OFFLINE ? "offline" : "up"; $idc_list = preg_split("/[,]+/", $idc); // split by , foreach ($idc_list as $idc_each) { $idc_host = ZkConf::getZkHost($idc_each); $zk_web = new QconfZkWebBase(Log::INFO); $zk_web->connect($idc_host); $get_ret = ServiceController::getServicesAndStatusWithLink($zk_web, $path, $idc_each, $exist_services); if ($get_ret != InfoDescUtil::QCONF_OK) { $res = InfoDescUtil::getErrorMsg($get_ret); echo json_encode($res); return; } foreach ($service_list as $service) { $show_ser_path = PathUtil::unionPath($path, $service); // check service exist if (!array_key_exists($service, $exist_services)) { $res = InfoDescUtil::getErrorMsg(InfoDescUtil::ERR_SERVICE_NO_EXIST); echo json_encode($res); return; } if ($op_type === InfoDescUtil::OP_TYPE_OFFLINE) { //check up service cout for offline operation $is_last = TRUE; foreach ($exist_services as $one_exist_service => $service_status) { if ($service_status === InfoDescUtil::SERV_STATUS_UP && $one_exist_service != $service) { $is_last = FALSE; break; } } if ($is_last) { $res = InfoDescUtil::getErrorMsg(InfoDescUtil::ERR_OFFILE_SERVICE_ONLY); QconfMgrLog::err(__FILE__, __LINE__, "{$service} is the last up service under {$path}"); echo json_encode($res); return; } $ret = ServiceController::offlineServiceWithLink($zk_web, $path, $service, $idc_each); $exist_services[$service] = InfoDescUtil::SERV_STATUS_DOWN; } else { $ret = ServiceController::upServiceWithLink($zk_web, $path, $service, $idc_each); } if ($ret != InfoDescUtil::QCONF_OK) { $res = InfoDescUtil::getErrorMsg($ret); QconfMgrLog::err(__FILE__, __LINE__, "{$op_type_msg} service!"); OpServ::insert($op_type, $show_ser_path, $idc_each, InfoDescUtil::OP_STATUS_ZOO_FAILED, $main_buss_id, $sub_buss_id, $user, ""); echo json_encode($res); return; } OpServ::insert($op_type, $show_ser_path, $idc_each, InfoDescUtil::OP_STATUS_SUCCESS, $main_buss_id, $sub_buss_id, $user, $op_type === InfoDescUtil::OP_TYPE_OFFLINE ? InfoDescUtil::SERV_STATUS_OFFLINE : InfoDescUtil::SERV_STATUS_UP); } } $res = array("errno" => "0", "errmsg" => "", "data" => "{$op_type_msg} service success"); $json = json_encode($res); echo $json; return; }
case 'addNew': $serviceRequestsController->addNew(); break; case 'updateRequestStatus': $serviceRequestsController->updateRequestStatus(); break; case 'deleteRequest': $serviceRequestsController->deleteRequest(); break; default: $serviceRequestsController->render(); break; } break; case "services": $serviceController = new ServiceController(); $where = $route[2]; switch ($where) { case 'addNew': $serviceController->addNew(); break; case 'updateRequestStatus': $serviceController->updateService(); break; default: $serviceController->render(); break; } break; case "users": $userController = new UserController();
* autoformat Use toTitle/UCWORDS or not * debug Enable debug mode or not * cache To use cache or not * stype Type of command (py, php, etc.) */ if (defined('ROOT')) { exit('Only Direct Access Is Allowed'); } define('ROOT', dirname(dirname(__FILE__)) . '/'); require_once ROOT . 'services/initialize.php'; if (!isset($_REQUEST['scmd'])) { trigger_logikserror(901, E_USER_ERROR); exit; } loadAppServices(SITENAME); loadLogiksBootEngines(); //Check blacklists, bots, and others $security = new LogiksSecurity(); $security->checkServiceRequest(); runHooks("serviceStart"); $ctrl = new ServiceController(); //loads the parameters into the service controller $ctrl->setupRequest($_REQUEST); //access_control, privilege_model, APIKEY check if ($ctrl->checkRequest()) { //checks cache and if required executes the scmd and prints the output $ctrl->executeRequest(); } else { trigger_logikserror(905, E_USER_ERROR); } runHooks("serviceStop");
public function rollbackAction() { $path = trim($this->getRequest("path", ""), "/"); $idc = $this->getRequest("idc", ""); $main_buss_id = $this->getRequest("main_buss_id", ""); $op_user = $this->userInfo["userName"]; // 1. parameter null if ($path === "" || $main_buss_id === "" || $idc === "") { $res = InfoDescUtil::getErrorMsg(InfoDescUtil::ERR_BAD_ARGS); QconfMgrLog::err(__FILE__, __LINE__, "parameter 'main_buss_id', 'path' or 'idc' is null!"); echo json_encode($res); return; } // 2. check node exist $path = "/" . $path; $node = NodeServ::getNodeByNodeWhole($path, $main_buss_id); if ($node === FALSE) { $res = InfoDescUtil::getErrorMsg(InfoDescUtil::ERR_NODE_NOT_EXIST); QconfMgrLog::err(__FILE__, __LINE__, "node({$path}) with main_buss_id({$main_buss_id}) not exist!"); echo json_encode($res); return; } $node_whole = $node["node_whole"]; //[USERPERM CHECK] $userperm_ret = UserPermServ::checkPerm($op_user, $node_whole); if ($userperm_ret === FALSE) { QconfMgrLog::err(__FILE__, __LINE__, "Insufficient permission of {$op_user} on node {$node_whole}"); $res = InfoDescUtil::getErrorMsg(InfoDescUtil::ERR_USER_PERM_PERMISSION_DENIED); echo json_encode($res); return; } $main_buss_id = $node["main_buss_id"]; $sub_buss_id = $node["sub_buss_id"]; // 3. idc validation $cur_idcs = $node["idc"]; $check_res = self::idcValidation($idc, $cur_idcs); if ($check_res["errno"] != "0") { echo json_encode($check_res); return; } // 4. get snapshot content $snapshot_content = SnapShotUtil::getSnapShotContent($main_buss_id, $node_whole); if ($snapshot_content === FALSE) { $res = InfoDescUtil::getErrorMsg(InfoDescUtil::ERR_SNAPSHOT_MODULE_FAILED); QconfMgrLog::err(__FILE__, __LINE__, "failed to get snapshot by node_whole({$node_whole}), main_buss_id({$main_buss_id})"); echo json_encode($res); return; } // 5.rollback if (!array_key_exists($idc, $snapshot_content)) { $res = InfoDescUtil::getErrorMsg(InfoDescUtil::ERR_SNAPSHOT_IDC_NOT_EXIST); QconfMgrLog::err(__FILE__, __LINE__, "snapshot of node_whole({$node_whole}), main_buss_id({$main_buss_id}) do not exist on idc({$idc}) "); echo json_encode($res); return; } $result_idc = $snapshot_content[$idc]; if (!array_key_exists("conf", $result_idc) || !array_key_exists("serv", $result_idc)) { $res = InfoDescUtil::getErrorMsg(InfoDescUtil::ERR_SNAPSHOT_FILE_ERROR); QconfMgrLog::err(__FILE__, __LINE__, "snapshot error of node_whole({$node_whole}), main_buss_id({$main_buss_id})"); echo json_encode($res); return; } $idc_host = ZkConf::getZkHost($idc); $zk_web = new QconfZkWebBase(Log::INFO); $zk_web->connect($idc_host); $result_conf = $result_idc["conf"]; foreach ($result_conf as $key => $value) { $set_ret = NodeController::setConfWithLink($zk_web, $key, $idc, $value); if ($set_ret != InfoDescUtil::QCONF_OK) { OpServ::insert(InfoDescUtil::OP_TYPE_MOD, $key, $idc, InfoDescUtil::OP_STATUS_ZOO_FAILED, $main_buss_id, $sub_buss_id, $op_user, ""); $res = InfoDescUtil::getErrorMsg($set_ret); QconfMgrLog::err(__FILE__, __LINE__, "replace node value by snapshot failed, node_whole({$node_whole}),\n main_buss_id({$main_buss_id})"); echo json_encode($res); return; } OpServ::insert(InfoDescUtil::OP_TYPE_MOD, $key, $idc, InfoDescUtil::OP_STATUS_SUCCESS, $main_buss_id, $sub_buss_id, $op_user, $value); } $result_serv = $result_idc["serv"]; foreach ($result_serv as $key => $hosts) { $current_serv_no_statu = array(); $snapshot_serv_no_statu = array_keys($hosts); $get_ret = ServiceController::getServicesWithLink($zk_web, $key, $idc, $current_serv_no_statu); if ($get_ret != InfoDescUtil::QCONF_OK) { $res = InfoDescUtil::getErrorMsg($get_ret); QconfMgrLog::err(__FILE__, __LINE__, "get service failed, key({$key})!"); echo json_encode($res); return; } $serv_to_add = array_diff($snapshot_serv_no_statu, $current_serv_no_statu); $serv_to_delete = array_diff($current_serv_no_statu, $snapshot_serv_no_statu); $serv_to_modify = array_intersect($snapshot_serv_no_statu, $current_serv_no_statu); foreach ($serv_to_add as $ser) { $show_ser_path = PathUtil::unionPath($key, $ser); $add_ret = ServiceController::addServiceWithLink($zk_web, $key, $ser, $idc, $hosts[$ser]); if ($add_ret != InfoDescUtil::QCONF_OK) { $res = InfoDescUtil::getErrorMsg($add_ret); OpServ::insert(InfoDescUtil::OP_TYPE_ADD, $show_ser_path, $idc, InfoDescUtil::OP_STATUS_ZOO_FAILED, $main_buss_id, $sub_buss_id, $op_user, ""); echo json_encode($res); return; } OpServ::insert(InfoDescUtil::OP_TYPE_ADD, $show_ser_path, $idc, InfoDescUtil::OP_STATUS_SUCCESS, $main_buss_id, $sub_buss_id, $op_user, ""); } foreach ($serv_to_modify as $ser) { $show_ser_path = PathUtil::unionPath($key, $ser); $snapshot_statu = $hosts[$ser]; if ($snapshot_statu === InfoDescUtil::SERV_STATUS_UP || $snapshot_statu === InfoDescUtil::SERV_STATUS_DOWN) { $modify_ret = ServiceController::upServiceWithLink($zk_web, $key, $ser, $idc); $modify_type = InfoDescUtil::OP_TYPE_UP; } else { if ($snapshot_statu === InfoDescUtil::SERV_STATUS_OFFLINE) { $modify_ret = ServiceController::offlineServiceWithLink($zk_web, $key, $ser, $idc); $modify_type = InfoDescUtil::OP_TYPE_OFFLINE; } else { QconfMgrLog::err(__FILE__, __LINE__, "service status is unknown, show_ser_path({$show_ser_path})!"); } } if ($modify_ret != InfoDescUtil::QCONF_OK) { $res = InfoDescUtil::getErrorMsg($modify_ret); OpServ::insert($modify_type, $show_ser_path, $idc, InfoDescUtil::OP_STATUS_ZOO_FAILED, $main_buss_id, $sub_buss_id, $op_user, ""); echo json_encode($res); return; } OpServ::insert($modify_type, $show_ser_path, $idc, InfoDescUtil::OP_STATUS_SUCCESS, $main_buss_id, $sub_buss_id, $op_user, ""); } foreach ($serv_to_delete as $ser) { $show_ser_path = PathUtil::unionPath($key, $ser); $delete_ret = ServiceController::deleteServiceWithLink($zk_web, $key, $ser, $idc); if ($delete_ret != InfoDescUtil::QCONF_OK) { $res = InfoDescUtil::getErrorMsg($delete_ret); OpServ::insert(InfoDescUtil::OP_TYPE_DEL, $show_ser_path, $idc, InfoDescUtil::OP_STATUS_ZOO_FAILED, $main_buss_id, $sub_buss_id, $op_user, ""); echo json_encode($res); return; } OpServ::insert(InfoDescUtil::OP_TYPE_DEL, $show_ser_path, $idc, InfoDescUtil::OP_STATUS_SUCCESS, $main_buss_id, $sub_buss_id, $op_user, ""); } } OpServ::insert(InfoDescUtil::OP_TYPE_SNAPSHOT_ROLLBACK, $node_whole, $idc, InfoDescUtil::OP_STATUS_SUCCESS, $main_buss_id, $sub_buss_id, $op_user, ""); $res = array("errno" => "0", "errmsg" => "", "data" => "rollback success"); $json = json_encode($res); echo $json; return; }
ServiceController::store(); }); $routes->get('/palvelut/new', function () { ServiceController::create(); }); $routes->get('/palvelut/:id', function ($id) { ServiceController::show($id); }); $routes->get('/palvelut/:id/edit', function ($id) { ServiceController::edit($id); }); $routes->post('/palvelut/:id/edit', function ($id) { ServiceController::update($id); }); $routes->post('/palvelut/:id/destroy', function ($id) { ServiceController::destroy($id); }); //employee $routes->post('/tyontekijat/store', function () { EmployeeController::store(); }); $routes->get('/tyontekijat/new', function () { EmployeeController::create(); }); $routes->get('/tyontekijat/:id', function ($id) { EmployeeController::show($id); }); $routes->get('/tyontekijat/:id/edit', function ($id) { EmployeeController::edit($id); }); $routes->post('/tyontekijat/:id/edit', function ($id) {
ServiceController::make_reservation($id); }); $routes->get('/service/add', 'check_user_is_manager', function () { ServiceController::add(); })->name('service_add'); $routes->post('/service/add', 'check_user_is_manager', function () { ServiceController::create(); }); $routes->get('/service/:id/delete', 'check_user_is_manager', function ($id) { ServiceController::confirm_delete($id); })->name('service_delete'); $routes->post('/service/:id/delete', 'check_user_is_manager', function ($id) { ServiceController::delete($id); }); $routes->get('/service/:id/enable', 'check_user_is_manager', function ($id) { ServiceController::enable($id); })->name('service_enable'); $routes->get('/reservations', 'check_logged_in', function () { ReservationController::index(); })->name('reservations_index'); $routes->post('/reservations/:id/cancel', function ($id) { ReservationController::cancel_reservation($id); })->name('reservation_cancel'); $routes->get('/invoice', 'check_logged_in', function () { InvoiceController::index(); })->name('invoices_index'); $routes->get('/invoice/:id', 'check_logged_in', function ($id) { InvoiceController::invoice_details($id); })->name('invoice_detail'); $routes->get('/invoice/:id/accept', 'check_user_is_manager', function ($id) { InvoiceController::accept_invoice($id);
private function addOneIdcWithLink($qconf_node_type, $node_whole, $idc, $node_val, $node_services, $zk_web) { //echo "$qconf_node_type, $node_whole, $idc, $node_val,"; $qconf_path = PathUtil::getQconfPath($node_whole); if (intval($qconf_node_type) === intval(InfoDescUtil::NODE_TYPE_SERV_FATHER)) { // 1. add group path QconfMgrLog::err(__FILE__, __LINE__, "{$node_whole} in {$idc} set to be ser group path!"); $ret = -1; $retry_time = 0; while ($ret === -1 && $retry_time <= InfoDescUtil::ZK_MAX_RETRY_TIME) { QconfMgrLog::err(__FILE__, __LINE__, "retry {$retry_time} of " . InfoDescUtil::ZK_MAX_RETRY_TIME . " to add group path for {$node_whole}"); $ret = $zk_web->add_group_path($qconf_path); $retry_time++; } // 2. set conf if ($ret != -1) { $ret = self::setConfWithLink($zk_web, $node_whole, $idc, $node_val); } // 3.set services if needed if ($ret != -1 && $node_services != NULL) { foreach ($node_services as $ser => $status) { $ret = ServiceController::addServiceWithLink($zk_web, $node_whole, $ser, $idc, $status); if ($ret === -1) { break; } } } } else { $ret = -1; $retry_time = 0; while ($ret === -1 && $retry_time <= InfoDescUtil::ZK_MAX_RETRY_TIME) { QconfMgrLog::err(__FILE__, __LINE__, "retry {$retry_time} of " . InfoDescUtil::ZK_MAX_RETRY_TIME . " to add conf: {$node_whole}"); $ret = $zk_web->add_conf($qconf_path, $node_val); $retry_time++; } } return $ret; }