parent
2951bc8b91
commit
829fb33818
4 changed files with 150 additions and 108 deletions
@ -1,18 +1,28 @@ |
||||
<?php |
||||
require_once("usertable.php"); |
||||
try { |
||||
require_once("usertable.php"); |
||||
$user = $db->real_escape_string($_REQUEST['user']); |
||||
$pubkey = $db->real_escape_string($_REQUEST['pubkey']); |
||||
$pgp = gnupg_init(); |
||||
if (!$pgp) { |
||||
echo json_encode(array('success' => false, 'txt' => "pgp on server failed")); |
||||
} else { |
||||
$verify = gnupg_import($pgp, $_REQUEST['pubkey']); |
||||
if (!$verify) { |
||||
echo json_encode(array('success' => false, 'txt' => "wrong identity")); |
||||
} else { |
||||
$q = $db->query("select * from user where name='$user' and pubkey='$pubkey';"); |
||||
if ($q->num_rows==1) { |
||||
echo json_encode(true); |
||||
echo json_encode(array('success' => true, 'txt' => "user verified")); |
||||
} elseif ($q->num_rows==0) { |
||||
$q = $db->query("insert into user (name, pubkey) values ('$user', '$pubkey');"); |
||||
echo json_encode(true); |
||||
echo json_encode(array('success' => true, 'txt' => "user created")); |
||||
} else { |
||||
echo json_encode(false); |
||||
echo json_encode(array('success' => false, 'txt' => "server database defect")); |
||||
} |
||||
} |
||||
} |
||||
} catch (Exception $e) { |
||||
echo json_encode(false); |
||||
echo json_encode(array('success' => false, 'txt' => "login failed")); |
||||
} |
||||
?> |
||||
|
@ -1,16 +1,34 @@ |
||||
<?php |
||||
require_once("messagetable.php"); |
||||
try { |
||||
require_once("usertable.php"); |
||||
$user = $db->real_escape_string($_REQUEST['user']); |
||||
$msg = $db->real_escape_string($_REQUEST['msg']); |
||||
$pgp = gnupg_init(); |
||||
if (!$pgp) { |
||||
echo json_encode(array('success' => false, 'txt' => "pgp on server failed")); |
||||
} else { |
||||
$q = $db->query("select pubkey from user where name='$user';"); |
||||
if (!$q || $q->num_rows!=1) { |
||||
echo json_encode(array('success' => false, 'txt' => "user not found on server")); |
||||
} else { |
||||
$pubkey = gnupg_import($pgp, $q->fetch_row()[0]); |
||||
if (!$pubkey) { |
||||
echo json_encode(array('success' => false, 'txt' => "wrong identity")); |
||||
} else { |
||||
require_once("messagetable.php"); |
||||
$q = $db->query("insert into message (user, msg) values ('$user', '$msg');"); |
||||
if ($q) { |
||||
echo json_encode(true); |
||||
echo json_encode(array('success' => true, 'txt' => "message stored")); |
||||
} else { |
||||
error_log("Error storing message: ".$db->error); |
||||
echo json_encode(false); |
||||
echo json_encode(array('success' => false, 'txt' => "storing message failed")); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} catch (Exception $e) { |
||||
echo json_encode(false); |
||||
error_log("Error storing message: ".$e->message); |
||||
echo json_encode(array('success' => false, 'txt' => "storing message failed")); |
||||
} |
||||
|
||||
?> |
Loading…
Reference in new issue