Skip to content

Instantly share code, notes, and snippets.

@frdmn
Last active March 23, 2019 20:28
Show Gist options
  • Save frdmn/cdf4cc001446919dd0bb082ef8389dd2 to your computer and use it in GitHub Desktop.
Save frdmn/cdf4cc001446919dd0bb082ef8389dd2 to your computer and use it in GitHub Desktop.
<?
function returnAwsArecords(){
$expected_aws = [];
$cname_result = dns_get_record('open.rocket.chat')[0]['target'];
$dns_result = dns_get_record($cname_result);
foreach($dns_result as $a_record){
array_push($expected_aws, $a_record['ip']);
}
return $expected_aws;
}
function returnGcpArecords(){
$expected_gcp = [];
$dns_result = dns_get_record('stable.rocket.chat');
foreach($dns_result as $a_record){
array_push($expected_gcp, $a_record['ip']);
}
return $expected_gcp;
}
function returnCustomCloudArecords(){
$expected_custom = [];
$dns_result = dns_get_record('cdns.rocket.chat');
foreach($dns_result as $a_record){
array_push($expected_custom, $a_record['ip']);
}
return $expected_custom;
}
function checkHostname($hostname){
$expected_custom = dns_get_record('cdns.rocket.chat', DNS_A)[0]['ip'];
$expected_cloud = dns_get_record('stable.rocket.chat', DNS_A)[0]['ip'];
$dns = dns_get_record($hostname, DNS_A);
if (in_array($dns[0]['ip'], returnGcpArecords())){
return '<a class="button button-outline button-orange">Rocket.Chat Cloud (no custom domain, Google Cloud)</a>';
} elseif (in_array($dns[0]['ip'], returnAwsArecords())){
return '<a class="button button-outline button-orange">Rocket.Chat Cloud (no custom domain, AWS Cloud)</a>';
} elseif (in_array($dns[0]['ip'], returnCustomCloudArecords())){
return '<a class="button button-outline button-green">Rocket.Chat Cloud (custom domain)</a>';
} else {
if (empty($dns)){
return '<a class="button button-clear button-red">Doesn\'t exist - Check hostname!</a>';
} else {
return '<a class="button button-outline button-red">Self-Hosted / On-Premises</a>';
}
}
}
function getRCversion($hostname){
$public_api = json_decode(file_get_contents('https://'.$hostname.'/api/info'));
if ($public_api->success){
return $public_api->version;
} else {
return false;
}
}
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="author" content="frdmn">
<title>Rocket.Chat Cloud Hosting Check</title>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,300italic,700,700italic">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/3.0.3/normalize.css">
<link rel="stylesheet" href="../node_modules/milligram/dist/milligram.min.css">
<link rel="stylesheet" href="https://milligram.io/styles/main.css">
<style type="text/css">
.button-green {
color: green !important;
}
.button-outline.button-green {
border: 0.1rem solid green !important;
}
.button-orange {
color: orange !important;
}
.button-outline.button-orange {
border: 0.1rem solid orange !important;
}
.button-red {
color: red !important;
}
.button-outline.button-red {
border: 0.1rem solid red !important;
}
</style>
</head>
<body>
<main class="wrapper">
<nav class="navigation">
<section class="container">
<a class="navigation-title" href="/check-if-rocketchat-cloud">
<h1 class="title">Rocket.Chat cloud tester</h1>
</a>
</section>
</nav>
<section class="container">
<? if($_GET['hostname']){
$host = $_GET['hostname'];
?>
<table>
<thead>
<tr>
<th>Hostname</th>
<th>Version/Result</th>
<th></th>
</tr>
</thead>
<tbody>
<tr>
<td><code><?= $host ?></code></td>
<td><?= getRCversion($host) ?></td>
<td><?= checkHostname($host) ?></td>
</tr>
</tbody>
</table>
<? } else { ?>
<p><i>Type in an instance hostname in the input field below and click the submit button to check if the hostname in question is hosted on Rocket.Chat Cloud or if it's a self-hosted/on-premises one.</i></p>
<? } ?>
<form>
<fieldset>
<label for="nameFieldHostname">Hostname to check</label>
<input type="text" placeholder="custom.hostname.com" id="nameFieldHostname" name="hostname" <?= $_GET['hostname'] ? "value=".$_GET['hostname'] : "" ?>>
<input class="button-primary" type="submit" value="Submit">
</fieldset>
</form>
</section>
<footer class="footer">
<section class="container">
<p>Made with ♥ by <a href="https://frd.mn" title="frdmn" target="_blank">frdmn</a>. Licensed under the <a href="https://gist.github.com/frdmn/cdf4cc001446919dd0bb082ef8389dd2#file-license" title="MIT License" target="_blank"> MIT License</a>.</p>
</section>
</footer>
</main>
</body>
</html>
The MIT License (MIT)
Copyright (c) 2019 Jonas Friedmann
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment