Overview

Packages

  • CONTENIDO
  • Core
    • Authentication
    • Backend
    • Cache
    • CEC
    • Chain
    • ContentType
    • Database
    • Debug
    • Exception
    • Frontend
      • Search
      • URI
      • Util
    • GenericDB
      • Model
    • GUI
      • HTML
    • I18N
    • LayoutHandler
    • Log
    • Security
    • Session
    • Util
    • Validation
    • Versioning
    • XML
  • Module
    • ContentSitemapHtml
    • ContentSitemapXml
    • ContentUserForum
    • NavigationTop
    • ScriptCookieDirective
  • mpAutoloaderClassMap
  • None
  • PHP
  • Plugin
    • ContentAllocation
    • CronjobOverview
    • FormAssistant
    • FrontendLogic
    • FrontendUsers
    • Linkchecker
    • ModRewrite
    • Newsletter
    • Repository
      • FrontendNavigation
      • KeywordDensity
    • SmartyWrapper
    • UrlShortener
    • UserForum
    • Workflow
  • PluginManager
  • Setup
    • Form
    • GUI
    • Helper
      • Environment
      • Filesystem
      • MySQL
      • PHP
    • UpgradeJob

Classes

  • cCLISetup
  • cSetupLanguageChooser
  • cSetupNotInstallable
  • cSetupTypeChooser

Functions

  • checkAndInclude
  • checkExistingPlugin
  • checkInstallationSettings
  • findSimilarText
  • getArgs
  • getContenidoVersion
  • getSystemDirectories
  • initializeVariables
  • listClients
  • passwordPrompt
  • printHelpText
  • prnt
  • prntln
  • prntst
  • progressBar
  • stripLastSlash
  • updateClientPath
  • updateContenidoVersion
  • updateSysadminPassword
  • updateSystemProperties
  • Overview
  • Package
  • Class
  • Tree
  • Deprecated
  • Todo
  1: <?php
  2: /**
  3:  * Provides functions to gather the necessary settings for autoinstall.php
  4:  *
  5:  * @package Setup
  6:  * @subpackage Setup
  7:  * @author Mischa Holz
  8:  * @copyright four for business AG <www.4fb.de>
  9:  * @license http://www.contenido.org/license/LIZENZ.txt
 10:  * @link http://www.4fb.de
 11:  * @link http://www.contenido.org
 12:  */
 13: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
 14: 
 15: /**
 16:  * Provides functions to gather the necessary settings for autoinstall.php
 17:  *
 18:  * @package Setup
 19:  * @subpackage Setup
 20:  */
 21: class cCLISetup {
 22: 
 23:     /**
 24:      * holds the setup settings
 25:      * @var array
 26:      */
 27:     protected $_settings;
 28: 
 29:     /**
 30:      * holds the command line options
 31:      * @var array
 32:      */
 33:     protected $_args;
 34: 
 35:     /**
 36:      * path to the settings files
 37:      * @var string
 38:      */
 39:     protected $_settingsFile;
 40: 
 41:     /**
 42:      * Initiliazes the class and sets standard values for some settings
 43:      *
 44:      * @param array $args the parsed command line
 45:      */
 46:     public function __construct($args) {
 47: 
 48:         $this->_settings['db']['host'] = 'localhost';
 49:         $this->_settings['db']['user'] = 'root';
 50:         $this->_settings['db']['password'] = '';
 51:         $this->_settings['db']['charset'] = 'utf8';
 52:         $this->_settings['db']['collation'] = 'utf8_general_ci';
 53:         $this->_settings['db']['database'] = 'contenido';
 54:         $this->_settings['db']['prefix'] = 'con';
 55: 
 56:         $this->_settings['paths']['http_root_path'] = '';
 57: 
 58:         $this->_settings['setup']['client_mode'] = '';
 59: 
 60:         $this->_settings['admin_user']['password'] = '';
 61:         $this->_settings['admin_user']['email'] = '';
 62: 
 63:         $this->_args = $args;
 64: 
 65:         $this->_args['interactive'] = isset($this->_args['interactive']) || isset($this->_args['i']); // -i can be used instead of --interactive
 66: 
 67:         // the setup will search for autoinstall.ini first or use the file which is passed to the script with the --file switch
 68:         $this->_settingsFile = 'autoinstall.ini';
 69:     }
 70: 
 71:     /**
 72:      * Reads all parameters and gathers the settings for the installation accordingly
 73:      */
 74:     public function interpretCommandline() {
 75:         global $belang;
 76: 
 77:         $belang = ($this->_args['locale']) ? $this->_args['locale'] : "en_US"; // setting the language
 78: 
 79:         cI18n::init(CON_SETUP_PATH . '/locale/', $belang, 'setup');
 80: 
 81:         // check if we just need to print the help text
 82:         if (isset($this->_args['h']) || $this->_args['help']) {
 83:             printHelpText();
 84:             exit(0);
 85:         }
 86: 
 87:         // set the configuration file
 88:         if (isset($this->_args['file'])) {
 89:             $this->_settingsFile = $this->_args['file'];
 90:         }
 91: 
 92:         prntln("\r" . i18n('This program will install CONTENIDO on this computer.', 'setup'));
 93: 
 94:         // first check for the interactive switch
 95:         if ($this->_args['interactive']) {
 96:             // user wants the setup to be interactive - ignore any files and start the configuration
 97:             prntln();
 98:             prntln();
 99:             // the settings from the command line overwrite the settings but the UI settings overwrite everything
100:             // settings from the command line and the file (if existent) will be provided to the user as standard values for the questions
101:             $this->getSettingsFromFile($this->_settingsFile);
102:             $this->getSettingsFromCommandLine();
103:             $this->getUserInputSettings();
104:         } else if ($this->_args['noninteractive']) {
105:             // user does not want the setup to be interactive - look for the file
106:             echo(i18n('Looking for ', 'setup') . $this->_settingsFile . '...');
107:             if (file_exists($this->_settingsFile)) {
108:                 // file found - read the settings and start installing
109:                 prntln(i18n('found', 'setup'));
110:                 prntln(i18n('CONTENIDO will use the specified settings from ', 'setup') . $this->_settingsFile);
111:                 prntln();
112:                 $this->getSettingsFromFile($this->_settingsFile);
113:                 $this->getSettingsFromCommandLine();
114:                 $this->printSettings();
115:             } else {
116:                 // file not found - print error message and exit, since the user specifically said he wanted to use the file
117:                 prntln(i18n('not found', 'setup'));
118:                 prntln(sprintf(i18n('CONTENIDO was unable to locate the configuration file %s, but you asked to use it.', 'setup'), $this->_settingsFile));
119:                 prntln(i18n('Setup can not continue.', 'setup'));
120:                 exit(1);
121:             }
122:         } else {
123:             // default mode - look for the file. if it's there, use it. Otherwise start the interactive setup
124:             echo(i18n('Looking for ', 'setup') . $this->_settingsFile . '...');
125:             if (file_exists($this->_settingsFile)) {
126:                 // read the file
127:                 prntln(i18n('found', 'setup'));
128:                 prntln(i18n('CONTENIDO will use the specified settings from ', 'setup') . $this->_settingsFile);
129:                 prntln();
130:                 $this->getSettingsFromFile($this->_settingsFile);
131:                 $this->getSettingsFromCommandLine();
132:                 $this->printSettings();
133:             } else {
134:                 // start the interactive setup
135:                 prntln(i18n('not found', 'setup'));
136:                 prntln();
137:                 prntln();
138:                 $this->getSettingsFromFile($this->_settingsFile);
139:                 $this->getSettingsFromCommandLine();
140:                 $this->getUserInputSettings();
141:             }
142:         }
143:     }
144: 
145:     /**
146:      * Prints the settings json encoded to the console but removes passwords from it
147:      */
148:     public function printSettings() {
149:         prntln(i18n('CONTENIDO will be installed with the following settings: ', 'setup'));
150:         $noPasswordArray = $this->_settings;
151:         $noPasswordArray['db']['password'] = '**********';
152:         $noPasswordArray['admin_user']['password'] =  '**********';
153:         prntln(json_encode($noPasswordArray));
154:     }
155: 
156:     /**
157:      * Read the settings from various parameters from the command line
158:      */
159:     public function getSettingsFromCommandLine() {
160:         $this->_settings['db']['host'] = ($this->_args['dbhost'] == '') ? $this->_settings['db']['host'] : $this->_args['dbhost'];
161:         $this->_settings['db']['user'] = ($this->_args['dbuser'] == '') ? $this->_settings['db']['user'] : $this->_args['dbuser'];
162:         $this->_settings['db']['password'] = ($this->_args['dbpassword'] == '') ? $this->_settings['db']['password'] : $this->_args['dbpassword'];
163:         $this->_settings['db']['charset'] = ($this->_args['dbcharset'] == '') ? $this->_settings['db']['charset'] : $this->_args['dbcharset'];
164:         $this->_settings['db']['collation'] = ($this->_args['dbcollation'] == '') ? $this->_settings['db']['collation'] : $this->_args['dbcollation'];
165:         $this->_settings['db']['database'] = ($this->_args['dbdatabase'] == '') ? $this->_settings['db']['database'] : $this->_args['dbdatabase'];
166:         $this->_settings['db']['prefix'] = ($this->_args['dbprefix'] == '') ? $this->_settings['db']['prefix'] : $this->_args['dbprefix'];
167: 
168:         $this->_settings['paths']['http_root_path'] = ($this->_args['pathshttprootpath'] == '') ? $this->_settings['paths']['http_root_path'] : $this->_args['pathshttprootpath'];
169: 
170:         $this->_settings['setup']['client_mode'] = ($this->_args['setupclientmode'] == '') ? $this->_settings['setup']['client_mode'] : $this->_args['setupclientmode'];
171: 
172:         $this->_settings['admin_user']['password'] = ($this->_args['adminuserpassword'] == '') ? $this->_settings['admin_user']['password'] : $this->_args['adminuserpassword'];
173:         $this->_settings['admin_user']['email'] = ($this->_args['adminuseremail'] == '') ? $this->_settings['admin_user']['email'] : $this->_args['adminuseremail'];
174:         $this->_settings['advanced']['delete_database'] = ($this->_args['advanceddeletedatabase'] == '') ? $this->_settings['advanced']['delete_database'] : $this->_args['advanceddeletedatabase'];
175:     }
176: 
177:     /**
178:      * Start a dialog with the user to get the settings
179:      */
180:     public function getUserInputSettings() {
181: 
182:         // print welcome message
183:         prntln('>>>>> '. i18n('Welcome to CONTENIDO', 'setup'). ' <<<<<');
184:         prntln('');
185:         prntln(i18n('Database settings:', 'setup'));
186: 
187:         // database host
188:         prnt(i18n('Host', 'setup') . ' [' . $this->_settings['db']['host'] . ']: ', 1);
189:         $line = trim(fgets(STDIN));
190:         $this->_settings['db']['host'] = ($line == "") ? $this->_settings['db']['host'] : $line;
191: 
192:         // database user
193:         prnt(i18n('User', 'setup') . ' [' . $this->_settings['db']['user'] . ']: ', 1);
194:         $line = trim(fgets(STDIN));
195:         $this->_settings['db']['user'] = ($line == "") ? $this->_settings['db']['user'] : $line;
196: 
197:         // database password
198:         $dbpw = passwordPrompt(i18n('Password', 'setup'), 1);
199:         $this->_settings['db']['password'] = ($dbpw == '') ? $this->_settings['db']['password'] : $dbpw;
200: 
201:         // database name
202:         prnt(i18n('Database name', 'setup') .' [' . $this->_settings['db']['database'] . ']: ', 1);
203:         $line = trim(fgets(STDIN));
204:         $this->_settings['db']['database'] = ($line == "") ? $this->_settings['db']['database'] : $line;
205: 
206:         // database charset
207:         prnt(i18n('Charset', 'setup') . ' [' . $this->_settings['db']['charset'] . ']: ', 1);
208:         $line = trim(fgets(STDIN));
209:         $this->_settings['db']['charset'] = ($line == "") ? $this->_settings['db']['charset'] : $line;
210: 
211:         // database collation
212:         prnt(i18n('Collation', 'setup') . ' [' . $this->_settings['db']['collation'] . ']: ', 1);
213:         $line = trim(fgets(STDIN));
214:         $this->_settings['db']['collation'] = ($line == "") ? $this->_settings['db']['collation'] : $line;
215: 
216:         // database prefix
217:         prnt(i18n('Prefix', 'setup') . ' [' . $this->_settings['db']['prefix'] . ']: ', 1);
218:         $line = trim(fgets(STDIN));
219:         $this->_settings['db']['prefix'] = ($line == "") ? $this->_settings['db']['prefix'] : $line;
220: 
221:         // http root path
222:         prntln();
223:         prntln(i18n('Please enter the http path to where the contenido/ folder resides', 'setup'));
224:         prntln(i18n('e.g. http://localhost/', 'setup'));
225:         prnt(i18n('Backend web path', 'setup') .' [' . $this->_settings['paths']['http_root_path'] . ']: ', 1);
226:         $line = trim(fgets(STDIN));
227:         $this->_settings['paths']['http_root_path'] = ($line == "") ? $this->_settings['paths']['http_root_path'] : $line;
228: 
229:         // ask for the setup mode
230:         prntln();
231:         $displayStandard = i18n('yes', 'setup');
232:         if ($this->_settings['setup']['client_mode'] == 'CLIENTMODULES') {
233:             $displayStandard = i18n('modules', 'setup');
234:         } else if ($this->_settings['setup']['client_mode'] == 'NOCLIENT') {
235:             $displayStandard = i18n('no', 'setup');
236:         }
237:         $first = true;
238:         while ($this->_settings['setup']['client_mode'] == "" || $first) {
239:             $first = false;
240:             prntln(i18n('Do you want to install the example client?', 'setup'));
241:             prntln(i18n('Please choose "yes" (to install the modules AND the content), "modules" (to install only the modules) or "no"', 'setup'));
242:             prnt(i18n('Examples? (yes/modules/no)', 'setup') . '[' . $displayStandard . ']: ', 1);
243:             $line = cString::toLowerCase(trim(fgets(STDIN)));
244:             if ($line == "") {
245:                 $line = $displayStandard;
246:             }
247:             if ($line == 'yes' || $line == i18n('yes', 'setup')) {
248:                 $this->_settings['setup']['client_mode'] = 'CLIENTEXAMPLES';
249:             } else if ($line == 'modules' || $line == i18n('modules', 'setup')) {
250:                 $this->_settings['setup']['client_mode'] = 'CLIENTMODULES';
251:             } else if ($line == 'no' || $line == i18n('no', 'setup')) {
252:                 $this->_settings['setup']['client_mode'] = 'NOCLIENT';
253:             }
254:         }
255: 
256:         // admin password
257:         $password1 = "something";
258:         $password2 = "something else";
259:         prntln();
260:         prntln(i18n('Admin information:'));
261:         while ($password1 != $password2) {
262:             prntln(i18n('You have to enter the password twice and they have to match', 'setup'), 1);
263:             $password1 = passwordPrompt(i18n('Admin password', 'setup'), 1);
264: 
265:             $password2 = passwordPrompt(i18n('Repeat admin password', 'setup'), 1);
266:         }
267:         $this->_settings['admin_user']['password'] = ($password1 == '') ? $this->_settings['admin_user']['password'] : $password1;
268: 
269:         // admin email
270:         prnt(i18n('Admin email', 'setup') . ' [' . $this->_settings['admin_user']['email'] . ']: ', 1);
271:         $line = trim(fgets(STDIN));
272:         $this->_settings['admin_user']['email'] = ($line == "") ? $this->_settings['admin_user']['email'] : $line;
273: 
274:         // print thank you
275:         prntln(i18n('Thank you.', 'setup'));
276:         prntln();
277:         prntln();
278:     }
279: 
280:     /**
281:      * Reads the specified file and saves the values in the appropriate places
282:      *
283:      * @param string $file path to the file
284:      */
285:     public function getSettingsFromFile($file) {
286:         if (!cFileHandler::exists($file)) {
287:             return;
288:         }
289: 
290:         $ext = cString::toLowerCase(pathinfo($file, PATHINFO_EXTENSION));
291: 
292:         switch ($ext) {
293:             case 'ini':
294:                 $this->_settings = parse_ini_file($file, true);
295:                 break;
296:             case 'xml':
297:                 $xml = simplexml_load_file($file);
298:                 if (!$xml) {
299:                     return;
300:                 }
301: 
302:                 $this->_settings['db']['host'] = trim($xml->db->host);
303:                 $this->_settings['db']['user'] = trim($xml->db->user);
304:                 $this->_settings['db']['password'] = trim($xml->db->password);
305:                 $this->_settings['db']['charset'] = trim($xml->db->charset);
306:                 $this->_settings['db']['database'] = trim($xml->db->database);
307:                 $this->_settings['db']['prefix'] = trim($xml->db->prefix);
308:                 $this->_settings['db']['collation'] = trim($xml->db->collation);
309: 
310:                 $this->_settings['paths']['http_root_path'] = trim($xml->path->http_root_path);
311: 
312:                 $this->_settings['setup']['client_mode'] = trim($xml->client->client_mode);
313: 
314:                 $this->_settings['admin_user']['password'] = trim($xml->admin_user->password);
315:                 $this->_settings['admin_user']['email'] = trim($xml->admin_user->email);
316:                 $this->_settings['advanced']['delete_database'] = trim($xml->advanced->delete_database);
317:                 break;
318:             case 'json':
319:                 $this->_settings = json_decode(file_get_contents($file), true);
320:                 break;
321:         }
322: 
323:     }
324: 
325:     /**
326:      * Executes the CONTENIDO system tests and prints the result to the user.
327:      * In case of an error it asks if the user wants to continue anyway and,
328:      * if not, quits the script.
329:      *
330:      */
331:     public function executeSystemTests() {
332:         global $args, $belang;
333: 
334:         $cfg = cRegistry::getConfig();
335: 
336:         if ($this->_settings['advanced']['delete_database'] == '1' || $this->_settings['advanced']['delete_database'] == 'YES') {
337:             $answer = '';
338:             while ($answer != 'Y' && $answer != 'N') {
339:                 prnt(sprintf(i18n("You chose in the configuration file to delete the database '%s' before installing.\nDO YOU REALLY WANT TO CONTINUE WITH DELETING THIS DATABASE? (Y/N) [N]: ", 'setup'), $this->_settings['db']['database']));
340:                 $answer = trim(fgets(STDIN));
341:                 if ($answer == "") {
342:                     $answer = "N";
343:                 }
344:             }
345:             if ($answer != "Y") {
346:                 exit(3);
347:             }
348: 
349:             $db = getSetupMySQLDBConnection(false);
350:             $db->query('DROP DATABASE ' . $this->_settings['db']['database']);
351: 
352:             prntln();
353:             prntln(sprintf(i18n('THE DATABASE %s HAS BEEN DELETED!!!', 'setup'), $this->_settings['db']['database']));
354:             prntln();
355:         }
356: 
357:         prnt(i18n('Testing your system...', 'setup'));
358: 
359:         $fine = true;
360: 
361:         // load the CONTENIDO locale for the test results
362:         i18nInit('../data/locale/', $belang);
363: 
364:         // run the tests
365:         $test = new cSystemtest($cfg);
366:         $test->runTests(false); // general php tests
367:         $test->testFilesystem(true, false); // file system permission tests
368:         $test->testFrontendFolderCreation(); // more file system permission tests
369:         $test->checkSetupMysql('setup', $cfg['db']['connection']['database'], $_SESSION['dbprefix'], $_SESSION['dbcharset'], $_SESSION['dbcollation']); // test the SQL connection and database creation
370: 
371:         $testResults = $test->getResults();
372: 
373:         foreach ($testResults as $testResult) {
374:             if ($testResult["severity"] == cSystemtest::C_SEVERITY_NONE) {
375:                 continue;
376:             }
377: 
378:             if ($testResult['result'] == false) {
379:                 $fine = false;
380:             }
381:         }
382:         if (!$fine) {
383:             prntln(i18n('error', 'setup'));
384:             foreach ($testResults as $testResult) {
385:                 if ($testResult["severity"] == cSystemtest::C_SEVERITY_NONE) {
386:                     continue;
387:                 }
388: 
389:                 if ($testResult['result'] == false) {
390:                     prntln(html_entity_decode(strip_tags($testResult['headline'], 1)));
391:                     prntln(html_entity_decode(strip_tags($testResult['message'], 2)));
392:                 }
393:             }
394:             prntln();
395:             prntln(i18n('There have been errors during the system check.', 'setup'));
396:             prntln(i18n('However this might be caused by differing configurations between the CLI php and the CGI php.', 'setup'));
397: 
398:             if ($args['noninteractive']) {
399:                 exit(3);
400:             }
401: 
402:             $answer = '';
403:             while ($answer != 'y' && $answer != 'n' && $answer != i18n('y', 'setup') && $answer != i18n('n', 'setup')) {
404:                 prnt(i18n('Do you want to continue despite the errors? (y/n) [n]: ', 'setup'));
405:                 $answer = trim(fgets(STDIN));
406:                 if ($answer == "") {
407:                     $answer = "n";
408:                 }
409:             }
410:             if (cString::toLowerCase($answer) == "n" || cString::toLowerCase($answer) == cString::toLowerCase(i18n('n', 'setup'))) {
411:                 exit(3);
412:             }
413:         } else {
414:             prntln(i18n('Your system seems to be okay.', 'setup'));
415:             prntln();
416:         }
417:     }
418: 
419:     /**
420:      * Take the settings from the settings array and write them to the appropriate places
421:      */
422:     public function applySettings() {
423: 
424:         $cfg = cRegistry::getConfig();
425: 
426:         $cfg['db'] = array(
427:             'connection' => array(
428:                 'host'     => $this->_settings['db']['host'],
429:                 'user'     => $this->_settings['db']['user'],
430:                 'password' => $this->_settings['db']['password'],
431:                 'charset'  => $this->_settings['db']['charset'],
432:                 'database' => $this->_settings['db']['database']
433:             ),
434:             'haltBehavior'    => 'report',
435:             'haltMsgPrefix'   => (isset($_SERVER['REQUEST_URI'])) ? $_SERVER['REQUEST_URI'] . ' ' : '',
436:             'enableProfiling' => false
437:         );
438:         $_SESSION['setuptype'] = 'setup';
439:         $_SESSION['dbname'] = $this->_settings['db']['database'];
440:         $_SESSION['configmode'] = 'save';
441:         $_SESSION['override_root_http_path'] = $this->_settings['paths']['http_root_path'];
442:         $_SESSION['clientmode'] = $this->_settings['setup']['client_mode'];
443:         $_SESSION['adminpass'] = $this->_settings['admin_user']['password'];
444:         $_SESSION['adminmail'] = $this->_settings['admin_user']['email'];
445:         $_SESSION['dbprefix'] = $this->_settings['db']['prefix'];
446:         $_SESSION['dbcollation'] = $this->_settings['db']['collation'];
447:         $_SESSION['dbcharset'] = $this->_settings['db']['charset'];
448:         $cfg['sql']['sqlprefix'] = $this->_settings['db']['prefix'];
449:         // reload cfg_sql.inc.php because new sql prefix will change resulting array data
450:         include($cfg['path']['contenido_config'] . 'cfg_sql.inc.php');
451:     }
452: }
453: 
CMS CONTENIDO 4.10.0 API documentation generated by ApiGen 2.8.0