Created
October 18, 2025 02:13
-
-
Save mirai-iro/d152890264d550a4860705224b96d37f to your computer and use it in GitHub Desktop.
xrea-ssh-add-ip.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| define('XREA_API_SERVER', 'sXXX.xrea.com'); | |
| define('XREA_API_ACCOUNT', 'your-account'); | |
| define('XREA_API_SECRET_KEY', 'your-api-secret-key'); | |
| $param = [ | |
| 'addr' => getOwnGlobalIpAddr(), | |
| ]; | |
| # $result = requestXreaApiV1('user/info'); | |
| $result = requestXreaApiV1('tool/ssh_ip_allow', $param); | |
| var_dump($result); | |
| /** | |
| * @param string $endpoint | |
| * @param array $param | |
| * @return array | |
| */ | |
| function requestXreaApiV1($endpoint, array $param = []): array | |
| { | |
| $url = 'https://api.xrea.com/v1/' . $endpoint; | |
| $requestData = [ | |
| 'server_name' => XREA_API_SERVER, | |
| 'account' => XREA_API_ACCOUNT, | |
| 'api_secret_key' => XREA_API_SECRET_KEY, | |
| ]; | |
| if ($param) { | |
| foreach ($param as $key => $value) { | |
| $requestData['param[' . $key . ']'] = $value; | |
| } | |
| } | |
| $context = stream_context_create([ | |
| 'http' => [ | |
| 'method' => 'POST', | |
| 'content' => http_build_query($requestData), | |
| ] | |
| ]); | |
| $response = file_get_contents($url, false, $context); | |
| return json_decode($response, true); | |
| } | |
| /** | |
| * @return string | |
| */ | |
| function getOwnGlobalIpAddr(): string | |
| { | |
| return trim(file_get_contents('https://checkip.amazonaws.com/')); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment