diff --git a/examples/scn_send.sh b/examples/scn_send.sh index 9f5dd8d..060ee0d 100644 --- a/examples/scn_send.sh +++ b/examples/scn_send.sh @@ -21,6 +21,7 @@ user_key="????????????????????????????????????????????????????????????????" title=$1 content="" +sendtime=$(date +%s) if [ "$#" -gt 1 ]; then content=$2 @@ -37,7 +38,7 @@ usr_msg_id=$(uuidgen) while true ; do curlresp=$(curl -s -o /dev/null -w "%{http_code}" \ - -d "user_id=$user_id" -d "user_key=$user_key" -d "title=$title" \ + -d "user_id=$user_id" -d "user_key=$user_key" -d "title=$title" -d "timestamp=$sendtime" \ -d "content=$content" -d "priority=$priority" -d "msg_id=$usr_msg_id" \ https://scn.blackforestbytes.com/send.php) diff --git a/web/api/model.php b/web/api/model.php index aad9e3a..7cb9825 100644 --- a/web/api/model.php +++ b/web/api/model.php @@ -4,29 +4,30 @@ include('lib/httpful.phar'); class ERR { - const NO_ERROR = 0000; + const NO_ERROR = 0000; - const MISSING_UID = 1101; - const MISSING_TOK = 1102; - const MISSING_TITLE = 1103; - const INVALID_PRIO = 1104; - const REQ_METHOD = 1105; + const MISSING_UID = 1101; + const MISSING_TOK = 1102; + const MISSING_TITLE = 1103; + const INVALID_PRIO = 1104; + const REQ_METHOD = 1105; - const NO_TITLE = 1201; - const TITLE_TOO_LONG = 1202; - const CONTENT_TOO_LONG = 1203; - const USR_MSG_ID_TOO_LONG = 1204; + const NO_TITLE = 1201; + const TITLE_TOO_LONG = 1202; + const CONTENT_TOO_LONG = 1203; + const USR_MSG_ID_TOO_LONG = 1204; + const TIMESTAMP_OUT_OF_RANGE = 1205; - const USER_NOT_FOUND = 1301; - const USER_AUTH_FAILED = 1302; + const USER_NOT_FOUND = 1301; + const USER_AUTH_FAILED = 1302; - const NO_DEVICE_LINKED = 1401; + const NO_DEVICE_LINKED = 1401; - const QUOTA_REACHED = 2101; + const QUOTA_REACHED = 2101; - const FIREBASE_COM_FAILED = 9901; - const FIREBASE_COM_ERRORED = 9902; - const INTERNAL_EXCEPTION = 9903; + const FIREBASE_COM_FAILED = 9901; + const FIREBASE_COM_ERRORED = 9902; + const INTERNAL_EXCEPTION = 9903; } class Statics diff --git a/web/api/schema.sql b/web/api/schema.sql index 1a3b2f8..e97c6a8 100644 --- a/web/api/schema.sql +++ b/web/api/schema.sql @@ -23,12 +23,13 @@ CREATE TABLE `messages` `scn_message_id` INT(11) NOT NULL AUTO_INCREMENT, `sender_user_id` INT(11) NOT NULL, - `timestamp` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, + `timestamp_real` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, `ack` BIT NOT NULL DEFAULT 0, `title` VARCHAR(256) NOT NULL, `content` VARCHAR(12288) NULL, `priority` INT(11) NOT NULL, + `sendtime` BIGINT UNSIGNED NOT NULL, `fcm_message_id` VARCHAR(256) NULL, `usr_message_id` VARCHAR(256) NULL, diff --git a/web/api_more.php b/web/api_more.php index 90431fa..3d5d385 100644 --- a/web/api_more.php +++ b/web/api_more.php @@ -198,6 +198,25 @@ if (file_exists('/var/www/openwebanalytics/owa_php.php'))
+
+ You can modify the displayed timestamp of a message by sending the timestamp
parameter. The format must be a valid UNIX timestamp (elapsed seconds since 1970-01-01 GMT)
+
+ But the custom timestamp must be within 48 hoours of the current time. This parameter is only intended to supply a more precise value in case the message sending was delayed +
+curl \ + --data "user_id={userid}" \ + --data "user_key={userkey}" \ + --data "title={message_title}" \ + --data "timestamp={unix_timestamp}" \ + https://scn.blackforestbytes.com/send.php+
+ Be aware that the server only saves send messages for a short amount of time. Because of that you can only use this to prevent duplicates in a short time-frame, older messages with the same ID are probably already deleted and the message will be send again. +
+@@ -227,6 +246,7 @@ user_key="???????????????????????????????????????? title=$1 content="" +sendtime=$(date +%s) if [ "$#" -gt 1 ]; then content=$2 @@ -243,7 +263,7 @@ usr_msg_id=$(uuidgen) while true ; do curlresp=$(curl -s -o /dev/null -w "%{http_code}" \ - -d "user_id=$user_id" -d "user_key=$user_key" -d "title=$title" \ + -d "user_id=$user_id" -d "user_key=$user_key" -d "title=$title" -d "timestamp=$sendtime" \ -d "content=$content" -d "priority=$priority" -d "msg_id=$usr_msg_id" \ https://scn.blackforestbytes.com/send.php) diff --git a/web/send.php b/web/send.php index 1703546..915f605 100644 --- a/web/send.php +++ b/web/send.php @@ -5,8 +5,6 @@ include_once 'api/model.php'; try { -//------------------------------------------------------------------ -//sleep(1); //------------------------------------------------------------------ if ($_SERVER['REQUEST_METHOD'] !== 'POST') api_return(400, ['success' => false, 'error' => ERR::REQ_METHOD, 'errhighlight' => -1, 'message' => 'Invalid request method (must be POST)']); @@ -19,16 +17,18 @@ try //------------------------------------------------------------------ - $user_id = $INPUT['user_id']; $user_key = $INPUT['user_key']; $message = $INPUT['title']; - $content = isset($INPUT['content']) ? $INPUT['content'] : ''; - $priority = isset($INPUT['priority']) ? $INPUT['priority'] : '1'; - $usrmsgid = isset($INPUT['msg_id']) ? $INPUT['msg_id'] : null; + $content = isset($INPUT['content']) ? $INPUT['content'] : ''; + $priority = isset($INPUT['priority']) ? $INPUT['priority'] : '1'; + $usrmsgid = isset($INPUT['msg_id']) ? $INPUT['msg_id'] : null; + $time = isset($INPUT['timestamp']) ? $INPUT['timestamp'] : time(); //------------------------------------------------------------------ + if (abs($time - time()) > 60*60*24*2) api_return(400, ['success' => false, 'error' => ERR::TIMESTAMP_OUT_OF_RANGE, 'errhighlight' => -1, 'message' => 'The timestamp mus be within 24 hours of now()']); + if ($priority !== '0' && $priority !== '1' && $priority !== '2') api_return(400, ['success' => false, 'error' => ERR::INVALID_PRIO, 'errhighlight' => 105, 'message' => 'Invalid priority']); if (strlen(trim($message)) == 0) api_return(400, ['success' => false, 'error' => ERR::NO_TITLE, 'errhighlight' => 103, 'message' => 'No title specified']); @@ -95,13 +95,14 @@ try $pdo->beginTransaction(); - $stmt = $pdo->prepare('INSERT INTO messages (sender_user_id, title, content, priority, fcm_message_id, usr_message_id) VALUES (:suid, :t, :c, :p, :fmid, :umid)'); + $stmt = $pdo->prepare('INSERT INTO messages (sender_user_id, title, content, priority, sendtime, fcm_message_id, usr_message_id) VALUES (:suid, :t, :c, :p, :ts, :fmid, :umid)'); $stmt->execute( [ 'suid' => $user_id, 't' => $message, 'c' => $content, 'p' => $priority, + 'ts' => $time, 'fmid' => null, 'umid' => $usrmsgid, ]); @@ -125,7 +126,7 @@ try 'body' => str_limit($content, 1900), 'trimmed' => (strlen($content) > 1900), 'priority' => $priority, - 'timestamp' => time(), + 'timestamp' => $time, 'usr_msg_id' => $usrmsgid, 'scn_msg_id' => $scn_msg_id, ]