h2r-bwmsgsv2.php

 1<?php
 2/*
 3  Copyright (C) 2020  Denver Gingerich <denver@ossguy.com>
 4
 5  This file is part of sgx-bwmsgsv2.
 6
 7  sgx-bwmsgsv2 is free software: you can redistribute it and/or modify it under
 8  the terms of the GNU Affero General Public License as published by the Free
 9  Software Foundation, either version 3 of the License, or (at your option) any
10  later version.
11
12  sgx-bwmsgsv2 is distributed in the hope that it will be useful, but WITHOUT
13  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14  FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more
15  details.
16
17  You should have received a copy of the GNU Affero General Public License along
18  with sgx-bwmsgsv2.  If not, see <http://www.gnu.org/licenses/>.
19*/
20
21$time = microtime(true);
22$tai_timestamp = trim(shell_exec('./tai'));
23
24$raw_data = file_get_contents('php://input');
25
26include 'settings-h2r.php';
27$redis = new Redis();
28$rv = $redis->pconnect($redis_host, $redis_port);
29
30if (!$rv) {
31	error_log("ERROR 1a in Redis connect at $time - cannot save $raw_data");
32	http_response_code(503);  # Service Unavailable
33	exit(0);
34}
35
36if (!empty($redis_auth)) {
37	# TODO: check return value to confirm login succeeded
38	$redis->auth($redis_auth);
39}
40
41$time2 = microtime(true);
42$tai_timestamp2 = trim(shell_exec('./tai'));
43
44$rv = $redis->lPush('incoming_messages-'.'test1a',  # TODO: update queue name
45	'"ts_020_tai-first_db_hit":'.$tai_timestamp2.
46	',"ts_020_unix-first_db_hit":'.$time2.
47	',"ts_010_tai-first_received":'.$tai_timestamp.
48	',"ts_010_unix-first_received":'.$time.',"MSG":'.$raw_data);
49
50if (!$rv) {
51	error_log("ERROR 2a in lPush at $time $time2 - cannot save $raw_data");
52	http_response_code(503);  # Service Unavailable
53	exit(0);
54}
55
56print 'ok';
57
58?>