diff --git a/action.php b/action.php index b53e41d..0eba00e 100644 --- a/action.php +++ b/action.php @@ -58,13 +58,25 @@ switch ($VARS['action']) { if (!is_numeric($VARS['landscape']) || ((int) $VARS['landscape'] !== 0 && (int) $VARS['landscape'] !== 1)) { returnToSender('invalid_parameters'); } + if ($VARS['password_protect'] == 1) { + if (!is_empty($VARS['password'])) { + $password = password_hash($VARS['password'], PASSWORD_BCRYPT); + } else if (!$insert) { + $password = $database->get("publications", 'pwd', ['pubid' => $VARS['pubid']]); + } + $permission = 3; + } else { + $password = null; + $permission = $VARS['perm']; + } $data = [ 'pubname' => $VARS['name'], 'pubdate' => date("Y-m-d H:i:s"), 'styleid' => $VARS['style'], 'columns' => $VARS['columns'], - 'permid' => $VARS['perm'], + 'permid' => $permission, + 'pwd' => $password, 'page_size' => $VARS['size'], 'landscape' => $VARS['landscape'] ]; @@ -141,7 +153,7 @@ switch ($VARS['action']) { } $pubid = $database->get("tiles", "pubid", ['tileid' => $VARS['tileid']]); - + if ($database->get("publications", 'uid', ['pubid' => $pubid]) != $_SESSION['uid']) { die(json_encode(["status" => "ERROR", "msg" => lang("no permission", false)])); } diff --git a/database.mwb b/database.mwb index 7954784..d8d6a15 100644 Binary files a/database.mwb and b/database.mwb differ diff --git a/lang/en_us.php b/lang/en_us.php index 7002bae..886db14 100644 --- a/lang/en_us.php +++ b/lang/en_us.php @@ -66,4 +66,9 @@ define("STRINGS", [ "visibility loggedin" => "People with accounts", "visibility link" => "Anyone with the link", "visibility password" => "Anyone with the link and password", + "password protect" => "Password protect", + "anyone with link and password can view" => "When a password is set, anyone with the link and password can view the publication.", + "enter password to view file" => "Enter password to view file", + "view file" => "View File", + "password incorrect" => "Password incorrect." ]); \ No newline at end of file diff --git a/lib/gencontent.php b/lib/gencontent.php index 2603096..65de7e7 100644 --- a/lib/gencontent.php +++ b/lib/gencontent.php @@ -5,7 +5,7 @@ if (!defined("IN_NEWSPEN")) { if (is_numeric($VARS['pubid'])) { if ($database->has('publications', ['pubid' => $VARS['pubid']])) { $pub = $VARS['pubid']; - $pubdata = $database->get("publications", ["[>]pub_permissions" => ["permid" => "permid"]], ["pubname", "uid", "pubdate", "styleid", "columns", "page_size", "landscape", "publications.permid", "permname"], ["pubid" => $pub]); + $pubdata = $database->get("publications", ["[>]pub_permissions" => ["permid" => "permid"]], ["pubname", "uid", "pubdate", "styleid", "columns", "page_size", "landscape", "publications.permid", "permname", "pwd"], ["pubid" => $pub]); if ($pubdata["permname"] != "LINK") { dieifnotloggedin(); } @@ -14,6 +14,55 @@ if (!defined("IN_NEWSPEN")) { die(lang("no permission")); } } + if ($pubdata['permname'] == "LINK" && !is_empty($pubdata['pwd']) && $_SESSION['loggedin'] != true) { + $passok = false; + $passfail = false; + if (isset($VARS['password'])) { + $passok = password_verify($VARS['password'], $pubdata['pwd']); + $passfail = !$passok; + } + if (!$passok) { + ?> + + + +