dolibarr 24.0.0-beta
admintool.php
1#!/usr/bin/env php
2<?php
3/*
4 * Copyright (C) 2012 Nicolas Villa aka Boyquotes http://informetic.fr
5 * Copyright (C) 2013 Florian Henry <forian.henry@open-concept.pro
6 * Copyright (C) 2013-2015 Laurent Destailleur <eldy@users.sourceforge.net>
7 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
8 * Copyright (C) 2025 MDW <mdeweerd@users.noreply.github.com>
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
30if (!defined('NOTOKENRENEWAL')) {
31 define('NOTOKENRENEWAL', '1'); // Disables token renewal
32}
33if (!defined('NOREQUIREMENU')) {
34 define('NOREQUIREMENU', '1');
35}
36if (!defined('NOREQUIREHTML')) {
37 define('NOREQUIREHTML', '1');
38}
39if (!defined('NOREQUIREAJAX')) {
40 define('NOREQUIREAJAX', '1');
41}
42if (!defined('NOLOGIN')) {
43 define('NOLOGIN', '1');
44}
45if (!defined('NOSESSION')) {
46 define('NOSESSION', '1');
47}
48
49// So log file will have a suffix
50if (!defined('USESUFFIXINLOG')) {
51 define('USESUFFIXINLOG', '_cron');
52}
53
54$sapi_type = php_sapi_name();
55$script_file = basename(__FILE__);
56$path = __DIR__.'/';
57
58// Error if Web mode
59if (substr($sapi_type, 0, 3) == 'cgi') {
60 echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n";
61 exit(1);
62}
63
64require_once $path."../../htdocs/master.inc.php";
65require_once DOL_DOCUMENT_ROOT.'/core/lib/functionscli.lib.php';
66require_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php';
67require_once DOL_DOCUMENT_ROOT."/cron/class/cronjob.class.php";
68require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
69
80// Check parameters
81if (!isset($argv[1]) || !$argv[1]) {
82 usageScript($path, $script_file);
83 exit(1);
84}
85$key = $argv[1];
86
87if (!in_array($key, array('showpass', 'encodepass', 'decodepass'))) {
88 usageScript($path, $script_file);
89 exit(1);
90}
91
92
93// Global variables
94$version = DOL_VERSION;
95$error = 0;
96
97$hookmanager->initHooks(array('cli'));
98
99
100/*
101 * Main
102 */
103
104// current date
105$now = dol_now();
106
107@set_time_limit(0);
108print "***** ".$script_file." (".$version.") pid=".dol_getmypid()." - ".dol_print_date($now, 'dayhourrfc', 'gmt')." - ".gethostname()." *****\n";
109
110// Show TZ of the serveur when ran from command line.
111//$ini_path = php_ini_loaded_file();
112//print 'TZ server = '.getServerTimeZoneString()." - set in PHP ini ".$ini_path."\n";
113
114if ($key == 'showpass') {
115 print dolDecrypt($dolibarr_main_db_pass)."\n";
116} elseif ($key == 'encodepass') {
117 $result = encodedecode_dbpassconf(1);
118 print $result;
119} elseif ($key == 'decodepass') {
120 $result = encodedecode_dbpassconf(0);
121 print $result;
122}
123
124print "\n";
125
126exit(0);
127
128
136function usageScript($path, $script_file)
137{
138 print "Usage: ".$script_file." showpass|encodepass|decodepass\n";
139}
dol_now($mode='gmt')
Return date for now.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
encodedecode_dbpassconf($level=0)
Encode or decode database password in config file.
dolDecrypt($chain, $key='', $patterntotest='')
Decode a string with a symmetric encryption.