dolibarr_import.php 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. <?php
  2. /* Copyright (C) 2006-2021 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2006-2012 Regis Houssin <regis.houssin@inodbox.com>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  17. */
  18. /**
  19. * \file htdocs/admin/tools/dolibarr_import.php
  20. * \ingroup core
  21. * \brief Page to import database
  22. */
  23. if (! defined('CSRFCHECK_WITH_TOKEN')) {
  24. define('CSRFCHECK_WITH_TOKEN', '1'); // Force use of CSRF protection with tokens even for GET
  25. }
  26. // Load Dolibarr environment
  27. require '../../main.inc.php';
  28. // Load translation files required by the page
  29. $langs->loadLangs(array("other", "admin"));
  30. if (!$user->admin) {
  31. accessforbidden();
  32. }
  33. $radio_dump = GETPOST('radio_dump');
  34. $showpass = GETPOST('showpass');
  35. /*
  36. * View
  37. */
  38. $label = $db::LABEL;
  39. $type = $db->type;
  40. $help_url = 'EN:Restores|FR:Restaurations|ES:Restauraciones';
  41. llxHeader('', '', $help_url);
  42. ?>
  43. <script type="text/javascript">
  44. jQuery(document).ready(function() {
  45. jQuery("#mysql_options").<?php echo $radio_dump == 'mysql_options' ? 'show()' : 'hide()'; ?>;
  46. jQuery("#postgresql_options").<?php echo $radio_dump == 'postgresql_options' ? 'show()' : 'hide()'; ?>;
  47. jQuery("#radio_dump_mysql").click(function() {
  48. jQuery("#mysql_options").show();
  49. });
  50. jQuery("#radio_dump_postgresql").click(function() {
  51. jQuery("#postgresql_options").show();
  52. });
  53. <?php
  54. if ($label == 'MySQL') {
  55. print 'jQuery("#radio_dump_mysql").click();';
  56. }
  57. if ($label == 'PostgreSQL') {
  58. print 'jQuery("#radio_dump_postgresql").click();';
  59. }
  60. ?>
  61. });
  62. </script>
  63. <?php
  64. print load_fiche_titre($langs->trans("Restore"), '', 'title_setup');
  65. print '<div class="center">';
  66. print $langs->trans("RestoreDesc", DOL_DATA_ROOT);
  67. print '</div>';
  68. print '<br>';
  69. ?>
  70. <fieldset>
  71. <legend style="font-size: 3em">1</legend>
  72. <?php
  73. print '<span class="opacitymedium">';
  74. print $langs->trans("RestoreDesc2", DOL_DATA_ROOT).'<br><br>';
  75. print '</span>';
  76. ?>
  77. </fieldset>
  78. <br>
  79. <fieldset>
  80. <legend style="font-size: 3em">2</legend>
  81. <?php
  82. print '<span class="opacitymedium">';
  83. print $langs->trans("RestoreDesc3", $dolibarr_main_db_name).'<br><br>';
  84. print '</span>';
  85. ?>
  86. <?php print $langs->trans("DatabaseName").' : <b>'.$dolibarr_main_db_name.'</b>'; ?><br><br>
  87. <table class="centpercent"><tr><td class="tdtop">
  88. <?php if ($conf->use_javascript_ajax) { ?>
  89. <div id="div_container_exportoptions">
  90. <fieldset id="exportoptions">
  91. <legend><?php echo $langs->trans("ImportMethod"); ?></legend>
  92. <?php
  93. if (in_array($type, array('mysql', 'mysqli'))) {
  94. ?>
  95. <div class="formelementrow">
  96. <input type="radio" name="what" value="mysql" id="radio_dump_mysql"<?php echo($radio_dump == 'mysql_options' ? ' checked' : ''); ?> />
  97. <label for="radio_dump_mysql">MySQL (mysql)</label>
  98. </div>
  99. <?php
  100. } elseif (in_array($type, array('pgsql'))) {
  101. ?>
  102. <div class="formelementrow">
  103. <input type="radio" name="what" value="mysql" id="radio_dump_postgresql"<?php echo($radio_dump == 'postgresql_options' ? ' checked' : ''); ?> />
  104. <label for="radio_dump_postgresql">PostgreSQL Restore (pg_restore or psql)</label>
  105. </div>
  106. <?php
  107. } else {
  108. print 'No method available with database '.$label;
  109. }
  110. ?>
  111. </fieldset>
  112. </div>
  113. <?php } ?>
  114. </td><td class="tdtop">
  115. <div id="div_container_sub_exportoptions" >
  116. <?php
  117. if (in_array($type, array('mysql', 'mysqli'))) {
  118. print '<fieldset id="mysql_options">';
  119. print '<legend>'.$langs->trans('RestoreMySQL').'</legend>';
  120. print '<div class="formelementrow centpercent">';
  121. // Parameteres execution
  122. $command = $db->getPathOfRestore();
  123. if (preg_match("/\s/", $command)) {
  124. $command = $command = escapeshellarg($command); // Use quotes on command
  125. }
  126. $param = $dolibarr_main_db_name;
  127. $param .= " -h ".$dolibarr_main_db_host;
  128. if (!empty($dolibarr_main_db_port)) {
  129. $param .= " -P ".$dolibarr_main_db_port;
  130. }
  131. $param .= " -u ".$dolibarr_main_db_user;
  132. $paramcrypted = $param;
  133. $paramclear = $param;
  134. if (!empty($dolibarr_main_db_pass)) {
  135. $paramcrypted .= " -p".preg_replace('/./i', '*', $dolibarr_main_db_pass);
  136. $paramclear .= " -p".$dolibarr_main_db_pass;
  137. }
  138. echo $langs->trans("ImportMySqlDesc");
  139. print '<br>';
  140. print '<textarea rows="1" id="restorecommand" class="centpercent">'.$langs->trans("ImportMySqlCommand", $command, ($showpass ? $paramclear : $paramcrypted)).'</textarea><br>';
  141. print ajax_autoselect('restorecommand');
  142. if (empty($_GET["showpass"]) && $dolibarr_main_db_pass) {
  143. print '<br><a href="'.$_SERVER["PHP_SELF"].'?showpass=1&amp;radio_dump=mysql_options">'.$langs->trans("UnHidePassword").'</a>';
  144. }
  145. //else print '<br><a href="'.$_SERVER["PHP_SELF"].'?showpass=0&amp;radio_dump=mysql_options">'.$langs->trans("HidePassword").'</a>';
  146. print '</div>';
  147. print '</fieldset>';
  148. } elseif (in_array($type, array('pgsql'))) {
  149. print '<fieldset id="postgresql_options">';
  150. print '<legend>Restore PostgreSQL</legend>';
  151. print '<div class="formelementrow">';
  152. // Parameteres execution
  153. $command = $db->getPathOfRestore();
  154. if (preg_match("/\s/", $command)) {
  155. $command = $command = escapeshellarg($command); // Use quotes on command
  156. }
  157. $param = " -d ".$dolibarr_main_db_name;
  158. $param .= " -h ".$dolibarr_main_db_host;
  159. if (!empty($dolibarr_main_db_port)) {
  160. $param .= " -p ".$dolibarr_main_db_port;
  161. }
  162. $param .= " -U ".$dolibarr_main_db_user;
  163. $paramcrypted = $param;
  164. $paramclear = $param;
  165. /*if (!empty($dolibarr_main_db_pass))
  166. {
  167. $paramcrypted.=" -p".preg_replace('/./i','*',$dolibarr_main_db_pass);
  168. $paramclear.=" -p".$dolibarr_main_db_pass;
  169. }*/
  170. $paramcrypted .= " -W";
  171. $paramclear .= " -W";
  172. // With psql:
  173. $paramcrypted .= " -f";
  174. $paramclear .= " -f";
  175. echo $langs->trans("ImportPostgreSqlDesc");
  176. print '<br>';
  177. print '<textarea rows="1" id="restorecommand" class="centpercent">'.$langs->trans("ImportPostgreSqlCommand", $command, ($showpass ? $paramclear : $paramcrypted)).'</textarea><br>';
  178. print ajax_autoselect('restorecommand');
  179. //if (empty($_GET["showpass"]) && $dolibarr_main_db_pass) print '<br><a href="'.$_SERVER["PHP_SELF"].'?showpass=1&amp;radio_dump=postgresql_options">'.$langs->trans("UnHidePassword").'</a>';
  180. //else print '<br><a href="'.$_SERVER["PHP_SELF"].'?showpass=0&amp;radio_dump=mysql_options">'.$langs->trans("HidePassword").'</a>';
  181. print '</div>';
  182. print '<br>';
  183. print '</fieldset>';
  184. }
  185. print '</div>';
  186. print '</td></tr></table>';
  187. print '</fieldset>';
  188. // End of page
  189. llxFooter();
  190. $db->close();