-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpost.php
More file actions
65 lines (58 loc) · 2.14 KB
/
Copy pathpost.php
File metadata and controls
65 lines (58 loc) · 2.14 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
//http://stackoverflow.com/a/31107425
//Generate a secure random string
function random_str($length, $keyspace = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_') {
$str = '';
//$max = mb_strlen($keyspace, '8bit') - 1;
for ($i = 0; $i < $length; ++$i) {
//$str .= $keyspace[random_int(0, $max)];//This is better crypto, but requires php7
$str .= $keyspace[rand(0, strlen($keyspace) - 1)];
}
return $str;
}
include 'library.php';
if(empty($_POST))
die("You should only come to this page when creating a new checklist");
$conn = pgConnect();
if(isset($_POST['editPass'])){
$stmt = "SELECT pk FROM checkMaster WHERE PK=$1 AND editPass=$2";
$vals = [$_POST['parent'], $_POST['editPass']];
$results = pgQuery($conn,$stmt,$vals);
if(!empty($results)) {
$stmt = "DELETE FROM checkItem WHERE parent=$1";
$vals = [$_POST['parent']];
$results = pgQuery($conn,$stmt,$vals);
$stmt = "DELETE FROM checkMaster WHERE pk=$1";
$vals = [$_POST['parent']];
$results = pgQuery($conn,$stmt,$vals);
$key = $_POST['parent'];
$editPass=$_POST['editPass'];
}
else {
die("Incorrect key");
}
}
else {
$key = random_str(20);
$editPass = random_str(20);
}
$stmt = 'INSERT INTO checkMaster (description, owner, pk, editPass) VALUES ($1,$2,$3, $4) RETURNING pk';
$vals = [$_POST['description'],0,$key,$editPass];
$results = pgQuery($conn,$stmt,$vals);
$parent = $results[0]['pk'];
$stmt = 'INSERT INTO checkItem (data, parent, depend, item) VALUES ($1, $2, $3, $4)';
foreach($_POST['data'] as $key => $data) {
if(!empty($data['detail'])) {
if(empty($data['depend']))
$data['depend'] = null;
$vals = [$data['detail'],$parent,$data['depend'],$key];
$results = pgQuery($conn,$stmt,$vals);
}
}
$absUrl = $_SERVER['HTTP_ORIGIN']."/check.html?$parent";
$relUrl = "check.html?$parent";
$editUrl = "make.php?parent=$parent&editPass=$editPass";
?>
<center><h1>Your super-secret URL is <a href="<?=$relUrl?>"><?=$absUrl?></a></h1></center>
<center><h2>Bookmark the above URL to come back to your checklist at any time</h2></center>
<center><h2>You can edit the checklist <a href="<?=$editUrl?>">Here</a> This link will not be shown again</h2></center>