fileconf.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731
  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'; $testclass = '';
  297. }
  298. if ($type == 'mysqli') {
  299. $testfunction = 'mysqli_connect'; $testclass = '';
  300. }
  301. if ($type == 'pgsql') {
  302. $testfunction = 'pg_connect'; $testclass = '';
  303. }
  304. if ($type == 'mssql') {
  305. $testfunction = 'mssql_connect'; $testclass = '';
  306. }
  307. if ($type == 'sqlite') {
  308. $testfunction = ''; $testclass = 'PDO';
  309. }
  310. if ($type == 'sqlite3') {
  311. $testfunction = ''; $testclass = 'SQLite3';
  312. }
  313. $option .= '<option value="'.$type.'"'.($defaultype == $type ? ' selected' : '');
  314. if ($testfunction && !function_exists($testfunction)) {
  315. $option .= ' disabled';
  316. }
  317. if ($testclass && !class_exists($testclass)) {
  318. $option .= ' disabled';
  319. }
  320. $option .= '>';
  321. $option .= $type.'&nbsp; &nbsp;';
  322. if ($note) {
  323. $option .= ' '.$note;
  324. }
  325. // Deprecated and experimental
  326. if ($type == 'mysql') {
  327. $option .= ' '.$langs->trans("Deprecated");
  328. } elseif ($type == 'mssql') {
  329. $option .= ' '.$langs->trans("VersionExperimental");
  330. } elseif ($type == 'sqlite') {
  331. $option .= ' '.$langs->trans("VersionExperimental");
  332. } elseif ($type == 'sqlite3') {
  333. $option .= ' '.$langs->trans("VersionExperimental");
  334. } elseif (!function_exists($testfunction)) {
  335. // No available
  336. $option .= ' - '.$langs->trans("FunctionNotAvailableInThisPHP");
  337. }
  338. $option .= '</option>';
  339. }
  340. }
  341. }
  342. ?>
  343. <select id="db_type"
  344. name="db_type"
  345. <?php if ($force_install_noedit == 2 && $force_install_type !== null) {
  346. print ' disabled';
  347. } ?>
  348. >
  349. <?php print $option; ?>
  350. </select>
  351. </td>
  352. <td class="comment"><?php echo $langs->trans("DatabaseType"); ?></td>
  353. </tr>
  354. <tr class="hidesqlite">
  355. <td class="label"><label for="db_host"><b><?php echo $langs->trans("DatabaseServer"); ?></b></label></td>
  356. <td class="label">
  357. <input type="text"
  358. id="db_host"
  359. name="db_host"
  360. value="<?php print (!empty($force_install_dbserver) ? $force_install_dbserver : (!empty($dolibarr_main_db_host) ? $dolibarr_main_db_host : 'localhost')); ?>"
  361. <?php if ($force_install_noedit == 2 && $force_install_dbserver !== null) {
  362. print ' disabled';
  363. } ?>
  364. >
  365. </td>
  366. <td class="comment"><?php echo $langs->trans("ServerAddressDescription"); ?>
  367. </td>
  368. </tr>
  369. <tr class="hidesqlite">
  370. <td class="label"><label for="db_port"><?php echo $langs->trans("Port"); ?></label></td>
  371. <td class="label">
  372. <input type="text"
  373. name="db_port"
  374. id="db_port"
  375. value="<?php print (!empty($force_install_port)) ? $force_install_port : $dolibarr_main_db_port; ?>"
  376. <?php if ($force_install_noedit == 2 && $force_install_port !== null) {
  377. print ' disabled';
  378. } ?>
  379. >
  380. </td>
  381. <td class="comment"><?php echo $langs->trans("ServerPortDescription"); ?>
  382. </td>
  383. </tr>
  384. <tr class="hidesqlite">
  385. <td class="label"><label for="db_prefix"><?php echo $langs->trans("DatabasePrefix"); ?></label></td>
  386. <td class="label">
  387. <input type="text"
  388. id="db_prefix"
  389. name="db_prefix"
  390. value="<?php echo(!empty($force_install_prefix) ? $force_install_prefix : (!empty($dolibarr_main_db_prefix) ? $dolibarr_main_db_prefix : 'llx_')); ?>"
  391. <?php if ($force_install_noedit == 2 && $force_install_prefix !== null) {
  392. print ' disabled';
  393. } ?>
  394. >
  395. </td>
  396. <td class="comment"><?php echo $langs->trans("DatabasePrefixDescription"); ?></td>
  397. </tr>
  398. <tr class="hidesqlite">
  399. <td class="label"><label for="db_create_database"><?php echo $langs->trans("CreateDatabase"); ?></label></td>
  400. <td class="label">
  401. <input type="checkbox"
  402. id="db_create_database"
  403. name="db_create_database"
  404. value="on"
  405. <?php
  406. $checked = 0;
  407. if ($force_install_createdatabase) {
  408. $checked = 1;
  409. print ' checked';
  410. } ?>
  411. <?php if ($force_install_noedit == 2 && $force_install_createdatabase !== null) {
  412. print ' disabled';
  413. } ?>
  414. >
  415. </td>
  416. <td class="comment">
  417. <?php echo $langs->trans("CheckToCreateDatabase"); ?>
  418. </td>
  419. </tr>
  420. <tr class="hidesqlite">
  421. <td class="label"><label for="db_user"><b><?php echo $langs->trans("Login"); ?></b></label></td>
  422. <td class="label">
  423. <input type="text"
  424. id="db_user"
  425. name="db_user"
  426. value="<?php print (!empty($force_install_databaselogin)) ? $force_install_databaselogin : $dolibarr_main_db_user; ?>"
  427. <?php if ($force_install_noedit == 2 && $force_install_databaselogin !== null) {
  428. print ' disabled';
  429. } ?>
  430. >
  431. </td>
  432. <td class="comment"><?php echo $langs->trans("AdminLogin"); ?></td>
  433. </tr>
  434. <tr class="hidesqlite">
  435. <td class="label"><label for="db_pass"><b><?php echo $langs->trans("Password"); ?></b></label></td>
  436. <td class="label">
  437. <input type="password" class="text-security"
  438. id="db_pass" autocomplete="off"
  439. name="db_pass"
  440. value="<?php
  441. // 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.
  442. $autofill = ((!empty($_SESSION['dol_save_pass'])) ? $_SESSION['dol_save_pass'] : str_pad('', strlen($force_install_databasepass), '*'));
  443. if (!empty($dolibarr_main_prod) && empty($_SESSION['dol_save_pass'])) { // So value can't be found if install page still accessible
  444. $autofill = '';
  445. }
  446. print dol_escape_htmltag($autofill);
  447. ?>"
  448. <?php if ($force_install_noedit == 2 && $force_install_databasepass !== null) {
  449. print ' disabled';
  450. } ?>
  451. >
  452. </td>
  453. <td class="comment"><?php echo $langs->trans("AdminPassword"); ?></td>
  454. </tr>
  455. <tr class="hidesqlite">
  456. <td class="label"><label for="db_create_user"><?php echo $langs->trans("CreateUser"); ?></label></td>
  457. <td class="label">
  458. <input type="checkbox"
  459. id="db_create_user"
  460. name="db_create_user"
  461. value="on"
  462. <?php
  463. $checked = 0;
  464. if (!empty($force_install_createuser)) {
  465. $checked = 1;
  466. print ' checked';
  467. } ?>
  468. <?php if ($force_install_noedit == 2 && $force_install_createuser !== null) {
  469. print ' disabled';
  470. } ?>
  471. >
  472. </td>
  473. <td class="comment">
  474. <?php echo $langs->trans("CheckToCreateUser"); ?>
  475. </td>
  476. </tr>
  477. <!-- Super access -->
  478. <?php
  479. $force_install_databaserootlogin = parse_database_login($force_install_databaserootlogin);
  480. $force_install_databaserootpass = parse_database_pass($force_install_databaserootpass);
  481. ?>
  482. <tr class="hidesqlite hideroot">
  483. <td colspan="3" class="label"><br>
  484. <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>
  485. </td>
  486. </tr>
  487. <tr class="hidesqlite hideroot">
  488. <td class="label"><label for="db_user_root"><b><?php echo $langs->trans("Login"); ?></b></label></td>
  489. <td class="label">
  490. <input type="text"
  491. id="db_user_root"
  492. name="db_user_root"
  493. class="needroot"
  494. 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 : '')); ?>"
  495. <?php if ($force_install_noedit > 0 && !empty($force_install_databaserootlogin)) {
  496. print ' disabled';
  497. } ?>
  498. >
  499. </td>
  500. <td class="comment"><?php echo $langs->trans("DatabaseRootLoginDescription"); ?>
  501. <!--
  502. <?php echo '<br>'.$langs->trans("Examples").':<br>' ?>
  503. <ul>
  504. <li>root (Mysql)</li>
  505. <li>postgres (PostgreSql)</li>
  506. </ul>
  507. </td>
  508. -->
  509. </tr>
  510. <tr class="hidesqlite hideroot">
  511. <td class="label"><label for="db_pass_root"><b><?php echo $langs->trans("Password"); ?></b></label></td>
  512. <td class="label">
  513. <input type="password"
  514. autocomplete="off"
  515. id="db_pass_root"
  516. name="db_pass_root"
  517. class="needroot text-security"
  518. value="<?php
  519. // 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.
  520. $autofill = ((!empty($force_install_databaserootpass)) ? str_pad('', strlen($force_install_databaserootpass), '*') : (isset($db_pass_root) ? $db_pass_root : ''));
  521. if (!empty($dolibarr_main_prod)) {
  522. $autofill = '';
  523. }
  524. // Do not autofill password if instance is a production instance
  525. if (!empty($_SERVER["SERVER_NAME"]) && !in_array(
  526. $_SERVER["SERVER_NAME"],
  527. array('127.0.0.1', 'localhost', 'localhostgit')
  528. )
  529. ) {
  530. $autofill = '';
  531. } // Do not autofill password for remote access
  532. print dol_escape_htmltag($autofill);
  533. ?>"
  534. <?php if ($force_install_noedit > 0 && !empty($force_install_databaserootpass)) {
  535. print ' disabled'; /* May be removed by javascript*/
  536. } ?>
  537. >
  538. </td>
  539. <td class="comment"><?php echo $langs->trans("KeepEmptyIfNoPassword"); ?>
  540. </td>
  541. </tr>
  542. </table>
  543. </div>
  544. <script type="text/javascript">
  545. function init_needroot()
  546. {
  547. console.log("init_needroot force_install_noedit=<?php echo $force_install_noedit?>");
  548. console.log(jQuery("#db_create_database").is(":checked"));
  549. console.log(jQuery("#db_create_user").is(":checked"));
  550. if (jQuery("#db_create_database").is(":checked") || jQuery("#db_create_user").is(":checked"))
  551. {
  552. console.log("init_needroot show root section");
  553. jQuery(".hideroot").show();
  554. <?php
  555. if (empty($force_install_noedit)) { ?>
  556. jQuery(".needroot").removeAttr('disabled');
  557. <?php } ?>
  558. }
  559. else
  560. {
  561. console.log("init_needroot hide root section");
  562. jQuery(".hideroot").hide();
  563. jQuery(".needroot").prop('disabled', true);
  564. }
  565. }
  566. function checkDatabaseName(databasename) {
  567. if (databasename.match(/[;\.]/)) { return false; }
  568. return true;
  569. }
  570. function jscheckparam()
  571. {
  572. console.log("Click on jscheckparam");
  573. var ok = true;
  574. if (document.forminstall.main_dir.value == '')
  575. {
  576. ok=false;
  577. alert('<?php echo dol_escape_js($langs->transnoentities("ErrorFieldRequired", $langs->transnoentitiesnoconv("WebPagesDirectory"))); ?>');
  578. }
  579. else if (document.forminstall.main_data_dir.value == '')
  580. {
  581. ok=false;
  582. alert('<?php echo dol_escape_js($langs->transnoentities("ErrorFieldRequired", $langs->transnoentitiesnoconv("DocumentsDirectory"))); ?>');
  583. }
  584. else if (document.forminstall.main_url.value == '')
  585. {
  586. ok=false;
  587. alert('<?php echo dol_escape_js($langs->transnoentities("ErrorFieldRequired", $langs->transnoentitiesnoconv("URLRoot"))); ?>');
  588. }
  589. else if (document.forminstall.db_host.value == '')
  590. {
  591. ok=false;
  592. alert('<?php echo dol_escape_js($langs->transnoentities("ErrorFieldRequired", $langs->transnoentitiesnoconv("Server"))); ?>');
  593. }
  594. else if (document.forminstall.db_name.value == '')
  595. {
  596. ok=false;
  597. alert('<?php echo dol_escape_js($langs->transnoentities("ErrorFieldRequired", $langs->transnoentitiesnoconv("DatabaseName"))); ?>');
  598. }
  599. else if (! checkDatabaseName(document.forminstall.db_name.value))
  600. {
  601. ok=false;
  602. alert('<?php echo dol_escape_js($langs->transnoentities("ErrorFieldCanNotContainSpecialCharacters", $langs->transnoentitiesnoconv("DatabaseName"))); ?>');
  603. }
  604. // If create database asked
  605. else if (document.forminstall.db_create_database.checked == true && (document.forminstall.db_user_root.value == ''))
  606. {
  607. ok=false;
  608. alert('<?php echo dol_escape_js($langs->transnoentities("YouAskToCreateDatabaseSoRootRequired")); ?>');
  609. init_needroot();
  610. }
  611. // If create user asked
  612. else if (document.forminstall.db_create_user.checked == true && (document.forminstall.db_user_root.value == ''))
  613. {
  614. ok=false;
  615. alert('<?php echo dol_escape_js($langs->transnoentities("YouAskToCreateDatabaseUserSoRootRequired")); ?>');
  616. init_needroot();
  617. }
  618. return ok;
  619. }
  620. jQuery(document).ready(function() { // TODO Test $( window ).load(function() to see if the init_needroot work better after a back
  621. var dbtype = jQuery("#db_type");
  622. dbtype.change(function () {
  623. if (dbtype.val() == 'sqlite' || dbtype.val() == 'sqlite3') {
  624. jQuery(".hidesqlite").hide();
  625. } else {
  626. jQuery(".hidesqlite").show();
  627. }
  628. // Automatically set default database ports and admin user
  629. if (dbtype.val() == 'mysql' || dbtype.val() == 'mysqli') {
  630. jQuery("#db_port").val(3306);
  631. jQuery("#db_user_root").val('root');
  632. } else if (dbtype.val() == 'pgsql') {
  633. jQuery("#db_port").val(5432);
  634. jQuery("#db_user_root").val('postgres');
  635. } else if (dbtype.val() == 'mssql') {
  636. jQuery("#db_port").val(1433);
  637. jQuery("#db_user_root").val('sa');
  638. }
  639. });
  640. jQuery("#db_create_database").click(function() {
  641. console.log("click on db_create_database");
  642. init_needroot();
  643. });
  644. jQuery("#db_create_user").click(function() {
  645. console.log("click on db_create_user");
  646. init_needroot();
  647. });
  648. <?php if ($force_install_noedit == 2 && empty($force_install_databasepass)) { ?>
  649. jQuery("#db_pass").focus();
  650. <?php } ?>
  651. init_needroot();
  652. });
  653. </script>
  654. <?php
  655. // $db->close(); Not database connexion yet
  656. dolibarr_install_syslog("- fileconf: end");
  657. pFooter($err, $setuplang, 'jscheckparam');