clean up usage of DatabaseSetupException and catch Exceptions in entrypoints
This commit is contained in:
parent
c0bdbd9d81
commit
8dc6bdd96b
124
cron.php
124
cron.php
|
@ -44,75 +44,81 @@ function handleUnexpectedShutdown() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
require_once 'lib/base.php';
|
try {
|
||||||
|
|
||||||
session_write_close();
|
require_once 'lib/base.php';
|
||||||
|
|
||||||
// Don't do anything if ownCloud has not been installed
|
session_write_close();
|
||||||
if (!OC_Config::getValue('installed', false)) {
|
|
||||||
exit(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Handle unexpected errors
|
// Don't do anything if ownCloud has not been installed
|
||||||
register_shutdown_function('handleUnexpectedShutdown');
|
if (!OC_Config::getValue('installed', false)) {
|
||||||
|
exit(0);
|
||||||
// Delete temp folder
|
|
||||||
OC_Helper::cleanTmpNoClean();
|
|
||||||
|
|
||||||
// Exit if background jobs are disabled!
|
|
||||||
$appmode = OC_BackgroundJob::getExecutionType();
|
|
||||||
if ($appmode == 'none') {
|
|
||||||
TemporaryCronClass::$sent = true;
|
|
||||||
if (OC::$CLI) {
|
|
||||||
echo 'Background Jobs are disabled!' . PHP_EOL;
|
|
||||||
} else {
|
|
||||||
OC_JSON::error(array('data' => array('message' => 'Background jobs disabled!')));
|
|
||||||
}
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (OC::$CLI) {
|
|
||||||
// Create lock file first
|
|
||||||
TemporaryCronClass::$lockfile = OC_Config::getValue("datadirectory", OC::$SERVERROOT . '/data') . '/cron.lock';
|
|
||||||
|
|
||||||
// We call ownCloud from the CLI (aka cron)
|
|
||||||
if ($appmode != 'cron') {
|
|
||||||
// Use cron in feature!
|
|
||||||
OC_BackgroundJob::setExecutionType('cron');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if backgroundjobs is still running
|
// Handle unexpected errors
|
||||||
if (file_exists(TemporaryCronClass::$lockfile)) {
|
register_shutdown_function('handleUnexpectedShutdown');
|
||||||
TemporaryCronClass::$keeplock = true;
|
|
||||||
|
// Delete temp folder
|
||||||
|
OC_Helper::cleanTmpNoClean();
|
||||||
|
|
||||||
|
// Exit if background jobs are disabled!
|
||||||
|
$appmode = OC_BackgroundJob::getExecutionType();
|
||||||
|
if ($appmode == 'none') {
|
||||||
TemporaryCronClass::$sent = true;
|
TemporaryCronClass::$sent = true;
|
||||||
echo "Another instance of cron.php is still running!";
|
if (OC::$CLI) {
|
||||||
|
echo 'Background Jobs are disabled!' . PHP_EOL;
|
||||||
|
} else {
|
||||||
|
OC_JSON::error(array('data' => array('message' => 'Background jobs disabled!')));
|
||||||
|
}
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a lock file
|
if (OC::$CLI) {
|
||||||
touch(TemporaryCronClass::$lockfile);
|
// Create lock file first
|
||||||
|
TemporaryCronClass::$lockfile = OC_Config::getValue("datadirectory", OC::$SERVERROOT . '/data') . '/cron.lock';
|
||||||
|
|
||||||
// Work
|
// We call ownCloud from the CLI (aka cron)
|
||||||
$jobList = new \OC\BackgroundJob\JobList();
|
if ($appmode != 'cron') {
|
||||||
$jobs = $jobList->getAll();
|
// Use cron in feature!
|
||||||
foreach ($jobs as $job) {
|
OC_BackgroundJob::setExecutionType('cron');
|
||||||
$job->execute($jobList);
|
}
|
||||||
}
|
|
||||||
} else {
|
// check if backgroundjobs is still running
|
||||||
// We call cron.php from some website
|
if (file_exists(TemporaryCronClass::$lockfile)) {
|
||||||
if ($appmode == 'cron') {
|
TemporaryCronClass::$keeplock = true;
|
||||||
// Cron is cron :-P
|
TemporaryCronClass::$sent = true;
|
||||||
OC_JSON::error(array('data' => array('message' => 'Backgroundjobs are using system cron!')));
|
echo "Another instance of cron.php is still running!";
|
||||||
} else {
|
exit(1);
|
||||||
// Work and success :-)
|
}
|
||||||
|
|
||||||
|
// Create a lock file
|
||||||
|
touch(TemporaryCronClass::$lockfile);
|
||||||
|
|
||||||
|
// Work
|
||||||
$jobList = new \OC\BackgroundJob\JobList();
|
$jobList = new \OC\BackgroundJob\JobList();
|
||||||
$job = $jobList->getNext();
|
$jobs = $jobList->getAll();
|
||||||
$job->execute($jobList);
|
foreach ($jobs as $job) {
|
||||||
$jobList->setLastJob($job);
|
$job->execute($jobList);
|
||||||
OC_JSON::success();
|
}
|
||||||
|
} else {
|
||||||
|
// We call cron.php from some website
|
||||||
|
if ($appmode == 'cron') {
|
||||||
|
// Cron is cron :-P
|
||||||
|
OC_JSON::error(array('data' => array('message' => 'Backgroundjobs are using system cron!')));
|
||||||
|
} else {
|
||||||
|
// Work and success :-)
|
||||||
|
$jobList = new \OC\BackgroundJob\JobList();
|
||||||
|
$job = $jobList->getNext();
|
||||||
|
$job->execute($jobList);
|
||||||
|
$jobList->setLastJob($job);
|
||||||
|
OC_JSON::success();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// done!
|
// done!
|
||||||
TemporaryCronClass::$sent = true;
|
TemporaryCronClass::$sent = true;
|
||||||
exit();
|
exit();
|
||||||
|
|
||||||
|
} catch (Exception $ex) {
|
||||||
|
\OCP\Util::writeLog('cron', $ex->getMessage(), \OCP\Util::FATAL);
|
||||||
|
}
|
13
index.php
13
index.php
|
@ -23,6 +23,15 @@
|
||||||
|
|
||||||
$RUNTIME_NOAPPS = true; //no apps, yet
|
$RUNTIME_NOAPPS = true; //no apps, yet
|
||||||
|
|
||||||
require_once 'lib/base.php';
|
try {
|
||||||
|
|
||||||
|
require_once 'lib/base.php';
|
||||||
|
|
||||||
OC::handleRequest();
|
OC::handleRequest();
|
||||||
|
|
||||||
|
} catch (Exception $ex) {
|
||||||
|
//show the user a detailed error page
|
||||||
|
OC_Response::setStatus(OC_Response::STATUS_INTERNAL_SERVER_ERROR);
|
||||||
|
\OCP\Util::writeLog('remote', $ex->getMessage(), \OCP\Util::FATAL);
|
||||||
|
OC_Template::printExceptionErrorPage($ex);
|
||||||
|
}
|
|
@ -11,6 +11,7 @@ class OC_Response {
|
||||||
const STATUS_NOT_MODIFIED = 304;
|
const STATUS_NOT_MODIFIED = 304;
|
||||||
const STATUS_TEMPORARY_REDIRECT = 307;
|
const STATUS_TEMPORARY_REDIRECT = 307;
|
||||||
const STATUS_NOT_FOUND = 404;
|
const STATUS_NOT_FOUND = 404;
|
||||||
|
const STATUS_INTERNAL_SERVER_ERROR = 500;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Enable response caching by sending correct HTTP headers
|
* @brief Enable response caching by sending correct HTTP headers
|
||||||
|
@ -70,6 +71,9 @@ class OC_Response {
|
||||||
case self::STATUS_NOT_FOUND;
|
case self::STATUS_NOT_FOUND;
|
||||||
$status = $status . ' Not Found';
|
$status = $status . ' Not Found';
|
||||||
break;
|
break;
|
||||||
|
case self::STATUS_INTERNAL_SERVER_ERROR;
|
||||||
|
$status = $status . ' Internal Server Error';
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
header($protocol.' '.$status);
|
header($protocol.' '.$status);
|
||||||
}
|
}
|
||||||
|
|
|
@ -106,12 +106,6 @@ class OC_Setup {
|
||||||
'hint' => $e->getHint()
|
'hint' => $e->getHint()
|
||||||
);
|
);
|
||||||
return($error);
|
return($error);
|
||||||
} catch (Exception $e) {
|
|
||||||
$error[] = array(
|
|
||||||
'error' => $e->getMessage(),
|
|
||||||
'hint' => ''
|
|
||||||
);
|
|
||||||
return($error);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
elseif($dbtype == 'pgsql') {
|
elseif($dbtype == 'pgsql') {
|
||||||
|
@ -127,7 +121,7 @@ class OC_Setup {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
self::setupPostgreSQLDatabase($dbhost, $dbuser, $dbpass, $dbname, $dbtableprefix, $username);
|
self::setupPostgreSQLDatabase($dbhost, $dbuser, $dbpass, $dbname, $dbtableprefix, $username);
|
||||||
} catch (Exception $e) {
|
} catch (DatabaseSetupException $e) {
|
||||||
$error[] = array(
|
$error[] = array(
|
||||||
'error' => $l->t('PostgreSQL username and/or password not valid'),
|
'error' => $l->t('PostgreSQL username and/or password not valid'),
|
||||||
'hint' => $l->t('You need to enter either an existing account or the administrator.')
|
'hint' => $l->t('You need to enter either an existing account or the administrator.')
|
||||||
|
@ -150,7 +144,7 @@ class OC_Setup {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
self::setupOCIDatabase($dbhost, $dbuser, $dbpass, $dbname, $dbtableprefix, $dbtablespace, $username);
|
self::setupOCIDatabase($dbhost, $dbuser, $dbpass, $dbname, $dbtableprefix, $dbtablespace, $username);
|
||||||
} catch (Exception $e) {
|
} catch (DatabaseSetupException $e) {
|
||||||
$error[] = array(
|
$error[] = array(
|
||||||
'error' => $l->t('Oracle connection could not be established'),
|
'error' => $l->t('Oracle connection could not be established'),
|
||||||
'hint' => $e->getMessage().' Check environment: ORACLE_HOME='.getenv('ORACLE_HOME')
|
'hint' => $e->getMessage().' Check environment: ORACLE_HOME='.getenv('ORACLE_HOME')
|
||||||
|
@ -177,7 +171,7 @@ class OC_Setup {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
self::setupMSSQLDatabase($dbhost, $dbuser, $dbpass, $dbname, $dbtableprefix);
|
self::setupMSSQLDatabase($dbhost, $dbuser, $dbpass, $dbname, $dbtableprefix);
|
||||||
} catch (Exception $e) {
|
} catch (DatabaseSetupException $e) {
|
||||||
$error[] = array(
|
$error[] = array(
|
||||||
'error' => 'MS SQL username and/or password not valid',
|
'error' => 'MS SQL username and/or password not valid',
|
||||||
'hint' => 'You need to enter either an existing account or the administrator.'
|
'hint' => 'You need to enter either an existing account or the administrator.'
|
||||||
|
@ -326,7 +320,7 @@ class OC_Setup {
|
||||||
$connection_string = "host='$e_host' dbname=postgres user='$e_user' password='$e_password'";
|
$connection_string = "host='$e_host' dbname=postgres user='$e_user' password='$e_password'";
|
||||||
$connection = @pg_connect($connection_string);
|
$connection = @pg_connect($connection_string);
|
||||||
if(!$connection) {
|
if(!$connection) {
|
||||||
throw new Exception($l->t('PostgreSQL username and/or password not valid'));
|
throw new DatabaseSetupException($l->t('PostgreSQL username and/or password not valid'));
|
||||||
}
|
}
|
||||||
$e_user = pg_escape_string($dbuser);
|
$e_user = pg_escape_string($dbuser);
|
||||||
//check for roles creation rights in postgresql
|
//check for roles creation rights in postgresql
|
||||||
|
@ -371,7 +365,7 @@ class OC_Setup {
|
||||||
$connection_string = "host='$e_host' dbname='$e_dbname' user='$e_user' password='$e_password'";
|
$connection_string = "host='$e_host' dbname='$e_dbname' user='$e_user' password='$e_password'";
|
||||||
$connection = @pg_connect($connection_string);
|
$connection = @pg_connect($connection_string);
|
||||||
if(!$connection) {
|
if(!$connection) {
|
||||||
throw new Exception($l->t('PostgreSQL username and/or password not valid'));
|
throw new DatabaseSetupException($l->t('PostgreSQL username and/or password not valid'));
|
||||||
}
|
}
|
||||||
$query = "select count(*) FROM pg_class WHERE relname='{$dbtableprefix}users' limit 1";
|
$query = "select count(*) FROM pg_class WHERE relname='{$dbtableprefix}users' limit 1";
|
||||||
$result = pg_query($connection, $query);
|
$result = pg_query($connection, $query);
|
||||||
|
@ -461,9 +455,9 @@ class OC_Setup {
|
||||||
if(!$connection) {
|
if(!$connection) {
|
||||||
$e = oci_error();
|
$e = oci_error();
|
||||||
if (is_array ($e) && isset ($e['message'])) {
|
if (is_array ($e) && isset ($e['message'])) {
|
||||||
throw new Exception($e['message']);
|
throw new DatabaseSetupException($e['message']);
|
||||||
}
|
}
|
||||||
throw new Exception($l->t('Oracle username and/or password not valid'));
|
throw new DatabaseSetupException($l->t('Oracle username and/or password not valid'));
|
||||||
}
|
}
|
||||||
//check for roles creation rights in oracle
|
//check for roles creation rights in oracle
|
||||||
|
|
||||||
|
@ -530,7 +524,7 @@ class OC_Setup {
|
||||||
}
|
}
|
||||||
$connection = @oci_connect($dbuser, $dbpass, $easy_connect_string);
|
$connection = @oci_connect($dbuser, $dbpass, $easy_connect_string);
|
||||||
if(!$connection) {
|
if(!$connection) {
|
||||||
throw new Exception($l->t('Oracle username and/or password not valid'));
|
throw new DatabaseSetupException($l->t('Oracle username and/or password not valid'));
|
||||||
}
|
}
|
||||||
$query = "SELECT count(*) FROM user_tables WHERE table_name = :un";
|
$query = "SELECT count(*) FROM user_tables WHERE table_name = :un";
|
||||||
$stmt = oci_parse($connection, $query);
|
$stmt = oci_parse($connection, $query);
|
||||||
|
@ -641,7 +635,7 @@ class OC_Setup {
|
||||||
} else {
|
} else {
|
||||||
$entry = '';
|
$entry = '';
|
||||||
}
|
}
|
||||||
throw new Exception($l->t('MS SQL username and/or password not valid: %s', array($entry)));
|
throw new DatabaseSetupException($l->t('MS SQL username and/or password not valid: %s', array($entry)));
|
||||||
}
|
}
|
||||||
|
|
||||||
OC_Config::setValue('dbuser', $dbuser);
|
OC_Config::setValue('dbuser', $dbuser);
|
||||||
|
|
42
public.php
42
public.php
|
@ -1,21 +1,31 @@
|
||||||
<?php
|
<?php
|
||||||
$RUNTIME_NOAPPS = true;
|
$RUNTIME_NOAPPS = true;
|
||||||
require_once 'lib/base.php';
|
|
||||||
OC::checkMaintenanceMode();
|
|
||||||
if (!isset($_GET['service'])) {
|
|
||||||
header('HTTP/1.0 404 Not Found');
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
$file = OCP\CONFIG::getAppValue('core', 'public_' . strip_tags($_GET['service']));
|
|
||||||
if(is_null($file)) {
|
|
||||||
header('HTTP/1.0 404 Not Found');
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
$parts=explode('/', $file, 2);
|
try {
|
||||||
$app=$parts[0];
|
|
||||||
|
|
||||||
OC_Util::checkAppEnabled($app);
|
require_once 'lib/base.php';
|
||||||
OC_App::loadApp($app);
|
OC::checkMaintenanceMode();
|
||||||
|
if (!isset($_GET['service'])) {
|
||||||
|
header('HTTP/1.0 404 Not Found');
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
$file = OCP\CONFIG::getAppValue('core', 'public_' . strip_tags($_GET['service']));
|
||||||
|
if(is_null($file)) {
|
||||||
|
header('HTTP/1.0 404 Not Found');
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
require_once OC_App::getAppPath($app) .'/'. $parts[1];
|
$parts=explode('/', $file, 2);
|
||||||
|
$app=$parts[0];
|
||||||
|
|
||||||
|
OC_Util::checkAppEnabled($app);
|
||||||
|
OC_App::loadApp($app);
|
||||||
|
|
||||||
|
require_once OC_App::getAppPath($app) .'/'. $parts[1];
|
||||||
|
|
||||||
|
} catch (Exception $ex) {
|
||||||
|
//show the user a detailed error page
|
||||||
|
OC_Response::setStatus(OC_Response::STATUS_INTERNAL_SERVER_ERROR);
|
||||||
|
\OCP\Util::writeLog('remote', $ex->getMessage(), \OCP\Util::FATAL);
|
||||||
|
OC_Template::printExceptionErrorPage($ex);
|
||||||
|
}
|
77
remote.php
77
remote.php
|
@ -1,40 +1,49 @@
|
||||||
<?php
|
<?php
|
||||||
$RUNTIME_NOAPPS = true;
|
$RUNTIME_NOAPPS = true;
|
||||||
require_once 'lib/base.php';
|
|
||||||
$path_info = OC_Request::getPathInfo();
|
|
||||||
if ($path_info === false || $path_info === '') {
|
|
||||||
OC_Response::setStatus(OC_Response::STATUS_NOT_FOUND);
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
if (!$pos = strpos($path_info, '/', 1)) {
|
|
||||||
$pos = strlen($path_info);
|
|
||||||
}
|
|
||||||
$service=substr($path_info, 1, $pos-1);
|
|
||||||
|
|
||||||
$file = OC_AppConfig::getValue('core', 'remote_' . $service);
|
try {
|
||||||
|
|
||||||
if(is_null($file)) {
|
require_once 'lib/base.php';
|
||||||
OC_Response::setStatus(OC_Response::STATUS_NOT_FOUND);
|
$path_info = OC_Request::getPathInfo();
|
||||||
exit;
|
if ($path_info === false || $path_info === '') {
|
||||||
}
|
OC_Response::setStatus(OC_Response::STATUS_NOT_FOUND);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
if (!$pos = strpos($path_info, '/', 1)) {
|
||||||
|
$pos = strlen($path_info);
|
||||||
|
}
|
||||||
|
$service=substr($path_info, 1, $pos-1);
|
||||||
|
|
||||||
$file=ltrim($file, '/');
|
$file = OC_AppConfig::getValue('core', 'remote_' . $service);
|
||||||
|
|
||||||
$parts=explode('/', $file, 2);
|
if(is_null($file)) {
|
||||||
$app=$parts[0];
|
OC_Response::setStatus(OC_Response::STATUS_NOT_FOUND);
|
||||||
switch ($app) {
|
exit;
|
||||||
case 'core':
|
}
|
||||||
$file = OC::$SERVERROOT .'/'. $file;
|
|
||||||
break;
|
$file=ltrim($file, '/');
|
||||||
default:
|
|
||||||
OC_Util::checkAppEnabled($app);
|
$parts=explode('/', $file, 2);
|
||||||
OC_App::loadApp($app);
|
$app=$parts[0];
|
||||||
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
|
switch ($app) {
|
||||||
$file = OC_App::getAppPath($app) .'/'. $parts[1];
|
case 'core':
|
||||||
}else{
|
$file = OC::$SERVERROOT .'/'. $file;
|
||||||
$file = '/' . OC_App::getAppPath($app) .'/'. $parts[1];
|
break;
|
||||||
}
|
default:
|
||||||
break;
|
OC_Util::checkAppEnabled($app);
|
||||||
}
|
OC_App::loadApp($app);
|
||||||
$baseuri = OC::$WEBROOT . '/remote.php/'.$service.'/';
|
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
|
||||||
require_once $file;
|
$file = OC_App::getAppPath($app) .'/'. $parts[1];
|
||||||
|
}else{
|
||||||
|
$file = '/' . OC_App::getAppPath($app) .'/'. $parts[1];
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
$baseuri = OC::$WEBROOT . '/remote.php/'.$service.'/';
|
||||||
|
require_once $file;
|
||||||
|
|
||||||
|
} catch (Exception $ex) {
|
||||||
|
OC_Response::setStatus(OC_Response::STATUS_INTERNAL_SERVER_ERROR);
|
||||||
|
\OCP\Util::writeLog('remote', $ex->getMessage(), \OCP\Util::FATAL);
|
||||||
|
OC_Template::printExceptionErrorPage($ex);
|
||||||
|
}
|
23
status.php
23
status.php
|
@ -23,13 +23,20 @@
|
||||||
|
|
||||||
$RUNTIME_NOAPPS = true; //no apps, yet
|
$RUNTIME_NOAPPS = true; //no apps, yet
|
||||||
|
|
||||||
require_once 'lib/base.php';
|
try {
|
||||||
|
|
||||||
if(OC_Config::getValue('installed')==1) $installed='true'; else $installed='false';
|
require_once 'lib/base.php';
|
||||||
$values=array(
|
|
||||||
'installed'=>$installed,
|
|
||||||
'version'=>implode('.', OC_Util::getVersion()),
|
|
||||||
'versionstring'=>OC_Util::getVersionString(),
|
|
||||||
'edition'=>OC_Util::getEditionString());
|
|
||||||
|
|
||||||
echo(json_encode($values));
|
if(OC_Config::getValue('installed')==1) $installed='true'; else $installed='false';
|
||||||
|
$values=array(
|
||||||
|
'installed'=>$installed,
|
||||||
|
'version'=>implode('.', OC_Util::getVersion()),
|
||||||
|
'versionstring'=>OC_Util::getVersionString(),
|
||||||
|
'edition'=>OC_Util::getEditionString());
|
||||||
|
|
||||||
|
echo(json_encode($values));
|
||||||
|
|
||||||
|
} catch (Exception $ex) {
|
||||||
|
OC_Response::setStatus(OC_Response::STATUS_INTERNAL_SERVER_ERROR);
|
||||||
|
\OCP\Util::writeLog('remote', $ex->getMessage(), \OCP\Util::FATAL);
|
||||||
|
}
|
Loading…
Reference in New Issue