Changeset 2439247
- Timestamp:
- 12/14/2020 05:39:29 PM (5 years ago)
- Location:
- unsproject/trunk
- Files:
-
- 4 edited
-
readme.md (modified) (1 diff)
-
src/ServerCall.php (modified) (3 diffs)
-
src/UnsApp.php (modified) (5 diffs)
-
unsproject.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
unsproject/trunk/readme.md
r2412807 r2439247 55 55 56 56 == Changelog == 57 = 1.1.0 (14 Dec 2020) 58 * On plugin cleanup delete data from UNS servers 59 * Remove prefix from uniqueID 60 57 61 = 1.0.0 (04 Nov 2020) = 58 62 * Initial release -
unsproject/trunk/src/ServerCall.php
r2412699 r2439247 22 22 $args = array( 23 23 'method' => strtoupper($method), 24 'body' => $parameters, 25 'timeout' => '5', 26 'redirection' => '5', 24 'timeout' => isset($parameters['timeout']) 25 ? $parameters['timeout'] 26 : 5, 27 'redirection' => isset($parameters['redirection']) 28 ? $parameters['redirection'] 29 : 5, 27 30 ); 31 32 if(isset($parameters['body'])){ 33 $args['body'] = $parameters['body']; 34 } 35 if(isset($parameters['headers'])){ 36 $args['headers'] = $parameters['headers']; 37 } 38 28 39 $response = wp_remote_request( $url, $args ); 29 40 $statusCode = wp_remote_retrieve_response_code( $response ); … … 59 70 * @param array $parameters 60 71 * @param int $statusCode 72 * @param null|string $callResult 61 73 * @return array 62 74 */ 63 public static function put($url, $parameters, &$statusCode ){64 return self::call(self::REQUEST_METHOD_PUT, $url, $parameters, $statusCode );75 public static function put($url, $parameters, &$statusCode, &$callResult){ 76 return self::call(self::REQUEST_METHOD_PUT, $url, $parameters, $statusCode, $callResult); 65 77 } 66 78 … … 69 81 * @param array $parameters 70 82 * @param int $statusCode 83 * @param null|string $callResult 71 84 * @return array 72 85 */ 73 public static function delete($url, $parameters,&$statusCode ){74 return self::call(self::REQUEST_METHOD_DELETE, $url, $parameters, $statusCode );86 public static function delete($url, $parameters,&$statusCode, &$callResult){ 87 return self::call(self::REQUEST_METHOD_DELETE, $url, $parameters, $statusCode, $callResult); 75 88 } 76 89 -
unsproject/trunk/src/UnsApp.php
r2412699 r2439247 40 40 /** 41 41 * @param SiteOptions $siteOption 42 * 43 * @return boolean 44 * @throws Libraries\JWTException|UnsAppException 45 */ 46 public static function deleteService($siteOption) 47 { 48 if(empty($siteOption->getValue('private_key'))){ 49 throw new UnsAppException('Missing plugin config. Please contact UNSproject support team to help you.'); 50 } 51 52 $parameters = [ 53 'body' => [ 54 'serviceNamespace' => $siteOption->getValue('uniqueId') 55 ], 56 'headers' => [ 57 'authorization' =>'Basic' . ' ' . JWT::encode( 58 [ 59 'delete' => $siteOption->getValue('uniqueId') 60 ], 61 base64_decode($siteOption->getValue('private_key')), 62 'RS256' 63 ) 64 ] 65 ]; 66 67 $url = self::API_URL. '/services'; 68 ServerCall::delete($url, $parameters, $statusCode, $result); 69 70 if(!in_array($statusCode, [200, 201])){ 71 throw new UnsAppException( 72 sprintf( 73 'Unable to delete the service. Status code: %s. Message: %s', 74 $statusCode, 75 strip_tags($result) 76 ) 77 ); 78 } 79 } 80 81 /** 82 * @param SiteOptions $siteOption 42 83 * @return SiteOptions 43 84 * @throws \Exception … … 47 88 list($privateKey, $publicKey) = self::generateNewPrivatePublicKeys(); 48 89 49 $siteOption->setValue('public_key', base64_encode($publicKey));50 $siteOption->setValue('private_key', base64_encode($privateKey));51 $siteOption->setValue('site_url', site_url());52 $siteOption->setValue('uniqueId', time() . "." .str_replace(['https://','http://','/'],'', site_url()));90 $siteOption->setValue('public_key', base64_encode($publicKey)); 91 $siteOption->setValue('private_key', base64_encode($privateKey)); 92 $siteOption->setValue('site_url', site_url()); 93 $siteOption->setValue('uniqueId', str_replace(['https://','http://','/'],'', site_url())); 53 94 54 95 //Register website … … 65 106 66 107 $url = self::API_URL . '/services/register'; 67 $response = ServerCall::post($url, $params, $statusCode, $plainResult);108 $response = ServerCall::post($url, ['body' => $params] , $statusCode, $plainResult); 68 109 69 110 if (!isset($response['validationCode'])) { … … 92 133 ]; 93 134 94 $result = ServerCall::post(self::API_URL . '/services/validate', $params, $statusCode, $plainResult);135 $result = ServerCall::post(self::API_URL . '/services/validate', ['body' => $params] , $statusCode, $plainResult); 95 136 if(empty($result) && !empty($plainResult) && $plainResult !== $expectedResult){ 96 137 throw new UnsAppException('Error while validating the website. '.ucfirst(strip_tags($plainResult)), UnsAppException::VALIDATION_ERROR); … … 132 173 133 174 $url = self::API_URL . '/tickets/request'; 134 $response = ServerCall::post($url, $params, $statusCode, $plainTextResult);175 $response = ServerCall::post($url, ['body' => $params], $statusCode, $plainTextResult); 135 176 136 177 if (!isset($response['authenticationTicket'])) { -
unsproject/trunk/unsproject.php
r2412699 r2439247 8 8 Text Domain: uns-project 9 9 Domain Path: /i18n 10 Version: 1. 010 Version: 1.1.0 11 11 */ 12 12 … … 49 49 50 50 if (isset($_REQUEST['clear'])) { 51 delete_site_option(SiteOptions::OPTION_NAME_CREDENTIALS); 52 $databaseService = new DatabaseService(); 53 $databaseService->truncateTable(DatabaseService::TABLE_USERS); 54 $databaseService->truncateTable(DatabaseService::TABLE_URLS); 55 $databaseService->truncateTable(DatabaseService::TABLE_TICKETS); 56 $siteOptions->resetAll(); 51 try { 52 UnsApp::deleteService($siteOptions); 53 delete_site_option(SiteOptions::OPTION_NAME_CREDENTIALS); 54 $databaseService = new DatabaseService(); 55 $databaseService->truncateTable(DatabaseService::TABLE_USERS); 56 $databaseService->truncateTable(DatabaseService::TABLE_URLS); 57 $databaseService->truncateTable(DatabaseService::TABLE_TICKETS); 58 $siteOptions->resetAll(); 59 }catch (\Exception $e){ 60 View::load('error.php', [ 61 'message' => $e->getMessage(). $e->getFile(). ':'. $e->getLine() 62 ]); 63 } 57 64 } 58 65
Note: See TracChangeset
for help on using the changeset viewer.