Merge branch 'remove-globals' of github.com:appwrite/appwrite into swoole
This commit is contained in:
commit
b2c5cdf054
179
app/app.php
179
app/app.php
|
@ -2,25 +2,132 @@
|
|||
|
||||
require_once __DIR__.'/init.php';
|
||||
|
||||
global $utopia, $request, $response, $register, $consoleDB, $project;
|
||||
global $request, $response, $register, $project;
|
||||
|
||||
use Utopia\App;
|
||||
use Utopia\Request;
|
||||
use Utopia\Response;
|
||||
use Utopia\View;
|
||||
use Utopia\Exception;
|
||||
use Utopia\Config\Config;
|
||||
use Utopia\Domains\Domain;
|
||||
use Utopia\Locale\Locale;
|
||||
use Appwrite\Auth\Auth;
|
||||
use Appwrite\Database\Database;
|
||||
use Appwrite\Database\Document;
|
||||
use Appwrite\Database\Validator\Authorization;
|
||||
use Appwrite\Database\Adapter\MySQL as MySQLAdapter;
|
||||
use Appwrite\Database\Adapter\Redis as RedisAdapter;
|
||||
use Appwrite\Event\Event;
|
||||
use Appwrite\Network\Validator\Origin;
|
||||
use Appwrite\Utopia\Response;
|
||||
|
||||
$request = new Request();
|
||||
$response = new Response();
|
||||
|
||||
$locale = $request->getParam('locale', $request->getHeader('X-Appwrite-Locale', ''));
|
||||
|
||||
if (\in_array($locale, Config::getParam('locales'))) {
|
||||
Locale::setDefault($locale);
|
||||
}
|
||||
|
||||
Config::setParam('env', App::getMode());
|
||||
Config::setParam('domain', $request->getServer('HTTP_HOST', ''));
|
||||
Config::setParam('domainVerification', false);
|
||||
Config::setParam('version', App::getEnv('_APP_VERSION', 'UNKNOWN'));
|
||||
Config::setParam('protocol', $request->getServer('HTTP_X_FORWARDED_PROTO', $request->getServer('REQUEST_SCHEME', 'https')));
|
||||
Config::setParam('port', (string) \parse_url(Config::getParam('protocol').'://'.$request->getServer('HTTP_HOST', ''), PHP_URL_PORT));
|
||||
Config::setParam('hostname', \parse_url(Config::getParam('protocol').'://'.$request->getServer('HTTP_HOST', null), PHP_URL_HOST));
|
||||
|
||||
\define('COOKIE_DOMAIN',
|
||||
(
|
||||
$request->getServer('HTTP_HOST', null) === 'localhost' ||
|
||||
$request->getServer('HTTP_HOST', null) === 'localhost:'.Config::getParam('port') ||
|
||||
(\filter_var(Config::getParam('hostname'), FILTER_VALIDATE_IP) !== false)
|
||||
)
|
||||
? null
|
||||
: '.'.Config::getParam('hostname')
|
||||
);
|
||||
\define('COOKIE_SAMESITE', Response::COOKIE_SAMESITE_NONE);
|
||||
|
||||
Authorization::disable();
|
||||
|
||||
$project = $consoleDB->getDocument($request->getParam('project', $request->getHeader('X-Appwrite-Project', '')));
|
||||
|
||||
Authorization::enable();
|
||||
|
||||
$console = $consoleDB->getDocument('console');
|
||||
|
||||
$mode = $request->getParam('mode', $request->getHeader('X-Appwrite-Mode', 'default'));
|
||||
|
||||
Auth::setCookieName('a_session_'.$project->getId());
|
||||
|
||||
if (APP_MODE_ADMIN === $mode) {
|
||||
Auth::setCookieName('a_session_'.$console->getId());
|
||||
}
|
||||
|
||||
$session = Auth::decodeSession(
|
||||
$request->getCookie(Auth::$cookieName, // Get sessions
|
||||
$request->getCookie(Auth::$cookieName.'_legacy', // Get fallback session from old clients (no SameSite support)
|
||||
$request->getHeader('X-Appwrite-Key', '')))); // Get API Key
|
||||
|
||||
// Get fallback session from clients who block 3rd-party cookies
|
||||
$response->addHeader('X-Debug-Fallback', 'false');
|
||||
|
||||
if(empty($session['id']) && empty($session['secret'])) {
|
||||
$response->addHeader('X-Debug-Fallback', 'true');
|
||||
$fallback = $request->getHeader('X-Fallback-Cookies', '');
|
||||
$fallback = \json_decode($fallback, true);
|
||||
$session = Auth::decodeSession(((isset($fallback[Auth::$cookieName])) ? $fallback[Auth::$cookieName] : ''));
|
||||
}
|
||||
|
||||
Auth::$unique = $session['id'];
|
||||
Auth::$secret = $session['secret'];
|
||||
|
||||
$projectDB = new Database();
|
||||
$projectDB->setAdapter(new RedisAdapter(new MySQLAdapter($register), $register));
|
||||
$projectDB->setNamespace('app_'.$project->getId());
|
||||
$projectDB->setMocks(Config::getParam('collections', []));
|
||||
|
||||
if (APP_MODE_ADMIN !== $mode) {
|
||||
$user = $projectDB->getDocument(Auth::$unique);
|
||||
}
|
||||
else {
|
||||
$user = $consoleDB->getDocument(Auth::$unique);
|
||||
|
||||
$user
|
||||
->setAttribute('$id', 'admin-'.$user->getAttribute('$id'))
|
||||
;
|
||||
}
|
||||
|
||||
if (empty($user->getId()) // Check a document has been found in the DB
|
||||
|| Database::SYSTEM_COLLECTION_USERS !== $user->getCollection() // Validate returned document is really a user document
|
||||
|| !Auth::tokenVerify($user->getAttribute('tokens', []), Auth::TOKEN_TYPE_LOGIN, Auth::$secret)) { // Validate user has valid login token
|
||||
$user = new Document(['$id' => '', '$collection' => Database::SYSTEM_COLLECTION_USERS]);
|
||||
}
|
||||
|
||||
if (APP_MODE_ADMIN === $mode) {
|
||||
if (!empty($user->search('teamId', $project->getAttribute('teamId'), $user->getAttribute('memberships')))) {
|
||||
Authorization::disable();
|
||||
} else {
|
||||
$user = new Document(['$id' => '', '$collection' => Database::SYSTEM_COLLECTION_USERS]);
|
||||
}
|
||||
}
|
||||
|
||||
// Set project mail
|
||||
$register->get('smtp')
|
||||
->setFrom(
|
||||
App::getEnv('_APP_SYSTEM_EMAIL_ADDRESS', APP_EMAIL_TEAM),
|
||||
($project->getId() === 'console')
|
||||
? \urldecode(App::getEnv('_APP_SYSTEM_EMAIL_NAME', APP_NAME.' Server'))
|
||||
: \sprintf(Locale::getText('account.emails.team'), $project->getAttribute('name')
|
||||
)
|
||||
);
|
||||
|
||||
/*
|
||||
* Configuration files
|
||||
*/
|
||||
$utopia = new App('Asia/Tel_Aviv');
|
||||
$webhook = new Event('v1-webhooks', 'WebhooksV1');
|
||||
$audit = new Event('v1-audits', 'AuditsV1');
|
||||
$usage = new Event('v1-usage', 'UsageV1');
|
||||
|
@ -31,35 +138,41 @@ $deletes = new Event('v1-deletes', 'DeletesV1');
|
|||
* Get All verified client URLs for both console and current projects
|
||||
* + Filter for duplicated entries
|
||||
*/
|
||||
// $clientsConsole = \array_map(function ($node) {
|
||||
// return $node['hostname'];
|
||||
// }, \array_filter($console->getAttribute('platforms', []), function ($node) {
|
||||
// if (isset($node['type']) && $node['type'] === 'web' && isset($node['hostname']) && !empty($node['hostname'])) {
|
||||
// return true;
|
||||
// }
|
||||
$clientsConsole = \array_map(function ($node) {
|
||||
return $node['hostname'];
|
||||
}, \array_filter($console->getAttribute('platforms', []), function ($node) {
|
||||
if (isset($node['type']) && $node['type'] === 'web' && isset($node['hostname']) && !empty($node['hostname'])) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// return false;
|
||||
// }));
|
||||
return false;
|
||||
}));
|
||||
|
||||
// $clients = \array_unique(\array_merge($clientsConsole, \array_map(function ($node) {
|
||||
// return $node['hostname'];
|
||||
// }, \array_filter($project->getAttribute('platforms', []), function ($node) {
|
||||
// if (isset($node['type']) && $node['type'] === 'web' && isset($node['hostname']) && !empty($node['hostname'])) {
|
||||
// return true;
|
||||
// }
|
||||
$clients = \array_unique(\array_merge($clientsConsole, \array_map(function ($node) {
|
||||
return $node['hostname'];
|
||||
}, \array_filter($project->getAttribute('platforms', []), function ($node) {
|
||||
if (isset($node['type']) && $node['type'] === 'web' && isset($node['hostname']) && !empty($node['hostname'])) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// return false;
|
||||
// }))));
|
||||
return false;
|
||||
}))));
|
||||
|
||||
$utopia->init(function () {
|
||||
global $utopia, $request, $response, $user, $project, $console, $webhook, $audit, $usage, $clients;
|
||||
var_dump(1);
|
||||
App::init(function () use ($utopia, $request, $response, &$user, $project, $console, $webhook, $audit, $usage, $clients) {
|
||||
|
||||
$route = $utopia->match($request);
|
||||
|
||||
if(!empty($route->getLabel('sdk.platform', [])) && empty($project->getId()) && ($route->getLabel('scope', '') !== 'public')) {
|
||||
throw new Exception('Missing or unknown project ID', 400);
|
||||
}
|
||||
|
||||
$console->setAttribute('platforms', [ // Allways allow current host
|
||||
'$collection' => Database::SYSTEM_COLLECTION_PLATFORMS,
|
||||
'name' => 'Current Host',
|
||||
'type' => 'web',
|
||||
'hostname' => \parse_url('https://'.$request->getServer('HTTP_HOST'), PHP_URL_HOST),
|
||||
], Document::SET_TYPE_APPEND);
|
||||
|
||||
$referrer = $request->getServer('HTTP_REFERER', '');
|
||||
$origin = \parse_url($request->getServer('HTTP_ORIGIN', $referrer), PHP_URL_HOST);
|
||||
$protocol = \parse_url($request->getServer('HTTP_ORIGIN', $referrer), PHP_URL_SCHEME);
|
||||
|
@ -81,7 +194,7 @@ $utopia->init(function () {
|
|||
* As recommended at:
|
||||
* @see https://www.owasp.org/index.php/List_of_useful_HTTP_headers
|
||||
*/
|
||||
if ($utopia->getEnv('_APP_OPTIONS_FORCE_HTTPS', 'disabled') === 'enabled') { // Force HTTPS
|
||||
if (App::getEnv('_APP_OPTIONS_FORCE_HTTPS', 'disabled') === 'enabled') { // Force HTTPS
|
||||
if(Config::getParam('protocol') !== 'https') {
|
||||
return $response->redirect('https://' . Config::getParam('domain').$request->getServer('REQUEST_URI'));
|
||||
}
|
||||
|
@ -226,7 +339,7 @@ $utopia->init(function () {
|
|||
;
|
||||
});
|
||||
|
||||
$utopia->shutdown(function () use ($response, $request, $webhook, $audit, $usage, $deletes, $mode, $project, $utopia) {
|
||||
App::shutdown(function () use ($response, $request, $webhook, $audit, $usage, $deletes, $mode, $project, $utopia) {
|
||||
|
||||
/*
|
||||
* Trigger events for background workers
|
||||
|
@ -256,7 +369,7 @@ $utopia->shutdown(function () use ($response, $request, $webhook, $audit, $usage
|
|||
}
|
||||
});
|
||||
|
||||
$utopia->options(function () use ($request, $response) {
|
||||
App::options(function () use ($request, $response) {
|
||||
$origin = $request->getServer('HTTP_ORIGIN');
|
||||
|
||||
$response
|
||||
|
@ -268,7 +381,8 @@ $utopia->options(function () use ($request, $response) {
|
|||
->send();
|
||||
});
|
||||
|
||||
$utopia->error(function ($error /* @var $error Exception */) use ($request, $response, $utopia, $project) {
|
||||
App::error(function ($error /* @var $error Exception */) use ($request, $response, $utopia, $project) {
|
||||
$env = Config::getParam('env');
|
||||
$version = Config::getParam('version');
|
||||
|
||||
switch ($error->getCode()) {
|
||||
|
@ -339,7 +453,7 @@ $utopia->error(function ($error /* @var $error Exception */) use ($request, $res
|
|||
$utopia->isDevelopment() ? Response::MODEL_ERROR_DEV : Response::MODEL_LOCALE);
|
||||
});
|
||||
|
||||
$utopia->get('/manifest.json')
|
||||
App::get('/manifest.json')
|
||||
->desc('Progressive app manifest file')
|
||||
->label('scope', 'public')
|
||||
->label('docs', false)
|
||||
|
@ -365,7 +479,7 @@ $utopia->get('/manifest.json')
|
|||
}
|
||||
);
|
||||
|
||||
$utopia->get('/robots.txt')
|
||||
App::get('/robots.txt')
|
||||
->desc('Robots.txt File')
|
||||
->label('scope', 'public')
|
||||
->label('docs', false)
|
||||
|
@ -376,7 +490,7 @@ $utopia->get('/robots.txt')
|
|||
}
|
||||
);
|
||||
|
||||
$utopia->get('/humans.txt')
|
||||
App::get('/humans.txt')
|
||||
->desc('Humans.txt File')
|
||||
->label('scope', 'public')
|
||||
->label('docs', false)
|
||||
|
@ -387,7 +501,7 @@ $utopia->get('/humans.txt')
|
|||
}
|
||||
);
|
||||
|
||||
$utopia->get('/.well-known/acme-challenge')
|
||||
App::get('/.well-known/acme-challenge')
|
||||
->desc('SSL Verification')
|
||||
->label('scope', 'public')
|
||||
->label('docs', false)
|
||||
|
@ -428,4 +542,11 @@ include_once __DIR__ . '/controllers/shared/web.php';
|
|||
|
||||
foreach(Config::getParam('services', []) as $service) {
|
||||
include_once $service['controller'];
|
||||
}
|
||||
}
|
||||
|
||||
App::setResource('utopia', function() use ($utopia) {return $utopia;});
|
||||
App::setResource('request', function() use ($request) {return $request;});
|
||||
App::setResource('response', function() use ($response) {return $response;});
|
||||
App::setResource('register', function() use ($register) {return $register;});
|
||||
|
||||
$utopia->run($request, $response);
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
<?php
|
||||
|
||||
global $utopia;
|
||||
|
||||
use Utopia\App;
|
||||
use Utopia\Config\Config;
|
||||
use Appwrite\Database\Database;
|
||||
|
||||
|
@ -36,13 +35,7 @@ $collections = [
|
|||
'name' => 'Localhost',
|
||||
'type' => 'web',
|
||||
'hostname' => 'localhost',
|
||||
],
|
||||
[
|
||||
'$collection' => Database::SYSTEM_COLLECTION_PLATFORMS,
|
||||
'name' => 'Current Host',
|
||||
'type' => 'web',
|
||||
'hostname' => \parse_url('https://'.$utopia->getEnv('HTTP_HOST'), PHP_URL_HOST),
|
||||
],
|
||||
], // Current host is added on app init
|
||||
],
|
||||
'legalName' => '',
|
||||
'legalCountry' => '',
|
||||
|
@ -50,9 +43,9 @@ $collections = [
|
|||
'legalCity' => '',
|
||||
'legalAddress' => '',
|
||||
'legalTaxId' => '',
|
||||
'authWhitelistEmails' => (!empty($utopia->getEnv('_APP_CONSOLE_WHITELIST_EMAILS', null))) ? \explode(',', $utopia->getEnv('_APP_CONSOLE_WHITELIST_EMAILS', null)) : [],
|
||||
'authWhitelistIPs' => (!empty($utopia->getEnv('_APP_CONSOLE_WHITELIST_IPS', null))) ? \explode(',', $utopia->getEnv('_APP_CONSOLE_WHITELIST_IPS', null)) : [],
|
||||
'authWhitelistDomains' => (!empty($utopia->getEnv('_APP_CONSOLE_WHITELIST_DOMAINS', null))) ? \explode(',', $utopia->getEnv('_APP_CONSOLE_WHITELIST_DOMAINS', null)) : [],
|
||||
'authWhitelistEmails' => (!empty(App::getEnv('_APP_CONSOLE_WHITELIST_EMAILS', null))) ? \explode(',', App::getEnv('_APP_CONSOLE_WHITELIST_EMAILS', null)) : [],
|
||||
'authWhitelistIPs' => (!empty(App::getEnv('_APP_CONSOLE_WHITELIST_IPS', null))) ? \explode(',', App::getEnv('_APP_CONSOLE_WHITELIST_IPS', null)) : [],
|
||||
'authWhitelistDomains' => (!empty(App::getEnv('_APP_CONSOLE_WHITELIST_DOMAINS', null))) ? \explode(',', App::getEnv('_APP_CONSOLE_WHITELIST_DOMAINS', null)) : [],
|
||||
],
|
||||
Database::SYSTEM_COLLECTION_COLLECTIONS => [
|
||||
'$collection' => Database::SYSTEM_COLLECTION_COLLECTIONS,
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
<?php
|
||||
|
||||
global $utopia, $register, $request, $response, $user, $audit,
|
||||
global $register, $request, $response, $user, $audit,
|
||||
$webhook, $mail, $project, $projectDB, $clients;
|
||||
|
||||
use Utopia\App;
|
||||
use Utopia\Exception;
|
||||
use Utopia\Config\Config;
|
||||
use Utopia\Validator\Assoc;
|
||||
|
@ -34,7 +35,7 @@ $oauthDefaultFailure = '/auth/oauth2/failure';
|
|||
|
||||
$oauth2Keys = [];
|
||||
|
||||
$utopia->init(function() use (&$oauth2Keys) {
|
||||
App::init(function() use (&$oauth2Keys) {
|
||||
foreach (Config::getParam('providers') as $key => $provider) {
|
||||
if (!$provider['enabled']) {
|
||||
continue;
|
||||
|
@ -45,7 +46,7 @@ $utopia->init(function() use (&$oauth2Keys) {
|
|||
}
|
||||
}, 'account');
|
||||
|
||||
$utopia->post('/v1/account')
|
||||
App::post('/v1/account')
|
||||
->desc('Create Account')
|
||||
->groups(['api', 'account'])
|
||||
->label('webhook', 'account.create')
|
||||
|
@ -136,7 +137,7 @@ $utopia->post('/v1/account')
|
|||
}
|
||||
);
|
||||
|
||||
$utopia->post('/v1/account/sessions')
|
||||
App::post('/v1/account/sessions')
|
||||
->desc('Create Account Session')
|
||||
->groups(['api', 'account'])
|
||||
->label('webhook', 'account.sessions.create')
|
||||
|
@ -227,7 +228,7 @@ $utopia->post('/v1/account/sessions')
|
|||
}
|
||||
);
|
||||
|
||||
$utopia->get('/v1/account/sessions/oauth2/:provider')
|
||||
App::get('/v1/account/sessions/oauth2/:provider')
|
||||
->desc('Create Account Session with OAuth2')
|
||||
->groups(['api', 'account'])
|
||||
->label('error', __DIR__.'/../../views/general/error.phtml')
|
||||
|
@ -255,7 +256,7 @@ $utopia->get('/v1/account/sessions/oauth2/:provider')
|
|||
$appSecret = \json_decode($appSecret, true);
|
||||
|
||||
if (!empty($appSecret) && isset($appSecret['version'])) {
|
||||
$key = $request->getServer('_APP_OPENSSL_KEY_V'.$appSecret['version']);
|
||||
$key = App::getEnv('_APP_OPENSSL_KEY_V'.$appSecret['version']);
|
||||
$appSecret = OpenSSL::decrypt($appSecret['data'], $appSecret['method'], $key, 0, \hex2bin($appSecret['iv']), \hex2bin($appSecret['tag']));
|
||||
}
|
||||
|
||||
|
@ -278,7 +279,7 @@ $utopia->get('/v1/account/sessions/oauth2/:provider')
|
|||
}
|
||||
);
|
||||
|
||||
$utopia->get('/v1/account/sessions/oauth2/callback/:provider/:projectId')
|
||||
App::get('/v1/account/sessions/oauth2/callback/:provider/:projectId')
|
||||
->desc('OAuth2 Callback')
|
||||
->groups(['api', 'account'])
|
||||
->label('error', __DIR__.'/../../views/general/error.phtml')
|
||||
|
@ -301,7 +302,7 @@ $utopia->get('/v1/account/sessions/oauth2/callback/:provider/:projectId')
|
|||
}
|
||||
);
|
||||
|
||||
$utopia->post('/v1/account/sessions/oauth2/callback/:provider/:projectId')
|
||||
App::post('/v1/account/sessions/oauth2/callback/:provider/:projectId')
|
||||
->desc('OAuth2 Callback')
|
||||
->groups(['api', 'account'])
|
||||
->label('error', __DIR__.'/../../views/general/error.phtml')
|
||||
|
@ -325,7 +326,7 @@ $utopia->post('/v1/account/sessions/oauth2/callback/:provider/:projectId')
|
|||
}
|
||||
);
|
||||
|
||||
$utopia->get('/v1/account/sessions/oauth2/:provider/redirect')
|
||||
App::get('/v1/account/sessions/oauth2/:provider/redirect')
|
||||
->desc('OAuth2 Redirect')
|
||||
->groups(['api', 'account'])
|
||||
->label('error', __DIR__.'/../../views/general/error.phtml')
|
||||
|
@ -350,7 +351,7 @@ $utopia->get('/v1/account/sessions/oauth2/:provider/redirect')
|
|||
$appSecret = \json_decode($appSecret, true);
|
||||
|
||||
if (!empty($appSecret) && isset($appSecret['version'])) {
|
||||
$key = $request->getServer('_APP_OPENSSL_KEY_V'.$appSecret['version']);
|
||||
$key = App::getEnv('_APP_OPENSSL_KEY_V'.$appSecret['version']);
|
||||
$appSecret = OpenSSL::decrypt($appSecret['data'], $appSecret['method'], $key, 0, \hex2bin($appSecret['iv']), \hex2bin($appSecret['tag']));
|
||||
}
|
||||
|
||||
|
@ -519,7 +520,7 @@ $utopia->get('/v1/account/sessions/oauth2/:provider/redirect')
|
|||
}
|
||||
);
|
||||
|
||||
$utopia->get('/v1/account')
|
||||
App::get('/v1/account')
|
||||
->desc('Get Account')
|
||||
->groups(['api', 'account'])
|
||||
->label('scope', 'account')
|
||||
|
@ -528,13 +529,14 @@ $utopia->get('/v1/account')
|
|||
->label('sdk.method', 'get')
|
||||
->label('sdk.description', '/docs/references/account/get.md')
|
||||
->label('sdk.response', ['200' => 'user'])
|
||||
->inject('response')
|
||||
->action(
|
||||
function () use ($response, &$user, $oauth2Keys) {
|
||||
$response->dynamic($user->setAttribute('roles', Authorization::getRoles()), Response::MODEL_USER);
|
||||
}
|
||||
);
|
||||
|
||||
$utopia->get('/v1/account/prefs')
|
||||
App::get('/v1/account/prefs')
|
||||
->desc('Get Account Preferences')
|
||||
->groups(['api', 'account'])
|
||||
->label('scope', 'account')
|
||||
|
@ -557,7 +559,7 @@ $utopia->get('/v1/account/prefs')
|
|||
}
|
||||
);
|
||||
|
||||
$utopia->get('/v1/account/sessions')
|
||||
App::get('/v1/account/sessions')
|
||||
->desc('Get Account Sessions')
|
||||
->groups(['api', 'account'])
|
||||
->label('scope', 'account')
|
||||
|
@ -616,7 +618,7 @@ $utopia->get('/v1/account/sessions')
|
|||
}
|
||||
);
|
||||
|
||||
$utopia->get('/v1/account/logs')
|
||||
App::get('/v1/account/logs')
|
||||
->desc('Get Account Logs')
|
||||
->groups(['api', 'account'])
|
||||
->label('scope', 'account')
|
||||
|
@ -689,7 +691,7 @@ $utopia->get('/v1/account/logs')
|
|||
}
|
||||
);
|
||||
|
||||
$utopia->patch('/v1/account/name')
|
||||
App::patch('/v1/account/name')
|
||||
->desc('Update Account Name')
|
||||
->groups(['api', 'account'])
|
||||
->label('webhook', 'account.update.name')
|
||||
|
@ -719,7 +721,7 @@ $utopia->patch('/v1/account/name')
|
|||
}
|
||||
);
|
||||
|
||||
$utopia->patch('/v1/account/password')
|
||||
App::patch('/v1/account/password')
|
||||
->desc('Update Account Password')
|
||||
->groups(['api', 'account'])
|
||||
->label('webhook', 'account.update.password')
|
||||
|
@ -754,7 +756,7 @@ $utopia->patch('/v1/account/password')
|
|||
}
|
||||
);
|
||||
|
||||
$utopia->patch('/v1/account/email')
|
||||
App::patch('/v1/account/email')
|
||||
->desc('Update Account Email')
|
||||
->groups(['api', 'account'])
|
||||
->label('webhook', 'account.update.email')
|
||||
|
@ -804,7 +806,7 @@ $utopia->patch('/v1/account/email')
|
|||
}
|
||||
);
|
||||
|
||||
$utopia->patch('/v1/account/prefs')
|
||||
App::patch('/v1/account/prefs')
|
||||
->desc('Update Account Preferences')
|
||||
->groups(['api', 'account'])
|
||||
->label('webhook', 'account.update.prefs')
|
||||
|
@ -845,7 +847,7 @@ $utopia->patch('/v1/account/prefs')
|
|||
}
|
||||
);
|
||||
|
||||
$utopia->delete('/v1/account')
|
||||
App::delete('/v1/account')
|
||||
->desc('Delete Account')
|
||||
->groups(['api', 'account'])
|
||||
->label('webhook', 'account.delete')
|
||||
|
@ -901,7 +903,7 @@ $utopia->delete('/v1/account')
|
|||
}
|
||||
);
|
||||
|
||||
$utopia->delete('/v1/account/sessions/:sessionId')
|
||||
App::delete('/v1/account/sessions/:sessionId')
|
||||
->desc('Delete Account Session')
|
||||
->groups(['api', 'account'])
|
||||
->label('scope', 'account')
|
||||
|
@ -961,7 +963,7 @@ $utopia->delete('/v1/account/sessions/:sessionId')
|
|||
}
|
||||
);
|
||||
|
||||
$utopia->delete('/v1/account/sessions')
|
||||
App::delete('/v1/account/sessions')
|
||||
->desc('Delete All Account Sessions')
|
||||
->groups(['api', 'account'])
|
||||
->label('scope', 'account')
|
||||
|
@ -1012,7 +1014,7 @@ $utopia->delete('/v1/account/sessions')
|
|||
}
|
||||
);
|
||||
|
||||
$utopia->post('/v1/account/recovery')
|
||||
App::post('/v1/account/recovery')
|
||||
->desc('Create Password Recovery')
|
||||
->groups(['api', 'account'])
|
||||
->label('scope', 'public')
|
||||
|
@ -1111,7 +1113,7 @@ $utopia->post('/v1/account/recovery')
|
|||
}
|
||||
);
|
||||
|
||||
$utopia->put('/v1/account/recovery')
|
||||
App::put('/v1/account/recovery')
|
||||
->desc('Complete Password Recovery')
|
||||
->groups(['api', 'account'])
|
||||
->label('scope', 'public')
|
||||
|
@ -1181,7 +1183,7 @@ $utopia->put('/v1/account/recovery')
|
|||
}
|
||||
);
|
||||
|
||||
$utopia->post('/v1/account/verification')
|
||||
App::post('/v1/account/verification')
|
||||
->desc('Create Email Verification')
|
||||
->groups(['api', 'account'])
|
||||
->label('scope', 'account')
|
||||
|
@ -1268,7 +1270,7 @@ $utopia->post('/v1/account/verification')
|
|||
}
|
||||
);
|
||||
|
||||
$utopia->put('/v1/account/verification')
|
||||
App::put('/v1/account/verification')
|
||||
->desc('Complete Email Verification')
|
||||
->groups(['api', 'account'])
|
||||
->label('scope', 'public')
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
<?php
|
||||
|
||||
global $utopia, $request, $response;
|
||||
global $response;
|
||||
|
||||
use Utopia\App;
|
||||
use Utopia\Exception;
|
||||
use Utopia\Validator\Boolean;
|
||||
use Utopia\Validator\Text;
|
||||
|
@ -19,21 +20,16 @@ use BaconQrCode\Writer;
|
|||
use Utopia\Config\Config;
|
||||
use Utopia\Validator\HexColor;
|
||||
|
||||
$types = [
|
||||
'browsers' => include __DIR__.'/../../config/avatars/browsers.php',
|
||||
'credit-cards' => include __DIR__.'/../../config/avatars/credit-cards.php',
|
||||
'flags' => include __DIR__.'/../../config/avatars/flags.php',
|
||||
];
|
||||
|
||||
$avatarCallback = function ($type, $code, $width, $height, $quality) use ($types, $response) {
|
||||
$avatarCallback = function ($type, $code, $width, $height, $quality) use ($response) {
|
||||
$code = \strtolower($code);
|
||||
$type = \strtolower($type);
|
||||
$set = Config::getParam('avatar-'.$type, []);
|
||||
|
||||
if (!\array_key_exists($type, $types)) {
|
||||
if (empty($set)) {
|
||||
throw new Exception('Avatar set not found', 404);
|
||||
}
|
||||
|
||||
if (!\array_key_exists($code, $types[$type])) {
|
||||
if (!\array_key_exists($code, $set)) {
|
||||
throw new Exception('Avatar not found', 404);
|
||||
}
|
||||
|
||||
|
@ -44,7 +40,7 @@ $avatarCallback = function ($type, $code, $width, $height, $quality) use ($types
|
|||
$output = 'png';
|
||||
$date = \date('D, d M Y H:i:s', \time() + (60 * 60 * 24 * 45)).' GMT'; // 45 days cache
|
||||
$key = \md5('/v1/avatars/:type/:code-'.$code.$width.$height.$quality.$output);
|
||||
$path = $types[$type][$code];
|
||||
$path = $set[$code];
|
||||
$type = 'png';
|
||||
|
||||
if (!\is_readable($path)) {
|
||||
|
@ -87,10 +83,10 @@ $avatarCallback = function ($type, $code, $width, $height, $quality) use ($types
|
|||
unset($resize);
|
||||
};
|
||||
|
||||
$utopia->get('/v1/avatars/credit-cards/:code')
|
||||
App::get('/v1/avatars/credit-cards/:code')
|
||||
->desc('Get Credit Card Icon')
|
||||
->groups(['api', 'avatars'])
|
||||
->param('code', '', function () use ($types) { return new WhiteList(\array_keys($types['credit-cards'])); }, 'Credit Card Code. Possible values: '.\implode(', ', \array_keys($types['credit-cards'])).'.')
|
||||
->param('code', '', function () { return new WhiteList(\array_keys(Config::getParam('avatar-credit-cards'))); }, 'Credit Card Code. Possible values: '.\implode(', ', \array_keys(Config::getParam('avatar-credit-cards'))).'.')
|
||||
->param('width', 100, function () { return new Range(0, 2000); }, 'Image width. Pass an integer between 0 to 2000. Defaults to 100.', true)
|
||||
->param('height', 100, function () { return new Range(0, 2000); }, 'Image height. Pass an integer between 0 to 2000. Defaults to 100.', true)
|
||||
->param('quality', 100, function () { return new Range(0, 100); }, 'Image quality. Pass an integer between 0 to 100. Defaults to 100.', true)
|
||||
|
@ -104,10 +100,10 @@ $utopia->get('/v1/avatars/credit-cards/:code')
|
|||
return $avatarCallback('credit-cards', $code, $width, $height, $quality);
|
||||
});
|
||||
|
||||
$utopia->get('/v1/avatars/browsers/:code')
|
||||
App::get('/v1/avatars/browsers/:code')
|
||||
->desc('Get Browser Icon')
|
||||
->groups(['api', 'avatars'])
|
||||
->param('code', '', function () use ($types) { return new WhiteList(\array_keys($types['browsers'])); }, 'Browser Code.')
|
||||
->param('code', '', function () { return new WhiteList(\array_keys(Config::getParam('avatar-browsers'))); }, 'Browser Code.')
|
||||
->param('width', 100, function () { return new Range(0, 2000); }, 'Image width. Pass an integer between 0 to 2000. Defaults to 100.', true)
|
||||
->param('height', 100, function () { return new Range(0, 2000); }, 'Image height. Pass an integer between 0 to 2000. Defaults to 100.', true)
|
||||
->param('quality', 100, function () { return new Range(0, 100); }, 'Image quality. Pass an integer between 0 to 100. Defaults to 100.', true)
|
||||
|
@ -121,10 +117,10 @@ $utopia->get('/v1/avatars/browsers/:code')
|
|||
return $avatarCallback('browsers', $code, $width, $height, $quality);
|
||||
});
|
||||
|
||||
$utopia->get('/v1/avatars/flags/:code')
|
||||
App::get('/v1/avatars/flags/:code')
|
||||
->desc('Get Country Flag')
|
||||
->groups(['api', 'avatars'])
|
||||
->param('code', '', function () use ($types) { return new WhiteList(\array_keys($types['flags'])); }, 'Country Code. ISO Alpha-2 country code format.')
|
||||
->param('code', '', function () { return new WhiteList(\array_keys(Config::getParam('avatar-flags'))); }, 'Country Code. ISO Alpha-2 country code format.')
|
||||
->param('width', 100, function () { return new Range(0, 2000); }, 'Image width. Pass an integer between 0 to 2000. Defaults to 100.', true)
|
||||
->param('height', 100, function () { return new Range(0, 2000); }, 'Image height. Pass an integer between 0 to 2000. Defaults to 100.', true)
|
||||
->param('quality', 100, function () { return new Range(0, 100); }, 'Image quality. Pass an integer between 0 to 100. Defaults to 100.', true)
|
||||
|
@ -138,7 +134,7 @@ $utopia->get('/v1/avatars/flags/:code')
|
|||
return $avatarCallback('flags', $code, $width, $height, $quality);
|
||||
});
|
||||
|
||||
$utopia->get('/v1/avatars/image')
|
||||
App::get('/v1/avatars/image')
|
||||
->desc('Get Image from URL')
|
||||
->groups(['api', 'avatars'])
|
||||
->param('url', '', function () { return new URL(); }, 'Image URL which you want to crop.')
|
||||
|
@ -206,7 +202,7 @@ $utopia->get('/v1/avatars/image')
|
|||
}
|
||||
);
|
||||
|
||||
$utopia->get('/v1/avatars/favicon')
|
||||
App::get('/v1/avatars/favicon')
|
||||
->desc('Get Favicon')
|
||||
->groups(['api', 'avatars'])
|
||||
->param('url', '', function () { return new URL(); }, 'Website URL which you want to fetch the favicon from.')
|
||||
|
@ -217,7 +213,7 @@ $utopia->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;
|
||||
|
@ -250,7 +246,7 @@ $utopia->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)
|
||||
),
|
||||
]);
|
||||
|
||||
|
@ -359,7 +355,7 @@ $utopia->get('/v1/avatars/favicon')
|
|||
}
|
||||
);
|
||||
|
||||
$utopia->get('/v1/avatars/qr')
|
||||
App::get('/v1/avatars/qr')
|
||||
->desc('Get QR Code')
|
||||
->groups(['api', 'avatars'])
|
||||
->param('text', '', function () { return new Text(512); }, 'Plain text to be converted to QR code image.')
|
||||
|
@ -395,7 +391,7 @@ $utopia->get('/v1/avatars/qr')
|
|||
}
|
||||
);
|
||||
|
||||
$utopia->get('/v1/avatars/initials')
|
||||
App::get('/v1/avatars/initials')
|
||||
->desc('Get User Initials')
|
||||
->groups(['api', 'avatars'])
|
||||
->param('name', '', function () { return new Text(512); }, 'Full Name. When empty, current user name or email will be used.', true)
|
||||
|
|
|
@ -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;
|
||||
|
@ -27,7 +26,7 @@ use Appwrite\Database\Exception\Structure as StructureException;
|
|||
// use DeviceDetector\DeviceDetector;
|
||||
// use GeoIp2\Database\Reader;
|
||||
|
||||
$utopia->post('/v1/database/collections')
|
||||
App::post('/v1/database/collections')
|
||||
->desc('Create Collection')
|
||||
->groups(['api', 'database'])
|
||||
->label('webhook', 'database.collections.create')
|
||||
|
@ -101,7 +100,7 @@ $utopia->post('/v1/database/collections')
|
|||
}
|
||||
);
|
||||
|
||||
$utopia->get('/v1/database/collections')
|
||||
App::get('/v1/database/collections')
|
||||
->desc('List Collections')
|
||||
->groups(['api', 'database'])
|
||||
->label('scope', 'collections.read')
|
||||
|
@ -131,7 +130,7 @@ $utopia->get('/v1/database/collections')
|
|||
}
|
||||
);
|
||||
|
||||
$utopia->get('/v1/database/collections/:collectionId')
|
||||
App::get('/v1/database/collections/:collectionId')
|
||||
->desc('Get Collection')
|
||||
->groups(['api', 'database'])
|
||||
->label('scope', 'collections.read')
|
||||
|
@ -152,7 +151,7 @@ $utopia->get('/v1/database/collections/:collectionId')
|
|||
}
|
||||
);
|
||||
|
||||
// $utopia->get('/v1/database/collections/:collectionId/logs')
|
||||
// App::get('/v1/database/collections/:collectionId/logs')
|
||||
// ->desc('Get Collection Logs')
|
||||
// ->groups(['api', 'database'])
|
||||
// ->label('scope', 'collections.read')
|
||||
|
@ -217,7 +216,7 @@ $utopia->get('/v1/database/collections/:collectionId')
|
|||
// }
|
||||
// );
|
||||
|
||||
$utopia->put('/v1/database/collections/:collectionId')
|
||||
App::put('/v1/database/collections/:collectionId')
|
||||
->desc('Update Collection')
|
||||
->groups(['api', 'database'])
|
||||
->label('scope', 'collections.write')
|
||||
|
@ -290,7 +289,7 @@ $utopia->put('/v1/database/collections/:collectionId')
|
|||
}
|
||||
);
|
||||
|
||||
$utopia->delete('/v1/database/collections/:collectionId')
|
||||
App::delete('/v1/database/collections/:collectionId')
|
||||
->desc('Delete Collection')
|
||||
->groups(['api', 'database'])
|
||||
->label('scope', 'collections.write')
|
||||
|
@ -328,7 +327,7 @@ $utopia->delete('/v1/database/collections/:collectionId')
|
|||
}
|
||||
);
|
||||
|
||||
$utopia->post('/v1/database/collections/:collectionId/documents')
|
||||
App::post('/v1/database/collections/:collectionId/documents')
|
||||
->desc('Create Document')
|
||||
->groups(['api', 'database'])
|
||||
->label('webhook', 'database.documents.create')
|
||||
|
@ -448,7 +447,7 @@ $utopia->post('/v1/database/collections/:collectionId/documents')
|
|||
}
|
||||
);
|
||||
|
||||
$utopia->get('/v1/database/collections/:collectionId/documents')
|
||||
App::get('/v1/database/collections/:collectionId/documents')
|
||||
->desc('List Documents')
|
||||
->groups(['api', 'database'])
|
||||
->label('scope', 'documents.read')
|
||||
|
@ -465,7 +464,7 @@ $utopia->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()) {
|
||||
|
@ -484,7 +483,7 @@ $utopia->get('/v1/database/collections/:collectionId/documents')
|
|||
]),
|
||||
]);
|
||||
|
||||
if ($utopia->isDevelopment()) {
|
||||
if (App::isDevelopment()) {
|
||||
$collection
|
||||
->setAttribute('debug', $projectDB->getDebug())
|
||||
->setAttribute('limit', $limit)
|
||||
|
@ -508,7 +507,7 @@ $utopia->get('/v1/database/collections/:collectionId/documents')
|
|||
}
|
||||
);
|
||||
|
||||
$utopia->get('/v1/database/collections/:collectionId/documents/:documentId')
|
||||
App::get('/v1/database/collections/:collectionId/documents/:documentId')
|
||||
->desc('Get Document')
|
||||
->groups(['api', 'database'])
|
||||
->label('scope', 'documents.read')
|
||||
|
@ -554,7 +553,7 @@ $utopia->get('/v1/database/collections/:collectionId/documents/:documentId')
|
|||
}
|
||||
);
|
||||
|
||||
$utopia->patch('/v1/database/collections/:collectionId/documents/:documentId')
|
||||
App::patch('/v1/database/collections/:collectionId/documents/:documentId')
|
||||
->desc('Update Document')
|
||||
->groups(['api', 'database'])
|
||||
->label('webhook', 'database.documents.update')
|
||||
|
@ -634,7 +633,7 @@ $utopia->patch('/v1/database/collections/:collectionId/documents/:documentId')
|
|||
}
|
||||
);
|
||||
|
||||
$utopia->delete('/v1/database/collections/:collectionId/documents/:documentId')
|
||||
App::delete('/v1/database/collections/:collectionId/documents/:documentId')
|
||||
->desc('Delete Document')
|
||||
->groups(['api', 'database'])
|
||||
->label('scope', 'documents.write')
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
global $utopia;
|
||||
use Utopia\App;
|
||||
|
||||
/**
|
||||
* TODO:
|
||||
|
@ -12,7 +12,7 @@ global $utopia;
|
|||
* 6. Write tests!
|
||||
*/
|
||||
|
||||
$utopia->post('/v1/graphql')
|
||||
App::post('/v1/graphql')
|
||||
->desc('GraphQL Endpoint')
|
||||
->groups(['api', 'graphql'])
|
||||
->label('scope', 'public')
|
||||
|
|
|
@ -1,13 +1,14 @@
|
|||
<?php
|
||||
|
||||
global $utopia, $request, $response, $register, $project;
|
||||
global $request, $response, $register;
|
||||
|
||||
use Utopia\App;
|
||||
use Utopia\Exception;
|
||||
use Appwrite\Storage\Device\Local;
|
||||
use Appwrite\Storage\Storage;
|
||||
use Appwrite\ClamAV\Network;
|
||||
|
||||
$utopia->get('/v1/health')
|
||||
App::get('/v1/health')
|
||||
->desc('Get HTTP')
|
||||
->groups(['api', 'health'])
|
||||
->label('scope', 'health.read')
|
||||
|
@ -21,7 +22,7 @@ $utopia->get('/v1/health')
|
|||
}
|
||||
);
|
||||
|
||||
$utopia->get('/v1/health/version')
|
||||
App::get('/v1/health/version')
|
||||
->desc('Get Version')
|
||||
->groups(['api', 'health'])
|
||||
->label('scope', 'public')
|
||||
|
@ -31,7 +32,7 @@ $utopia->get('/v1/health/version')
|
|||
}
|
||||
);
|
||||
|
||||
$utopia->get('/v1/health/db')
|
||||
App::get('/v1/health/db')
|
||||
->desc('Get DB')
|
||||
->groups(['api', 'health'])
|
||||
->label('scope', 'health.read')
|
||||
|
@ -47,7 +48,7 @@ $utopia->get('/v1/health/db')
|
|||
}
|
||||
);
|
||||
|
||||
$utopia->get('/v1/health/cache')
|
||||
App::get('/v1/health/cache')
|
||||
->desc('Get Cache')
|
||||
->groups(['api', 'health'])
|
||||
->label('scope', 'health.read')
|
||||
|
@ -63,7 +64,7 @@ $utopia->get('/v1/health/cache')
|
|||
}
|
||||
);
|
||||
|
||||
$utopia->get('/v1/health/time')
|
||||
App::get('/v1/health/time')
|
||||
->desc('Get Time')
|
||||
->groups(['api', 'health'])
|
||||
->label('scope', 'health.read')
|
||||
|
@ -111,7 +112,7 @@ $utopia->get('/v1/health/time')
|
|||
}
|
||||
);
|
||||
|
||||
$utopia->get('/v1/health/queue/webhooks')
|
||||
App::get('/v1/health/queue/webhooks')
|
||||
->desc('Get Webhooks Queue')
|
||||
->groups(['api', 'health'])
|
||||
->label('scope', 'health.read')
|
||||
|
@ -125,7 +126,7 @@ $utopia->get('/v1/health/queue/webhooks')
|
|||
}
|
||||
);
|
||||
|
||||
$utopia->get('/v1/health/queue/tasks')
|
||||
App::get('/v1/health/queue/tasks')
|
||||
->desc('Get Tasks Queue')
|
||||
->groups(['api', 'health'])
|
||||
->label('scope', 'health.read')
|
||||
|
@ -139,7 +140,7 @@ $utopia->get('/v1/health/queue/tasks')
|
|||
}
|
||||
);
|
||||
|
||||
$utopia->get('/v1/health/queue/logs')
|
||||
App::get('/v1/health/queue/logs')
|
||||
->desc('Get Logs Queue')
|
||||
->groups(['api', 'health'])
|
||||
->label('scope', 'health.read')
|
||||
|
@ -153,7 +154,7 @@ $utopia->get('/v1/health/queue/logs')
|
|||
}
|
||||
);
|
||||
|
||||
$utopia->get('/v1/health/queue/usage')
|
||||
App::get('/v1/health/queue/usage')
|
||||
->desc('Get Usage Queue')
|
||||
->groups(['api', 'health'])
|
||||
->label('scope', 'health.read')
|
||||
|
@ -167,7 +168,7 @@ $utopia->get('/v1/health/queue/usage')
|
|||
}
|
||||
);
|
||||
|
||||
$utopia->get('/v1/health/queue/certificates')
|
||||
App::get('/v1/health/queue/certificates')
|
||||
->desc('Get Certificate Queue')
|
||||
->groups(['api', 'health'])
|
||||
->label('scope', 'health.read')
|
||||
|
@ -181,7 +182,7 @@ $utopia->get('/v1/health/queue/certificates')
|
|||
}
|
||||
);
|
||||
|
||||
$utopia->get('/v1/health/queue/functions')
|
||||
App::get('/v1/health/queue/functions')
|
||||
->desc('Get Functions Queue')
|
||||
->groups(['api', 'health'])
|
||||
->label('scope', 'health.read')
|
||||
|
@ -195,7 +196,7 @@ $utopia->get('/v1/health/queue/functions')
|
|||
}
|
||||
);
|
||||
|
||||
$utopia->get('/v1/health/storage/local')
|
||||
App::get('/v1/health/storage/local')
|
||||
->desc('Get Local Storage')
|
||||
->groups(['api', 'health'])
|
||||
->label('scope', 'health.read')
|
||||
|
@ -226,7 +227,7 @@ $utopia->get('/v1/health/storage/local')
|
|||
}
|
||||
);
|
||||
|
||||
$utopia->get('/v1/health/anti-virus')
|
||||
App::get('/v1/health/anti-virus')
|
||||
->desc('Get Anti virus')
|
||||
->groups(['api', 'health'])
|
||||
->label('scope', 'health.read')
|
||||
|
@ -235,8 +236,8 @@ $utopia->get('/v1/health/anti-virus')
|
|||
->label('sdk.method', 'getAntiVirus')
|
||||
->label('sdk.description', '/docs/references/health/get-storage-anti-virus.md')
|
||||
->action(
|
||||
function () use ($request, $response) {
|
||||
if ($request->getServer('_APP_STORAGE_ANTIVIRUS') === 'disabled') { // Check if scans are enabled
|
||||
function () use ($response) {
|
||||
if (App::getEnv('_APP_STORAGE_ANTIVIRUS') === 'disabled') { // Check if scans are enabled
|
||||
throw new Exception('Anitvirus is disabled');
|
||||
}
|
||||
|
||||
|
@ -249,7 +250,7 @@ $utopia->get('/v1/health/anti-virus')
|
|||
}
|
||||
);
|
||||
|
||||
$utopia->get('/v1/health/stats') // Currently only used internally
|
||||
App::get('/v1/health/stats') // Currently only used internally
|
||||
->desc('Get System Stats')
|
||||
->groups(['api', 'health'])
|
||||
->label('scope', 'god')
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
global $utopia, $register, $request, $response, $projectDB, $project, $user, $audit;
|
||||
global $request, $response, $user;
|
||||
|
||||
use Appwrite\Database\Document;
|
||||
use Appwrite\Utopia\Response;
|
||||
|
@ -8,7 +8,7 @@ use Utopia\App;
|
|||
use Utopia\Locale\Locale;
|
||||
use GeoIp2\Database\Reader;
|
||||
|
||||
$utopia->get('/v1/locale')
|
||||
App::get('/v1/locale')
|
||||
->desc('Get User Locale')
|
||||
->groups(['api', 'locale'])
|
||||
->label('scope', 'locale.read')
|
||||
|
@ -17,7 +17,7 @@ $utopia->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');
|
||||
|
@ -27,7 +27,7 @@ $utopia->get('/v1/locale')
|
|||
$countries = Locale::getText('countries');
|
||||
$continents = Locale::getText('continents');
|
||||
|
||||
if (App::MODE_TYPE_PRODUCTION !== $utopia->getMode()) {
|
||||
if (!App::isProduction()) {
|
||||
$ip = '79.177.241.94';
|
||||
}
|
||||
|
||||
|
@ -69,7 +69,7 @@ $utopia->get('/v1/locale')
|
|||
}
|
||||
);
|
||||
|
||||
$utopia->get('/v1/locale/countries')
|
||||
App::get('/v1/locale/countries')
|
||||
->desc('List Countries')
|
||||
->groups(['api', 'locale'])
|
||||
->label('scope', 'locale.read')
|
||||
|
@ -87,7 +87,7 @@ $utopia->get('/v1/locale/countries')
|
|||
}
|
||||
);
|
||||
|
||||
$utopia->get('/v1/locale/countries/eu')
|
||||
App::get('/v1/locale/countries/eu')
|
||||
->desc('List EU Countries')
|
||||
->groups(['api', 'locale'])
|
||||
->label('scope', 'locale.read')
|
||||
|
@ -113,7 +113,7 @@ $utopia->get('/v1/locale/countries/eu')
|
|||
}
|
||||
);
|
||||
|
||||
$utopia->get('/v1/locale/countries/phones')
|
||||
App::get('/v1/locale/countries/phones')
|
||||
->desc('List Countries Phone Codes')
|
||||
->groups(['api', 'locale'])
|
||||
->label('scope', 'locale.read')
|
||||
|
@ -139,7 +139,7 @@ $utopia->get('/v1/locale/countries/phones')
|
|||
}
|
||||
);
|
||||
|
||||
$utopia->get('/v1/locale/continents')
|
||||
App::get('/v1/locale/continents')
|
||||
->desc('List Continents')
|
||||
->groups(['api', 'locale'])
|
||||
->label('scope', 'locale.read')
|
||||
|
@ -158,7 +158,7 @@ $utopia->get('/v1/locale/continents')
|
|||
);
|
||||
|
||||
|
||||
$utopia->get('/v1/locale/currencies')
|
||||
App::get('/v1/locale/currencies')
|
||||
->desc('List Currencies')
|
||||
->groups(['api', 'locale'])
|
||||
->label('scope', 'locale.read')
|
||||
|
@ -175,7 +175,7 @@ $utopia->get('/v1/locale/currencies')
|
|||
);
|
||||
|
||||
|
||||
$utopia->get('/v1/locale/languages')
|
||||
App::get('/v1/locale/languages')
|
||||
->desc('List Languages')
|
||||
->groups(['api', 'locale'])
|
||||
->label('scope', 'locale.read')
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
<?php
|
||||
|
||||
global $utopia, $request, $response, $register, $user, $consoleDB, $projectDB, $deletes;
|
||||
global $response, $register, $user, $consoleDB, $projectDB, $deletes;
|
||||
|
||||
use Utopia\App;
|
||||
use Utopia\Exception;
|
||||
use Utopia\Response;
|
||||
use Utopia\Validator\ArrayList;
|
||||
|
@ -23,7 +24,7 @@ use Cron\CronExpression;
|
|||
|
||||
$scopes = include __DIR__.'/../../../app/config/scopes.php';
|
||||
|
||||
$utopia->post('/v1/projects')
|
||||
App::post('/v1/projects')
|
||||
->desc('Create Project')
|
||||
->groups(['api', 'projects'])
|
||||
->label('scope', 'projects.write')
|
||||
|
@ -41,7 +42,7 @@ $utopia->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()) {
|
||||
|
@ -86,14 +87,14 @@ $utopia->post('/v1/projects')
|
|||
}
|
||||
);
|
||||
|
||||
$utopia->get('/v1/projects')
|
||||
App::get('/v1/projects')
|
||||
->desc('List Projects')
|
||||
->groups(['api', 'projects'])
|
||||
->label('scope', 'projects.read')
|
||||
->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,
|
||||
|
@ -110,7 +111,7 @@ $utopia->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'])));
|
||||
}
|
||||
}
|
||||
|
@ -120,7 +121,7 @@ $utopia->get('/v1/projects')
|
|||
}
|
||||
);
|
||||
|
||||
$utopia->get('/v1/projects/:projectId')
|
||||
App::get('/v1/projects/:projectId')
|
||||
->desc('Get Project')
|
||||
->groups(['api', 'projects'])
|
||||
->label('scope', 'projects.read')
|
||||
|
@ -128,7 +129,7 @@ $utopia->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()) {
|
||||
|
@ -139,7 +140,7 @@ $utopia->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'])));
|
||||
}
|
||||
}
|
||||
|
@ -148,7 +149,7 @@ $utopia->get('/v1/projects/:projectId')
|
|||
}
|
||||
);
|
||||
|
||||
$utopia->get('/v1/projects/:projectId/usage')
|
||||
App::get('/v1/projects/:projectId/usage')
|
||||
->desc('Get Project')
|
||||
->groups(['api', 'projects'])
|
||||
->label('scope', 'projects.read')
|
||||
|
@ -310,7 +311,7 @@ $utopia->get('/v1/projects/:projectId/usage')
|
|||
}
|
||||
);
|
||||
|
||||
$utopia->patch('/v1/projects/:projectId')
|
||||
App::patch('/v1/projects/:projectId')
|
||||
->desc('Update Project')
|
||||
->groups(['api', 'projects'])
|
||||
->label('scope', 'projects.write')
|
||||
|
@ -356,7 +357,7 @@ $utopia->patch('/v1/projects/:projectId')
|
|||
}
|
||||
);
|
||||
|
||||
$utopia->patch('/v1/projects/:projectId/oauth2')
|
||||
App::patch('/v1/projects/:projectId/oauth2')
|
||||
->desc('Update Project OAuth2')
|
||||
->groups(['api', 'projects'])
|
||||
->label('scope', 'projects.write')
|
||||
|
@ -367,14 +368,14 @@ $utopia->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([
|
||||
|
@ -398,7 +399,7 @@ $utopia->patch('/v1/projects/:projectId/oauth2')
|
|||
}
|
||||
);
|
||||
|
||||
$utopia->delete('/v1/projects/:projectId')
|
||||
App::delete('/v1/projects/:projectId')
|
||||
->desc('Delete Project')
|
||||
->groups(['api', 'projects'])
|
||||
->label('scope', 'projects.write')
|
||||
|
@ -444,7 +445,7 @@ $utopia->delete('/v1/projects/:projectId')
|
|||
|
||||
// Webhooks
|
||||
|
||||
$utopia->post('/v1/projects/:projectId/webhooks')
|
||||
App::post('/v1/projects/:projectId/webhooks')
|
||||
->desc('Create Webhook')
|
||||
->groups(['api', 'projects'])
|
||||
->label('scope', 'projects.write')
|
||||
|
@ -458,7 +459,7 @@ $utopia->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()) {
|
||||
|
@ -466,7 +467,7 @@ $utopia->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([
|
||||
|
@ -510,7 +511,7 @@ $utopia->post('/v1/projects/:projectId/webhooks')
|
|||
}
|
||||
);
|
||||
|
||||
$utopia->get('/v1/projects/:projectId/webhooks')
|
||||
App::get('/v1/projects/:projectId/webhooks')
|
||||
->desc('List Webhooks')
|
||||
->groups(['api', 'projects'])
|
||||
->label('scope', 'projects.read')
|
||||
|
@ -518,7 +519,7 @@ $utopia->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()) {
|
||||
|
@ -534,7 +535,7 @@ $utopia->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'])));
|
||||
}
|
||||
|
@ -543,7 +544,7 @@ $utopia->get('/v1/projects/:projectId/webhooks')
|
|||
}
|
||||
);
|
||||
|
||||
$utopia->get('/v1/projects/:projectId/webhooks/:webhookId')
|
||||
App::get('/v1/projects/:projectId/webhooks/:webhookId')
|
||||
->desc('Get Webhook')
|
||||
->groups(['api', 'projects'])
|
||||
->label('scope', 'projects.read')
|
||||
|
@ -552,7 +553,7 @@ $utopia->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()) {
|
||||
|
@ -568,7 +569,7 @@ $utopia->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'])));
|
||||
}
|
||||
|
||||
|
@ -577,7 +578,7 @@ $utopia->get('/v1/projects/:projectId/webhooks/:webhookId')
|
|||
);
|
||||
|
||||
|
||||
$utopia->put('/v1/projects/:projectId/webhooks/:webhookId')
|
||||
App::put('/v1/projects/:projectId/webhooks/:webhookId')
|
||||
->desc('Update Webhook')
|
||||
->groups(['api', 'projects'])
|
||||
->label('scope', 'projects.write')
|
||||
|
@ -591,7 +592,7 @@ $utopia->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()) {
|
||||
|
@ -599,7 +600,7 @@ $utopia->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([
|
||||
|
@ -633,7 +634,7 @@ $utopia->put('/v1/projects/:projectId/webhooks/:webhookId')
|
|||
}
|
||||
);
|
||||
|
||||
$utopia->delete('/v1/projects/:projectId/webhooks/:webhookId')
|
||||
App::delete('/v1/projects/:projectId/webhooks/:webhookId')
|
||||
->desc('Delete Webhook')
|
||||
->groups(['api', 'projects'])
|
||||
->label('scope', 'projects.write')
|
||||
|
@ -665,7 +666,7 @@ $utopia->delete('/v1/projects/:projectId/webhooks/:webhookId')
|
|||
|
||||
// Keys
|
||||
|
||||
$utopia->post('/v1/projects/:projectId/keys')
|
||||
App::post('/v1/projects/:projectId/keys')
|
||||
->desc('Create Key')
|
||||
->groups(['api', 'projects'])
|
||||
->label('scope', 'projects.write')
|
||||
|
@ -712,7 +713,7 @@ $utopia->post('/v1/projects/:projectId/keys')
|
|||
}
|
||||
);
|
||||
|
||||
$utopia->get('/v1/projects/:projectId/keys')
|
||||
App::get('/v1/projects/:projectId/keys')
|
||||
->desc('List Keys')
|
||||
->groups(['api', 'projects'])
|
||||
->label('scope', 'projects.read')
|
||||
|
@ -731,7 +732,7 @@ $utopia->get('/v1/projects/:projectId/keys')
|
|||
}
|
||||
);
|
||||
|
||||
$utopia->get('/v1/projects/:projectId/keys/:keyId')
|
||||
App::get('/v1/projects/:projectId/keys/:keyId')
|
||||
->desc('Get Key')
|
||||
->groups(['api', 'projects'])
|
||||
->label('scope', 'projects.read')
|
||||
|
@ -757,7 +758,7 @@ $utopia->get('/v1/projects/:projectId/keys/:keyId')
|
|||
}
|
||||
);
|
||||
|
||||
$utopia->put('/v1/projects/:projectId/keys/:keyId')
|
||||
App::put('/v1/projects/:projectId/keys/:keyId')
|
||||
->desc('Update Key')
|
||||
->groups(['api', 'projects'])
|
||||
->label('scope', 'projects.write')
|
||||
|
@ -794,7 +795,7 @@ $utopia->put('/v1/projects/:projectId/keys/:keyId')
|
|||
}
|
||||
);
|
||||
|
||||
$utopia->delete('/v1/projects/:projectId/keys/:keyId')
|
||||
App::delete('/v1/projects/:projectId/keys/:keyId')
|
||||
->desc('Delete Key')
|
||||
->groups(['api', 'projects'])
|
||||
->label('scope', 'projects.write')
|
||||
|
@ -826,7 +827,7 @@ $utopia->delete('/v1/projects/:projectId/keys/:keyId')
|
|||
|
||||
// Tasks
|
||||
|
||||
$utopia->post('/v1/projects/:projectId/tasks')
|
||||
App::post('/v1/projects/:projectId/tasks')
|
||||
->desc('Create Task')
|
||||
->groups(['api', 'projects'])
|
||||
->label('scope', 'projects.write')
|
||||
|
@ -842,7 +843,7 @@ $utopia->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()) {
|
||||
|
@ -853,7 +854,7 @@ $utopia->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([
|
||||
|
@ -909,7 +910,7 @@ $utopia->post('/v1/projects/:projectId/tasks')
|
|||
}
|
||||
);
|
||||
|
||||
$utopia->get('/v1/projects/:projectId/tasks')
|
||||
App::get('/v1/projects/:projectId/tasks')
|
||||
->desc('List Tasks')
|
||||
->groups(['api', 'projects'])
|
||||
->label('scope', 'projects.read')
|
||||
|
@ -917,7 +918,7 @@ $utopia->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()) {
|
||||
|
@ -933,7 +934,7 @@ $utopia->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'])));
|
||||
}
|
||||
|
@ -942,7 +943,7 @@ $utopia->get('/v1/projects/:projectId/tasks')
|
|||
}
|
||||
);
|
||||
|
||||
$utopia->get('/v1/projects/:projectId/tasks/:taskId')
|
||||
App::get('/v1/projects/:projectId/tasks/:taskId')
|
||||
->desc('Get Task')
|
||||
->groups(['api', 'projects'])
|
||||
->label('scope', 'projects.read')
|
||||
|
@ -951,7 +952,7 @@ $utopia->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()) {
|
||||
|
@ -967,7 +968,7 @@ $utopia->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'])));
|
||||
}
|
||||
|
||||
|
@ -975,7 +976,7 @@ $utopia->get('/v1/projects/:projectId/tasks/:taskId')
|
|||
}
|
||||
);
|
||||
|
||||
$utopia->put('/v1/projects/:projectId/tasks/:taskId')
|
||||
App::put('/v1/projects/:projectId/tasks/:taskId')
|
||||
->desc('Update Task')
|
||||
->groups(['api', 'projects'])
|
||||
->label('scope', 'projects.write')
|
||||
|
@ -993,7 +994,7 @@ $utopia->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()) {
|
||||
|
@ -1010,7 +1011,7 @@ $utopia->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([
|
||||
|
@ -1047,7 +1048,7 @@ $utopia->put('/v1/projects/:projectId/tasks/:taskId')
|
|||
}
|
||||
);
|
||||
|
||||
$utopia->delete('/v1/projects/:projectId/tasks/:taskId')
|
||||
App::delete('/v1/projects/:projectId/tasks/:taskId')
|
||||
->desc('Delete Task')
|
||||
->groups(['api', 'projects'])
|
||||
->label('scope', 'projects.write')
|
||||
|
@ -1079,7 +1080,7 @@ $utopia->delete('/v1/projects/:projectId/tasks/:taskId')
|
|||
|
||||
// Platforms
|
||||
|
||||
$utopia->post('/v1/projects/:projectId/platforms')
|
||||
App::post('/v1/projects/:projectId/platforms')
|
||||
->desc('Create Platform')
|
||||
->groups(['api', 'projects'])
|
||||
->label('scope', 'projects.write')
|
||||
|
@ -1133,7 +1134,7 @@ $utopia->post('/v1/projects/:projectId/platforms')
|
|||
}
|
||||
);
|
||||
|
||||
$utopia->get('/v1/projects/:projectId/platforms')
|
||||
App::get('/v1/projects/:projectId/platforms')
|
||||
->desc('List Platforms')
|
||||
->groups(['api', 'projects'])
|
||||
->label('scope', 'projects.read')
|
||||
|
@ -1154,7 +1155,7 @@ $utopia->get('/v1/projects/:projectId/platforms')
|
|||
}
|
||||
);
|
||||
|
||||
$utopia->get('/v1/projects/:projectId/platforms/:platformId')
|
||||
App::get('/v1/projects/:projectId/platforms/:platformId')
|
||||
->desc('Get Platform')
|
||||
->groups(['api', 'projects'])
|
||||
->label('scope', 'projects.read')
|
||||
|
@ -1180,7 +1181,7 @@ $utopia->get('/v1/projects/:projectId/platforms/:platformId')
|
|||
}
|
||||
);
|
||||
|
||||
$utopia->put('/v1/projects/:projectId/platforms/:platformId')
|
||||
App::put('/v1/projects/:projectId/platforms/:platformId')
|
||||
->desc('Update Platform')
|
||||
->groups(['api', 'projects'])
|
||||
->label('scope', 'projects.write')
|
||||
|
@ -1222,7 +1223,7 @@ $utopia->put('/v1/projects/:projectId/platforms/:platformId')
|
|||
}
|
||||
);
|
||||
|
||||
$utopia->delete('/v1/projects/:projectId/platforms/:platformId')
|
||||
App::delete('/v1/projects/:projectId/platforms/:platformId')
|
||||
->desc('Delete Platform')
|
||||
->groups(['api', 'projects'])
|
||||
->label('scope', 'projects.write')
|
||||
|
@ -1254,7 +1255,7 @@ $utopia->delete('/v1/projects/:projectId/platforms/:platformId')
|
|||
|
||||
// Domains
|
||||
|
||||
$utopia->post('/v1/projects/:projectId/domains')
|
||||
App::post('/v1/projects/:projectId/domains')
|
||||
->desc('Create Domain')
|
||||
->groups(['api', 'projects'])
|
||||
->label('scope', 'projects.write')
|
||||
|
@ -1263,7 +1264,7 @@ $utopia->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()) {
|
||||
|
@ -1276,7 +1277,7 @@ $utopia->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);
|
||||
|
@ -1317,7 +1318,7 @@ $utopia->post('/v1/projects/:projectId/domains')
|
|||
}
|
||||
);
|
||||
|
||||
$utopia->get('/v1/projects/:projectId/domains')
|
||||
App::get('/v1/projects/:projectId/domains')
|
||||
->desc('List Domains')
|
||||
->groups(['api', 'projects'])
|
||||
->label('scope', 'projects.read')
|
||||
|
@ -1338,7 +1339,7 @@ $utopia->get('/v1/projects/:projectId/domains')
|
|||
}
|
||||
);
|
||||
|
||||
$utopia->get('/v1/projects/:projectId/domains/:domainId')
|
||||
App::get('/v1/projects/:projectId/domains/:domainId')
|
||||
->desc('Get Domain')
|
||||
->groups(['api', 'projects'])
|
||||
->label('scope', 'projects.read')
|
||||
|
@ -1364,7 +1365,7 @@ $utopia->get('/v1/projects/:projectId/domains/:domainId')
|
|||
}
|
||||
);
|
||||
|
||||
$utopia->patch('/v1/projects/:projectId/domains/:domainId/verification')
|
||||
App::patch('/v1/projects/:projectId/domains/:domainId/verification')
|
||||
->desc('Update Domain Verification Status')
|
||||
->groups(['api', 'projects'])
|
||||
->label('scope', 'projects.write')
|
||||
|
@ -1373,7 +1374,7 @@ $utopia->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()) {
|
||||
|
@ -1386,7 +1387,7 @@ $utopia->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);
|
||||
|
@ -1421,7 +1422,7 @@ $utopia->patch('/v1/projects/:projectId/domains/:domainId/verification')
|
|||
}
|
||||
);
|
||||
|
||||
$utopia->delete('/v1/projects/:projectId/domains/:domainId')
|
||||
App::delete('/v1/projects/:projectId/domains/:domainId')
|
||||
->desc('Delete Domain')
|
||||
->groups(['api', 'projects'])
|
||||
->label('scope', 'projects.write')
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
<?php
|
||||
|
||||
global $utopia, $request, $response, $register, $user, $audit, $usage, $project, $projectDB;
|
||||
global $request, $response, $user, $audit, $usage, $project, $projectDB;
|
||||
|
||||
use Utopia\App;
|
||||
use Utopia\Exception;
|
||||
use Utopia\Response;
|
||||
use Utopia\Validator\ArrayList;
|
||||
|
@ -129,11 +130,11 @@ $mimes = [
|
|||
'application/pdf',
|
||||
];
|
||||
|
||||
$utopia->init(function () use ($project) {
|
||||
App::init(function () use ($project) {
|
||||
Storage::addDevice('local', new Local(APP_STORAGE_UPLOADS.'/app-'.$project->getId()));
|
||||
}, 'storage');
|
||||
|
||||
$utopia->post('/v1/storage/files')
|
||||
App::post('/v1/storage/files')
|
||||
->desc('Create File')
|
||||
->groups(['api', 'storage'])
|
||||
->label('scope', 'files.write')
|
||||
|
@ -158,7 +159,7 @@ $utopia->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)) {
|
||||
|
@ -199,7 +200,7 @@ $utopia->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
|
||||
|
@ -213,7 +214,7 @@ $utopia->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);
|
||||
|
||||
|
@ -270,7 +271,7 @@ $utopia->post('/v1/storage/files')
|
|||
}
|
||||
);
|
||||
|
||||
$utopia->get('/v1/storage/files')
|
||||
App::get('/v1/storage/files')
|
||||
->desc('List Files')
|
||||
->groups(['api', 'storage'])
|
||||
->label('scope', 'files.read')
|
||||
|
@ -304,7 +305,7 @@ $utopia->get('/v1/storage/files')
|
|||
}
|
||||
);
|
||||
|
||||
$utopia->get('/v1/storage/files/:fileId')
|
||||
App::get('/v1/storage/files/:fileId')
|
||||
->desc('Get File')
|
||||
->groups(['api', 'storage'])
|
||||
->label('scope', 'files.read')
|
||||
|
@ -325,7 +326,7 @@ $utopia->get('/v1/storage/files/:fileId')
|
|||
}
|
||||
);
|
||||
|
||||
$utopia->get('/v1/storage/files/:fileId/preview')
|
||||
App::get('/v1/storage/files/:fileId/preview')
|
||||
->desc('Get File Preview')
|
||||
->groups(['api', 'storage'])
|
||||
->label('scope', 'files.read')
|
||||
|
@ -410,7 +411,7 @@ $utopia->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'))
|
||||
|
@ -448,7 +449,7 @@ $utopia->get('/v1/storage/files/:fileId/preview')
|
|||
}
|
||||
);
|
||||
|
||||
$utopia->get('/v1/storage/files/:fileId/download')
|
||||
App::get('/v1/storage/files/:fileId/download')
|
||||
->desc('Get File for Download')
|
||||
->groups(['api', 'storage'])
|
||||
->label('scope', 'files.read')
|
||||
|
@ -460,7 +461,7 @@ $utopia->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()) {
|
||||
|
@ -482,7 +483,7 @@ $utopia->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'))
|
||||
|
@ -502,7 +503,7 @@ $utopia->get('/v1/storage/files/:fileId/download')
|
|||
}
|
||||
);
|
||||
|
||||
$utopia->get('/v1/storage/files/:fileId/view')
|
||||
App::get('/v1/storage/files/:fileId/view')
|
||||
->desc('Get File for View')
|
||||
->groups(['api', 'storage'])
|
||||
->label('scope', 'files.read')
|
||||
|
@ -515,7 +516,7 @@ $utopia->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()) {
|
||||
|
@ -543,7 +544,7 @@ $utopia->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'))
|
||||
|
@ -573,7 +574,7 @@ $utopia->get('/v1/storage/files/:fileId/view')
|
|||
}
|
||||
);
|
||||
|
||||
$utopia->put('/v1/storage/files/:fileId')
|
||||
App::put('/v1/storage/files/:fileId')
|
||||
->desc('Update File')
|
||||
->groups(['api', 'storage'])
|
||||
->label('scope', 'files.write')
|
||||
|
@ -619,7 +620,7 @@ $utopia->put('/v1/storage/files/:fileId')
|
|||
}
|
||||
);
|
||||
|
||||
$utopia->delete('/v1/storage/files/:fileId')
|
||||
App::delete('/v1/storage/files/:fileId')
|
||||
->desc('Delete File')
|
||||
->groups(['api', 'storage'])
|
||||
->label('scope', 'files.write')
|
||||
|
@ -662,7 +663,7 @@ $utopia->delete('/v1/storage/files/:fileId')
|
|||
}
|
||||
);
|
||||
|
||||
// $utopia->get('/v1/storage/files/:fileId/scan')
|
||||
// App::get('/v1/storage/files/:fileId/scan')
|
||||
// ->desc('Scan Storage')
|
||||
// ->groups(['api', 'storage'])
|
||||
// ->label('scope', 'god')
|
||||
|
@ -695,7 +696,7 @@ $utopia->delete('/v1/storage/files/:fileId')
|
|||
// $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,7 +1,8 @@
|
|||
<?php
|
||||
|
||||
global $utopia, $register, $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;
|
||||
use Utopia\Config\Config;
|
||||
use Utopia\Validator\Email;
|
||||
|
@ -20,7 +21,7 @@ use Appwrite\Database\Exception\Duplicate;
|
|||
use Appwrite\Template\Template;
|
||||
use Appwrite\Utopia\Response;
|
||||
|
||||
$utopia->post('/v1/teams')
|
||||
App::post('/v1/teams')
|
||||
->desc('Create Team')
|
||||
->groups(['api', 'teams'])
|
||||
->label('scope', 'teams.write')
|
||||
|
@ -82,7 +83,7 @@ $utopia->post('/v1/teams')
|
|||
}
|
||||
);
|
||||
|
||||
$utopia->get('/v1/teams')
|
||||
App::get('/v1/teams')
|
||||
->desc('List Teams')
|
||||
->groups(['api', 'teams'])
|
||||
->label('scope', 'teams.read')
|
||||
|
@ -115,7 +116,7 @@ $utopia->get('/v1/teams')
|
|||
}
|
||||
);
|
||||
|
||||
$utopia->get('/v1/teams/:teamId')
|
||||
App::get('/v1/teams/:teamId')
|
||||
->desc('Get Team')
|
||||
->groups(['api', 'teams'])
|
||||
->label('scope', 'teams.read')
|
||||
|
@ -136,7 +137,7 @@ $utopia->get('/v1/teams/:teamId')
|
|||
}
|
||||
);
|
||||
|
||||
$utopia->put('/v1/teams/:teamId')
|
||||
App::put('/v1/teams/:teamId')
|
||||
->desc('Update Team')
|
||||
->groups(['api', 'teams'])
|
||||
->label('scope', 'teams.write')
|
||||
|
@ -166,7 +167,7 @@ $utopia->put('/v1/teams/:teamId')
|
|||
}
|
||||
);
|
||||
|
||||
$utopia->delete('/v1/teams/:teamId')
|
||||
App::delete('/v1/teams/:teamId')
|
||||
->desc('Delete Team')
|
||||
->groups(['api', 'teams'])
|
||||
->label('scope', 'teams.write')
|
||||
|
@ -206,7 +207,7 @@ $utopia->delete('/v1/teams/:teamId')
|
|||
}
|
||||
);
|
||||
|
||||
$utopia->post('/v1/teams/:teamId/memberships')
|
||||
App::post('/v1/teams/:teamId/memberships')
|
||||
->desc('Create Team Membership')
|
||||
->groups(['api', 'teams'])
|
||||
->label('scope', 'teams.write')
|
||||
|
@ -373,7 +374,7 @@ $utopia->post('/v1/teams/:teamId/memberships')
|
|||
}
|
||||
);
|
||||
|
||||
$utopia->get('/v1/teams/:teamId/memberships')
|
||||
App::get('/v1/teams/:teamId/memberships')
|
||||
->desc('Get Team Memberships')
|
||||
->groups(['api', 'teams'])
|
||||
->label('scope', 'teams.read')
|
||||
|
@ -423,7 +424,7 @@ $utopia->get('/v1/teams/:teamId/memberships')
|
|||
}
|
||||
);
|
||||
|
||||
$utopia->patch('/v1/teams/:teamId/memberships/:inviteId/status')
|
||||
App::patch('/v1/teams/:teamId/memberships/:inviteId/status')
|
||||
->desc('Update Team Membership Status')
|
||||
->groups(['api', 'teams'])
|
||||
->label('scope', 'public')
|
||||
|
@ -548,7 +549,7 @@ $utopia->patch('/v1/teams/:teamId/memberships/:inviteId/status')
|
|||
}
|
||||
);
|
||||
|
||||
$utopia->delete('/v1/teams/:teamId/memberships/:inviteId')
|
||||
App::delete('/v1/teams/:teamId/memberships/:inviteId')
|
||||
->desc('Delete Team Membership')
|
||||
->groups(['api', 'teams'])
|
||||
->label('scope', 'teams.write')
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
<?php
|
||||
|
||||
global $utopia, $response, $projectDB;
|
||||
global $response, $projectDB;
|
||||
|
||||
use Utopia\App;
|
||||
use Utopia\Exception;
|
||||
use Utopia\Validator\Assoc;
|
||||
use Utopia\Validator\WhiteList;
|
||||
|
@ -21,7 +22,7 @@ use Appwrite\Utopia\Response;
|
|||
use DeviceDetector\DeviceDetector;
|
||||
use GeoIp2\Database\Reader;
|
||||
|
||||
$utopia->post('/v1/users')
|
||||
App::post('/v1/users')
|
||||
->desc('Create User')
|
||||
->groups(['api', 'users'])
|
||||
->label('scope', 'users.write')
|
||||
|
@ -82,7 +83,7 @@ $utopia->post('/v1/users')
|
|||
}
|
||||
);
|
||||
|
||||
$utopia->get('/v1/users')
|
||||
App::get('/v1/users')
|
||||
->desc('List Users')
|
||||
->groups(['api', 'users'])
|
||||
->label('scope', 'users.read')
|
||||
|
@ -137,7 +138,7 @@ $utopia->get('/v1/users')
|
|||
}
|
||||
);
|
||||
|
||||
$utopia->get('/v1/users/:userId')
|
||||
App::get('/v1/users/:userId')
|
||||
->desc('Get User')
|
||||
->groups(['api', 'users'])
|
||||
->label('scope', 'users.read')
|
||||
|
@ -179,7 +180,7 @@ $utopia->get('/v1/users/:userId')
|
|||
}
|
||||
);
|
||||
|
||||
$utopia->get('/v1/users/:userId/prefs')
|
||||
App::get('/v1/users/:userId/prefs')
|
||||
->desc('Get User Preferences')
|
||||
->groups(['api', 'users'])
|
||||
->label('scope', 'users.read')
|
||||
|
@ -209,7 +210,7 @@ $utopia->get('/v1/users/:userId/prefs')
|
|||
}
|
||||
);
|
||||
|
||||
$utopia->get('/v1/users/:userId/sessions')
|
||||
App::get('/v1/users/:userId/sessions')
|
||||
->desc('Get User Sessions')
|
||||
->groups(['api', 'users'])
|
||||
->label('scope', 'users.read')
|
||||
|
@ -273,7 +274,7 @@ $utopia->get('/v1/users/:userId/sessions')
|
|||
}
|
||||
);
|
||||
|
||||
$utopia->get('/v1/users/:userId/logs')
|
||||
App::get('/v1/users/:userId/logs')
|
||||
->desc('Get User Logs')
|
||||
->groups(['api', 'users'])
|
||||
->label('scope', 'users.read')
|
||||
|
@ -354,7 +355,7 @@ $utopia->get('/v1/users/:userId/logs')
|
|||
}
|
||||
);
|
||||
|
||||
$utopia->patch('/v1/users/:userId/status')
|
||||
App::patch('/v1/users/:userId/status')
|
||||
->desc('Update User Status')
|
||||
->groups(['api', 'users'])
|
||||
->label('scope', 'users.write')
|
||||
|
@ -403,7 +404,7 @@ $utopia->patch('/v1/users/:userId/status')
|
|||
}
|
||||
);
|
||||
|
||||
$utopia->patch('/v1/users/:userId/prefs')
|
||||
App::patch('/v1/users/:userId/prefs')
|
||||
->desc('Update User Preferences')
|
||||
->groups(['api', 'users'])
|
||||
->label('scope', 'users.write')
|
||||
|
@ -446,7 +447,7 @@ $utopia->patch('/v1/users/:userId/prefs')
|
|||
);
|
||||
|
||||
|
||||
$utopia->delete('/v1/users/:userId/sessions/:sessionId')
|
||||
App::delete('/v1/users/:userId/sessions/:sessionId')
|
||||
->desc('Delete User Session')
|
||||
->groups(['api', 'users'])
|
||||
->label('scope', 'users.write')
|
||||
|
@ -479,7 +480,7 @@ $utopia->delete('/v1/users/:userId/sessions/:sessionId')
|
|||
}
|
||||
);
|
||||
|
||||
$utopia->delete('/v1/users/:userId/sessions')
|
||||
App::delete('/v1/users/:userId/sessions')
|
||||
->desc('Delete User Sessions')
|
||||
->groups(['api', 'users'])
|
||||
->label('scope', 'users.write')
|
||||
|
|
|
@ -2,16 +2,17 @@
|
|||
|
||||
global $utopia, $request, $response;
|
||||
|
||||
use Utopia\App;
|
||||
use Utopia\Response;
|
||||
use Utopia\Validator\Numeric;
|
||||
use Utopia\Validator\Text;
|
||||
use Utopia\Validator\ArrayList;
|
||||
use Utopia\Response;
|
||||
use Utopia\Validator\Host;
|
||||
use Appwrite\Storage\Validator\File;
|
||||
|
||||
$result = [];
|
||||
|
||||
$utopia->get('/v1/mock/tests/foo')
|
||||
App::get('/v1/mock/tests/foo')
|
||||
->desc('Mock a get request for SDK tests')
|
||||
->label('scope', 'public')
|
||||
->label('sdk.namespace', 'foo')
|
||||
|
@ -25,7 +26,7 @@ $utopia->get('/v1/mock/tests/foo')
|
|||
}
|
||||
);
|
||||
|
||||
$utopia->post('/v1/mock/tests/foo')
|
||||
App::post('/v1/mock/tests/foo')
|
||||
->desc('Mock a post request for SDK tests')
|
||||
->label('scope', 'public')
|
||||
->label('sdk.namespace', 'foo')
|
||||
|
@ -39,7 +40,7 @@ $utopia->post('/v1/mock/tests/foo')
|
|||
}
|
||||
);
|
||||
|
||||
$utopia->patch('/v1/mock/tests/foo')
|
||||
App::patch('/v1/mock/tests/foo')
|
||||
->desc('Mock a patch request for SDK tests')
|
||||
->label('scope', 'public')
|
||||
->label('sdk.namespace', 'foo')
|
||||
|
@ -53,7 +54,7 @@ $utopia->patch('/v1/mock/tests/foo')
|
|||
}
|
||||
);
|
||||
|
||||
$utopia->put('/v1/mock/tests/foo')
|
||||
App::put('/v1/mock/tests/foo')
|
||||
->desc('Mock a put request for SDK tests')
|
||||
->label('scope', 'public')
|
||||
->label('sdk.namespace', 'foo')
|
||||
|
@ -67,7 +68,7 @@ $utopia->put('/v1/mock/tests/foo')
|
|||
}
|
||||
);
|
||||
|
||||
$utopia->delete('/v1/mock/tests/foo')
|
||||
App::delete('/v1/mock/tests/foo')
|
||||
->desc('Mock a delete request for SDK tests')
|
||||
->label('scope', 'public')
|
||||
->label('sdk.namespace', 'foo')
|
||||
|
@ -81,7 +82,7 @@ $utopia->delete('/v1/mock/tests/foo')
|
|||
}
|
||||
);
|
||||
|
||||
$utopia->get('/v1/mock/tests/bar')
|
||||
App::get('/v1/mock/tests/bar')
|
||||
->desc('Mock a get request for SDK tests')
|
||||
->label('scope', 'public')
|
||||
->label('sdk.namespace', 'bar')
|
||||
|
@ -95,7 +96,7 @@ $utopia->get('/v1/mock/tests/bar')
|
|||
}
|
||||
);
|
||||
|
||||
$utopia->post('/v1/mock/tests/bar')
|
||||
App::post('/v1/mock/tests/bar')
|
||||
->desc('Mock a post request for SDK tests')
|
||||
->label('scope', 'public')
|
||||
->label('sdk.namespace', 'bar')
|
||||
|
@ -109,7 +110,7 @@ $utopia->post('/v1/mock/tests/bar')
|
|||
}
|
||||
);
|
||||
|
||||
$utopia->patch('/v1/mock/tests/bar')
|
||||
App::patch('/v1/mock/tests/bar')
|
||||
->desc('Mock a patch request for SDK tests')
|
||||
->label('scope', 'public')
|
||||
->label('sdk.namespace', 'bar')
|
||||
|
@ -123,7 +124,7 @@ $utopia->patch('/v1/mock/tests/bar')
|
|||
}
|
||||
);
|
||||
|
||||
$utopia->put('/v1/mock/tests/bar')
|
||||
App::put('/v1/mock/tests/bar')
|
||||
->desc('Mock a put request for SDK tests')
|
||||
->label('scope', 'public')
|
||||
->label('sdk.namespace', 'bar')
|
||||
|
@ -137,7 +138,7 @@ $utopia->put('/v1/mock/tests/bar')
|
|||
}
|
||||
);
|
||||
|
||||
$utopia->delete('/v1/mock/tests/bar')
|
||||
App::delete('/v1/mock/tests/bar')
|
||||
->desc('Mock a delete request for SDK tests')
|
||||
->label('scope', 'public')
|
||||
->label('sdk.namespace', 'bar')
|
||||
|
@ -151,7 +152,7 @@ $utopia->delete('/v1/mock/tests/bar')
|
|||
}
|
||||
);
|
||||
|
||||
$utopia->post('/v1/mock/tests/general/upload')
|
||||
App::post('/v1/mock/tests/general/upload')
|
||||
->desc('Mock a post request for SDK tests')
|
||||
->label('scope', 'public')
|
||||
->label('sdk.namespace', 'general')
|
||||
|
@ -189,7 +190,7 @@ $utopia->post('/v1/mock/tests/general/upload')
|
|||
}
|
||||
);
|
||||
|
||||
$utopia->get('/v1/mock/tests/general/redirect')
|
||||
App::get('/v1/mock/tests/general/redirect')
|
||||
->desc('Mock a post request for SDK tests')
|
||||
->label('scope', 'public')
|
||||
->label('sdk.namespace', 'general')
|
||||
|
@ -201,7 +202,7 @@ $utopia->get('/v1/mock/tests/general/redirect')
|
|||
}
|
||||
);
|
||||
|
||||
$utopia->get('/v1/mock/tests/general/redirected')
|
||||
App::get('/v1/mock/tests/general/redirected')
|
||||
->desc('Mock a post request for SDK tests')
|
||||
->label('scope', 'public')
|
||||
->label('sdk.namespace', 'general')
|
||||
|
@ -212,7 +213,7 @@ $utopia->get('/v1/mock/tests/general/redirected')
|
|||
}
|
||||
);
|
||||
|
||||
$utopia->get('/v1/mock/tests/general/set-cookie')
|
||||
App::get('/v1/mock/tests/general/set-cookie')
|
||||
->desc('Mock a cookie request for SDK tests')
|
||||
->label('scope', 'public')
|
||||
->label('sdk.namespace', 'general')
|
||||
|
@ -224,7 +225,7 @@ $utopia->get('/v1/mock/tests/general/set-cookie')
|
|||
}
|
||||
);
|
||||
|
||||
$utopia->get('/v1/mock/tests/general/get-cookie')
|
||||
App::get('/v1/mock/tests/general/get-cookie')
|
||||
->desc('Mock a cookie request for SDK tests')
|
||||
->label('scope', 'public')
|
||||
->label('sdk.namespace', 'general')
|
||||
|
@ -238,7 +239,7 @@ $utopia->get('/v1/mock/tests/general/get-cookie')
|
|||
}
|
||||
);
|
||||
|
||||
$utopia->get('/v1/mock/tests/general/empty')
|
||||
App::get('/v1/mock/tests/general/empty')
|
||||
->desc('Mock a post request for SDK tests')
|
||||
->label('scope', 'public')
|
||||
->label('sdk.namespace', 'general')
|
||||
|
@ -251,7 +252,7 @@ $utopia->get('/v1/mock/tests/general/empty')
|
|||
}
|
||||
);
|
||||
|
||||
$utopia->get('/v1/mock/tests/general/oauth2')
|
||||
App::get('/v1/mock/tests/general/oauth2')
|
||||
->desc('Mock an OAuth2 login route')
|
||||
->label('scope', 'public')
|
||||
->label('docs', false)
|
||||
|
@ -265,7 +266,7 @@ $utopia->get('/v1/mock/tests/general/oauth2')
|
|||
}
|
||||
);
|
||||
|
||||
$utopia->get('/v1/mock/tests/general/oauth2/token')
|
||||
App::get('/v1/mock/tests/general/oauth2/token')
|
||||
->desc('Mock an OAuth2 login route')
|
||||
->label('scope', 'public')
|
||||
->label('docs', false)
|
||||
|
@ -291,7 +292,7 @@ $utopia->get('/v1/mock/tests/general/oauth2/token')
|
|||
}
|
||||
);
|
||||
|
||||
$utopia->get('/v1/mock/tests/general/oauth2/user')
|
||||
App::get('/v1/mock/tests/general/oauth2/user')
|
||||
->desc('Mock an OAuth2 user route')
|
||||
->label('scope', 'public')
|
||||
->label('docs', false)
|
||||
|
@ -310,7 +311,7 @@ $utopia->get('/v1/mock/tests/general/oauth2/user')
|
|||
}
|
||||
);
|
||||
|
||||
$utopia->get('/v1/mock/tests/general/oauth2/success')
|
||||
App::get('/v1/mock/tests/general/oauth2/success')
|
||||
->label('scope', 'public')
|
||||
->label('docs', false)
|
||||
->action(
|
||||
|
@ -321,7 +322,7 @@ $utopia->get('/v1/mock/tests/general/oauth2/success')
|
|||
}
|
||||
);
|
||||
|
||||
$utopia->get('/v1/mock/tests/general/oauth2/failure')
|
||||
App::get('/v1/mock/tests/general/oauth2/failure')
|
||||
->label('scope', 'public')
|
||||
->label('docs', false)
|
||||
->action(
|
||||
|
@ -334,7 +335,7 @@ $utopia->get('/v1/mock/tests/general/oauth2/failure')
|
|||
}
|
||||
);
|
||||
|
||||
$utopia->shutdown(function() use ($response, $request, &$result, $utopia) {
|
||||
App::shutdown(function() use ($response, $request, &$result, $utopia) {
|
||||
$route = $utopia->match($request);
|
||||
$path = APP_STORAGE_CACHE.'/tests.json';
|
||||
$tests = (\file_exists($path)) ? \json_decode(\file_get_contents($path), true) : [];
|
||||
|
|
|
@ -1,12 +1,13 @@
|
|||
<?php
|
||||
|
||||
use Utopia\App;
|
||||
use Utopia\Exception;
|
||||
use Utopia\Abuse\Abuse;
|
||||
use Utopia\Abuse\Adapters\TimeLimit;
|
||||
|
||||
global $utopia, $request, $response, $register, $user, $project;
|
||||
|
||||
$utopia->init(function () use ($utopia, $request, $response, $register, $user, $project) {
|
||||
App::init(function () use ($utopia, $request, $response, $register, $user, $project) {
|
||||
$route = $utopia->match($request);
|
||||
|
||||
if (empty($project->getId()) && $route->getLabel('abuse-limit', 0) > 0) { // Abuse limit requires an active project scope
|
||||
|
@ -43,7 +44,7 @@ $utopia->init(function () use ($utopia, $request, $response, $register, $user, $
|
|||
;
|
||||
}
|
||||
|
||||
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');
|
|
@ -1,11 +1,12 @@
|
|||
<?php
|
||||
|
||||
use Utopia\App;
|
||||
use Utopia\View;
|
||||
use Utopia\Config\Config;
|
||||
|
||||
$layout = new View(__DIR__.'/../../views/layouts/default.phtml');
|
||||
|
||||
$utopia->init(function () use ($utopia, $response, $request, $layout) {
|
||||
App::init(function () use ($utopia, $response, $request, $layout) {
|
||||
|
||||
/* AJAX check */
|
||||
if (!empty($request->getQuery('version', ''))) {
|
||||
|
@ -15,8 +16,8 @@ $utopia->init(function () use ($utopia, $response, $request, $layout) {
|
|||
->setParam('title', APP_NAME)
|
||||
->setParam('protocol', Config::getParam('protocol'))
|
||||
->setParam('domain', Config::getParam('domain'))
|
||||
->setParam('home', $request->getServer('_APP_HOME'))
|
||||
->setParam('setup', $request->getServer('_APP_SETUP'))
|
||||
->setParam('home', App::getEnv('_APP_HOME'))
|
||||
->setParam('setup', App::getEnv('_APP_SETUP'))
|
||||
->setParam('class', 'unknown')
|
||||
->setParam('icon', '/images/favicon.png')
|
||||
->setParam('roles', [
|
||||
|
@ -24,7 +25,7 @@ $utopia->init(function () use ($utopia, $response, $request, $layout) {
|
|||
['type' => 'developer', 'label' => 'Developer'],
|
||||
['type' => 'admin', 'label' => 'Admin'],
|
||||
])
|
||||
->setParam('env', $utopia->getMode())
|
||||
->setParam('env', App::getMode())
|
||||
;
|
||||
|
||||
$time = (60 * 60 * 24 * 45); // 45 days cache
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
global $utopia, $response, $request, $layout, $projectDB;
|
||||
|
||||
use Utopia\App;
|
||||
use Utopia\View;
|
||||
use Utopia\Config\Config;
|
||||
use Utopia\Domains\Domain;
|
||||
|
@ -10,19 +11,19 @@ use Appwrite\Database\Validator\Authorization;
|
|||
use Appwrite\Database\Validator\UID;
|
||||
use Appwrite\Storage\Storage;
|
||||
|
||||
$utopia->init(function () use ($layout) {
|
||||
App::init(function () use ($layout) {
|
||||
$layout
|
||||
->setParam('description', 'Appwrite Console allows you to easily manage, monitor, and control your entire backend API and tools.')
|
||||
->setParam('analytics', 'UA-26264668-5')
|
||||
;
|
||||
}, 'console');
|
||||
|
||||
$utopia->shutdown(function () use ($response, $request, $layout) {
|
||||
App::shutdown(function () use ($response, $layout) {
|
||||
$header = new View(__DIR__.'/../../views/console/comps/header.phtml');
|
||||
$footer = new View(__DIR__.'/../../views/console/comps/footer.phtml');
|
||||
|
||||
$footer
|
||||
->setParam('home', $request->getServer('_APP_HOME', ''))
|
||||
->setParam('home', App::getEnv('_APP_HOME', ''))
|
||||
->setParam('version', Config::getParam('version'))
|
||||
;
|
||||
|
||||
|
@ -34,7 +35,7 @@ $utopia->shutdown(function () use ($response, $request, $layout) {
|
|||
$response->send($layout->render());
|
||||
}, 'console');
|
||||
|
||||
$utopia->get('/error/:code')
|
||||
App::get('/error/:code')
|
||||
->groups(['web', 'console'])
|
||||
->label('permission', 'public')
|
||||
->label('scope', 'home')
|
||||
|
@ -51,15 +52,15 @@ $utopia->get('/error/:code')
|
|||
->setParam('body', $page);
|
||||
});
|
||||
|
||||
$utopia->get('/console')
|
||||
App::get('/console')
|
||||
->groups(['web', 'console'])
|
||||
->label('permission', 'public')
|
||||
->label('scope', 'console')
|
||||
->action(function () use ($layout, $request) {
|
||||
->action(function () use ($layout) {
|
||||
$page = new View(__DIR__.'/../../views/console/index.phtml');
|
||||
|
||||
$page
|
||||
->setParam('home', $request->getServer('_APP_HOME', ''))
|
||||
->setParam('home', App::getEnv('_APP_HOME', ''))
|
||||
;
|
||||
|
||||
$layout
|
||||
|
@ -67,7 +68,7 @@ $utopia->get('/console')
|
|||
->setParam('body', $page);
|
||||
});
|
||||
|
||||
$utopia->get('/console/account')
|
||||
App::get('/console/account')
|
||||
->groups(['web', 'console'])
|
||||
->label('permission', 'public')
|
||||
->label('scope', 'console')
|
||||
|
@ -85,7 +86,7 @@ $utopia->get('/console/account')
|
|||
->setParam('body', $page);
|
||||
});
|
||||
|
||||
$utopia->get('/console/notifications')
|
||||
App::get('/console/notifications')
|
||||
->groups(['web', 'console'])
|
||||
->label('permission', 'public')
|
||||
->label('scope', 'console')
|
||||
|
@ -97,7 +98,7 @@ $utopia->get('/console/notifications')
|
|||
->setParam('body', $page);
|
||||
});
|
||||
|
||||
$utopia->get('/console/home')
|
||||
App::get('/console/home')
|
||||
->groups(['web', 'console'])
|
||||
->label('permission', 'public')
|
||||
->label('scope', 'console')
|
||||
|
@ -109,12 +110,12 @@ $utopia->get('/console/home')
|
|||
->setParam('body', $page);
|
||||
});
|
||||
|
||||
$utopia->get('/console/settings')
|
||||
App::get('/console/settings')
|
||||
->groups(['web', 'console'])
|
||||
->label('permission', 'public')
|
||||
->label('scope', 'console')
|
||||
->action(function () use ($request, $layout) {
|
||||
$target = new Domain($request->getServer('_APP_DOMAIN_TARGET', ''));
|
||||
->action(function () use ($layout) {
|
||||
$target = new Domain(App::getEnv('_APP_DOMAIN_TARGET', ''));
|
||||
|
||||
$page = new View(__DIR__.'/../../views/console/settings/index.phtml');
|
||||
|
||||
|
@ -128,7 +129,7 @@ $utopia->get('/console/settings')
|
|||
->setParam('body', $page);
|
||||
});
|
||||
|
||||
$utopia->get('/console/webhooks')
|
||||
App::get('/console/webhooks')
|
||||
->groups(['web', 'console'])
|
||||
->label('permission', 'public')
|
||||
->label('scope', 'console')
|
||||
|
@ -144,7 +145,7 @@ $utopia->get('/console/webhooks')
|
|||
->setParam('body', $page);
|
||||
});
|
||||
|
||||
$utopia->get('/console/keys')
|
||||
App::get('/console/keys')
|
||||
->groups(['web', 'console'])
|
||||
->label('permission', 'public')
|
||||
->label('scope', 'console')
|
||||
|
@ -159,7 +160,7 @@ $utopia->get('/console/keys')
|
|||
->setParam('body', $page);
|
||||
});
|
||||
|
||||
$utopia->get('/console/tasks')
|
||||
App::get('/console/tasks')
|
||||
->groups(['web', 'console'])
|
||||
->label('permission', 'public')
|
||||
->label('scope', 'console')
|
||||
|
@ -171,7 +172,7 @@ $utopia->get('/console/tasks')
|
|||
->setParam('body', $page);
|
||||
});
|
||||
|
||||
$utopia->get('/console/database')
|
||||
App::get('/console/database')
|
||||
->groups(['web', 'console'])
|
||||
->label('permission', 'public')
|
||||
->label('scope', 'console')
|
||||
|
@ -183,7 +184,7 @@ $utopia->get('/console/database')
|
|||
->setParam('body', $page);
|
||||
});
|
||||
|
||||
$utopia->get('/console/database/collection')
|
||||
App::get('/console/database/collection')
|
||||
->groups(['web', 'console'])
|
||||
->label('permission', 'public')
|
||||
->label('scope', 'console')
|
||||
|
@ -215,7 +216,7 @@ $utopia->get('/console/database/collection')
|
|||
;
|
||||
});
|
||||
|
||||
$utopia->get('/console/database/document')
|
||||
App::get('/console/database/document')
|
||||
->groups(['web', 'console'])
|
||||
->label('permission', 'public')
|
||||
->label('scope', 'console')
|
||||
|
@ -245,7 +246,7 @@ $utopia->get('/console/database/document')
|
|||
->setParam('body', $page);
|
||||
});
|
||||
|
||||
$utopia->get('/console/storage')
|
||||
App::get('/console/storage')
|
||||
->groups(['web', 'console'])
|
||||
->label('permission', 'public')
|
||||
->label('scope', 'console')
|
||||
|
@ -253,9 +254,9 @@ $utopia->get('/console/storage')
|
|||
$page = new View(__DIR__.'/../../views/console/storage/index.phtml');
|
||||
|
||||
$page
|
||||
->setParam('home', $request->getServer('_APP_HOME', 0))
|
||||
->setParam('fileLimit', $request->getServer('_APP_STORAGE_LIMIT', 0))
|
||||
->setParam('fileLimitHuman', Storage::human($request->getServer('_APP_STORAGE_LIMIT', 0)))
|
||||
->setParam('home', App::getEnv('_APP_HOME', 0))
|
||||
->setParam('fileLimit', App::getEnv('_APP_STORAGE_LIMIT', 0))
|
||||
->setParam('fileLimitHuman', Storage::human(App::getEnv('_APP_STORAGE_LIMIT', 0)))
|
||||
;
|
||||
|
||||
$layout
|
||||
|
@ -263,7 +264,7 @@ $utopia->get('/console/storage')
|
|||
->setParam('body', $page);
|
||||
});
|
||||
|
||||
$utopia->get('/console/users')
|
||||
App::get('/console/users')
|
||||
->groups(['web', 'console'])
|
||||
->label('permission', 'public')
|
||||
->label('scope', 'console')
|
||||
|
@ -277,7 +278,7 @@ $utopia->get('/console/users')
|
|||
->setParam('body', $page);
|
||||
});
|
||||
|
||||
$utopia->get('/console/users/user')
|
||||
App::get('/console/users/user')
|
||||
->groups(['web', 'console'])
|
||||
->label('permission', 'public')
|
||||
->label('scope', 'console')
|
||||
|
@ -289,7 +290,7 @@ $utopia->get('/console/users/user')
|
|||
->setParam('body', $page);
|
||||
});
|
||||
|
||||
$utopia->get('/console/users/teams/team')
|
||||
App::get('/console/users/teams/team')
|
||||
->groups(['web', 'console'])
|
||||
->label('permission', 'public')
|
||||
->label('scope', 'console')
|
||||
|
|
|
@ -2,12 +2,13 @@
|
|||
|
||||
global $utopia, $response, $request, $layout;
|
||||
|
||||
use Utopia\App;
|
||||
use Utopia\View;
|
||||
use Utopia\Config\Config;
|
||||
use Utopia\Validator\WhiteList;
|
||||
use Utopia\Validator\Range;
|
||||
|
||||
$utopia->init(function () use ($layout) {
|
||||
App::init(function () use ($layout) {
|
||||
$header = new View(__DIR__.'/../../views/home/comps/header.phtml');
|
||||
$footer = new View(__DIR__.'/../../views/home/comps/footer.phtml');
|
||||
|
||||
|
@ -25,11 +26,11 @@ $utopia->init(function () use ($layout) {
|
|||
;
|
||||
}, 'home');
|
||||
|
||||
$utopia->shutdown(function () use ($response, $layout) {
|
||||
App::shutdown(function () use ($response, $layout) {
|
||||
$response->send($layout->render());
|
||||
}, 'home');
|
||||
|
||||
$utopia->get('/')
|
||||
App::get('/')
|
||||
->groups(['web', 'home'])
|
||||
->label('permission', 'public')
|
||||
->label('scope', 'home')
|
||||
|
@ -39,7 +40,7 @@ $utopia->get('/')
|
|||
}
|
||||
);
|
||||
|
||||
$utopia->get('/auth/signin')
|
||||
App::get('/auth/signin')
|
||||
->groups(['web', 'home'])
|
||||
->label('permission', 'public')
|
||||
->label('scope', 'home')
|
||||
|
@ -51,7 +52,7 @@ $utopia->get('/auth/signin')
|
|||
->setParam('body', $page);
|
||||
});
|
||||
|
||||
$utopia->get('/auth/signup')
|
||||
App::get('/auth/signup')
|
||||
->groups(['web', 'home'])
|
||||
->label('permission', 'public')
|
||||
->label('scope', 'home')
|
||||
|
@ -63,7 +64,7 @@ $utopia->get('/auth/signup')
|
|||
->setParam('body', $page);
|
||||
});
|
||||
|
||||
$utopia->get('/auth/recovery')
|
||||
App::get('/auth/recovery')
|
||||
->groups(['web', 'home'])
|
||||
->label('permission', 'public')
|
||||
->label('scope', 'home')
|
||||
|
@ -75,7 +76,7 @@ $utopia->get('/auth/recovery')
|
|||
->setParam('body', $page);
|
||||
});
|
||||
|
||||
$utopia->get('/auth/confirm')
|
||||
App::get('/auth/confirm')
|
||||
->groups(['web', 'home'])
|
||||
->label('permission', 'public')
|
||||
->label('scope', 'home')
|
||||
|
@ -87,7 +88,7 @@ $utopia->get('/auth/confirm')
|
|||
->setParam('body', $page);
|
||||
});
|
||||
|
||||
$utopia->get('/auth/join')
|
||||
App::get('/auth/join')
|
||||
->groups(['web', 'home'])
|
||||
->label('permission', 'public')
|
||||
->label('scope', 'home')
|
||||
|
@ -99,7 +100,7 @@ $utopia->get('/auth/join')
|
|||
->setParam('body', $page);
|
||||
});
|
||||
|
||||
$utopia->get('/auth/recovery/reset')
|
||||
App::get('/auth/recovery/reset')
|
||||
->groups(['web', 'home'])
|
||||
->label('permission', 'public')
|
||||
->label('scope', 'home')
|
||||
|
@ -112,7 +113,7 @@ $utopia->get('/auth/recovery/reset')
|
|||
});
|
||||
|
||||
|
||||
$utopia->get('/auth/oauth2/success')
|
||||
App::get('/auth/oauth2/success')
|
||||
->groups(['web', 'home'])
|
||||
->label('permission', 'public')
|
||||
->label('scope', 'home')
|
||||
|
@ -127,7 +128,7 @@ $utopia->get('/auth/oauth2/success')
|
|||
;
|
||||
});
|
||||
|
||||
$utopia->get('/auth/oauth2/failure')
|
||||
App::get('/auth/oauth2/failure')
|
||||
->groups(['web', 'home'])
|
||||
->label('permission', 'public')
|
||||
->label('scope', 'home')
|
||||
|
@ -142,7 +143,7 @@ $utopia->get('/auth/oauth2/failure')
|
|||
;
|
||||
});
|
||||
|
||||
$utopia->get('/error/:code')
|
||||
App::get('/error/:code')
|
||||
->groups(['web', 'home'])
|
||||
->label('permission', 'public')
|
||||
->label('scope', 'home')
|
||||
|
@ -159,7 +160,7 @@ $utopia->get('/error/:code')
|
|||
->setParam('body', $page);
|
||||
});
|
||||
|
||||
$utopia->get('/open-api-2.json')
|
||||
App::get('/open-api-2.json')
|
||||
->groups(['web', 'home'])
|
||||
->label('scope', 'public')
|
||||
->label('docs', false)
|
||||
|
@ -167,7 +168,7 @@ $utopia->get('/open-api-2.json')
|
|||
->param('extensions', 0, function () {return new Range(0, 1);}, 'Show extra data.', true)
|
||||
->param('tests', 0, function () {return new Range(0, 1);}, 'Include only test services.', true)
|
||||
->action(
|
||||
function ($platform, $extensions, $tests) use ($response, $request, $utopia) {
|
||||
function ($platform, $extensions, $tests) use ($response, $utopia) {
|
||||
$services = Config::getParam('services', []);
|
||||
|
||||
function fromCamelCase($input)
|
||||
|
@ -292,14 +293,14 @@ $utopia->get('/open-api-2.json')
|
|||
'contact' => [
|
||||
'name' => 'Appwrite Team',
|
||||
'url' => 'https://appwrite.io/support',
|
||||
'email' => $request->getServer('_APP_SYSTEM_EMAIL_ADDRESS', APP_EMAIL_TEAM),
|
||||
'email' => App::getEnv('_APP_SYSTEM_EMAIL_ADDRESS', APP_EMAIL_TEAM),
|
||||
],
|
||||
'license' => [
|
||||
'name' => 'BSD-3-Clause',
|
||||
'url' => 'https://raw.githubusercontent.com/appwrite/appwrite/master/LICENSE',
|
||||
],
|
||||
],
|
||||
'host' => \parse_url($request->getServer('_APP_HOME', Config::getParam('domain')), PHP_URL_HOST),
|
||||
'host' => \parse_url(App::getEnv('_APP_HOME', Config::getParam('domain')), PHP_URL_HOST),
|
||||
'basePath' => '/v1',
|
||||
'schemes' => ['https'],
|
||||
'consumes' => ['application/json', 'multipart/form-data'],
|
||||
|
|
191
app/init.php
191
app/init.php
|
@ -12,17 +12,13 @@ if (\file_exists(__DIR__.'/../vendor/autoload.php')) {
|
|||
}
|
||||
|
||||
use Utopia\App;
|
||||
use Utopia\Request;
|
||||
use Utopia\Config\Config;
|
||||
use Utopia\Locale\Locale;
|
||||
use Utopia\Registry\Registry;
|
||||
use Appwrite\Auth\Auth;
|
||||
use Appwrite\Database\Database;
|
||||
use Appwrite\Database\Document;
|
||||
use Appwrite\Database\Validator\Authorization;
|
||||
use Appwrite\Database\Adapter\MySQL as MySQLAdapter;
|
||||
use Appwrite\Database\Adapter\Redis as RedisAdapter;
|
||||
use Appwrite\Utopia\Response;
|
||||
use Appwrite\Event\Event;
|
||||
use PHPMailer\PHPMailer\PHPMailer;
|
||||
|
||||
$locale = 'en';
|
||||
|
@ -52,7 +48,9 @@ const APP_SOCIAL_GITHUB = 'https://github.com/appwrite';
|
|||
const APP_SOCIAL_DISCORD = 'https://discord.gg/GSeTUeA';
|
||||
const APP_SOCIAL_DEV = 'https://dev.to/appwrite';
|
||||
|
||||
$utopia->setMode($utopia->getEnv('_APP_ENV', App::MODE_TYPE_PRODUCTION));
|
||||
$register = new Registry();
|
||||
|
||||
App::setMode(App::getEnv('_APP_ENV', App::MODE_TYPE_PRODUCTION));
|
||||
|
||||
/*
|
||||
* ENV vars
|
||||
|
@ -64,37 +62,21 @@ Config::load('locales', __DIR__.'/../app/config/locales.php');
|
|||
Config::load('collections', __DIR__.'/../app/config/collections.php');
|
||||
Config::load('roles', __DIR__.'/../app/config/roles.php'); // User roles and scopes
|
||||
Config::load('services', __DIR__.'/../app/config/services.php'); // List of services
|
||||
Config::load('avatar-browsers', __DIR__.'/../app/config/avatars/browsers.php');
|
||||
Config::load('avatar-credit-cards', __DIR__.'/../app/config/avatars/credit-cards.php');
|
||||
Config::load('avatar-flags', __DIR__.'/../app/config/avatars/flags.php');
|
||||
|
||||
Config::setParam('env', $utopia->getMode());
|
||||
Config::setParam('domain', $utopia->getEnv('HTTP_HOST', ''));
|
||||
Config::setParam('domainVerification', false);
|
||||
Config::setParam('version', $utopia->getEnv('_APP_VERSION', 'UNKNOWN'));
|
||||
Config::setParam('protocol', $utopia->getEnv('HTTP_X_FORWARDED_PROTO', $utopia->getEnv('REQUEST_SCHEME', 'https')));
|
||||
Config::setParam('port', (string) \parse_url(Config::getParam('protocol').'://'.$utopia->getEnv('HTTP_HOST', ''), PHP_URL_PORT));
|
||||
Config::setParam('hostname', \parse_url(Config::getParam('protocol').'://'.$utopia->getEnv('HTTP_HOST', null), PHP_URL_HOST));
|
||||
|
||||
Resque::setBackend($utopia->getEnv('_APP_REDIS_HOST', '')
|
||||
.':'.$utopia->getEnv('_APP_REDIS_PORT', ''));
|
||||
|
||||
\define('COOKIE_DOMAIN',
|
||||
(
|
||||
$utopia->getEnv('HTTP_HOST', null) === 'localhost' ||
|
||||
$utopia->getEnv('HTTP_HOST', null) === 'localhost:'.Config::getParam('port') ||
|
||||
(\filter_var(Config::getParam('hostname'), FILTER_VALIDATE_IP) !== false)
|
||||
)
|
||||
? null
|
||||
: '.'.Config::getParam('hostname')
|
||||
);
|
||||
\define('COOKIE_SAMESITE', Response::COOKIE_SAMESITE_NONE);
|
||||
Resque::setBackend(App::getEnv('_APP_REDIS_HOST', '')
|
||||
.':'.App::getEnv('_APP_REDIS_PORT', ''));
|
||||
|
||||
/*
|
||||
* Registry
|
||||
*/
|
||||
$register->set('db', function () use ($utopia) { // Register DB connection
|
||||
$dbHost = $utopia->getEnv('_APP_DB_HOST', '');
|
||||
$dbUser = $utopia->getEnv('_APP_DB_USER', '');
|
||||
$dbPass = $utopia->getEnv('_APP_DB_PASS', '');
|
||||
$dbScheme = $utopia->getEnv('_APP_DB_SCHEMA', '');
|
||||
$register->set('db', function () { // Register DB connection
|
||||
$dbHost = App::getEnv('_APP_DB_HOST', '');
|
||||
$dbUser = App::getEnv('_APP_DB_USER', '');
|
||||
$dbPass = App::getEnv('_APP_DB_PASS', '');
|
||||
$dbScheme = App::getEnv('_APP_DB_SCHEMA', '');
|
||||
|
||||
$pdo = new PDO("mysql:host={$dbHost};dbname={$dbScheme};charset=utf8mb4", $dbUser, $dbPass, array(
|
||||
PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8mb4',
|
||||
|
@ -107,9 +89,9 @@ $register->set('db', function () use ($utopia) { // Register DB connection
|
|||
|
||||
return $pdo;
|
||||
});
|
||||
$register->set('influxdb', function () use ($utopia) { // Register DB connection
|
||||
$host = $utopia->getEnv('_APP_INFLUXDB_HOST', '');
|
||||
$port = $utopia->getEnv('_APP_INFLUXDB_PORT', '');
|
||||
$register->set('influxdb', function () { // Register DB connection
|
||||
$host = App::getEnv('_APP_INFLUXDB_HOST', '');
|
||||
$port = App::getEnv('_APP_INFLUXDB_PORT', '');
|
||||
|
||||
if (empty($host) || empty($port)) {
|
||||
return;
|
||||
|
@ -119,43 +101,43 @@ $register->set('influxdb', function () use ($utopia) { // Register DB connection
|
|||
|
||||
return $client;
|
||||
});
|
||||
$register->set('statsd', function () use ($utopia) { // Register DB connection
|
||||
$host = $utopia->getEnv('_APP_STATSD_HOST', 'telegraf');
|
||||
$port = $utopia->getEnv('_APP_STATSD_PORT', 8125);
|
||||
$register->set('statsd', function () { // Register DB connection
|
||||
$host = App::getEnv('_APP_STATSD_HOST', 'telegraf');
|
||||
$port = App::getEnv('_APP_STATSD_PORT', 8125);
|
||||
|
||||
$connection = new \Domnikl\Statsd\Connection\UdpSocket($host, $port);
|
||||
$statsd = new \Domnikl\Statsd\Client($connection);
|
||||
|
||||
return $statsd;
|
||||
});
|
||||
$register->set('cache', function () use ($utopia) { // Register cache connection
|
||||
$register->set('cache', function () { // Register cache connection
|
||||
$redis = new Redis();
|
||||
|
||||
$redis->connect($utopia->getEnv('_APP_REDIS_HOST', ''),
|
||||
$utopia->getEnv('_APP_REDIS_PORT', ''));
|
||||
$redis->connect(App::getEnv('_APP_REDIS_HOST', ''),
|
||||
App::getEnv('_APP_REDIS_PORT', ''));
|
||||
|
||||
return $redis;
|
||||
});
|
||||
$register->set('smtp', function () use ($utopia) {
|
||||
$register->set('smtp', function () {
|
||||
$mail = new PHPMailer(true);
|
||||
|
||||
$mail->isSMTP();
|
||||
|
||||
$username = $utopia->getEnv('_APP_SMTP_USERNAME', null);
|
||||
$password = $utopia->getEnv('_APP_SMTP_PASSWORD', null);
|
||||
$username = App::getEnv('_APP_SMTP_USERNAME', null);
|
||||
$password = App::getEnv('_APP_SMTP_PASSWORD', null);
|
||||
|
||||
$mail->XMailer = 'Appwrite Mailer';
|
||||
$mail->Host = $utopia->getEnv('_APP_SMTP_HOST', 'smtp');
|
||||
$mail->Port = $utopia->getEnv('_APP_SMTP_PORT', 25);
|
||||
$mail->Host = App::getEnv('_APP_SMTP_HOST', 'smtp');
|
||||
$mail->Port = App::getEnv('_APP_SMTP_PORT', 25);
|
||||
$mail->SMTPAuth = (!empty($username) && !empty($password));
|
||||
$mail->Username = $username;
|
||||
$mail->Password = $password;
|
||||
$mail->SMTPSecure = $utopia->getEnv('_APP_SMTP_SECURE', false);
|
||||
$mail->SMTPSecure = App::getEnv('_APP_SMTP_SECURE', false);
|
||||
$mail->SMTPAutoTLS = false;
|
||||
$mail->CharSet = 'UTF-8';
|
||||
|
||||
$from = \urldecode($utopia->getEnv('_APP_SYSTEM_EMAIL_NAME', APP_NAME.' Server'));
|
||||
$email = $utopia->getEnv('_APP_SYSTEM_EMAIL_ADDRESS', APP_EMAIL_TEAM);
|
||||
$from = \urldecode(App::getEnv('_APP_SYSTEM_EMAIL_NAME', APP_NAME.' Server'));
|
||||
$email = App::getEnv('_APP_SYSTEM_EMAIL_ADDRESS', APP_EMAIL_TEAM);
|
||||
|
||||
$mail->setFrom($email, $from);
|
||||
$mail->addReplyTo($email, $from);
|
||||
|
@ -164,14 +146,26 @@ $register->set('smtp', function () use ($utopia) {
|
|||
|
||||
return $mail;
|
||||
});
|
||||
$register->set('queue-webhooks', function () {
|
||||
return new Event('v1-webhooks', 'WebhooksV1');
|
||||
});
|
||||
$register->set('queue-audits', function () {
|
||||
return new Event('v1-audits', 'AuditsV1');
|
||||
});
|
||||
$register->set('queue-usage', function () {
|
||||
return new Event('v1-usage', 'UsageV1');
|
||||
});
|
||||
$register->set('queue-mails', function () {
|
||||
return new Event('v1-mails', 'MailsV1');
|
||||
});
|
||||
$register->set('queue-deletes', function () {
|
||||
return new Event('v1-deletes', 'DeletesV1');
|
||||
});
|
||||
|
||||
/*
|
||||
* Localization
|
||||
*/
|
||||
// $locale = $request->getParam('locale', $request->getHeader('X-Appwrite-Locale', ''));
|
||||
|
||||
Locale::$exceptions = false;
|
||||
|
||||
Locale::setLanguage('af', include __DIR__.'/config/locales/af.php');
|
||||
Locale::setLanguage('ar', include __DIR__.'/config/locales/ar.php');
|
||||
Locale::setLanguage('bn', include __DIR__.'/config/locales/bn.php');
|
||||
|
@ -221,98 +215,21 @@ Locale::setLanguage('zh-tw', include __DIR__.'/config/locales/zh-tw.php');
|
|||
|
||||
Locale::setDefault('en');
|
||||
|
||||
if (\in_array($locale, Config::getParam('locales'))) {
|
||||
Locale::setDefault($locale);
|
||||
}
|
||||
|
||||
\stream_context_set_default([ // Set global user agent and http settings
|
||||
'http' => [
|
||||
'method' => 'GET',
|
||||
'user_agent' => \sprintf(APP_USERAGENT,
|
||||
Config::getParam('version'),
|
||||
$utopia->getEnv('_APP_SYSTEM_SECURITY_EMAIL_ADDRESS', APP_EMAIL_SECURITY)),
|
||||
App::getEnv('_APP_SYSTEM_SECURITY_EMAIL_ADDRESS', APP_EMAIL_SECURITY)),
|
||||
'timeout' => 2,
|
||||
],
|
||||
]);
|
||||
|
||||
// /*
|
||||
// * Auth & Project Scope
|
||||
// */
|
||||
// $consoleDB = new Database();
|
||||
// $consoleDB->setAdapter(new RedisAdapter(new MySQLAdapter($register), $register));
|
||||
// $consoleDB->setNamespace('app_console'); // Should be replaced with param if we want to have parent projects
|
||||
/*
|
||||
* Auth & Project Scope
|
||||
*/
|
||||
$consoleDB = new Database();
|
||||
$consoleDB->setAdapter(new RedisAdapter(new MySQLAdapter($register), $register));
|
||||
$consoleDB->setNamespace('app_console'); // Should be replaced with param if we want to have parent projects
|
||||
|
||||
// $consoleDB->setMocks(Config::getParam('collections', []));
|
||||
// Authorization::disable();
|
||||
|
||||
// $project = $consoleDB->getDocument($request->getParam('project', $request->getHeader('X-Appwrite-Project', '')));
|
||||
|
||||
// Authorization::enable();
|
||||
|
||||
// $console = $consoleDB->getDocument('console');
|
||||
|
||||
// $mode = $request->getParam('mode', $request->getHeader('X-Appwrite-Mode', 'default'));
|
||||
|
||||
// Auth::setCookieName('a_session_'.$project->getId());
|
||||
|
||||
// if (APP_MODE_ADMIN === $mode) {
|
||||
// Auth::setCookieName('a_session_'.$console->getId());
|
||||
// }
|
||||
|
||||
// $session = Auth::decodeSession(
|
||||
// $request->getCookie(Auth::$cookieName, // Get sessions
|
||||
// $request->getCookie(Auth::$cookieName.'_legacy', // Get fallback session from old clients (no SameSite support)
|
||||
// $request->getHeader('X-Appwrite-Key', '')))); // Get API Key
|
||||
|
||||
// // Get fallback session from clients who block 3rd-party cookies
|
||||
// $response->addHeader('X-Debug-Fallback', 'false');
|
||||
|
||||
// if(empty($session['id']) && empty($session['secret'])) {
|
||||
// $response->addHeader('X-Debug-Fallback', 'true');
|
||||
// $fallback = $request->getHeader('X-Fallback-Cookies', '');
|
||||
// $fallback = \json_decode($fallback, true);
|
||||
// $session = Auth::decodeSession(((isset($fallback[Auth::$cookieName])) ? $fallback[Auth::$cookieName] : ''));
|
||||
// }
|
||||
|
||||
// Auth::$unique = $session['id'];
|
||||
// Auth::$secret = $session['secret'];
|
||||
|
||||
// $projectDB = new Database();
|
||||
// $projectDB->setAdapter(new RedisAdapter(new MySQLAdapter($register), $register));
|
||||
// $projectDB->setNamespace('app_'.$project->getId());
|
||||
// $projectDB->setMocks(Config::getParam('collections', []));
|
||||
|
||||
// if (APP_MODE_ADMIN !== $mode) {
|
||||
// $user = $projectDB->getDocument(Auth::$unique);
|
||||
// }
|
||||
// else {
|
||||
// $user = $consoleDB->getDocument(Auth::$unique);
|
||||
|
||||
// $user
|
||||
// ->setAttribute('$id', 'admin-'.$user->getAttribute('$id'))
|
||||
// ;
|
||||
// }
|
||||
|
||||
// if (empty($user->getId()) // Check a document has been found in the DB
|
||||
// || Database::SYSTEM_COLLECTION_USERS !== $user->getCollection() // Validate returned document is really a user document
|
||||
// || !Auth::tokenVerify($user->getAttribute('tokens', []), Auth::TOKEN_TYPE_LOGIN, Auth::$secret)) { // Validate user has valid login token
|
||||
// $user = new Document(['$id' => '', '$collection' => Database::SYSTEM_COLLECTION_USERS]);
|
||||
// }
|
||||
|
||||
// if (APP_MODE_ADMIN === $mode) {
|
||||
// if (!empty($user->search('teamId', $project->getAttribute('teamId'), $user->getAttribute('memberships')))) {
|
||||
// Authorization::disable();
|
||||
// } else {
|
||||
// $user = new Document(['$id' => '', '$collection' => Database::SYSTEM_COLLECTION_USERS]);
|
||||
// }
|
||||
// }
|
||||
|
||||
// // Set project mail
|
||||
// $register->get('smtp')
|
||||
// ->setFrom(
|
||||
// $utopia->getEnv('_APP_SYSTEM_EMAIL_ADDRESS', APP_EMAIL_TEAM),
|
||||
// ($project->getId() === 'console')
|
||||
// ? \urldecode($utopia->getEnv('_APP_SYSTEM_EMAIL_NAME', APP_NAME.' Server'))
|
||||
// : \sprintf(Locale::getText('account.emails.team'), $project->getAttribute('name')
|
||||
// )
|
||||
// );
|
||||
$consoleDB->setMocks(Config::getParam('collections', []));
|
||||
|
|
|
@ -3,11 +3,10 @@
|
|||
|
||||
require_once __DIR__.'/../init.php';
|
||||
|
||||
global $request;
|
||||
|
||||
use Appwrite\ClamAV\Network;
|
||||
use Appwrite\Storage\Device\Local;
|
||||
use Appwrite\Storage\Storage;
|
||||
use Utopia\App;
|
||||
use Utopia\CLI\CLI;
|
||||
use Utopia\CLI\Console;
|
||||
use Utopia\Domains\Domain;
|
||||
|
@ -17,8 +16,8 @@ $cli = new CLI();
|
|||
$cli
|
||||
->task('ssl')
|
||||
->desc('Validate server certificates')
|
||||
->action(function () use ($request) {
|
||||
$domain = $request->getServer('_APP_DOMAIN', '');
|
||||
->action(function () {
|
||||
$domain = App::getEnv('_APP_DOMAIN', '');
|
||||
|
||||
Console::log('Issue a TLS certificate for master domain ('.$domain.')');
|
||||
|
||||
|
@ -33,17 +32,17 @@ $cli
|
|||
$cli
|
||||
->task('doctor')
|
||||
->desc('Validate server health')
|
||||
->action(function () use ($request, $register) {
|
||||
->action(function () use ($register) {
|
||||
Console::log(" __ ____ ____ _ _ ____ __ ____ ____ __ __
|
||||
/ _\ ( _ \( _ \/ )( \( _ \( )(_ _)( __) ( )/ \
|
||||
/ \ ) __/ ) __/\ /\ / ) / )( )( ) _) _ )(( O )
|
||||
\_/\_/(__) (__) (_/\_)(__\_)(__) (__) (____)(_)(__)\__/ ");
|
||||
|
||||
Console::log("\n".'👩⚕️ Running '.APP_NAME.' Doctor for version '.$request->getServer('_APP_VERSION', 'UNKNOWN').' ...'."\n");
|
||||
Console::log("\n".'👩⚕️ Running '.APP_NAME.' Doctor for version '.App::getEnv('_APP_VERSION', 'UNKNOWN').' ...'."\n");
|
||||
|
||||
Console::log('Checking for production best practices...');
|
||||
|
||||
$domain = new Domain($request->getServer('_APP_DOMAIN'));
|
||||
$domain = new Domain(App::getEnv('_APP_DOMAIN'));
|
||||
|
||||
if(!$domain->isKnown() || $domain->isTest()) {
|
||||
Console::log('🔴 Hostname has a public suffix');
|
||||
|
@ -52,7 +51,7 @@ $cli
|
|||
Console::log('🟢 Hostname has a public suffix');
|
||||
}
|
||||
|
||||
$domain = new Domain($request->getServer('_APP_DOMAIN_TARGET'));
|
||||
$domain = new Domain(App::getEnv('_APP_DOMAIN_TARGET'));
|
||||
|
||||
if(!$domain->isKnown() || $domain->isTest()) {
|
||||
Console::log('🔴 CNAME target has a public suffix');
|
||||
|
@ -61,30 +60,30 @@ $cli
|
|||
Console::log('🟢 CNAME target has a public suffix');
|
||||
}
|
||||
|
||||
if($request->getServer('_APP_OPENSSL_KEY_V1', 'your-secret-key') === 'your-secret-key') {
|
||||
if(App::getEnv('_APP_OPENSSL_KEY_V1', 'your-secret-key') === 'your-secret-key') {
|
||||
Console::log('🔴 Using a unique secret key for encryption');
|
||||
}
|
||||
else {
|
||||
Console::log('🟢 Using a unique secret key for encryption');
|
||||
}
|
||||
|
||||
if($request->getServer('_APP_ENV', 'development') === 'development') {
|
||||
if(App::getEnv('_APP_ENV', 'development') === 'development') {
|
||||
Console::log('🔴 App enviornment is set for production');
|
||||
}
|
||||
else {
|
||||
Console::log('🟢 App enviornment is set for production');
|
||||
}
|
||||
|
||||
if($request->getServer('_APP_OPTIONS_ABUSE', 'disabled') === 'disabled') {
|
||||
if(App::getEnv('_APP_OPTIONS_ABUSE', 'disabled') === 'disabled') {
|
||||
Console::log('🔴 Abuse protection is enabled');
|
||||
}
|
||||
else {
|
||||
Console::log('🟢 Abuse protection is enabled');
|
||||
}
|
||||
|
||||
$authWhitelistEmails = $request->getServer('_APP_CONSOLE_WHITELIST_EMAILS', null);
|
||||
$authWhitelistIPs = $request->getServer('_APP_CONSOLE_WHITELIST_IPS', null);
|
||||
$authWhitelistDomains = $request->getServer('_APP_CONSOLE_WHITELIST_DOMAINS', null);
|
||||
$authWhitelistEmails = App::getEnv('_APP_CONSOLE_WHITELIST_EMAILS', null);
|
||||
$authWhitelistIPs = App::getEnv('_APP_CONSOLE_WHITELIST_IPS', null);
|
||||
$authWhitelistDomains = App::getEnv('_APP_CONSOLE_WHITELIST_DOMAINS', null);
|
||||
|
||||
if(empty($authWhitelistEmails)
|
||||
&& empty($authWhitelistDomains)
|
||||
|
@ -96,7 +95,7 @@ $cli
|
|||
Console::log('🟢 Console access limits are enabled');
|
||||
}
|
||||
|
||||
if(empty($request->getServer('_APP_OPTIONS_FORCE_HTTPS', null))) {
|
||||
if(empty(App::getEnv('_APP_OPTIONS_FORCE_HTTPS', null))) {
|
||||
Console::log('🔴 HTTP force option is disabled');
|
||||
}
|
||||
else {
|
||||
|
@ -132,7 +131,7 @@ $cli
|
|||
Console::error('Cache............disconnected 👎');
|
||||
}
|
||||
|
||||
if($request->getServer('_APP_STORAGE_ANTIVIRUS') === 'enabled') { // Check if scans are enabled
|
||||
if(App::getEnv('_APP_STORAGE_ANTIVIRUS') === 'enabled') { // Check if scans are enabled
|
||||
try {
|
||||
$antiVirus = new Network('clamav', 3310);
|
||||
|
||||
|
@ -161,8 +160,8 @@ $cli
|
|||
Console::error('SMTP.............disconnected 👎');
|
||||
}
|
||||
|
||||
$host = $request->getServer('_APP_STATSD_HOST', 'telegraf');
|
||||
$port = $request->getServer('_APP_STATSD_PORT', 8125);
|
||||
$host = App::getEnv('_APP_STATSD_HOST', 'telegraf');
|
||||
$port = App::getEnv('_APP_STATSD_PORT', 8125);
|
||||
|
||||
if($fp = @\fsockopen('udp://'.$host, $port, $errCode, $errStr, 2)){
|
||||
Console::success('StatsD..............connected 👍');
|
||||
|
@ -171,8 +170,8 @@ $cli
|
|||
Console::error('StatsD...........disconnected 👎');
|
||||
}
|
||||
|
||||
$host = $request->getServer('_APP_INFLUXDB_HOST', '');
|
||||
$port = $request->getServer('_APP_INFLUXDB_PORT', '');
|
||||
$host = App::getEnv('_APP_INFLUXDB_HOST', '');
|
||||
$port = App::getEnv('_APP_INFLUXDB_PORT', '');
|
||||
|
||||
if($fp = @\fsockopen($host, $port, $errCode, $errStr, 2)){
|
||||
Console::success('InfluxDB............connected 👍');
|
||||
|
@ -238,10 +237,10 @@ $cli
|
|||
|
||||
try {
|
||||
Console::log('');
|
||||
$version = \json_decode(@\file_get_contents($request->getServer('_APP_HOME', 'http://localhost').'/v1/health/version'), true);
|
||||
$version = \json_decode(@\file_get_contents(App::getEnv('_APP_HOME', 'http://localhost').'/v1/health/version'), true);
|
||||
|
||||
if($version && isset($version['version'])) {
|
||||
if(\version_compare($version['version'], $request->getServer('_APP_VERSION', 'UNKNOWN')) === 0) {
|
||||
if(\version_compare($version['version'], App::getEnv('_APP_VERSION', 'UNKNOWN')) === 0) {
|
||||
Console::info('You are running the latest version of '.APP_NAME.'! 🥳');
|
||||
}
|
||||
else {
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
require_once __DIR__.'/../init.php';
|
||||
|
||||
global $register, $projectDB, $console, $request;
|
||||
global $register, $projectDB, $console;
|
||||
|
||||
use Utopia\Config\Config;
|
||||
use Utopia\CLI\CLI;
|
||||
|
|
|
@ -37,21 +37,7 @@ $home = $this->getParam('home', '');
|
|||
|
||||
<p data-ls-if="({{project.platforms.length}})" class="text-fade text-size-small" data-ls-bind="{{project.platforms.length}} apps"></p>
|
||||
<p data-ls-if="(!{{project.platforms.length}})" class="text-fade text-size-small"> </p>
|
||||
<!-- <ul data-ls-loop="project.platforms" data-ls-as="platform" class="clear margin-bottom" style="min-height: 30px; overflow: hidden;">
|
||||
<li class="pull-start">
|
||||
<div data-ls-if="{{platform.type}} === 'web'" class="corner">
|
||||
<img src="" data-ls-attrs="src=/images/clients/web.png?v=<?php echo APP_CACHE_BUSTER; ?>" class="avatar xxs no-shadow" loading="lazy" width="30" height="30" />
|
||||
</div>
|
||||
|
||||
<div data-ls-if="{{platform.type}} === 'flutter-ios'" class="corner">
|
||||
<img src="" data-ls-attrs="src=/images/clients/ios.png?v=<?php echo APP_CACHE_BUSTER; ?>" class="avatar xxs no-shadow" loading="lazy" width="30" height="30" />
|
||||
</div>
|
||||
|
||||
<div data-ls-if="{{platform.type}} === 'flutter-android'" class="corner">
|
||||
<img src="" data-ls-attrs="src=/images/clients/android.png?v=<?php echo APP_CACHE_BUSTER; ?>" class="avatar xxs no-shadow" loading="lazy" width="30" height="30" />
|
||||
</div>
|
||||
</li>
|
||||
</ul> -->
|
||||
|
||||
<div>
|
||||
<i class="icon-right-open"></i>
|
||||
</div>
|
||||
|
|
|
@ -23,7 +23,7 @@ class CertificatesV1
|
|||
|
||||
public function perform()
|
||||
{
|
||||
global $request, $consoleDB;
|
||||
global $consoleDB;
|
||||
|
||||
/**
|
||||
* 1. Get new domain document - DONE
|
||||
|
@ -62,7 +62,7 @@ class CertificatesV1
|
|||
}
|
||||
|
||||
if($validateTarget) {
|
||||
$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.');
|
||||
|
@ -107,7 +107,7 @@ class CertificatesV1
|
|||
$staging = (Config::getParam('env') === App::MODE_TYPE_PRODUCTION) ? '' : ' --dry-run';
|
||||
|
||||
$response = \shell_exec("certbot certonly --webroot --noninteractive --agree-tos{$staging} \
|
||||
--email ".$request->getServer('_APP_SYSTEM_EMAIL_ADDRESS', 'security@localhost.test')." \
|
||||
--email ".App::getEnv('_APP_SYSTEM_EMAIL_ADDRESS', 'security@localhost.test')." \
|
||||
-w ".APP_STORAGE_CERTIFICATES." \
|
||||
-d {$domain->get()}");
|
||||
|
||||
|
|
|
@ -20,8 +20,6 @@ class DeletesV1
|
|||
|
||||
public function perform()
|
||||
{
|
||||
global $consoleDB, $request;
|
||||
|
||||
$document = $this->args['document'];
|
||||
$document = new Document($document);
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
require_once __DIR__.'/../init.php';
|
||||
|
||||
use Utopia\App;
|
||||
use Utopia\Config\Config;
|
||||
use Appwrite\Database\Database;
|
||||
use Appwrite\Database\Validator\Authorization;
|
||||
|
@ -24,7 +25,7 @@ class TasksV1
|
|||
|
||||
public function perform()
|
||||
{
|
||||
global $consoleDB, $request;
|
||||
global $consoleDB;
|
||||
|
||||
/*
|
||||
* 1. Get Original Task
|
||||
|
@ -96,7 +97,7 @@ class TasksV1
|
|||
\curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
\curl_setopt($ch, 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)
|
||||
));
|
||||
\curl_setopt(
|
||||
$ch,
|
||||
|
|
|
@ -9,6 +9,7 @@ echo APP_NAME.' webhooks worker v1 has started';
|
|||
use Utopia\Config\Config;
|
||||
use Appwrite\Database\Database;
|
||||
use Appwrite\Database\Validator\Authorization;
|
||||
use Utopia\App;
|
||||
|
||||
class WebhooksV1
|
||||
{
|
||||
|
@ -61,7 +62,7 @@ class WebhooksV1
|
|||
\curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
\curl_setopt($ch, 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)
|
||||
));
|
||||
\curl_setopt(
|
||||
$ch,
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
|
||||
"appwrite/php-clamav": "1.0.*",
|
||||
|
||||
"utopia-php/framework": "0.4.0",
|
||||
"utopia-php/framework": "0.6.0",
|
||||
"utopia-php/abuse": "0.2.*",
|
||||
"utopia-php/audit": "0.3.*",
|
||||
"utopia-php/cache": "0.2.*",
|
||||
|
|
22
composer.lock
generated
22
composer.lock
generated
|
@ -4,7 +4,7 @@
|
|||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "06dff1e6bbf24c18592e978fd9baab7d",
|
||||
"content-hash": "54f5e7c2291eb22ff442d2c491fa4eca",
|
||||
"packages": [
|
||||
{
|
||||
"name": "appwrite/php-clamav",
|
||||
|
@ -1596,16 +1596,16 @@
|
|||
},
|
||||
{
|
||||
"name": "utopia-php/framework",
|
||||
"version": "0.4.0",
|
||||
"version": "0.6.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/utopia-php/framework.git",
|
||||
"reference": "30aeb2aeecf8ea2ab83242efad0f5f9fab8d4be5"
|
||||
"reference": "5412a080f6fdf99310f20a803a797ae97de8b539"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/utopia-php/framework/zipball/30aeb2aeecf8ea2ab83242efad0f5f9fab8d4be5",
|
||||
"reference": "30aeb2aeecf8ea2ab83242efad0f5f9fab8d4be5",
|
||||
"url": "https://api.github.com/repos/utopia-php/framework/zipball/5412a080f6fdf99310f20a803a797ae97de8b539",
|
||||
"reference": "5412a080f6fdf99310f20a803a797ae97de8b539",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
|
@ -1636,7 +1636,7 @@
|
|||
"php",
|
||||
"upf"
|
||||
],
|
||||
"time": "2020-06-25T18:21:48+00:00"
|
||||
"time": "2020-06-28T16:54:35+00:00"
|
||||
},
|
||||
{
|
||||
"name": "utopia-php/locale",
|
||||
|
@ -1942,16 +1942,16 @@
|
|||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/myclabs/DeepCopy.git",
|
||||
"reference": "a491d65139e2411c75704e871dd02bdddf5a4bdc"
|
||||
"reference": "5796d127b0c4ff505b77455148ea9d5269d99758"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/a491d65139e2411c75704e871dd02bdddf5a4bdc",
|
||||
"reference": "a491d65139e2411c75704e871dd02bdddf5a4bdc",
|
||||
"url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/5796d127b0c4ff505b77455148ea9d5269d99758",
|
||||
"reference": "5796d127b0c4ff505b77455148ea9d5269d99758",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": "^7.1"
|
||||
"php": "^7.1 || ^8.0"
|
||||
},
|
||||
"replace": {
|
||||
"myclabs/deep-copy": "self.version"
|
||||
|
@ -1982,7 +1982,7 @@
|
|||
"object",
|
||||
"object graph"
|
||||
],
|
||||
"time": "2020-03-12T21:49:07+00:00"
|
||||
"time": "2020-06-28T07:02:41+00:00"
|
||||
},
|
||||
{
|
||||
"name": "phar-io/manifest",
|
||||
|
|
|
@ -11,13 +11,8 @@
|
|||
error_reporting(0);
|
||||
ini_set('display_errors', 0);
|
||||
|
||||
// ini_set('display_errors', 1);
|
||||
// ini_set('display_startup_errors', 1);
|
||||
// error_reporting(E_ALL);
|
||||
|
||||
$path = (isset($_GET['q'])) ? explode('/', $_GET['q']) : [];
|
||||
|
||||
array_shift($path);
|
||||
$version = array_shift($path);
|
||||
ini_set('display_errors', 1);
|
||||
ini_set('display_startup_errors', 1);
|
||||
error_reporting(E_ALL);
|
||||
|
||||
include __DIR__ . '/../app/app.php';
|
||||
|
|
|
@ -118,7 +118,7 @@ class Database
|
|||
/**
|
||||
* @param array $options
|
||||
*
|
||||
* @return Document[]|Document
|
||||
* @return Document[]
|
||||
*/
|
||||
public function getCollection(array $options)
|
||||
{
|
||||
|
|
|
@ -2,9 +2,9 @@
|
|||
|
||||
namespace Appwrite\Tests;
|
||||
|
||||
use Utopia\Request;
|
||||
use Appwrite\Event\Event;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Utopia\App;
|
||||
|
||||
class EventTest extends TestCase
|
||||
{
|
||||
|
@ -20,9 +20,8 @@ class EventTest extends TestCase
|
|||
|
||||
public function setUp()
|
||||
{
|
||||
$request = new Request();
|
||||
$redisHost = $request->getServer('_APP_REDIS_HOST', '');
|
||||
$redisPort = $request->getServer('_APP_REDIS_PORT', '');
|
||||
$redisHost = App::getEnv('_APP_REDIS_HOST', '');
|
||||
$redisPort = App::getEnv('_APP_REDIS_PORT', '');
|
||||
\Resque::setBackend($redisHost.':'.$redisPort);
|
||||
|
||||
$this->queue = 'v1-tests' . uniqid();
|
||||
|
|
Loading…
Reference in a new issue