login.tpl.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470
  1. <?php
  2. /* Copyright (C) 2009-2015 Regis Houssin <regis.houssin@inodbox.com>
  3. * Copyright (C) 2011-2021 Laurent Destailleur <eldy@users.sourceforge.net>
  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. // Need global variable $urllogo, $title and $titletruedolibarrversion to be defined by caller (like dol_loginfunction in security2.lib.php)
  19. // Caller can also set $morelogincontent = array(['options']=>array('js'=>..., 'table'=>...);
  20. if (!defined('NOBROWSERNOTIF')) {
  21. define('NOBROWSERNOTIF', 1);
  22. }
  23. // Protection to avoid direct call of template
  24. if (empty($conf) || !is_object($conf)) {
  25. print "Error, template page can't be called as URL";
  26. exit;
  27. }
  28. // DDOS protection
  29. $size = (int) $_SERVER['CONTENT_LENGTH'];
  30. if ($size > 10000) {
  31. http_response_code(413);
  32. exit;
  33. }
  34. require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  35. header('Cache-Control: Public, must-revalidate');
  36. header("Content-type: text/html; charset=".$conf->file->character_set_client);
  37. if (GETPOST('dol_hide_topmenu')) {
  38. $conf->dol_hide_topmenu = 1;
  39. }
  40. if (GETPOST('dol_hide_leftmenu')) {
  41. $conf->dol_hide_leftmenu = 1;
  42. }
  43. if (GETPOST('dol_optimize_smallscreen')) {
  44. $conf->dol_optimize_smallscreen = 1;
  45. }
  46. if (GETPOST('dol_no_mouse_hover')) {
  47. $conf->dol_no_mouse_hover = 1;
  48. }
  49. if (GETPOST('dol_use_jmobile')) {
  50. $conf->dol_use_jmobile = 1;
  51. }
  52. // If we force to use jmobile, then we reenable javascript
  53. if (!empty($conf->dol_use_jmobile)) {
  54. $conf->use_javascript_ajax = 1;
  55. }
  56. $php_self = empty($php_self) ? dol_escape_htmltag($_SERVER['PHP_SELF']) : $php_self;
  57. $php_self .= dol_escape_htmltag($_SERVER["QUERY_STRING"]) ? '?'.dol_escape_htmltag($_SERVER["QUERY_STRING"]) : '';
  58. if (!preg_match('/mainmenu=/', $php_self)) {
  59. $php_self .= (preg_match('/\?/', $php_self) ? '&' : '?').'mainmenu=home';
  60. }
  61. // Javascript code on logon page only to detect user tz, dst_observed, dst_first, dst_second
  62. $arrayofjs = array(
  63. '/includes/jstz/jstz.min.js'.(empty($conf->dol_use_jmobile) ? '' : '?version='.urlencode(DOL_VERSION)),
  64. '/core/js/dst.js'.(empty($conf->dol_use_jmobile) ? '' : '?version='.urlencode(DOL_VERSION))
  65. );
  66. // We display application title instead Login term
  67. if (!empty($conf->global->MAIN_APPLICATION_TITLE)) {
  68. $titleofloginpage = $conf->global->MAIN_APPLICATION_TITLE;
  69. } else {
  70. $titleofloginpage = $langs->trans('Login');
  71. }
  72. $titleofloginpage .= ' @ '.$titletruedolibarrversion; // $titletruedolibarrversion is defined by dol_loginfunction in security2.lib.php. We must keep the @, some tools use it to know it is login page and find true dolibarr version.
  73. $disablenofollow = 1;
  74. if (!preg_match('/'.constant('DOL_APPLICATION_TITLE').'/', $title)) {
  75. $disablenofollow = 0;
  76. }
  77. if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
  78. $disablenofollow = 0;
  79. }
  80. print top_htmlhead('', $titleofloginpage, 0, 0, $arrayofjs, array(), 1, $disablenofollow);
  81. $colorbackhmenu1 = '60,70,100'; // topmenu
  82. if (!isset($conf->global->THEME_ELDY_TOPMENU_BACK1)) {
  83. $conf->global->THEME_ELDY_TOPMENU_BACK1 = $colorbackhmenu1;
  84. }
  85. $colorbackhmenu1 = empty($user->conf->THEME_ELDY_ENABLE_PERSONALIZED) ? (empty($conf->global->THEME_ELDY_TOPMENU_BACK1) ? $colorbackhmenu1 : $conf->global->THEME_ELDY_TOPMENU_BACK1) : (empty($user->conf->THEME_ELDY_TOPMENU_BACK1) ? $colorbackhmenu1 : $user->conf->THEME_ELDY_TOPMENU_BACK1);
  86. $colorbackhmenu1 = join(',', colorStringToArray($colorbackhmenu1)); // Normalize value to 'x,y,z'
  87. print "<!-- BEGIN PHP TEMPLATE LOGIN.TPL.PHP -->\n";
  88. if (!empty($conf->global->ADD_UNSPLASH_LOGIN_BACKGROUND)) {
  89. // For example $conf->global->ADD_UNSPLASH_LOGIN_BACKGROUND = 'https://source.unsplash.com/random'
  90. ?>
  91. <body class="body bodylogin" style="background-image: url('<?php echo dol_escape_htmltag($conf->global->ADD_UNSPLASH_LOGIN_BACKGROUND); ?>'); background-repeat: no-repeat; background-position: center center; background-attachment: fixed; background-size: cover; background-color: #ffffff;">
  92. <?php
  93. } else {
  94. ?>
  95. <body class="body bodylogin"<?php print empty($conf->global->MAIN_LOGIN_BACKGROUND) ? '' : ' style="background-size: cover; background-position: center center; background-attachment: fixed; background-repeat: no-repeat; background-image: url(\''.DOL_URL_ROOT.'/viewimage.php?cache=1&noalt=1&modulepart=mycompany&file=logos/'.urlencode($conf->global->MAIN_LOGIN_BACKGROUND).'\')"'; ?>>
  96. <?php
  97. }
  98. ?>
  99. <?php if (empty($conf->dol_use_jmobile)) { ?>
  100. <script>
  101. $(document).ready(function () {
  102. /* Set focus on correct field */
  103. <?php if ($focus_element) {
  104. ?>$('#<?php echo $focus_element; ?>').focus(); <?php
  105. } ?> // Warning to use this only on visible element
  106. });
  107. </script>
  108. <?php } ?>
  109. <div class="login_center center"<?php print empty($conf->global->MAIN_LOGIN_BACKGROUND) ? ' style="background-size: cover; background-position: center center; background-attachment: fixed; background-repeat: no-repeat; background-image: linear-gradient(rgb('.$colorbackhmenu1.',0.3), rgb(240,240,240));"' : '' ?>>
  110. <div class="login_vertical_align">
  111. <form id="login" name="login" method="post" action="<?php echo $php_self; ?>">
  112. <input type="hidden" name="token" value="<?php echo newToken(); ?>" />
  113. <input type="hidden" name="actionlogin" value="login">
  114. <input type="hidden" name="loginfunction" value="loginfunction" />
  115. <!-- Add fields to send local user information -->
  116. <input type="hidden" name="tz" id="tz" value="" />
  117. <input type="hidden" name="tz_string" id="tz_string" value="" />
  118. <input type="hidden" name="dst_observed" id="dst_observed" value="" />
  119. <input type="hidden" name="dst_first" id="dst_first" value="" />
  120. <input type="hidden" name="dst_second" id="dst_second" value="" />
  121. <input type="hidden" name="screenwidth" id="screenwidth" value="" />
  122. <input type="hidden" name="screenheight" id="screenheight" value="" />
  123. <input type="hidden" name="dol_hide_topmenu" id="dol_hide_topmenu" value="<?php echo $dol_hide_topmenu; ?>" />
  124. <input type="hidden" name="dol_hide_leftmenu" id="dol_hide_leftmenu" value="<?php echo $dol_hide_leftmenu; ?>" />
  125. <input type="hidden" name="dol_optimize_smallscreen" id="dol_optimize_smallscreen" value="<?php echo $dol_optimize_smallscreen; ?>" />
  126. <input type="hidden" name="dol_no_mouse_hover" id="dol_no_mouse_hover" value="<?php echo $dol_no_mouse_hover; ?>" />
  127. <input type="hidden" name="dol_use_jmobile" id="dol_use_jmobile" value="<?php echo $dol_use_jmobile; ?>" />
  128. <!-- Title with version -->
  129. <div class="login_table_title center" title="<?php echo dol_escape_htmltag($title); ?>">
  130. <?php
  131. if ($disablenofollow) {
  132. echo '<a class="login_table_title" href="https://www.dolibarr.org" target="_blank" rel="noopener noreferrer external">';
  133. }
  134. echo dol_escape_htmltag($title);
  135. if ($disablenofollow) {
  136. echo '</a>';
  137. }
  138. ?>
  139. </div>
  140. <div class="login_table">
  141. <div id="login_line1">
  142. <div id="login_left">
  143. <img alt="" src="<?php echo $urllogo; ?>" id="img_logo" />
  144. </div>
  145. <br>
  146. <div id="login_right">
  147. <div class="tagtable left centpercent" title="<?php echo $langs->trans("EnterLoginDetail"); ?>">
  148. <!-- Login -->
  149. <div class="trinputlogin">
  150. <div class="tagtd nowraponall center valignmiddle tdinputlogin">
  151. <?php if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
  152. ?><label for="username" class="hidden"><?php echo $langs->trans("Login"); ?></label><?php
  153. } ?>
  154. <!-- <span class="span-icon-user">-->
  155. <span class="fa fa-user"></span>
  156. <input type="text" id="username" maxlength="255" placeholder="<?php echo $langs->trans("Login"); ?>" name="username" class="flat input-icon-user minwidth150" value="<?php echo dol_escape_htmltag($login); ?>" tabindex="1" autofocus="autofocus" />
  157. </div>
  158. </div>
  159. <!-- Password -->
  160. <div class="trinputlogin">
  161. <div class="tagtd nowraponall center valignmiddle tdinputlogin">
  162. <?php if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
  163. ?><label for="password" class="hidden"><?php echo $langs->trans("Password"); ?></label><?php
  164. } ?>
  165. <!--<span class="span-icon-password">-->
  166. <span class="fa fa-key"></span>
  167. <input type="password" id="password" maxlength="128" placeholder="<?php echo $langs->trans("Password"); ?>" name="password" class="flat input-icon-password minwidth150" value="<?php echo dol_escape_htmltag($password); ?>" tabindex="2" autocomplete="<?php echo empty($conf->global->MAIN_LOGIN_ENABLE_PASSWORD_AUTOCOMPLETE) ? 'off' : 'on'; ?>" />
  168. </div></div>
  169. <?php
  170. if (!empty($captcha)) {
  171. // Add a variable param to force not using cache (jmobile)
  172. $php_self = preg_replace('/[&\?]time=(\d+)/', '', $php_self); // Remove param time
  173. if (preg_match('/\?/', $php_self)) {
  174. $php_self .= '&time='.dol_print_date(dol_now(), 'dayhourlog');
  175. } else {
  176. $php_self .= '?time='.dol_print_date(dol_now(), 'dayhourlog');
  177. }
  178. // TODO: provide accessible captcha variants
  179. ?>
  180. <!-- Captcha -->
  181. <div class="trinputlogin">
  182. <div class="tagtd none valignmiddle tdinputlogin nowrap">
  183. <span class="fa fa-unlock"></span>
  184. <span class="span-icon-security inline-block">
  185. <input id="securitycode" placeholder="<?php echo $langs->trans("SecurityCode"); ?>" class="flat input-icon-security width125" type="text" maxlength="5" name="code" tabindex="3" autocomplete="off" />
  186. </span>
  187. <span class="nowrap inline-block">
  188. <img class="inline-block valignmiddle" src="<?php echo DOL_URL_ROOT ?>/core/antispamimage.php" border="0" width="80" height="32" id="img_securitycode" />
  189. <a class="inline-block valignmiddle" href="<?php echo $php_self; ?>" tabindex="4" data-role="button"><?php echo $captcha_refresh; ?></a>
  190. </span>
  191. </div></div>
  192. <?php
  193. }
  194. if (!empty($morelogincontent)) {
  195. if (is_array($morelogincontent)) {
  196. foreach ($morelogincontent as $format => $option) {
  197. if ($format == 'table') {
  198. echo '<!-- Option by hook -->';
  199. echo $option;
  200. }
  201. }
  202. } else {
  203. echo '<!-- Option by hook -->';
  204. echo $morelogincontent;
  205. }
  206. }
  207. ?>
  208. </div>
  209. </div> <!-- end div login_right -->
  210. </div> <!-- end div login_line1 -->
  211. <div id="login_line2" style="clear: both">
  212. <!-- Button Connection -->
  213. <br>
  214. <div id="login-submit-wrapper">
  215. <input type="submit" class="button" value="&nbsp; <?php echo $langs->trans('Connection'); ?> &nbsp;" tabindex="5" />
  216. </div>
  217. <?php
  218. if ($forgetpasslink || $helpcenterlink) {
  219. $moreparam = '';
  220. if ($dol_hide_topmenu) {
  221. $moreparam .= (strpos($moreparam, '?') === false ? '?' : '&').'dol_hide_topmenu='.$dol_hide_topmenu;
  222. }
  223. if ($dol_hide_leftmenu) {
  224. $moreparam .= (strpos($moreparam, '?') === false ? '?' : '&').'dol_hide_leftmenu='.$dol_hide_leftmenu;
  225. }
  226. if ($dol_no_mouse_hover) {
  227. $moreparam .= (strpos($moreparam, '?') === false ? '?' : '&').'dol_no_mouse_hover='.$dol_no_mouse_hover;
  228. }
  229. if ($dol_use_jmobile) {
  230. $moreparam .= (strpos($moreparam, '?') === false ? '?' : '&').'dol_use_jmobile='.$dol_use_jmobile;
  231. }
  232. echo '<br>';
  233. echo '<div class="center" style="margin-top: 5px;">';
  234. if ($forgetpasslink) {
  235. $url = DOL_URL_ROOT.'/user/passwordforgotten.php'.$moreparam;
  236. if (!empty($conf->global->MAIN_PASSWORD_FORGOTLINK)) {
  237. $url = $conf->global->MAIN_PASSWORD_FORGOTLINK;
  238. }
  239. echo '<a class="alogin" href="'.dol_escape_htmltag($url).'">';
  240. echo $langs->trans('PasswordForgotten');
  241. echo '</a>';
  242. }
  243. if ($forgetpasslink && $helpcenterlink) {
  244. echo '&nbsp;-&nbsp;';
  245. }
  246. if ($helpcenterlink) {
  247. $url = DOL_URL_ROOT.'/support/index.php'.$moreparam;
  248. if (!empty($conf->global->MAIN_HELPCENTER_LINKTOUSE)) {
  249. $url = $conf->global->MAIN_HELPCENTER_LINKTOUSE;
  250. }
  251. echo '<a class="alogin" href="'.dol_escape_htmltag($url).'" target="_blank" rel="noopener noreferrer">';
  252. echo $langs->trans('NeedHelpCenter');
  253. echo '</a>';
  254. }
  255. echo '</div>';
  256. }
  257. if (isset($conf->file->main_authentication) && preg_match('/openid/', $conf->file->main_authentication)) {
  258. $langs->load("users");
  259. //if (! empty($conf->global->MAIN_OPENIDURL_PERUSER)) $url=
  260. echo '<br>';
  261. echo '<div class="center" style="margin-top: 4px;">';
  262. $url = $conf->global->MAIN_AUTHENTICATION_OPENID_URL;
  263. if (!empty($url)) {
  264. print '<a class="alogin" href="'.$url.'">'.$langs->trans("LoginUsingOpenID").'</a>';
  265. } else {
  266. $langs->load("errors");
  267. print '<span class="warning">'.$langs->trans("ErrorOpenIDSetupNotComplete", 'MAIN_AUTHENTICATION_OPENID_URL').'</span>';
  268. }
  269. echo '</div>';
  270. }
  271. if (isset($conf->file->main_authentication) && preg_match('/google/', $conf->file->main_authentication)) {
  272. $langs->load("users");
  273. global $dolibarr_main_url_root;
  274. // Define $urlwithroot
  275. $urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root));
  276. $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
  277. //$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current
  278. echo '<br>';
  279. echo '<div class="center" style="margin-top: 4px;">';
  280. //$shortscope = 'userinfo_email,userinfo_profile';
  281. $shortscope = 'openid,email,profile'; // For openid connect
  282. $oauthstateanticsrf = bin2hex(random_bytes(128/8));
  283. $_SESSION['oauthstateanticsrf'] = $shortscope.'-'.$oauthstateanticsrf;
  284. $urltorenew = $urlwithroot.'/core/modules/oauth/google_oauthcallback.php?shortscope='.$shortscope.'&state=forlogin-'.$shortscope.'-'.$oauthstateanticsrf;
  285. $url = $urltorenew;
  286. print img_picto('', 'google', 'class="pictofixedwidth"').'<a class="alogin" href="'.$url.'">'.$langs->trans("LoginWith", "Google").'</a>';
  287. echo '</div>';
  288. }
  289. ?>
  290. </div> <!-- end login line 2 -->
  291. </div> <!-- end login table -->
  292. </form>
  293. <?php
  294. // Show error message if defined
  295. if (!empty($_SESSION['dol_loginmesg'])) {
  296. ?>
  297. <div class="center login_main_message"><div class="error">
  298. <?php echo dol_escape_htmltag($_SESSION['dol_loginmesg']); ?>
  299. </div></div>
  300. <?php
  301. }
  302. // Add commit strip
  303. if (!empty($conf->global->MAIN_EASTER_EGG_COMMITSTRIP)) {
  304. include_once DOL_DOCUMENT_ROOT.'/core/lib/geturl.lib.php';
  305. if (substr($langs->defaultlang, 0, 2) == 'fr') {
  306. $resgetcommitstrip = getURLContent("https://www.commitstrip.com/fr/feed/");
  307. } else {
  308. $resgetcommitstrip = getURLContent("https://www.commitstrip.com/en/feed/");
  309. }
  310. if ($resgetcommitstrip && $resgetcommitstrip['http_code'] == '200') {
  311. $xml = simplexml_load_string($resgetcommitstrip['content'], 'SimpleXMLElement', LIBXML_NOCDATA|LIBXML_NONET);
  312. $little = $xml->channel->item[0]->children('content', true);
  313. print preg_replace('/width="650" height="658"/', '', $little->encoded);
  314. }
  315. }
  316. ?>
  317. <?php if ($main_home) {
  318. ?>
  319. <div class="center login_main_home paddingtopbottom <?php echo empty($conf->global->MAIN_LOGIN_BACKGROUND) ? '' : ' backgroundsemitransparent boxshadow'; ?>" style="max-width: 70%">
  320. <?php echo $main_home; ?>
  321. </div><br>
  322. <?php
  323. }
  324. ?>
  325. <!-- authentication mode = <?php echo $main_authentication ?> -->
  326. <!-- cookie name used for this session = <?php echo $session_name ?> -->
  327. <!-- urlfrom in this session = <?php echo isset($_SESSION["urlfrom"]) ? $_SESSION["urlfrom"] : ''; ?> -->
  328. <!-- Common footer is not used for login page, this is same than footer but inside login tpl -->
  329. <?php
  330. if (!empty($conf->global->MAIN_HTML_FOOTER)) {
  331. print $conf->global->MAIN_HTML_FOOTER;
  332. }
  333. if (!empty($morelogincontent) && is_array($morelogincontent)) {
  334. foreach ($morelogincontent as $format => $option) {
  335. if ($format == 'js') {
  336. echo "\n".'<!-- Javascript by hook -->';
  337. echo $option."\n";
  338. }
  339. }
  340. } elseif (!empty($moreloginextracontent)) {
  341. echo '<!-- Javascript by hook -->';
  342. echo $moreloginextracontent;
  343. }
  344. // Google Analytics
  345. // TODO Add a hook here
  346. if (!empty($conf->google->enabled) && !empty($conf->global->MAIN_GOOGLE_AN_ID)) {
  347. $tmptagarray = explode(',', $conf->global->MAIN_GOOGLE_AN_ID);
  348. foreach ($tmptagarray as $tmptag) {
  349. print "\n";
  350. print "<!-- JS CODE TO ENABLE for google analtics tag -->\n";
  351. print "
  352. <!-- Global site tag (gtag.js) - Google Analytics -->
  353. <script async src=\"https://www.googletagmanager.com/gtag/js?id=".trim($tmptag)."\"></script>
  354. <script>
  355. window.dataLayer = window.dataLayer || [];
  356. function gtag(){dataLayer.push(arguments);}
  357. gtag('js', new Date());
  358. gtag('config', '".trim($tmptag)."');
  359. </script>";
  360. print "\n";
  361. }
  362. }
  363. // TODO Replace this with a hook
  364. // Google Adsense (need Google module)
  365. if (!empty($conf->google->enabled) && !empty($conf->global->MAIN_GOOGLE_AD_CLIENT) && !empty($conf->global->MAIN_GOOGLE_AD_SLOT)) {
  366. if (empty($conf->dol_use_jmobile)) {
  367. ?>
  368. <div class="center"><br>
  369. <script><!--
  370. google_ad_client = "<?php echo $conf->global->MAIN_GOOGLE_AD_CLIENT ?>";
  371. google_ad_slot = "<?php echo $conf->global->MAIN_GOOGLE_AD_SLOT ?>";
  372. google_ad_width = <?php echo $conf->global->MAIN_GOOGLE_AD_WIDTH ?>;
  373. google_ad_height = <?php echo $conf->global->MAIN_GOOGLE_AD_HEIGHT ?>;
  374. //-->
  375. </script>
  376. <script src="//pagead2.googlesyndication.com/pagead/show_ads.js"></script>
  377. </div>
  378. <?php
  379. }
  380. }
  381. ?>
  382. </div>
  383. </div><!-- end of center -->
  384. </body>
  385. </html>
  386. <!-- END PHP TEMPLATE -->