Files
BE_CPONE/application/controllers/fix/Mobile_check.php
2026-04-27 10:26:26 +07:00

151 lines
4.8 KiB
PHP

<?php
class Mobile_check extends MY_Controller
{
function index()
{
global $_SERVER;
$this->print_table_style();
//ping
$origin = $_SERVER["SERVER_NAME"];
$rows = [];
$rows[] = ["host" => "Server $origin"];
$this->print_table($rows,array_keys($rows[0]),"Origin");
$output = [];
exec("ping -c 3 mobile.pramita.co.id",$output,$result_code);
$rows = [];
$rows[] = ["Ping Test to mobile.pramita.co.id" => "Result Code : $result_code"];
$rows[] = ["Ping Test to mobile.pramita.co.id" =>
implode("<br/>",$output)];
$this->print_table($rows,array_keys($rows[0]));
//curl to mobile.pramita.co.id
echo "<br/>";
$resp = $this->post("https://mobile.pramita.co.id/one-api/info","");
$this->print_table([$resp], array_keys($resp), "curl https://mobile.pramita.co.id/one-api/info");
$rows = $this->get_heartbeat();
echo "<br/>";
$this->print_table($rows,array_keys($rows[0]),"Last HeartBeat status");
echo "<br/>";
$rows = $this->get_upload();
$this->print_table($rows,array_keys($rows[0]),"Last Post Back status");
}
function get_upload() {
$sql = "select distinct pbUploadCode,pbUploadExecuted from pb_upload";
$qry = $this->db->query($sql);
if (!$qry) {
echo "Error Get Poll Back status : " . $this->db->error()["message"];
return [];
}
$rows = $qry->result_array();
return $rows;
}
function get_heartbeat() {
$sql = "select distinct heartbeatCode,heartbeatExecuted,heartbeatStatus from regonline.heartbeat";
$qry = $this->db->query($sql);
if (!$qry) {
echo "Error Get HeartBeat status : " . $ths->db->error()["message"];
return [];
}
$rows = $qry->result_array();
foreach($rows as $idx => $r) {
switch($r["heartbeatCode"]) {
case "CAROUSEL" :
$rows[$idx]["heartbeatCode"] = "Caraousel";
break;
case "PING" :
$rows[$idx]["heartbeatCode"] = "Ping";
break;
case "SWAB" :
$rows[$idx]["heartbeatCode"] = "Schedule";
break;
case "QUOTA_PCR":
$rows[$idx]["heartbeatCode"] = "Quota";
break;
case "PRICE_PACKET":
$rows[$idx]["heartbeatCode"] = "Price and Agreement";
break;
case "HS":
case "MOU_REG":
case "ORDER_BRANCH":
unset($rows[$idx]);
break;
case "BEST_SELLER":
$rows[$idx]["heartbeatCode"] = "Best Seller";
break;
}
}
return $rows;
}
public function post($url, $data)
{
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($ch, CURLOPT_TIMEOUT, 120);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data)
));
$z_result = curl_exec($ch);
if (curl_errno($ch) > 0) {
return array(
"status" => "ERR",
"message" => curl_error($ch)
);
}
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($httpCode != 200) {
return array(
"status" => "ERR",
"message" => "Http Response : $httpCode | $z_result"
);
}
$j_result = ["status" => "OK", "message" => "Connection OK"];
return $j_result;
}
public function print_table_style()
{
echo "
<style>
th, td {
padding: 15px;
text-align: left;
}
tr:nth-child(even) {background-color: #f2f2f2;}
table {
border: solid 1px ;
min-width:600px;
}
</style>
";
}
public function print_table($rows, $keys, $title = false)
{
echo "<table>";
if ($title) {
$col_span = count($keys);
echo "<tr>";
echo "<th colspan=$col_span>$title</th>";
echo "</tr>";
}
echo "<tr>";
foreach ($keys as $k) {
echo "<td>$k</td>";
}
echo "</tr>\n";
foreach ($rows as $r) {
echo "<tr>";
foreach ($keys as $k) {
echo "<td>" . $r[$k] . "</td>";
}
echo "</tr>";
}
echo "</table>";
}
}
?>