4 require_once
'logging.i';
5 require_once
'hcuEnv.i';
6 require_once
'hcuCommon.i';
10 $env = LoadSystemEnv(
'version');
12 if ($env[
'devmode']) {
13 $env[
'logger']->warning(
"Showing /getcus info - DEVMODE.");
14 $myhostname =
"localhost:80";
15 $getcustatusvalues = array(
"stage.homecu.io",
"http://" . $myhostname .
"/cumaps/getcustatus.prg");
17 $myhostname =
"my.homecu.net";
18 $getcustatusvalues = array(
"my.homecu.net",
"https://" . $myhostname .
"/cumaps/getcustatus.prg");
22 $HB_ENV = LoadSystemEnv(
"banking");
25 $connect_to = sprintf(
'host=%s port=%d dbname=%s', $db[
'host'],
26 $db[
'port'], $db[
'dbname']);
27 if (!is_null($db[
'user'])) {
28 $connect_to .=
' user=' . $db[
'user'];
30 if (!is_null($db[
'connect_timeout'])) {
31 $connect_to .=
' connect_timeout=' . $db[
'connect_timeout'];
33 if (!is_null($db[
'password'])) {
34 $connect_to .=
' password=' . $db[
'password'];
36 $r = pg_connect($connect_to);
39 throw new Exception(
'DB connect error');
41 if (pg_connection_status($r) !== PGSQL_CONNECTION_OK) {
42 throw new Exception(
'DB status error');
45 throw new Exception(
'DB ping error');
49 $result = pg_query($r,
"select user_name, name, vendor, geo_lat, geo_long, dec_31_assets, dec_31_mem, www_server, system_options from cuinfo where ((system_options & 64) = 0) order by user_name");
52 $fields = array(
"name",
"cuname",
"vendor",
"lat",
"lng",
"assets",
"members",
"www_server" );
54 while ($row = pg_fetch_row($result)) {
55 $row[0] = trim($row[0]);
58 for ($i=0; $i<count($fields); $i++){
59 $entry[$fields[$i]] = trim($row[$i]);
71 array(
"www5",
'https://nobody:no1home@www5.homecu.net/hcuadm/getcustatus'),
72 array(
"www3",
'https://nobody:no1home@www3.homecu.net/hcuadm/getcustatus'),
73 array(
"www6",
'https://nobody:no1home@www6.homecu.net/hcuadm/getcustatus'),
78 list($server, $url) = $locations;
81 curl_setopt($ch, CURLOPT_URL, $url);
82 curl_setopt($ch, CURLOPT_RETURNTRANSFER,
true);
83 $output = curl_exec($ch);
84 $resp = json_decode($output,
true);
88 foreach( $resp as $name => $values ){
89 if ($env[
'devmode']) {
90 $env[
'logger']->warning(
"cuname " . $name .
" values " . json_encode($values));
92 if(HCU_array_key_exists($name, $res)){
93 if( $res[$name][
"www_server"] == $server){
94 foreach( array(
"livebatch",
"offlinestat") as $field ) {
95 $res[$name][$field] = $values[$field];
102 header(
'Content-Type: application/json');
103 echo json_encode($res);