You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

788 lines
21 KiB

16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
  1. <?php
  2. /**
  3. * ownCloud
  4. *
  5. * @author Frank Karlitschek
  6. * @copyright 2010 Frank Karlitschek karlitschek@kde.org
  7. *
  8. * This library is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
  10. * License as published by the Free Software Foundation; either
  11. * version 3 of the License, or any later version.
  12. *
  13. * This library is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public
  19. * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. // set some stuff
  23. //ob_start();
  24. // error_reporting(E_ALL | E_STRICT);
  25. error_reporting( E_ERROR | E_PARSE | E_WARNING ); // MDB2 gives loads of strict error, disabling for now
  26. date_default_timezone_set('Europe/Berlin');
  27. ini_set('arg_separator.output','&amp;');
  28. ini_set('session.cookie_httponly','1;');
  29. session_start();
  30. // calculate the documentroot
  31. $SERVERROOT=substr(__FILE__,0,-13);
  32. $DOCUMENTROOT=realpath($_SERVER['DOCUMENT_ROOT']);
  33. $SERVERROOT=str_replace("\\",'/',$SERVERROOT);
  34. $SUBURI=substr(realpath($_SERVER["SCRIPT_FILENAME"]),strlen($SERVERROOT));
  35. $WEBROOT=substr($_SERVER["SCRIPT_NAME"],0,strlen($_SERVER["SCRIPT_NAME"])-strlen($SUBURI));
  36. if($WEBROOT!='' and $WEBROOT[0]!=='/'){
  37. $WEBROOT='/'.$WEBROOT;
  38. }
  39. // set the right include path
  40. // set_include_path(get_include_path().PATH_SEPARATOR.$SERVERROOT.PATH_SEPARATOR.$SERVERROOT.'/inc'.PATH_SEPARATOR.$SERVERROOT.'/config');
  41. // define runtime variables - unless this already has been done
  42. if( !isset( $RUNTIME_NOSETUPFS )){
  43. $RUNTIME_NOSETUPFS = false;
  44. }
  45. // define default config values
  46. $CONFIG_INSTALLED=false;
  47. $CONFIG_DATADIRECTORY=$SERVERROOT.'/data';
  48. $CONFIG_BACKUPDIRECTORY=$SERVERROOT.'/backup';
  49. $CONFIG_HTTPFORCESSL=false;
  50. $CONFIG_ENABLEBACKUP=false;
  51. $CONFIG_DATEFORMAT='j M Y G:i';
  52. $CONFIG_DBNAME='owncloud';
  53. $CONFIG_DBTYPE='sqlite';
  54. $CONFIG_FILESYSTEM=array();
  55. // include the generated configfile
  56. @include_once($SERVERROOT.'/config/config.php');
  57. $CONFIG_DATADIRECTORY_ROOT=$CONFIG_DATADIRECTORY;// store this in a seperate variable so we can change the data directory to jail users.
  58. // redirect to https site if configured
  59. if(isset($CONFIG_HTTPFORCESSL) and $CONFIG_HTTPFORCESSL){
  60. if(!isset($_SERVER['HTTPS']) or $_SERVER['HTTPS'] != 'on') {
  61. $url = "https://". $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
  62. header("Location: $url");
  63. exit;
  64. }
  65. }
  66. // load core libs
  67. oc_require_once('helper.php');
  68. oc_require_once('app.php');
  69. oc_require_once('files.php');
  70. oc_require_once('filesystem.php');
  71. oc_require_once('filestorage.php');
  72. oc_require_once('fileobserver.php');
  73. oc_require_once('log.php');
  74. oc_require_once('config.php');
  75. oc_require_once('user.php');
  76. oc_require_once('group.php');
  77. oc_require_once('ocs.php');
  78. oc_require_once('connect.php');
  79. oc_require_once('remotestorage.php');
  80. oc_require_once('plugin.php');
  81. OC_PLUGIN::loadPlugins( "" );
  82. if(!isset($CONFIG_BACKEND)){
  83. $CONFIG_BACKEND='database';
  84. }
  85. OC_USER::setBackend( $CONFIG_BACKEND );
  86. OC_GROUP::setBackend( $CONFIG_BACKEND );
  87. // Set up file system unless forbidden
  88. if( !$RUNTIME_NOSETUPFS ){
  89. OC_UTIL::setupFS();
  90. }
  91. // Add the stuff we need always
  92. OC_APP::addPersonalMenuEntry( array( "order" => 1000, "href" => OC_HELPER::linkTo( "", "index.php?logout=1" ), "name" => "Logout" ));
  93. OC_UTIL::addScript( "jquery-1.5.min" );
  94. OC_UTIL::addScript( "jquery-ui-1.8.10.custom.min" );
  95. OC_UTIL::addScript( "js" );
  96. OC_UTIL::addStyle( "jquery-ui-1.8.10.custom" );
  97. OC_UTIL::addStyle( "styles" );
  98. // Load Apps
  99. OC_APP::loadApps();
  100. // check if the server is correctly configured for ownCloud
  101. OC_UTIL::checkserver();
  102. /**
  103. * Class for utility functions
  104. *
  105. */
  106. class OC_UTIL {
  107. public static $scripts=array();
  108. public static $styles=array();
  109. private static $fsSetup=false;
  110. // Can be set up
  111. public static function setupFS( $user = "", $root = "files" ){// configure the initial filesystem based on the configuration
  112. if(self::$fsSetup){//setting up the filesystem twice can only lead to trouble
  113. return false;
  114. }
  115. // Global Variables
  116. global $SERVERROOT;
  117. global $CONFIG_DATADIRECTORY_ROOT;
  118. global $CONFIG_DATADIRECTORY;
  119. global $CONFIG_BACKUPDIRECTORY;
  120. global $CONFIG_ENABLEBACKUP;
  121. global $CONFIG_FILESYSTEM;
  122. // Create root dir
  123. if(!is_dir($CONFIG_DATADIRECTORY_ROOT)){
  124. @mkdir($CONFIG_DATADIRECTORY_ROOT) or die("Can't create data directory ($CONFIG_DATADIRECTORY_ROOT), you can usually fix this by setting the owner of '$SERVERROOT' to the user that the web server uses (www-data for debian/ubuntu)");
  125. }
  126. // If we are not forced to load a specific user we load the one that is logged in
  127. if( $user == "" && OC_USER::isLoggedIn()){
  128. $user = $_SESSION['user_id'];
  129. }
  130. if( $user != "" ){ //if we aren't logged in, there is no use to set up the filesystem
  131. //first set up the local "root" storage and the backupstorage if needed
  132. $rootStorage=OC_FILESYSTEM::createStorage('local',array('datadir'=>$CONFIG_DATADIRECTORY));
  133. if($CONFIG_ENABLEBACKUP){
  134. // This creates the Directorys recursively
  135. if(!is_dir( "$CONFIG_BACKUPDIRECTORY/$user/$root" )){
  136. mkdir( "$CONFIG_BACKUPDIRECTORY/$user/$root", 0x755, true );
  137. }
  138. $backupStorage=OC_FILESYSTEM::createStorage('local',array('datadir'=>$CONFIG_BACKUPDIRECTORY));
  139. $backup=new OC_FILEOBSERVER_BACKUP(array('storage'=>$backupStorage));
  140. $rootStorage->addObserver($backup);
  141. }
  142. OC_FILESYSTEM::mount($rootStorage,'/');
  143. $CONFIG_DATADIRECTORY = "$CONFIG_DATADIRECTORY_ROOT/$user/$root";
  144. if( !is_dir( $CONFIG_DATADIRECTORY )){
  145. mkdir( $CONFIG_DATADIRECTORY, 0x755, true );
  146. }
  147. //set up the other storages according to the system settings
  148. foreach($CONFIG_FILESYSTEM as $storageConfig){
  149. if(OC_FILESYSTEM::hasStorageType($storageConfig['type'])){
  150. $arguments=$storageConfig;
  151. unset($arguments['type']);
  152. unset($arguments['mountpoint']);
  153. $storage=OC_FILESYSTEM::createStorage($storageConfig['type'],$arguments);
  154. if($storage){
  155. OC_FILESYSTEM::mount($storage,$storageConfig['mountpoint']);
  156. }
  157. }
  158. }
  159. //jail the user into his "home" directory
  160. OC_FILESYSTEM::chroot("/$user/$root");
  161. self::$fsSetup=true;
  162. }
  163. }
  164. /**
  165. * get the current installed version of ownCloud
  166. * @return array
  167. */
  168. public static function getVersion(){
  169. return array(1,2,0);
  170. }
  171. /**
  172. * add a javascript file
  173. *
  174. * @param url $url
  175. */
  176. public static function addScript( $application, $file = null ){
  177. if( is_null( $file )){
  178. $file = $application;
  179. $application = "";
  180. }
  181. self::$scripts[] = "$application/js/$file";
  182. }
  183. /**
  184. * add a css file
  185. *
  186. * @param url $url
  187. */
  188. public static function addStyle( $application, $file = null ){
  189. if( is_null( $file )){
  190. $file = $application;
  191. $application = "";
  192. }
  193. self::$styles[] = "$application/css/$file";
  194. }
  195. /**
  196. * check if the current server configuration is suitable for ownCloud
  197. *
  198. */
  199. public static function checkServer(){
  200. global $SERVERROOT;
  201. global $CONFIG_DATADIRECTORY_ROOT;
  202. global $CONFIG_BACKUPDIRECTORY;
  203. global $CONFIG_ENABLEBACKUP;
  204. global $CONFIG_INSTALLED;
  205. $error='';
  206. if(!is_callable('sqlite_open') and !is_callable('mysql_connect')){
  207. $error.='No database drivers (sqlite or mysql) installed.<br/>';
  208. }
  209. global $CONFIG_DBTYPE;
  210. global $CONFIG_DBNAME;
  211. if(!stristr(PHP_OS, 'WIN')){
  212. if($CONFIG_DBTYPE=='sqlite'){
  213. $file=$SERVERROOT.'/'.$CONFIG_DBNAME;
  214. if(file_exists($file)){
  215. $prems=substr(decoct(fileperms($file)),-3);
  216. if(substr($prems,2,1)!='0'){
  217. @chmod($file,0660);
  218. clearstatcache();
  219. $prems=substr(decoct(fileperms($file)),-3);
  220. if(substr($prems,2,1)!='0'){
  221. $error.='SQLite database file ('.$file.') is readable from the web<br/>';
  222. }
  223. }
  224. }
  225. }
  226. $prems=substr(decoct(fileperms($CONFIG_DATADIRECTORY_ROOT)),-3);
  227. if(substr($prems,-1)!='0'){
  228. chmodr($CONFIG_DATADIRECTORY_ROOT,0770);
  229. clearstatcache();
  230. $prems=substr(decoct(fileperms($CONFIG_DATADIRECTORY_ROOT)),-3);
  231. if(substr($prems,2,1)!='0'){
  232. $error.='Data directory ('.$CONFIG_DATADIRECTORY_ROOT.') is readable from the web<br/>';
  233. }
  234. }
  235. if($CONFIG_ENABLEBACKUP){
  236. $prems=substr(decoct(fileperms($CONFIG_BACKUPDIRECTORY)),-3);
  237. if(substr($prems,-1)!='0'){
  238. chmodr($CONFIG_BACKUPDIRECTORY,0770);
  239. clearstatcache();
  240. $prems=substr(decoct(fileperms($CONFIG_BACKUPDIRECTORY)),-3);
  241. if(substr($prems,2,1)!='0'){
  242. $error.='Data directory ('.$CONFIG_BACKUPDIRECTORY.') is readable from the web<br/>';
  243. }
  244. }
  245. }
  246. }else{
  247. //TODO: premisions checks for windows hosts
  248. }
  249. if($error){
  250. die($error);
  251. }
  252. }
  253. }
  254. /**
  255. * This class manages the hooks. It basically provides two functions: adding
  256. * slots and emitting signals.
  257. */
  258. class OC_HOOK{
  259. static private $registered = array();
  260. /**
  261. * @brief connects a function to a hook
  262. * @param $signalclass class name of emitter
  263. * @param $signalname name of signal
  264. * @param $slotclass class name of slot
  265. * @param $slotname name of slot
  266. * @returns true/false
  267. *
  268. * This function makes it very easy to connect to use hooks.
  269. *
  270. * TODO: write example
  271. */
  272. public function connect( $signalclass, $signalname, $slotclass, $slotname ){
  273. // Cerate the data structure
  274. if( !array_key_exists( $signalclass, self::$registered )){
  275. self::$registered[$signalclass] = array();
  276. }
  277. if( !array_key_exists( $signalname, self::$registered[$signalclass] )){
  278. self::$registered[$signalclass][$signalname] = array();
  279. }
  280. // register hook
  281. self::$registered[$signalclass][$signalname][] = array(
  282. "class" => $slotclass,
  283. "name" => $slotname );
  284. // No chance for failure ;-)
  285. return true;
  286. }
  287. /**
  288. * @brief emitts a signal
  289. * @param $signalclass class name of emitter
  290. * @param $signalname name of signal
  291. * @param $params defautl: array() array with additional data
  292. * @returns true if slots exists or false if not
  293. *
  294. * Emits a signal. To get data from the slot use references!
  295. *
  296. * TODO: write example
  297. */
  298. public function emit( $signalclass, $signalname, $params = array()){
  299. // Return false if there are no slots
  300. if( !array_key_exists( $signalclass, self::$registered )){
  301. return false;
  302. }
  303. if( !array_key_exists( $signalname, self::$registered[$signalclass] )){
  304. return false;
  305. }
  306. // Call all slots
  307. foreach( $registered[$signalclass][$signalname] as $i ){
  308. call_user_func( array( $i["class"], $i["name"] ), $params );
  309. }
  310. // return true
  311. return true;
  312. }
  313. }
  314. /**
  315. * This class manages the access to the database. It basically is a wrapper for
  316. * MDB2 with some adaptions.
  317. */
  318. class OC_DB {
  319. static private $DBConnection=false;
  320. static private $schema=false;
  321. static private $affected=0;
  322. static private $result=false;
  323. /**
  324. * @brief connects to the database
  325. * @returns true if connection can be established or nothing (die())
  326. *
  327. * Connects to the database as specified in config.php
  328. */
  329. static public function connect(){
  330. // The global data we need
  331. global $CONFIG_DBNAME;
  332. global $CONFIG_DBHOST;
  333. global $CONFIG_DBUSER;
  334. global $CONFIG_DBPASSWORD;
  335. global $CONFIG_DBTYPE;
  336. global $DOCUMENTROOT;
  337. global $SERVERROOT;
  338. // do nothing if the connection already has been established
  339. if(!self::$DBConnection){
  340. // Require MDB2.php (TODO: why here not in head of file?)
  341. @oc_require_once('MDB2.php');
  342. // Prepare options array
  343. $options = array(
  344. 'portability' => MDB2_PORTABILITY_ALL,
  345. 'log_line_break' => '<br>',
  346. 'idxname_format' => '%s',
  347. 'debug' => true,
  348. 'quote_identifier' => true );
  349. // Add the dsn according to the database type
  350. if( $CONFIG_DBTYPE == 'sqlite' ){
  351. // sqlite
  352. $dsn = array(
  353. 'phptype' => 'sqlite',
  354. 'database' => "$SERVERROOT/$CONFIG_DBNAME",
  355. 'mode' => '0644' );
  356. }
  357. elseif( $CONFIG_DBTYPE == 'mysql' ){
  358. // MySQL
  359. $dsn = array(
  360. 'phptype' => 'mysql',
  361. 'username' => $CONFIG_DBUSER,
  362. 'password' => $CONFIG_DBPASSWORD,
  363. 'hostspec' => $CONFIG_DBHOST,
  364. 'database' => $CONFIG_DBNAME );
  365. }
  366. elseif( $CONFIG_DBTYPE == 'pgsql' ){
  367. // PostgreSQL
  368. $dsn = array(
  369. 'phptype' => 'pgsql',
  370. 'username' => $CONFIG_DBUSER,
  371. 'password' => $CONFIG_DBPASSWORD,
  372. 'hostspec' => $CONFIG_DBHOST,
  373. 'database' => $CONFIG_DBNAME );
  374. }
  375. // Try to establish connection
  376. self::$DBConnection = MDB2::factory( $dsn, $options );
  377. // Die if we could not connect
  378. if( PEAR::isError( self::$DBConnection )){
  379. echo( '<b>can not connect to database, using '.$CONFIG_DBTYPE.'. ('.self::$DBConnection->getUserInfo().')</center>');
  380. $error = self::$DBConnection->getMessage();
  381. error_log( $error);
  382. error_log( self::$DBConnection->getUserInfo());
  383. die( $error );
  384. }
  385. // We always, really always want associative arrays
  386. self::$DBConnection->setFetchMode(MDB2_FETCHMODE_ASSOC);
  387. }
  388. // we are done. great!
  389. return true;
  390. }
  391. /**
  392. * @brief SQL query
  393. * @param $query Query string
  394. * @returns result as MDB2_Result
  395. *
  396. * SQL query via MDB2 query()
  397. */
  398. static public function query( $query ){
  399. // Optimize the query
  400. $query = self::processQuery( $query );
  401. self::connect();
  402. //fix differences between sql versions
  403. // return the result
  404. $result = self::$DBConnection->exec( $query );
  405. // Die if we have an error (error means: bad query, not 0 results!)
  406. if( PEAR::isError($result)) {
  407. $entry = 'DB Error: "'.$result->getMessage().'"<br />';
  408. $entry .= 'Offending command was: '.$cmd.'<br />';
  409. error_log( $entry );
  410. die( $entry );
  411. }
  412. return $result;
  413. }
  414. /**
  415. * @brief Prepare a SQL query
  416. * @param $query Query string
  417. * @returns prepared SQL query
  418. *
  419. * SQL query via MDB2 prepare(), needs to be execute()'d!
  420. */
  421. static public function prepare( $query ){
  422. // Optimize the query
  423. $query = self::processQuery( $query );
  424. self::connect();
  425. //fix differences between sql versions
  426. // return the result
  427. $result = self::$DBConnection->prepare( $query );
  428. // Die if we have an error (error means: bad query, not 0 results!)
  429. if( PEAR::isError($result)) {
  430. $entry = 'DB Error: "'.$result->getMessage().'"<br />';
  431. $entry .= 'Offending command was: '.$cmd.'<br />';
  432. error_log( $entry );
  433. die( $entry );
  434. }
  435. return $result;
  436. }
  437. /**
  438. * @brief gets last value of autoincrement
  439. * @returns id
  440. *
  441. * MDB2 lastInsertID()
  442. *
  443. * Call this method right after the insert command or other functions may
  444. * cause trouble!
  445. */
  446. public static function insertid(){
  447. self::connect();
  448. return self::$DBConnection->lastInsertID();
  449. }
  450. /**
  451. * @brief Disconnect
  452. * @returns true/false
  453. *
  454. * This is good bye, good bye, yeah!
  455. */
  456. public static function disconnect(){
  457. // Cut connection if required
  458. if(self::$DBConnection){
  459. self::$DBConnection->disconnect();
  460. self::$DBConnection=false;
  461. }
  462. return true;
  463. }
  464. /**
  465. * @brief Escapes bad characters
  466. * @param $string string with dangerous characters
  467. * @returns escaped string
  468. *
  469. * MDB2 escape()
  470. */
  471. public static function escape( $string ){
  472. self::connect();
  473. return self::$DBConnection->escape( $string );
  474. }
  475. /**
  476. * @brief saves database scheme to xml file
  477. * @param $file name of file
  478. * @returns true/false
  479. *
  480. * TODO: write more documentation
  481. */
  482. public static function getDbStructure( $file ){
  483. self::connectScheme();
  484. // write the scheme
  485. $definition = self::$schema->getDefinitionFromDatabase();
  486. $dump_options = array(
  487. 'output_mode' => 'file',
  488. 'output' => $file,
  489. 'end_of_line' => "\n"
  490. );
  491. self::$schema->dumpDatabase( $definition, $dump_options, MDB2_SCHEMA_DUMP_STRUCTURE );
  492. return true;
  493. }
  494. /**
  495. * @brief Creates tables from XML file
  496. * @param $file file to read structure from
  497. * @returns true/false
  498. *
  499. * TODO: write more documentation
  500. */
  501. public static function createDbFromStructure( $file ){
  502. global $CONFIG_DBNAME;
  503. global $CONFIG_DBTABLEPREFIX;
  504. self::connectScheme();
  505. // read file
  506. $content = file_get_contents( $file );
  507. // Make changes and save them to a temporary file
  508. $file2 = tempnam( sys_get_temp_dir(), 'oc_db_scheme_' );
  509. $content = str_replace( '*dbname*', $CONFIG_DBNAME, $content );
  510. $content = str_replace( '*dbprefix*', $CONFIG_DBTABLEPREFIX, $content );
  511. file_put_contents( $file2, $content );
  512. // Try to create tables
  513. $definition = @self::$schema->parseDatabaseDefinitionFile( $file2 );
  514. // Delete our temporary file
  515. unlink( $file2 );
  516. // Die in case something went wrong
  517. if( $definition instanceof MDB2_Schema_Error ){
  518. die( $definition->getMessage().': '.$definition->getUserInfo());
  519. }
  520. $ret=@self::$schema->createDatabase( $definition );
  521. // Die in case something went wrong
  522. if( $ret instanceof MDB2_Error ){
  523. die ($ret->getMessage() . ': ' . $ret->getUserInfo());
  524. }
  525. return true;
  526. }
  527. /**
  528. * @brief connects to a MDB2 database scheme
  529. * @returns true/false
  530. *
  531. * Connects to a MDB2 database scheme
  532. */
  533. private static function connectScheme(){
  534. // We need a database connection
  535. self::connect();
  536. // Connect if this did not happen before
  537. if(!self::$schema){
  538. @oc_require_once('MDB2/Schema.php');
  539. self::$schema=&MDB2_Schema::factory(self::$DBConnection);
  540. }
  541. return true;
  542. }
  543. /**
  544. * @brief does minor chages to query
  545. * @param $query Query string
  546. * @returns corrected query string
  547. *
  548. * This function replaces *PREFIX* with the value of $CONFIG_DBTABLEPREFIX
  549. * and replaces the ` woth ' or " according to the database driver.
  550. */
  551. private static function processQuery( $query ){
  552. // We need Database type and table prefix
  553. global $CONFIG_DBTYPE;
  554. global $CONFIG_DBTABLEPREFIX;
  555. // differences in escaping of table names (` for mysql)
  556. // Problem: what if there is a ` in the value we want to insert?
  557. if( $CONFIG_DBTYPE == 'sqlite' ){
  558. $query = str_replace( '`', '\'', $query );
  559. }
  560. elseif( $CONFIG_DBTYPE == 'pgsql' ){
  561. $query = str_replace( '`', '"', $query );
  562. }
  563. // replace table names
  564. $query = str_replace( '*PREFIX*', $CONFIG_DBTABLEPREFIX, $query );
  565. return $query;
  566. }
  567. }
  568. //custom require/include functions because not all hosts allow us to set the include path
  569. function oc_require($file){
  570. global $SERVERROOT;
  571. global $DOCUMENTROOT;
  572. global $WEBROOT;
  573. global $CONFIG_DBNAME;
  574. global $CONFIG_DBHOST;
  575. global $CONFIG_DBUSER;
  576. global $CONFIG_DBPASSWORD;
  577. global $CONFIG_DBTYPE;
  578. global $CONFIG_DATADIRECTORY;
  579. global $CONFIG_HTTPFORCESSL;
  580. global $CONFIG_DATEFORMAT;
  581. global $CONFIG_INSTALLED;
  582. if(is_file($file)){
  583. return require($file);
  584. }
  585. elseif(is_file($SERVERROOT.'/'.$file)){
  586. return require($SERVERROOT.'/'.$file);
  587. }
  588. elseif(is_file($SERVERROOT.'/lib/'.$file)){
  589. return require($SERVERROOT.'/lib/'.$file);
  590. }
  591. elseif(is_file($SERVERROOT.'/3dparty/'.$file)){
  592. return require($SERVERROOT.'/3dparty/'.$file);
  593. }
  594. }
  595. function oc_require_once($file){
  596. global $SERVERROOT;
  597. global $DOCUMENTROOT;
  598. global $WEBROOT;
  599. global $CONFIG_DBNAME;
  600. global $CONFIG_DBHOST;
  601. global $CONFIG_DBUSER;
  602. global $CONFIG_DBPASSWORD;
  603. global $CONFIG_DBTYPE;
  604. global $CONFIG_DATADIRECTORY;
  605. global $CONFIG_HTTPFORCESSL;
  606. global $CONFIG_DATEFORMAT;
  607. global $CONFIG_INSTALLED;
  608. if(is_file($file)){
  609. return require_once($file);
  610. }
  611. elseif(is_file($SERVERROOT.'/'.$file)){
  612. return require_once($SERVERROOT.'/'.$file);
  613. }
  614. elseif(is_file($SERVERROOT.'/lib/'.$file)){
  615. return require_once($SERVERROOT.'/lib/'.$file);
  616. }
  617. elseif(is_file($SERVERROOT.'/3dparty/'.$file)){
  618. return require_once($SERVERROOT.'/3dparty/'.$file);
  619. }
  620. }
  621. function oc_include($file){
  622. global $SERVERROOT;
  623. global $DOCUMENTROOT;
  624. global $WEBROOT;
  625. global $CONFIG_DBNAME;
  626. global $CONFIG_DBHOST;
  627. global $CONFIG_DBUSER;
  628. global $CONFIG_DBPASSWORD;
  629. global $CONFIG_DBTYPE;
  630. global $CONFIG_DATADIRECTORY;
  631. global $CONFIG_HTTPFORCESSL;
  632. global $CONFIG_DATEFORMAT;
  633. global $CONFIG_INSTALLED;
  634. if(is_file($file)){
  635. return include($file);
  636. }
  637. elseif(is_file($SERVERROOT.'/'.$file)){
  638. return include($SERVERROOT.'/'.$file);
  639. }
  640. elseif(is_file($SERVERROOT.'/lib/'.$file)){
  641. return include($SERVERROOT.'/lib/'.$file);
  642. }
  643. elseif(is_file($SERVERROOT.'/3dparty/'.$file)){
  644. return include($SERVERROOT.'/3dparty/'.$file);
  645. }
  646. }
  647. function oc_include_once($file){
  648. global $SERVERROOT;
  649. global $DOCUMENTROOT;
  650. global $WEBROOT;
  651. global $CONFIG_DBNAME;
  652. global $CONFIG_DBHOST;
  653. global $CONFIG_DBUSER;
  654. global $CONFIG_DBPASSWORD;
  655. global $CONFIG_DBTYPE;
  656. global $CONFIG_DATADIRECTORY;
  657. global $CONFIG_HTTPFORCESSL;
  658. global $CONFIG_DATEFORMAT;
  659. global $CONFIG_INSTALLED;
  660. if(is_file($file)){
  661. return include_once($file);
  662. }
  663. elseif(is_file($SERVERROOT.'/'.$file)){
  664. return include_once($SERVERROOT.'/'.$file);
  665. }
  666. elseif(is_file($SERVERROOT.'/lib/'.$file)){
  667. return include_once($SERVERROOT.'/lib/'.$file);
  668. }
  669. elseif(is_file($SERVERROOT.'/3dparty/'.$file)){
  670. return include_once($SERVERROOT.'/3dparty/'.$file);
  671. }
  672. }
  673. function chmodr($path, $filemode) {
  674. // echo "$path<br/>";
  675. if (!is_dir($path))
  676. return chmod($path, $filemode);
  677. $dh = opendir($path);
  678. while (($file = readdir($dh)) !== false) {
  679. if($file != '.' && $file != '..') {
  680. $fullpath = $path.'/'.$file;
  681. if(is_link($fullpath))
  682. return FALSE;
  683. elseif(!is_dir($fullpath) && !chmod($fullpath, $filemode))
  684. return FALSE;
  685. elseif(!chmodr($fullpath, $filemode))
  686. return FALSE;
  687. }
  688. }
  689. closedir($dh);
  690. if(chmod($path, $filemode))
  691. return TRUE;
  692. else
  693. return FALSE;
  694. }
  695. ?>