├── .gitignore ├── CODEOWNERS ├── LICENSE ├── README.md ├── composer.json ├── lib └── Nitrapi │ ├── Admin │ ├── Admin.php │ └── Servers │ │ ├── Ipmi │ │ └── Ipmi.php │ │ └── ServerManager.php │ ├── Common │ ├── Exceptions │ │ ├── NitrapiConcurrencyException.php │ │ ├── NitrapiErrorException.php │ │ ├── NitrapiException.php │ │ ├── NitrapiHttpErrorException.php │ │ ├── NitrapiMaintenanceException.php │ │ ├── NitrapiPaymentException.php │ │ ├── NitrapiRateLimitException.php │ │ ├── NitrapiServiceNotActiveException.php │ │ └── NitrapiServiceTypeNotFoundException.php │ ├── Http │ │ └── Client.php │ └── NitrapiObject.php │ ├── Customer │ ├── AccessToken.php │ ├── Customer.php │ ├── Phone.php │ ├── Registration.php │ ├── ThirdPartyLogin.php │ └── TwoFactor.php │ ├── Domain │ ├── Domain.php │ ├── DomainManager.php │ ├── Handle.php │ ├── HandleManager.php │ ├── Record.php │ ├── Redirect.php │ └── Zone.php │ ├── DynamicShare │ └── DynamicShare.php │ ├── GameInfo │ ├── GameInfo.php │ └── GameInfoInterface.php │ ├── Geo │ └── CountryManager.php │ ├── Nitrapi.php │ ├── OAuth │ ├── Client.php │ └── OAuth.php │ ├── Order │ └── Pricing │ │ ├── DimensionPricing.php │ │ ├── Location.php │ │ ├── PartPricing.php │ │ ├── Pricing.php │ │ ├── PricingException.php │ │ ├── PricingInterface.php │ │ └── Products │ │ ├── Bouncer.php │ │ ├── CloudServer.php │ │ ├── CloudServerDynamic.php │ │ ├── Gameserver.php │ │ ├── Mumble.php │ │ ├── Musicbot.php │ │ ├── Teamspeak3.php │ │ ├── Ventrilo.php │ │ └── Webspace.php │ ├── SSHKeys │ ├── Manager.php │ └── SSHKey.php │ ├── Services │ ├── Bouncers │ │ ├── Bouncer.php │ │ ├── BouncerDetails.php │ │ └── Ident.php │ ├── Clanpages │ │ └── Clanpage.php │ ├── CloudServers │ │ ├── Apps │ │ │ ├── App.php │ │ │ ├── AppDescription.php │ │ │ └── AppManager.php │ │ ├── Backup │ │ │ ├── Backup.php │ │ │ └── BackupManager.php │ │ ├── CloudServer.php │ │ ├── CloudServerDetails.php │ │ ├── FileServer │ │ │ └── FileServer.php │ │ ├── Firewall │ │ │ └── Firewall.php │ │ ├── Image.php │ │ └── System │ │ │ ├── Systemd.php │ │ │ └── Unit.php │ ├── Gameservers │ │ ├── Adminlist.php │ │ ├── ApplicationServer │ │ │ └── ApplicationServer.php │ │ ├── BackupManager.php │ │ ├── Banlist.php │ │ ├── CallbackHandler.php │ │ ├── CurseforgeWorkshop.php │ │ ├── CustomerSettings │ │ │ ├── CustomerSettingNotFoundException.php │ │ │ └── CustomerSettings.php │ │ ├── FileServer │ │ │ └── FileServer.php │ │ ├── Games │ │ │ ├── Arkse.php │ │ │ ├── Corekeeper.php │ │ │ ├── Game.php │ │ │ ├── Minecraft.php │ │ │ ├── TS3Musicbot.php │ │ │ └── Valheim.php │ │ ├── Gameserver.php │ │ ├── GameserverDetails.php │ │ ├── GameserverFeatures.php │ │ ├── LicenseKeys │ │ │ ├── LicenseKey.php │ │ │ └── LicenseKeyFactory.php │ │ ├── MariaDBs │ │ │ ├── MariaDB.php │ │ │ └── MariaDBFactory.php │ │ ├── Packages │ │ │ ├── Package.php │ │ │ └── PackageManager.php │ │ ├── Player.php │ │ └── Whitelist.php │ ├── Rootservers │ │ └── Rootserver.php │ ├── Service.php │ ├── ServiceCollection.php │ ├── ServiceFactory.php │ ├── ServiceItem.php │ ├── Storages │ │ └── Storage.php │ ├── SupportAuthorization.php │ ├── TaskManager │ │ ├── Task.php │ │ ├── TaskException.php │ │ └── TaskManager.php │ ├── Voiceservers │ │ ├── Types │ │ │ ├── Mumble.php │ │ │ ├── Teamspeak3.php │ │ │ └── Type.php │ │ ├── Voiceserver.php │ │ └── VoiceserverDetails.php │ └── Webspaces │ │ └── Webspace.php │ ├── Steam │ ├── Steam.php │ └── Workshop │ │ └── Workshop.php │ └── TopLevelDomain │ ├── TopLevelDomain.php │ └── TopLevelDomainManager.php ├── phpunit.xml └── test ├── NitrapiTestCase.php ├── bootstrap.php ├── fixtures ├── cloud_server.images.response ├── gameservers.logs.response ├── gameservers.response ├── ping.response ├── service3.response └── user.response └── tests ├── CloudServerTest.php ├── GameserverLogsTest.php ├── PingTest.php └── UserTest.php /.gitignore: -------------------------------------------------------------------------------- 1 | .idea/ 2 | *.iml 3 | vendor/ 4 | composer.phar 5 | composer.lock 6 | /examples/ 7 | .DS_Store -------------------------------------------------------------------------------- /CODEOWNERS: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2016 marbis GmbH 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Nitrapi-PHP 2 | =========== 3 | 4 | [![Latest Stable Version](https://poser.pugx.org/nitrado/nitrapi-php-lib/v/stable.png)](https://packagist.org/packages/nitrado/nitrapi-php-lib) 5 | [![Latest Unstable Version](https://poser.pugx.org/nitrado/nitrapi-php-lib/v/unstable.svg)](https://packagist.org/packages/nitrado/nitrapi-php-lib) 6 | [![Total Downloads](https://poser.pugx.org/nitrado/nitrapi-php-lib/downloads.png)](https://packagist.org/packages/nitrado/nitrapi-php-lib) 7 | 8 | Official PHP based SDK for the Nitrapi RESTful API. 9 | 10 | 11 | Recommends 12 | --------- 13 | 14 | * PHP 5.5 or higher 15 | * Composer 16 | 17 | 18 | Installation 19 | ------------ 20 | 21 | Edit the composer.json and execute composer.phar update 22 | ``` php 23 | { 24 | "require": { 25 | "nitrado/nitrapi-php-lib": "dev-master", 26 | } 27 | } 28 | ``` 29 | 30 | Example 31 | ------- 32 | 33 | ```php 34 | "); 40 | 41 | var_dump($api->getServices()); 42 | 43 | } catch(\Exception $e) { 44 | var_dump("API Error: " . $e->getMessage()); 45 | } 46 | ``` 47 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "nitrado/nitrapi-php-lib", 3 | "description": "PHP SDK for Nitrapi", 4 | "keywords": ["nitrapi", "nitrado", "marbis", "api"], 5 | "type": "library", 6 | "license": "MIT", 7 | "authors": [ 8 | { 9 | "name": "Alexander Birkner", 10 | "email": "alexander.birkner@marbis.net", 11 | "homepage" : "https://github.com/BirknerAlex" 12 | }, 13 | { 14 | "name": "Aaron Fischer", 15 | "email": "aaron.fischer@marbis.net", 16 | "homepage" : "https://github.com/f0086" 17 | } 18 | ], 19 | "autoload": { 20 | "psr-0": { 21 | "Nitrapi": ["lib/"] 22 | } 23 | }, 24 | "require": { 25 | "php" : ">=5.5", 26 | "ext-json": "*", 27 | "guzzlehttp/guzzle": "~6.0" 28 | }, 29 | "require-dev": { 30 | "phpunit/phpunit": "~5.0" 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /lib/Nitrapi/Admin/Admin.php: -------------------------------------------------------------------------------- 1 | $scopeString, 43 | 'user_id' => $userId 44 | ]; 45 | 46 | if (!empty($serviceId)) { 47 | $payload['service_id'] = $serviceId; 48 | } 49 | 50 | if (!empty($expires_in)) { 51 | $payload['expires_in'] = $expires_in; 52 | } 53 | 54 | return new AccessToken($this->getApi()->dataPost('token/sub', $payload)['token']); 55 | } 56 | } -------------------------------------------------------------------------------- /lib/Nitrapi/Admin/Servers/Ipmi/Ipmi.php: -------------------------------------------------------------------------------- 1 | setServerManager($serverManager); 13 | } 14 | 15 | /** 16 | * @return bool 17 | */ 18 | public function getIKVM($hostname) { 19 | return $this->getServerManager()->getAdmin()->getApi()->dataGet('/admin/server/ipmi/ikvm', null, [ 20 | 'query' => [ 21 | 'hostname' => $hostname 22 | ] 23 | ])['ipmi']; 24 | } 25 | 26 | public function doReset($hostname) { 27 | $this->getServerManager()->getAdmin()->getApi()->dataPost('/admin/server/ipmi/reset', [ 28 | 'hostname' => $hostname 29 | ]); 30 | return true; 31 | } 32 | 33 | public function doPowerOff($hostname) { 34 | $this->getServerManager()->getAdmin()->getApi()->dataPost('/admin/server/ipmi/power_off', [ 35 | 'hostname' => $hostname 36 | ]); 37 | return true; 38 | } 39 | 40 | public function doPowerOn($hostname) { 41 | $this->getServerManager()->getAdmin()->getApi()->dataPost('/admin/server/ipmi/power_on', [ 42 | 'hostname' => $hostname 43 | ]); 44 | return true; 45 | } 46 | 47 | public function doIKVMReset($hostname) { 48 | $this->getServerManager()->getAdmin()->getApi()->dataPost('/admin/server/ipmi/ikvm_reset', [ 49 | 'hostname' => $hostname 50 | ]); 51 | return true; 52 | } 53 | 54 | /** 55 | * @param ServerManager $serverManager 56 | */ 57 | protected function setServerManager(ServerManager $serverManager) { 58 | $this->serverManager = $serverManager; 59 | } 60 | 61 | /** 62 | * @return ServerManager 63 | */ 64 | public function getServerManager() { 65 | return $this->serverManager; 66 | } 67 | } -------------------------------------------------------------------------------- /lib/Nitrapi/Admin/Servers/ServerManager.php: -------------------------------------------------------------------------------- 1 | setAdmin($admin); 13 | } 14 | 15 | public function getIpmi() { 16 | return new Ipmi($this); 17 | } 18 | 19 | /** 20 | * @param Admin $admin 21 | */ 22 | protected function setAdmin(\Nitrapi\Admin\Admin $admin) { 23 | $this->admin = $admin; 24 | } 25 | 26 | /** 27 | * @return Admin 28 | */ 29 | public function getAdmin() { 30 | return $this->admin; 31 | } 32 | } -------------------------------------------------------------------------------- /lib/Nitrapi/Common/Exceptions/NitrapiConcurrencyException.php: -------------------------------------------------------------------------------- 1 | errorId; 18 | } 19 | 20 | public function setErrorId($errorId) { 21 | $this->errorId = $errorId; 22 | } 23 | 24 | /** 25 | * @return ResponseInterface|null 26 | */ 27 | public function getResponse() { 28 | return $this->response; 29 | } 30 | 31 | /** 32 | * @param ResponseInterface|null $response 33 | */ 34 | public function setResponse($response) { 35 | $this->response = $response; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /lib/Nitrapi/Common/Exceptions/NitrapiHttpErrorException.php: -------------------------------------------------------------------------------- 1 | rateLimit = $rateLimit; 25 | $this->resetTime = $resetTime; 26 | 27 | $resetTimeString = $resetTime->format('Y-m-d H:i:s'); 28 | parent::__construct("The rate limit ($rateLimit requests in one hour) is exceeded. You need to wait until $resetTimeString to make another request."); 29 | } 30 | 31 | public function getRateLimit() { 32 | return $this->rateLimit; 33 | } 34 | 35 | public function getResetTime() { 36 | return $this->resetTime; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /lib/Nitrapi/Common/Exceptions/NitrapiServiceNotActiveException.php: -------------------------------------------------------------------------------- 1 | setApi($api); 14 | } 15 | 16 | /** 17 | * @param Nitrapi $api 18 | */ 19 | public function setApi(Nitrapi $api) 20 | { 21 | $this->api = $api; 22 | } 23 | 24 | /** 25 | * @return Nitrapi 26 | */ 27 | public function getApi() 28 | { 29 | return $this->api; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /lib/Nitrapi/Customer/AccessToken.php: -------------------------------------------------------------------------------- 1 | token = $data['access_token']; 14 | 15 | $this->expiresAt = !empty($data['expires_at']) ? $data['expires_at'] : ($data['expires_in'] + time()); 16 | $this->tokenType = !empty($data['token_type']) ? $data['token_type'] : 'Bearer'; 17 | $this->scopes = isset($data['scopes']) ? $data['scopes'] : explode(' ', $data['scope']); 18 | 19 | if (!empty($data['refresh_token'])) { 20 | $this->refreshToken = $data['refresh_token']; 21 | } 22 | } 23 | 24 | public function getToken() { 25 | return $this->token; 26 | } 27 | 28 | public function getRefreshToken() { 29 | return $this->refreshToken; 30 | } 31 | 32 | public function getExpiresAt() { 33 | return $this->expiresAt; 34 | } 35 | 36 | public function getExpiresIn() { 37 | return $this->getExpiresAt() - time(); 38 | } 39 | 40 | public function getType() { 41 | return $this->tokenType; 42 | } 43 | 44 | public function getScopes() { 45 | return $this->scopes; 46 | } 47 | 48 | public function hasScope($scope) { 49 | return in_array($scope, $this->getScopes()); 50 | } 51 | } -------------------------------------------------------------------------------- /lib/Nitrapi/Customer/Customer.php: -------------------------------------------------------------------------------- 1 | data = $this->getApi()->dataGet("user")['user']; 18 | } 19 | 20 | /** 21 | * Returns the User ID. 22 | * 23 | * @return string 24 | */ 25 | public function getUserId() 26 | { 27 | return $this->data['user_id']; 28 | } 29 | 30 | /** 31 | * Returns the Username. 32 | * 33 | * @return string username 34 | */ 35 | public function getUsername() 36 | { 37 | return $this->data['username']; 38 | } 39 | 40 | /** 41 | * Returns true if the User is already activated. 42 | * 43 | * @return bool 44 | */ 45 | public function isActivated() 46 | { 47 | return $this->data['activated']; 48 | } 49 | 50 | /** 51 | * Return the User Timezone. 52 | * 53 | * @return string 54 | */ 55 | public function getTimezone() 56 | { 57 | return $this->data['timezone']; 58 | } 59 | 60 | /** 61 | * Updates the User Timezone. 62 | * 63 | * @param $updateToken 64 | * @param $newTimezone 65 | * @return bool 66 | */ 67 | public function setTimezone($updateToken, $newTimezone) 68 | { 69 | $this->getApi()->dataPost('user', [ 70 | 'timezone' => $newTimezone, 71 | 'token' => $updateToken 72 | ]); 73 | $this->data['timezone'] = $newTimezone; 74 | return true; 75 | } 76 | 77 | /** 78 | * Returns email address of the user. 79 | * 80 | * @return string 81 | */ 82 | public function getEmail() 83 | { 84 | return $this->data['email']; 85 | } 86 | 87 | /** 88 | * Returns credit. 89 | * 90 | * @return int 91 | */ 92 | public function getCredit() 93 | { 94 | return $this->data['credit']; 95 | } 96 | 97 | /** 98 | * Returns the currency. 99 | * 100 | * @return string 101 | */ 102 | public function getCurrency() 103 | { 104 | return $this->data['currency']; 105 | } 106 | 107 | /** 108 | * Return the Registration Date. 109 | * 110 | * @return \DateTime 111 | */ 112 | public function getRegistrationDate() 113 | { 114 | return (new \DateTime())->setTimestamp(strtotime($this->data['registered'])); 115 | } 116 | 117 | /** 118 | * Return the User language as 3 digit ISO code. 119 | * 120 | * @return string 121 | */ 122 | public function getLanguage() 123 | { 124 | return $this->data['language']; 125 | } 126 | 127 | /** 128 | * Returns the Avatar URL if available. 129 | * 130 | * @return string|null 131 | */ 132 | public function getAvatar() 133 | { 134 | return $this->data['avatar']; 135 | } 136 | 137 | /** 138 | * Returns true if Donations are enabled. 139 | * 140 | * @return bool 141 | */ 142 | public function hasDonationsEnabled() 143 | { 144 | return $this->data['donations']; 145 | } 146 | 147 | /** 148 | * Returns the User Phone censored Number and Status 149 | * 150 | * @return array 151 | */ 152 | public function getPhone() { 153 | return $this->data['phone']; 154 | } 155 | 156 | /** 157 | * Returns a array with the enabled Two Factor Methods. 158 | * 159 | * @return array 160 | */ 161 | public function getTwoFactorMethods() { 162 | return $this->data['two_factor']; 163 | } 164 | 165 | /** 166 | * A user can have various permissions associated to it. This can be used to 167 | * limit functionality on the UI or add additional features if the user has 168 | * a certain permission. The permission reflect also the capability of the 169 | * API endpoints. If the user do not have the permission to order domains, the 170 | * order domains endpoint results in an error. The list of all possible 171 | * permissions can be changed over time, so there exist no final list of them. 172 | * 173 | * @return array The permissions associated to the user 174 | */ 175 | public function getPermissions() { 176 | return $this->data['permissions']; 177 | } 178 | 179 | /** 180 | * Check if the user has the given permission. The permission is a string 181 | * (all uppercase). 182 | * 183 | * @see Customer::getPermissions() 184 | * 185 | * @param $permission 186 | * @return bool 187 | */ 188 | public function hasPermission($permission) { 189 | return in_array($permission, $this->getPermissions(), true); 190 | } 191 | 192 | /** 193 | * @deprecated 194 | */ 195 | public function getPersonalData() 196 | { 197 | return $this->getProfile(); 198 | } 199 | 200 | /** 201 | * Returns the Customer profile information. 202 | * 203 | * @return array 204 | */ 205 | public function getProfile() { 206 | return $this->data['profile']; 207 | } 208 | 209 | /** 210 | * Update the Customer profile information. 211 | * 212 | * @param $updateToken 213 | * @param array $profile 214 | * @return bool 215 | */ 216 | public function updateProfile($updateToken, array $profile) { 217 | $data = []; 218 | $data['token'] = $updateToken; 219 | $data['profile'] = $profile; 220 | 221 | $this->getApi()->dataPost('user', $data); 222 | return true; 223 | } 224 | 225 | /** 226 | * Returns an update token for this user. 227 | * 228 | * @param $password 229 | * @return array|bool 230 | */ 231 | public function getUpdateToken($password) 232 | { 233 | return $this->getApi()->dataPost('user/token', [ 234 | 'password' => $password 235 | ]); 236 | } 237 | 238 | /** 239 | * Updates the user password. 240 | * 241 | * @param $updateToken 242 | * @param $newPassword 243 | * @return bool 244 | */ 245 | public function changePassword($updateToken, $newPassword) 246 | { 247 | $this->getApi()->dataPost('user', [ 248 | 'password' => $newPassword, 249 | 'token' => $updateToken 250 | ]); 251 | return true; 252 | } 253 | 254 | /** 255 | * Updates the user donation setting. 256 | * 257 | * @param $updateToken 258 | * @param $newState 259 | * @return bool 260 | */ 261 | public function setDonations($updateToken, $newState = true) 262 | { 263 | $this->getApi()->dataPost('user', [ 264 | 'donations' => (($newState) ? 'true' : 'false'), 265 | 'token' => $updateToken 266 | ]); 267 | $this->data['donations'] = $newState; 268 | return true; 269 | } 270 | 271 | /** 272 | * Requests a sub token for this user. This can be used to drop scopes on the token. 273 | * 274 | * @param array|string $scopes The scopes for the new token. Can only contain scopes of the current token. 275 | * May be passed in as array or space separated string. 276 | * @param null|integer $serviceId A serviceID to pin the token to. It won't be possible to access other services with this 277 | * token. Passing null allows all services to be accessed. 278 | * @param null|integer $expires_in The time in seconds the new token will be valid for. The life time of a sub token 279 | * can never exceed the life time of the parent token. Pass in null for taking the parent token's life time. 280 | * 281 | * @return AccessToken 282 | */ 283 | public function getSubToken($scopes, $serviceId = null, $expires_in = null) { 284 | $scopeString = $scopes; 285 | if (is_array($scopes)) { 286 | $scopeString = implode(' ', $scopes); 287 | } 288 | 289 | $payload = [ 290 | 'scope' => $scopeString 291 | ]; 292 | 293 | if (!empty($serviceId)) { 294 | $payload['service_id'] = $serviceId; 295 | } 296 | 297 | if (!empty($expires_in)) { 298 | $payload['expires_in'] = $expires_in; 299 | } 300 | 301 | return new AccessToken($this->getApi()->dataPost('token/sub', $payload)['token']); 302 | } 303 | 304 | /** 305 | * Return the User's rate limit for the Nitrado API 306 | * 307 | * @return int 308 | */ 309 | public function getRateLimit() 310 | { 311 | return isset($this->data['rate_limit']) ? $this->data['rate_limit'] : 15000; 312 | } 313 | 314 | /** 315 | * Get the subscribed and active newsletter campaigns 316 | * 317 | * @return array 318 | */ 319 | public function getNewsletterCampaigns() 320 | { 321 | if(isset($this->data['newsletter_campaigns'])){ 322 | return $this->data['newsletter_campaigns']; 323 | } 324 | return []; 325 | } 326 | 327 | /** 328 | * Subscribe to newsletter campaign 329 | * 330 | * @param int $newsletterCampaignId 331 | * @return true 332 | */ 333 | public function subscribeToNewsletterCampaign($newsletterCampaignId) 334 | { 335 | $this->getApi()->dataPost('user/newsletter_campaign/'.$newsletterCampaignId.'/subscribe'); 336 | return true; 337 | } 338 | 339 | /** 340 | * Unsubscribe from newsletter campaign 341 | * 342 | * @param int $newsletterCampaignId 343 | * @return true 344 | */ 345 | public function unsubscribeFromNewsletterCampaign($newsletterCampaignId) 346 | { 347 | $this->getApi()->dataPut('user/newsletter_campaign/'.$newsletterCampaignId.'/unsubscribe'); 348 | return true; 349 | } 350 | } 351 | -------------------------------------------------------------------------------- /lib/Nitrapi/Customer/Phone.php: -------------------------------------------------------------------------------- 1 | api = $api; 15 | } 16 | 17 | /** 18 | * Adds a mobile phone number to the user profile. 19 | * 20 | * Important: Number including country code. 21 | * 22 | * @param $updateToken 23 | * @param $number 24 | * @return bool 25 | */ 26 | public function addNumber($updateToken, $number) { 27 | $this->api->dataPost("user/phone", [ 28 | 'token' => $updateToken, 29 | 'number' => $number 30 | ]); 31 | return true; 32 | } 33 | 34 | /** 35 | * Verifies the new number, code will be sent via SMS. 36 | * 37 | * @param $code 38 | * @return bool 39 | */ 40 | public function verifyNumber($code) { 41 | $this->api->dataPost("user/phone/verify", [ 42 | 'code' => $code 43 | ]); 44 | return true; 45 | } 46 | 47 | /** 48 | * Deletes the number. 49 | * 50 | * @param $updateToken 51 | * @return bool 52 | */ 53 | public function deleteNumber($updateToken) { 54 | $this->api->dataDelete("user/phone", [ 55 | 'token' => $updateToken 56 | ]); 57 | return true; 58 | } 59 | 60 | } -------------------------------------------------------------------------------- /lib/Nitrapi/Customer/Registration.php: -------------------------------------------------------------------------------- 1 | api = $api; 27 | $parameters = [ 28 | "client_id" => $oAuthClientId, 29 | "client_secret" => $oAuthClientSecret, 30 | "username" => $userName, 31 | "email" => $email, 32 | "password" => $password, 33 | "consent_privacy" => $consentPrivacy, 34 | "consent_age" => $consentAge, 35 | "consent_tos" => $consentTos, 36 | "consent_newsletter" => $consentNewsletter 37 | ]; 38 | 39 | if (!empty($recaptchaResponse)) { 40 | $parameters["recaptcha"] = $recaptchaResponse; 41 | } 42 | 43 | if (!empty($currency)) { 44 | $parameters["currency"] = $currency; 45 | } 46 | 47 | if (!empty($language)) { 48 | $parameters["language"] = $language; 49 | } 50 | 51 | if (!empty($timezone)) { 52 | $parameters["timezone"] = $timezone; 53 | } 54 | 55 | $this->data = $this->api->dataPost("registration", $parameters); 56 | } 57 | 58 | public static function getRecaptchaSiteKey(Nitrapi $api) { 59 | $data = $api->dataGet("registration"); 60 | if (empty($data["registration"]["google_recaptcha"]["enabled"])) { 61 | return false; 62 | } 63 | 64 | return $data["registration"]["google_recaptcha"]["key"]; 65 | } 66 | 67 | public function getUserId() { 68 | return $this->data["registration"]["user"]["id"]; 69 | } 70 | 71 | public function getAccessToken() { 72 | return $this->data["registration"]["oauth"]["access_token"]; 73 | } 74 | 75 | public function getRefreshToken() { 76 | return $this->data["registration"]["oauth"]["refresh_token"]; 77 | } 78 | 79 | public function getTokenExpiration() { 80 | return $this->data["registration"]["oauth"]["expires_in"]; 81 | } 82 | 83 | public function getTokenScope() { 84 | return $this->data["registration"]["oauth"]["scope"]; 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /lib/Nitrapi/Customer/ThirdPartyLogin.php: -------------------------------------------------------------------------------- 1 | api = $api; 15 | } 16 | 17 | /** 18 | * List all connected 3rd Party accounts. 19 | * 20 | * @return mixed 21 | */ 22 | public function getList() { 23 | return $this->api->dataGet("/user/third_party")['connections']; 24 | } 25 | 26 | /** 27 | * Add a Google Account. 28 | * This method returns a URL, you need to redirect the User to this URL. 29 | * 30 | * @param $updateToken 31 | * @param $redirectUrl 32 | * @return string 33 | */ 34 | public function addGoogle($updateToken, $redirectUrl) { 35 | return $this->api->dataPost("/user/third_party/google", [ 36 | 'token' => $updateToken, 37 | 'redirect_url' => $redirectUrl, 38 | ])['url']; 39 | } 40 | 41 | /** 42 | * Add a Facebook Account. 43 | * This method returns a URL, you need to redirect the User to this URL. 44 | * 45 | * @param $updateToken 46 | * @param $redirectUrl 47 | * @return string 48 | */ 49 | public function addFacebook($updateToken, $redirectUrl) { 50 | return $this->api->dataPost("/user/third_party/facebook", [ 51 | 'token' => $updateToken, 52 | 'redirect_url' => $redirectUrl, 53 | ])['url']; 54 | } 55 | 56 | /** 57 | * Add a Twitch Account. 58 | * This method returns a URL, you need to redirect the User to this URL. 59 | * 60 | * @param $updateToken 61 | * @param $redirectUrl 62 | * @return string 63 | */ 64 | public function addTwitch($updateToken, $redirectUrl) { 65 | return $this->api->dataPost("/user/third_party/twitch", [ 66 | 'token' => $updateToken, 67 | 'redirect_url' => $redirectUrl, 68 | ])['url']; 69 | } 70 | 71 | /** 72 | * Add a Github Account. 73 | * This method returns a URL, you need to redirect the User to this URL. 74 | * 75 | * @param $updateToken 76 | * @param $redirectUrl 77 | * @return string 78 | */ 79 | public function addGithub($updateToken, $redirectUrl) { 80 | return $this->api->dataPost("/user/third_party/github", [ 81 | 'token' => $updateToken, 82 | 'redirect_url' => $redirectUrl, 83 | ])['url']; 84 | } 85 | 86 | /** 87 | * Add a Microsoft Account. 88 | * This method returns a URL, you need to redirect the User to this URL. 89 | * 90 | * @param $updateToken 91 | * @param $redirectUrl 92 | * @return string 93 | */ 94 | public function addMicrosoft($updateToken, $redirectUrl) { 95 | return $this->api->dataPost("/user/third_party/microsoft", [ 96 | 'token' => $updateToken, 97 | 'redirect_url' => $redirectUrl, 98 | ])['url']; 99 | } 100 | 101 | /** 102 | * Deletes a existing Google connection. 103 | * 104 | * @param $updateToken 105 | * @return bool 106 | */ 107 | public function deleteGoogle($updateToken) { 108 | return $this->api->dataDelete("/user/third_party/google", [ 109 | 'token' => $updateToken 110 | ]); 111 | } 112 | 113 | /** 114 | * Deletes a existing Facebook connection. 115 | * 116 | * @param $updateToken 117 | * @return bool 118 | */ 119 | public function deleteFacebook($updateToken) { 120 | return $this->api->dataDelete("/user/third_party/facebook", [ 121 | 'token' => $updateToken 122 | ]); 123 | } 124 | 125 | /** 126 | * Deletes a existing Twitch connection. 127 | * 128 | * @param $updateToken 129 | * @return bool 130 | */ 131 | public function deleteTwitch($updateToken) { 132 | return $this->api->dataDelete("/user/third_party/twitch", [ 133 | 'token' => $updateToken 134 | ]); 135 | } 136 | 137 | /** 138 | * Deletes a existing Github connection. 139 | * 140 | * @param $updateToken 141 | * @return bool 142 | */ 143 | public function deleteGithub($updateToken) { 144 | return $this->api->dataDelete("/user/third_party/github", [ 145 | 'token' => $updateToken 146 | ]); 147 | } 148 | 149 | /** 150 | * Deletes a existing Microsoft connection. 151 | * 152 | * @param $updateToken 153 | * @return bool 154 | */ 155 | public function deleteMicrosoft($updateToken) { 156 | return $this->api->dataDelete("/user/third_party/microsoft", [ 157 | 'token' => $updateToken 158 | ]); 159 | } 160 | 161 | } -------------------------------------------------------------------------------- /lib/Nitrapi/Customer/TwoFactor.php: -------------------------------------------------------------------------------- 1 | api = $api; 15 | } 16 | 17 | /** 18 | * Current Google Authenticator Information 19 | * Also contains Information to add new Phone. 20 | * 21 | * @param $updateToken 22 | * @return array 23 | */ 24 | public function getGoogleAuthenticator($updateToken) { 25 | return $this->api->dataGet("user/two_factor/google", null, [ 26 | 'query' => [ 27 | 'token' => $updateToken 28 | ] 29 | ])['google']; 30 | } 31 | 32 | /** 33 | * Adds the a Google Authenticator Device. 34 | * 35 | * @param $updateToken 36 | * @param string $sessionIdToIgnore 37 | * @param $code 38 | * @return string 39 | */ 40 | public function addGoogleAuthenticator($updateToken, $code, $sessionIdToIgnore = NULL) { 41 | return $this->api->dataPost("user/two_factor/google", [ 42 | 'token' => $updateToken, 43 | 'code' => $code, 44 | 'session_id_to_ignore' => $sessionIdToIgnore 45 | ]); 46 | } 47 | 48 | /** 49 | * Deletes the current Google Authenticator Device 50 | * 51 | * @param $updateToken 52 | * @return string 53 | */ 54 | public function deleteGoogleAuthenticator($updateToken) { 55 | return $this->api->dataDelete("user/two_factor/google", [ 56 | 'token' => $updateToken 57 | ]); 58 | } 59 | 60 | /** 61 | * Current U2F Information 62 | * Also contains Information to add new U2F Token. 63 | * 64 | * @param $updateToken 65 | * @return array 66 | */ 67 | public function getU2F($updateToken) { 68 | return $this->api->dataGet("user/two_factor/u2f", null, [ 69 | 'query' => [ 70 | 'token' => $updateToken 71 | ] 72 | ])['u2f']; 73 | } 74 | 75 | /** 76 | * Adds a new U2F Token 77 | * 78 | * @param $updateToken 79 | * @param $response 80 | * @param string $sessionIdToIgnore add a session id that will not be terminated 81 | * @return string 82 | */ 83 | public function addU2F($updateToken, $response, $sessionIdToIgnore = NULL) { 84 | return $this->api->dataPost("user/two_factor/u2f", [ 85 | 'token' => $updateToken, 86 | 'response' => $response, 87 | 'session_id_to_ignore' => $sessionIdToIgnore 88 | ]); 89 | } 90 | 91 | /** 92 | * Deletes a specific U2F Token 93 | * 94 | * @param $updateToken 95 | * @param $key 96 | * @return string 97 | */ 98 | public function deleteU2F($updateToken, $key) { 99 | return $this->api->dataDelete("user/two_factor/u2f", [ 100 | 'token' => $updateToken, 101 | 'key' => $key 102 | ]); 103 | } 104 | 105 | } 106 | -------------------------------------------------------------------------------- /lib/Nitrapi/Domain/DomainManager.php: -------------------------------------------------------------------------------- 1 | api = $api; 18 | } 19 | 20 | /** 21 | * Returns an array with all available top-level domains and prices. 22 | * 23 | * @return array 24 | */ 25 | public function getPricing() 26 | { 27 | return $this->api->dataGet('/domain/pricing'); 28 | } 29 | 30 | /** 31 | * Returns a list with all active domains. 32 | * 33 | * @return Domain[] 34 | */ 35 | public function getDomains() 36 | { 37 | $domains = []; 38 | 39 | foreach ($this->api->dataGet('/domain')['domains'] as $domain) { 40 | $domains[] = new Domain($this->api, $domain); 41 | } 42 | 43 | return $domains; 44 | } 45 | 46 | /** 47 | * Returns a single Domain object by domain or ID. 48 | * 49 | * @param mixed $domain 50 | * @return Domain 51 | */ 52 | public function getDomain($domain) 53 | { 54 | foreach ($this->api->dataGet('/domain')['domains'] as $_domain) { 55 | if ($domain === $_domain['domain'] || (preg_match("@^[0-9]+$@", $domain) && $_domain['id'] === (int)$domain)) { 56 | return new Domain($this->api, $_domain); 57 | } 58 | } 59 | 60 | throw new NitrapiException("Domain " . $domain . " can't be found"); 61 | } 62 | 63 | /** 64 | * Registers a new Domain on your account. 65 | * 66 | * @param Domain $domain 67 | * @param Handle $handle 68 | * @param null $authCode 69 | * @return string 70 | */ 71 | public function registerDomain(Domain $domain, Handle $handle, $authCode = null) 72 | { 73 | $data = [ 74 | 'owner_c' => $handle->getHandle(), 75 | 'admin_c' => $handle->getHandle(), 76 | ]; 77 | 78 | if (!empty($authCode)) { 79 | $data['auth_code'] = $authCode; 80 | } 81 | 82 | return $this->api->dataPost('/domain/' . $domain->getDomain() . '/order', $data); 83 | } 84 | 85 | } 86 | -------------------------------------------------------------------------------- /lib/Nitrapi/Domain/Handle.php: -------------------------------------------------------------------------------- 1 | setData($data); 24 | } 25 | 26 | public function setData($data) 27 | { 28 | if (count($data) > 0) { 29 | $this->data = $data; 30 | } 31 | 32 | return $this; 33 | } 34 | 35 | public function getHandle() 36 | { 37 | if (!empty($this->data['handle'])) { 38 | return $this->data['handle']; 39 | } 40 | 41 | return null; 42 | } 43 | 44 | public function getDomainList() 45 | { 46 | return $this->getApi()->dataGet('/domain/contact/' . $this->getHandle() . '/domains')['domains']; 47 | } 48 | 49 | public function setOrganization($organization) 50 | { 51 | return $this->data['organization'] = $organization; 52 | } 53 | 54 | public function getOrganization() 55 | { 56 | if (!empty($this->data['organization'])) { 57 | return $this->data['organization']; 58 | } 59 | 60 | return null; 61 | } 62 | 63 | public function setFirstName($firstName) 64 | { 65 | $this->data['first_name'] = $firstName; 66 | return $this; 67 | } 68 | 69 | public function getFirstName() 70 | { 71 | return $this->data['first_name']; 72 | } 73 | 74 | public function setLastName($lastName) 75 | { 76 | $this->data['last_name'] = $lastName; 77 | return $this; 78 | } 79 | 80 | public function getLastName() 81 | { 82 | return $this->data['last_name']; 83 | } 84 | 85 | public function setEMail($email) 86 | { 87 | $this->data['email'] = $email; 88 | return $this; 89 | } 90 | 91 | public function getEMail() 92 | { 93 | return $this->data['email']; 94 | } 95 | 96 | public function setPhone($phone) 97 | { 98 | $this->data['phone'] = $phone; 99 | return $this; 100 | } 101 | 102 | public function getPhone() 103 | { 104 | return $this->data['phone']; 105 | } 106 | 107 | public function setFax($fax) 108 | { 109 | $this->data['fax'] = $fax; 110 | return $this; 111 | } 112 | 113 | public function getFax() 114 | { 115 | if (!empty($this->data['fax'])) { 116 | return $this->data['fax']; 117 | } 118 | 119 | return null; 120 | } 121 | 122 | public function setStreet($street) 123 | { 124 | $this->data['street'] = $street; 125 | return $this; 126 | } 127 | 128 | public function getStreet() 129 | { 130 | return $this->data['street']; 131 | } 132 | 133 | public function setPostCode($postCode) 134 | { 135 | $this->data['postcode'] = $postCode; 136 | return $this; 137 | } 138 | 139 | public function getPostCode() 140 | { 141 | return $this->data['postcode']; 142 | } 143 | 144 | public function setCity($city) 145 | { 146 | $this->data['city'] = $city; 147 | return $this; 148 | } 149 | 150 | public function getCity() 151 | { 152 | return $this->data['city']; 153 | } 154 | 155 | public function setState($state) 156 | { 157 | $this->data['state'] = $state; 158 | return $this; 159 | } 160 | 161 | public function getState() 162 | { 163 | return $this->data['state']; 164 | } 165 | 166 | public function setCountry($country) 167 | { 168 | $this->data['country'] = $country; 169 | return $this; 170 | } 171 | 172 | public function getCountry() 173 | { 174 | return $this->data['country']; 175 | } 176 | 177 | public function save() 178 | { 179 | $request = [ 180 | 'contact' => [ 181 | 'organization' => $this->getOrganization(), 182 | 'first_name' => $this->getFirstName(), 183 | 'last_name' => $this->getLastName(), 184 | 'email' => $this->getEMail(), 185 | 'phone' => $this->getPhone(), 186 | 'fax' => $this->getFax(), 187 | 'street' => $this->getStreet(), 188 | 'postcode' => $this->getPostCode(), 189 | 'city' => $this->getCity(), 190 | 'state' => $this->getState(), 191 | 'country' => $this->getCountry() 192 | ] 193 | ]; 194 | 195 | // New handle 196 | if ($this->getHandle() === null) { 197 | return $this->getApi()->dataPost('/domain/contact', $request); 198 | } 199 | 200 | //Update 201 | return $this->getApi()->dataPut('/domain/contact/' . $this->getHandle(), $request); 202 | } 203 | 204 | public function delete() 205 | { 206 | return $this->getApi()->dataDelete('/domain/contact/' . $this->getHandle()); 207 | } 208 | 209 | } 210 | -------------------------------------------------------------------------------- /lib/Nitrapi/Domain/HandleManager.php: -------------------------------------------------------------------------------- 1 | api = $api; 21 | } 22 | 23 | /** 24 | * Returns a array with all handles for your user. 25 | * 26 | * @return Handle[] 27 | */ 28 | public function getHandles() { 29 | $handles = []; 30 | 31 | foreach ($this->api->dataGet('/domain/contact')['contacts'] as $contact) { 32 | $handles[] = new Handle($this->api, $contact); 33 | } 34 | 35 | return $handles; 36 | } 37 | 38 | /** 39 | * Returns a single handle object. 40 | * 41 | * @param $handle 42 | * @return Handle 43 | */ 44 | public function getHandle($handle) { 45 | foreach ($this->api->dataGet('/domain/contact')['contacts'] as $contact) { 46 | if ($contact['handle'] === $handle) { 47 | return new Handle($this->api, $contact); 48 | } 49 | } 50 | 51 | throw new NitrapiException("Handle " . $handle . " can't be found"); 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /lib/Nitrapi/Domain/Record.php: -------------------------------------------------------------------------------- 1 | setData($data); 31 | $this->setFqdn($fqdn); 32 | } 33 | 34 | /** 35 | * Sets data field $data to specified value. 36 | * 37 | * @param $data 38 | * @return $this 39 | */ 40 | public function setData($data) 41 | { 42 | if (count($data) > 0) { 43 | $this->data = $data; 44 | } 45 | 46 | return $this; 47 | } 48 | 49 | /** 50 | * Sets fqdn field $fqdn to specified value. 51 | * 52 | * @param $fqdn 53 | * @return $this 54 | */ 55 | public function setFqdn($fqdn) 56 | { 57 | $this->fqdn = $fqdn; 58 | 59 | return $this; 60 | } 61 | 62 | /** 63 | * Returns if the record is set by the customer 64 | * 65 | * @return bool 66 | */ 67 | public function setByUser() 68 | { 69 | return $this->data['mode'] == "manual"; 70 | } 71 | 72 | /** 73 | * Changes the record 74 | * 75 | * @param string $name 76 | * @param string $type 77 | * @param string $content 78 | * @param int $ttl 79 | * @return mixed 80 | */ 81 | public function update($name, $type, $content, $ttl) 82 | { 83 | $data = [ 84 | "name_old" => $this->getName(), 85 | "type_old" => $this->getType(), 86 | "content_old" => $this->getContent(), 87 | "ttl" => $ttl, 88 | "name" => $name, 89 | "content" => $content, 90 | "type" => $type 91 | ]; 92 | return $this->getApi()->dataPut("/domain/" . $this->fqdn . "/records", $data); 93 | } 94 | 95 | /** 96 | * Return the record name 97 | * 98 | * @return string 99 | */ 100 | public function getName() 101 | { 102 | return $this->data['name']; 103 | } 104 | 105 | /** 106 | * Return the record Type 107 | * 108 | * @return string 109 | */ 110 | public function getType() 111 | { 112 | return $this->data['type']; 113 | } 114 | 115 | /** 116 | * Return the record Content 117 | * 118 | * @return string 119 | */ 120 | public function getContent() 121 | { 122 | return $this->data['content']; 123 | } 124 | 125 | /** 126 | * Deletes the record 127 | * 128 | * @return bool 129 | */ 130 | public function delete() 131 | { 132 | $data = [ 133 | "name" => $this->getName(), 134 | "type" => $this->getType(), 135 | "content" => $this->getContent() 136 | ]; 137 | return $this->getApi()->dataDelete("/domain/" . $this->fqdn . "/records", $data); 138 | } 139 | 140 | 141 | } 142 | -------------------------------------------------------------------------------- /lib/Nitrapi/Domain/Redirect.php: -------------------------------------------------------------------------------- 1 | setData($data); 31 | $this->setFqdn($fqdn); 32 | } 33 | 34 | /** 35 | * Sets fqdn field $fqdn to specified value. 36 | * 37 | * @param $fqdn 38 | * @return $this 39 | */ 40 | public function setFqdn($fqdn) 41 | { 42 | $this->fqdn = $fqdn; 43 | 44 | return $this; 45 | } 46 | 47 | /** 48 | * Sets data field $data to specified value. 49 | * 50 | * @param array $data 51 | * @return $this 52 | */ 53 | public function setData($data) 54 | { 55 | if (count($data) > 0) { 56 | $this->data = $data; 57 | } 58 | 59 | return $this; 60 | } 61 | 62 | /** 63 | * Get the redirect type 64 | * 65 | * @return string 66 | */ 67 | public function getType() 68 | { 69 | return $this->data['type']; 70 | } 71 | 72 | /** 73 | * Get the redirect id 74 | * 75 | * @return int 76 | */ 77 | public function getId() 78 | { 79 | return (int) $this->data['id']; 80 | } 81 | 82 | /** 83 | * Get the redirect sld 84 | * 85 | * @return string 86 | */ 87 | public function getSld() 88 | { 89 | return $this->data['type']; 90 | } 91 | 92 | /** 93 | * Get the redirect target 94 | * 95 | * @return string 96 | */ 97 | public function getTarget() 98 | { 99 | return $this->data['target']; 100 | } 101 | 102 | /** 103 | * Get the redirect pagetitle 104 | * 105 | * @return string 106 | */ 107 | public function getPagetitle() 108 | { 109 | return $this->data['pagetitle']; 110 | } 111 | 112 | /** 113 | * Get the meta description from the redirect 114 | * 115 | * @return string 116 | */ 117 | public function getMetadescr() 118 | { 119 | return $this->data['metadescr']; 120 | } 121 | 122 | /** 123 | * Get the redirect metakey 124 | * 125 | * @return string 126 | */ 127 | public function getMetakey() 128 | { 129 | return $this->data['metakey']; 130 | } 131 | 132 | /** 133 | * Update the redirect 134 | * 135 | * @param string $type 136 | * @param string $target 137 | * @param string $pagetitle 138 | * @param string $metadescr 139 | * @param string $metakey 140 | * @return mixed 141 | */ 142 | public function update($type = NULL, $target = NULL, $pagetitle = NULL, $metadescr = NULL, $metakey = NULL) 143 | { 144 | $data = [ 145 | 'id' => $this->data['id'] 146 | ]; 147 | 148 | if (!is_null($type)) { 149 | $data['type'] = $type; 150 | } 151 | if (!is_null($target)) { 152 | $data['target'] = $target; 153 | } 154 | if (!is_null($pagetitle)) { 155 | $data['pagetitle'] = $pagetitle; 156 | } 157 | if (!is_null($metadescr)) { 158 | $data['metadescr'] = $metadescr; 159 | } 160 | if (!is_null($metakey)) { 161 | $data['metakey'] = $metakey; 162 | } 163 | 164 | return $this->getApi()->dataPut("/domain/" . $this->fqdn . "/redirects", $data); 165 | } 166 | 167 | /** 168 | * Delete the redirect 169 | * 170 | * @return bool 171 | */ 172 | public function delete() 173 | { 174 | return $this->getApi()->dataDelete("/domain/" . $this->fqdn . "/redirects", ["id" => $this->getId()]); 175 | } 176 | 177 | 178 | } 179 | -------------------------------------------------------------------------------- /lib/Nitrapi/Domain/Zone.php: -------------------------------------------------------------------------------- 1 | setData($data); 26 | $this->setFqdn($fqdn); 27 | } 28 | 29 | /** 30 | * Sets data field $data to specified value. 31 | * 32 | * @param array $data 33 | * @return $this 34 | */ 35 | public function setData($data) 36 | { 37 | if (count($data) > 0) { 38 | $this->data = $data; 39 | } 40 | 41 | return $this; 42 | } 43 | 44 | /** 45 | * Sets fqdn field $fqdn to specified value. 46 | * 47 | * @param $fqdn 48 | * @return $this 49 | */ 50 | public function setFqdn($fqdn) 51 | { 52 | $this->fqdn = $fqdn; 53 | 54 | return $this; 55 | } 56 | 57 | /** 58 | * Returns DNSSEC status 59 | * 60 | * @return bool 61 | */ 62 | public function getDNSSEC() 63 | { 64 | return (bool) $this->data['DNSSEC']; 65 | } 66 | 67 | /** 68 | * Sets the DNSSEC status 69 | * 70 | * @param bool $dnssec 71 | * @return mixed 72 | */ 73 | public function setDNSSEC($dnssec) 74 | { 75 | $data = [ 76 | "dnssec" => $dnssec 77 | ]; 78 | return $this->getApi()->dataPut("/domain/" . $this->fqdn . "/zone", $data); 79 | } 80 | 81 | 82 | } 83 | -------------------------------------------------------------------------------- /lib/Nitrapi/DynamicShare/DynamicShare.php: -------------------------------------------------------------------------------- 1 | setApi($api); 12 | } 13 | 14 | /** 15 | * @param string $pattern 16 | * @param int $service_id 17 | * @return string token 18 | */ 19 | public function create($pattern = null, $service_id = 0) { 20 | $url = "hostsystem/dynamic_share"; 21 | return $this->getApi()->dataPost($url, [ 22 | "pattern" => $pattern, 23 | "service_id" => $service_id 24 | ])['share']['token']; 25 | } 26 | 27 | public function attach($token, $user, $password) { 28 | $url = "hostsystem/dynamic_share/attach"; 29 | return $this->getApi()->dataPost($url, [ 30 | "token" => $token, 31 | "user" => $user, 32 | "password" => $password 33 | ])['share']; 34 | } 35 | 36 | public function share($token, $service_id = 0) { 37 | $url = "hostsystem/dynamic_share"; 38 | return $this->getApi()->dataGet($url, null, [ 39 | 'query' => [ 40 | "token" => $token, 41 | "service_id" => $service_id 42 | ] 43 | ])['share']; 44 | } 45 | 46 | public function shares($host) { 47 | $url = "hostsystem/dynamic_share/shares"; 48 | return $this->getApi()->dataGet($url, null, [ 49 | 'query' => [ 50 | "host" => $host 51 | ] 52 | ])['shares']; 53 | } 54 | 55 | /** 56 | * @param Nitrapi $api 57 | */ 58 | protected function setApi(Nitrapi $api) { 59 | $this->api = $api; 60 | } 61 | 62 | /** 63 | * @return Nitrapi 64 | */ 65 | public function getApi() { 66 | return $this->api; 67 | } 68 | } -------------------------------------------------------------------------------- /lib/Nitrapi/GameInfo/GameInfo.php: -------------------------------------------------------------------------------- 1 | data = $data; 14 | } 15 | 16 | public function getData() { 17 | return $this->data; 18 | } 19 | 20 | public function getId() { 21 | return $this->data['id']; 22 | } 23 | 24 | public function getName() { 25 | return $this->data['name']; 26 | } 27 | 28 | public function getMinimumSlots() { 29 | return $this->data['minimum_slots']; 30 | } 31 | 32 | public function getMaximumRecommendedSlots() { 33 | return $this->data['maximum_recommended_slots']; 34 | } 35 | 36 | public function getLocationIds() { 37 | return $this->data['locations']; 38 | } 39 | 40 | public function getPreOrderLocationIds() { 41 | return !empty($this->data['preorder_locations']) ? $this->data['preorder_locations'] : []; 42 | } 43 | 44 | public function getSlotMultiplier() { 45 | return $this->data['slot_multiplier']; 46 | } 47 | 48 | public function getFolderShort() { 49 | return $this->data['folder_short']; 50 | } 51 | 52 | public function getPortlistShort() { 53 | return $this->data['portlist_short']; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /lib/Nitrapi/GameInfo/GameInfoInterface.php: -------------------------------------------------------------------------------- 1 | getApi(); 11 | $result = []; 12 | 13 | $gameList = $api->dataGet('/gameserver/games')['games']['games']; 14 | 15 | foreach ($gameList as $gameListEntry) { 16 | $result[$gameListEntry['id']] = new GameInfo($api, $gameListEntry); 17 | } 18 | 19 | return $result; 20 | } 21 | 22 | public function getGameListByFolderShort() { 23 | $result = []; 24 | $gameList = $this->getGameList(); 25 | 26 | foreach ($gameList as $gameInfo) { 27 | $result[$gameInfo->getFolderShort()] = $gameInfo; 28 | } 29 | 30 | return $result; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /lib/Nitrapi/Geo/CountryManager.php: -------------------------------------------------------------------------------- 1 | api = $api; 17 | } 18 | 19 | /** 20 | * Returns all tlds 21 | * 22 | * @param bool $show_disabled show disabled tlds 23 | * @param string $provider limit to one provider 24 | * @return TopLevelDomain[] 25 | */ 26 | public function getTlds($show_disabled = false, $provider = NULL) { 27 | $tlds = []; 28 | $data = [ 29 | "query" => [ 30 | "show_disabled" => $show_disabled ? 'true' : 'false', 31 | ] 32 | ]; 33 | if (!is_null($provider)) { 34 | $data['provider'] = $provider; 35 | } 36 | 37 | foreach ($this->api->dataGet("/tlds", null, $data) as $tld) { 38 | $tlds[] = new TopLevelDomain($this->api, $tld); 39 | } 40 | 41 | return $tlds; 42 | } 43 | 44 | /** 45 | * Returns all country codes and the corresponding countries 46 | * 47 | * @return array list that matches 2 character country codes to the countries name 48 | */ 49 | public function getCountrycodes() { 50 | return $this->api->dataGet("/geo/countrycodes"); 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /lib/Nitrapi/Nitrapi.php: -------------------------------------------------------------------------------- 1 | setAccessToken($accessToken); 22 | 23 | $query = array(); 24 | if (isset($options['user_ip']) && filter_var($options['user_ip'], FILTER_VALIDATE_IP)) { 25 | $query['user_ip'] = $options['user_ip']; 26 | } 27 | 28 | if (isset($options['user_ipv6']) && filter_var($options['user_ipv6'], FILTER_VALIDATE_IP)) { 29 | $query['user_ipv6'] = $options['user_ipv6']; 30 | } 31 | 32 | if (!empty($options['locale'])) { 33 | $query['locale'] = (string)$options['locale']; 34 | } 35 | 36 | if (!empty($options['oAuthClientId'])) { 37 | $this->oAuthClientId = $options['oAuthClientId']; 38 | } 39 | 40 | if (!empty($options['oAuthClientSecret'])) { 41 | $this->oAuthClientSecret = $options['oAuthClientSecret']; 42 | } 43 | 44 | $options['query'] = $query; 45 | parent::__construct($url, $options); 46 | } 47 | 48 | /** 49 | * Gets a specific service 50 | * 51 | * @param array $options 52 | * @return Service 53 | */ 54 | public function getService(array $options = array()) { 55 | return ServiceFactory::factory($this, $options); 56 | } 57 | 58 | /** 59 | * @param array $options 60 | * @return array 61 | */ 62 | public function getServices(array $options = array()) { 63 | $collection = new ServiceCollection($this, $options); 64 | 65 | return $collection->getServices(); 66 | } 67 | 68 | /** 69 | * Returns the admin controller 70 | * 71 | * @return Admin 72 | */ 73 | public function getAdmin() { 74 | return new Admin($this); 75 | } 76 | 77 | /** 78 | * Gets the customer data set 79 | * 80 | * @return Customer 81 | */ 82 | public function getCustomer() { 83 | return new Customer($this); 84 | } 85 | 86 | public function getGameInfoInterface() { 87 | return new \Nitrapi\GameInfo\GameInfoInterface($this); 88 | } 89 | 90 | /** @see https://doc.nitrado.net/#api-Registration-Create */ 91 | public function registerUser($userName, $email, $password, $consentPrivacy, $consentAge, $consentTos, $recaptchaResponse = null, $currency = null, $language = null, $timezone = null, $consentNewsletter = false) { 92 | return new \Nitrapi\Customer\Registration($this, $this->oAuthClientId, $this->oAuthClientSecret, $userName, $email, $password, $consentPrivacy, $consentAge, $consentTos, $recaptchaResponse, $currency, $language, $timezone, $consentNewsletter); 93 | } 94 | 95 | public function getRecaptchaSiteKey() { 96 | return \Nitrapi\Customer\Registration::getRecaptchaSiteKey($this); 97 | } 98 | 99 | public function getAccessTokenInfo() { 100 | return new \Nitrapi\Customer\AccessToken( 101 | array_merge( 102 | $this->dataGet('/token')['token'], 103 | ['access_token' => $this->getAccessToken()] 104 | )); 105 | } 106 | } 107 | -------------------------------------------------------------------------------- /lib/Nitrapi/OAuth/Client.php: -------------------------------------------------------------------------------- 1 | api = $api; 21 | $this->data = $data; 22 | } 23 | 24 | public function getClientId() { 25 | return $this->data['id']; 26 | } 27 | 28 | /** 29 | * Only available if client has been created. 30 | * 31 | * @return string|null 32 | */ 33 | public function getClientSecret() { 34 | return $this->data['secret']; 35 | } 36 | 37 | /** 38 | * Returns true if the client is a official Nitrado.net Client. 39 | * 40 | * @return bool 41 | */ 42 | public function isOfficial() { 43 | return $this->data['official']; 44 | } 45 | 46 | /** 47 | * Returns false if the client has been locked by the Nitrado.net staff. 48 | * 49 | * @return bool 50 | */ 51 | public function isEnabled() { 52 | return $this->data['enabled']; 53 | } 54 | 55 | /** 56 | * Returns the name of the client. 57 | * 58 | * @return string 59 | */ 60 | public function getName() { 61 | return $this->data['name']; 62 | } 63 | 64 | /** 65 | * Returns a base64 encoded icon if available. 66 | * 67 | * @return string 68 | */ 69 | public function getIcon() { 70 | return $this->data['icon']; 71 | } 72 | 73 | /** 74 | * Returns the client description. 75 | * 76 | * @return string 77 | */ 78 | public function getDescription() { 79 | return $this->data['description']; 80 | } 81 | 82 | /** 83 | * Returns the client email address. 84 | * 85 | * @return string 86 | */ 87 | public function getEMail() { 88 | return $this->data['email']; 89 | } 90 | 91 | /** 92 | * Returns the website. 93 | * 94 | * @return string 95 | */ 96 | public function getWebsite() { 97 | return $this->data['website']; 98 | } 99 | 100 | /** 101 | * Returns all valid redirect uris for this client. 102 | * 103 | * @return array 104 | */ 105 | public function getRedirectURIs() { 106 | return (array)$this->data['redirect_uris']; 107 | } 108 | 109 | /** 110 | * Returns all allowed grant types for this client. 111 | * 112 | * @return array 113 | */ 114 | public function getGrantTypes() { 115 | return (array)$this->data['grant_types']; 116 | } 117 | 118 | /** 119 | * Updates the client. 120 | * 121 | * @param array $data 122 | */ 123 | public function update(array $data) { 124 | $this->data = $this->api->dataPut('/oauth/' . $this->getClientId(), $data)['client']; 125 | } 126 | 127 | /** 128 | * Returns a new client secret and invalidates the old one! 129 | * 130 | * @param $updateToken 131 | * @return string 132 | */ 133 | public function renewSecret($updateToken) { 134 | return $this->api->dataPut('/oauth/' . $this->getClientId() . '/secret', [ 135 | 'token' => $updateToken 136 | ])['client']['secret']; 137 | } 138 | 139 | /** 140 | * Deletes the client! 141 | * 142 | * This invalidates all access and refresh tokens! 143 | * 144 | * @param $updateToken 145 | * @return bool 146 | */ 147 | public function delete($updateToken) { 148 | return $this->api->dataDelete('/oauth/' . $this->getClientId(), [ 149 | 'token' => $updateToken 150 | ]); 151 | } 152 | 153 | } -------------------------------------------------------------------------------- /lib/Nitrapi/OAuth/OAuth.php: -------------------------------------------------------------------------------- 1 | api = $api; 16 | } 17 | 18 | /** 19 | * Returns a specific OAuth 2.0 Client by id. 20 | * 21 | * @param $id 22 | * @return Client 23 | */ 24 | public function getClient($id) { 25 | $_client = $this->api->dataGet('/oauth/' . $id)['client']; 26 | return new Client($this->api, $_client); 27 | } 28 | 29 | /** 30 | * Returns all your OAuth 2.0 clients. 31 | * 32 | * @return array 33 | */ 34 | public function getClients() { 35 | $clients = []; 36 | $_clients = $this->api->dataGet('/oauth')['clients']; 37 | 38 | foreach ($_clients as $_client) { 39 | $clients[] = new Client($this->api, $_client); 40 | } 41 | 42 | return $clients; 43 | } 44 | 45 | /** 46 | * Creates a new OAuth 2.0 client. 47 | * 48 | * @param array $data 49 | * @return Client 50 | */ 51 | public function createClient(array $data) { 52 | $_client = $this->api->dataPost('/oauth/', $data)['client']; 53 | return new Client($this->api, $_client); 54 | } 55 | 56 | } -------------------------------------------------------------------------------- /lib/Nitrapi/Order/Pricing/DimensionPricing.php: -------------------------------------------------------------------------------- 1 | dimensions === null) { 14 | $this->getDimensions(); 15 | } 16 | 17 | if (!array_key_exists($dimension, $this->dimensions)) { 18 | throw new PricingException("Dimension " . $dimension . " is not available for this product."); 19 | } 20 | 21 | $this->dimensions[$dimension] = $value; 22 | } 23 | 24 | /** 25 | * @deprecated Use addDimension($dimension, $value) instead. 26 | */ 27 | public function addDimenstion($dimension, $value) { 28 | $this->addDimension($dimension, $value); 29 | } 30 | 31 | public function getDimensions() { 32 | if ($this->dimensions === null) { 33 | $prices = $this->getPrices(); 34 | $this->dimensions = []; 35 | foreach ($prices['dimensions'] as $dimension) { 36 | $this->dimensions[$dimension['id']] = null; 37 | } 38 | } 39 | 40 | return $this->dimensions; 41 | } 42 | 43 | /** 44 | * Returns the price for the service. 45 | * 46 | * @param $rentalTime 47 | * @param Service|null $service 48 | * @return int 49 | */ 50 | public function getPrice($rentalTime, Service &$service = null) { 51 | $information = $this->getPrices($service); 52 | $dimensions = $this->getDimensions(); 53 | $dimensions['rental_time'] = $rentalTime; 54 | 55 | $prices = $information['prices']; 56 | foreach ($dimensions as $key => $value) { 57 | if ($value === null) continue; 58 | if (array_key_exists($value, $prices)) { 59 | $prices = $prices[$value]; 60 | } else { 61 | throw new PricingException("No dimension information for " . $value . " found."); 62 | } 63 | } 64 | 65 | if (is_array($prices) && isset($prices['price'])) { 66 | $price = (int)$prices['price']; 67 | $advice = $information['advice']; 68 | 69 | // Remove 50% of advice if the old service is not a Cloud Server Dynamic 70 | $removePercent = 50.0; 71 | if ($service instanceof CloudServer && $service->getDetails()->isDynamic()) { 72 | $removePercent = 0.0; 73 | } 74 | 75 | return $this->calcAdvicePrice($price, $advice, $removePercent); 76 | } 77 | 78 | throw new PricingException("No price for selected dimensions not found."); 79 | } 80 | 81 | protected function getNewOrderArray($rentalTime) { 82 | $orderArray = [ 83 | 'price' => $this->getPrice($rentalTime), 84 | 'rental_time' => $rentalTime, 85 | 'location' => $this->locationId, 86 | 'dimensions' => $this->getDimensions(), 87 | 'additionals' => $this->additionals 88 | ]; 89 | return $orderArray; 90 | } 91 | 92 | protected function getSwitchOrderArray(Service &$service, $rentalTime) { 93 | $orderArray = [ 94 | 'price' => $this->getSwitchPrice($service, $rentalTime), 95 | 'rental_time' => $rentalTime, 96 | 'location' => $this->locationId, 97 | 'dimensions' => $this->getDimensions(), 98 | 'additionals' => $this->additionals, 99 | 'method' => 'switch', 100 | 'service_id' => $service->getId(), 101 | ]; 102 | 103 | return $orderArray; 104 | } 105 | } -------------------------------------------------------------------------------- /lib/Nitrapi/Order/Pricing/Location.php: -------------------------------------------------------------------------------- 1 | data = $data; 11 | } 12 | 13 | public function getId() { 14 | return $this->data['id']; 15 | } 16 | 17 | public function getCountry() { 18 | return $this->data['country']; 19 | } 20 | 21 | public function getCity() { 22 | return $this->data['city']; 23 | } 24 | 25 | public function getProducts() { 26 | return $this->data['products']; 27 | } 28 | } -------------------------------------------------------------------------------- /lib/Nitrapi/Order/Pricing/PartPricing.php: -------------------------------------------------------------------------------- 1 | parts === null) { 14 | $this->getParts(); 15 | } 16 | 17 | if (!array_key_exists($part, $this->parts)) { 18 | throw new PricingException("Part " . $part . " is not available for this product."); 19 | } 20 | 21 | $this->parts[$part] = $value; 22 | } 23 | 24 | public function getParts() { 25 | if ($this->parts === null) { 26 | $prices = $this->getPrices(); 27 | $this->parts = []; 28 | foreach ($prices['parts'] as $part) { 29 | $this->parts[$part['type']] = null; 30 | } 31 | } 32 | 33 | return $this->parts; 34 | } 35 | 36 | public function getPrice($rentalTime, Service &$service = null) { 37 | $this->checkDependencies(); 38 | $prices = $this->getPrices($service); 39 | $parts = $this->getParts(); 40 | 41 | $multiply = 1; 42 | $totalPrice = 0; 43 | 44 | // Dynamic rental times 45 | if ($prices['rental_times'] === null) { 46 | if(($rentalTime % $prices['min_rental_time']) !== 0) { 47 | throw new PricingException("Rental time " . $rentalTime . " is invalid (Modulu ".$prices['min_rental_time'].")."); 48 | } 49 | 50 | $multiply = $rentalTime / $prices['min_rental_time']; 51 | $rentalTime = $prices['min_rental_time']; 52 | } 53 | 54 | foreach ($prices['parts'] as $part) { 55 | $amount = $parts[$part['type']]; 56 | if (empty($amount)) continue; 57 | 58 | if ($amount <= 0) throw new PricingException("The amount of {$part['type']} can't be 0."); 59 | if ($amount > $part['max_count']) throw new PricingException("The amount {$amount} of type {$part['type']} is too big."); 60 | if ($amount < $part['min_count']) throw new PricingException("The amount {$amount} of type {$part['type']} is too low."); 61 | if (!empty($part['steps']) && !in_array($amount, $part['steps'])) throw new PricingException("The amount {$amount} of type {$part['type']} is not available."); 62 | 63 | $bestPrice = false; 64 | foreach ($part['rental_times'] as $hoursAndPrices) 65 | if ($hoursAndPrices['hours'] == $rentalTime) 66 | foreach ($hoursAndPrices['prices'] as $price) 67 | if ($price['count'] === $amount) 68 | $bestPrice = $price['price']; 69 | 70 | if (!is_float($bestPrice) && !is_int($bestPrice)) throw new PricingException("No valid price found for part {$part['type']}."); 71 | $totalPrice += $bestPrice; 72 | } 73 | 74 | // Multiple by rental time if dynamic rental times 75 | $totalPrice *= $multiply; 76 | 77 | // Remove 50% of advice if the old service is not a Cloud Server Dynamic 78 | $removePercent = 50; 79 | if ($service instanceof CloudServer && $service->getDetails()->isDynamic()) { 80 | $removePercent = 0; 81 | } 82 | 83 | $totalPrice = $this->calcAdvicePrice(round($totalPrice, 0), $prices['advice'], $removePercent); 84 | 85 | return $totalPrice; 86 | } 87 | 88 | public function checkDependencies() { 89 | $prices = $this->getPrices(); 90 | $parts = $this->getParts(); 91 | foreach ($prices['parts'] as $part) { 92 | if ($part['optional'] === false && 93 | (!isset($parts[$part['type']]) || empty($parts[$part['type']]))) { 94 | throw new PricingException("No value provided for needed part type " . $part['type'] . "."); 95 | } 96 | } 97 | } 98 | 99 | protected function getNewOrderArray($rentalTime) { 100 | $this->checkDependencies(); 101 | $orderArray = [ 102 | 'price' => $this->getPrice($rentalTime), 103 | 'rental_time' => $rentalTime, 104 | 'location' => $this->locationId, 105 | 'parts' => $this->getParts(), 106 | 'additionals' => $this->additionals 107 | ]; 108 | 109 | return $orderArray; 110 | } 111 | 112 | protected function getSwitchOrderArray(Service &$service, $rentalTime) { 113 | $this->checkDependencies(); 114 | $orderArray = [ 115 | 'price' => $this->getSwitchPrice($service, $rentalTime), 116 | 'rental_time' => $rentalTime, 117 | 'location' => $this->locationId, 118 | 'parts' => $this->getParts(), 119 | 'additionals' => $this->additionals, 120 | 'method' => 'switch', 121 | 'service_id' => $service->getId(), 122 | ]; 123 | 124 | return $orderArray; 125 | } 126 | } -------------------------------------------------------------------------------- /lib/Nitrapi/Order/Pricing/Pricing.php: -------------------------------------------------------------------------------- 1 | nitrapi = $nitrapi; 48 | $this->locationId = $location->getId(); 49 | } 50 | 51 | /** 52 | * This can be used only for pricing information 53 | * 54 | * @var $currency 55 | */ 56 | public function setCurrency($currency = null) { 57 | $this->currency = $currency; 58 | } 59 | 60 | /** 61 | * Changes the location id 62 | * 63 | * @param $locationId 64 | */ 65 | public function setLocationId($locationId) { 66 | $this->locationId = $locationId; 67 | } 68 | 69 | /** 70 | * @param Nitrapi $nitrapi 71 | * @return mixed 72 | */ 73 | public static function getLocations(Nitrapi &$nitrapi) { 74 | if (static::$product === null) { 75 | throw new PricingException("You can not use the Pricing() class. Please use a product class."); 76 | } 77 | $_locations = $nitrapi->dataGet("/order/order/locations")['locations']; 78 | $locations = []; 79 | foreach ($_locations as $key => $location) { 80 | if (!isset($location['products'][static::$product])) continue; 81 | if ($location['products'][static::$product] !== true) continue; 82 | $locations[] = new Location($location); 83 | } 84 | 85 | return $locations; 86 | } 87 | 88 | /** 89 | * @param Nitrapi $nitrapi 90 | * @param int $id 91 | * @return mixed 92 | */ 93 | public static function getLocation(Nitrapi &$nitrapi, $id) { 94 | if (static::$product === null) { 95 | throw new PricingException("You can not use the Pricing() class. Please use a product class."); 96 | } 97 | $_locations = $nitrapi->dataGet("/order/order/locations")['locations']; 98 | foreach ($_locations as $key => $location) { 99 | if (!isset($location['products'][static::$product])) continue; 100 | if ($location['products'][static::$product] !== true) continue; 101 | if ($location['id'] !== $id) continue; 102 | return new Location($location); 103 | } 104 | 105 | throw new PricingException("Location " . $id . " not found or product not supported"); 106 | } 107 | 108 | /** 109 | * Get full price list for specified product 110 | * 111 | * @return mixed 112 | */ 113 | public function getPrices(Service &$service = null) { 114 | $cacheName = $this->locationId . "/" . $this->currency; 115 | if ($service instanceof Service) $cacheName .= "/" . $service->getId(); 116 | if (isset($this->prices[$cacheName])) { 117 | return $this->prices[$cacheName]; 118 | } 119 | 120 | $query = [ 121 | 'location' => $this->locationId 122 | ]; 123 | 124 | if ($service instanceof Service) { 125 | $query['sale_service'] = $service->getId(); 126 | } 127 | 128 | if (!empty($this->currency) && (!($service instanceof Service))) { 129 | $query['currency'] = $this->currency; 130 | } 131 | 132 | $this->prices[$cacheName] = $this->nitrapi->dataGet("/order/pricing/" . $this->getProduct(), null, [ 133 | 'query' => $query 134 | ])['prices']; 135 | 136 | return $this->prices[$cacheName]; 137 | } 138 | 139 | /** 140 | * Returns the price for extending a specific service 141 | * 142 | * @param Service $service 143 | * @param $rentalTime 144 | */ 145 | public function getExtendPriceForService(Service &$service, $rentalTime) { 146 | $this->setCurrency(null); //use user currency 147 | return $this->prices[$this->locationId] = $this->nitrapi->dataGet("/order/pricing/" . $this->getProduct(), null, [ 148 | 'query' => [ 149 | 'method' => 'extend', 150 | 'service_id' => $service->getId(), 151 | 'rental_time' => $rentalTime 152 | ] 153 | ])['extend']['prices'][$rentalTime]; 154 | } 155 | 156 | /** 157 | * Extends the specific service about the specific rental time 158 | * 159 | * @param Service $service 160 | * @param $rentalTime 161 | * @return int The service's service_id 162 | */ 163 | public function extendService(Service &$service, $rentalTime) { 164 | $this->setCurrency(null); //use user currency 165 | $price = $this->getExtendPriceForService($service, $rentalTime); 166 | $orderArray = [ 167 | 'price' => $price, 168 | 'rental_time' => $rentalTime, 169 | 'service_id' => $service->getId(), 170 | 'method' => 'extend' 171 | ]; 172 | 173 | $this->nitrapi->dataPost("order/order/" . $this->getProduct(), $orderArray); 174 | 175 | return $service->getId(); 176 | } 177 | 178 | /** 179 | * Orders the specified service 180 | * 181 | * @param $rentalTime 182 | * @return int The new service's service_id 183 | */ 184 | public function orderService($rentalTime) { 185 | $this->setCurrency(null); //use user currency 186 | 187 | $orderArray = $this->getNewOrderArray($rentalTime); 188 | 189 | $result = $this->nitrapi->dataPost("order/order/" . $this->getProduct(), $orderArray); 190 | 191 | //if no exception appears, order was successful 192 | return $result['order']['service_id']; 193 | } 194 | 195 | /** 196 | * Returns the price for swichting 197 | * 198 | * @param $rentalTime 199 | * @param Service $service 200 | * @return int 201 | */ 202 | public function getSwitchPrice(Service &$service, $rentalTime) { 203 | $this->setCurrency(null); //use user currency 204 | return $this->getPrice($rentalTime, $service); 205 | } 206 | 207 | /** 208 | * Switches the product of a specific service 209 | * 210 | * @param Service $service 211 | * @param $rentalTime 212 | * @return int The service's service_id 213 | */ 214 | public function switchService(Service &$service, $rentalTime) { 215 | $this->setCurrency(null); //use user currency 216 | $orderArray = $this->getSwitchOrderArray($service, $rentalTime); 217 | 218 | $result = $this->nitrapi->dataPost("order/order/" . $this->getProduct(), $orderArray); 219 | 220 | //if no exception appears, order was successful 221 | return $result['order']['service_id']; 222 | } 223 | 224 | /** 225 | * Removes X% of the advice if the advice is higher then the price. 226 | * 227 | * @param $price int 228 | * @param $advice int 229 | * @param $removePercent float 230 | * @return int 231 | */ 232 | protected function calcAdvicePrice($price, $advice, $removePercent) { 233 | if ($advice > $price) { 234 | $advice -= round(($advice - $price) * ($removePercent / 100)); 235 | } 236 | 237 | return ($price - $advice); 238 | } 239 | 240 | protected function getProduct() { 241 | return static::$product; 242 | } 243 | 244 | protected abstract function getNewOrderArray($rentalTime); 245 | protected abstract function getSwitchOrderArray(Service &$service, $rentalTime); 246 | } 247 | -------------------------------------------------------------------------------- /lib/Nitrapi/Order/Pricing/PricingException.php: -------------------------------------------------------------------------------- 1 | additionals['image_id'] = $image->getId(); 14 | } 15 | 16 | public function setHostname($hostname) { 17 | $this->additionals['hostname'] = $hostname; 18 | } 19 | 20 | } -------------------------------------------------------------------------------- /lib/Nitrapi/Order/Pricing/Products/CloudServerDynamic.php: -------------------------------------------------------------------------------- 1 | additionals['image_id'] = $image->getId(); 14 | } 15 | 16 | public function setHostname($hostname) { 17 | $this->additionals['hostname'] = $hostname; 18 | } 19 | 20 | } -------------------------------------------------------------------------------- /lib/Nitrapi/Order/Pricing/Products/Gameserver.php: -------------------------------------------------------------------------------- 1 | promoCode = $promoCode; 19 | } 20 | 21 | public function setGame($game) { 22 | $this->additionals['game'] = $game; 23 | } 24 | 25 | public function setModpack($modpack) { 26 | $this->additionals['modpack'] = $modpack; 27 | } 28 | 29 | /** 30 | * Set the autoextend status. 31 | * Important: This does NOT enable autoextend. Use /services/:id/auto_extend instead. 32 | * @param int $autoextend 33 | * @return void 34 | */ 35 | public function setAutoextend($autoextend) { 36 | $this->additionals['autoextend'] = $autoextend; 37 | } 38 | 39 | /** 40 | * Returns the price for the service. 41 | * 42 | * @param $rentalTime 43 | * @param Service|null $service 44 | * @throws \Nitrapi\Order\Pricing\PricingException 45 | * @return int 46 | */ 47 | public function getPrice($rentalTime, Service &$service = null) { 48 | $price = parent::getPrice($rentalTime, $service); 49 | 50 | if (!empty($this->promoCode)) { 51 | try { 52 | $result = $this->nitrapi->dataGet('/order/promo_code/' . $this->promoCode); 53 | if ($result['promo_code']['effect_type'] === 'DISCOUNT') { 54 | $amount = $result['promo_code']['effect_params']['amount']; 55 | 56 | $price = $price - intval($amount * $price); 57 | } 58 | } catch(\Exception $e) { 59 | //Ignore faulty promo code 60 | } 61 | 62 | } 63 | 64 | return $price; 65 | } 66 | 67 | protected function getNewOrderArray($rentalTime) { 68 | $orderArray = parent::getNewOrderArray($rentalTime); 69 | 70 | if (!empty($this->promoCode)) { 71 | $orderArray['promo_code'] = $this->promoCode; 72 | } 73 | 74 | return $orderArray; 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /lib/Nitrapi/Order/Pricing/Products/Mumble.php: -------------------------------------------------------------------------------- 1 | api = $api; 17 | } 18 | 19 | /** 20 | * Returns all your SSH Public Keys 21 | * 22 | * @return array 23 | */ 24 | public function getPublicKeys() 25 | { 26 | $url = "user/ssh_keys"; 27 | $keys = []; 28 | foreach ($this->api->dataGet($url)['keys'] as $key) { 29 | $keys[] = new SSHKey($this->api, $key); 30 | } 31 | return $keys; 32 | } 33 | 34 | /** 35 | * Uploads a new SSH Public Key 36 | * 37 | * @param $key 38 | * @param bool $enabled 39 | * @return bool 40 | */ 41 | public function uploadPublicKey($key, $enabled = true) 42 | { 43 | $url = "user/ssh_keys"; 44 | $this->api->dataPost($url, [ 45 | 'key' => $key, 46 | 'enabled' => ($enabled ? 'true' : 'false') 47 | ]); 48 | 49 | return true; 50 | } 51 | 52 | } -------------------------------------------------------------------------------- /lib/Nitrapi/SSHKeys/SSHKey.php: -------------------------------------------------------------------------------- 1 | api = $api; 21 | $this->data = $data; 22 | $this->data['full_public_key'] = $this->data['type'] . ' ' . $this->data['public_key'] . ' ' . $this->data['comment']; 23 | } 24 | 25 | /** 26 | * Return the SSH Key ID 27 | * 28 | * @return int 29 | */ 30 | public function getId() { 31 | return (int)$this->data['id']; 32 | } 33 | 34 | /** 35 | * Return the SSH Key type 36 | * 37 | * @return string 38 | */ 39 | public function getType() { 40 | return $this->data['type']; 41 | } 42 | 43 | /** 44 | * Returns the SSH Key Comment 45 | * 46 | * @return string 47 | */ 48 | public function getComment() { 49 | return $this->data['comment']; 50 | } 51 | 52 | /** 53 | * Returns the full SSH public key 54 | * 55 | * @return string 56 | */ 57 | public function getPublicKey() 58 | { 59 | return $this->data['full_public_key']; 60 | } 61 | 62 | /** 63 | * Updates the existing SSH public key 64 | * 65 | * @return SSHKey 66 | */ 67 | public function setPublicKey($key) 68 | { 69 | $this->data['full_public_key'] = $key; 70 | $this->doUpdate(); 71 | return $this; 72 | } 73 | 74 | /** 75 | * Returns true if the key is enabled 76 | * 77 | * @return bool 78 | */ 79 | public function isEnabled() 80 | { 81 | return (bool)$this->data['enabled']; 82 | } 83 | 84 | /** 85 | * Returns true if the key is enabled 86 | * 87 | * @return SSHKey 88 | */ 89 | public function setEnabled($enabled = true) 90 | { 91 | $this->data['enabled'] = $enabled; 92 | $this->doUpdate(); 93 | return $this; 94 | } 95 | 96 | /** 97 | * Deletes this SSH public key 98 | * 99 | * @return bool 100 | */ 101 | public function doDelete() 102 | { 103 | $url = "user/ssh_keys/" . $this->data['id']; 104 | $this->api->dataDelete($url); 105 | 106 | return true; 107 | } 108 | 109 | /** 110 | * Updates this SSH public key in database 111 | * 112 | * @return $this 113 | */ 114 | private function doUpdate() 115 | { 116 | $url = "user/ssh_keys/" . $this->data['id']; 117 | $this->api->dataPost($url, [ 118 | 'key' => $this->getPublicKey(), 119 | 'enabled' => ($this->isEnabled() ? 'true' : 'false') 120 | ]); 121 | 122 | return $this; 123 | } 124 | 125 | } -------------------------------------------------------------------------------- /lib/Nitrapi/Services/Bouncers/Bouncer.php: -------------------------------------------------------------------------------- 1 | isActive()) { 15 | $this->info = $this->getApi()->dataGet($this->url())['bouncer']; 16 | } 17 | } 18 | 19 | public function getDetails() { 20 | return new BouncerDetails($this->info); 21 | } 22 | 23 | public function addIdent($identName, $password) { 24 | return $this->getApi()->dataPost($this->url(), [ 25 | 'ident' => $identName, 26 | 'password' => $password 27 | ]); 28 | } 29 | 30 | public function editPassword(Ident $ident, $newPassword) { 31 | return $this->getApi()->dataPut($this->url(), [ 32 | 'ident' => $ident->getIdent(), 33 | 'password' => $newPassword, 34 | ]); 35 | } 36 | 37 | public function deleteIdent(Ident $ident) { 38 | return $this->getApi()->dataDelete($this->url(), [ 39 | 'ident' => $ident->getIdent() 40 | ]); 41 | } 42 | 43 | private function url($path = '') { 44 | return 'services/' . $this->getId() . '/bouncers' . $path; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /lib/Nitrapi/Services/Bouncers/BouncerDetails.php: -------------------------------------------------------------------------------- 1 | data = $data; 11 | } 12 | 13 | public function getIdents() { 14 | return array_map(function($i) { 15 | return new Ident($i); 16 | }, $this->data['bouncers']); 17 | } 18 | 19 | public function getType() { 20 | return (string)$this->data['type']; 21 | } 22 | 23 | public function getIdentLimit() { 24 | return (int)$this->data['max_bouncer']; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /lib/Nitrapi/Services/Bouncers/Ident.php: -------------------------------------------------------------------------------- 1 | data = $data; 11 | } 12 | 13 | public function getPassword() { 14 | return $this->data['password']; 15 | } 16 | 17 | public function getIdent() { 18 | return $this->data['ident']; 19 | } 20 | 21 | public function getServer() { 22 | return $this->data['server']['name']; 23 | } 24 | 25 | public function getPort() { 26 | return $this->data['server']['port']; 27 | } 28 | 29 | public function hasRunningTasks() { 30 | return $this->data['running_tasks']; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /lib/Nitrapi/Services/Clanpages/Clanpage.php: -------------------------------------------------------------------------------- 1 | appManager = $appManager; 49 | $this->data = $data; 50 | 51 | if (!isset($this->data['ports'])) { 52 | $this->data['ports'] = []; 53 | } 54 | } 55 | 56 | /** 57 | * Implement the getter and setter methods to access the $data 58 | * array via getter and set the data via the setter. 59 | * 60 | * @example $app->setAppName('mc_server'); 61 | * @example $app->getStatus(); 62 | * 63 | * @param string $name The method name 64 | * @param array $args The args 65 | * @return mixed The resulting value from $data 66 | * @throws DataMissingException if the key in $data does not exist. 67 | * @throws \BadMethodCallException if the method does not exist. 68 | */ 69 | public function __call($name, $args) { 70 | if (preg_match('/(get|set)(.+)/', $name) === 0) { 71 | throw new \BadMethodCallException("Method $name not found."); 72 | } 73 | $method = strtolower($name[3]) . substr($name, 4); // Remove "get..." 74 | $key = strtolower(preg_replace('/(?data[$key])) { 78 | return $this->data[$key]; 79 | } 80 | 81 | if ($prefix === 'set') { 82 | $this->data[$key] = $args[0]; 83 | return $this; 84 | } 85 | 86 | throw new DataMissingException('The key ' . $key . ' does not exist. Please set first.'); 87 | } 88 | 89 | /** 90 | * Saves all the changed data attributes 91 | * @return $this 92 | */ 93 | public function persist() { 94 | $this->_api()->dataPut($this->_url($this->getAppName()), [ 95 | 'cmd' => $this->getCmd(), 96 | 'parameters' => $this->getParameters() 97 | ]); 98 | return $this; 99 | } 100 | 101 | /** 102 | * Install the application 103 | * 104 | * @return $this 105 | */ 106 | public function install() { 107 | $this->_api()->dataPost($this->_url(''), [ 108 | 'app_type' => $this->getAppType(), 109 | 'app_name' => $this->getAppName(), 110 | 'ports' => $this->getPorts() 111 | ]); 112 | 113 | /** 114 | * Update the $data array 115 | * @var $installedApps App[] 116 | */ 117 | $installedApps = $this->appManager->getInstalledApps(); 118 | foreach ($installedApps as $app) { 119 | if ($app->getAppType() === $this->getAppType() && 120 | $app->getAppName() === $this->getAppName()) { 121 | $this->data = $app->data; 122 | } 123 | } 124 | 125 | return $this; 126 | } 127 | 128 | /** 129 | * Uninstall the application. 130 | * 131 | * @return $this 132 | */ 133 | public function uninstall() { 134 | $this->_api()->dataDelete($this->_url($this->getAppName())); 135 | return $this; 136 | } 137 | 138 | /** 139 | * Update teh application. 140 | * 141 | * @return $this 142 | */ 143 | public function update() { 144 | $this->_api()->dataPost($this->_url($this->getAppName() . '/update')); 145 | return $this; 146 | } 147 | 148 | /** 149 | * Restart the application. 150 | * 151 | * @return $this 152 | */ 153 | public function restart() { 154 | $this->_api()->dataPost($this->_url($this->getAppName() . '/restart')); 155 | return $this; 156 | } 157 | 158 | /** 159 | * Stop the application. 160 | * 161 | * @return $this 162 | */ 163 | public function stop() { 164 | $this->_api()->dataPost($this->_url($this->getAppName() . '/stop')); 165 | return $this; 166 | } 167 | 168 | private function _url($method) { 169 | return '/services/' . $this->appManager->service->getId() . '/cloud_servers/apps/' . $method; 170 | } 171 | 172 | private function _api() { 173 | return $this->appManager->service->getApi(); 174 | } 175 | } 176 | -------------------------------------------------------------------------------- /lib/Nitrapi/Services/CloudServers/Apps/AppDescription.php: -------------------------------------------------------------------------------- 1 | data = $data; 15 | } 16 | 17 | /** 18 | * @return string the app type 19 | */ 20 | public function getAppType() { 21 | return $this->data['app_type']; 22 | } 23 | 24 | /** 25 | * @return string the category 26 | */ 27 | public function getCategory() { 28 | return $this->data['category']; 29 | } 30 | 31 | /** 32 | * @return string the description 33 | */ 34 | public function getDescription() { 35 | return $this->data['description']; 36 | } 37 | 38 | /** 39 | * @return bool if the app has IP binding 40 | */ 41 | public function hasIPBinding() { 42 | return (bool)$this->data['supports_ip_binding']; 43 | } 44 | 45 | /** 46 | * @return array all ports for that app 47 | */ 48 | public function getPorts() { 49 | return $this->data['ports']; 50 | } 51 | 52 | /** 53 | * @return array the minimum requirements the app needs to fullfill. 54 | */ 55 | public function getMinimumRequirements() { 56 | return $this->data['minimum_requirements']; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /lib/Nitrapi/Services/CloudServers/Apps/AppManager.php: -------------------------------------------------------------------------------- 1 | service = $service; 20 | } 21 | 22 | /** 23 | * Return all installed apps 24 | * 25 | * @return App[] all installed apps 26 | */ 27 | public function getInstalledApps() { 28 | $url = '/services/' . $this->service->getId() . '/cloud_servers/apps'; 29 | /* @var $apiResponse array[][] */ 30 | $apiResponse = $this->service->getApi()->dataGet($url); 31 | 32 | $apps = []; 33 | foreach ($apiResponse['apps'] as $app) { 34 | $apps[] = new App($this, $app); 35 | } 36 | 37 | // Sort 38 | usort($apps, function(App $a, App $b) { 39 | return strcmp(strtolower($a->getAppName()), strtolower($b->getAppName())); 40 | }); 41 | 42 | return $apps; 43 | } 44 | 45 | /** 46 | * Return all app descriptions 47 | * 48 | * @return AppDescription[] All app descriptions 49 | */ 50 | public function getAvailableAppDescriptions() { 51 | $url = '/services/' . $this->service->getId() . '/cloud_servers/apps/available'; 52 | /* @var $apiResponse array[][] */ 53 | $apiResponse = $this->service->getApi()->dataGet($url); 54 | 55 | $apps = []; 56 | foreach ($apiResponse['apps'] as $description) { 57 | $apps[] = new AppDescription($description); 58 | } 59 | return $apps; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /lib/Nitrapi/Services/CloudServers/Backup/Backup.php: -------------------------------------------------------------------------------- 1 | backupManager = $backupManager; 16 | $this->data = $data; 17 | } 18 | 19 | public function getId() { 20 | return $this->data['id']; 21 | } 22 | 23 | public function getName() { 24 | return $this->data['name']; 25 | } 26 | 27 | public function getStatus() { 28 | return $this->data['status']; 29 | } 30 | 31 | public function getCreatedAt() { 32 | return (new \DateTime())->setTimestamp(strtotime($this->data['created_at'])); 33 | } 34 | 35 | public function getType() { 36 | return $this->data['type']; 37 | } 38 | 39 | /** 40 | * Restores the specific Backup to the Cloud Server. 41 | * This will take up to 30 minutes. 42 | * 43 | * The Cloud Server instance will reset to the Backup, this causes data-loss. 44 | * 45 | * @return bool 46 | */ 47 | public function doRestore() { 48 | $url = "/services/".$this->backupManager->getCloudServer()->getId()."/cloud_servers/backups/" . $this->getId() . "/restore"; 49 | $this->backupManager->getCloudServer()->getApi()->dataPost($url); 50 | 51 | return true; 52 | } 53 | 54 | /** 55 | * Deletes a specific Backup. 56 | * 57 | * Information: 58 | * Automatic Backups can't be deleted and will throw a Exception. 59 | * 60 | * @return bool 61 | */ 62 | public function doDelete() { 63 | $url = "/services/".$this->backupManager->getCloudServer()->getId()."/cloud_servers/backups/" . $this->getId(); 64 | $this->backupManager->getCloudServer()->getApi()->dataDelete($url); 65 | 66 | return true; 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /lib/Nitrapi/Services/CloudServers/Backup/BackupManager.php: -------------------------------------------------------------------------------- 1 | service = $service; 16 | } 17 | 18 | /** 19 | * @return CloudServer 20 | */ 21 | public function getCloudServer() { 22 | return $this->service; 23 | } 24 | 25 | /** 26 | * Return all Cloud Server Backups 27 | */ 28 | public function getBackups() { 29 | $url = "/services/".$this->service->getId()."/cloud_servers/backups"; 30 | $backups = []; 31 | 32 | foreach ($this->service->getApi()->dataGet($url)['backups'] as $backup) { 33 | $backups[] = new Backup($this, $backup); 34 | } 35 | 36 | return $backups; 37 | } 38 | 39 | /** 40 | * Create a new Cloud Server Backup. 41 | * This action can take some minutes. 42 | * 43 | * @return bool 44 | */ 45 | public function createBackup() { 46 | $url = "/services/".$this->service->getId()."/cloud_servers/backups"; 47 | $this->service->getApi()->dataPost($url); 48 | 49 | return true; 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /lib/Nitrapi/Services/CloudServers/CloudServer.php: -------------------------------------------------------------------------------- 1 | refresh()) { 30 | throw new NitrapiHttpErrorException('Received invalid data from NitrAPI.'); 31 | } 32 | } 33 | 34 | /** 35 | * @see Gameserver::refresh() 36 | * @see Service::forceAction() 37 | * 38 | * @return bool 39 | * @throws NitrapiServiceNotActiveException 40 | */ 41 | public function refresh() { 42 | if (self::$ensureActiveService && $this->getStatus() !== self::SERVICE_STATUS_ACTIVE) { 43 | throw new NitrapiServiceNotActiveException('Service is not active any more.'); 44 | } 45 | 46 | if (in_array($this->getStatus(), [self::SERVICE_STATUS_ACTIVE, self::SERVICE_STATUS_SUSPENDED])) { 47 | $url = 'services/' . $this->getId() . '/cloud_servers'; 48 | $res = $this->getApi()->dataGet($url); 49 | if ($res !== null) { 50 | $this->info = $res; 51 | return true; 52 | } 53 | 54 | return false; 55 | } 56 | 57 | 58 | 59 | return true; 60 | } 61 | 62 | /** 63 | * Return information about the Cloud Server. 64 | * 65 | * @return CloudServerDetails 66 | */ 67 | public function getDetails() { 68 | return new CloudServerDetails($this->info['cloud_server']); 69 | } 70 | 71 | /** 72 | * List all the users (with groups) on a Cloud Server. This users 73 | * are located in the /etc/passwd. All newly creates users on the 74 | * system are included in this array. 75 | * 76 | * @return array 77 | */ 78 | public function getUsers() { 79 | $url = 'services/' . $this->getId() . '/cloud_servers/user'; 80 | $users = $this->getApi()->dataGet($url); 81 | if (isset($users['users']['users'])) return $users['users']['users']; 82 | return []; 83 | } 84 | 85 | /** 86 | * Returns the password if it's still available. 87 | * After the password has been received it will 88 | * be permanently deleted from the Nitrado database. 89 | * 90 | * @return mixed 91 | */ 92 | public function getInitialPassword() { 93 | $url = 'services/' . $this->getId() . '/cloud_servers/password'; 94 | $password = $this->getApi()->dataGet($url); 95 | 96 | if (isset($password['password'])) { 97 | return $password['password']; 98 | } 99 | 100 | return null; 101 | } 102 | 103 | /** 104 | * Boots a turned down server. 105 | * 106 | * @return string 107 | */ 108 | public function doBoot() { 109 | $url = 'services/' . $this->getId() . '/cloud_servers/boot'; 110 | return $this->getApi()->dataPost($url); 111 | } 112 | 113 | /** 114 | * Sends a shutdown command via ACPI. 115 | * 116 | * @return string 117 | */ 118 | public function doShutdown() { 119 | $url = 'services/' . $this->getId() . '/cloud_servers/shutdown'; 120 | return $this->getApi()->dataPost($url); 121 | } 122 | 123 | /** 124 | * Sends a reboot command via ACPI. 125 | * 126 | * @return string 127 | */ 128 | public function doReboot() { 129 | $url = 'services/' . $this->getId() . '/cloud_servers/reboot'; 130 | return $this->getApi()->dataPost($url); 131 | } 132 | 133 | /** 134 | * This method resets your server immediately. 135 | * This action might result in data loss. 136 | * 137 | * @return string 138 | */ 139 | public function doHardReset() { 140 | $url = 'services/' . $this->getId() . '/cloud_servers/hard_reset'; 141 | return $this->getApi()->dataPost($url); 142 | } 143 | 144 | /** 145 | * This method reboots your server in rescue mode. 146 | * This action might result in data loss. 147 | * 148 | * @return string 149 | */ 150 | public function doRescue() { 151 | $url = 'services/' . $this->getId() . '/cloud_servers/rescue'; 152 | return $this->getApi()->dataPost($url); 153 | } 154 | 155 | /** 156 | * This method leaves the rescue mode and reboots the server. 157 | * This action might result in data loss. 158 | * 159 | * @return string 160 | */ 161 | public function doUnrescue() { 162 | $url = 'services/' . $this->getId() . '/cloud_servers/unrescue'; 163 | return $this->getApi()->dataPost($url); 164 | } 165 | 166 | /** 167 | * Returns the noVNC console endpoint. 168 | * 169 | * @return array 170 | */ 171 | public function getConsole() { 172 | $url = 'services/' . $this->getId() . '/cloud_servers/console'; 173 | return $this->getApi()->dataGet($url); 174 | } 175 | 176 | /** 177 | * Changes the PTR record of a specific IPv4 address. 178 | * 179 | * @param string $ip 180 | * @param string $hostname 181 | * @return bool 182 | */ 183 | public function changePTRRecord($ip, $hostname) { 184 | $url = 'services/' . $this->getId() . '/cloud_servers/ptr/' . $ip; 185 | $this->getApi()->dataPost($url, [ 186 | 'hostname' => $hostname 187 | ]); 188 | return true; 189 | } 190 | 191 | /** 192 | * Changes the hostname of the server. 193 | * If no hostname has been provided, it will be reset to default. 194 | * 195 | * @param string $hostname 196 | * @return bool 197 | */ 198 | public function changeHostname($hostname = null) { 199 | $url = 'services/' . $this->getId() . '/cloud_servers/hostname'; 200 | $this->getApi()->dataPost($url, [ 201 | 'hostname' => $hostname 202 | ]); 203 | return true; 204 | } 205 | 206 | /** 207 | * Returns a full list with all available images. 208 | * 209 | * @param Nitrapi $nitrapi 210 | * @return array 211 | */ 212 | public static function getAvailableImages(Nitrapi &$nitrapi) { 213 | $images = $nitrapi->dataGet('/information/cloud_servers/images'); 214 | $imgs = []; 215 | foreach ($images['images'] as $image) { 216 | $imgs[] = new Image($image['id'], $image['name'], $image['is_windows'], $image['default'], $image['has_daemon'], $image['is_daemon_compatible']); 217 | } 218 | return $imgs; 219 | } 220 | 221 | /** 222 | * Returns the daily traffic usage of the last 30 days. 223 | * 224 | * @return array 225 | */ 226 | public function getTrafficStatistics() { 227 | $url = 'services/' . $this->getId() . '/cloud_servers/traffic'; 228 | return $this->getApi()->dataGet($url)['traffic']; 229 | } 230 | 231 | /** 232 | * Returns the Cloud Server resources usages. 233 | * 234 | * @return array 235 | */ 236 | public function getResources($time = '4h') { 237 | $url = 'services/' . $this->getId() . '/cloud_servers/resources'; 238 | return $this->getApi()->dataGet($url, null, [ 239 | 'query' => [ 240 | 'time' => $time 241 | ] 242 | ])['resources']; 243 | } 244 | 245 | /** 246 | * Triggers a reinstallation. 247 | * Optional you can pass a new image. 248 | * 249 | * DANGER! This deletes all your data! 250 | * 251 | * @param Image|null $image 252 | */ 253 | public function doReinstall(Image $image = null) { 254 | $url = 'services/' . $this->getId() . '/cloud_servers/reinstall'; 255 | 256 | $data = []; 257 | if ($image instanceof Image) { 258 | if ($image->isWindows() && !$this->getDetails()->getHardwareInfo()['windows']) { 259 | throw new NitrapiException('You need to rent the windows option to install a windows image.'); 260 | } 261 | 262 | $data['image_id'] = $image->getId(); 263 | } 264 | 265 | $this->getApi()->dataPost($url, $data); 266 | return true; 267 | } 268 | 269 | public function getSupportAuthorization() { 270 | $url = 'services/' . $this->getId() . '/support_authorization'; 271 | 272 | try { 273 | $nitrapi = $this->getApi(); 274 | $result = new SupportAuthorization($nitrapi, $nitrapi->dataGet($url)); 275 | } catch (NitrapiHttpErrorException $e) { 276 | // No SupportAuthorization exists 277 | $result = null; 278 | } 279 | 280 | return $result; 281 | 282 | } 283 | 284 | public function createSupportAuthorization() { 285 | $url = 'services/' . $this->getId() . '/support_authorization'; 286 | 287 | $nitrapi = $this->getApi(); 288 | return new SupportAuthorization($nitrapi, $nitrapi->dataPost($url)); 289 | } 290 | 291 | public function deleteSupportAuthorization() { 292 | $url = 'services/' . $this->getId() . '/support_authorization'; 293 | 294 | try { 295 | $this->getApi()->dataDelete($url); 296 | } catch (NitrapiHttpErrorException $e) { 297 | return false; 298 | } 299 | 300 | return true; 301 | } 302 | } 303 | -------------------------------------------------------------------------------- /lib/Nitrapi/Services/CloudServers/CloudServerDetails.php: -------------------------------------------------------------------------------- 1 | data = $data; 12 | } 13 | 14 | /** 15 | * Returns the current Cloud Server status 16 | * 17 | * @return string 18 | */ 19 | public function getStatus() { 20 | return (string)$this->data['status']; 21 | } 22 | 23 | /** 24 | * Returns the Cloud Server hostname 25 | * 26 | * @return string 27 | */ 28 | public function getHostname() { 29 | return (string)$this->data['hostname']; 30 | } 31 | 32 | /** 33 | * Returns the Dynamic Cloud Server 34 | * 35 | * @return string 36 | */ 37 | public function isDynamic() { 38 | return (bool)$this->data['dynamic']; 39 | } 40 | 41 | /** 42 | * Returns the main ip address of the server 43 | * 44 | * @return string 45 | */ 46 | public function getMainIP() { 47 | foreach ($this->getIPs() as $ip) { 48 | if ($ip['main_ip'] && $ip['version'] == 4) { 49 | return $ip['address']; 50 | } 51 | } 52 | 53 | return null; 54 | } 55 | 56 | /** 57 | * Returns the Cloud Server ips 58 | * 59 | * @return array 60 | */ 61 | public function getIPs() { 62 | return (array)$this->data['ips']; 63 | } 64 | 65 | /** 66 | * Returns the Hardware information 67 | * 68 | * @return array 69 | */ 70 | public function getHardwareInfo() { 71 | return (array)$this->data['hardware']; 72 | } 73 | 74 | /** 75 | * Return true if the initial password is available 76 | * 77 | * @return boolean 78 | */ 79 | public function isPasswordAvailable() { 80 | return (bool)$this->data['password_available']; 81 | } 82 | 83 | /** 84 | * Return true if the bandwdith is currently limited 85 | * 86 | * @return boolean 87 | */ 88 | public function isBandwidthLimited() { 89 | return (bool)$this->data['bandwidth_limited']; 90 | } 91 | 92 | /** 93 | * Returns the ID of the currently installed image. 94 | * 95 | * @return int 96 | */ 97 | public function getImageId() { 98 | return $this->data['image']['id']; 99 | } 100 | 101 | /** 102 | * Returns the name of the currently installed image, as displayed to the user. 103 | * 104 | * @return string 105 | */ 106 | public function getImageName() { 107 | return $this->data['image']['name']; 108 | } 109 | 110 | /** 111 | * Returns true if the Cloud Server has a Nitrapi Daemon instance running. 112 | * 113 | * @return bool 114 | */ 115 | public function hasDaemonSupport() { 116 | return $this->data['daemon_available']; 117 | } 118 | 119 | } -------------------------------------------------------------------------------- /lib/Nitrapi/Services/CloudServers/Firewall/Firewall.php: -------------------------------------------------------------------------------- 1 | service = $service; 26 | $this->refresh(); 27 | } 28 | 29 | /** 30 | * Refresh firewall data 31 | */ 32 | public function refresh() { 33 | $url = "/services/".$this->service->getId()."/cloud_servers/firewall"; 34 | $firewall = $this->service->getApi()->dataGet($url)['firewall']; 35 | 36 | $this->enabled = $firewall['enabled']; 37 | $this->rules = $firewall['rules']; 38 | } 39 | 40 | /** 41 | * Returns the Firewall Status 42 | * 43 | * @return bool 44 | */ 45 | public function isEnabled() { 46 | return $this->enabled; 47 | } 48 | 49 | /** 50 | * Return the firewall rules 51 | * 52 | * @return array 53 | */ 54 | public function getRules() { 55 | return $this->rules; 56 | } 57 | 58 | /** 59 | * Deletes a specific rule by number. 60 | * 61 | * @param $number 62 | * @return bool 63 | */ 64 | public function deleteRule($number) { 65 | $url = "/services/".$this->service->getId()."/cloud_servers/firewall/remove"; 66 | $this->service->getApi()->dataDelete($url, [ 67 | 'number' => $number 68 | ]); 69 | $this->refresh(); 70 | return true; 71 | } 72 | 73 | /** 74 | * Enables the Firewall. 75 | * 76 | * @return bool 77 | */ 78 | public function enableFirewall() { 79 | $url = "/services/".$this->service->getId()."/cloud_servers/firewall/enable"; 80 | $this->service->getApi()->dataPost($url); 81 | $this->refresh(); 82 | return true; 83 | } 84 | 85 | /** 86 | * Disables the Firewall. 87 | * 88 | * @return bool 89 | */ 90 | public function disableFirewall() { 91 | $url = "/services/".$this->service->getId()."/cloud_servers/firewall/disable"; 92 | $this->service->getApi()->dataPost($url); 93 | $this->refresh(); 94 | return true; 95 | } 96 | 97 | /** 98 | * Creates a new Firewall Rule. 99 | * 100 | * @param $sourceIp string 101 | * @param $targetIp string 102 | * @param $targetPort integer 103 | * @param $protocol string 104 | * @param $comment string 105 | * @return bool 106 | */ 107 | public function addRule($sourceIp = null, $targetIp = null, $targetPort = null, $protocol = 'tcp', $comment = 'Firewall rule') { 108 | $url = "/services/".$this->service->getId()."/cloud_servers/firewall/add"; 109 | $this->service->getApi()->dataPost($url, [ 110 | 'source_ip' => $sourceIp, 111 | 'target_ip' => $targetIp, 112 | 'target_port' => $targetPort, 113 | 'protocol' => $protocol, 114 | 'comment' => $comment, 115 | ]); 116 | $this->refresh(); 117 | return true; 118 | } 119 | 120 | } 121 | -------------------------------------------------------------------------------- /lib/Nitrapi/Services/CloudServers/Image.php: -------------------------------------------------------------------------------- 1 | id = $id; 16 | $this->name = $name; 17 | $this->isWindows = $isWindows; 18 | $this->default = $default; 19 | $this->hasDaemon = $hasDaemon; 20 | $this->isDaemonCompatible = $isDaemonCompatible; 21 | } 22 | 23 | public function getId() { 24 | return $this->id; 25 | } 26 | 27 | public function getName() { 28 | return $this->name; 29 | } 30 | 31 | public function isWindows() { 32 | return $this->isWindows; 33 | } 34 | 35 | public function isDefault() { 36 | return $this->default; 37 | } 38 | 39 | public function hasDaemon() { 40 | return $this->hasDaemon; 41 | } 42 | 43 | public function isDaemonCompatible() { 44 | return $this->isDaemonCompatible; 45 | } 46 | } -------------------------------------------------------------------------------- /lib/Nitrapi/Services/CloudServers/System/Systemd.php: -------------------------------------------------------------------------------- 1 | service = $service; 21 | } 22 | 23 | /** 24 | * Returns a SSE (server-send event) stream URL, which will stream 25 | * changes on the Systemd services. 26 | * 27 | * @param null|string $unit a unit to filter at 28 | * @param bool $initialState to send an initial state for all units 29 | * @return string The URL 30 | */ 31 | public function changeFeedUrl($unit=null, $initialState=false) { 32 | /* @var $apiResults array[][] */ 33 | $apiResult = $this->service->getApi()->dataGet( 34 | $this->url('/changefeed'), [ 35 | 'unit' => $unit, 36 | 'initial_state' => $initialState 37 | ]); 38 | return $apiResult['token']['url']; 39 | } 40 | 41 | /** 42 | * Reset all units in failure state back to normal. 43 | * 44 | * @return void 45 | */ 46 | public function resetAllFailedUnits() { 47 | $this->service->getApi()->dataPost($this->url('/reset_all_failed')); 48 | } 49 | 50 | /** 51 | * Reload the Systemd daemon 52 | * 53 | * @return void 54 | */ 55 | public function reloadDaemon() { 56 | $this->service->getApi()->dataPost($this->url('/daemon_reload')); 57 | } 58 | 59 | /** 60 | * Lists all the units Systemd manages. The resulting array will be sorted 61 | * by type and name. 62 | * 63 | * @return Unit[] the list of units 64 | */ 65 | public function getUnits() { 66 | /* @var $apiResults array[][] */ 67 | $apiResults = $this->service->getApi()->dataGet($this->url('')); 68 | $units = []; 69 | foreach ($apiResults['units'] as $data) { 70 | $units[] = new Unit($this, $data); 71 | } 72 | 73 | // Sort 74 | usort($units, function(Unit $a, Unit $b) { 75 | $aType = explode('.', $a->getName()); 76 | $bType = explode('.', $b->getName()); 77 | 78 | $aType = end($aType); 79 | $bType = end($bType); 80 | 81 | if ($aType !== $bType) { 82 | return strcmp($aType, $bType); 83 | } 84 | 85 | return strcmp(strtolower($a->getName()), strtolower($b->getName())); 86 | }); 87 | 88 | return $units; 89 | } 90 | 91 | private function url($endpoint) { 92 | return '/services/' . $this->service->getId() . '/cloud_servers/system/units' . $endpoint; 93 | } 94 | } -------------------------------------------------------------------------------- /lib/Nitrapi/Services/CloudServers/System/Unit.php: -------------------------------------------------------------------------------- 1 | systemd = $systemd; 41 | $this->data = $data; 42 | } 43 | 44 | /** 45 | * Implement the getter methods for the $data array. 46 | * 47 | * @example $app->getJobType(); 48 | * 49 | * @param string $name The method name 50 | * @param array $_ params, which are not used 51 | * @return mixed The resulting value from $data 52 | * @throws DataMissingException if the key in $data does not exist. 53 | * @throws \BadMethodCallException if the method does not exits. 54 | */ 55 | public function __call($name, $_) { 56 | if (in_array($name, ['enable', 'disable', 'mask', 'umask'], true)) { 57 | /* @var array[][] $apiResponse */ 58 | $apiResponse = $this->api()->dataPost($this->url('/' . $name)); 59 | return $apiResponse['changes']; 60 | } 61 | 62 | if (in_array($name, ['start', 'stop', 'restart', 'reload'], true)) { 63 | /* @var array[][] $apiResponse */ 64 | $apiResponse = $this->api()->dataPost($this->url('/' . $name)); 65 | return $apiResponse['job']; 66 | } 67 | 68 | if (preg_match('/get(.+)/', $name) === 0) { 69 | throw new \BadMethodCallException("Method $name not found."); 70 | } 71 | $method = strtolower($name[3]) . substr($name, 4); 72 | $key = strtolower(preg_replace('/(?data[$key])) return $this->data[$key]; 74 | throw new DataMissingException('The key ' . $key . ' does not exist. Please set first.'); 75 | } 76 | 77 | /** 78 | * Resets the failure state of a unit back to normal. 79 | * 80 | * @return void 81 | */ 82 | public function resetFailed() { 83 | $this->api()->dataPost($this->url('/reset_failed')); 84 | } 85 | 86 | /** 87 | * Send a POSIX signal to the process(es) running in a unit. 88 | * 89 | * @param string $who which process to send the kill signal 90 | * @param int $signal which signal will be send 91 | * @return void 92 | */ 93 | public function kill($who='all', $signal=15) { 94 | $this->api()->dataPost($this->url('/kill'), [ 95 | 'who' => $who, 96 | 'signal' => $signal 97 | ]); 98 | } 99 | 100 | 101 | private function url($endpoint) { 102 | return '/services/' . $this->systemd->service->getId() . '/cloud_servers/system/units/' . $this->getName() . $endpoint; 103 | } 104 | 105 | private function api() { 106 | return $this->systemd->service->getApi(); 107 | } 108 | } 109 | 110 | -------------------------------------------------------------------------------- /lib/Nitrapi/Services/Gameservers/Adminlist.php: -------------------------------------------------------------------------------- 1 | service = $service; 14 | } 15 | 16 | /** 17 | * Returns the admin list from the game server. 18 | * 19 | * @return array 20 | */ 21 | public function getAdminlist() { 22 | $url = "/services/".$this->service->getId()."/gameservers/games/adminlist"; 23 | $whitelist = $this->service->getApi()->dataGet($url); 24 | 25 | return $whitelist; 26 | } 27 | 28 | /** 29 | * Adds a player as admin to the game server. 30 | * 31 | * @param $identifier 32 | * @return string 33 | */ 34 | public function addAdminlist($identifier) { 35 | $url = "/services/".$this->service->getId()."/gameservers/games/adminlist"; 36 | return $this->service->getApi()->dataPost($url, [ 37 | 'identifier' => $identifier 38 | ]); 39 | } 40 | 41 | /** 42 | * Removes a admin player from the game server. 43 | * 44 | * @param $identifier 45 | * @return string 46 | */ 47 | public function removeAdminlist($identifier) { 48 | $url = "/services/".$this->service->getId()."/gameservers/games/adminlist"; 49 | return $this->service->getApi()->dataDelete($url, [ 50 | 'identifier' => $identifier 51 | ]); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /lib/Nitrapi/Services/Gameservers/ApplicationServer/ApplicationServer.php: -------------------------------------------------------------------------------- 1 | service = $service; 17 | } 18 | 19 | /** 20 | * Sends a ping to the application server 21 | * 22 | * @return bool 23 | */ 24 | public function ping() { 25 | try { 26 | $url = "/services/".$this->service->getId()."/gameservers/app_server"; 27 | $this->service->getApi()->dataGet($url); 28 | return true; 29 | } catch (\Exception $e) {} 30 | 31 | return false; 32 | } 33 | 34 | /** 35 | * Sends a command to the app server 36 | * 37 | * @param $command string 38 | * @return bool 39 | */ 40 | public function sendCommand($command) { 41 | $url = "/services/".$this->service->getId()."/gameservers/app_server/command"; 42 | $this->service->getApi()->dataPost($url, array( 43 | "command" => $command 44 | )); 45 | return true; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /lib/Nitrapi/Services/Gameservers/BackupManager.php: -------------------------------------------------------------------------------- 1 | service = $service; 14 | } 15 | 16 | 17 | /** 18 | * Returns details about the backup archive 19 | * 20 | * @return object 21 | */ 22 | public function info() { 23 | 24 | $url = 'services/' . $this->service->getId() . '/backups/info'; 25 | $response = $this->service->getApi()->dataGet($url); 26 | 27 | if (!isset($response)) { 28 | throw new NitrapiErrorException('Unable to fetch repository details'); 29 | } 30 | 31 | return $response; 32 | } 33 | 34 | /** 35 | * List archives available in the repository 36 | * 37 | * @return array 38 | */ 39 | public function list() { 40 | 41 | $url = 'services/' . $this->service->getId() . '/backups'; 42 | $response = $this->service->getApi()->dataGet($url); 43 | 44 | if (!isset($response)) { 45 | throw new NitrapiErrorException('No backup have been returned from API.'); 46 | } 47 | 48 | return $response; 49 | } 50 | 51 | /** 52 | * Create a backup 53 | * 54 | * @param string $type type of backup 55 | * @return bool 56 | */ 57 | public function create($type = 'game') { 58 | 59 | $url = 'services/' . $this->service->getId() . '/backups'; 60 | $response = $this->service->getApi()->dataPost($url, [ 61 | 'type' => $type 62 | ]); 63 | 64 | if (!isset($response) || $response['status'] != 'success') { 65 | throw new NitrapiErrorException('Backup creation failed!'); 66 | } 67 | 68 | return $response; 69 | } 70 | 71 | 72 | /** 73 | * Restore a backup 74 | * 75 | * @param string $backup name of the archive 76 | * @return bool 77 | */ 78 | public function extract($backup, $paths = []) { 79 | $url = 'services/' . $this->service->getId() . '/backups/extract'; 80 | $response = $this->service->getApi()->dataPost($url, [ 81 | 'name' => $backup, 82 | 'paths' => $paths 83 | ]); 84 | 85 | 86 | if (!isset($response)) { 87 | throw new NitrapiErrorException('Backup restore failed!'); 88 | } 89 | 90 | return $response; 91 | } 92 | 93 | /** 94 | * Deletes a archive 95 | * 96 | * @param string $backup name of the archive 97 | * @return bool 98 | */ 99 | public function delete($backup) { 100 | $url = 'services/' . $this->service->getId() . '/backups'; 101 | $response = $this->service->getApi()->dataDelete($url, [], [], [ 102 | 'query' => [ 103 | 'prefix' => $backup 104 | ] 105 | ]); 106 | 107 | if (!isset($response)) { 108 | throw new NitrapiErrorException('Backup deletion failed!'); 109 | } 110 | 111 | return $response; 112 | } 113 | } 114 | -------------------------------------------------------------------------------- /lib/Nitrapi/Services/Gameservers/Banlist.php: -------------------------------------------------------------------------------- 1 | service = $service; 14 | } 15 | 16 | /** 17 | * Get the ban list of the game server. 18 | * 19 | * @return array 20 | */ 21 | public function getBanlist() { 22 | $url = "/services/".$this->service->getId()."/gameservers/games/banlist"; 23 | $whitelist = $this->service->getApi()->dataGet($url); 24 | 25 | return $whitelist; 26 | } 27 | 28 | /** 29 | * Adds a player to the ban list. 30 | * 31 | * @param $identifier 32 | * @return string 33 | */ 34 | public function addBanlist($identifier) { 35 | $url = "/services/".$this->service->getId()."/gameservers/games/banlist"; 36 | return $this->service->getApi()->dataPost($url, [ 37 | 'identifier' => $identifier 38 | ]); 39 | } 40 | 41 | /** 42 | * Removes a player from the ban list. 43 | * 44 | * @param $identifier 45 | * @return string 46 | */ 47 | public function removeBanlist($identifier) { 48 | $url = "/services/".$this->service->getId()."/gameservers/games/banlist"; 49 | return $this->service->getApi()->dataDelete($url, [ 50 | 'identifier' => $identifier 51 | ]); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /lib/Nitrapi/Services/Gameservers/CallbackHandler.php: -------------------------------------------------------------------------------- 1 | service = $service; 11 | } 12 | 13 | public function getService() { 14 | return $this->service; 15 | } 16 | 17 | /** 18 | * Trigger if a game has been installed 19 | * @param string $gameShort 20 | * @return bool 21 | */ 22 | public function installed($gameShort) { 23 | $url = "/services/".$this->getService()->getId()."/gameservers/callback/installed"; 24 | $this->getService()->getApi()->dataPost($url, array( 25 | "game_short" => $gameShort 26 | )); 27 | return true; 28 | } 29 | 30 | /** 31 | * Trigger if a game has been uninstalled 32 | * @param string $gameShort 33 | * @return bool 34 | */ 35 | public function uninstalled($gameShort) { 36 | $url = "/services/".$this->getService()->getId()."/gameservers/callback/uninstalled"; 37 | $this->getService()->getApi()->dataPost($url, array( 38 | "game_short" => $gameShort 39 | )); 40 | return true; 41 | } 42 | 43 | /** 44 | * Trigger if the service has been restarted 45 | * @return bool 46 | */ 47 | public function restarted() { 48 | $url = "/services/".$this->getService()->getId()."/gameservers/callback/restarted"; 49 | $this->getService()->getApi()->dataPost($url); 50 | return true; 51 | } 52 | 53 | /** 54 | * Trigger if the complete service has been deleted 55 | * @return bool 56 | */ 57 | public function deleted() { 58 | $url = "/services/".$this->getService()->getId()."/gameservers/callback/deleted"; 59 | $this->getService()->getApi()->dataPost($url); 60 | return true; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /lib/Nitrapi/Services/Gameservers/CurseforgeWorkshop.php: -------------------------------------------------------------------------------- 1 | service = $service; 12 | } 13 | 14 | public function searchMods($searchString, $page = 0, $sortBy = 'popularity') { 15 | $url = $this->baseEndpointUrl() . "/search_mods"; 16 | $query = [ 17 | 'page' => $page, 18 | 'sort_by' => $sortBy 19 | ]; 20 | if (!empty($searchString)) { 21 | $query['search'] = $searchString; 22 | } 23 | return $this->service->getApi()->dataGet($url, null, ['query' => $query]); 24 | } 25 | 26 | public function getInstalledMods() { 27 | $url = $this->baseEndpointUrl() . "/installed_mods"; 28 | return $this->service->getApi()->dataGet($url); 29 | } 30 | 31 | private function baseEndpointUrl() { 32 | return "/services/".$this->service->getId()."/gameservers/curseforge_workshop"; 33 | } 34 | } -------------------------------------------------------------------------------- /lib/Nitrapi/Services/Gameservers/CustomerSettings/CustomerSettingNotFoundException.php: -------------------------------------------------------------------------------- 1 | service = $service; 20 | $this->settings = &$settings; 21 | } 22 | 23 | /** 24 | * Return the default value for a customer setting. If no parameter is 25 | * provided, all defaults (with the appropriate categories) will be returned. 26 | * If a category is provided, all settings in this category will be 27 | * returned. If category and key is provided, the actual value is 28 | * returned. 29 | * 30 | * @see CustomerSettingsDBSetting::setDefaultValue() 31 | * 32 | * @param string|null $category The setting category 33 | * @param string|null $key The setting key 34 | * @return array|string The default values 35 | * 36 | * @throws CustomerSettingNotFoundException 37 | */ 38 | public function getDefaults($category=null, $key=null) { 39 | // Refresh the cache. 40 | if ($this->defaults === null) { 41 | $this->defaults = $this->service->getApi()->dataGet('services/' . $this->service->getId() . '/gameservers/settings/defaults')['settings']; 42 | } 43 | 44 | if ($category !== null && !isset($this->defaults[$category])) { 45 | throw new CustomerSettingNotFoundException('Category "'.$category.'" not found'); 46 | } 47 | 48 | if ($key !== null && !isset($this->defaults[$category][$key])) { 49 | throw new CustomerSettingNotFoundException('Setting "'.$key.'" in category "'.$category.'" not found'); 50 | } 51 | 52 | // Return a single default value 53 | if ($category !== null && $key !== null) { 54 | return $this->defaults[$category][$key]; 55 | } 56 | 57 | // Return a whole category 58 | if ($category !== null) { 59 | return $this->defaults[$category]; 60 | } 61 | 62 | // Return all default values with categories 63 | return $this->defaults; 64 | } 65 | 66 | public function readSetting($category = null, $key = null) { 67 | if (!empty($category) && !$this->hasCategory($category)) { 68 | throw new CustomerSettingNotFoundException("Category \"".$category."\" not found"); 69 | } 70 | 71 | if (!empty($key) && !$this->hasSetting($category, $key)) { 72 | throw new CustomerSettingNotFoundException("Setting \"".$key."\" in category \"".$category."\" not found"); 73 | } 74 | 75 | if (!empty($category) && !empty($key)) { 76 | return $this->settings[$category][$key]; 77 | } 78 | 79 | if (!empty($category)) { 80 | return $this->settings[$category]; 81 | } 82 | 83 | return $this->settings; 84 | } 85 | 86 | public function writeSetting($category, $key, $value) { 87 | if (!$this->hasSetting($category, $key)) { 88 | throw new CustomerSettingNotFoundException("Setting \"".$key."\" in category \"".$category."\" not found"); 89 | } 90 | 91 | $this->service->getApi()->dataPost("services/" . $this->service->getId() . "/gameservers/settings", [ 92 | "category" => $category, 93 | "key" => $key, 94 | "value" => $value, 95 | ]); 96 | 97 | // Update internal storage 98 | $this->settings[$category][$key] = $value; 99 | 100 | return true; 101 | } 102 | 103 | public function getConfigSets() { 104 | return $this->service->getApi()->dataGet("services/" . $this->service->getId() . "/gameservers/settings/sets")['sets']; 105 | } 106 | 107 | public function restoreConfigset($id) { 108 | $this->service->getApi()->dataPost("services/" . $this->service->getId() . "/gameservers/settings/sets/".$id."/restore"); 109 | return true; 110 | } 111 | 112 | public function deleteConfigset($id) { 113 | $this->service->getApi()->dataDelete("services/" . $this->service->getId() . "/gameservers/settings/sets/".$id); 114 | return true; 115 | } 116 | 117 | public function createConfigset($name = null) { 118 | $settings = (!empty($name)) ? ['name' => $name] : []; 119 | 120 | $this->service->getApi()->dataPost("services/" . $this->service->getId() . "/gameservers/settings/sets", $settings); 121 | return true; 122 | } 123 | 124 | public function resetSettings() { 125 | $this->service->getApi()->dataDelete("services/" . $this->service->getId() . "/gameservers/settings"); 126 | return true; 127 | } 128 | 129 | public function hasCategory($category) { 130 | if (!isset($this->settings[$category])) { 131 | return false; 132 | } 133 | 134 | return true; 135 | } 136 | 137 | public function hasSetting($category, $key) { 138 | if (!$this->hasCategory($category)) { 139 | return false; 140 | } 141 | 142 | if (!isset($this->settings[$category][$key])) { 143 | return false; 144 | } 145 | 146 | return true; 147 | } 148 | } 149 | -------------------------------------------------------------------------------- /lib/Nitrapi/Services/Gameservers/Games/Arkse.php: -------------------------------------------------------------------------------- 1 | service->getId() . "/gameservers/games/arkse/modlist"; 16 | return $this->service->getApi()->dataGet($url)['modlist']; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /lib/Nitrapi/Services/Gameservers/Games/Corekeeper.php: -------------------------------------------------------------------------------- 1 | service = $service; 21 | } 22 | 23 | public function getGame() { 24 | return $this->game; 25 | } 26 | 27 | /** 28 | * @return mixed 29 | * @throws \Nitrapi\Common\Exceptions\NitrapiHttpErrorException 30 | */ 31 | public function getInfo() { 32 | $url = "services/" . $this->service->getId() . "/gameservers/games/" . $this->getGame(); 33 | return $this->service->getApi()->dataGet($url); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /lib/Nitrapi/Services/Gameservers/Games/Minecraft.php: -------------------------------------------------------------------------------- 1 | service->getId() . "/gameservers/games/minecraft/chunkfix"; 18 | $this->service->getApi()->dataPost($url, [ 19 | 'world' => $world, 20 | 'limit' => $limit, 21 | ]); 22 | 23 | return true; 24 | } 25 | 26 | /** 27 | * Rendering overview map 28 | * 29 | * @return bool 30 | */ 31 | public function renderOverviewMap() { 32 | $url = "services/" . $this->service->getId() . "/gameservers/games/minecraft/overviewmap_render"; 33 | $this->service->getApi()->dataPost($url); 34 | 35 | return true; 36 | } 37 | 38 | /** 39 | * Return the minecraft overview map log file 40 | * 41 | * @return mixed 42 | */ 43 | public function getOverviewMapLog() { 44 | $url = "services/" . $this->service->getId() . "/gameservers/games/minecraft/overviewmap_log"; 45 | $result = $this->service->getApi()->dataGet($url); 46 | 47 | if (isset($result['log'])) { 48 | return $result['log']; 49 | } 50 | 51 | return null; 52 | } 53 | 54 | /** 55 | * Changing some overview map settings 56 | * 57 | * @param bool|false $enabled 58 | * @param bool|true $signs 59 | * @param $ 60 | * @return bool 61 | */ 62 | public function setOverviewMap($enabled = false, $signs = true, $ipsonly = null, $reset = null, $version = 'pre_1.13') { 63 | #If reset is null, do not change anything. If reset is bool val, validate 64 | if(is_bool($reset)){ 65 | $reset = (int)($reset); 66 | } else { 67 | $reset = null; 68 | } 69 | $url = "services/" . $this->service->getId() . "/gameservers/games/minecraft/overviewmap"; 70 | $this->service->getApi()->dataPost($url, [ 71 | 'enabled' => (int)$enabled, 72 | 'version' => $version, 73 | 'reset' => $reset, 74 | 'ipsonly' => $ipsonly, 75 | ]); 76 | 77 | return true; 78 | } 79 | 80 | /** 81 | * Resets the overviewmap 82 | * @return bool 83 | */ 84 | public function resetOverviewMap() { 85 | $url = "services/" . $this->service->getId() . "/gameservers/games/minecraft/overviewmap"; 86 | $response = $this->service->getApi()->dataPost($url, [ 87 | 'reset' => 'true' 88 | ]); 89 | 90 | return true; 91 | } 92 | 93 | /** 94 | * Changing bungeecord settings 95 | * 96 | * @param bool|false $enabled 97 | * @param bool|false $only 98 | * @param string $firewall 99 | * @param null $ip 100 | * @return bool 101 | */ 102 | public function setBungeeCord($enabled = false, $only = false, $firewall = 'off', $ip = null) { 103 | $url = "services/" . $this->service->getId() . "/gameservers/games/minecraft/bungeecord"; 104 | $this->service->getApi()->dataPost($url, [ 105 | 'enabled' => (int)$enabled, 106 | 'only' => (int)$only, 107 | 'firewall' => $firewall, 108 | 'firewall_ip' => $ip, 109 | ]); 110 | 111 | return true; 112 | } 113 | 114 | /** 115 | * Changing rtk settings 116 | * 117 | * @param bool|false $enabled 118 | * @param null $username 119 | * @param null $password 120 | * @return bool 121 | */ 122 | public function setRemoteToolkit($enabled = false, $username = null, $password = null) { 123 | $url = "services/" . $this->service->getId() . "/gameservers/games/minecraft/rtk"; 124 | $this->service->getApi()->dataPost($url, [ 125 | 'enabled' => (int)$enabled, 126 | 'username' => $username, 127 | 'password' => $password, 128 | ]); 129 | 130 | return true; 131 | } 132 | 133 | /** 134 | * Creates a new backup of a specified world 135 | * 136 | * @param $world 137 | * @return bool 138 | */ 139 | public function createBackup($world) { 140 | $url = "services/" . $this->service->getId() . "/gameservers/games/minecraft/backup"; 141 | $this->service->getApi()->dataPost($url, [ 142 | 'world' => $world 143 | ]); 144 | 145 | return true; 146 | } 147 | 148 | /** 149 | * Deletes a specified backup 150 | * 151 | * @param $backup 152 | * @return bool 153 | */ 154 | public function deleteBackup($backup) { 155 | $url = "services/" . $this->service->getId() . "/gameservers/games/minecraft/backup/" . $backup; 156 | $this->service->getApi()->dataDelete($url); 157 | 158 | return true; 159 | } 160 | 161 | /** 162 | * Restore a specified backup 163 | * 164 | * @param $backup 165 | * @return bool 166 | */ 167 | public function restoreBackup($backup) { 168 | $url = "services/" . $this->service->getId() . "/gameservers/games/minecraft/backup/" . $backup . "/restore"; 169 | $this->service->getApi()->dataPost($url); 170 | 171 | return true; 172 | } 173 | 174 | /** 175 | * Installs a specific Minecraft Version 176 | * 177 | * @param $md5 178 | * @return bool 179 | */ 180 | public function switchVersion($md5) { 181 | $url = "services/" . $this->service->getId() . "/gameservers/games/minecraft/change_version"; 182 | $this->service->getApi()->dataPost($url, [ 183 | 'md5' => $md5 184 | ]); 185 | 186 | return true; 187 | } 188 | 189 | /** 190 | * Returns the formated UUID id of the specific minecraft user 191 | * 192 | * @param $username 193 | * @return array 194 | */ 195 | public function getUUID($username) { 196 | $url = "services/" . $this->service->getId() . "/gameservers/games/minecraft/uuid"; 197 | return $this->service->getApi()->dataGet($url, null, [ 198 | 'query' => [ 199 | 'username' => $username 200 | ] 201 | ])['user']; 202 | } 203 | 204 | /** 205 | * Returns the avatar as base64 encoded content of the specific minecraft user 206 | * Note: case sensitive! 207 | * 208 | * @param $username 209 | * @return array 210 | */ 211 | public function getAvatar($username) { 212 | $url = "services/" . $this->service->getId() . "/gameservers/games/minecraft/avatar"; 213 | return $this->service->getApi()->dataGet($url, null, [ 214 | 'query' => [ 215 | 'username' => $username 216 | ] 217 | ])['user']; 218 | } 219 | 220 | /** 221 | * Returns all installed Bukkit/Spigot Plugins at Minecraft Bukkit 222 | * 223 | * @return array 224 | */ 225 | public function getPlugins() { 226 | $url = "services/" . $this->service->getId() . "/gameservers/games/minecraft/plugins"; 227 | $result = $this->service->getApi()->dataGet($url); 228 | 229 | if (isset($result['plugins'])) { 230 | return $result['plugins']; 231 | } 232 | 233 | return []; 234 | } 235 | } 236 | -------------------------------------------------------------------------------- /lib/Nitrapi/Services/Gameservers/Games/TS3Musicbot.php: -------------------------------------------------------------------------------- 1 | service->getId() . "/gameservers/games/ts3musicbot/reinstall"; 16 | $this->service->getApi()->dataPost($url); 17 | 18 | return true; 19 | } 20 | 21 | } -------------------------------------------------------------------------------- /lib/Nitrapi/Services/Gameservers/Games/Valheim.php: -------------------------------------------------------------------------------- 1 | data = $data; 12 | } 13 | 14 | /** 15 | * Return true if the game can manage world backups. 16 | * 17 | * @return boolean true if the game has world backups 18 | */ 19 | public function hasWorldBackups() { 20 | return $this->data['has_world_backups']; 21 | } 22 | 23 | public function hasBackups() { 24 | return $this->data['has_backups']; 25 | } 26 | 27 | public function hasPackages() { 28 | return $this->data['has_packages']; 29 | } 30 | 31 | /** 32 | * Redirect the output stream from a running service. 33 | * 34 | * This feature is deprecated and should not be used any more. We keep 35 | * it here for compatibility concerns, but will be removed in the 36 | * future. 37 | * 38 | * @deprecated 39 | * @return bool if the gameserver supports the old application server 40 | */ 41 | public function hasApplicationServer() { 42 | return $this->data['has_application_server']; 43 | } 44 | 45 | /** 46 | * Replacement feature for the deprecated application server. 47 | * 48 | * The container websockets allows to access a websocket server on the 49 | * hostsystem on 'wss://[hostsystem].gamedata.io:34882'. This websocket 50 | * provide the STDOUT and STDERR stream, directly from within the 51 | * container. It also supports events like attaching to a container or 52 | * a status event when the container died. you can also use this 53 | * websocket to send commands to a container. For that, just send a 54 | * JSON message with "command" and "container" keys. 55 | * 56 | * @return bool true if the gameserver supports container websockets 57 | */ 58 | public function hasContainerWebsocket() { 59 | return $this->data['has_container_websocket']; 60 | } 61 | 62 | public function hasFileBrowser() { 63 | return $this->data['has_file_browser']; 64 | } 65 | 66 | public function hasExpertMode() { 67 | return $this->data['has_expert_mode']; 68 | } 69 | 70 | public function hasDatabase() { 71 | return $this->data['has_database']; 72 | } 73 | 74 | public function hasRestartMessageSupport() { 75 | return $this->data['has_restart_message_support']; 76 | } 77 | 78 | public function hasPlayerManagement() { 79 | return $this->data['has_playermanagement_feature']; 80 | } 81 | 82 | public function hasPluginSystem() { 83 | return $this->data['has_plugin_system']; 84 | } 85 | 86 | public function hasRCon() { 87 | return $this->data['has_rcon']; 88 | } 89 | 90 | public function hasFTP() { 91 | return $this->data['has_ftp']; 92 | } 93 | 94 | public function hasCurseforgeWorkshop() { 95 | return $this->data['has_curseforge_workshop']; 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /lib/Nitrapi/Services/Gameservers/LicenseKeys/LicenseKey.php: -------------------------------------------------------------------------------- 1 | setService($service); 24 | } 25 | 26 | public function getId() { 27 | return (int)$this->id; 28 | } 29 | 30 | public function getKey() { 31 | return $this->key; 32 | } 33 | 34 | public function getType() { 35 | return $this->type; 36 | } 37 | 38 | public function getGame() { 39 | return $this->game_short; 40 | } 41 | 42 | public function getAssignedDateTime() { 43 | return new \DateTime($this->assigned_at); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /lib/Nitrapi/Services/Gameservers/LicenseKeys/LicenseKeyFactory.php: -------------------------------------------------------------------------------- 1 | setService($service); 24 | 25 | } 26 | 27 | public function getId() { 28 | return (int)$this->id; 29 | } 30 | 31 | public function getUsername() { 32 | return $this->username; 33 | } 34 | 35 | public function getPassword() { 36 | return $this->password; 37 | } 38 | 39 | public function getSchema() { 40 | return $this->schema; 41 | } 42 | 43 | public function getHostname() { 44 | return $this->hostname; 45 | } 46 | 47 | /** 48 | * Imports a sql from uri 49 | * 50 | * @param $uri 51 | * @return bool 52 | */ 53 | public function import($uri) { 54 | $url = "/services/".$this->getService()->getId()."/gameservers/mariadbs/".$this->getId()."/import"; 55 | $this->getService()->getApi()->dataPost($url, array( 56 | "uri" => $uri 57 | )); 58 | return true; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /lib/Nitrapi/Services/Gameservers/MariaDBs/MariaDBFactory.php: -------------------------------------------------------------------------------- 1 | getApi()->dataGet("services/" . $service->getId() . "/gameservers/mariadbs/" . $id); 11 | 12 | return new MariaDB($service, $data['database']); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /lib/Nitrapi/Services/Gameservers/Packages/Package.php: -------------------------------------------------------------------------------- 1 | name = $name; 17 | $this->description = $description; 18 | $this->status = $status; 19 | $this->service = $service; 20 | $this->version = $version; 21 | $this->patches = $patches; 22 | $this->dependencies = $dependencies; 23 | } 24 | 25 | public function getName() { 26 | return $this->name; 27 | } 28 | 29 | public function getDescription() { 30 | return $this->description; 31 | } 32 | 33 | public function getStatus() { 34 | return $this->status; 35 | } 36 | 37 | public function getVersion() { 38 | return $this->version; 39 | } 40 | 41 | public function getPatches() { 42 | return $this->patches; 43 | } 44 | 45 | public function getDependencies() { 46 | return $this->dependencies; 47 | } 48 | 49 | public function install($version) { 50 | $url = "/services/".$this->service->getId()."/gameservers/packages/install"; 51 | return $this->service->getApi()->dataPost($url, array( 52 | "package" => $this->name, 53 | "version" => $version 54 | )); 55 | } 56 | public function uninstall() { 57 | $url = "/services/".$this->service->getId()."/gameservers/packages/uninstall"; 58 | return $this->service->getApi()->dataDelete($url, array( 59 | "package" => $this->name 60 | )); 61 | } 62 | public function reinstall() { 63 | $url = "/services/".$this->service->getId()."/gameservers/packages/reinstall"; 64 | return $this->service->getApi()->dataPut($url, array( 65 | "package" => $this->name 66 | )); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /lib/Nitrapi/Services/Gameservers/Packages/PackageManager.php: -------------------------------------------------------------------------------- 1 | service = $service; 16 | } 17 | 18 | public function availablePackages() { 19 | try { 20 | $url = "/services/".$this->service->getId()."/gameservers/packages/"; 21 | $packages = $this->service->getApi()->dataGet($url); 22 | } catch (NitrapiException $e) { 23 | throw new NitrapiException($e->getMessage()); 24 | } 25 | 26 | if (!is_array($packages)) 27 | throw new NitrapiException($packages); 28 | 29 | $packageInstances = []; 30 | foreach ($packages['packages'] as $package => $params) 31 | $packageInstances[] = new Package($this->service, $package, $params['description'], $params['status'], $params['version'], $params['patches'], $params['dependencies']); 32 | return $packageInstances; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /lib/Nitrapi/Services/Gameservers/Player.php: -------------------------------------------------------------------------------- 1 | service = $service; 14 | } 15 | 16 | /** 17 | * Return a list of all online players. 18 | * 19 | * @return array 20 | */ 21 | public function getOnlinePlayers() { 22 | $url = "/services/".$this->service->getId()."/gameservers/games/players"; 23 | $whitelist = $this->service->getApi()->dataGet($url); 24 | 25 | return $whitelist; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /lib/Nitrapi/Services/Gameservers/Whitelist.php: -------------------------------------------------------------------------------- 1 | service = $service; 14 | } 15 | 16 | /** 17 | * Returns the whitelist of the game server. 18 | * 19 | * @return array 20 | */ 21 | public function getWhitelist() { 22 | $url = "/services/".$this->service->getId()."/gameservers/games/whitelist"; 23 | $whitelist = $this->service->getApi()->dataGet($url); 24 | 25 | return $whitelist; 26 | } 27 | 28 | /** 29 | * Adds a player to the whitelist. 30 | * 31 | * @param $identifier 32 | * @return string 33 | */ 34 | public function addWhitelist($identifier) { 35 | $url = "/services/".$this->service->getId()."/gameservers/games/whitelist"; 36 | return $this->service->getApi()->dataPost($url, [ 37 | 'identifier' => $identifier 38 | ]); 39 | } 40 | 41 | /** 42 | * Removes a player from the whitelist. 43 | * 44 | * @param $identifier 45 | * @return string 46 | */ 47 | public function removeWhitelist($identifier) 48 | { 49 | $url = "/services/" . $this->service->getId() . "/gameservers/games/whitelist"; 50 | return $this->service->getApi()->dataDelete($url, [ 51 | 'identifier' => $identifier 52 | ]); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /lib/Nitrapi/Services/Rootservers/Rootserver.php: -------------------------------------------------------------------------------- 1 | setApi($api); 22 | 23 | $_services = $this->getApi()->dataGet("services", null, $options); 24 | if (count($_services['services']) > 0) { 25 | foreach ($_services['services'] as $service) { 26 | try { 27 | $this->services[] = ServiceFactory::factory($this->getApi(), array( 28 | 'id' => $service['id'], 29 | )); 30 | } catch (\Exception $e) {} 31 | } 32 | } 33 | } 34 | 35 | /** 36 | * Returns all services 37 | * 38 | * @return array 39 | */ 40 | public function getServices() { 41 | return $this->services; 42 | } 43 | 44 | protected function setApi(Nitrapi $api) { 45 | $this->api = $api; 46 | } 47 | 48 | protected function getApi() { 49 | return $this->api; 50 | } 51 | } -------------------------------------------------------------------------------- /lib/Nitrapi/Services/ServiceFactory.php: -------------------------------------------------------------------------------- 1 | dataGet("services/" . $options['id'], null); 12 | 13 | $type = $data['service']['type']; 14 | if ($type == 'cloud_server') $type = 'CloudServer'; //todo make it more fancy 15 | 16 | $class = "Nitrapi\\Services\\" . ucfirst($type) . "s\\" . ucfirst($type); 17 | 18 | if (!class_exists($class)) { 19 | throw new NitrapiServiceTypeNotFoundException("Class for Type " . $type . " not found"); 20 | } 21 | 22 | return new $class($api, $data['service']); 23 | } 24 | } -------------------------------------------------------------------------------- /lib/Nitrapi/Services/ServiceItem.php: -------------------------------------------------------------------------------- 1 | setService($service); 11 | $this->loadData($data); 12 | } 13 | 14 | /** 15 | * @param array $data 16 | */ 17 | protected function loadData(array $data) { 18 | $reflectionClass = new \ReflectionClass($this); 19 | $properties = $reflectionClass->getProperties(); 20 | 21 | foreach ($properties as $property) { 22 | if (!isset($data[$property->getName()])) continue; 23 | if (!$property->isProtected()) continue; 24 | $value = $data[$property->getName()]; 25 | if ($value === null) continue; 26 | 27 | $property->setAccessible(true); 28 | $property->setValue($this, $value); 29 | $property->setAccessible(false); 30 | } 31 | } 32 | 33 | /** 34 | * @param Service $service 35 | */ 36 | protected function setService(Service $service) { 37 | $this->service = $service; 38 | } 39 | 40 | /** 41 | * @return Service 42 | */ 43 | protected function getService() { 44 | return $this->service; 45 | } 46 | } -------------------------------------------------------------------------------- /lib/Nitrapi/Services/Storages/Storage.php: -------------------------------------------------------------------------------- 1 | data = $data; 16 | } 17 | 18 | public function getExpiresAt() { 19 | return (new \DateTime())->setTimestamp(strtotime($this->data['support_authorization']['expires_at'])); 20 | } 21 | 22 | public function getCreatedAt() { 23 | return (new \DateTime())->setTimestamp(strtotime($this->data['support_authorization']['created_at'])); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /lib/Nitrapi/Services/TaskManager/Task.php: -------------------------------------------------------------------------------- 1 | taskManager = $taskManager; 36 | parent::__construct($taskManager->getService(), $data); 37 | $this->setService($taskManager->getService()); 38 | } 39 | 40 | public function getId() { 41 | return (int)$this->id; 42 | } 43 | 44 | public function getMinute() { 45 | return $this->minute; 46 | } 47 | 48 | public function setMinute($minute) { 49 | $this->minute = $minute; 50 | 51 | return $this; 52 | } 53 | 54 | public function getHour() { 55 | return $this->hour; 56 | } 57 | 58 | public function setHour($hour) { 59 | $this->hour = $hour; 60 | 61 | return $this; 62 | } 63 | 64 | public function getDay() { 65 | return $this->day; 66 | } 67 | 68 | public function setDay($day) { 69 | $this->day = $day; 70 | 71 | return $this; 72 | } 73 | 74 | public function getMonth() { 75 | return $this->month; 76 | } 77 | 78 | public function setMonth($month) { 79 | $this->month = $month; 80 | 81 | return $this; 82 | } 83 | 84 | public function getWeekDay() { 85 | return $this->weekday; 86 | } 87 | 88 | public function setWeekday($weekday) { 89 | $this->weekday = $weekday; 90 | 91 | return $this; 92 | } 93 | 94 | public function getActionMethod() { 95 | return $this->action_method; 96 | } 97 | 98 | public function setActionMethod($actionMethod) { 99 | $this->action_method = $actionMethod; 100 | 101 | return $this; 102 | } 103 | 104 | public function getActionData() { 105 | return $this->action_data; 106 | } 107 | 108 | public function setActionData($actionData) { 109 | $this->action_data = $actionData; 110 | 111 | return $this; 112 | } 113 | 114 | public function getNextRun() { 115 | if (empty($this->next_run)) 116 | return null; 117 | 118 | return (new \DateTime())->setTimestamp(strtotime($this->next_run)); 119 | } 120 | 121 | public function getLastRun() { 122 | if (empty($this->last_run)) 123 | return null; 124 | 125 | return (new \DateTime())->setTimestamp(strtotime($this->last_run)); 126 | } 127 | 128 | public function getTimeZone() { 129 | return $this->timezone; 130 | } 131 | 132 | public function reloadData() { 133 | if (!empty($this->id)) { 134 | $url = "services/" . $this->getService()->getId() . "/tasks"; 135 | $_tasks = $this->getService()->getApi()->dataGet($url); 136 | 137 | foreach ($_tasks['tasks'] as $task) { 138 | if ($task['id'] == $this->getId()) { 139 | $this->loadData($task); 140 | break; 141 | } 142 | } 143 | } 144 | } 145 | } 146 | -------------------------------------------------------------------------------- /lib/Nitrapi/Services/TaskManager/TaskException.php: -------------------------------------------------------------------------------- 1 | service = $service; 14 | $this->reloadTasks(); 15 | } 16 | 17 | public function getService() { 18 | return $this->service; 19 | } 20 | 21 | /** 22 | * Returns all available tasks 23 | * 24 | * @return array 25 | */ 26 | public function getTasks() { 27 | return $this->tasks; 28 | } 29 | 30 | public function getTaskList() { 31 | $url = "services/" . $this->getService()->getId() . "/tasks/list"; 32 | return $this->getService()->getApi()->dataGet($url)['tasks']; 33 | } 34 | 35 | /** 36 | * Persists a task 37 | * 38 | * @param Task $task 39 | * @return Task 40 | */ 41 | public function persistTask(Task $task) { 42 | $id = $task->getId(); 43 | 44 | if (empty($id)) { 45 | //create new task 46 | $url = "services/" . $this->getService()->getId() . "/tasks"; 47 | } else { 48 | //save task 49 | $url = "services/" . $this->getService()->getId() . "/tasks/" . $id; 50 | } 51 | 52 | $this->getService()->getApi()->dataPost($url, [ 53 | 'minute' => $task->getMinute(), 54 | 'hour' => $task->getHour(), 55 | 'day' => $task->getDay(), 56 | 'month' => $task->getMonth(), 57 | 'weekday' => $task->getWeekDay(), 58 | 'action_method' => $task->getActionMethod(), 59 | 'action_data' => $task->getActionData(), 60 | ]); 61 | 62 | $task->reloadData(); 63 | 64 | return $task; 65 | } 66 | 67 | /** 68 | * Deletes a task 69 | * 70 | * @param Task $task 71 | * @return bool 72 | */ 73 | public function deleteTask(Task $task) { 74 | $id = $task->getId(); 75 | 76 | if (empty($id)) { 77 | throw new TaskException("This is not a persistent task, no delete needed"); 78 | } 79 | 80 | $url = "services/" . $this->getService()->getId() . "/tasks/" . $id; 81 | $this->getService()->getApi()->dataDelete($url); 82 | 83 | unset($this->tasks[$id]); 84 | 85 | return true; 86 | } 87 | 88 | 89 | public function reloadTasks() { 90 | $url = "services/" . $this->getService()->getId() . "/tasks"; 91 | $_tasks = $this->getService()->getApi()->dataGet($url); 92 | 93 | $this->tasks = []; 94 | foreach ($_tasks['tasks'] as $task) { 95 | $_ = new Task(); 96 | $_->setTaskManager($this, $task); 97 | $this->tasks[$task['id']] = $_; 98 | } 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /lib/Nitrapi/Services/Voiceservers/Types/Mumble.php: -------------------------------------------------------------------------------- 1 | service->getId() . "/voiceservers/mumble/user"; 16 | $this->service->getApi()->dataPost($url, [ 17 | 'username' => $username, 18 | 'password' => $password, 19 | ]); 20 | 21 | return true; 22 | 23 | } 24 | 25 | /** 26 | * Deletes a User 27 | * 28 | * @param string $username 29 | * @return string 30 | */ 31 | public function deleteUser($username) { 32 | $url = "services/" . $this->service->getId() . "/voiceservers/mumble/user"; 33 | $this->service->getApi()->dataDelete($url, [ 34 | 'username' => $username 35 | ]); 36 | 37 | return true; 38 | } 39 | } -------------------------------------------------------------------------------- /lib/Nitrapi/Services/Voiceservers/Types/Teamspeak3.php: -------------------------------------------------------------------------------- 1 | service->getId() . "/voiceservers/teamspeak3/status"; 9 | $params = []; 10 | if($show_icons) { 11 | $params["show_icons"] = true; 12 | } 13 | $status = $this->service->getApi()->dataGet($url, null, ["query" => $params])['status']; 14 | return $status; 15 | } 16 | 17 | public function icon($icon_id) { 18 | $url = "services/" . $this->service->getId() . "/voiceservers/teamspeak3/icon"; 19 | $icon = $this->service->getApi()->dataGet($url, null, ["query" => ["icon_id" => $icon_id]])['icon']; 20 | return $icon; 21 | } 22 | 23 | public function getWhitelist() { 24 | $url = "services/" . $this->service->getId() . "/voiceservers/whitelist"; 25 | return $this->service->getApi()->dataGet($url, null)['list']; 26 | } 27 | 28 | public function addWhitelist($ip, $comment) { 29 | $url = "services/" . $this->service->getId() . "/voiceservers/whitelist"; 30 | return $this->service->getApi()->dataPost($url, [ 31 | 'ip' => $ip, 32 | 'comment' => $comment 33 | ])['entry']; 34 | } 35 | 36 | public function deleteWhitelist($id) { 37 | $url = "services/" . $this->service->getId() . "/voiceservers/whitelist"; 38 | $this->service->getApi()->dataDelete($url, [ 39 | 'id' => $id 40 | ]); 41 | return true; 42 | } 43 | 44 | public function getBanlist() { 45 | $url = "services/" . $this->service->getId() . "/voiceservers/teamspeak3/bans"; 46 | return $this->service->getApi()->dataGet($url, null); 47 | } 48 | 49 | public function deleteBanlist($id) { 50 | $url = "services/" . $this->service->getId() . "/voiceservers/teamspeak3/bans"; 51 | $this->service->getApi()->dataDelete($url, [ 52 | 'ban_id' => $id 53 | ]); 54 | return true; 55 | } 56 | 57 | public function setHostMessage($mode, $message) { 58 | $url = "services/" . $this->service->getId() . "/voiceservers/teamspeak3/hostmessage"; 59 | $this->service->getApi()->dataPost($url, [ 60 | 'mode' => $mode, 61 | 'message' => $message, 62 | ]); 63 | return true; 64 | } 65 | 66 | public function addPassword($password, $description, $duration = 10) { 67 | $url = "services/" . $this->service->getId() . "/voiceservers/teamspeak3/temppassword"; 68 | $this->service->getApi()->dataPost($url, [ 69 | 'password' => $password, 70 | 'description' => $description, 71 | 'duration' => $duration, 72 | ]); 73 | return true; 74 | } 75 | 76 | public function enableLogView($group) { 77 | $url = "services/" . $this->service->getId() . "/voiceservers/teamspeak3/enable_log_view"; 78 | return $this->service->getApi()->dataPost($url, [ 79 | 'group' => $group 80 | ]); 81 | } 82 | 83 | public function cleanupUsers($groups, $days) { 84 | $url = "services/" . $this->service->getId() . "/voiceservers/teamspeak3/cleanup_users"; 85 | return $this->service->getApi()->dataPost($url, [ 86 | 'groups' => $groups, 87 | 'days' => $days 88 | ])['cleanup']; 89 | } 90 | 91 | public function info() { 92 | $url = "services/" . $this->service->getId() . "/voiceservers/teamspeak3/info"; 93 | return $this->service->getApi()->dataGet($url, null)['info']; 94 | } 95 | 96 | /** 97 | * Send commands to voiceserver 98 | * 99 | * @param array $commands 100 | * @return array 101 | */ 102 | public function query($commands) { 103 | $url = "services/" . $this->service->getId() . "/voiceservers/teamspeak3/query"; 104 | $response = $this->service->getApi()->dataPost($url, null, null, [ 105 | 'json' => [ 106 | 'commands' => $commands 107 | ] 108 | ]); 109 | return $response['query']; 110 | } 111 | 112 | /** 113 | * Creates a new Admin Group 114 | * 115 | * @return string 116 | */ 117 | public function addGroup($name) { 118 | $url = "services/" . $this->service->getId() . "/voiceservers/teamspeak3/group"; 119 | return $this->service->getApi()->dataPost($url, [ 120 | 'name' => $name 121 | ])['token']; 122 | } 123 | 124 | /** 125 | * Deletes a Group 126 | * 127 | * @return string 128 | */ 129 | public function deleteGroup($groupId) { 130 | $url = "services/" . $this->service->getId() . "/voiceservers/teamspeak3/group"; 131 | $this->service->getApi()->dataDelete($url, [ 132 | 'sgid' => $groupId 133 | ]); 134 | 135 | return true; 136 | } 137 | 138 | /** 139 | * Adds a new token for a Group 140 | * 141 | * @return string 142 | */ 143 | public function addToken($groupId) { 144 | $url = "services/" . $this->service->getId() . "/voiceservers/teamspeak3/token"; 145 | return $this->service->getApi()->dataGet($url, null, [ 146 | 'query' => [ 147 | 'sgid' => $groupId 148 | ] 149 | ])['token']; 150 | } 151 | 152 | /** 153 | * Deletes a Token 154 | * 155 | * @return string 156 | */ 157 | public function deleteToken($token) { 158 | $url = "services/" . $this->service->getId() . "/voiceservers/teamspeak3/token"; 159 | $this->service->getApi()->dataDelete($url, [ 160 | 'token' => $token 161 | ]); 162 | 163 | return true; 164 | } 165 | 166 | /** 167 | * Shows all available teamspeak 3 hostsystems 168 | * 169 | * @admin 170 | * @return array 171 | */ 172 | public function getHostsystems() { 173 | $url = "services/" . $this->service->getId() . "/voiceservers/teamspeak3/servers"; 174 | return $this->service->getApi()->dataGet($url)['servers']; 175 | } 176 | 177 | /** 178 | * Switches a teamspeak 3 instance to a new hostsystem 179 | * Except files and icons, these are not migrated 180 | * 181 | * @admin 182 | * @return bool 183 | */ 184 | public function doSwitch($hostname) { 185 | $url = "services/" . $this->service->getId() . "/voiceservers/teamspeak3/switch"; 186 | $this->service->getApi()->dataPost($url, [ 187 | 'server' => $hostname 188 | ]); 189 | 190 | return true; 191 | } 192 | 193 | } -------------------------------------------------------------------------------- /lib/Nitrapi/Services/Voiceservers/Types/Type.php: -------------------------------------------------------------------------------- 1 | service = $service; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /lib/Nitrapi/Services/Voiceservers/Voiceserver.php: -------------------------------------------------------------------------------- 1 | isActive()) { 18 | $this->info = $this->getApi()->dataGet("services/" . $this->getId() . "/voiceservers"); 19 | } 20 | } 21 | 22 | public function refresh() { 23 | $url = "services/" . $this->getId() . "/voiceservers"; 24 | $this->info = $this->getApi()->dataGet($url); 25 | } 26 | 27 | /** 28 | * Returns informations about the voiceserver 29 | * 30 | * @return VoiceserverDetails 31 | * @throws NitrapiErrorException 32 | */ 33 | public function getDetails() { 34 | if (!isset($this->info['voiceserver'])) { 35 | throw new NitrapiErrorException('No voiceserver data available'); 36 | } 37 | return new VoiceserverDetails($this->info['voiceserver']); 38 | } 39 | 40 | /** 41 | * Restarts the voiceserver 42 | * 43 | * @return bool 44 | */ 45 | public function doRestart() { 46 | $url = "services/" . $this->getId() . "/voiceservers/restart"; 47 | $this->getApi()->dataPost($url); 48 | return true; 49 | } 50 | 51 | /** 52 | * Stopps the voiceserver 53 | * 54 | * @return bool 55 | */ 56 | public function doStop() { 57 | $url = "services/" . $this->getId() . "/voiceservers/stop"; 58 | $this->getApi()->dataPost($url); 59 | return true; 60 | } 61 | 62 | /** 63 | * Stopps the voiceserver 64 | * 65 | * @return bool 66 | */ 67 | public function doReinstall() { 68 | $url = "services/" . $this->getId() . "/voiceservers/reinstall"; 69 | $this->getApi()->dataPost($url); 70 | 71 | return true; 72 | } 73 | 74 | /** 75 | * Configures the voiceserver 76 | * 77 | * @return bool 78 | */ 79 | public function doConfigChange($key, $value) { 80 | $url = "services/" . $this->getId() . "/voiceservers"; 81 | $this->getApi()->dataPost($url, [ 82 | 'key' => $key, 83 | 'value' => $value 84 | ]); 85 | 86 | return true; 87 | } 88 | 89 | /** 90 | * Returns all available Backups 91 | * 92 | * @return array 93 | */ 94 | public function getBackups() { 95 | if (!isset($this->info['voiceserver']['specific']['snapshots'])) { 96 | return []; 97 | } 98 | 99 | return $this->info['voiceserver']['specific']['snapshots']; 100 | } 101 | 102 | /** 103 | * Creates a new Backup 104 | * 105 | * @return array 106 | */ 107 | public function createBackup() { 108 | $url = "services/" . $this->getId() . "/voiceservers/backup"; 109 | $result = $this->getApi()->dataPost($url)['snapshot']; 110 | 111 | $this->refresh(); 112 | return $result; 113 | } 114 | 115 | /** 116 | * Deployes a specific snapshot to the Voiceserver 117 | * The server will be restarted after a successful deployment. 118 | * 119 | * @param $id 120 | * @return bool 121 | */ 122 | public function restoreBackup($id) { 123 | $url = "services/" . $this->getId() . "/voiceservers/backup/".(int)$id."/restore"; 124 | $this->getApi()->dataPost($url); 125 | 126 | return true; 127 | } 128 | 129 | /** 130 | * Deletes a specific Backup from the Voiceserver 131 | * 132 | * @param $id 133 | * @return bool 134 | */ 135 | public function deleteBackup($id) { 136 | $url = "services/" . $this->getId() . "/voiceservers/backup/".(int)$id; 137 | $this->getApi()->dataDelete($url); 138 | 139 | $this->refresh(); 140 | return true; 141 | } 142 | 143 | /** 144 | * Downloads a specific backup file 145 | * 146 | * @param $id 147 | * @return string 148 | */ 149 | public function downloadBackup($id) { 150 | $url = "services/" . $this->getId() . "/voiceservers/backup/".(int)$id; 151 | $backup = $this->getApi()->dataGet($url)['snapshot']; 152 | 153 | return base64_decode($backup); 154 | } 155 | 156 | public function uploadBackup($backup) { 157 | $url = "services/" . $this->getId() . "/voiceservers/backup/upload/"; 158 | $result = $this->getApi()->dataPost($url, null, null, [ 159 | 'body' => base64_encode($backup) 160 | ])['snapshot']; 161 | 162 | $this->refresh(); 163 | return $result; 164 | } 165 | 166 | /** 167 | * Returns a voiceserver type instance 168 | **/ 169 | public function getVoiceserverTypeInstance() { 170 | $class = "Nitrapi\\Services\\Voiceservers\\Types\\" . ucfirst($this->getDetails()->getType()); 171 | 172 | if (!class_exists($class)) { 173 | throw new NitrapiServiceTypeNotFoundException("Voiceserver Type " . $this->getDetails()->getType() . " not found"); 174 | } 175 | 176 | return new $class($this); 177 | } 178 | } -------------------------------------------------------------------------------- /lib/Nitrapi/Services/Voiceservers/VoiceserverDetails.php: -------------------------------------------------------------------------------- 1 | data = $data; 12 | } 13 | 14 | public function getType() { 15 | return (string)$this->data['type']; 16 | } 17 | 18 | public function getIP() { 19 | return (string)$this->data['ip']; 20 | } 21 | 22 | public function isStarted() { 23 | return (bool)$this->data['started']; 24 | } 25 | 26 | public function isStopped() { 27 | return !$this->isStarted(); 28 | } 29 | 30 | public function getPort() { 31 | return (int)$this->data['port']; 32 | } 33 | 34 | public function getSlots() { 35 | return (int)$this->data['slots']; 36 | } 37 | 38 | public function getSettingKeys() { 39 | return $this->data['setting_keys']; 40 | } 41 | 42 | public function getSpecificInformation() { 43 | return $this->data['specific']; 44 | } 45 | } -------------------------------------------------------------------------------- /lib/Nitrapi/Services/Webspaces/Webspace.php: -------------------------------------------------------------------------------- 1 | setApi($api); 14 | } 15 | 16 | /** 17 | * Returns the Workshop Object 18 | * 19 | * @return ServerManager 20 | */ 21 | public function getWorkshop() { 22 | return new Workshop($this); 23 | } 24 | 25 | /** 26 | * @param Nitrapi $api 27 | */ 28 | protected function setApi(Nitrapi $api) { 29 | $this->api = $api; 30 | } 31 | 32 | /** 33 | * @return Nitrapi 34 | */ 35 | public function getApi() { 36 | return $this->api; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /lib/Nitrapi/Steam/Workshop/Workshop.php: -------------------------------------------------------------------------------- 1 | setSteam($steam); 11 | } 12 | 13 | protected function setSteam(\Nitrapi\Steam\Steam $steam) { 14 | $this->steam = $steam; 15 | } 16 | 17 | public function getSteam() { 18 | return $this->steam; 19 | } 20 | 21 | public function getItemInfo($ids) { 22 | $reponse = $this->getSteam()->getApi()->dataGet("/steam_workshop/item_info", null, array("query" => array("ids" => implode(',', $ids)))); 23 | return $reponse['workshop_items']; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /lib/Nitrapi/TopLevelDomain/TopLevelDomain.php: -------------------------------------------------------------------------------- 1 | setData($data); 29 | } 30 | 31 | /** 32 | * Sets data field $data to specified value. 33 | * 34 | * @param $data 35 | * @return $this 36 | */ 37 | public function setData($data) { 38 | if (count($data) > 0) { 39 | $this->data = $data; 40 | } 41 | 42 | return $this; 43 | } 44 | 45 | /** 46 | * Return the id of the Tld 47 | * 48 | * @return int 49 | */ 50 | public function getId(): int { 51 | return (int)$this->data['id']; 52 | } 53 | 54 | /** 55 | * Returns the tld name 56 | * 57 | * @return string 58 | */ 59 | public function getTld(): string { 60 | return $this->data['tld']; 61 | } 62 | 63 | /** 64 | * Returns the tld features 65 | * 66 | * @return array 67 | */ 68 | public function getFeatures(): array { 69 | return $this->data['features']; 70 | } 71 | 72 | } 73 | -------------------------------------------------------------------------------- /lib/Nitrapi/TopLevelDomain/TopLevelDomainManager.php: -------------------------------------------------------------------------------- 1 | api = $api; 17 | } 18 | 19 | /** 20 | * Returns all tlds 21 | * 22 | * @param bool $show_disabled show disabled tlds (that can no longer be bought) 23 | * @param string $provider limit to one provider (one of cps, nicdirect) 24 | * @return TopLevelDomain[] 25 | */ 26 | public function getTlds($show_disabled = false, $provider = NULL) { 27 | $tlds = []; 28 | $data = [ 29 | "show_disabled" => $show_disabled ? 'true' : 'false', 30 | ]; 31 | if (!is_null($provider)) { 32 | $data['provider'] = $provider; 33 | } 34 | 35 | foreach ($this->api->dataGet("/tlds", $data) as $tld) { 36 | $tlds[] = new TopLevelDomain($this->api, $tld); 37 | } 38 | 39 | return $tlds; 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /phpunit.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | ./test/tests/ 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /test/NitrapiTestCase.php: -------------------------------------------------------------------------------- 1 | $params) 15 | $responses[] = new Response(200, $params, file_get_contents(__DIR__ . '/fixtures/' . $url . '.response')); 16 | $mock = new MockHandler($responses); 17 | $handler = HandlerStack::create($mock); 18 | return new Nitrapi(null, ['handler' => $handler], null); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /test/bootstrap.php: -------------------------------------------------------------------------------- 1 | nitrapiMock([ 14 | 'cloud_server.images' => [] 15 | ]); 16 | $this->images = CloudServer::getAvailableImages($nitrapi); 17 | } 18 | 19 | function testImageObjectCreation() { 20 | $this->assertInstanceOf('Nitrapi\Services\CloudServers\Image', $this->images[0]); 21 | } 22 | 23 | function testImageAttributes() { 24 | $linux = $this->images[0]; 25 | $this->assertEquals($linux->getId(), 2); 26 | $this->assertEquals($linux->getName(), "Ubuntu 14.04 LTS (Plain)"); 27 | $this->assertFalse($linux->isWindows()); 28 | } 29 | 30 | function testImageWindowsFlag() { 31 | $this->assertFalse($this->images[0]->isWindows()); 32 | $this->assertTrue($this->images[1]->isWindows()); 33 | } 34 | } -------------------------------------------------------------------------------- /test/tests/GameserverLogsTest.php: -------------------------------------------------------------------------------- 1 | nitrapiMock([ 11 | 'service3' => [], 12 | 'gameservers' => [], 13 | 'gameservers.logs' => [] 14 | ]); 15 | 16 | $service = $nitrapi->getService(['id' => 3]); 17 | $logfiles = $service->getLogs(); 18 | 19 | $this->assertEquals(1, $logfiles['current_page']); 20 | $this->assertEquals(40, $logfiles['logs_per_page']); 21 | $this->assertTrue(is_array($logfiles['logs'])); 22 | $this->assertTrue(is_array($logfiles['logs'][0])); 23 | $this->assertEquals('Tyrola', $logfiles['logs'][0]['user']); 24 | } 25 | } -------------------------------------------------------------------------------- /test/tests/PingTest.php: -------------------------------------------------------------------------------- 1 | nitrapiMock(['ping' => []]); 11 | 12 | $response = $nitrapi->dataGet('ping'); 13 | $this->assertEquals($response, 'All systems operate as expected.'); 14 | } 15 | } -------------------------------------------------------------------------------- /test/tests/UserTest.php: -------------------------------------------------------------------------------- 1 | nitrapiMock(['user' => []]); 16 | $this->user = $nitrapi->getCustomer(); 17 | } 18 | 19 | function testFindAUser() { 20 | $this->assertEquals('Marty', $this->user->getUsername()); 21 | $this->assertEquals(1337, $this->user->getUserId()); 22 | $this->assertEquals(1955, $this->user->getCredit()); 23 | $this->assertEquals('marty.mcfly@biffco.com', $this->user->getEmail()); 24 | $this->assertEquals('eng', $this->user->get('language')); 25 | } 26 | 27 | function testPersonalData() { 28 | $this->assertEquals('Marty McFly', $this->user->getPersonalData()['name']); 29 | $this->assertEquals('DeLorean Street 12', $this->user->getPersonalData()['street']); 30 | $this->assertEquals('2209', $this->user->getPersonalData()['postcode']); 31 | $this->assertEquals('Hill Valley', $this->user->getPersonalData()['city']); 32 | } 33 | } --------------------------------------------------------------------------------