Overview

Packages

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