Cleaned up globals
This commit is contained in:
parent
4f7d5aa132
commit
655aecd29d
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
global $utopia, $register, $request, $response, $user, $audit,
|
||||
global $register, $request, $response, $user, $audit,
|
||||
$webhook, $mail, $project, $projectDB, $clients;
|
||||
|
||||
use Utopia\App;
|
||||
|
@ -255,7 +255,7 @@ App::get('/v1/account/sessions/oauth2/:provider')
|
|||
->param('failure', $oauthDefaultFailure, function () use ($clients) { return new Host($clients); }, 'URL to redirect back to your app after a failed login attempt. Only URLs from hostnames in your project platform list are allowed. This requirement helps to prevent an [open redirect](https://cheatsheetseries.owasp.org/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.html) attack against your project API.', true)
|
||||
->param('scopes', [], function () { return new ArrayList(new Text(128)); }, 'A list of custom OAuth2 scopes. Check each provider internal docs for a list of supported scopes.', true)
|
||||
->action(
|
||||
function ($provider, $success, $failure, $scopes) use ($response, $request, $utopia, $project) {
|
||||
function ($provider, $success, $failure, $scopes) use ($response, $request, $project) {
|
||||
$protocol = Config::getParam('protocol');
|
||||
$callback = $protocol.'://'.$request->getServer('HTTP_HOST').'/v1/account/sessions/oauth2/callback/'.$provider.'/'.$project->getId();
|
||||
$appId = $project->getAttribute('usersOauth2'.\ucfirst($provider).'Appid', '');
|
||||
|
@ -347,7 +347,7 @@ App::get('/v1/account/sessions/oauth2/:provider/redirect')
|
|||
->param('code', '', function () { return new Text(1024); }, 'OAuth2 code.')
|
||||
->param('state', '', function () { return new Text(2048); }, 'OAuth2 state params.', true)
|
||||
->action(
|
||||
function ($provider, $code, $state) use ($response, $request, $utopia, $user, $projectDB, $project, $audit, $oauthDefaultSuccess) {
|
||||
function ($provider, $code, $state) use ($response, $request, $user, $projectDB, $project, $audit, $oauthDefaultSuccess) {
|
||||
$protocol = Config::getParam('protocol');
|
||||
$callback = $protocol.'://'.$request->getServer('HTTP_HOST').'/v1/account/sessions/oauth2/callback/'.$provider.'/'.$project->getId();
|
||||
$defaultState = ['success' => $project->getAttribute('url', ''), 'failure' => ''];
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
global $utopia, $request, $response;
|
||||
global $response;
|
||||
|
||||
use Utopia\App;
|
||||
use Utopia\Exception;
|
||||
|
@ -213,7 +213,7 @@ App::get('/v1/avatars/favicon')
|
|||
->label('sdk.methodType', 'location')
|
||||
->label('sdk.description', '/docs/references/avatars/get-favicon.md')
|
||||
->action(
|
||||
function ($url) use ($response, $request) {
|
||||
function ($url) use ($response) {
|
||||
$width = 56;
|
||||
$height = 56;
|
||||
$quality = 80;
|
||||
|
@ -246,7 +246,7 @@ App::get('/v1/avatars/favicon')
|
|||
CURLOPT_URL => $url,
|
||||
CURLOPT_USERAGENT => \sprintf(APP_USERAGENT,
|
||||
Config::getParam('version'),
|
||||
$request->getServer('_APP_SYSTEM_SECURITY_EMAIL_ADDRESS', APP_EMAIL_SECURITY)
|
||||
App::getEnv('_APP_SYSTEM_SECURITY_EMAIL_ADDRESS', APP_EMAIL_SECURITY)
|
||||
),
|
||||
]);
|
||||
|
||||
|
|
|
@ -1,11 +1,10 @@
|
|||
<?php
|
||||
|
||||
global $utopia, $register, $request, $response, $webhook, $audit, $projectDB;
|
||||
global $request, $response, $webhook, $audit, $projectDB;
|
||||
|
||||
use Utopia\App;
|
||||
use Utopia\Exception;
|
||||
use Utopia\Response;
|
||||
use Utopia\Validator\Boolean;
|
||||
use Utopia\Validator\Range;
|
||||
use Utopia\Validator\WhiteList;
|
||||
use Utopia\Validator\Text;
|
||||
|
@ -484,7 +483,7 @@ App::get('/v1/database/collections/:collectionId/documents')
|
|||
->param('orderCast', 'string', function () { return new WhiteList(array('int', 'string', 'date', 'time', 'datetime')); }, 'Order field type casting. Possible values are int, string, date, time or datetime. The database will attempt to cast the order field to the value you pass here. The default value is a string.', true)
|
||||
->param('search', '', function () { return new Text(256); }, 'Search query. Enter any free text search. The database will try to find a match against all document attributes and children.', true)
|
||||
->action(
|
||||
function ($collectionId, $filters, $offset, $limit, $orderField, $orderType, $orderCast, $search) use ($response, $projectDB, $utopia) {
|
||||
function ($collectionId, $filters, $offset, $limit, $orderField, $orderType, $orderCast, $search) use ($response, $projectDB) {
|
||||
$collection = $projectDB->getDocument($collectionId, false);
|
||||
|
||||
if (\is_null($collection->getId()) || Database::SYSTEM_COLLECTION_COLLECTIONS != $collection->getCollection()) {
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
<?php
|
||||
|
||||
global $utopia;
|
||||
|
||||
use Utopia\App;
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
global $utopia, $request, $response, $register;
|
||||
global $request, $response, $register;
|
||||
|
||||
use Utopia\App;
|
||||
use Utopia\Exception;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
global $utopia, $request, $response, $user;
|
||||
global $request, $response, $user;
|
||||
|
||||
use Utopia\App;
|
||||
use Utopia\Locale\Locale;
|
||||
|
@ -15,7 +15,7 @@ App::get('/v1/locale')
|
|||
->label('sdk.method', 'get')
|
||||
->label('sdk.description', '/docs/references/locale/get-locale.md')
|
||||
->action(
|
||||
function () use ($response, $request, $utopia) {
|
||||
function () use ($response, $request) {
|
||||
$eu = include __DIR__.'/../../config/eu.php';
|
||||
$currencies = include __DIR__.'/../../config/currencies.php';
|
||||
$reader = new Reader(__DIR__.'/../../db/DBIP/dbip-country-lite-2020-01.mmdb');
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
global $utopia, $request, $response, $register, $user, $consoleDB, $projectDB, $deletes;
|
||||
global $response, $register, $user, $consoleDB, $projectDB, $deletes;
|
||||
|
||||
use Utopia\App;
|
||||
use Utopia\Exception;
|
||||
|
@ -42,7 +42,7 @@ App::post('/v1/projects')
|
|||
->param('legalAddress', '', function () { return new Text(256); }, 'Project legal Address.', true)
|
||||
->param('legalTaxId', '', function () { return new Text(256); }, 'Project legal Tax ID.', true)
|
||||
->action(
|
||||
function ($name, $teamId, $description, $logo, $url, $legalName, $legalCountry, $legalState, $legalCity, $legalAddress, $legalTaxId) use ($response, $user, $consoleDB, $projectDB) {
|
||||
function ($name, $teamId, $description, $logo, $url, $legalName, $legalCountry, $legalState, $legalCity, $legalAddress, $legalTaxId) use ($response, $consoleDB, $projectDB) {
|
||||
$team = $projectDB->getDocument($teamId);
|
||||
|
||||
if (empty($team->getId()) || Database::SYSTEM_COLLECTION_TEAMS != $team->getCollection()) {
|
||||
|
@ -94,7 +94,7 @@ App::get('/v1/projects')
|
|||
->label('sdk.namespace', 'projects')
|
||||
->label('sdk.method', 'list')
|
||||
->action(
|
||||
function () use ($request, $response, $consoleDB) {
|
||||
function () use ($response, $consoleDB) {
|
||||
$results = $consoleDB->getCollection([
|
||||
'limit' => 20,
|
||||
'offset' => 0,
|
||||
|
@ -111,7 +111,7 @@ App::get('/v1/projects')
|
|||
$secret = \json_decode($project->getAttribute('usersOauth2'.\ucfirst($provider).'Secret', '{}'), true);
|
||||
|
||||
if (!empty($secret) && isset($secret['version'])) {
|
||||
$key = $request->getServer('_APP_OPENSSL_KEY_V'.$secret['version']);
|
||||
$key = App::getEnv('_APP_OPENSSL_KEY_V'.$secret['version']);
|
||||
$project->setAttribute('usersOauth2'.\ucfirst($provider).'Secret', OpenSSL::decrypt($secret['data'], $secret['method'], $key, 0, \hex2bin($secret['iv']), \hex2bin($secret['tag'])));
|
||||
}
|
||||
}
|
||||
|
@ -129,7 +129,7 @@ App::get('/v1/projects/:projectId')
|
|||
->label('sdk.method', 'get')
|
||||
->param('projectId', '', function () { return new UID(); }, 'Project unique ID.')
|
||||
->action(
|
||||
function ($projectId) use ($request, $response, $consoleDB) {
|
||||
function ($projectId) use ($response, $consoleDB) {
|
||||
$project = $consoleDB->getDocument($projectId);
|
||||
|
||||
if (empty($project->getId()) || Database::SYSTEM_COLLECTION_PROJECTS != $project->getCollection()) {
|
||||
|
@ -140,7 +140,7 @@ App::get('/v1/projects/:projectId')
|
|||
$secret = \json_decode($project->getAttribute('usersOauth2'.\ucfirst($provider).'Secret', '{}'), true);
|
||||
|
||||
if (!empty($secret) && isset($secret['version'])) {
|
||||
$key = $request->getServer('_APP_OPENSSL_KEY_V'.$secret['version']);
|
||||
$key = App::getEnv('_APP_OPENSSL_KEY_V'.$secret['version']);
|
||||
$project->setAttribute('usersOauth2'.\ucfirst($provider).'Secret', OpenSSL::decrypt($secret['data'], $secret['method'], $key, 0, \hex2bin($secret['iv']), \hex2bin($secret['tag'])));
|
||||
}
|
||||
}
|
||||
|
@ -368,14 +368,14 @@ App::patch('/v1/projects/:projectId/oauth2')
|
|||
->param('appId', '', function () { return new Text(256); }, 'Provider app ID.', true)
|
||||
->param('secret', '', function () { return new text(512); }, 'Provider secret key.', true)
|
||||
->action(
|
||||
function ($projectId, $provider, $appId, $secret) use ($request, $response, $consoleDB) {
|
||||
function ($projectId, $provider, $appId, $secret) use ($response, $consoleDB) {
|
||||
$project = $consoleDB->getDocument($projectId);
|
||||
|
||||
if (empty($project->getId()) || Database::SYSTEM_COLLECTION_PROJECTS != $project->getCollection()) {
|
||||
throw new Exception('Project not found', 404);
|
||||
}
|
||||
|
||||
$key = $request->getServer('_APP_OPENSSL_KEY_V1');
|
||||
$key = App::getEnv('_APP_OPENSSL_KEY_V1');
|
||||
$iv = OpenSSL::randomPseudoBytes(OpenSSL::cipherIVLength(OpenSSL::CIPHER_AES_128_GCM));
|
||||
$tag = null;
|
||||
$secret = \json_encode([
|
||||
|
@ -459,7 +459,7 @@ App::post('/v1/projects/:projectId/webhooks')
|
|||
->param('httpUser', '', function () { return new Text(256); }, 'Webhook HTTP user.', true)
|
||||
->param('httpPass', '', function () { return new Text(256); }, 'Webhook HTTP password.', true)
|
||||
->action(
|
||||
function ($projectId, $name, $events, $url, $security, $httpUser, $httpPass) use ($request, $response, $consoleDB) {
|
||||
function ($projectId, $name, $events, $url, $security, $httpUser, $httpPass) use ($response, $consoleDB) {
|
||||
$project = $consoleDB->getDocument($projectId);
|
||||
|
||||
if (empty($project->getId()) || Database::SYSTEM_COLLECTION_PROJECTS != $project->getCollection()) {
|
||||
|
@ -467,7 +467,7 @@ App::post('/v1/projects/:projectId/webhooks')
|
|||
}
|
||||
|
||||
$security = ($security === '1' || $security === 'true' || $security === 1 || $security === true);
|
||||
$key = $request->getServer('_APP_OPENSSL_KEY_V1');
|
||||
$key = App::getEnv('_APP_OPENSSL_KEY_V1');
|
||||
$iv = OpenSSL::randomPseudoBytes(OpenSSL::cipherIVLength(OpenSSL::CIPHER_AES_128_GCM));
|
||||
$tag = null;
|
||||
$httpPass = \json_encode([
|
||||
|
@ -519,7 +519,7 @@ App::get('/v1/projects/:projectId/webhooks')
|
|||
->label('sdk.method', 'listWebhooks')
|
||||
->param('projectId', '', function () { return new UID(); }, 'Project unique ID.')
|
||||
->action(
|
||||
function ($projectId) use ($request, $response, $consoleDB) {
|
||||
function ($projectId) use ($response, $consoleDB) {
|
||||
$project = $consoleDB->getDocument($projectId);
|
||||
|
||||
if (empty($project->getId()) || Database::SYSTEM_COLLECTION_PROJECTS != $project->getCollection()) {
|
||||
|
@ -535,7 +535,7 @@ App::get('/v1/projects/:projectId/webhooks')
|
|||
continue;
|
||||
}
|
||||
|
||||
$key = $request->getServer('_APP_OPENSSL_KEY_V'.$httpPass['version']);
|
||||
$key = App::getEnv('_APP_OPENSSL_KEY_V'.$httpPass['version']);
|
||||
|
||||
$webhook->setAttribute('httpPass', OpenSSL::decrypt($httpPass['data'], $httpPass['method'], $key, 0, \hex2bin($httpPass['iv']), \hex2bin($httpPass['tag'])));
|
||||
}
|
||||
|
@ -553,7 +553,7 @@ App::get('/v1/projects/:projectId/webhooks/:webhookId')
|
|||
->param('projectId', null, function () { return new UID(); }, 'Project unique ID.')
|
||||
->param('webhookId', null, function () { return new UID(); }, 'Webhook unique ID.')
|
||||
->action(
|
||||
function ($projectId, $webhookId) use ($request, $response, $consoleDB) {
|
||||
function ($projectId, $webhookId) use ($response, $consoleDB) {
|
||||
$project = $consoleDB->getDocument($projectId);
|
||||
|
||||
if (empty($project->getId()) || Database::SYSTEM_COLLECTION_PROJECTS != $project->getCollection()) {
|
||||
|
@ -569,7 +569,7 @@ App::get('/v1/projects/:projectId/webhooks/:webhookId')
|
|||
$httpPass = \json_decode($webhook->getAttribute('httpPass', '{}'), true);
|
||||
|
||||
if (!empty($httpPass) && isset($httpPass['version'])) {
|
||||
$key = $request->getServer('_APP_OPENSSL_KEY_V'.$httpPass['version']);
|
||||
$key = App::getEnv('_APP_OPENSSL_KEY_V'.$httpPass['version']);
|
||||
$webhook->setAttribute('httpPass', OpenSSL::decrypt($httpPass['data'], $httpPass['method'], $key, 0, \hex2bin($httpPass['iv']), \hex2bin($httpPass['tag'])));
|
||||
}
|
||||
|
||||
|
@ -592,7 +592,7 @@ App::put('/v1/projects/:projectId/webhooks/:webhookId')
|
|||
->param('security', false, function () { return new Boolean(true); }, 'Certificate verification, false for disabled or true for enabled.') ->param('httpUser', '', function () { return new Text(256); }, 'Webhook HTTP user.', true)
|
||||
->param('httpPass', '', function () { return new Text(256); }, 'Webhook HTTP password.', true)
|
||||
->action(
|
||||
function ($projectId, $webhookId, $name, $events, $url, $security, $httpUser, $httpPass) use ($request, $response, $consoleDB) {
|
||||
function ($projectId, $webhookId, $name, $events, $url, $security, $httpUser, $httpPass) use ($response, $consoleDB) {
|
||||
$project = $consoleDB->getDocument($projectId);
|
||||
|
||||
if (empty($project->getId()) || Database::SYSTEM_COLLECTION_PROJECTS != $project->getCollection()) {
|
||||
|
@ -600,7 +600,7 @@ App::put('/v1/projects/:projectId/webhooks/:webhookId')
|
|||
}
|
||||
|
||||
$security = ($security === '1' || $security === 'true' || $security === 1 || $security === true);
|
||||
$key = $request->getServer('_APP_OPENSSL_KEY_V1');
|
||||
$key = App::getEnv('_APP_OPENSSL_KEY_V1');
|
||||
$iv = OpenSSL::randomPseudoBytes(OpenSSL::cipherIVLength(OpenSSL::CIPHER_AES_128_GCM));
|
||||
$tag = null;
|
||||
$httpPass = \json_encode([
|
||||
|
@ -843,7 +843,7 @@ App::post('/v1/projects/:projectId/tasks')
|
|||
->param('httpUser', '', function () { return new Text(256); }, 'Task HTTP user.', true)
|
||||
->param('httpPass', '', function () { return new Text(256); }, 'Task HTTP password.', true)
|
||||
->action(
|
||||
function ($projectId, $name, $status, $schedule, $security, $httpMethod, $httpUrl, $httpHeaders, $httpUser, $httpPass) use ($request, $response, $consoleDB) {
|
||||
function ($projectId, $name, $status, $schedule, $security, $httpMethod, $httpUrl, $httpHeaders, $httpUser, $httpPass) use ($response, $consoleDB) {
|
||||
$project = $consoleDB->getDocument($projectId);
|
||||
|
||||
if (empty($project->getId()) || Database::SYSTEM_COLLECTION_PROJECTS != $project->getCollection()) {
|
||||
|
@ -854,7 +854,7 @@ App::post('/v1/projects/:projectId/tasks')
|
|||
$next = ($status == 'play') ? $cron->getNextRunDate()->format('U') : null;
|
||||
|
||||
$security = ($security === '1' || $security === 'true' || $security === 1 || $security === true);
|
||||
$key = $request->getServer('_APP_OPENSSL_KEY_V1');
|
||||
$key = App::getEnv('_APP_OPENSSL_KEY_V1');
|
||||
$iv = OpenSSL::randomPseudoBytes(OpenSSL::cipherIVLength(OpenSSL::CIPHER_AES_128_GCM));
|
||||
$tag = null;
|
||||
$httpPass = \json_encode([
|
||||
|
@ -918,7 +918,7 @@ App::get('/v1/projects/:projectId/tasks')
|
|||
->label('sdk.method', 'listTasks')
|
||||
->param('projectId', '', function () { return new UID(); }, 'Project unique ID.')
|
||||
->action(
|
||||
function ($projectId) use ($request, $response, $consoleDB) {
|
||||
function ($projectId) use ($response, $consoleDB) {
|
||||
$project = $consoleDB->getDocument($projectId);
|
||||
|
||||
if (empty($project->getId()) || Database::SYSTEM_COLLECTION_PROJECTS != $project->getCollection()) {
|
||||
|
@ -934,7 +934,7 @@ App::get('/v1/projects/:projectId/tasks')
|
|||
continue;
|
||||
}
|
||||
|
||||
$key = $request->getServer('_APP_OPENSSL_KEY_V'.$httpPass['version']);
|
||||
$key = App::getEnv('_APP_OPENSSL_KEY_V'.$httpPass['version']);
|
||||
|
||||
$task->setAttribute('httpPass', OpenSSL::decrypt($httpPass['data'], $httpPass['method'], $key, 0, \hex2bin($httpPass['iv']), \hex2bin($httpPass['tag'])));
|
||||
}
|
||||
|
@ -952,7 +952,7 @@ App::get('/v1/projects/:projectId/tasks/:taskId')
|
|||
->param('projectId', null, function () { return new UID(); }, 'Project unique ID.')
|
||||
->param('taskId', null, function () { return new UID(); }, 'Task unique ID.')
|
||||
->action(
|
||||
function ($projectId, $taskId) use ($request, $response, $consoleDB) {
|
||||
function ($projectId, $taskId) use ($response, $consoleDB) {
|
||||
$project = $consoleDB->getDocument($projectId);
|
||||
|
||||
if (empty($project->getId()) || Database::SYSTEM_COLLECTION_PROJECTS != $project->getCollection()) {
|
||||
|
@ -968,7 +968,7 @@ App::get('/v1/projects/:projectId/tasks/:taskId')
|
|||
$httpPass = \json_decode($task->getAttribute('httpPass', '{}'), true);
|
||||
|
||||
if (!empty($httpPass) && isset($httpPass['version'])) {
|
||||
$key = $request->getServer('_APP_OPENSSL_KEY_V'.$httpPass['version']);
|
||||
$key = App::getEnv('_APP_OPENSSL_KEY_V'.$httpPass['version']);
|
||||
$task->setAttribute('httpPass', OpenSSL::decrypt($httpPass['data'], $httpPass['method'], $key, 0, \hex2bin($httpPass['iv']), \hex2bin($httpPass['tag'])));
|
||||
}
|
||||
|
||||
|
@ -994,7 +994,7 @@ App::put('/v1/projects/:projectId/tasks/:taskId')
|
|||
->param('httpUser', '', function () { return new Text(256); }, 'Task HTTP user.', true)
|
||||
->param('httpPass', '', function () { return new Text(256); }, 'Task HTTP password.', true)
|
||||
->action(
|
||||
function ($projectId, $taskId, $name, $status, $schedule, $security, $httpMethod, $httpUrl, $httpHeaders, $httpUser, $httpPass) use ($request, $response, $consoleDB) {
|
||||
function ($projectId, $taskId, $name, $status, $schedule, $security, $httpMethod, $httpUrl, $httpHeaders, $httpUser, $httpPass) use ($response, $consoleDB) {
|
||||
$project = $consoleDB->getDocument($projectId);
|
||||
|
||||
if (empty($project->getId()) || Database::SYSTEM_COLLECTION_PROJECTS != $project->getCollection()) {
|
||||
|
@ -1011,7 +1011,7 @@ App::put('/v1/projects/:projectId/tasks/:taskId')
|
|||
$next = ($status == 'play') ? $cron->getNextRunDate()->format('U') : null;
|
||||
|
||||
$security = ($security === '1' || $security === 'true' || $security === 1 || $security === true);
|
||||
$key = $request->getServer('_APP_OPENSSL_KEY_V1');
|
||||
$key = App::getEnv('_APP_OPENSSL_KEY_V1');
|
||||
$iv = OpenSSL::randomPseudoBytes(OpenSSL::cipherIVLength(OpenSSL::CIPHER_AES_128_GCM));
|
||||
$tag = null;
|
||||
$httpPass = \json_encode([
|
||||
|
@ -1264,7 +1264,7 @@ App::post('/v1/projects/:projectId/domains')
|
|||
->param('projectId', null, function () { return new UID(); }, 'Project unique ID.')
|
||||
->param('domain', null, function () { return new DomainValidator(); }, 'Domain name.')
|
||||
->action(
|
||||
function ($projectId, $domain) use ($request, $response, $consoleDB) {
|
||||
function ($projectId, $domain) use ($response, $consoleDB) {
|
||||
$project = $consoleDB->getDocument($projectId);
|
||||
|
||||
if (empty($project->getId()) || Database::SYSTEM_COLLECTION_PROJECTS != $project->getCollection()) {
|
||||
|
@ -1277,7 +1277,7 @@ App::post('/v1/projects/:projectId/domains')
|
|||
throw new Exception('Domain already exists', 409);
|
||||
}
|
||||
|
||||
$target = new Domain($request->getServer('_APP_DOMAIN_TARGET', ''));
|
||||
$target = new Domain(App::getEnv('_APP_DOMAIN_TARGET', ''));
|
||||
|
||||
if (!$target->isKnown() || $target->isTest()) {
|
||||
throw new Exception('Unreachable CNAME target ('.$target->get().'), plesse use a domain with a public suffix.', 500);
|
||||
|
@ -1374,7 +1374,7 @@ App::patch('/v1/projects/:projectId/domains/:domainId/verification')
|
|||
->param('projectId', null, function () { return new UID(); }, 'Project unique ID.')
|
||||
->param('domainId', null, function () { return new UID(); }, 'Domain unique ID.')
|
||||
->action(
|
||||
function ($projectId, $domainId) use ($request, $response, $consoleDB) {
|
||||
function ($projectId, $domainId) use ($response, $consoleDB) {
|
||||
$project = $consoleDB->getDocument($projectId);
|
||||
|
||||
if (empty($project->getId()) || Database::SYSTEM_COLLECTION_PROJECTS != $project->getCollection()) {
|
||||
|
@ -1387,7 +1387,7 @@ App::patch('/v1/projects/:projectId/domains/:domainId/verification')
|
|||
throw new Exception('Domain not found', 404);
|
||||
}
|
||||
|
||||
$target = new Domain($request->getServer('_APP_DOMAIN_TARGET', ''));
|
||||
$target = new Domain(App::getEnv('_APP_DOMAIN_TARGET', ''));
|
||||
|
||||
if (!$target->isKnown() || $target->isTest()) {
|
||||
throw new Exception('Unreachable CNAME target ('.$target->get().'), plesse use a domain with a public suffix.', 500);
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
global $utopia, $request, $response, $user, $audit, $usage, $project, $projectDB;
|
||||
global $request, $response, $user, $audit, $usage, $project, $projectDB;
|
||||
|
||||
use Utopia\App;
|
||||
use Utopia\Exception;
|
||||
|
@ -159,7 +159,7 @@ App::post('/v1/storage/files')
|
|||
* Validators
|
||||
*/
|
||||
//$fileType = new FileType(array(FileType::FILE_TYPE_PNG, FileType::FILE_TYPE_GIF, FileType::FILE_TYPE_JPEG));
|
||||
$fileSize = new FileSize($request->getServer('_APP_STORAGE_LIMIT', 0));
|
||||
$fileSize = new FileSize(App::getEnv('_APP_STORAGE_LIMIT', 0));
|
||||
$upload = new Upload();
|
||||
|
||||
if (empty($file)) {
|
||||
|
@ -200,7 +200,7 @@ App::post('/v1/storage/files')
|
|||
|
||||
$mimeType = $device->getFileMimeType($path); // Get mime-type before compression and encryption
|
||||
|
||||
if ($request->getServer('_APP_STORAGE_ANTIVIRUS') === 'enabled') { // Check if scans are enabled
|
||||
if (App::getEnv('_APP_STORAGE_ANTIVIRUS') === 'enabled') { // Check if scans are enabled
|
||||
$antiVirus = new Network('clamav', 3310);
|
||||
|
||||
// Check if file size is exceeding allowed limit
|
||||
|
@ -214,7 +214,7 @@ App::post('/v1/storage/files')
|
|||
$compressor = new GZIP();
|
||||
$data = $device->read($path);
|
||||
$data = $compressor->compress($data);
|
||||
$key = $request->getServer('_APP_OPENSSL_KEY_V1');
|
||||
$key = App::getEnv('_APP_OPENSSL_KEY_V1');
|
||||
$iv = OpenSSL::randomPseudoBytes(OpenSSL::cipherIVLength(OpenSSL::CIPHER_AES_128_GCM));
|
||||
$data = OpenSSL::encrypt($data, OpenSSL::CIPHER_AES_128_GCM, $key, 0, $iv, $tag);
|
||||
|
||||
|
@ -411,7 +411,7 @@ App::get('/v1/storage/files/:fileId/preview')
|
|||
$source = OpenSSL::decrypt(
|
||||
$source,
|
||||
$file->getAttribute('fileOpenSSLCipher'),
|
||||
$request->getServer('_APP_OPENSSL_KEY_V'.$file->getAttribute('fileOpenSSLVersion')),
|
||||
App::getEnv('_APP_OPENSSL_KEY_V'.$file->getAttribute('fileOpenSSLVersion')),
|
||||
0,
|
||||
\hex2bin($file->getAttribute('fileOpenSSLIV')),
|
||||
\hex2bin($file->getAttribute('fileOpenSSLTag'))
|
||||
|
@ -461,7 +461,7 @@ App::get('/v1/storage/files/:fileId/download')
|
|||
->label('sdk.methodType', 'location')
|
||||
->param('fileId', '', function () { return new UID(); }, 'File unique ID.')
|
||||
->action(
|
||||
function ($fileId) use ($response, $request, $projectDB) {
|
||||
function ($fileId) use ($response, $projectDB) {
|
||||
$file = $projectDB->getDocument($fileId);
|
||||
|
||||
if (empty($file->getId()) || Database::SYSTEM_COLLECTION_FILES != $file->getCollection()) {
|
||||
|
@ -483,7 +483,7 @@ App::get('/v1/storage/files/:fileId/download')
|
|||
$source = OpenSSL::decrypt(
|
||||
$source,
|
||||
$file->getAttribute('fileOpenSSLCipher'),
|
||||
$request->getServer('_APP_OPENSSL_KEY_V'.$file->getAttribute('fileOpenSSLVersion')),
|
||||
App::getEnv('_APP_OPENSSL_KEY_V'.$file->getAttribute('fileOpenSSLVersion')),
|
||||
0,
|
||||
\hex2bin($file->getAttribute('fileOpenSSLIV')),
|
||||
\hex2bin($file->getAttribute('fileOpenSSLTag'))
|
||||
|
@ -516,7 +516,7 @@ App::get('/v1/storage/files/:fileId/view')
|
|||
->param('fileId', '', function () { return new UID(); }, 'File unique ID.')
|
||||
->param('as', '', function () { return new WhiteList(['pdf', /*'html',*/ 'text']); }, 'Choose a file format to convert your file to. Currently you can only convert word and pdf files to pdf or txt. This option is currently experimental only, use at your own risk.', true)
|
||||
->action(
|
||||
function ($fileId, $as) use ($response, $request, $projectDB, $mimes) {
|
||||
function ($fileId, $as) use ($response, $projectDB, $mimes) {
|
||||
$file = $projectDB->getDocument($fileId);
|
||||
|
||||
if (empty($file->getId()) || Database::SYSTEM_COLLECTION_FILES != $file->getCollection()) {
|
||||
|
@ -544,7 +544,7 @@ App::get('/v1/storage/files/:fileId/view')
|
|||
$source = OpenSSL::decrypt(
|
||||
$source,
|
||||
$file->getAttribute('fileOpenSSLCipher'),
|
||||
$request->getServer('_APP_OPENSSL_KEY_V'.$file->getAttribute('fileOpenSSLVersion')),
|
||||
App::getEnv('_APP_OPENSSL_KEY_V'.$file->getAttribute('fileOpenSSLVersion')),
|
||||
0,
|
||||
\hex2bin($file->getAttribute('fileOpenSSLIV')),
|
||||
\hex2bin($file->getAttribute('fileOpenSSLTag'))
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
global $utopia, $request, $response, $projectDB, $project, $user, $audit, $mail, $mode, $clients;
|
||||
global $request, $response, $projectDB, $project, $user, $audit, $mail, $mode, $clients;
|
||||
|
||||
use Utopia\App;
|
||||
use Utopia\Exception;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
global $utopia, $response, $projectDB;
|
||||
global $response, $projectDB;
|
||||
|
||||
use Utopia\App;
|
||||
use Utopia\Exception;
|
||||
|
|
|
@ -44,7 +44,7 @@ App::init(function () use ($utopia, $request, $response, $register, $user, $proj
|
|||
;
|
||||
}
|
||||
|
||||
if ($abuse->check() && $request->getServer('_APP_OPTIONS_ABUSE', 'enabled') !== 'disabled') {
|
||||
if ($abuse->check() && App::getEnv('_APP_OPTIONS_ABUSE', 'enabled') !== 'disabled') {
|
||||
throw new Exception('Too many requests', 429);
|
||||
}
|
||||
}, 'api');
|
|
@ -118,7 +118,7 @@ class Database
|
|||
/**
|
||||
* @param array $options
|
||||
*
|
||||
* @return Document[]|Document
|
||||
* @return Document[]
|
||||
*/
|
||||
public function getCollection(array $options)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue