Exemplo n.º 1
0
    if (!($username = PicCLI::getGetopt(2))) {
        $username = PicCLI::prompt("Username");
        if (!$username) {
            $io->errln("No username specified.");
            exit(PicCLI::EXIT_INPUT);
        }
    }
    $id = loadPicFile("helpers/id/user.php", array("username" => $username));
    if (!$id) {
        $io->errln(sprintf("User '%s' does not exist.", $username));
        exit(PicCLI::EXIT_INPUT);
    }
    $idType = "users";
    $label = $username;
} elseif (PicCLI::getGetopt("--group")) {
    if (!($name = PicCLI::getGetopt(2))) {
        $name = PicCLI::prompt("Name");
        if (!$name) {
            $io->errln("No group name specified.");
            exit(PicCLI::EXIT_INPUT);
        }
    }
    $id = loadPicFile("helpers/id/group.php", array("name" => $name));
    if (!$id) {
        $io->errln(sprintf("Group '%s' does not exist.", $name));
        exit(PicCLI::EXIT_INPUT);
    }
    $idType = "groups";
    $label = $name;
} else {
    $io->errln("No ID type specified.");
Exemplo n.º 2
0
define("BASE_PATH", dirname(__DIR__) . "/");
if (file_exists(BASE_PATH . "conf/app.json")) {
    fwrite(STDERR, "Pictorials is already installed.\n");
    exit(1);
}
require BASE_PATH . "main/bootstrap-base.php";
loadPicFile("classes/cli.php");
PicCLI::initCLI();
PicCLI::initGetopt(array("dbtype:", "appname:", "cachedir:", "asset-baseurl:", "script-baseurl:", "webroot:"));
$io = PicCLI::getIO();
if (!is_writeable(BASE_PATH . "/conf")) {
    $io->errln("Current user must have permission to write to conf directory.");
    exit(PicCLI::EXIT_FAIL);
}
$dbType = PicCLI::getGetopt("--dbtype");
if (!file_exists(BASE_PATH . "helpers/install/db.{$dbType}.php")) {
    $io->errln("You must specify a supported database type.");
    exit(PicCLI::EXIT_USAGE);
}
$appConf = loadPicFile("helpers/install/appconf.php");
loadPicFile("helpers/install/db.{$dbType}.php");
$dbConf = array("type" => $dbType, "config" => PicDBInstall::configure());
$webroot = loadPicFile("helpers/install/webroot.php");
$webEntryTemplate = '<?php
define("BASE_PATH", "%s");
require(BASE_PATH . "entry/web.php");';
file_put_contents(BASE_PATH . "/conf/app.json", json_encode($appConf, JSON_PRETTY_PRINT));
file_put_contents(BASE_PATH . "/conf/db.json", json_encode($dbConf, JSON_PRETTY_PRINT));
if ($webroot) {
    $webroot = rtrim($webroot, "/");
Exemplo n.º 3
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 {
Exemplo n.º 4
0
if (!($pathID = PicCLI::getGetopt(1))) {
    $io->errln("No path ID specified.");
    exit(PicCLI::EXIT_USAGE);
}
if (!is_numeric($pathID)) {
    $io->errln("Invalid path ID specified.");
    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);
}
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));
Exemplo n.º 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"]));
    }
}
Exemplo n.º 6
0
<?php

PicCLI::initGetopt(array());
$io = PicCLI::getIO();
if (!($groupName = PicCLI::getGetopt(1))) {
    $groupName = PicCLI::prompt("Group");
    if (!$groupName) {
        $io->errln("No group specified.");
        exit(PicCLI::EXIT_INPUT);
    }
}
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();
Exemplo n.º 7
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);
    }
}
if (!($username = PicCLI::getGetopt(2))) {
    $username = PicCLI::prompt("Username");
    if (!$username) {
        $io->errln("No username specified.");
        exit(PicCLI::EXIT_INPUT);
    }
}
if (!($password = PicCLI::getGetopt(3))) {
    $password = PicCLI::prompt("Password");
    if (!$password) {
        $io->errln("No password specified.");
        exit(PicCLI::EXIT_INPUT);
    }
}
loadPicFile("classes/db.php");
PicDB::initDB();
$insert = PicDB::newInsert();
$insert->into("users")->cols(array("name" => $name, "username" => $username, "password" => $password));
PicDB::crud($insert);
PicCLI::success();
Exemplo n.º 8
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;
Exemplo n.º 9
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);
Exemplo n.º 10
0
}
if (!($path = PicCLI::getGetopt(2))) {
    $path = PicCLI::prompt("Path");
    if (!$path) {
        $io->errln("No path specified.");
        exit(PicCLI::EXIT_INPUT);
    }
}
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;
    }
}