diff --git a/action.php b/action.php index b734f07..f3442c0 100644 --- a/action.php +++ b/action.php @@ -33,6 +33,9 @@ switch ($VARS['action']) { } else { if ($database->has('publications', ['pubid' => $VARS['pubid']])) { $insert = false; + if ($database->get("publications", 'uid', ['pubid' => $VARS['pubid']]) != $_SESSION['uid']) { + returnToSender("no_permission"); + } } else { returnToSender("invalid_pubid"); } @@ -98,6 +101,9 @@ switch ($VARS['action']) { returnToSender("pub_saved"); case "deletepub": if ($database->has('publications', ['pubid' => $VARS['pubid']])) { + if ($database->get("publications", 'uid', ['pubid' => $VARS['pubid']]) != $_SESSION['uid']) { + returnToSender("no_permission"); + } $database->delete('tiles', ['pubid' => $VARS['pubid']]); $database->delete('publications', ['pubid' => $VARS['pubid']]); returnToSender("pub_deleted"); @@ -109,6 +115,10 @@ switch ($VARS['action']) { die(json_encode(["status" => "ERROR", "msg" => lang("invalid pubid", false)])); } + if ($database->get("publications", 'uid', ['pubid' => $VARS['pubid']]) != $_SESSION['uid']) { + die(json_encode(["status" => "ERROR", "msg" => lang("no permission", false)])); + } + $data = [ "pubid" => $VARS['pubid'], "page" => $VARS['page'], @@ -130,6 +140,10 @@ switch ($VARS['action']) { die(json_encode(["status" => "ERROR", "msg" => lang("invalid tileid", false)])); } + if ($database->get("publications", 'uid', ['pubid' => $VARS['pubid']]) != $_SESSION['uid']) { + die(json_encode(["status" => "ERROR", "msg" => lang("no permission", false)])); + } + $database->delete('tiles', ["tileid" => $VARS['tileid']]); exit(json_encode(["status" => "OK"])); case "signout": diff --git a/lang/en_us.php b/lang/en_us.php index 0b585fc..5142794 100644 --- a/lang/en_us.php +++ b/lang/en_us.php @@ -60,5 +60,6 @@ define("STRINGS", [ "edit content" => "Edit Content", "delete" => "Delete", "open" => "Open", - "page" => "Page" + "page" => "Page", + "no permission" => "You don't have permission to do that." ]); \ No newline at end of file diff --git a/lang/messages.php b/lang/messages.php index 4128300..f59da3d 100644 --- a/lang/messages.php +++ b/lang/messages.php @@ -25,4 +25,8 @@ define("MESSAGES", [ "string" => "invalid pubid", "type" => "danger" ], + "no_permission" => [ + "string" => "no permission", + "type" => "danger" + ], ]); diff --git a/lib/gencontent.php b/lib/gencontent.php index 149057c..3d35a8d 100644 --- a/lib/gencontent.php +++ b/lib/gencontent.php @@ -1,12 +1,19 @@ has('publications', ['pubid' => $VARS['pubid']])) { $pub = $VARS['pubid']; - $pubdata = $database->get("publications", ["pubname", "pubdate", "styleid", "columns", "page_size", "landscape"], ["pubid" => $pub]); + $pubdata = $database->get("publications", ["[>]pub_permissions" => ["permid" => "permid"]], ["pubname", "uid", "pubdate", "styleid", "columns", "page_size", "landscape", "publications.permid", "permname"], ["pubid" => $pub]); + if ($pubdata["permname"] != "LINK") { + dieifnotloggedin(); + } + if ($pubdata["uid"] != $_SESSION['uid']) { + if ($pubdata["permname"] == "OWNER") { + die(lang("no permission")); + } + } } else { die(lang("invalid parameters", false)); } diff --git a/lib/getpubtable.php b/lib/getpubtable.php index 3b705e8..3df6b99 100644 --- a/lib/getpubtable.php +++ b/lib/getpubtable.php @@ -62,6 +62,13 @@ if (!is_null($order)) { $where["ORDER"] = $order; } +$where["OR #perms"] = [ + "uid" => $_SESSION['uid'], + "permname #logg" => "LOGGEDIN", + "permname #link" => "LINK" +]; + +//var_dump($where); $pubs = $database->select('publications', [ '[>]pub_styles' => ['styleid' => 'styleid'], @@ -82,7 +89,6 @@ $pubs = $database->select('publications', [ ], $where); - $out['status'] = "OK"; if ($filter) { $recordsFiltered = $database->count('publications', [ @@ -96,8 +102,12 @@ $out['recordsFiltered'] = $recordsFiltered; $usercache = []; for ($i = 0; $i < count($pubs); $i++) { - $pubs[$i]["editbtn"] = ' ' . lang("edit", false) . ''; - $pubs[$i]["clonebtn"] = ' ' . lang("clone", false) . ''; + if ($pubs[$i]["uid"] == $_SESSION['uid']) { + $pubs[$i]["editbtn"] = ' ' . lang("edit", false) . ''; + } else { + $pubs[$i]["editbtn"] = ' ' . lang("view", false) . ''; + } + $pubs[$i]["clonebtn"] = ' ' . lang("clone", false) . ''; $pubs[$i]["pubdate"] = date(DATETIME_FORMAT, strtotime($pubs[$i]["pubdate"])); if (is_null($pubs[$i]['uid'])) { $pubs[$i]["username"] = ""; diff --git a/pages/content.php b/pages/content.php index 2b90d2d..fe3c71a 100644 --- a/pages/content.php +++ b/pages/content.php @@ -7,10 +7,20 @@ $pub = false; $pubdata = []; +$edit = false; + if (is_numeric($VARS['pubid'])) { if ($database->has('publications', ['pubid' => $VARS['pubid']])) { $pub = $VARS['pubid']; - $pubdata = $database->get("publications", ["pubname", "pubdate", "styleid", "columns", "page_size", "landscape"], ["pubid" => $pub]); + $pubdata = $database->get("publications", ["[>]pub_permissions" => ["permid" => "permid"]], ["pubname", "uid", "pubdate", "styleid", "columns", "page_size", "landscape", "publications.permid", "permname"], ["pubid" => $pub]); + if ($pubdata["uid"] == $_SESSION['uid']) { + $edit = true; + } else { + if ($pubdata["permname"] == "OWNER") { + header("Location: app.php?page=content&msg=no_permission"); + die(); + } + } } else { header("Location: app.php?page=content&msg=invalid_pubid"); die(); @@ -33,107 +43,111 @@ if ($pub === false) { ?> - + - -