-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_raw.php
71 lines (64 loc) · 2.54 KB
/
get_raw.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
require_once("config/db_connect.php");
require_once("lang/language.php");
$mysqli = new mysqli($db_host, $db_user, $db_pass, $db_name);
$name = $_POST["name"];
$pass = $_POST["pass"];
$sql = "SELECT password FROM user WHERE `name`='$name'";
$res = $mysqli->query($sql);
if ($res && mysqli_num_rows($res) > 0) {
$hash = $res->fetch_row()[0];
if (password_verify($pass, $hash)){
$verified_name = $name;
} else {
echo $l["Wrong password"];
exit;
}
}else{
echo $l["No user with that username"];
exit;
}
if (isset($_GET["link"]) && $_GET["link"] != "") {
require_once("src/helper.php");
$file_id = $_GET["link"];
$filename = explode(":", $file_id)[1];
$namespace = explode(":", $file_id)[0];
$access_filter = ($verified_name == $namespace)?"":" AND `access`=1";
$sql = "SELECT * FROM zettel WHERE `user`='$namespace' AND `name`='$filename'" . $access_filter;
$result = $mysqli->query($sql);
if ($result->num_rows == 1) {
$content = get_content($namespace, $filename);
echo $content;
} else {
echo $l["Access denied"];
}
}elseif(isset($_GET["list_all"]) && $_GET["list_all"] != ""){
$username = $_GET["list_all"];
if ($handle = opendir("zettel/$username")) {
while (false !== ($filename = readdir($handle))) {
if (substr($filename, 0, 1) != "."){
$access_filter = (($verified_name == $username) && isset($_POST["access_all"]))?"":" AND `access`=1";
$file_id = explode(".org", $filename)[0];
$sql = "SELECT * FROM zettel WHERE `user`='$username' AND `name`='$file_id'" . $access_filter;
$result = $mysqli->query($sql);
if ($result->num_rows == 1) {
echo "$filename\n";
}
}
}
}
}elseif(isset($_GET["bib"]) && $_GET["bib"] != ""){
$name = $_GET["bib"];
$access_filter = ($verified_name == $name)?"":" AND `access`=1";
$sql = "SELECT * FROM zettel WHERE `user`='$name'" . $access_filter;
$result = $mysqli->query($sql);
if ($result->num_rows >= 1) {
$bib_location = "bibliography/$name.bib";
if (is_file($bib_location)){
echo file_get_contents($bib_location);
}
}
}else{
echo "No Zettel specified!";
}
?>