-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathupdate.php
46 lines (40 loc) · 1.1 KB
/
update.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php
function send_success(){
print '{"status": "success", "message":"secret owned"}';
}
function send_failed($msg){
print '{"status": "failed", "'.$msg.'"}';
}
function set_owner($fname){
$uid = $_POST['uid'];
$encrypted_message = $_POST['encrypted_message'];
$iv = $_POST['iv'];
$salt = $_POST['salt'];
$json_text = file_get_contents("keys/$fname");
if ($json_text == false){
send_failed('No such secret');
return 0;
}
$json_obj = json_decode($json_text);
if ($json_obj->{'uid'} != ""){
send_failed('Secret already owned');
return 0;
}
$json_obj->{'encrypted'} = "true";
$json_obj->{'encrypted_message'} = $encrypted_message;
$json_obj->{'message'} = "";
$json_obj->{'uid'} = $uid;
$json_obj->{'iv'} = $iv;
$json_obj->{'salt'} = $salt;
$json_text = json_encode($json_obj);
file_put_contents("keys/$fname", $json_text);
send_success();
}
if ($_POST['view']){
$fname = $_POST['view'];
$result = preg_match("/^[a-zA-Z0-9]+$/",$fname);
if ($result){
set_owner($fname);
}
}
?>