Exemple #1
0
<?php

$select = PicDB::newSelect();
$select->cols(array("id"))->from("paths")->where("id = :id")->bindValue("id", $id);
if (PicDB::fetch($select, "one")) {
    return true;
} else {
    return false;
}
Exemple #2
0
$row = PicDB::fetch($select, "one");
class PicPathAccessException extends Exception
{
    public $mode;
    public $idType;
    public $label;
    public static function initE($mode, $idType, $label)
    {
        $e = new self();
        $e->mode = $mode;
        $e->idType = $idType;
        $e->label = $label;
        throw $e;
    }
}
if ($row && $mode === "add") {
    PicPathAccessException::initE($mode, $idType, $label);
} elseif (!$row && $mode === "remove") {
    PicPathAccessException::initE($mode, $idType, $label);
}
if ($mode === "add") {
    $insert = PicDB::newInsert();
    $insert->into("path_access")->cols(array("path_id" => $pathID, "auth_type" => $authType, "id_type" => $idType, "auth_id" => $id));
    PicDB::crud($insert);
} elseif ($mode === "remove") {
    $delete = PicDB::newDelete();
    $delete->from("path_access")->where("id = :id")->bindValue("id", $row["id"]);
    PicDB::crud($delete);
}
PicConfCache::remove("pathauth.json");
PicCLI::success();
 /**
  * @return PicPath
  */
 public static function getCurrentPath()
 {
     if (self::$currentPath !== null) {
         return self::$currentPath;
     }
     $pathID = self::verifyCurrentPathAccess();
     $pathSelect = PicDB::newSelect();
     $pathSelect->cols(array("name", "path"))->from("paths")->where("id = :id")->bindValue("id", $pathID);
     $pathDetails = PicDB::fetch($pathSelect, "one");
     $permSelect = PicDB::newSelect();
     $permSelect->cols(array("permission"))->from("path_permissions")->where("path_id = :path_id")->bindValue("path_id", $pathID);
     $permissions = PicDB::fetch($permSelect, "col");
     self::$currentPath = new PicPath($pathDetails["name"], $pathDetails["path"], $permissions);
     return self::$currentPath;
 }
Exemple #4
0
<?php

PicCLI::initGetopt(array());
$io = PicCLI::getIO();
if (!($name = PicCLI::getGetopt(1))) {
    $name = PicCLI::prompt("Name");
    if (!$name) {
        $io->errln("No name specified.");
        exit(PicCLI::EXIT_INPUT);
    }
}
loadPicFile("classes/db.php");
PicDB::initDB();
$insert = PicDB::newInsert();
$insert->into("groups")->cols(array("name" => $name));
PicDB::crud($insert);
PicCLI::success();
Exemple #5
0
<?php

PicCLI::initGetopt(array("sort::"));
$io = PicCLI::getIO();
loadPicFile("classes/db.php");
PicDB::initDB();
$select = PicDB::newSelect();
$select->cols(array("id", "name", "path"))->from("paths");
$sortOption = PicCLI::getGetopt("--sort");
if ($sortOption === true || $sortOption === "sortorder") {
    $select->orderBy(array("sort_order ASC"));
} elseif ($sortOption === "name") {
    $select->orderBy(array("name ASC"));
}
$select->orderBy(array("id ASC"));
$rows = PicDB::fetch($select, "assoc");
if (empty($rows)) {
    $io->outln("No paths have been created.");
} else {
    $highestId = max(array_keys($rows));
    $idWidth = strlen((string) $highestId);
    foreach ($rows as $id => $data) {
        $io->out(sprintf("<<blue>>%s<<reset>> ", str_pad($id, $idWidth)));
        $io->outln(sprintf('%1$s - %2$s', $data["name"], $data["path"]));
    }
}
Exemple #6
0
 public static function initDB()
 {
     $dbConf = loadPicFile("conf/db.json");
     self::$queryFactory = new QueryFactory($dbConf["type"], QueryFactory::COMMON);
     self::$conn = loadPicFile("helpers/db/" . $dbConf["type"] . ".php", array("config" => $dbConf["config"]));
 }
Exemple #7
0
if (!($name = PicCLI::getGetopt(1))) {
    $io->errln("No name specified.");
    exit(PicCLI::EXIT_USAGE);
}
loadPicFile("classes/db.php");
PicDB::initDB();
$mySelect = PicDB::newSelect();
$mySelect->cols(array("group_id", "user_id"))->from("group_memberships");
$myResult = PicDB::fetch($mySelect, "group");
var_dump($myResult);
exit;
$groupId = loadPicFile("helpers/id/group.php", array("name" => $name));
if (!$groupId) {
    $io->errln(sprintf("Group '%s' does not exist.", $name));
    exit(PicCLI::EXIT_INPUT);
}
$uidSelect = PicDB::newSelect();
$uidSelect->cols(array("user_id"))->from("group_memberships")->where("group_id = :group_id")->bindValue("group_id", $groupId);
$userIds = PicDB::fetch($uidSelect, "col");
$io->outln(sprintf("<<blue>>Group:<<reset>> %s", $name));
if (empty($userIds)) {
    $io->outln("No users assigned.");
} else {
    $uSelect = PicDB::newSelect();
    $uSelect->cols(array("name", "username"))->from("users")->where("id IN (:ids)")->bindValue("ids", array_map("intval", $userIds));
    $userDetails = PicDB::fetch($uSelect, "all");
    $io->outln("<<blue>>Users:<<reset>>");
    foreach ($userDetails as $user) {
        $io->outln(sprintf(' - %1$s (%2$s)', $user["name"], $user["username"]));
    }
}
<?php

if (empty($_POST)) {
    $appConf = loadPicFile("conf/app.json");
    $pathSelect = PicDB::newSelect();
    $pathSelect->cols(array("id", "name"))->from("paths")->where("id IN (:ids)")->bindValue("ids", Access::getAllowedPaths());
    $templateVars = array("paths" => PicDB::fetch($pathSelect, "pairs"), "imageSizes" => $appConf["image_sizes"]);
    if (isset($appConf["mapbox"])) {
        $templateVars["mapboxConf"] = $appConf["mapbox"];
    }
    loadPicTemplate("templates/filebrowser.phtml", $templateVars);
    exit;
}
$path = Access::getCurrentPath();
if (!empty($_POST["relpath"])) {
    $relpath = loadPicFile("helpers/filenamereject.php", array("filename" => $_POST["relpath"]));
    if (!is_dir($path->path . "/" . $relpath)) {
        sendError(404);
    }
}
use Symfony\Component\Finder\Finder;
$directoryFinder = new Finder();
$directoryFinder->directories()->ignoreUnreadableDirs()->depth(0)->sortByName();
if ($path->hasPermission("symlinks")) {
    $directoryFinder->followLinks();
}
if (!empty($relpath)) {
    $directoryFinder->path($relpath)->depth(substr_count($relpath, "/") + 1);
}
if ($path->hasPermission("nsfw") === false) {
    $directoryFinder->notPath("/.*\\/NSFW\\/.*/")->notPath("/NSFW\\/.*/")->notPath("/.*\\/NSFW/");
Exemple #9
0
<?php

require BASE_PATH . "main/bootstrap.php";
loadPicFile("main/logging.php");
loadPicFile("classes/db.php");
loadPicFile("classes/accesscontrol.php");
loadPicFile("classes/image.php");
loadPicFile("classes/mrmime.php");
PicDB::initDB();
loadPicFile("main/auth.php");
if (empty($_GET["mode"])) {
    loadPicFile("modes/filebrowser.php");
    exit;
}
switch ($_GET["mode"]) {
    case "download":
    case "filebrowser":
    case "loadimage":
    case "share":
    case "sysload":
        loadPicFile("modes/{$_GET["mode"]}.php");
        break;
    default:
        sendError(404);
}
Exemple #10
0
<?php

$select = PicDB::newSelect();
$select->cols(array("id"))->from("users")->where("username = :username")->bindValue("username", $username);
$id = PicDB::fetch($select, "value");
if ($id) {
    return (int) $id;
} else {
    return null;
}
Exemple #11
0
<?php

$select = PicDB::newSelect();
$select->cols(array("path_id", "files"))->from("shares")->where("share_id = :share_id")->bindValue("share_id", $shareID);
$row = PicDB::fetch($select, "one");
if ($row) {
    return array($row["path_id"], explode(PATH_SEPARATOR, $row["files"]));
} else {
    return null;
}
    goto finalise;
}
$authConfigTemplate = ["allow" => ["users" => [], "groups" => []], "deny" => ["users" => [], "groups" => []]];
$pathIDSelect = PicDB::newSelect();
$pathIDSelect->cols(array("id"))->from("paths");
$pathIDs = PicDB::fetch($pathIDSelect, "col");
$authConfig = array();
foreach ($pathIDs as $pathID) {
    $authConfig[$pathID] = $authConfigTemplate;
}
$accessSelect = PicDB::newSelect();
$accessSelect->cols(array("path_id", "id_type", "auth_id"))->from("path_access")->where("auth_type = :auth_type");
$accessSelect->bindValue("auth_type", "allow");
$allowRows = PicDB::fetch($accessSelect, "group", PDO::FETCH_NAMED);
$accessSelect->bindValue("auth_type", "deny");
$denyRows = PicDB::fetch($accessSelect, "group", PDO::FETCH_NAMED);
foreach ($allowRows as $path => $allowRow) {
    foreach ($allowRow as $auth) {
        $authConfig[$path]["allow"][$auth["id_type"]][] = $auth["auth_id"];
    }
}
foreach ($denyRows as $path => $denyRow) {
    foreach ($denyRow as $auth) {
        $authConfig[$path]["deny"][$auth["id_type"]][] = $auth["auth_id"];
    }
}
PicConfCache::set("pathauth.json", $authConfig);
finalise:
if (isset($selectedPathId)) {
    return $authConfig[$selectedPathId];
} else {
Exemple #13
0
} else {
    $io->outln("");
    $uSelect->bindValue("ids", array_map("intval", $allowRows["users"]));
    $userRows = PicDB::fetch($uSelect, "all");
    foreach ($userRows as $userRow) {
        $io->outln(sprintf('   - %1$s (%2$s)', $userRow["name"], $userRow["username"]));
    }
}
$io->outln("<<blue>>Denied access:<<reset>>");
$io->out("  <<blue>>Groups:<<reset>> ");
if (empty($denyRows["groups"])) {
    $io->outln("None");
} else {
    $io->outln("");
    $gSelect->bindValue("ids", array_map("intval", $denyRows["groups"]));
    $groupNames = PicDB::fetch($gSelect, "col");
    foreach ($groupNames as $groupName) {
        $io->outln(sprintf("   - %s", $groupName));
    }
}
$io->out("  <<blue>>Users:<<reset>>");
if (empty($denyRows["users"])) {
    $io->outln(" None");
} else {
    $io->outln("");
    $uSelect->bindValue("ids", array_map("intval", $denyRows["users"]));
    $userRows = PicDB::fetch($uSelect, "all");
    foreach ($userRows as $userRow) {
        $io->outln(sprintf('   - %1$s (%2$s)', $userRow["name"], $userRow["username"]));
    }
}
Exemple #14
0
PicCLI::initGetopt(array());
$io = PicCLI::getIO();
if (!($username = PicCLI::getGetopt(1))) {
    $io->errln("No username specified.");
    exit(PicCLI::EXIT_USAGE);
}
loadPicFile("classes/db.php");
PicDB::initDB();
$userId = loadPicFile("helpers/id/user.php", array("username" => $username));
if (!$userId) {
    $io->errln(sprintf("User '%s' does not exist.", $username));
    exit(PicCLI::EXIT_INPUT);
}
$select = PicDB::newSelect();
$select->cols(array("name"))->from("users")->where("username = :username")->bindValue("username", $username);
$name = PicDB::fetch($select, "value");
$gidSelect = PicDB::newSelect();
$gidSelect->cols(array("group_id"))->from("group_memberships")->where("user_id = :user_id")->bindValue("user_id", $userId);
$groupIds = PicDB::fetch($gidSelect, "col");
$io->outln(sprintf("<<blue>>Name:<<reset>> %s", $name));
if (empty($groupIds)) {
    $io->outln("Not assigned to any groups.");
} else {
    $gSelect = PicDB::newSelect();
    $gSelect->cols(array("name"))->from("groups")->where("id IN (:ids)")->bindValue("ids", array_map("intval", $groupIds));
    $groupNames = PicDB::fetch($gSelect, "col");
    $io->outln("<<blue>>Groups:<<reset>>");
    foreach ($groupNames as $groupName) {
        $io->outln(sprintf(' - %s', $groupName));
    }
}
Exemple #15
0
    }
}
if ($path[0] !== "/") {
    $io->errln("Paths must be absolute, not relative.");
    exit(PicCLI::EXIT_INPUT);
}
$path = rtrim($path, "/") . "/";
loadPicFile("classes/db.php");
PicDB::initDB();
if ($sortOrder = PicCLI::getGetopt("--sortorder")) {
    $sortOrder = (int) $sortOrder;
    if ($sortOrder <= 0) {
        $io->errln("Sort orders must be above zero.");
        exit(PicCLI::EXIT_INPUT);
    }
} else {
    $soSelect = PicDB::newSelect();
    $soSelect->cols(array("MAX(sort_order)"))->from("paths");
    $sortOrder = (int) PicDB::fetch($soSelect, "value");
    if ($sortOrder) {
        $sortOrder = max($sortOrder, 1) + 1;
    } else {
        $sortOrder = 1;
    }
}
$insert = PicDB::newInsert();
$insert->into("paths")->cols(array("name" => $name, "path" => $path, "sort_order" => $sortOrder));
PicDB::crud($insert);
$io->outln(sprintf("<<blue>>Path ID:<<reset>> %d", PicDB::lastInsertId()));
PicConfCache::remove("pathauth.json");
PicCLI::success();