2006-08-20 21:15:47 +02:00
|
|
|
<?php
|
2021-08-04 12:26:38 +02:00
|
|
|
/* Copyright (C) 2006-2021 Laurent Destailleur <eldy@users.sourceforge.net>
|
2018-10-27 14:43:12 +02:00
|
|
|
* Copyright (C) 2006-2012 Regis Houssin <regis.houssin@inodbox.com>
|
2024-11-04 23:53:20 +01:00
|
|
|
* Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
|
2006-08-20 21:15:47 +02:00
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
2013-01-16 15:36:08 +01:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2006-08-20 21:15:47 +02:00
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2019-09-23 21:55:30 +02:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2006-08-20 21:15:47 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
2008-12-10 14:56:01 +01:00
|
|
|
* \file htdocs/admin/tools/dolibarr_import.php
|
2009-07-06 20:29:40 +02:00
|
|
|
* \ingroup core
|
|
|
|
|
* \brief Page to import database
|
2008-12-10 14:56:01 +01:00
|
|
|
*/
|
2006-11-11 01:46:15 +01:00
|
|
|
|
2021-08-04 12:26:38 +02:00
|
|
|
if (! defined('CSRFCHECK_WITH_TOKEN')) {
|
|
|
|
|
define('CSRFCHECK_WITH_TOKEN', '1'); // Force use of CSRF protection with tokens even for GET
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-07 20:08:59 +02:00
|
|
|
// Load Dolibarr environment
|
2012-08-22 23:24:21 +02:00
|
|
|
require '../../main.inc.php';
|
2006-08-20 21:15:47 +02:00
|
|
|
|
2024-11-04 23:53:20 +01:00
|
|
|
/**
|
|
|
|
|
* @var Conf $conf
|
|
|
|
|
* @var DoliDB $db
|
|
|
|
|
* @var HookManager $hookmanager
|
|
|
|
|
* @var Translate $langs
|
|
|
|
|
* @var User $user
|
|
|
|
|
*/
|
|
|
|
|
|
2018-09-08 10:30:10 +02:00
|
|
|
// Load translation files required by the page
|
2020-04-10 10:59:32 +02:00
|
|
|
$langs->loadLangs(array("other", "admin"));
|
2006-08-20 21:15:47 +02:00
|
|
|
|
2021-02-26 22:04:03 +01:00
|
|
|
if (!$user->admin) {
|
2012-08-02 10:07:55 +02:00
|
|
|
accessforbidden();
|
2021-02-26 22:04:03 +01:00
|
|
|
}
|
2012-08-02 10:07:55 +02:00
|
|
|
|
2020-04-10 10:59:32 +02:00
|
|
|
$radio_dump = GETPOST('radio_dump');
|
2024-11-28 13:40:38 +01:00
|
|
|
$action = GETPOST('action', 'aZ09');
|
2006-08-20 21:15:47 +02:00
|
|
|
|
|
|
|
|
|
2008-12-10 14:56:01 +01:00
|
|
|
/*
|
|
|
|
|
* View
|
|
|
|
|
*/
|
|
|
|
|
|
2020-04-10 10:59:32 +02:00
|
|
|
$label = $db::LABEL;
|
|
|
|
|
$type = $db->type;
|
2015-09-29 09:11:13 +02:00
|
|
|
|
2012-03-15 20:45:08 +01:00
|
|
|
|
2020-04-10 10:59:32 +02:00
|
|
|
$help_url = 'EN:Restores|FR:Restaurations|ES:Restauraciones';
|
2024-06-08 17:03:08 +02:00
|
|
|
llxHeader('', '', $help_url, '', 0, 0, '', '', '', 'mod-admin page-tools_dolibarr_import');
|
2006-08-20 21:15:47 +02:00
|
|
|
|
2010-09-06 11:51:00 +02:00
|
|
|
?>
|
2011-11-21 01:34:37 +01:00
|
|
|
<script type="text/javascript">
|
2010-09-06 11:51:00 +02:00
|
|
|
jQuery(document).ready(function() {
|
2020-04-10 10:59:32 +02:00
|
|
|
jQuery("#mysql_options").<?php echo $radio_dump == 'mysql_options' ? 'show()' : 'hide()'; ?>;
|
|
|
|
|
jQuery("#postgresql_options").<?php echo $radio_dump == 'postgresql_options' ? 'show()' : 'hide()'; ?>;
|
2010-09-06 11:51:00 +02:00
|
|
|
|
|
|
|
|
jQuery("#radio_dump_mysql").click(function() {
|
|
|
|
|
jQuery("#mysql_options").show();
|
|
|
|
|
});
|
|
|
|
|
jQuery("#radio_dump_postgresql").click(function() {
|
|
|
|
|
jQuery("#postgresql_options").show();
|
|
|
|
|
});
|
2012-03-15 20:45:08 +01:00
|
|
|
<?php
|
2021-02-26 22:04:03 +01:00
|
|
|
if ($label == 'MySQL') {
|
|
|
|
|
print 'jQuery("#radio_dump_mysql").click();';
|
|
|
|
|
}
|
|
|
|
|
if ($label == 'PostgreSQL') {
|
|
|
|
|
print 'jQuery("#radio_dump_postgresql").click();';
|
|
|
|
|
}
|
2012-03-15 20:45:08 +01:00
|
|
|
?>
|
2010-09-06 11:51:00 +02:00
|
|
|
});
|
|
|
|
|
</script>
|
|
|
|
|
<?php
|
|
|
|
|
|
2019-01-27 11:55:16 +01:00
|
|
|
print load_fiche_titre($langs->trans("Restore"), '', 'title_setup');
|
2006-11-11 01:46:15 +01:00
|
|
|
|
2021-08-04 12:26:38 +02:00
|
|
|
print '<div class="center">';
|
2019-01-27 11:55:16 +01:00
|
|
|
print $langs->trans("RestoreDesc", DOL_DATA_ROOT);
|
2017-05-20 18:46:15 +02:00
|
|
|
print '</div>';
|
2017-07-12 22:52:56 +02:00
|
|
|
print '<br>';
|
2017-05-20 18:46:15 +02:00
|
|
|
|
2015-04-03 17:17:02 +02:00
|
|
|
?>
|
|
|
|
|
<fieldset>
|
|
|
|
|
<legend style="font-size: 3em">1</legend>
|
|
|
|
|
<?php
|
2021-08-04 12:26:38 +02:00
|
|
|
print '<span class="opacitymedium">';
|
2019-01-27 11:55:16 +01:00
|
|
|
print $langs->trans("RestoreDesc2", DOL_DATA_ROOT).'<br><br>';
|
2021-08-04 12:26:38 +02:00
|
|
|
print '</span>';
|
2015-04-03 17:17:02 +02:00
|
|
|
?>
|
|
|
|
|
</fieldset>
|
2006-11-11 01:46:15 +01:00
|
|
|
|
2015-04-03 17:17:02 +02:00
|
|
|
<br>
|
|
|
|
|
|
|
|
|
|
<fieldset>
|
|
|
|
|
<legend style="font-size: 3em">2</legend>
|
|
|
|
|
<?php
|
2021-08-04 12:26:38 +02:00
|
|
|
print '<span class="opacitymedium">';
|
2019-01-27 11:55:16 +01:00
|
|
|
print $langs->trans("RestoreDesc3", $dolibarr_main_db_name).'<br><br>';
|
2021-08-04 12:26:38 +02:00
|
|
|
print '</span>';
|
2007-08-08 15:12:20 +02:00
|
|
|
?>
|
2006-11-11 01:46:15 +01:00
|
|
|
|
2015-04-03 17:17:02 +02:00
|
|
|
<?php print $langs->trans("DatabaseName").' : <b>'.$dolibarr_main_db_name.'</b>'; ?><br><br>
|
|
|
|
|
|
2017-05-20 18:46:15 +02:00
|
|
|
<table class="centpercent"><tr><td class="tdtop">
|
2007-08-08 15:12:20 +02:00
|
|
|
|
2010-09-06 12:08:36 +02:00
|
|
|
<?php if ($conf->use_javascript_ajax) { ?>
|
2007-08-08 15:12:20 +02:00
|
|
|
<div id="div_container_exportoptions">
|
|
|
|
|
<fieldset id="exportoptions">
|
|
|
|
|
<legend><?php echo $langs->trans("ImportMethod"); ?></legend>
|
2021-02-26 22:04:03 +01:00
|
|
|
<?php
|
|
|
|
|
if (in_array($type, array('mysql', 'mysqli'))) {
|
2020-10-31 14:32:18 +01:00
|
|
|
?>
|
2021-02-26 22:04:03 +01:00
|
|
|
<div class="formelementrow">
|
2023-12-04 11:41:14 +01:00
|
|
|
<input type="radio" name="what" value="mysql" id="radio_dump_mysql"<?php echo($radio_dump == 'mysql_options' ? ' checked' : ''); ?> />
|
2021-02-26 22:04:03 +01:00
|
|
|
<label for="radio_dump_mysql">MySQL (mysql)</label>
|
|
|
|
|
</div>
|
|
|
|
|
<?php
|
|
|
|
|
} elseif (in_array($type, array('pgsql'))) {
|
2020-10-31 14:32:18 +01:00
|
|
|
?>
|
2021-02-26 22:04:03 +01:00
|
|
|
<div class="formelementrow">
|
2023-12-04 11:41:14 +01:00
|
|
|
<input type="radio" name="what" value="mysql" id="radio_dump_postgresql"<?php echo($radio_dump == 'postgresql_options' ? ' checked' : ''); ?> />
|
2021-02-26 22:04:03 +01:00
|
|
|
<label for="radio_dump_postgresql">PostgreSQL Restore (pg_restore or psql)</label>
|
|
|
|
|
</div>
|
|
|
|
|
<?php
|
2020-10-31 14:32:18 +01:00
|
|
|
} else {
|
|
|
|
|
print 'No method available with database '.$label;
|
|
|
|
|
}
|
|
|
|
|
?>
|
2007-08-08 15:12:20 +02:00
|
|
|
</fieldset>
|
|
|
|
|
</div>
|
2010-09-06 12:08:36 +02:00
|
|
|
<?php } ?>
|
2007-08-08 15:12:20 +02:00
|
|
|
|
2017-01-22 12:13:32 +01:00
|
|
|
</td><td class="tdtop">
|
2007-08-08 15:12:20 +02:00
|
|
|
|
|
|
|
|
|
2017-05-20 18:46:15 +02:00
|
|
|
<div id="div_container_sub_exportoptions" >
|
2009-11-29 20:32:16 +01:00
|
|
|
<?php
|
2021-02-26 22:04:03 +01:00
|
|
|
if (in_array($type, array('mysql', 'mysqli'))) {
|
2024-11-28 13:40:38 +01:00
|
|
|
print '<fieldset id="mysql_options">';
|
|
|
|
|
print '<legend>'.$langs->trans('RestoreMySQL').'</legend>';
|
|
|
|
|
print '<div class="formelementrow centpercent">';
|
|
|
|
|
|
|
|
|
|
// Parameters execution
|
|
|
|
|
$command = $db->getPathOfRestore();
|
2023-12-13 12:46:23 +01:00
|
|
|
if (preg_match("/\s/", $command)) {
|
|
|
|
|
$command = $command = escapeshellarg($command); // Use quotes on command
|
|
|
|
|
}
|
2020-04-10 10:59:32 +02:00
|
|
|
|
2023-12-04 11:41:14 +01:00
|
|
|
$param = $dolibarr_main_db_name;
|
|
|
|
|
$param .= " -h ".$dolibarr_main_db_host;
|
2023-12-13 12:46:23 +01:00
|
|
|
if (!empty($dolibarr_main_db_port)) {
|
|
|
|
|
$param .= " -P ".$dolibarr_main_db_port;
|
|
|
|
|
}
|
2023-12-04 11:41:14 +01:00
|
|
|
$param .= " -u ".$dolibarr_main_db_user;
|
|
|
|
|
$paramcrypted = $param;
|
|
|
|
|
$paramclear = $param;
|
2023-12-13 12:46:23 +01:00
|
|
|
if (!empty($dolibarr_main_db_pass)) {
|
|
|
|
|
$paramcrypted .= " -p".preg_replace('/./i', '*', $dolibarr_main_db_pass);
|
|
|
|
|
$paramclear .= " -p".$dolibarr_main_db_pass;
|
|
|
|
|
}
|
2009-01-23 15:46:33 +01:00
|
|
|
|
2024-11-28 13:40:38 +01:00
|
|
|
print $langs->trans("ImportMySqlDesc");
|
|
|
|
|
print '<br>';
|
|
|
|
|
print '<textarea rows="1" id="restorecommand" class="centpercent">'.$langs->trans("ImportMySqlCommand", $command, ($action == 'showpass' ? $paramclear : $paramcrypted)).'</textarea><br>';
|
|
|
|
|
print ajax_autoselect('restorecommand');
|
2017-07-12 22:52:56 +02:00
|
|
|
|
2024-11-28 13:40:38 +01:00
|
|
|
if (GETPOST("action") != 'showpass' && $dolibarr_main_db_pass) {
|
|
|
|
|
print '<br><a href="'.$_SERVER["PHP_SELF"].'?action=showpass&token='.newToken().'&radio_dump=mysql_options">'.$langs->trans("UnHidePassword").'</a>';
|
2023-12-13 12:46:23 +01:00
|
|
|
}
|
2024-11-28 13:40:38 +01:00
|
|
|
//else print '<br><a href="'.$_SERVER["PHP_SELF"].'?radio_dump=mysql_options">'.$langs->trans("HidePassword").'</a>';
|
|
|
|
|
print '</div>';
|
|
|
|
|
print '</fieldset>';
|
2023-12-13 12:46:23 +01:00
|
|
|
} elseif (in_array($type, array('pgsql'))) {
|
|
|
|
|
print '<fieldset id="postgresql_options">';
|
|
|
|
|
print '<legend>Restore PostgreSQL</legend>';
|
|
|
|
|
print '<div class="formelementrow">';
|
2024-01-11 09:59:52 +01:00
|
|
|
// Parameters execution
|
2023-12-13 12:46:23 +01:00
|
|
|
$command = $db->getPathOfRestore();
|
|
|
|
|
if (preg_match("/\s/", $command)) {
|
|
|
|
|
$command = $command = escapeshellarg($command); // Use quotes on command
|
|
|
|
|
}
|
2020-10-31 14:32:18 +01:00
|
|
|
|
2023-12-13 12:46:23 +01:00
|
|
|
$param = " -d ".$dolibarr_main_db_name;
|
|
|
|
|
$param .= " -h ".$dolibarr_main_db_host;
|
|
|
|
|
if (!empty($dolibarr_main_db_port)) {
|
|
|
|
|
$param .= " -p ".$dolibarr_main_db_port;
|
2021-02-26 22:04:03 +01:00
|
|
|
}
|
2023-12-13 12:46:23 +01:00
|
|
|
$param .= " -U ".$dolibarr_main_db_user;
|
|
|
|
|
$paramcrypted = $param;
|
|
|
|
|
$paramclear = $param;
|
|
|
|
|
/*if (!empty($dolibarr_main_db_pass))
|
|
|
|
|
{
|
|
|
|
|
$paramcrypted.=" -p".preg_replace('/./i','*',$dolibarr_main_db_pass);
|
|
|
|
|
$paramclear.=" -p".$dolibarr_main_db_pass;
|
|
|
|
|
}*/
|
|
|
|
|
$paramcrypted .= " -W";
|
|
|
|
|
$paramclear .= " -W";
|
|
|
|
|
// With psql:
|
|
|
|
|
$paramcrypted .= " -f";
|
|
|
|
|
$paramclear .= " -f";
|
|
|
|
|
|
|
|
|
|
echo $langs->trans("ImportPostgreSqlDesc");
|
|
|
|
|
print '<br>';
|
2024-11-28 13:40:38 +01:00
|
|
|
print '<textarea rows="1" id="restorecommand" class="centpercent">'.$langs->trans("ImportPostgreSqlCommand", $command, ($action == 'showpass' ? $paramclear : $paramcrypted)).'</textarea><br>';
|
2023-12-13 12:46:23 +01:00
|
|
|
print ajax_autoselect('restorecommand');
|
|
|
|
|
print '</div>';
|
|
|
|
|
|
|
|
|
|
print '<br>';
|
|
|
|
|
|
|
|
|
|
print '</fieldset>';
|
|
|
|
|
}
|
2009-01-23 15:46:33 +01:00
|
|
|
|
2019-10-20 01:09:11 +02:00
|
|
|
print '</div>';
|
2007-08-08 15:12:20 +02:00
|
|
|
|
|
|
|
|
|
2019-10-20 01:09:11 +02:00
|
|
|
print '</td></tr></table>';
|
|
|
|
|
print '</fieldset>';
|
2007-08-08 15:12:20 +02:00
|
|
|
|
2018-07-28 14:29:28 +02:00
|
|
|
// End of page
|
2011-12-28 01:28:16 +01:00
|
|
|
llxFooter();
|
2010-09-06 11:51:00 +02:00
|
|
|
$db->close();
|