Beispiel #1
0
    }
}
if (!($username = PicCLI::getGetopt(2))) {
    $username = PicCLI::prompt("Username");
    if (!$username) {
        $io->errln("No username specified.");
        exit(PicCLI::EXIT_INPUT);
    }
}
loadPicFile("classes/db.php");
PicDB::initDB();
$groupId = loadPicFile("helpers/id/group.php", array("name" => $groupName));
if (!$groupId) {
    $io->errln(sprintf("Group '%s' does not exist.", $groupName));
    exit(PicCLI::EXIT_INPUT);
}
$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("id"))->from("group_memberships")->where("group_id = :group_id")->where("user_id = :user_id")->bindValues(array("group_id" => $groupId, "user_id" => $userId));
if (PicDB::fetch($select, "one")) {
    PicCLI::warn(sprintf('User \'%1$s\' is already a member of group \'%2$s\'.', $username, $groupName));
    exit;
}
$insert = PicDB::newInsert();
$insert->into("group_memberships")->cols(array("group_id" => $groupId, "user_id" => $userId));
PicDB::crud($insert);
PicCLI::success();
Beispiel #2
0
if (!($permission = PicCLI::getGetopt(2))) {
    $permission = PicCLI::prompt("Permission");
    if (!$permission) {
        $io->errln("No permission specified.");
        exit(PicCLI::EXIT_INPUT);
    }
}
if (!in_array($permission, array("gps", "metadata", "nsfw", "symlinks"))) {
    $io->errln("Invalid permission supplied.");
    exit(PicCLI::EXIT_INPUT);
}
$select = PicDB::newSelect();
$select->cols(array("id"))->from("path_permissions")->where("path_id = :path_id")->where("permission = :permission")->bindValues(array("path_id" => $pathID, "permission" => $permission));
$row = PicDB::fetch($select, "one");
if ($row && $mode === "add") {
    PicCLI::warn(sprintf('Path \'%1$s\' already has the \'%2$s\' permission.', $pathID, $permission));
    exit;
} elseif (!$row && $mode === "remove") {
    PicCLI::warn(sprintf('Path \'%1$s\' already doesn\'t have the \'%2$s\' permission.', $pathID, $permission));
    exit;
}
if ($mode === "add") {
    $insert = PicDB::newInsert();
    $insert->into("path_permissions")->cols(array("path_id" => $pathID, "permission" => $permission));
    PicDB::crud($insert);
} elseif ($mode === "remove") {
    $delete = PicDB::newDelete();
    $delete->from("path_permissions")->where("id = :id")->bindValue("id", $row["id"]);
    PicDB::crud($delete);
}
PicCLI::success();
Beispiel #3
0
<?php

try {
    loadPicFile("entry/_path/_access.php", array("authType" => "deny"));
} catch (PicPathAccessException $e) {
    if ($e->mode === "add") {
        PicCLI::warn(sprintf('%1$s \'%2$s\' is already denied access to this path.', ucwords($e->idType), $e->label));
    } elseif ($e->mode === "remove") {
        PicCLI::warn(sprintf('%1$s \'%2$s\' is already not explicitly denied access to this path.', ucwords($e->idType), $e->label));
    }
}