Skip to content
Snippets Groups Projects
Commit 6318b12a authored by Laurent Destailleur's avatar Laurent Destailleur
Browse files

Fix confirmation of scripts make scripts not working with cron

parent 1401deba
Branches
Tags
No related merge requests found
...@@ -34,12 +34,6 @@ if (substr($sapi_type, 0, 3) == 'cgi') { ...@@ -34,12 +34,6 @@ if (substr($sapi_type, 0, 3) == 'cgi') {
exit(-1); exit(-1);
} }
if (! isset($argv[1]) || ! $argv[1]) {
print "Usage: $script_file now\n";
exit(-1);
}
$now=$argv[1];
require_once($path."../../htdocs/master.inc.php"); require_once($path."../../htdocs/master.inc.php");
require_once(DOL_DOCUMENT_ROOT."/contact/class/contact.class.php"); require_once(DOL_DOCUMENT_ROOT."/contact/class/contact.class.php");
...@@ -49,6 +43,7 @@ require_once(DOL_DOCUMENT_ROOT."/core/class/ldap.class.php"); ...@@ -49,6 +43,7 @@ require_once(DOL_DOCUMENT_ROOT."/core/class/ldap.class.php");
// Global variables // Global variables
$version=DOL_VERSION; $version=DOL_VERSION;
$error=0; $error=0;
$confirmed=0;
/* /*
...@@ -59,6 +54,18 @@ $error=0; ...@@ -59,6 +54,18 @@ $error=0;
print "***** ".$script_file." (".$version.") pid=".dol_getmypid()." *****\n"; print "***** ".$script_file." (".$version.") pid=".dol_getmypid()." *****\n";
dol_syslog($script_file." launched with arg ".join(',',$argv)); dol_syslog($script_file." launched with arg ".join(',',$argv));
if (! isset($argv[1]) || ! $argv[1]) {
print "Usage: $script_file now [-y]\n";
exit(-1);
}
foreach($argv as $key => $val)
{
if (preg_match('/-y$/',$val,$reg)) $confirmed=1;
}
$now=$argv[1];
print "Mails sending disabled (useless in batch mode)\n"; print "Mails sending disabled (useless in batch mode)\n";
$conf->global->MAIN_DISABLE_ALL_MAILS=1; // On bloque les mails $conf->global->MAIN_DISABLE_ALL_MAILS=1; // On bloque les mails
print "\n"; print "\n";
...@@ -77,12 +84,16 @@ print "login=".$conf->global->LDAP_ADMIN_DN."\n"; ...@@ -77,12 +84,16 @@ print "login=".$conf->global->LDAP_ADMIN_DN."\n";
print "pass=".preg_replace('/./i','*',$conf->global->LDAP_ADMIN_PASS)."\n"; print "pass=".preg_replace('/./i','*',$conf->global->LDAP_ADMIN_PASS)."\n";
print "DN target=".$conf->global->LDAP_CONTACT_DN."\n"; print "DN target=".$conf->global->LDAP_CONTACT_DN."\n";
print "\n"; print "\n";
if (! $confirmed)
{
print "Press a key to confirm...\n"; print "Press a key to confirm...\n";
$input = trim(fgets(STDIN)); $input = trim(fgets(STDIN));
print "Warning, this operation may result in data loss if it failed.\n"; print "Warning, this operation may result in data loss if it failed.\n";
print "Be sure to have a backup of your LDAP database (With OpenLDAP: slapcat > save.ldif).\n"; print "Be sure to have a backup of your LDAP database (With OpenLDAP: slapcat > save.ldif).\n";
print "Hit Enter to continue or CTRL+C to stop...\n"; print "Hit Enter to continue or CTRL+C to stop...\n";
$input = trim(fgets(STDIN)); $input = trim(fgets(STDIN));
}
/* /*
if (! $conf->global->LDAP_CONTACT_ACTIVE) if (! $conf->global->LDAP_CONTACT_ACTIVE)
......
...@@ -43,7 +43,7 @@ $langs->load("main"); ...@@ -43,7 +43,7 @@ $langs->load("main");
// Global variables // Global variables
$version=DOL_VERSION; $version=DOL_VERSION;
$error=0; $error=0;
$confirmed=0;
/* /*
...@@ -55,9 +55,15 @@ print "***** ".$script_file." (".$version.") pid=".dol_getmypid()." *****\n"; ...@@ -55,9 +55,15 @@ print "***** ".$script_file." (".$version.") pid=".dol_getmypid()." *****\n";
dol_syslog($script_file." launched with arg ".join(',',$argv)); dol_syslog($script_file." launched with arg ".join(',',$argv));
if (! isset($argv[1]) || ! $argv[1]) { if (! isset($argv[1]) || ! $argv[1]) {
print "Usage: $script_file now\n"; print "Usage: $script_file now [-y]\n";
exit(-1); exit(-1);
} }
foreach($argv as $key => $val)
{
if (preg_match('/-y$/',$val,$reg)) $confirmed=1;
}
$now=$argv[1]; $now=$argv[1];
print "Mails sending disabled (useless in batch mode)\n"; print "Mails sending disabled (useless in batch mode)\n";
...@@ -78,13 +84,16 @@ print "login=".$conf->global->LDAP_ADMIN_DN."\n"; ...@@ -78,13 +84,16 @@ print "login=".$conf->global->LDAP_ADMIN_DN."\n";
print "pass=".preg_replace('/./i','*',$conf->global->LDAP_ADMIN_PASS)."\n"; print "pass=".preg_replace('/./i','*',$conf->global->LDAP_ADMIN_PASS)."\n";
print "DN target=".$conf->global->LDAP_MEMBER_DN."\n"; print "DN target=".$conf->global->LDAP_MEMBER_DN."\n";
print "\n"; print "\n";
if (! $confirmed)
{
print "Press a key to confirm...\n"; print "Press a key to confirm...\n";
$input = trim(fgets(STDIN)); $input = trim(fgets(STDIN));
print "Warning, this operation may result in data loss if it failed.\n"; print "Warning, this operation may result in data loss if it failed.\n";
print "Be sure to have a backup of your LDAP database (With OpenLDAP: slapcat > save.ldif).\n"; print "Be sure to have a backup of your LDAP database (With OpenLDAP: slapcat > save.ldif).\n";
print "Hit Enter to continue or CTRL+C to stop...\n"; print "Hit Enter to continue or CTRL+C to stop...\n";
$input = trim(fgets(STDIN)); $input = trim(fgets(STDIN));
}
/* /*
if (! $conf->global->LDAP_MEMBER_ACTIVE) if (! $conf->global->LDAP_MEMBER_ACTIVE)
......
...@@ -48,7 +48,7 @@ $langs->load("errors"); ...@@ -48,7 +48,7 @@ $langs->load("errors");
$version=DOL_VERSION; $version=DOL_VERSION;
$error=0; $error=0;
$forcecommit=0; $forcecommit=0;
$confirmed=0;
/* /*
...@@ -94,7 +94,7 @@ $required_fields=array_unique(array_values(array_filter($required_fields, "dolVa ...@@ -94,7 +94,7 @@ $required_fields=array_unique(array_values(array_filter($required_fields, "dolVa
if (! isset($argv[2]) || ! is_numeric($argv[2])) { if (! isset($argv[2]) || ! is_numeric($argv[2])) {
print "Usage: $script_file (nocommitiferror|commitiferror) id_member_type [--server=ldapserverhost]\n"; print "Usage: $script_file (nocommitiferror|commitiferror) id_member_type [--server=ldapserverhost] [-y]\n";
exit(-1); exit(-1);
} }
...@@ -103,6 +103,7 @@ foreach($argv as $key => $val) ...@@ -103,6 +103,7 @@ foreach($argv as $key => $val)
{ {
if ($val == 'commitiferror') $forcecommit=1; if ($val == 'commitiferror') $forcecommit=1;
if (preg_match('/--server=([^\s]+)$/',$val,$reg)) $conf->global->LDAP_SERVER_HOST=$reg[1]; if (preg_match('/--server=([^\s]+)$/',$val,$reg)) $conf->global->LDAP_SERVER_HOST=$reg[1];
if (preg_match('/-y$/',$val,$reg)) $confirmed=1;
} }
print "Mails sending disabled (useless in batch mode)\n"; print "Mails sending disabled (useless in batch mode)\n";
...@@ -139,9 +140,11 @@ if ($typeid <= 0) ...@@ -139,9 +140,11 @@ if ($typeid <= 0)
} }
if (! $confirmed)
{
print "Hit Enter to continue or CTRL+C to stop...\n"; print "Hit Enter to continue or CTRL+C to stop...\n";
$input = trim(fgets(STDIN)); $input = trim(fgets(STDIN));
}
// Load table of correspondence of countries // Load table of correspondence of countries
$hashlib2rowid=array(); $hashlib2rowid=array();
......
...@@ -49,6 +49,7 @@ $langs->load("errors"); ...@@ -49,6 +49,7 @@ $langs->load("errors");
$version=DOL_VERSION; $version=DOL_VERSION;
$error=0; $error=0;
$forcecommit=0; $forcecommit=0;
$confirmed=0;
/* /*
...@@ -73,7 +74,7 @@ $required_fields=array_unique(array_values(array_filter($required_fields, "dolVa ...@@ -73,7 +74,7 @@ $required_fields=array_unique(array_values(array_filter($required_fields, "dolVa
if (! isset($argv[1])) { if (! isset($argv[1])) {
//print "Usage: $script_file (nocommitiferror|commitiferror) [id_group]\n"; //print "Usage: $script_file (nocommitiferror|commitiferror) [id_group]\n";
print "Usage: $script_file (nocommitiferror|commitiferror) [--server=ldapserverhost] [--excludeuser=user1,user2...]\n"; print "Usage: $script_file (nocommitiferror|commitiferror) [--server=ldapserverhost] [--excludeuser=user1,user2...] [-y]\n";
exit(-1); exit(-1);
} }
...@@ -82,6 +83,7 @@ foreach($argv as $key => $val) ...@@ -82,6 +83,7 @@ foreach($argv as $key => $val)
if ($val == 'commitiferror') $forcecommit=1; if ($val == 'commitiferror') $forcecommit=1;
if (preg_match('/--server=([^\s]+)$/',$val,$reg)) $conf->global->LDAP_SERVER_HOST=$reg[1]; if (preg_match('/--server=([^\s]+)$/',$val,$reg)) $conf->global->LDAP_SERVER_HOST=$reg[1];
if (preg_match('/--excludeuser=([^\s]+)$/',$val,$reg)) $excludeuser=explode(',',$reg[1]); if (preg_match('/--excludeuser=([^\s]+)$/',$val,$reg)) $excludeuser=explode(',',$reg[1]);
if (preg_match('/-y$/',$val,$reg)) $confirmed=1;
} }
print "Mails sending disabled (useless in batch mode)\n"; print "Mails sending disabled (useless in batch mode)\n";
...@@ -105,9 +107,11 @@ print "commitiferror=".$forcecommit."\n"; ...@@ -105,9 +107,11 @@ print "commitiferror=".$forcecommit."\n";
print "Mapped LDAP fields=".join(',',$required_fields)."\n"; print "Mapped LDAP fields=".join(',',$required_fields)."\n";
print "\n"; print "\n";
if (! $confirmed)
{
print "Hit Enter to continue or CTRL+C to stop...\n"; print "Hit Enter to continue or CTRL+C to stop...\n";
$input = trim(fgets(STDIN)); $input = trim(fgets(STDIN));
}
if (empty($conf->global->LDAP_GROUP_DN)) if (empty($conf->global->LDAP_GROUP_DN))
{ {
......
...@@ -48,7 +48,7 @@ $version=DOL_VERSION; ...@@ -48,7 +48,7 @@ $version=DOL_VERSION;
$error=0; $error=0;
$forcecommit=0; $forcecommit=0;
$excludeuser=array(); $excludeuser=array();
$confirmed=0;
/* /*
* Main * Main
...@@ -85,7 +85,7 @@ $required_fields = array( ...@@ -85,7 +85,7 @@ $required_fields = array(
$required_fields=array_unique(array_values(array_filter($required_fields, "dolValidElement"))); $required_fields=array_unique(array_values(array_filter($required_fields, "dolValidElement")));
if (! isset($argv[1])) { if (! isset($argv[1])) {
print "Usage: $script_file (nocommitiferror|commitiferror) [--server=ldapserverhost] [--excludeuser=user1,user2...]\n"; print "Usage: $script_file (nocommitiferror|commitiferror) [--server=ldapserverhost] [--excludeuser=user1,user2...] [-y]\n";
exit(-1); exit(-1);
} }
...@@ -94,6 +94,7 @@ foreach($argv as $key => $val) ...@@ -94,6 +94,7 @@ foreach($argv as $key => $val)
if ($val == 'commitiferror') $forcecommit=1; if ($val == 'commitiferror') $forcecommit=1;
if (preg_match('/--server=([^\s]+)$/',$val,$reg)) $conf->global->LDAP_SERVER_HOST=$reg[1]; if (preg_match('/--server=([^\s]+)$/',$val,$reg)) $conf->global->LDAP_SERVER_HOST=$reg[1];
if (preg_match('/--excludeuser=([^\s]+)$/',$val,$reg)) $excludeuser=explode(',',$reg[1]); if (preg_match('/--excludeuser=([^\s]+)$/',$val,$reg)) $excludeuser=explode(',',$reg[1]);
if (preg_match('/-y$/',$val,$reg)) $confirmed=1;
} }
print "Mails sending disabled (useless in batch mode)\n"; print "Mails sending disabled (useless in batch mode)\n";
...@@ -118,9 +119,11 @@ print "excludeuser=".join(',',$excludeuser)."\n"; ...@@ -118,9 +119,11 @@ print "excludeuser=".join(',',$excludeuser)."\n";
print "Mapped LDAP fields=".join(',',$required_fields)."\n"; print "Mapped LDAP fields=".join(',',$required_fields)."\n";
print "\n"; print "\n";
if (! $confirmed)
{
print "Hit Enter to continue or CTRL+C to stop...\n"; print "Hit Enter to continue or CTRL+C to stop...\n";
$input = trim(fgets(STDIN)); $input = trim(fgets(STDIN));
}
if (empty($conf->global->LDAP_USER_DN)) if (empty($conf->global->LDAP_USER_DN))
{ {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment