From ba52eb870cabe2569dff275f37849911b6580a21 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 7 Oct 2016 17:53:41 +0200 Subject: [PATCH] Enhancement of Oauth module --- ChangeLog | 2 + htdocs/admin/oauth.php | 235 +-------------- htdocs/admin/oauthlogintokens.php | 275 +++++++++++++++++ htdocs/core/lib/functions.lib.php | 2 +- htdocs/core/lib/oauth.lib.php | 277 ++++++++++++++++++ .../bank/doc/pdf_sepamandate.modules.php | 2 +- .../modules/oauth/google_oauthcallback.php | 2 +- .../modules/printing/printgcp.modules.php | 42 +-- .../OAuth/Common/Storage/DoliStorage.php | 1 + htdocs/langs/en_US/oauth.lang | 19 +- htdocs/langs/en_US/printing.lang | 4 - htdocs/langs/en_US/withdrawals.lang | 2 +- htdocs/printing/admin/printing.php | 45 ++- 13 files changed, 647 insertions(+), 261 deletions(-) create mode 100644 htdocs/admin/oauthlogintokens.php create mode 100644 htdocs/core/lib/oauth.lib.php diff --git a/ChangeLog b/ChangeLog index 333bd035b14..51107b308c2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -35,6 +35,8 @@ check you make a fetch on object before calling the delete. - The javascript "datatables" library was used to be provided into Dolibarr sources, but it was not used by application. So there is no reason to maintain its compatibility with other dolibarr components. If an external module need this library, this external module must embed hte library in his own sources/packages. +- Trigger name SUPPLIER_PROPOSAL_CREATE has been renamed into PROPOSAL_SUPPLIER_CREATE + ***** ChangeLog for 4.0.1 compared to 4.0.0 ***** diff --git a/htdocs/admin/oauth.php b/htdocs/admin/oauth.php index 02a5ffc50e8..34aa49ea237 100644 --- a/htdocs/admin/oauth.php +++ b/htdocs/admin/oauth.php @@ -24,9 +24,8 @@ */ require '../main.inc.php'; - -// required Class require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/oauth.lib.php'; // Define $urlwithroot @@ -44,224 +43,6 @@ if (!$user->admin) $action = GETPOST('action', 'alpha'); -// Supported OAUTH (a provider is supported when a file xxx_oauthcallback.php is available into htdocs/core/modules/oauth) -$supportedoauth2array=array('OAUTH_GOOGLE_NAME'=>'google'); - -// API access parameters OAUTH -$list = array ( - array( - 'OAUTH_AMAZON_NAME', - 'OAUTH_AMAZON_ID', - 'OAUTH_AMAZON_SECRET', - ), - array( - 'OAUTH_BITBUCKET_NAME', - 'OAUTH_BITBUCKET_ID', - 'OAUTH_BITBUCKET_SECRET', - ), - array( - 'OAUTH_BITLY_NAME', - 'OAUTH_BITLY_ID', - 'OAUTH_BITLY_SECRET', - ), - array( - 'OAUTH_BITRIX24_NAME', - 'OAUTH_BITRIX24_ID', - 'OAUTH_BITRIX24_SECRET', - ), - array( - 'OAUTH_BOX_NAME', - 'OAUTH_BOX_ID', - 'OAUTH_BOX_SECRET', - ), - array( - 'OAUTH_BUFFER_NAME', - 'OAUTH_BUFFER_ID', - 'OAUTH_BUFFER_SECRET', - ), - array( - 'OAUTH_DAILYMOTION_NAME', - 'OAUTH_DAILYMOTION_ID', - 'OAUTH_DAILYMOTION_SECRET', - ), - array( - 'OAUTH_DEVIANTART_NAME', - 'OAUTH_DEVIANTART_ID', - 'OAUTH_DEVIANTART_SECRET', - ), - array( - 'OAUTH_DROPBOX_NAME', - 'OAUTH_DROPBOX_ID', - 'OAUTH_DROPBOX_SECRET', - ), - array( - 'OAUTH_ETSY_NAME', - 'OAUTH_ETSY_ID', - 'OAUTH_ETSY_SECRET', - ), - array( - 'OAUTH_EVEONLINE_NAME', - 'OAUTH_EVEONLINE_ID', - 'OAUTH_EVEONLINE_SECRET', - ), - array( - 'OAUTH_FACEBOOK_NAME', - 'OAUTH_FACEBOOK_ID', - 'OAUTH_FACEBOOK_SECRET', - ), - array( - 'OAUTH_FITBIT_NAME', - 'OAUTH_FITBIT_ID', - 'OAUTH_FITBIT_SECRET', - ), - array( - 'OAUTH_FIVEHUNDREDPX_NAME', - 'OAUTH_FIVEHUNDREDPX_ID', - 'OAUTH_FIVEHUNDREDPX_SECRET', - ), - array( - 'OAUTH_FLICKR_NAME', - 'OAUTH_FLICKR_ID', - 'OAUTH_FLICKR_SECRET', - ), - array( - 'OAUTH_FOURSQUARE_NAME', - 'OAUTH_FOURSQUARE_ID', - 'OAUTH_FOURSQUARE_SECRET', - ), - array( - 'OAUTH_GITHUB_NAME', - 'OAUTH_GITHUB_ID', - 'OAUTH_GITHUB_SECRET', - ), - array( - 'OAUTH_GOOGLE_NAME', - 'OAUTH_GOOGLE_ID', - 'OAUTH_GOOGLE_SECRET', - 'OAUTH_GOOGLE_DESC', - ), - array( - 'OAUTH_HUBIC_NAME', - 'OAUTH_HUBIC_ID', - 'OAUTH_HUBIC_SECRET', - ), - array( - 'OAUTH_INSTAGRAM_NAME', - 'OAUTH_INSTAGRAM_ID', - 'OAUTH_INSTAGRAM_SECRET', - ), - array( - 'OAUTH_LINKEDIN_NAME', - 'OAUTH_LINKEDIN_ID', - 'OAUTH_LINKEDIN_SECRET', - ), - array( - 'OAUTH_MAILCHIMP_NAME', - 'OAUTH_MAILCHIMP_ID', - 'OAUTH_MAILCHIMP_SECRET', - ), - array( - 'OAUTH_MICROSOFT_NAME', - 'OAUTH_MICROSOFT_ID', - 'OAUTH_MICROSOFT_SECRET', - ), - array( - 'OAUTH_NEST_NAME', - 'OAUTH_NEST_ID', - 'OAUTH_NEST_SECRET', - ), - array( - 'OAUTH_NETATMO_NAME', - 'OAUTH_NETATMO_ID', - 'OAUTH_NETATMO_SECRET', - ), - array( - 'OAUTH_PARROTFLOWERPOWER_NAME', - 'OAUTH_PARROTFLOWERPOWER_ID', - 'OAUTH_PARROTFLOWERPOWER_SECRET', - ), - array( - 'OAUTH_PAYPAL_NAME', - 'OAUTH_PAYPAL_ID', - 'OAUTH_PAYPAL_SECRET', - ), - array( - 'OAUTH_POCKET_NAME', - 'OAUTH_POCKET_ID', - 'OAUTH_POCKET_SECRET', - ), - array( - 'OAUTH_QUICKBOOKS_NAME', - 'OAUTH_QUICKBOOKS_ID', - 'OAUTH_QUICKBOOKS_SECRET', - ), - array( - 'OAUTH_REDDIT_NAME', - 'OAUTH_REDDIT_ID', - 'OAUTH_REDDIT_SECRET', - ), - array( - 'OAUTH_REDMINE_NAME', - 'OAUTH_REDMINE_ID', - 'OAUTH_REDMINE_SECRET', - ), - array( - 'OAUTH_RUNKEEPER_NAME', - 'OAUTH_RUNKEEPER_ID', - 'OAUTH_RUNKEEPER_SECRET', - ), - array( - 'OAUTH_SCOOPIT_NAME', - 'OAUTH_SCOOPIT_ID', - 'OAUTH_SCOOPIT_SECRET', - ), - array( - 'OAUTH_SOUNDCLOUD_NAME', - 'OAUTH_SOUNDCLOUD_ID', - 'OAUTH_SOUNDCLOUD_SECRET', - ), - array( - 'OAUTH_SPOTIFY_NAME', - 'OAUTH_SPOTIFY_ID', - 'OAUTH_SPOTIFY_SECRET', - ), - array( - 'OAUTH_STRAVA_NAME', - 'OAUTH_STRAVA_ID', - 'OAUTH_STRAVA_SECRET', - ), - array( - 'OAUTH_TUMBLR_NAME', - 'OAUTH_TUMBLR_ID', - 'OAUTH_TUMBLR_SECRET', - ), - array( - 'OAUTH_TWITTER_NAME', - 'OAUTH_TWITTER_ID', - 'OAUTH_TWITTER_SECRET', - ), - array( - 'OAUTH_USTREAM_NAME', - 'OAUTH_USTREAM_ID', - 'OAUTH_USTREAM_SECRET', - ), - array( - 'OAUTH_VIMEO_NAME', - 'OAUTH_VIMEO_ID', - 'OAUTH_VIMEO_SECRET', - ), - array( - 'OAUTH_YAHOO_NAME', - 'OAUTH_YAHOO_ID', - 'OAUTH_YAHOO_SECRET', - ), - array( - 'OAUTH_YAMMER_NAME', - 'OAUTH_YAMMER_ID', - 'OAUTH_YAMMER_SECRET', - ), -); - /* * Actions @@ -303,10 +84,9 @@ print '
'; print ''; print ''; -/* - * Parameters - */ -dol_fiche_head(array(), '', '', 0, 'technic'); +$head = oauthadmin_prepare_head(); + +dol_fiche_head($head, 'services', '', 0, 'technic'); print $langs->trans("ListOfSupportedOauthProviders").'

'; @@ -314,14 +94,17 @@ print $langs->trans("ListOfSupportedOauthProviders").'

'; print ''; $var = true; +$i=0; foreach ($list as $key) { $supported=0; if (in_array($key[0], array_keys($supportedoauth2array))) $supported=1; if (! $supported) continue; // show only supported - - print ''; + + $i++; + + print ''; // Api Name $label = $langs->trans($key[0]); print ''; diff --git a/htdocs/admin/oauthlogintokens.php b/htdocs/admin/oauthlogintokens.php new file mode 100644 index 00000000000..b41ae78d4c7 --- /dev/null +++ b/htdocs/admin/oauthlogintokens.php @@ -0,0 +1,275 @@ + + * Copyright (C) 2014-2015 Frederic France + * + * 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 + * the Free Software Foundation; either version 3 of the License, or + * (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 + * along with this program. If not, see . + */ + +/** + * \file htdocs/admin/oauthlogintoken.php + * \ingroup oauth + * \brief Setup page to configure oauth access to login information + */ + +require '../main.inc.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/oauth.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; +use OAuth\Common\Storage\DoliStorage; + +$langs->load("admin"); +$langs->load("printing"); +$langs->load("oauth"); + +if (! $user->admin) accessforbidden(); + +$action = GETPOST('action','alpha'); +$mode = GETPOST('mode','alpha'); +$value = GETPOST('value','alpha'); +$varname = GETPOST('varname', 'alpha'); +$driver = GETPOST('driver', 'alpha'); + +if (! empty($driver)) $langs->load($driver); + +if (!$mode) $mode='setup'; + + +/* + * Action + */ + +/*if (($mode == 'test' || $mode == 'setup') && empty($driver)) +{ + setEventMessages($langs->trans('PleaseSelectaDriverfromList'), null); + header("Location: ".$_SERVER['PHP_SELF'].'?mode=config'); + exit; +}*/ + +if ($action == 'setconst' && $user->admin) +{ + $error=0; + $db->begin(); + foreach ($_POST['setupdriver'] as $setupconst) { + //print '
'.print_r($setupconst, true).'
'; + $result=dolibarr_set_const($db, $setupconst['varname'],$setupconst['value'],'chaine',0,'',$conf->entity); + if (! $result > 0) $error++; + } + + if (! $error) + { + $db->commit(); + setEventMessages($langs->trans("SetupSaved"), null); + } + else + { + $db->rollback(); + dol_print_error($db); + } + $action=''; +} + +if ($action == 'setvalue' && $user->admin) +{ + $db->begin(); + + $result=dolibarr_set_const($db, $varname, $value,'chaine',0,'',$conf->entity); + if (! $result > 0) $error++; + + if (! $error) + { + $db->commit(); + setEventMessages($langs->trans("SetupSaved"), null); + } + else + { + $db->rollback(); + dol_print_error($db); + } + $action = ''; +} + + +/* + * View + */ + +$form = new Form($db); + +llxHeader('',$langs->trans("PrintingSetup")); + +$linkback=''.$langs->trans("BackToModuleList").''; +print load_fiche_titre($langs->trans('ConfigOAuth'),$linkback,'title_setup'); + +$head=oauthadmin_prepare_head($mode); + +dol_fiche_head($head, 'tokengeneration', '', 0, 'technic'); + + +if ($mode == 'setup' && $user->admin) +{ + + print $langs->trans("OAuthSetupForLogin")."

\n"; + + foreach($list as $key) + { + $supported=0; + if (in_array($key[0], array_keys($supportedoauth2array))) $supported=1; + if (! $supported) continue; // show only supported + + print ''; + print ''; + print ''; + + + print '
'.$label.'
'."\n"; + $var=true; + print ''; + print ''; + print ''; + print ''; + print "\n"; + $submit_enabled=0; + + print ''; + print ''.$langs->trans($key['varname']).''; + print ''; + print ''; + print ''."\n"; + + // Show value of token + if ($key['varname'] == 'PRINTGCP_TOKEN_ACCESS') + { + // Token + print ''; + print ''; + print ''; + print ''; + print ''."\n"; + } + + print '
'.$langs->trans("Parameters").''.$langs->trans("Value").' 
'.$langs->trans($key['info']).''; + if ($key['varname'] == 'PRINTGCP_TOKEN_ACCESS') + { + // Delete remote tokens + if (! empty($key['delete'])) print ''.$langs->trans('DeleteAccess').'

'; + // Request remote token + print ''.$langs->trans('RequestAccess').'

'; + // Check remote access + print $langs->trans("ToCheckDeleteTokenOnProvider", $OAUTH_SERVICENAME_GOOGLE).': https://security.google.com/settings/security/permissions'; + } + print '
'.$langs->trans("Token").''; + // Dolibarr storage + $storage = new DoliStorage($db, $conf); + try + { + $tokenobj = $storage->retrieveAccessToken($OAUTH_SERVICENAME_GOOGLE); + } + catch(Exception $e) + { + // Return an error if token not found + } + if (is_object($tokenobj)) + { + //var_dump($tokenobj); + print $tokenobj->getAccessToken().'
'; + //print 'Refresh: '.$tokenobj->getRefreshToken().'
'; + //print 'EndOfLife: '.$tokenobj->getEndOfLife().'
'; + //var_dump($tokenobj->getExtraParams()); + /*print '
Extra:
';*/ + } + print '
'; + print '
'; + + if (! empty($driver)) + { + if ($submit_enabled) { + print '
'; + } + } + + print '
'; + } + +} + +if ($mode == 'test' && $user->admin) +{ + print $langs->trans('PrintTestDesc'.$driver)."

\n"; + + print ''; + if (! empty($driver)) + { + require_once DOL_DOCUMENT_ROOT.'/core/modules/printing/'.$driver.'.modules.php'; + $classname = 'printing_'.$driver; + $langs->load($driver); + $printer = new $classname($db); + //print '
'.print_r($printer, true).'
'; + if (count($printer->getlist_available_printers())) { + if ($printer->listAvailablePrinters()==0) { + print $printer->resprint; + } else { + setEventMessages($printer->error, $printer->errors, 'errors'); + } + } + else { + print $langs->trans('PleaseConfigureDriverfromList'); + } + + } + + print '
'; + +} + +if ($mode == 'userconf' && $user->admin) +{ + print $langs->trans('PrintUserConfDesc'.$driver)."

\n"; + + print ''; + $var=true; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print "\n"; + $sql = 'SELECT p.rowid, p.printer_name, p.printer_location, p.printer_id, p.copy, p.module, p.driver, p.userid, u.login FROM '.MAIN_DB_PREFIX.'printing as p, '.MAIN_DB_PREFIX.'user as u WHERE p.userid=u.rowid'; + $resql = $db->query($sql); + while ($row=$db->fetch_array($resql)) { + $var=!$var; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print "\n"; + } + print '
'.$langs->trans("User").''.$langs->trans("PrintModule").''.$langs->trans("PrintDriver").''.$langs->trans("Printer").''.$langs->trans("PrinterLocation").''.$langs->trans("PrinterId").''.$langs->trans("NumberOfCopy").''.$langs->trans("Delete").'
'.$row['login'].''.$row['module'].''.$row['driver'].''.$row['printer_name'].''.$row['printer_location'].''.$row['printer_id'].''.$row['copy'].''.img_picto($langs->trans("Delete"), 'delete').'
'; +} + +dol_fiche_end(); + +llxFooter(); + +$db->close(); diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 3c3cfc9267a..ba745ad04ce 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -713,7 +713,7 @@ function dol_syslog($message, $level = LOG_INFO, $ident = 0, $suffixinfilename=' /** * Show tab header of a card * - * @param array $links Array of tabs + * @param array $links Array of tabs. Currently initialized by calling a function xxx_admin_prepare_head * @param string $active Active tab name (document', 'info', 'ldap', ....) * @param string $title Title * @param int $notab 0=Add tab header, 1=no tab header. If you set this to 1, using dol_fiche_end() to close tab is not required. diff --git a/htdocs/core/lib/oauth.lib.php b/htdocs/core/lib/oauth.lib.php new file mode 100644 index 00000000000..6f47ef6e62b --- /dev/null +++ b/htdocs/core/lib/oauth.lib.php @@ -0,0 +1,277 @@ + + * + * 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 + * the Free Software Foundation; either version 3 of the License, or + * (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 + * along with this program. If not, see . + */ + +/** + * \file core/lib/oauth.lib.php + * \brief Function for module Oauth + * \ingroup oauth + */ + + +// Supported OAUTH (a provider is supported when a file xxx_oauthcallback.php is available into htdocs/core/modules/oauth) +$supportedoauth2array=array( + 'OAUTH_GOOGLE_NAME'=>'google', + 'OAUTH_GITHUB_NAME'=>'github' +); + +// API access parameters OAUTH +$list = array ( + array( + 'OAUTH_AMAZON_NAME', + 'OAUTH_AMAZON_ID', + 'OAUTH_AMAZON_SECRET', + ), + array( + 'OAUTH_BITBUCKET_NAME', + 'OAUTH_BITBUCKET_ID', + 'OAUTH_BITBUCKET_SECRET', + ), + array( + 'OAUTH_BITLY_NAME', + 'OAUTH_BITLY_ID', + 'OAUTH_BITLY_SECRET', + ), + array( + 'OAUTH_BITRIX24_NAME', + 'OAUTH_BITRIX24_ID', + 'OAUTH_BITRIX24_SECRET', + ), + array( + 'OAUTH_BOX_NAME', + 'OAUTH_BOX_ID', + 'OAUTH_BOX_SECRET', + ), + array( + 'OAUTH_BUFFER_NAME', + 'OAUTH_BUFFER_ID', + 'OAUTH_BUFFER_SECRET', + ), + array( + 'OAUTH_DAILYMOTION_NAME', + 'OAUTH_DAILYMOTION_ID', + 'OAUTH_DAILYMOTION_SECRET', + ), + array( + 'OAUTH_DEVIANTART_NAME', + 'OAUTH_DEVIANTART_ID', + 'OAUTH_DEVIANTART_SECRET', + ), + array( + 'OAUTH_DROPBOX_NAME', + 'OAUTH_DROPBOX_ID', + 'OAUTH_DROPBOX_SECRET', + ), + array( + 'OAUTH_ETSY_NAME', + 'OAUTH_ETSY_ID', + 'OAUTH_ETSY_SECRET', + ), + array( + 'OAUTH_EVEONLINE_NAME', + 'OAUTH_EVEONLINE_ID', + 'OAUTH_EVEONLINE_SECRET', + ), + array( + 'OAUTH_FACEBOOK_NAME', + 'OAUTH_FACEBOOK_ID', + 'OAUTH_FACEBOOK_SECRET', + ), + array( + 'OAUTH_FITBIT_NAME', + 'OAUTH_FITBIT_ID', + 'OAUTH_FITBIT_SECRET', + ), + array( + 'OAUTH_FIVEHUNDREDPX_NAME', + 'OAUTH_FIVEHUNDREDPX_ID', + 'OAUTH_FIVEHUNDREDPX_SECRET', + ), + array( + 'OAUTH_FLICKR_NAME', + 'OAUTH_FLICKR_ID', + 'OAUTH_FLICKR_SECRET', + ), + array( + 'OAUTH_FOURSQUARE_NAME', + 'OAUTH_FOURSQUARE_ID', + 'OAUTH_FOURSQUARE_SECRET', + ), + array( + 'OAUTH_GITHUB_NAME', + 'OAUTH_GITHUB_ID', + 'OAUTH_GITHUB_SECRET', + 'OAUTH_GITHUB_DESC', + ), + array( + 'OAUTH_GOOGLE_NAME', + 'OAUTH_GOOGLE_ID', + 'OAUTH_GOOGLE_SECRET', + 'OAUTH_GOOGLE_DESC', + ), + array( + 'OAUTH_HUBIC_NAME', + 'OAUTH_HUBIC_ID', + 'OAUTH_HUBIC_SECRET', + ), + array( + 'OAUTH_INSTAGRAM_NAME', + 'OAUTH_INSTAGRAM_ID', + 'OAUTH_INSTAGRAM_SECRET', + ), + array( + 'OAUTH_LINKEDIN_NAME', + 'OAUTH_LINKEDIN_ID', + 'OAUTH_LINKEDIN_SECRET', + ), + array( + 'OAUTH_MAILCHIMP_NAME', + 'OAUTH_MAILCHIMP_ID', + 'OAUTH_MAILCHIMP_SECRET', + ), + array( + 'OAUTH_MICROSOFT_NAME', + 'OAUTH_MICROSOFT_ID', + 'OAUTH_MICROSOFT_SECRET', + ), + array( + 'OAUTH_NEST_NAME', + 'OAUTH_NEST_ID', + 'OAUTH_NEST_SECRET', + ), + array( + 'OAUTH_NETATMO_NAME', + 'OAUTH_NETATMO_ID', + 'OAUTH_NETATMO_SECRET', + ), + array( + 'OAUTH_PARROTFLOWERPOWER_NAME', + 'OAUTH_PARROTFLOWERPOWER_ID', + 'OAUTH_PARROTFLOWERPOWER_SECRET', + ), + array( + 'OAUTH_PAYPAL_NAME', + 'OAUTH_PAYPAL_ID', + 'OAUTH_PAYPAL_SECRET', + ), + array( + 'OAUTH_POCKET_NAME', + 'OAUTH_POCKET_ID', + 'OAUTH_POCKET_SECRET', + ), + array( + 'OAUTH_QUICKBOOKS_NAME', + 'OAUTH_QUICKBOOKS_ID', + 'OAUTH_QUICKBOOKS_SECRET', + ), + array( + 'OAUTH_REDDIT_NAME', + 'OAUTH_REDDIT_ID', + 'OAUTH_REDDIT_SECRET', + ), + array( + 'OAUTH_REDMINE_NAME', + 'OAUTH_REDMINE_ID', + 'OAUTH_REDMINE_SECRET', + ), + array( + 'OAUTH_RUNKEEPER_NAME', + 'OAUTH_RUNKEEPER_ID', + 'OAUTH_RUNKEEPER_SECRET', + ), + array( + 'OAUTH_SCOOPIT_NAME', + 'OAUTH_SCOOPIT_ID', + 'OAUTH_SCOOPIT_SECRET', + ), + array( + 'OAUTH_SOUNDCLOUD_NAME', + 'OAUTH_SOUNDCLOUD_ID', + 'OAUTH_SOUNDCLOUD_SECRET', + ), + array( + 'OAUTH_SPOTIFY_NAME', + 'OAUTH_SPOTIFY_ID', + 'OAUTH_SPOTIFY_SECRET', + ), + array( + 'OAUTH_STRAVA_NAME', + 'OAUTH_STRAVA_ID', + 'OAUTH_STRAVA_SECRET', + ), + array( + 'OAUTH_TUMBLR_NAME', + 'OAUTH_TUMBLR_ID', + 'OAUTH_TUMBLR_SECRET', + ), + array( + 'OAUTH_TWITTER_NAME', + 'OAUTH_TWITTER_ID', + 'OAUTH_TWITTER_SECRET', + ), + array( + 'OAUTH_USTREAM_NAME', + 'OAUTH_USTREAM_ID', + 'OAUTH_USTREAM_SECRET', + ), + array( + 'OAUTH_VIMEO_NAME', + 'OAUTH_VIMEO_ID', + 'OAUTH_VIMEO_SECRET', + ), + array( + 'OAUTH_YAHOO_NAME', + 'OAUTH_YAHOO_ID', + 'OAUTH_YAHOO_SECRET', + ), + array( + 'OAUTH_YAMMER_NAME', + 'OAUTH_YAMMER_ID', + 'OAUTH_YAMMER_SECRET', + ), +); + + + +/** + * Return array of tabs to used on pages to setup cron module. + * + * @return array Array of tabs + */ +function oauthadmin_prepare_head() +{ + global $langs, $conf, $user; + $h = 0; + $head = array(); + + $head[$h][0] = dol_buildpath('/admin/oauth.php', 1); + $head[$h][1] = $langs->trans("OAuthServices"); + $head[$h][2] = 'services'; + $h++; + + $head[$h][0] = dol_buildpath('/admin/oauthlogintokens.php', 1); + $head[$h][1] = $langs->trans("ManualTokenGeneration"); + $head[$h][2] = 'tokengeneration'; + $h++; + + complete_head_from_modules($conf, $langs, null, $head, $h, 'oauthadmin'); + + complete_head_from_modules($conf, $langs, null, $head, $h, 'oauthadmin', 'remove'); + + + return $head; +} diff --git a/htdocs/core/modules/bank/doc/pdf_sepamandate.modules.php b/htdocs/core/modules/bank/doc/pdf_sepamandate.modules.php index 3340836c9f5..1074e83489d 100644 --- a/htdocs/core/modules/bank/doc/pdf_sepamandate.modules.php +++ b/htdocs/core/modules/bank/doc/pdf_sepamandate.modules.php @@ -452,7 +452,7 @@ class pdf_sepamandate extends ModeleBankAccountDoc $pdf->SetXY($this->marge_gauche, $posy); $pdf->SetFont('','', $default_font_size); - $pdf->MultiCell(100, 3, $outputlangs->trans("PleaseReturnMandate").':', 0, 'L', 0); + $pdf->MultiCell(100, 3, $outputlangs->trans("PleaseReturnMandate", $mysoc->email).':', 0, 'L', 0); $posy=$pdf->GetY()+2; $pdf->SetXY($this->marge_gauche, $posy); diff --git a/htdocs/core/modules/oauth/google_oauthcallback.php b/htdocs/core/modules/oauth/google_oauthcallback.php index 623c131086b..3068a29098c 100644 --- a/htdocs/core/modules/oauth/google_oauthcallback.php +++ b/htdocs/core/modules/oauth/google_oauthcallback.php @@ -123,7 +123,7 @@ if (! empty($_GET['code'])) // We are coming from Google oauth page //var_dump($apiService); // OAuth\OAuth2\Service\Google $token = $apiService->requestAccessToken($_GET['code'], $state); - setEventMessages($langs->trans('NewTokenStored'), null, 'mesgs'); + setEventMessages($langs->trans('NewTokenStored'), null, 'mesgs'); // Stored into object managed by class DoliStorage so into table oauth_token } catch (Exception $e) { print $e->getMessage(); } diff --git a/htdocs/core/modules/printing/printgcp.modules.php b/htdocs/core/modules/printing/printgcp.modules.php index cc8699a4e84..3d086466c87 100644 --- a/htdocs/core/modules/printing/printgcp.modules.php +++ b/htdocs/core/modules/printing/printgcp.modules.php @@ -46,6 +46,8 @@ class printing_printgcp extends PrintingDriver var $errors = array(); var $db; + private $OAUTH_SERVICENAME_GOOGLE = 'Google'; + const LOGIN_URL = 'https://accounts.google.com/o/oauth2/token'; const PRINTERS_SEARCH_URL = 'https://www.google.com/cloudprint/search'; const PRINTERS_GET_JOBS = 'https://www.google.com/cloudprint/jobs'; @@ -74,19 +76,19 @@ class printing_printgcp extends PrintingDriver $this->google_secret = $conf->global->OAUTH_GOOGLE_SECRET; // Token storage $storage = new DoliStorage($this->db, $this->conf); - //$storage->clearToken('Google'); + //$storage->clearToken($this->OAUTH_SERVICENAME_GOOGLE); // Setup the credentials for the requests $credentials = new Credentials( $this->google_id, $this->google_secret, $urlwithroot.'/core/modules/oauth/google_oauthcallback.php' ); - $access = ($storage->hasAccessToken('Google')?'HasAccessToken':'NoAccessToken'); + $access = ($storage->hasAccessToken($this->OAUTH_SERVICENAME_GOOGLE)?'HasAccessToken':'NoAccessToken'); $serviceFactory = new \OAuth\ServiceFactory(); - $apiService = $serviceFactory->createService('Google', $credentials, $storage, array()); + $apiService = $serviceFactory->createService($this->OAUTH_SERVICENAME_GOOGLE, $credentials, $storage, array()); $token_ok=true; try { - $token = $storage->retrieveAccessToken('Google'); + $token = $storage->retrieveAccessToken($this->OAUTH_SERVICENAME_GOOGLE); } catch (Exception $e) { $this->errors[] = $e->getMessage(); $token_ok = false; @@ -106,24 +108,24 @@ class printing_printgcp extends PrintingDriver $refreshtoken = $token->getRefreshToken(); $token = $apiService->refreshAccessToken($token); $token->setRefreshToken($refreshtoken); - $storage->storeAccessToken('Google', $token); + $storage->storeAccessToken($this->OAUTH_SERVICENAME_GOOGLE, $token); } catch (Exception $e) { $this->errors[] = $e->getMessage(); } } if ($this->google_id != '' && $this->google_secret != '') { $this->conf[] = array('varname'=>'PRINTGCP_INFO', 'info'=>'GoogleAuthConfigured', 'type'=>'info'); - $this->conf[] = array('varname'=>'PRINTGCP_TOKEN_ACCESS', 'info'=>$access, 'type'=>'info', 'renew'=>$urlwithroot.'/core/modules/oauth/google_oauthcallback.php?state=userinfo_email,userinfo_profile,cloud_print&backtourl='.urlencode(DOL_URL_ROOT.'/printing/admin/printing.php?mode=setup&driver=printgcp'), 'delete'=>($storage->hasAccessToken('Google')?$urlwithroot.'/core/modules/oauth/google_oauthcallback.php?action=delete&backtourl='.urlencode(DOL_URL_ROOT.'/printing/admin/printing.php?mode=setup&driver=printgcp'):'')); + $this->conf[] = array('varname'=>'PRINTGCP_TOKEN_ACCESS', 'info'=>$access, 'type'=>'info', 'renew'=>$urlwithroot.'/core/modules/oauth/google_oauthcallback.php?state=userinfo_email,userinfo_profile,cloud_print&backtourl='.urlencode(DOL_URL_ROOT.'/printing/admin/printing.php?mode=setup&driver=printgcp'), 'delete'=>($storage->hasAccessToken($this->OAUTH_SERVICENAME_GOOGLE)?$urlwithroot.'/core/modules/oauth/google_oauthcallback.php?action=delete&backtourl='.urlencode(DOL_URL_ROOT.'/printing/admin/printing.php?mode=setup&driver=printgcp'):'')); if ($token_ok) { $refreshtoken = $token->getRefreshToken(); - $this->conf[] = array('varname'=>'PRINTGCP_TOKEN_REFRESH', 'info'=>((! empty($refreshtoken))?'Yes':'No'), 'type'=>'info'); - $this->conf[] = array('varname'=>'PRINTGCP_TOKEN_EXPIRED', 'info'=>($expire?'Yes':'No'), 'type'=>'info'); - $this->conf[] = array('varname'=>'PRINTGCP_TOKEN_EXPIRE_AT', 'info'=>(dol_print_date($token->getEndOfLife(), "dayhour")), 'type'=>'info'); + $this->conf[] = array('varname'=>'TOKEN_REFRESH', 'info'=>((! empty($refreshtoken))?'Yes':'No'), 'type'=>'info'); + $this->conf[] = array('varname'=>'TOKEN_EXPIRED', 'info'=>($expire?'Yes':'No'), 'type'=>'info'); + $this->conf[] = array('varname'=>'TOKEN_EXPIRE_AT', 'info'=>(dol_print_date($token->getEndOfLife(), "dayhour")), 'type'=>'info'); } /* - if ($storage->hasAccessToken('Google')) { + if ($storage->hasAccessToken($this->OAUTH_SERVICENAME_GOOGLE)) { $this->conf[] = array('varname'=>'PRINTGCP_AUTHLINK', 'link'=>$urlwithroot.'/core/modules/oauth/google_oauthcallback.php?backtourl='.urlencode(DOL_URL_ROOT.'/printing/admin/printing.php?mode=setup&driver=printgcp'), 'type'=>'authlink'); - $this->conf[] = array('varname'=>'PRINTGCP_DELETE_TOKEN', 'link'=>$urlwithroot.'/core/modules/oauth/google_oauthcallback.php?action=delete&backtourl='.urlencode(DOL_URL_ROOT.'/printing/admin/printing.php?mode=setup&driver=printgcp'), 'type'=>'delete'); + $this->conf[] = array('varname'=>'DELETE_TOKEN', 'link'=>$urlwithroot.'/core/modules/oauth/google_oauthcallback.php?action=delete&backtourl='.urlencode(DOL_URL_ROOT.'/printing/admin/printing.php?mode=setup&driver=printgcp'), 'type'=>'delete'); } else { $this->conf[] = array('varname'=>'PRINTGCP_AUTHLINK', 'link'=>$urlwithroot.'/core/modules/oauth/google_oauthcallback.php?backtourl='.urlencode(DOL_URL_ROOT.'/printing/admin/printing.php?mode=setup&driver=printgcp'), 'type'=>'authlink'); }*/ @@ -203,11 +205,11 @@ class printing_printgcp extends PrintingDriver DOL_MAIN_URL_ROOT.'/core/modules/oauth/google_oauthcallback.php' ); $serviceFactory = new \OAuth\ServiceFactory(); - $apiService = $serviceFactory->createService('Google', $credentials, $storage, array()); + $apiService = $serviceFactory->createService($this->OAUTH_SERVICENAME_GOOGLE, $credentials, $storage, array()); // Check if we have auth token $token_ok=true; try { - $token = $storage->retrieveAccessToken('Google'); + $token = $storage->retrieveAccessToken($this->OAUTH_SERVICENAME_GOOGLE); } catch (Exception $e) { $this->errors[] = $e->getMessage(); $token_ok = false; @@ -225,7 +227,7 @@ class printing_printgcp extends PrintingDriver $refreshtoken = $token->getRefreshToken(); $token = $apiService->refreshAccessToken($token); $token->setRefreshToken($refreshtoken); - $storage->storeAccessToken('Google', $token); + $storage->storeAccessToken($this->OAUTH_SERVICENAME_GOOGLE, $token); } catch (Exception $e) { $this->errors[] = $e->getMessage(); } @@ -341,12 +343,12 @@ class printing_printgcp extends PrintingDriver DOL_MAIN_URL_ROOT.'/core/modules/oauth/google_oauthcallback.php?service=google' ); $serviceFactory = new \OAuth\ServiceFactory(); - $apiService = $serviceFactory->createService('Google', $credentials, $storage, array()); + $apiService = $serviceFactory->createService($this->OAUTH_SERVICENAME_GOOGLE, $credentials, $storage, array()); // Check if we have auth token and refresh it $token_ok=true; try { - $token = $storage->retrieveAccessToken('Google'); + $token = $storage->retrieveAccessToken($this->OAUTH_SERVICENAME_GOOGLE); } catch (Exception $e) { $this->errors[] = $e->getMessage(); $token_ok = false; @@ -357,7 +359,7 @@ class printing_printgcp extends PrintingDriver $refreshtoken = $token->getRefreshToken(); $token = $apiService->refreshAccessToken($token); $token->setRefreshToken($refreshtoken); - $storage->storeAccessToken('Google', $token); + $storage->storeAccessToken($this->OAUTH_SERVICENAME_GOOGLE, $token); } catch (Exception $e) { $this->errors[] = $e->getMessage(); } @@ -390,11 +392,11 @@ class printing_printgcp extends PrintingDriver DOL_MAIN_URL_ROOT.'/core/modules/oauth/google_oauthcallback.php' ); $serviceFactory = new \OAuth\ServiceFactory(); - $apiService = $serviceFactory->createService('Google', $credentials, $storage, array()); + $apiService = $serviceFactory->createService($this->OAUTH_SERVICENAME_GOOGLE, $credentials, $storage, array()); // Check if we have auth token $token_ok=true; try { - $token = $storage->retrieveAccessToken('Google'); + $token = $storage->retrieveAccessToken($this->OAUTH_SERVICENAME_GOOGLE); } catch (Exception $e) { $this->errors[] = $e->getMessage(); $token_ok = false; @@ -413,7 +415,7 @@ class printing_printgcp extends PrintingDriver $refreshtoken = $token->getRefreshToken(); $token = $apiService->refreshAccessToken($token); $token->setRefreshToken($refreshtoken); - $storage->storeAccessToken('Google', $token); + $storage->storeAccessToken($this->OAUTH_SERVICENAME_GOOGLE, $token); } catch (Exception $e) { $this->errors[] = $e->getMessage(); $error++; diff --git a/htdocs/includes/OAuth/Common/Storage/DoliStorage.php b/htdocs/includes/OAuth/Common/Storage/DoliStorage.php index 0ce3abf39c1..7e82bb63cb2 100644 --- a/htdocs/includes/OAuth/Common/Storage/DoliStorage.php +++ b/htdocs/includes/OAuth/Common/Storage/DoliStorage.php @@ -128,6 +128,7 @@ class DoliStorage implements TokenStorageInterface public function hasAccessToken($service) { // get from db + dol_syslog("hasAccessToken service=".$service); $sql = "SELECT token FROM ".MAIN_DB_PREFIX."oauth_token"; $sql.= " WHERE service='".$service."'"; $resql = $this->db->query($sql); diff --git a/htdocs/langs/en_US/oauth.lang b/htdocs/langs/en_US/oauth.lang index f8dfee9788f..a338ab4d5df 100644 --- a/htdocs/langs/en_US/oauth.lang +++ b/htdocs/langs/en_US/oauth.lang @@ -1,5 +1,7 @@ # Dolibarr language file - Source file is en_US - oauth ConfigOAuth=Oauth Configuration +OAuthServices=OAuth services +ManualTokenGeneration=Manual token generation NoAccessToken=No access token saved into local database HasAccessToken=A token was generated and saved into local database NewTokenStored=Token received ans saved @@ -9,7 +11,16 @@ RequestAccess=Click here to request/renew access and receive a new token to save DeleteAccess=Click here to delete token UseTheFollowingUrlAsRedirectURI=Use the following URL as the Redirect URI when creating your credential on your OAuth provider: ListOfSupportedOauthProviders=Enter here credential provided by your OAuth2 provider. Only supported OAuth2 providers are visible here. This setup may be used by other modules that need OAuth2 authentication. -OAUTH_GOOGLE_NAME=Api Google -OAUTH_GOOGLE_ID=Api Google Id -OAUTH_GOOGLE_SECRET=Api Google Secret -OAUTH_GOOGLE_DESC=Go on this page then Credentials to create Oauth credentials +TOKEN_ACCESS= +TOKEN_REFRESH=Token Refresh Present +TOKEN_EXPIRED=Token expired +TOKEN_EXPIRE_AT=Token expire at +TOKEN_DELETE=Delete saved token +OAUTH_GOOGLE_NAME=Oauth Google service +OAUTH_GOOGLE_ID=Oauth Google Id +OAUTH_GOOGLE_SECRET=Oauth Google Secret +OAUTH_GOOGLE_DESC=Go on this page then "Credentials" to create Oauth credentials +OAUTH_GITHUB_NAME=Oauth GitHub service +OAUTH_GITHUB_ID=Oauth GitHub Id +OAUTH_GITHUB_SECRET=Oauth GitHub Secret +OAUTH_GITHUB_DESC=Go on this page then "Register a new application" to create Oauth credentials diff --git a/htdocs/langs/en_US/printing.lang b/htdocs/langs/en_US/printing.lang index 2da614e96f9..d6cf49bd525 100644 --- a/htdocs/langs/en_US/printing.lang +++ b/htdocs/langs/en_US/printing.lang @@ -18,10 +18,6 @@ UserConf=Setup per user PRINTGCP_INFO=Google OAuth API setup PRINTGCP_AUTHLINK=Authentication PRINTGCP_TOKEN_ACCESS=Google Cloud Print OAuth Token -PRINTGCP_TOKEN_REFRESH=Token Refresh Present -PRINTGCP_TOKEN_EXPIRED=Token Expired -PRINTGCP_TOKEN_EXPIRE_AT=Token expire at -PRINTGCP_DELETE_TOKEN=Delete saved token PrintGCPDesc=This driver allow to send documents directly to a printer with Google Cloud Print. GCP_Name=Name GCP_displayName=Display Name diff --git a/htdocs/langs/en_US/withdrawals.lang b/htdocs/langs/en_US/withdrawals.lang index d997c8fd35f..89af1623e48 100644 --- a/htdocs/langs/en_US/withdrawals.lang +++ b/htdocs/langs/en_US/withdrawals.lang @@ -80,7 +80,7 @@ WithdrawRequestAmount=Withdraw request amount: WithdrawRequestErrorNilAmount=Unable to create withdraw request for nil amount. SepaMandate=SEPA Direct Debit Mandate SepaMandateShort=SEPA Mandate -PleaseReturnMandate=Please return this mandate form to +PleaseReturnMandate=Please return this mandate form by email to %s or by mail to SEPALegalText=By signing this mandate form, you authorize (A) %s to send instructions to your bank to debit your account and (B) your bank to debit your account in accordance with the instructions from %s. As part of your rights, you are entitled to a refund from your bank under the terms and conditions of your agreement with your bank. A refund must be claimed within 8 weeks starting from the date on which your account was debited. Your rights regarding the above mandate are explained in a statement that you can obtain from your bank. CreditorIdentifier=Creditor Identifier CreditorName=Creditor’s Name diff --git a/htdocs/printing/admin/printing.php b/htdocs/printing/admin/printing.php index ea051113faa..8e9a9d20b9a 100644 --- a/htdocs/printing/admin/printing.php +++ b/htdocs/printing/admin/printing.php @@ -1,5 +1,5 @@ +/* Copyright (C) 2013-2016 Laurent Destailleur * Copyright (C) 2014-2015 Frederic France * * This program is free software; you can redistribute it and/or modify @@ -28,6 +28,7 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/modules/printing/modules_printing.php'; require_once DOL_DOCUMENT_ROOT.'/printing/lib/printing.lib.php'; +use OAuth\Common\Storage\DoliStorage; $langs->load("admin"); $langs->load("printing"); @@ -45,6 +46,8 @@ if (! empty($driver)) $langs->load($driver); if (!$mode) $mode='config'; +$OAUTH_SERVICENAME_GOOGLE = 'Google'; + /* * Action @@ -100,6 +103,7 @@ if ($action == 'setvalue' && $user->admin) $action = ''; } + /* * View */ @@ -138,7 +142,6 @@ if ($mode == 'setup' && $user->admin) $classname = 'printing_'.$driver; $langs->load($driver); $printer = new $classname($db); - //var_dump($printer); $i=0; $submit_enabled=0; @@ -163,9 +166,12 @@ if ($mode == 'setup' && $user->admin) print ''; if ($key['varname'] == 'PRINTGCP_TOKEN_ACCESS') { + // Delete remote tokens if (! empty($key['delete'])) print ''.$langs->trans('DeleteAccess').'

'; + // Request remote token print ''.$langs->trans('RequestAccess').'

'; - print $langs->trans("ToCheckDeleteTokenOnProvider", 'Google').': https://security.google.com/settings/security/permissions'; + // Check remote access + print $langs->trans("ToCheckDeleteTokenOnProvider", $OAUTH_SERVICENAME_GOOGLE).': https://security.google.com/settings/security/permissions'; } print ''; print ''."\n"; @@ -175,6 +181,39 @@ if ($mode == 'setup' && $user->admin) break; } $i++; + + if ($key['varname'] == 'PRINTGCP_TOKEN_ACCESS') + { + // Token + print ''; + print ''.$langs->trans("Token").''; + print ''; + // Dolibarr storage + $storage = new DoliStorage($db, $conf); + try + { + $tokenobj = $storage->retrieveAccessToken($OAUTH_SERVICENAME_GOOGLE); + } + catch(Exception $e) + { + // Return an error if token not found + } + if (is_object($tokenobj)) + { + //var_dump($tokenobj); + print $tokenobj->getAccessToken().'
'; + //print 'Refresh: '.$tokenobj->getRefreshToken().'
'; + //print 'EndOfLife: '.$tokenobj->getEndOfLife().'
'; + //var_dump($tokenobj->getExtraParams()); + /*print '
Extra:
';*/ + } + print ''; + print ''; + print ''; + print ''."\n"; + } } } else { print $langs->trans('PleaseSelectaDriverfromList');