dolibarr 24.0.0-beta
callback.php
1<?php
2/* Copyright (C) 2023 Maximilien Rozniecki <mrozniecki@easya.solutions>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17
34define('NOLOGIN', '1');
35define('NOTOKENRENEWAL', '1');
36define('NOCSRFCHECK', 1);
37
38require '../../../main.inc.php';
39require_once DOL_DOCUMENT_ROOT.'/core/lib/functions.lib.php';
40
46// Javascript code on logon page only to detect user tz, dst_observed, dst_first, dst_second
47$arrayofjs = array(
48 '/core/js/dst.js'.(empty($conf->dol_use_jmobile) ? '' : '?version='.urlencode(DOL_VERSION))
49);
50
51top_htmlhead('', '', 0, 0, $arrayofjs);
52
53$prefix = dol_getprefix('');
54
55$callbackUrl = isset($_COOKIE["DOL_rollback_url_".$prefix]) ? $_COOKIE["DOL_rollback_url_".$prefix] : '';
56
57if (empty($callbackUrl) || !preg_match('/^\/[a-z0-9]/i', $callbackUrl)) {
58 // We accept only value that is an internal relative URL. URL starting with http are not allowed.
59 $callbackUrl = '/';
60}
61if ($callbackUrl === '/') {
62 $callbackUrl = $dolibarr_main_url_root . '/index.php?mainmenu=home&leftmenu=';
63} else {
64 dolSetCookie('DOL_rollback_url_'.dol_getprefix(''), "", time() + 1);
65}
66
67// Get OIDC parameters from the provider's redirect (GET) and store in session
68$oidcState = GETPOST('state', 'aZ09');
69$oidcCode = GETPOST('code', 'password');
70
71// Store in $_SESSION so they are not exposed as GET params on the redirect to index.php
72$_SESSION['oidc_code'] = $oidcCode;
73$_SESSION['oidc_state'] = $oidcState;
74?>
75
76<!-- Hidden fields for dst.js to populate with timezone detection -->
77<input type="hidden" id="tz" value="" />
78<input type="hidden" id="tz_string" value="" />
79<input type="hidden" id="dst_observed" value="" />
80<input type="hidden" id="dst_first" value="" />
81<input type="hidden" id="dst_second" value="" />
82<input type="hidden" id="screenwidth" value="" />
83<input type="hidden" id="screenheight" value="" />
84
85<script type="text/javascript">
86 $(document).ready(function () {
87 // dst.js has already populated the hidden fields above.
88 // Build a GET redirect URL with openid_mode flag + timezone info.
89 var baseUrl = '<?php echo dol_escape_js($callbackUrl); ?>';
90 var sep = baseUrl.indexOf('?') === -1 ? '?' : '&';
91
92 var url = baseUrl + sep + 'openid_mode=true';
93 url += '&tz=' + encodeURIComponent($('#tz').val());
94 url += '&tz_string=' + encodeURIComponent($('#tz_string').val());
95 url += '&dst_observed=' + encodeURIComponent($('#dst_observed').val());
96 url += '&dst_first=' + encodeURIComponent($('#dst_first').val());
97 url += '&dst_second=' + encodeURIComponent($('#dst_second').val());
98 url += '&screenwidth=' + encodeURIComponent($('#screenwidth').val());
99 url += '&screenheight=' + encodeURIComponent($('#screenheight').val());
100
101 window.location.href = url;
102 });
103</script>
global $dolibarr_main_url_root
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
dolSetCookie(string $cookiename, string $cookievalue, int $expire=-1)
Set a cookie.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
top_htmlhead($head, $title='', $disablejs=0, $disablehead=0, $arrayofjs=array(), $arrayofcss=array(), $disableforlogin=0, $disablenofollow=0, $disablenoindex=0)
Output html header of a page.
if(preg_match('/(crypted|dolcrypt):/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
'integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter[:Sortfield]]]',...
Definition repair.php:130