Files
safechat/html/send.php

51 lines
1.6 KiB
PHP
Raw Normal View History

2015-06-28 20:58:51 +00:00
<?php
2015-07-15 21:33:06 +00:00
/*! @file
@id $Id$
@see @ref apisend
@page api
@section apisend Send Message To Server
API-call send.php
Send a message to the server. Sever checks if user exists and has
a valid public key. More test could be added later.
@param user The name of the user that send the message.
@param msg The armored signed and encrypted message. There is a
limit of 100000 bytes for the message.
@return
- success() if the message has been stored successfully
- error() in case of any error
*/
// 1 2 3 4 5 6 7 8
// 45678901234567890123456789012345678901234567890123456789012345678901234567890
2015-06-28 20:58:51 +00:00
try {
2015-07-02 07:08:13 +00:00
require_once("usertable.php");
2015-06-28 20:58:51 +00:00
$user = $db->real_escape_string($_REQUEST['user']);
$msg = $db->real_escape_string($_REQUEST['msg']);
2015-07-02 07:08:13 +00:00
$pgp = gnupg_init();
2015-07-08 05:48:27 +00:00
if (strlen($_REQUEST['msg'])>100000) error("message is too long");
if (!$pgp) error("pgp on server failed");
$q = $db->query("select pubkey from user where name='$user';");
if (!$q || $q->num_rows!=1) error("user not found on server");
$pubkey = gnupg_import($pgp, $q->fetch_row()[0]);
if (!$pubkey) error("wrong identity");
require_once("messagetable.php");
$q = $db->query("insert into message (user, msg) values ('$user', '$msg');");
if (!$q) {
error_log("Error storing message: ".$db->error);
error("storing message failed");
2015-07-01 00:07:33 +00:00
}
2015-07-08 05:48:27 +00:00
success("message stored");
2015-06-28 20:58:51 +00:00
} catch (Exception $e) {
2015-07-02 07:08:13 +00:00
error_log("Error storing message: ".$e->message);
2015-07-08 05:48:27 +00:00
error("storing message failed");
2015-06-28 20:58:51 +00:00
}
2015-07-02 07:08:13 +00:00
2015-06-28 20:58:51 +00:00
?>