Added backend locking feature so the existence of the file typo3conf/LOCK_BACKEND...
authorKasper Skårhøj <kasper@typo3.org>
Sat, 31 Jan 2009 13:23:04 +0000 (13:23 +0000)
committerKasper Skårhøj <kasper@typo3.org>
Sat, 31 Jan 2009 13:23:04 +0000 (13:23 +0000)
git-svn-id: https://svn.typo3.org/TYPO3v4/Core/trunk@4901 709f56b5-9817-0410-a4d7-c38de5d9e867

ChangeLog
typo3/init.php
typo3/sysext/lowlevel/admin_cli.php [new file with mode: 0755]
typo3/sysext/lowlevel/class.tx_lowlevel_admin_core.php [new file with mode: 0644]
typo3/sysext/lowlevel/ext_localconf.php

index 712ddeb..35d865e 100755 (executable)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 2009-01-31     Kasper Sk\8crh¿j  <kasper@typo3.org>
 
+       * Added backend locking feature so the existence of the file typo3conf/LOCK_BACKEND will lock down the backend for browser access. For CLI-script processing.
+
+2009-01-31     Kasper Sk\8crh¿j  <kasper@typo3.org>
+
        * Fixed bug that add-wizard did not work with flexform fields.
        
 2009-01-31     Kasper Sk\8crh¿j  <kasper@typo3.org>
index fd9f30c..4a28288 100755 (executable)
@@ -254,6 +254,15 @@ if ($TYPO3_CONF_VARS['BE']['adminOnly'] < 0)       {
        header('Location: http://');    // Just point us away from here...
        exit;   // ... and exit good!
 }
+if (!(defined('TYPO3_cliMode') && TYPO3_cliMode) && @is_file(PATH_typo3conf.'LOCK_BACKEND'))   {
+       $fContent = t3lib_div::getUrl(PATH_typo3conf.'LOCK_BACKEND');
+       if ($fContent)  {
+               header('Location: '.$fContent); // Redirect
+       } else {
+               die('Browser backend is locked for maintenance. Remove lock by removing the file "typo3conf/LOCK_BACKEND" or use CLI-scripts.'.chr(10).chr(10));
+       }
+       exit;
+}
 
 // **********************
 // Check IP
diff --git a/typo3/sysext/lowlevel/admin_cli.php b/typo3/sysext/lowlevel/admin_cli.php
new file mode 100755 (executable)
index 0000000..a990f09
--- /dev/null
@@ -0,0 +1,11 @@
+<?php
+
+if (!defined('TYPO3_cliMode')) die('You cannot run this script directly!');
+
+require_once(t3lib_extMgm::extPath('lowlevel').'class.tx_lowlevel_admin_core.php');
+
+       // Call the functionality
+$adminObj = t3lib_div::makeInstance('tx_lowlevel_admin_core');
+$adminObj->cli_main($_SERVER["argv"]);
+
+?>
\ No newline at end of file
diff --git a/typo3/sysext/lowlevel/class.tx_lowlevel_admin_core.php b/typo3/sysext/lowlevel/class.tx_lowlevel_admin_core.php
new file mode 100644 (file)
index 0000000..edb0d93
--- /dev/null
@@ -0,0 +1,151 @@
+<?php
+/***************************************************************
+*  Copyright notice
+*
+*  (c) 2009 Kasper Skaarhoj (kasperYYYY@typo3.com)
+*  All rights reserved
+*
+*  This script is part of the TYPO3 project. The TYPO3 project is
+*  free software; you can redistribute it and/or modify
+*  it under the terms of the GNU General Public License as published by
+*  the Free Software Foundation; either version 2 of the License, or
+*  (at your option) any later version.
+*
+*  The GNU General Public License can be found at
+*  http://www.gnu.org/copyleft/gpl.html.
+*  A copy is found in the textfile GPL.txt and important notices to the license
+*  from the author is found in LICENSE.txt distributed with these scripts.
+*
+*
+*  This script is distributed in the hope that it will be useful,
+*  but WITHOUT ANY WARRANTY; without even the implied warranty of
+*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+*  GNU General Public License for more details.
+*
+*  This copyright notice MUST APPEAR in all copies of the script!
+***************************************************************/
+/**
+ * Core functions for admin
+ *
+ * $Id: class.tx_lowlevel_admin_core.php 4875 2009-01-27 15:22:12 +0000 (Tue, 27 Jan 2009) kasper $
+ *
+ * @author     Kasper Skårhøj <kasperYYYY@typo3.com>
+ */
+/**
+ * [CLASS/FUNCTION INDEX of SCRIPT]
+ *
+ */
+
+
+require_once(PATH_t3lib.'class.t3lib_admin.php');
+require_once(PATH_t3lib.'class.t3lib_cli.php');
+
+
+
+/**
+ * Core functions for administration
+ *
+ * @author     Kasper Skårhøj <kasperYYYY@typo3.com>
+ * @package TYPO3
+ * @subpackage tx_lowlevel
+ */
+class tx_lowlevel_admin_core extends t3lib_cli {
+
+       var $adminModules = array(
+               'setBElock' => 'Set the Backend Lock',
+               'clearBElock' => 'Clears the Backend Lock',
+               'msg' => 1
+       );
+
+       /**
+        * Constructor
+        *
+        * @return      void
+        */
+       function tx_lowlevel_admin_core()       {
+
+                       // Running parent class constructor
+               parent::t3lib_cli();
+
+                       // Adding options to help archive:
+               $this->cli_options[] = array('--redirect=[URL]', 'For toolkey "setBElock": The URL to which the redirection will occur.');
+
+                       // Setting help texts:
+               $this->cli_help['name'] = 'lowlevel_admin -- Various functions for administration and maintenance of TYPO3 from the command line';
+               $this->cli_help['synopsis'] = 'toolkey ###OPTIONS###';
+               $this->cli_help['description'] = "The 'toolkey' keywords are:\n\n  ".implode("\n  ",array_keys($this->adminModules));
+               $this->cli_help['examples'] = "/.../cli_dispatch.phpsh lowlevel_admin setBElock --redirect=http://url_which_explains_why.com/";
+               $this->cli_help['author'] = "Kasper Skaarhoej, (c) 2009";
+       }
+
+
+
+
+
+
+
+
+
+       /**************************
+        *
+        * CLI functionality
+        *
+        *************************/
+
+       /**
+        * CLI engine
+        *
+        * @param       array           Command line arguments
+        * @return      string
+        */
+       function cli_main($argv) {
+
+                       // Force user to admin state and set workspace to "Live":
+               $GLOBALS['BE_USER']->user['admin'] = 1;
+               $GLOBALS['BE_USER']->setWorkspace(0);
+
+                       // Print help
+               $analysisType = (string)$this->cli_args['_DEFAULT'][1];
+               if (!$analysisType)     {
+                       $this->cli_validateArgs();
+                       $this->cli_help();
+                       exit;
+               }
+
+                       // Analysis type:
+               switch((string)$analysisType)    {
+                       case 'setBElock':
+                               if (@is_file(PATH_typo3conf.'LOCK_BACKEND'))    {
+                                       $this->cli_echo("A lockfile already exists. Overwriting it... \n");
+                               }
+                               $lockFileContent = $this->cli_argValue('--redirect');
+                               t3lib_div::writeFile(PATH_typo3conf.'LOCK_BACKEND', $lockFileContent);
+                               $this->cli_echo("Wrote lock-file to '".PATH_typo3conf."LOCK_BACKEND' with content '".$lockFileContent."'");
+                       break;
+                       case 'clearBElock':
+                               if (@is_file(PATH_typo3conf.'LOCK_BACKEND'))    {
+                                       unlink(PATH_typo3conf.'LOCK_BACKEND');
+                                       if (@is_file(PATH_typo3conf.'LOCK_BACKEND')     )       {
+                                               $this->cli_echo("ERROR: Could not remove lock file '".PATH_typo3conf."LOCK_BACKEND'!!\n",1);
+                                       } else {
+                                               $this->cli_echo("Removed lock file '".PATH_typo3conf."LOCK_BACKEND'\n");
+                                       }
+                               } else {
+                                       $this->cli_echo("No lock file '".PATH_typo3conf."LOCK_BACKEND' was found; hence no lock can be removed.'\n");
+                               }
+                       break;
+                       default:
+                               $this->cli_echo("Unknown toolkey, '".$analysisType."'");
+                       break;
+               }
+               $this->cli_echo("\n");
+       }
+
+
+}
+
+if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/lowlevel/class.tx_lowlevel_admin.php'])       {
+       include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/lowlevel/class.tx_lowlevel_admin.php']);
+}
+
+?>
\ No newline at end of file
index 4e81e2f..1bf8080 100644 (file)
@@ -5,6 +5,7 @@ if (TYPO3_MODE=='BE')   {
                // Setting up scripts that can be run from the cli_dispatch.phpsh script.
        $TYPO3_CONF_VARS['SC_OPTIONS']['GLOBAL']['cliKeys']['lowlevel_refindex'] = array('EXT:lowlevel/dbint/cli/refindex_cli.php','_CLI_lowlevel');
        $TYPO3_CONF_VARS['SC_OPTIONS']['GLOBAL']['cliKeys']['lowlevel_cleaner'] = array('EXT:lowlevel/dbint/cli/cleaner_cli.php','_CLI_lowlevel');
+       $TYPO3_CONF_VARS['SC_OPTIONS']['GLOBAL']['cliKeys']['lowlevel_admin'] = array('EXT:lowlevel/admin_cli.php','_CLI_lowlevel');
        
        $TYPO3_CONF_VARS['EXTCONF']['lowlevel']['cleanerModules']['missing_files'] = array('EXT:lowlevel/clmods/class.missing_files.php:tx_lowlevel_missing_files');
        $TYPO3_CONF_VARS['EXTCONF']['lowlevel']['cleanerModules']['missing_relations'] = array('EXT:lowlevel/clmods/class.missing_relations.php:tx_lowlevel_missing_relations');