Example #1
0
/**
 * Write the main system config file
 * @param string $path Path to the config file
 */
function write_system_config_file($path)
{
    global $dbHostForm;
    global $dbUsernameForm;
    global $dbPassForm;
    global $dbNameForm;
    global $urlForm;
    global $pathForm;
    global $urlAppendPath;
    global $languageForm;
    global $encryptPassForm;
    global $session_lifetime;
    global $new_version;
    global $new_version_stable;
    $root_sys = api_add_trailing_slash(str_replace('\\', '/', realpath($pathForm)));
    $content = file_get_contents(dirname(__FILE__) . '/' . SYSTEM_CONFIG_FILENAME);
    $config['{DATE_GENERATED}'] = date('r');
    $config['{DATABASE_HOST}'] = $dbHostForm;
    $config['{DATABASE_USER}'] = $dbUsernameForm;
    $config['{DATABASE_PASSWORD}'] = $dbPassForm;
    $config['{DATABASE_MAIN}'] = $dbNameForm;
    $config['{ROOT_WEB}'] = $urlForm;
    $config['{ROOT_SYS}'] = $root_sys;
    $config['{URL_APPEND_PATH}'] = $urlAppendPath;
    $config['{PLATFORM_LANGUAGE}'] = $languageForm;
    $config['{SECURITY_KEY}'] = md5(uniqid(rand() . time()));
    $config['{ENCRYPT_PASSWORD}'] = $encryptPassForm;
    $config['SESSION_LIFETIME'] = $session_lifetime;
    $config['{NEW_VERSION}'] = $new_version;
    $config['NEW_VERSION_STABLE'] = trueFalse($new_version_stable);
    foreach ($config as $key => $value) {
        $content = str_replace($key, $value, $content);
    }
    $fp = @fopen($path, 'w');
    if (!$fp) {
        echo '<strong><font color="red">Your script doesn\'t have write access to the config directory</font></strong><br />
                        <em>(' . str_replace('\\', '/', realpath($path)) . ')</em><br /><br />
                        You probably do not have write access on Chamilo root directory,
                        i.e. you should <em>CHMOD 777</em> or <em>755</em> or <em>775</em>.<br /><br />
                        Your problems can be related on two possible causes:<br />
                        <ul>
                          <li>Permission problems.<br />Try initially with <em>chmod -R 777</em> and increase restrictions gradually.</li>
                          <li>PHP is running in <a href="http://www.php.net/manual/en/features.safe-mode.php" target="_blank">Safe-Mode</a>. If possible, try to switch it off.</li>
                        </ul>
                        <a href="http://forum.chamilo.org/" target="_blank">Read about this problem in Support Forum</a><br /><br />
                        Please go back to step 5.
                        <p><input type="submit" name="step5" value="&lt; Back" /></p>
                        </td></tr></table></form></body></html>';
        exit;
    }
    fwrite($fp, $content);
    fclose($fp);
}
Example #2
0
            $ext_loaded = ' (extension not loaded)';
        }
        $diag_mesgs .= "GD version is set to {$convert_GD_ver}{$ext_loaded},&nbsp; ";
    } else {
        if ($gdv = gdVersion()) {
            $diag_mesgs .= "GD version {$gdv} detected,&nbsp; ";
        } else {
            $diag_mesgs .= "GD is not detected,&nbsp; ";
        }
    }
    if (eregi('/phpinfo/', ini_get('disable_functions'))) {
        $diag_mesgs .= "phpinfo() function is disabled<br />\n";
    } else {
        $diag_mesgs .= "phpinfo() function is enabled<br />\n";
    }
    $diag_mesgs .= '$convert_writable is ' . trueFalse($convert_writable) . ',&nbsp; ' . '$convert_readable is ' . trueFalse($convert_readable) . ',&nbsp; ' . '$reqd_view is ' . $reqd_view . "<br />\n" . '$thmbs_ena is ' . trueFalse($thmbs_ena) . ',&nbsp; ' . '$namelinks_ena is ' . trueFalse($namelinks_ena) . ',&nbsp; ' . '$check_security is ' . trueFalse($check_security) . "<br />\n" . '$is_readable_disa is ' . trueFalse($is_readable_disa) . ',&nbsp; ' . '$file_exists_disa is ' . trueFalse($file_exists_disa) . ',&nbsp; ' . '$compat_quote is ' . trueFalse($compat_quote) . "<br /></span>\n";
}
/*
+----------+
|  Output  |
+----------+
*/
/**
* Echo an HTML header if the script is running stand-alone.
*/
echo htmlHeader($header);
/**
* Image is a popup target (experimental).
*/
if (@$get_vars['Qtmp'] == 'popup') {
    echo displayImage($reqd_image, $img_sz_labels);
Example #3
0
 /**
  * Save all properties in config file
  */
 function save($generatorFile = __FILE__)
 {
     // split generation file
     if (strlen($generatorFile) > 50) {
         $generatorFile = str_replace("\\", "/", $generatorFile);
         $generatorFile = "\n\t\t" . str_replace("/", "\n\t\t/", $generatorFile);
     }
     $fileHeader = '<?php ' . "\n" . '/** ' . ' * DONT EDIT THIS FILE - NE MODIFIEZ PAS CE FICHIER ' . "\n" . ' * -------------------------------------------------' . "\n" . ' * Generated by ' . $generatorFile . ' ' . "\n" . ' * Date ' . claro_html_localised_date(get_locale('dateTimeFormatLong')) . "\n" . ' * -------------------------------------------------' . "\n" . ' * DONT EDIT THIS FILE - NE MODIFIEZ PAS CE FICHIER ' . "\n" . ' **/' . "\n\n";
     $fileHeader .= '// $' . $this->config_code . 'GenDate is an internal mark' . "\n" . '   $' . $this->config_code . 'GenDate = "' . time() . '";' . "\n\n";
     if (!empty($this->conf_def['technicalInfo'])) {
         $fileHeader .= '/*' . str_replace('*/', '* /', $this->conf_def['technicalInfo']) . '*/';
     }
     // open configuration file
     if (false !== ($handle = @fopen($this->config_filename, 'w'))) {
         // write header
         fwrite($handle, $fileHeader);
         foreach ($this->property_list as $name => $value) {
             // build comment about the property
             $propertyComment = '';
             // comment : add description
             if (!empty($this->conf_def_property_list[$name]['description'])) {
                 $propertyComment .= '/* ' . $name . ' : ' . str_replace("\n", '', $this->conf_def_property_list[$name]['description']) . ' */' . "\n";
             } else {
                 if (isset($this->conf_def_property_list[$name]['label'])) {
                     $propertyComment .= '/* ' . $name . ' : ' . str_replace("\n", "", $this->conf_def_property_list[$name]['label']) . ' */' . "\n";
                 }
             }
             // comment : add technical info
             if (!empty($this->conf_def_property_list[$name]['technicalInfo'])) {
                 $propertyComment .= '/*' . "\n" . str_replace('*/', '* /', $this->conf_def_property_list[$name]['technicalInfo']) . "\n" . '*/' . "\n";
             }
             // property type define how to write the value
             switch ($this->conf_def_property_list[$name]['type']) {
                 case 'boolean':
                     if (is_bool($value)) {
                         $valueToWrite = trueFalse($value);
                     } else {
                         switch (strtoupper($value)) {
                             case 'TRUE':
                             case '1':
                                 $valueToWrite = 'TRUE';
                                 break;
                             case 'FALSE':
                             case '0':
                                 $valueToWrite = 'FALSE';
                                 break;
                             default:
                                 trigger_error('$value is not a boolean ', E_USER_NOTICE);
                                 return false;
                         }
                     }
                     break;
                 case 'integer':
                     $valueToWrite = $value;
                     break;
                 case 'multi':
                     $valueToWrite = 'array(';
                     if (!empty($value) && is_array($value)) {
                         $valueToWrite .= '\'' . implode('\',\'', $value) . '\'';
                     }
                     $valueToWrite .= ')';
                     break;
                 default:
                     $valueToWrite = "'" . str_replace("'", "\\'", $value) . "'";
                     break;
             }
             // container : Constance or variable
             if (isset($this->conf_def_property_list[$name]['container']) && strtoupper($this->conf_def_property_list[$name]['container']) == 'CONST') {
                 $propertyLine = 'if (!defined("' . $name . '")) define("' . $name . '",' . $valueToWrite . ');' . "\n";
             } else {
                 $propertyLine = '$GLOBALS[\'' . $name . '\'] = ' . $valueToWrite . ';' . "\n";
                 // $propertyLine = '$'.$name.' = '. $valueToWrite .';'."\n";
                 // in the next version, config would change to
                 // $propertyLine .= '$_conf[\''.$name.'\'] = '. $valueToWrite .';'."\n";
             }
             $propertyLine .= "\n\n";
             fwrite($handle, $propertyComment);
             fwrite($handle, $propertyLine);
         }
         fwrite($handle, "\n" . '?>');
         fclose($handle);
         // save the new md5 value
         $this->save_md5();
         return true;
     } else {
         $this->backlog->failure(get_lang('Cannot open %filename', array('%filename' => $this->config_filename)));
         return false;
     }
 }