fileconf.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737
  1. <?php
  2. /* Copyright (C) 2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com>
  4. * Copyright (C) 2004-2012 Laurent Destailleur <eldy@users.sourceforge.net>
  5. * Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be>
  6. * Copyright (C) 2004 Sebastien DiCintio <sdicintio@ressource-toi.org>
  7. * Copyright (C) 2005-2011 Regis Houssin <regis.houssin@inodbox.com>
  8. * Copyright (C) 2016 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 3 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  22. */
  23. /**
  24. * \file htdocs/install/fileconf.php
  25. * \ingroup install
  26. * \brief Ask all information required to build Dolibarr htdocs/conf/conf.php file (will be written to disk on next page step1)
  27. */
  28. include_once 'inc.php';
  29. global $langs;
  30. $err = 0;
  31. $setuplang = GETPOST("selectlang", 'alpha', 3) ? GETPOST("selectlang", 'alpha', 3) : (GETPOST('lang', 'alpha', 1) ? GETPOST('lang', 'alpha', 1) : 'auto');
  32. $langs->setDefaultLang($setuplang);
  33. $langs->loadLangs(array("install", "errors"));
  34. dolibarr_install_syslog("- fileconf: entering fileconf.php page");
  35. // You can force preselected values of the config step of Dolibarr by adding a file
  36. // install.forced.php into directory htdocs/install (This is the case with some wizard
  37. // installer like DoliWamp, DoliMamp or DoliBuntu).
  38. // We first init "forced values" to nothing.
  39. if (!isset($force_install_noedit)) {
  40. $force_install_noedit = ''; // 1=To block vars specific to distrib, 2 to block all technical parameters
  41. }
  42. if (!isset($force_install_type)) {
  43. $force_install_type = '';
  44. }
  45. if (!isset($force_install_dbserver)) {
  46. $force_install_dbserver = '';
  47. }
  48. if (!isset($force_install_port)) {
  49. $force_install_port = '';
  50. }
  51. if (!isset($force_install_database)) {
  52. $force_install_database = '';
  53. }
  54. if (!isset($force_install_prefix)) {
  55. $force_install_prefix = '';
  56. }
  57. if (!isset($force_install_createdatabase)) {
  58. $force_install_createdatabase = '';
  59. }
  60. if (!isset($force_install_databaselogin)) {
  61. $force_install_databaselogin = '';
  62. }
  63. if (!isset($force_install_databasepass)) {
  64. $force_install_databasepass = '';
  65. }
  66. if (!isset($force_install_databaserootlogin)) {
  67. $force_install_databaserootlogin = '';
  68. }
  69. if (!isset($force_install_databaserootpass)) {
  70. $force_install_databaserootpass = '';
  71. }
  72. // Now we load forced values from install.forced.php file.
  73. $useforcedwizard = false;
  74. $forcedfile = "./install.forced.php";
  75. if ($conffile == "/etc/dolibarr/conf.php") {
  76. $forcedfile = "/etc/dolibarr/install.forced.php"; // Must be after inc.php
  77. }
  78. if (@file_exists($forcedfile)) {
  79. $useforcedwizard = true;
  80. include_once $forcedfile;
  81. }
  82. /*
  83. * View
  84. */
  85. session_start(); // To be able to keep info into session (used for not losing pass during navigation. pass must not transit through parmaeters)
  86. pHeader($langs->trans("ConfigurationFile"), "step1", "set", "", (empty($force_dolibarr_js_JQUERY) ? '' : $force_dolibarr_js_JQUERY.'/'), 'main-inside-bis');
  87. // Test if we can run a first install process
  88. if (!is_writable($conffile)) {
  89. print $langs->trans("ConfFileIsNotWritable", $conffiletoshow);
  90. dolibarr_install_syslog("fileconf: config file is not writable", LOG_WARNING);
  91. dolibarr_install_syslog("- fileconf: end");
  92. pFooter(1, $setuplang, 'jscheckparam');
  93. exit;
  94. }
  95. if (!empty($force_install_message)) {
  96. print '<div><br>'.$langs->trans($force_install_message).'</div>';
  97. /*print '<script type="text/javascript">';
  98. print ' jQuery(document).ready(function() {
  99. jQuery("#linktoshowtechnicalparam").click(function() {
  100. jQuery(".hidewhenedit").hide();
  101. jQuery(".hidewhennoedit").show();
  102. });';
  103. if ($force_install_noedit) print 'jQuery(".hidewhennoedit").hide();';
  104. print '});';
  105. print '</script>';
  106. print '<br><a href="#" id="linktoshowtechnicalparam" class="hidewhenedit">'.$langs->trans("ShowEditTechnicalParameters").'</a><br>';
  107. */
  108. }
  109. ?>
  110. <div>
  111. <table class="nobordernopadding<?php if ($force_install_noedit) {
  112. print ' hidewhennoedit';
  113. } ?>">
  114. <tr>
  115. <td colspan="3" class="label">
  116. <h3><img class="valignmiddle inline-block paddingright" src="../theme/common/octicons/build/svg/globe.svg" width="20" alt="webserver"> <?php echo $langs->trans("WebServer"); ?></h3>
  117. </td>
  118. </tr>
  119. <!-- Documents root $dolibarr_main_document_root -->
  120. <tr>
  121. <td class="label"><label for="main_dir"><b><?php print $langs->trans("WebPagesDirectory"); ?></b></label></td>
  122. <?php
  123. if (empty($dolibarr_main_document_root)) {
  124. $dolibarr_main_document_root = GETPOSTISSET('main_dir') ? GETPOST('main_dir') : detect_dolibarr_main_document_root();
  125. }
  126. ?>
  127. <td class="label">
  128. <input type="text"
  129. class="minwidth300"
  130. id="main_dir"
  131. name="main_dir"
  132. value="<?php print $dolibarr_main_document_root ?>"
  133. <?php
  134. if (!empty($force_install_noedit)) {
  135. print ' disabled';
  136. }
  137. ?>
  138. >
  139. </td>
  140. <td class="comment"><?php
  141. print '<span class="opacitymedium">'.$langs->trans("WithNoSlashAtTheEnd")."</span><br>";
  142. print $langs->trans("Examples").":<br>";
  143. ?>
  144. <ul>
  145. <li>/var/www/dolibarr/htdocs</li>
  146. <li>C:/wwwroot/dolibarr/htdocs</li>
  147. </ul>
  148. </td>
  149. </tr>
  150. <!-- Documents URL $dolibarr_main_data_root -->
  151. <tr>
  152. <td class="label"><label for="main_data_dir"><b><?php print $langs->trans("DocumentsDirectory"); ?></b></label></td>
  153. <?php
  154. if (!empty($force_install_main_data_root)) {
  155. $dolibarr_main_data_root = @$force_install_main_data_root;
  156. }
  157. if (empty($dolibarr_main_data_root)) {
  158. $dolibarr_main_data_root = GETPOSTISSET('main_data_dir') ? GETPOST('main_data_dir') : detect_dolibarr_main_data_root($dolibarr_main_document_root);
  159. }
  160. ?>
  161. <td class="label">
  162. <input type="text"
  163. class="minwidth300"
  164. id="main_data_dir"
  165. name="main_data_dir"
  166. value="<?php print $dolibarr_main_data_root ?>"
  167. <?php if (!empty($force_install_noedit)) {
  168. print ' disabled';
  169. } ?>
  170. >
  171. </td>
  172. <td class="comment"><?php
  173. print '<span class="opacitymedium">'.$langs->trans("WithNoSlashAtTheEnd")."</span><br>";
  174. print $langs->trans("DirectoryRecommendation")."<br>";
  175. print $langs->trans("Examples").":<br>";
  176. ?>
  177. <ul>
  178. <li>/var/lib/dolibarr/documents</li>
  179. <li>C:/My Documents/dolibarr/documents</li>
  180. </ul>
  181. </td>
  182. </tr>
  183. <!-- Root URL $dolibarr_main_url_root -->
  184. <?php
  185. if (empty($dolibarr_main_url_root)) {
  186. $dolibarr_main_url_root = GETPOSTISSET('main_url') ? GETPOST('main_url') : detect_dolibarr_main_url_root();
  187. }
  188. ?>
  189. <tr>
  190. <td class="label"><label for="main_url"><b><?php echo $langs->trans("URLRoot"); ?></b></label>
  191. </td>
  192. <td class="label">
  193. <input type="text"
  194. class="minwidth300"
  195. id="main_url"
  196. name="main_url"
  197. value="<?php print $dolibarr_main_url_root; ?> "
  198. <?php if (!empty($force_install_noedit)) {
  199. print ' disabled';
  200. }
  201. ?>
  202. >
  203. </td>
  204. <td class="comment"><?php print $langs->trans("Examples").":<br>"; ?>
  205. <ul>
  206. <li>http://localhost/</li>
  207. <li>http://www.myserver.com:8180/dolibarr</li>
  208. <li>https://www.myvirtualfordolibarr.com/</li>
  209. </ul>
  210. </td>
  211. </tr>
  212. <?php
  213. if (!empty($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] == 'on') { // Enabled if the installation process is "https://"
  214. ?>
  215. <tr>
  216. <td class="label"><label for="main_force_https"><?php echo $langs->trans("ForceHttps"); ?></label></td>
  217. <td class="label">
  218. <input type="checkbox"
  219. id="main_force_https"
  220. name="main_force_https"
  221. <?php if (!empty($force_install_mainforcehttps)) {
  222. print ' checked';
  223. } ?>
  224. <?php if ($force_install_noedit == 2 && $force_install_mainforcehttps !== null) {
  225. print ' disabled';
  226. } ?>
  227. >
  228. </td>
  229. <td class="comment"><?php echo $langs->trans("CheckToForceHttps"); ?>
  230. </td>
  231. </tr>
  232. <?php
  233. }
  234. ?>
  235. <!-- Dolibarr database -->
  236. <tr>
  237. <td colspan="3" class="label"><br>
  238. <h3><img class="valignmiddle inline-block paddingright" src="../theme/common/octicons/build/svg/database.svg" width="20" alt="webserver"> <?php echo $langs->trans("DolibarrDatabase"); ?></h3>
  239. </td>
  240. </tr>
  241. <tr>
  242. <td class="label"><label for="db_name"><b><?php echo $langs->trans("DatabaseName"); ?></b></label></td>
  243. <td class="label">
  244. <input type="text"
  245. id="db_name"
  246. name="db_name"
  247. value="<?php echo (!empty($dolibarr_main_db_name)) ? $dolibarr_main_db_name : ($force_install_database ? $force_install_database : 'dolibarr'); ?>"
  248. <?php if ($force_install_noedit == 2 && $force_install_database !== null) {
  249. print ' disabled';
  250. } ?>
  251. >
  252. </td>
  253. <td class="comment"><?php echo $langs->trans("DatabaseName"); ?></td>
  254. </tr>
  255. <?php
  256. if (!isset($dolibarr_main_db_host)) {
  257. $dolibarr_main_db_host = "localhost";
  258. }
  259. ?>
  260. <tr>
  261. <!-- Driver type -->
  262. <td class="label"><label for="db_type"><b><?php echo $langs->trans("DriverType"); ?></b></label></td>
  263. <td class="label">
  264. <?php
  265. $defaultype = !empty($dolibarr_main_db_type) ? $dolibarr_main_db_type : (empty($force_install_type) ? 'mysqli' : $force_install_type);
  266. $modules = array();
  267. $nbok = $nbko = 0;
  268. $option = '';
  269. // Scan les drivers
  270. $dir = DOL_DOCUMENT_ROOT.'/core/db';
  271. $handle = opendir($dir);
  272. if (is_resource($handle)) {
  273. while (($file = readdir($handle)) !== false) {
  274. if (is_readable($dir."/".$file) && preg_match('/^(.*)\.class\.php$/i', $file, $reg)) {
  275. $type = $reg[1];
  276. if ($type === 'DoliDB') {
  277. continue; // Skip abstract class
  278. }
  279. $class = 'DoliDB'.ucfirst($type);
  280. include_once $dir."/".$file;
  281. if ($type == 'sqlite') {
  282. continue; // We hide sqlite because support can't be complete until sqlite does not manage foreign key creation after table creation (ALTER TABLE child ADD CONSTRAINT not supported)
  283. }
  284. if ($type == 'sqlite3') {
  285. continue; // We hide sqlite3 because support can't be complete until sqlite does not manage foreign key creation after table creation (ALTER TABLE child ADD CONSTRAINT not supported)
  286. }
  287. // Version min of database
  288. $versionbasemin = explode('.', $class::VERSIONMIN);
  289. $note = '('.$class::LABEL.' >= '.$class::VERSIONMIN.')';
  290. // Switch to mysql if mysqli is not present
  291. if ($defaultype == 'mysqli' && !function_exists('mysqli_connect')) {
  292. $defaultype = 'mysql';
  293. }
  294. // Show line into list
  295. if ($type == 'mysql') {
  296. $testfunction = 'mysql_connect';
  297. $testclass = '';
  298. }
  299. if ($type == 'mysqli') {
  300. $testfunction = 'mysqli_connect';
  301. $testclass = '';
  302. }
  303. if ($type == 'pgsql') {
  304. $testfunction = 'pg_connect';
  305. $testclass = '';
  306. }
  307. if ($type == 'mssql') {
  308. $testfunction = 'mssql_connect';
  309. $testclass = '';
  310. }
  311. if ($type == 'sqlite') {
  312. $testfunction = '';
  313. $testclass = 'PDO';
  314. }
  315. if ($type == 'sqlite3') {
  316. $testfunction = '';
  317. $testclass = 'SQLite3';
  318. }
  319. $option .= '<option value="'.$type.'"'.($defaultype == $type ? ' selected' : '');
  320. if ($testfunction && !function_exists($testfunction)) {
  321. $option .= ' disabled';
  322. }
  323. if ($testclass && !class_exists($testclass)) {
  324. $option .= ' disabled';
  325. }
  326. $option .= '>';
  327. $option .= $type.'&nbsp; &nbsp;';
  328. if ($note) {
  329. $option .= ' '.$note;
  330. }
  331. // Deprecated and experimental
  332. if ($type == 'mysql') {
  333. $option .= ' '.$langs->trans("Deprecated");
  334. } elseif ($type == 'mssql') {
  335. $option .= ' '.$langs->trans("VersionExperimental");
  336. } elseif ($type == 'sqlite') {
  337. $option .= ' '.$langs->trans("VersionExperimental");
  338. } elseif ($type == 'sqlite3') {
  339. $option .= ' '.$langs->trans("VersionExperimental");
  340. } elseif (!function_exists($testfunction)) {
  341. // No available
  342. $option .= ' - '.$langs->trans("FunctionNotAvailableInThisPHP");
  343. }
  344. $option .= '</option>';
  345. }
  346. }
  347. }
  348. ?>
  349. <select id="db_type"
  350. name="db_type"
  351. <?php if ($force_install_noedit == 2 && $force_install_type !== null) {
  352. print ' disabled';
  353. } ?>
  354. >
  355. <?php print $option; ?>
  356. </select>
  357. </td>
  358. <td class="comment"><?php echo $langs->trans("DatabaseType"); ?></td>
  359. </tr>
  360. <tr class="hidesqlite">
  361. <td class="label"><label for="db_host"><b><?php echo $langs->trans("DatabaseServer"); ?></b></label></td>
  362. <td class="label">
  363. <input type="text"
  364. id="db_host"
  365. name="db_host"
  366. value="<?php print(!empty($force_install_dbserver) ? $force_install_dbserver : (!empty($dolibarr_main_db_host) ? $dolibarr_main_db_host : 'localhost')); ?>"
  367. <?php if ($force_install_noedit == 2 && $force_install_dbserver !== null) {
  368. print ' disabled';
  369. } ?>
  370. >
  371. </td>
  372. <td class="comment"><?php echo $langs->trans("ServerAddressDescription"); ?>
  373. </td>
  374. </tr>
  375. <tr class="hidesqlite">
  376. <td class="label"><label for="db_port"><?php echo $langs->trans("Port"); ?></label></td>
  377. <td class="label">
  378. <input type="text"
  379. name="db_port"
  380. id="db_port"
  381. value="<?php print (!empty($force_install_port)) ? $force_install_port : $dolibarr_main_db_port; ?>"
  382. <?php if ($force_install_noedit == 2 && $force_install_port !== null) {
  383. print ' disabled';
  384. } ?>
  385. >
  386. </td>
  387. <td class="comment"><?php echo $langs->trans("ServerPortDescription"); ?>
  388. </td>
  389. </tr>
  390. <tr class="hidesqlite">
  391. <td class="label"><label for="db_prefix"><?php echo $langs->trans("DatabasePrefix"); ?></label></td>
  392. <td class="label">
  393. <input type="text"
  394. id="db_prefix"
  395. name="db_prefix"
  396. value="<?php echo(!empty($force_install_prefix) ? $force_install_prefix : (!empty($dolibarr_main_db_prefix) ? $dolibarr_main_db_prefix : 'llx_')); ?>"
  397. <?php if ($force_install_noedit == 2 && $force_install_prefix !== null) {
  398. print ' disabled';
  399. } ?>
  400. >
  401. </td>
  402. <td class="comment"><?php echo $langs->trans("DatabasePrefixDescription"); ?></td>
  403. </tr>
  404. <tr class="hidesqlite">
  405. <td class="label"><label for="db_create_database"><?php echo $langs->trans("CreateDatabase"); ?></label></td>
  406. <td class="label">
  407. <input type="checkbox"
  408. id="db_create_database"
  409. name="db_create_database"
  410. value="on"
  411. <?php
  412. $checked = 0;
  413. if ($force_install_createdatabase) {
  414. $checked = 1;
  415. print ' checked';
  416. } ?>
  417. <?php if ($force_install_noedit == 2 && $force_install_createdatabase !== null) {
  418. print ' disabled';
  419. } ?>
  420. >
  421. </td>
  422. <td class="comment">
  423. <?php echo $langs->trans("CheckToCreateDatabase"); ?>
  424. </td>
  425. </tr>
  426. <tr class="hidesqlite">
  427. <td class="label"><label for="db_user"><b><?php echo $langs->trans("Login"); ?></b></label></td>
  428. <td class="label">
  429. <input type="text"
  430. id="db_user"
  431. name="db_user"
  432. value="<?php print (!empty($force_install_databaselogin)) ? $force_install_databaselogin : $dolibarr_main_db_user; ?>"
  433. <?php if ($force_install_noedit == 2 && $force_install_databaselogin !== null) {
  434. print ' disabled';
  435. } ?>
  436. >
  437. </td>
  438. <td class="comment"><?php echo $langs->trans("AdminLogin"); ?></td>
  439. </tr>
  440. <tr class="hidesqlite">
  441. <td class="label"><label for="db_pass"><b><?php echo $langs->trans("Password"); ?></b></label></td>
  442. <td class="label">
  443. <input type="password" class="text-security"
  444. id="db_pass" autocomplete="off"
  445. name="db_pass"
  446. value="<?php
  447. // If $force_install_databasepass is on, we don't want to set password, we just show '***'. Real value will be extracted from the forced install file at step1.
  448. $autofill = ((!empty($_SESSION['dol_save_pass'])) ? $_SESSION['dol_save_pass'] : str_pad('', strlen($force_install_databasepass), '*'));
  449. if (!empty($dolibarr_main_prod) && empty($_SESSION['dol_save_pass'])) { // So value can't be found if install page still accessible
  450. $autofill = '';
  451. }
  452. print dol_escape_htmltag($autofill);
  453. ?>"
  454. <?php if ($force_install_noedit == 2 && $force_install_databasepass !== null) {
  455. print ' disabled';
  456. } ?>
  457. >
  458. </td>
  459. <td class="comment"><?php echo $langs->trans("AdminPassword"); ?></td>
  460. </tr>
  461. <tr class="hidesqlite">
  462. <td class="label"><label for="db_create_user"><?php echo $langs->trans("CreateUser"); ?></label></td>
  463. <td class="label">
  464. <input type="checkbox"
  465. id="db_create_user"
  466. name="db_create_user"
  467. value="on"
  468. <?php
  469. $checked = 0;
  470. if (!empty($force_install_createuser)) {
  471. $checked = 1;
  472. print ' checked';
  473. } ?>
  474. <?php if ($force_install_noedit == 2 && $force_install_createuser !== null) {
  475. print ' disabled';
  476. } ?>
  477. >
  478. </td>
  479. <td class="comment">
  480. <?php echo $langs->trans("CheckToCreateUser"); ?>
  481. </td>
  482. </tr>
  483. <!-- Super access -->
  484. <?php
  485. $force_install_databaserootlogin = parse_database_login($force_install_databaserootlogin);
  486. $force_install_databaserootpass = parse_database_pass($force_install_databaserootpass);
  487. ?>
  488. <tr class="hidesqlite hideroot">
  489. <td colspan="3" class="label"><br>
  490. <h3><img class="valignmiddle inline-block paddingright" src="../theme/common/octicons/build/svg/shield.svg" width="20" alt="webserver"> <?php echo $langs->trans("DatabaseSuperUserAccess"); ?></h3>
  491. </td>
  492. </tr>
  493. <tr class="hidesqlite hideroot">
  494. <td class="label"><label for="db_user_root"><b><?php echo $langs->trans("Login"); ?></b></label></td>
  495. <td class="label">
  496. <input type="text"
  497. id="db_user_root"
  498. name="db_user_root"
  499. class="needroot"
  500. value="<?php print (!empty($force_install_databaserootlogin)) ? $force_install_databaserootlogin : (GETPOSTISSET('db_user_root') ? GETPOST('db_user_root') : (isset($db_user_root) ? $db_user_root : '')); ?>"
  501. <?php if ($force_install_noedit > 0 && !empty($force_install_databaserootlogin)) {
  502. print ' disabled';
  503. } ?>
  504. >
  505. </td>
  506. <td class="comment"><?php echo $langs->trans("DatabaseRootLoginDescription"); ?>
  507. <!--
  508. <?php echo '<br>'.$langs->trans("Examples").':<br>' ?>
  509. <ul>
  510. <li>root (Mysql)</li>
  511. <li>postgres (PostgreSql)</li>
  512. </ul>
  513. </td>
  514. -->
  515. </tr>
  516. <tr class="hidesqlite hideroot">
  517. <td class="label"><label for="db_pass_root"><b><?php echo $langs->trans("Password"); ?></b></label></td>
  518. <td class="label">
  519. <input type="password"
  520. autocomplete="off"
  521. id="db_pass_root"
  522. name="db_pass_root"
  523. class="needroot text-security"
  524. value="<?php
  525. // If $force_install_databaserootpass is on, we don't want to set password here, we just show '***'. Real value will be extracted from the forced install file at step1.
  526. $autofill = ((!empty($force_install_databaserootpass)) ? str_pad('', strlen($force_install_databaserootpass), '*') : (isset($db_pass_root) ? $db_pass_root : ''));
  527. if (!empty($dolibarr_main_prod)) {
  528. $autofill = '';
  529. }
  530. // Do not autofill password if instance is a production instance
  531. if (!empty($_SERVER["SERVER_NAME"]) && !in_array(
  532. $_SERVER["SERVER_NAME"],
  533. array('127.0.0.1', 'localhost', 'localhostgit')
  534. )
  535. ) {
  536. $autofill = '';
  537. } // Do not autofill password for remote access
  538. print dol_escape_htmltag($autofill);
  539. ?>"
  540. <?php if ($force_install_noedit > 0 && !empty($force_install_databaserootpass)) {
  541. print ' disabled'; /* May be removed by javascript*/
  542. } ?>
  543. >
  544. </td>
  545. <td class="comment"><?php echo $langs->trans("KeepEmptyIfNoPassword"); ?>
  546. </td>
  547. </tr>
  548. </table>
  549. </div>
  550. <script type="text/javascript">
  551. function init_needroot()
  552. {
  553. console.log("init_needroot force_install_noedit=<?php echo $force_install_noedit?>");
  554. console.log(jQuery("#db_create_database").is(":checked"));
  555. console.log(jQuery("#db_create_user").is(":checked"));
  556. if (jQuery("#db_create_database").is(":checked") || jQuery("#db_create_user").is(":checked"))
  557. {
  558. console.log("init_needroot show root section");
  559. jQuery(".hideroot").show();
  560. <?php
  561. if (empty($force_install_noedit)) { ?>
  562. jQuery(".needroot").removeAttr('disabled');
  563. <?php } ?>
  564. }
  565. else
  566. {
  567. console.log("init_needroot hide root section");
  568. jQuery(".hideroot").hide();
  569. jQuery(".needroot").prop('disabled', true);
  570. }
  571. }
  572. function checkDatabaseName(databasename) {
  573. if (databasename.match(/[;\.]/)) { return false; }
  574. return true;
  575. }
  576. function jscheckparam()
  577. {
  578. console.log("Click on jscheckparam");
  579. var ok = true;
  580. if (document.forminstall.main_dir.value == '')
  581. {
  582. ok=false;
  583. alert('<?php echo dol_escape_js($langs->transnoentities("ErrorFieldRequired", $langs->transnoentitiesnoconv("WebPagesDirectory"))); ?>');
  584. }
  585. else if (document.forminstall.main_data_dir.value == '')
  586. {
  587. ok=false;
  588. alert('<?php echo dol_escape_js($langs->transnoentities("ErrorFieldRequired", $langs->transnoentitiesnoconv("DocumentsDirectory"))); ?>');
  589. }
  590. else if (document.forminstall.main_url.value == '')
  591. {
  592. ok=false;
  593. alert('<?php echo dol_escape_js($langs->transnoentities("ErrorFieldRequired", $langs->transnoentitiesnoconv("URLRoot"))); ?>');
  594. }
  595. else if (document.forminstall.db_host.value == '')
  596. {
  597. ok=false;
  598. alert('<?php echo dol_escape_js($langs->transnoentities("ErrorFieldRequired", $langs->transnoentitiesnoconv("Server"))); ?>');
  599. }
  600. else if (document.forminstall.db_name.value == '')
  601. {
  602. ok=false;
  603. alert('<?php echo dol_escape_js($langs->transnoentities("ErrorFieldRequired", $langs->transnoentitiesnoconv("DatabaseName"))); ?>');
  604. }
  605. else if (! checkDatabaseName(document.forminstall.db_name.value))
  606. {
  607. ok=false;
  608. alert('<?php echo dol_escape_js($langs->transnoentities("ErrorFieldCanNotContainSpecialCharacters", $langs->transnoentitiesnoconv("DatabaseName"))); ?>');
  609. }
  610. // If create database asked
  611. else if (document.forminstall.db_create_database.checked == true && (document.forminstall.db_user_root.value == ''))
  612. {
  613. ok=false;
  614. alert('<?php echo dol_escape_js($langs->transnoentities("YouAskToCreateDatabaseSoRootRequired")); ?>');
  615. init_needroot();
  616. }
  617. // If create user asked
  618. else if (document.forminstall.db_create_user.checked == true && (document.forminstall.db_user_root.value == ''))
  619. {
  620. ok=false;
  621. alert('<?php echo dol_escape_js($langs->transnoentities("YouAskToCreateDatabaseUserSoRootRequired")); ?>');
  622. init_needroot();
  623. }
  624. return ok;
  625. }
  626. jQuery(document).ready(function() { // TODO Test $( window ).load(function() to see if the init_needroot work better after a back
  627. var dbtype = jQuery("#db_type");
  628. dbtype.change(function () {
  629. if (dbtype.val() == 'sqlite' || dbtype.val() == 'sqlite3') {
  630. jQuery(".hidesqlite").hide();
  631. } else {
  632. jQuery(".hidesqlite").show();
  633. }
  634. // Automatically set default database ports and admin user
  635. if (dbtype.val() == 'mysql' || dbtype.val() == 'mysqli') {
  636. jQuery("#db_port").val(3306);
  637. jQuery("#db_user_root").val('root');
  638. } else if (dbtype.val() == 'pgsql') {
  639. jQuery("#db_port").val(5432);
  640. jQuery("#db_user_root").val('postgres');
  641. } else if (dbtype.val() == 'mssql') {
  642. jQuery("#db_port").val(1433);
  643. jQuery("#db_user_root").val('sa');
  644. }
  645. });
  646. jQuery("#db_create_database").click(function() {
  647. console.log("click on db_create_database");
  648. init_needroot();
  649. });
  650. jQuery("#db_create_user").click(function() {
  651. console.log("click on db_create_user");
  652. init_needroot();
  653. });
  654. <?php if ($force_install_noedit == 2 && empty($force_install_databasepass)) { ?>
  655. jQuery("#db_pass").focus();
  656. <?php } ?>
  657. init_needroot();
  658. });
  659. </script>
  660. <?php
  661. // $db->close(); Not database connexion yet
  662. dolibarr_install_syslog("- fileconf: end");
  663. pFooter($err, $setuplang, 'jscheckparam');