123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811 |
- <?php
- class ApiController
- {
-
-
- private $returnJson = array('type' => 'api');
-
- public function __construct()
- {
-
-
- $server = new GuestModule;
- if (!$server->checkLogin()) {
- $this->returnJson['statusCode'] = '120005';
- exitOutput($this->returnJson);
- }
- }
-
- public function addApi()
- {
- $groupID = securelyInput('groupID');
-
- $module = new GroupModule();
- $userType = $module->getUserType($groupID);
- if ($userType < 0 || $userType > 2) {
- $this->returnJson['statusCode'] = '120007';
- exitOutput($this->returnJson);
- }
- $apiName = securelyInput('apiName');
- $apiURI = securelyInput('apiURI');
- $apiProtocol = securelyInput('apiProtocol');
- $apiRequestType = securelyInput('apiRequestType');
- $apiSuccessMock = quickInput('apiSuccessMock');
- $apiFailureMock = quickInput('apiFailureMock');
- $apiStatus = securelyInput('apiStatus');
- $starred = securelyInput('starred');
- $apiNoteType = securelyInput('apiNoteType');
- $apiNoteRaw = securelyInput('apiNoteRaw');
- $apiNote = securelyInput('apiNote');
- $apiRequestParamType = securelyInput('apiRequestParamType');
- $apiRequestRaw = securelyInput('apiRequestRaw');
- $apiHeader = json_decode($_POST['apiHeader'], TRUE);
- $apiRequestParam = json_decode($_POST['apiRequestParam'], TRUE);
- $apiResultParam = json_decode($_POST['apiResultParam'], TRUE);
- $mockRule = json_decode(quickInput('mockRule'), TRUE);
- $mockResult = securelyInput('mockResult');
- $mockConfig = quickInput('mockConfig');
- $failure_status_code = securelyInput('apiFailureStatusCode', '200');
- $success_status_code = securelyInput('apiSuccessStatusCode', '200');
- $before_inject = quickInput("beforeInject");
- $after_inject = quickInput("afterInject");
- $service = new ApiModule;
- $result = $service->addApi($apiName, $apiURI, $apiProtocol, $apiSuccessMock, $apiFailureMock, $apiRequestType, $apiStatus, $groupID, $apiHeader, $apiRequestParam, $apiResultParam, $starred, $apiNoteType, $apiNoteRaw, $apiNote, $apiRequestParamType, $apiRequestRaw, $mockRule, $mockResult, $mockConfig, $success_status_code, $failure_status_code, $before_inject, $after_inject);
- if ($result) {
- $this->returnJson['statusCode'] = '000000';
- $this->returnJson['apiID'] = $result['apiID'];
- $this->returnJson['groupID'] = $result['groupID'];
- } else {
- $this->returnJson['statusCode'] = '160000';
- }
- exitOutput($this->returnJson);
- }
-
- public function editApi()
- {
- $apiID = securelyInput('apiID');
- $module = new ApiModule();
-
- $userType = $module->getUserType($apiID);
- if ($userType < 0 || $userType > 2) {
- $this->returnJson['statusCode'] = '120007';
- exitOutput($this->returnJson);
- }
- $apiName = securelyInput('apiName');
- $apiURI = securelyInput('apiURI');
- $apiProtocol = securelyInput('apiProtocol');
- $apiRequestType = securelyInput('apiRequestType');
- $apiSuccessMock = quickInput('apiSuccessMock');
- $apiFailureMock = quickInput('apiFailureMock');
- $apiStatus = securelyInput('apiStatus');
- $starred = securelyInput('starred');
- $apiNoteType = securelyInput('apiNoteType');
- $apiNoteRaw = securelyInput('apiNoteRaw');
- $apiNote = securelyInput('apiNote');
- $apiRequestParamType = securelyInput('apiRequestParamType');
- $apiRequestRaw = securelyInput('apiRequestRaw');
- $groupID = securelyInput('groupID');
- $apiHeader = json_decode($_POST['apiHeader'], TRUE);
- $apiRequestParam = json_decode($_POST['apiRequestParam'], TRUE);
- $apiResultParam = json_decode($_POST['apiResultParam'], TRUE);
- $update_desc = securelyInput('updateDesc');
- $mockRule = json_decode(quickInput('mockRule'), TRUE);
- $mockResult = securelyInput('mockResult');
- $mockConfig = quickInput('mockConfig');
- $failure_status_code = securelyInput('apiFailureStatusCode', '200');
- $success_status_code = securelyInput('apiSuccessStatusCode', '200');
- $before_inject = quickInput("beforeInject");
- $after_inject = quickInput("afterInject");
- $service = new ApiModule;
- $result = $service->editApi($apiID, $apiName, $apiURI, $apiProtocol, $apiSuccessMock, $apiFailureMock, $apiRequestType, $apiStatus, $groupID, $apiHeader, $apiRequestParam, $apiResultParam, $starred, $apiNoteType, $apiNoteRaw, $apiNote, $apiRequestParamType, $apiRequestRaw, $update_desc, $mockRule, $mockResult, $mockConfig, $success_status_code, $failure_status_code, $before_inject, $after_inject);
- if ($result) {
- $this->returnJson['statusCode'] = '000000';
- $this->returnJson['apiID'] = $result['apiID'];
- $this->returnJson['groupID'] = $result['groupID'];
- } else {
- $this->returnJson['statusCode'] = '160000';
- }
- exitOutput($this->returnJson);
- }
-
- public function removeApi()
- {
-
- $ids = quickInput('apiID');
- $projectID = securelyInput('projectID');
-
- $module = new ProjectModule();
- $userType = $module->getUserType($projectID);
- if ($userType < 0 || $userType > 2) {
- $this->returnJson['statusCode'] = '120007';
- exitOutput($this->returnJson);
- }
- $arr = json_decode($ids);
- $arr = preg_grep('/^[0-9]{1,11}$/', $arr);
-
- if (empty($arr)) {
- $this->returnJson['statusCode'] = '160001';
- } elseif (!preg_match('/^[0-9]{1,11}$/', $projectID)) {
- $this->returnJson['statusCode'] = '160002';
- } else {
- $api_ids = implode(',', $arr);
- $api_module = new ApiModule;
- $result = $api_module->removeApis($projectID, $api_ids);
-
- if ($result) {
-
- $this->returnJson['statusCode'] = '000000';
- } else {
-
- $this->returnJson['statusCode'] = '160000';
- }
- }
- exitOutput($this->returnJson);
- }
-
- public function recoverApi()
- {
-
- $ids = securelyInput('apiID');
- $groupID = securelyInput('groupID');
-
- $module = new GroupModule();
- $userType = $module->getUserType($groupID);
- if ($userType < 0 || $userType > 2) {
- $this->returnJson['statusCode'] = '120007';
- exitOutput($this->returnJson);
- }
- $arr = json_decode($ids);
- $arr = preg_grep('/^[0-9]{1,11}$/', $arr);
-
- if (empty($arr)) {
- $this->returnJson['statusCode'] = '160001';
- } elseif (!preg_match('/^[0-9]{1,11}$/', $groupID)) {
- $this->returnJson['statusCode'] = '160002';
- } else {
- $api_ids = implode(',', $arr);
- $api_module = new ApiModule;
- $result = $api_module->recoverApis($groupID, $api_ids);
-
- if ($result) {
-
- $this->returnJson['statusCode'] = '000000';
- } else {
-
- $this->returnJson['statusCode'] = '160000';
- }
- }
- exitOutput($this->returnJson);
- }
-
- public function deleteApi()
- {
-
- $ids = securelyInput('apiID');
- $projectID = securelyInput('projectID');
-
- $module = new ProjectModule();
- $userType = $module->getUserType($projectID);
- if ($userType < 0 || $userType > 2) {
- $this->returnJson['statusCode'] = '120007';
- exitOutput($this->returnJson);
- }
- $arr = json_decode($ids);
- $arr = preg_grep('/^[0-9]{1,11}$/', $arr);
-
- if (empty($arr)) {
- $this->returnJson['statusCode'] = '160001';
- } elseif (!preg_match('/^[0-9]{1,11}$/', $projectID)) {
- $this->returnJson['statusCode'] = '160002';
- } else {
- $api_ids = implode(',', $arr);
- $api_module = new ApiModule;
- $result = $api_module->deleteApis($projectID, $api_ids);
-
- if ($result) {
-
- $this->returnJson['statusCode'] = '000000';
- } else {
-
- $this->returnJson['statusCode'] = '160000';
- }
- }
- exitOutput($this->returnJson);
- }
-
- public function cleanRecyclingStation()
- {
- $projectID = securelyInput('projectID');
- $module = new ProjectModule();
- $userType = $module->getUserType($projectID);
- if ($userType < 0 || $userType > 2) {
- $this->returnJson['statusCode'] = '120007';
- exitOutput($this->returnJson);
- }
- if (!preg_match('/^[0-9]{1,11}$/', $projectID)) {
- $this->returnJson['statusCode'] = '160002';
- } else {
- $service = new ApiModule;
- $result = $service->cleanRecyclingStation($projectID);
- if ($result) {
- $this->returnJson['statusCode'] = '000000';
- } else {
- $this->returnJson['statusCode'] = '160011';
- }
- }
- exitOutput($this->returnJson);
- }
-
- public function getRecyclingStationApiList()
- {
- $projectID = securelyInput('projectID');
- $orderBy = securelyInput('orderBy', 0);
- $asc = securelyInput('asc', 0);
- if (preg_match('/^[0-9]{1,11}$/', $projectID)) {
- $service = new ApiModule;
-
- switch ($orderBy) {
-
- case 0 :
- {
- $result = $service->getRecyclingStationApiListOrderByName($projectID, $asc);
- break;
- }
-
- case 1 :
- {
- $result = $service->getRecyclingStationApiListOrderByRemoveTime($projectID, $asc);
- break;
- }
-
- case 2 :
- {
- $result = $service->getRecyclingStationApiListOrderByStarred($projectID, $asc);
- break;
- }
-
- case 3 :
- {
- $result = $service->getRecyclingStationApiListOrderByCreateTime($projectID, $asc);
- }
- }
- if ($result) {
- $this->returnJson['statusCode'] = '000000';
- $this->returnJson['apiList'] = $result;
- } else {
- $this->returnJson['statusCode'] = '160007';
- }
- } else {
- $this->returnJson['statusCode'] = '160002';
- }
- exitOutput($this->returnJson);
- }
-
- public function getApiList()
- {
- $groupID = securelyInput('groupID');
- $orderBy = securelyInput('orderBy', 0);
- $asc = securelyInput('asc', 0);
- if (preg_match('/^[0-9]{1,11}$/', $groupID)) {
- $service = new ApiModule;
-
- switch ($orderBy) {
-
- case 0 :
- {
- $result = $service->getApiListOrderByName($groupID, $asc);
- break;
- }
-
- case 1 :
- {
- $result = $service->getApiListOrderByTime($groupID, $asc);
- break;
- }
-
- case 2 :
- {
- $asc = 1;
- $result = $service->getApiListOrderByStarred($groupID, $asc);
- break;
- }
-
- case 3 :
- {
- $result = $service->getApiListOrderByCreateTime($groupID, $asc);
- break;
- }
- }
- if ($result) {
- $this->returnJson['statusCode'] = '000000';
- $this->returnJson['apiList'] = $result;
- } else {
- $this->returnJson['statusCode'] = '160000';
- }
- } else {
- $this->returnJson['statusCode'] = '160002';
- }
- exitOutput($this->returnJson);
- }
-
- public function getApi()
- {
- $apiID = securelyInput('apiID');
- if (preg_match('/^[0-9]{1,11}$/', $apiID)) {
- $service = new ApiModule;
- $result = $service->getApi($apiID);
- if ($result) {
- $this->returnJson['statusCode'] = '000000';
- $this->returnJson['apiInfo'] = $result;
- } else {
- $this->returnJson['statusCode'] = '160000';
- }
- } else {
- $this->returnJson['statusCode'] = '160001';
- }
- exitOutput($this->returnJson);
- }
-
- public function getAllApiList()
- {
- $projectID = securelyInput('projectID');
- $orderBy = securelyInput('orderBy', 0);
- $asc = securelyInput('asc', 0);
- if (preg_match('/^[0-9]{1,11}$/', $projectID)) {
- $service = new ApiModule;
- switch ($orderBy) {
-
- case 0 :
- {
- $result = $service->getAllApiListOrderByName($projectID, $asc);
- break;
- }
-
- case 1 :
- {
- $result = $service->getAllApiListOrderByTime($projectID, $asc);
- break;
- }
-
- case 2 :
- {
- $asc = 1;
- $result = $service->getAllApiListOrderByStarred($projectID, $asc);
- break;
- }
-
- case 3 :
- {
- $result = $service->getAllApiListOrderByCreateTime($projectID, $asc);
- }
- }
- if ($result) {
- $this->returnJson['statusCode'] = '000000';
- $this->returnJson['apiList'] = $result;
- } else {
- $this->returnJson['statusCode'] = '160000';
- }
- } else {
- $this->returnJson['statusCode'] = '160003';
- }
- exitOutput($this->returnJson);
- }
-
- public function searchApi()
- {
- $tipsLen = mb_strlen(quickInput('tips'), 'utf8');
- $tips = securelyInput('tips');
- $projectID = securelyInput('projectID');
- if (!preg_match('/^[0-9]{1,11}$/', $projectID)) {
- $this->returnJson['statusCode'] = '160003';
- } else if ($tipsLen > 255 || $tipsLen == 0) {
- $this->returnJson['statusCode'] = '160004';
- } else {
- $service = new ApiModule;
- $result = $service->searchApi($tips, $projectID);
- if ($result) {
- $this->returnJson['statusCode'] = '000000';
- $this->returnJson['apiList'] = $result;
- } else {
- $this->returnJson['statusCode'] = '160000';
- }
- }
- exitOutput($this->returnJson);
- }
-
- public function addStar()
- {
- $apiID = securelyInput('apiID');
- if (preg_match('/^[0-9]{1,11}$/', $apiID)) {
- $service = new ApiModule;
- $result = $service->addStar($apiID);
- if ($result) {
- $this->returnJson['statusCode'] = '000000';
- } else {
- $this->returnJson['statusCode'] = '160000';
- }
- } else {
- $this->returnJson['statusCode'] = '160001';
- }
- exitOutput($this->returnJson);
- }
-
- public function removeStar()
- {
- $apiID = securelyInput('apiID');
- if (preg_match('/^[0-9]{1,11}$/', $apiID)) {
- $service = new ApiModule;
- $result = $service->removeStar($apiID);
- if ($result) {
- $this->returnJson['statusCode'] = '000000';
- } else {
- $this->returnJson['statusCode'] = '160000';
- }
- } else {
- $this->returnJson['statusCode'] = '160001';
- }
- exitOutput($this->returnJson);
- }
-
- public function getApiHistoryList()
- {
-
- $api_id = securelyInput('apiID');
-
- if (!preg_match('/^[0-9]{1,11}$/', $api_id)) {
- $this->returnJson['statusCode'] = '160001';
- } else {
- $api_module = new ApiModule();
- $result = $api_module->getApiHistoryList($api_id);
-
- if ($result) {
- $this->returnJson['statusCode'] = '000000';
- $this->returnJson = array_merge($this->returnJson, $result);
- } else {
- $this->returnJson['statusCode'] = '160000';
- }
- }
- exitOutput($this->returnJson);
- }
-
- public function deleteApiHistory()
- {
-
- $api_history_id = securelyInput('apiHistoryID');
-
- $api_id = securelyInput('apiID');
-
- $api_module = new ApiModule();
- $userType = $api_module->getUserType($api_id);
- if ($userType < 0 || $userType > 2) {
- $this->returnJson['statusCode'] = '120007';
- exitOutput($this->returnJson);
- }
-
- if (!preg_match('/^[0-9]{1,11}$/', $api_id)) {
- $this->returnJson['statusCode'] = '160001';
- }
- elseif (!preg_match('/^[0-9]{1,11}$/', $api_history_id)) {
- $this->returnJson['statusCode'] = '160004';
- } else {
- $result = $api_module->deleteApiHistory($api_id, $api_history_id);
-
- if ($result) {
- $this->returnJson['statusCode'] = '000000';
- } else {
- $this->returnJson['statusCode'] = '160000';
- }
- }
- exitOutput($this->returnJson);
- }
-
- public function toggleApiHistory()
- {
-
- $api_history_id = securelyInput('apiHistoryID');
-
- $api_id = securelyInput('apiID');
-
- $api_module = new ApiModule();
- $userType = $api_module->getUserType($api_id);
- if ($userType < 0 || $userType > 2) {
- $this->returnJson['statusCode'] = '120007';
- exitOutput($this->returnJson);
- }
-
- if (!preg_match('/^[0-9]{1,11}$/', $api_id)) {
- $this->returnJson['statusCode'] = '160001';
- }
- elseif (!preg_match('/^[0-9]{1,11}$/', $api_history_id)) {
- $this->returnJson['statusCode'] = '160004';
- } else {
- $result = $api_module->toggleApiHistory($api_id, $api_history_id);
-
- if ($result) {
- $this->returnJson['statusCode'] = '000000';
- } else {
- $this->returnJson['statusCode'] = '160000';
- }
- }
- exitOutput($this->returnJson);
- }
-
- public function getApiMockData()
- {
- $api_id = securelyInput('apiID');
-
- if (!preg_match('/^[0-9]{1,11}$/', $api_id)) {
- $this->returnJson['statusCode'] = '160001';
- } else {
- $module = new ApiModule();
- $result = $module->getApiMockData($api_id);
- if ($result) {
- $this->returnJson['statusCode'] = '000000';
- $this->returnJson = array_merge($this->returnJson, $result);
- } else {
- $this->returnJson['statusCode'] = '160000';
- }
- }
- exitOutput($this->returnJson);
- }
-
- public function editApiMockData()
- {
- $api_id = securelyInput('apiID');
- $module = new ApiModule();
-
- $userType = $module->getUserType($api_id);
- if ($userType < 0 || $userType > 2) {
- $this->returnJson['statusCode'] = '120007';
- exitOutput($this->returnJson);
- }
- $mock_rule = quickInput('mockRule', '');
- $mock_result = securelyInput('mockResult', '');
- $mock_config = quickInput('mockConfig');
-
- if (!preg_match('/^[0-9]{1,11}$/', $api_id)) {
- $this->returnJson['statusCode'] = '160001';
- } else {
- $result = $module->editApiMockData($api_id, $mock_rule, $mock_result, $mock_config);
- if ($result) {
- $this->returnJson['statusCode'] = '000000';
- } else {
- $this->returnJson['statusCode'] = '160000';
- }
- }
- exitOutput($this->returnJson);
- }
-
- public function changeApiGroup()
- {
-
- $ids = securelyInput('apiID');
- $group_id = securelyInput('groupID');
-
- $module = new GroupModule();
- $userType = $module->getUserType($group_id);
- if ($userType < 0 || $userType > 2) {
- $this->returnJson['statusCode'] = '120007';
- exitOutput($this->returnJson);
- }
- $arr = json_decode($ids);
- $arr = preg_grep('/^[0-9]{1,11}$/', $arr);
-
- if (empty($arr)) {
- $this->returnJson['statusCode'] = '160001';
- } elseif (!preg_match('/^[0-9]{1,11}$/', $group_id)) {
- $this->returnJson['statusCode'] = '160002';
- } else {
- $api_ids = implode(',', $arr);
- $api_module = new ApiModule;
- $result = $api_module->changeApiGroup($api_ids, $group_id);
-
- if ($result) {
-
- $this->returnJson['statusCode'] = '000000';
- } else {
-
- $this->returnJson['statusCode'] = '160000';
- }
- }
- exitOutput($this->returnJson);
- }
-
- public function exportApi()
- {
- $project_id = securelyInput('projectID');
-
- $ids = quickInput('apiID');
- $arr = json_decode($ids);
- $arr = preg_grep('/^[0-9]{1,11}$/', $arr);
- if (!preg_match('/^[0-9]{1,11}$/', $project_id)) {
- $this->returnJson['statusCode'] = '160003';
- }
- elseif (empty($arr)) {
-
- $this->returnJson['statusCode'] = '160001';
- } else {
- $project_module = new ProjectModule();
- $user_type = $project_module->getUserType($project_id);
- if ($user_type < 0 || $user_type > 2) {
- $this->returnJson['statusCode'] = '120007';
- } else {
- $api_ids = implode(',', $arr);
- $api_module = new ApiModule();
- $result = $api_module->exportApi($project_id, $api_ids);
-
- if ($result) {
- $this->returnJson['statusCode'] = '000000';
- $this->returnJson['fileName'] = $result;
- } else {
- $this->returnJson['statusCode'] = '160000';
- }
- }
- }
- exitOutput($this->returnJson);
- }
-
- public function importApi()
- {
- $json = quickInput('data');
- $data = json_decode($json, TRUE);
- $group_id = securelyInput('groupID');
-
- if (!preg_match('/^[0-9]{1,11}$/', $group_id)) {
-
- $this->returnJson['statusCode'] = '160005';
- }
- elseif (empty($data)) {
- $this->returnJson['statusCode'] = '160006';
- exitOutput($this->returnJson);
- } else {
- $group_module = new GroupModule();
- $user_type = $group_module->getUserType($group_id);
- if ($user_type < 0 || $user_type > 2) {
- $this->returnJson['statusCode'] = '120007';
- } else {
- $server = new ApiModule();
- $result = $server->importApi($group_id, $data);
-
- if ($result) {
- $this->returnJson['statusCode'] = '000000';
- } else {
- $this->returnJson['statusCode'] = '160000';
- }
- }
- }
- exitOutput($this->returnJson);
- }
- }
- ?>
|