Example #1
0
 /**
  * @return AuraStdioWrapper
  */
 public static function getIO()
 {
     if (self::$io === null) {
         self::$io = new AuraStdioWrapper((new CliFactory())->newStdio());
     }
     return self::$io;
 }
Example #2
0
 /**
  * @return array
  */
 public static function configure()
 {
     $io = PicCLI::getIO();
     $io->outln("Please specify the full path to where the SQLite database file should be created.");
     $path = PicCLI::prompt("Path");
     if (!$path) {
         $io->errln("No path specified.");
         exit(PicCLI::EXIT_INPUT);
     }
     if ($path[0] !== "/") {
         $io->errln("Must provide absolute path.");
         exit(PicCLI::EXIT_INPUT);
     }
     if (file_exists($path)) {
         $io->errln("Path to database file already exists.");
         exit(PicCLI::EXIT_INPUT);
     }
     if (!is_writeable(dirname($path))) {
         $io->errln("The current user does not have permission to write to that directory.");
         exit(PicCLI::EXIT_INPUT);
     }
     return array("path" => $path);
 }
Example #3
0
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();
Example #4
0
<?php

define("BASE_PATH", dirname(__DIR__) . "/");
if (!file_exists(BASE_PATH . "conf/app.json")) {
    fwrite(STDERR, "Pictorials is not installed.\n");
    exit(1);
}
if (empty($argv[1])) {
    fwrite(STDERR, "No sub-command specified.\n");
    exit(1);
}
require BASE_PATH . "main/bootstrap.php";
loadPicFile("classes/cli.php");
try {
    $command = PicCLI::initCommandCLI(array("create", "update", "delete", "view", "list", "allow", "deny", "permission"));
} catch (Exception $e) {
    PicCLI::getIO()->errln($e->getMessage());
    exit(PicCLI::EXIT_USAGE);
}
loadPicFile("entry/_path/{$command}.php");
Example #5
0
<?php

$io = PicCLI::getIO();
$validateWebroot = function ($webroot) {
    if ($webroot[0] !== "/") {
        throw new Exception("If supplying web root, must provide absolute path.");
    }
    if (!is_writeable($webroot)) {
        throw new Exception("Cannot create web root files automatically, web root is not writeable by current user.");
    }
};
if ($webroot = PicCLI::getGetopt("--webroot")) {
    try {
        $validateWebroot($webroot);
    } catch (Exception $e) {
        $io->errln($e->getMessage());
        exit(PicCLI::EXIT_USAGE);
    }
} else {
    $io->outln("Pictorials can automatically create the web entry point and asset symlink for you.");
    $io->outln("Enter the absolute path to the web root, or leave it empty so you can do this later.");
    $io->out("<<yellow>>Webroot: <<reset>>");
    $webroot = $io->in();
    if ($webroot) {
        try {
            $validateWebroot($webroot);
        } catch (Exception $e) {
            $io->errln($e->getMessage());
            exit(PicCLI::EXIT_INPUT);
        }
    } else {
Example #6
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"]));
    }
}
Example #7
0
<?php

PicCLI::initGetopt(array());
$io = PicCLI::getIO();
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>>");
Example #8
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));
    }
}
Example #9
0
<?php

$io = PicCLI::getIO();
$appConf = array("constants" => array("APP_NAME" => PicCLI::getGetopt("--appname", "Pictorials")), "image_sizes" => array("small" => array("width" => 250, "height" => 250), "medium" => array("width" => 400, "height" => 400), "large" => array("width" => 750, "height" => 750)), "image_types" => array("jpg", "png"));
$constantsKeys = array("cachedir" => "CACHE_DIR", "asset-baseurl" => "ASSET_BASE_URL", "script-baseurl" => "SCRIPT_BASE_URL");
foreach ($constantsKeys as $key => $const) {
    $val = PicCLI::getGetopt("--{$key}");
    if (!$val) {
        $io->errln("You must supply the --{$key} option.");
        exit(PicCLI::EXIT_USAGE);
    }
    if ($val[0] !== "/") {
        $io->errln("The path for the --{$key} setting must be absolute.");
        exit(PicCLI::EXIT_USAGE);
    }
    $appConf["constants"][$const] = $val;
}
$appConf["constants"]["ASSET_BASE_URL"] = rtrim($appConf["constants"]["ASSET_BASE_URL"], "/") . "/";
return $appConf;
Example #10
0
<?php

PicCLI::initGetopt(array());
$io = PicCLI::getIO();
if (!($pathID = PicCLI::getGetopt(1))) {
    $io->errln("No path ID specified.");
    exit(PicCLI::EXIT_USAGE);
}
if (!is_numeric($pathID)) {
    $io->errln("Invalid path ID supplied.");
    exit(PicCLI::EXIT_INPUT);
}
$pathID = (int) $pathID;
loadPicFile("classes/db.php");
PicDB::initDB();
if (!loadPicFile("helpers/id/path.php", array("id" => $pathID))) {
    $io->errln(sprintf("Path %d does not exist.", $pathID));
    exit(PicCLI::EXIT_INPUT);
}
$mainSelect = PicDB::newSelect();
$mainSelect->cols(array("name", "path", "sort_order"))->from("paths")->where("id = :id")->bindValue("id", $pathID);
$mainRow = PicDB::fetch($mainSelect, "one");
$permSelect = PicDB::newSelect();
$permSelect->cols(array("permission"))->from("path_permissions")->where("path_id = :path_id")->orderBy(array("permission ASC"))->bindValue("path_id", $pathID);
$permissions = PicDB::fetch($permSelect, "col");
$accessSelect = PicDB::newSelect();
$accessSelect->cols(array("path_id", "id_type", "auth_id"))->from("path_access")->where("path_id = :path_id")->where("auth_type = :auth_type")->bindValue("path_id", $pathID);
$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);
Example #11
0
<?php

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));