WIP IFTTT setup

This commit is contained in:
Laurent Destailleur 2019-03-22 19:20:54 +01:00
parent aab9734f52
commit 82d90a201c
2 changed files with 119 additions and 37 deletions

View File

@ -38,11 +38,12 @@ if (! $user->admin)
$action=GETPOST('action', 'aZ09');
if ($action == 'setproductionmode')
if ($action == 'set')
{
$status = GETPOST('status', 'alpha');
$res1 = dolibarr_set_const($db, 'IFTTT_SERVICE_KEY', GETPOST('IFTTT_SERVICE_KEY', 'alpha'), 'chaine', 0, '', 0);
$res2 = dolibarr_set_const($db, 'IFTTT_DOLIBARR_ENDPOINT_SECUREKEY', GETPOST('IFTTT_DOLIBARR_ENDPOINT_SECUREKEY', 'alpha'), 'chaine', 0, '', 0);
if (dolibarr_set_const($db, 'IFTTT_PRODUCTION_MODE', $status, 'chaine', 0, '', 0) > 0)
if ($res1 > 0 && $res2)
{
header("Location: ".$_SERVER["PHP_SELF"]);
exit;
@ -66,38 +67,44 @@ print load_fiche_titre($langs->trans("IFTTTSetup"), $linkback, 'title_setup');
print $langs->trans("IFTTTDesc")."<br>\n";
print "<br>\n";
//print '<form name="apisetupform" action="'.$_SERVER["PHP_SELF"].'" method="post">';
print '<form name="apisetupform" action="'.$_SERVER["PHP_SELF"].'" method="post">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="action" value="set">';
print '<table class="noborder" width="100%">';
print '<tr class="liste_titre">';
print "<td>".$langs->trans("Parameter")."</td>";
print '<td class="center">'.$langs->trans("Value")."</td>";
print '<td>'.$langs->trans("Value")."</td>";
print "<td>&nbsp;</td>";
print "</tr>";
print '<tr class="impair">';
print '<td>'.$langs->trans("ProductionMode").'</td>';
$production_mode=(empty($conf->global->IFTTT_PRODUCTION_MODE)?false:true);
if ($production_mode)
{
print '<td class="center"><a href="'.$_SERVER['PHP_SELF'].'?action=setproductionmode&value='.($i+1).'&status=0">';
print img_picto($langs->trans("Activated"), 'switch_on');
print '</a></td>';
}
else
{
print '<td class="center"><a href="'.$_SERVER['PHP_SELF'].'?action=setproductionmode&value='.($i+1).'&status=1">';
print img_picto($langs->trans("Disabled"), 'switch_off');
print '</a></td>';
}
print '<td>&nbsp;</td>';
print '<tr class="oddeven">';
print '<td>'.$langs->trans("IFTTT_SERVICE_KEY").'</td>';
print '<td>';
print '<input type="text" name="IFTTT_SERVICE_KEY" value="'.$conf->global->IFTTT_SERVICE_KEY.'">';
print '</td>';
print '<td>'.$langs->trans("YouWillFindItOnYourIFTTTAccount").'</td>';
print '</tr>';
print '<tr class="oddeven">';
print '<td>'.$langs->trans("IFTTT_DOLIBARR_ENDPOINT_SECUREKEY").'</td>';
print '<td>';
print '<input type="text" name="IFTTT_DOLIBARR_ENDPOINT_SECUREKEY" value="'.$conf->global->IFTTT_DOLIBARR_ENDPOINT_SECUREKEY.'">';
print '</td>';
print '<td>'.$langs->trans("DefineAValueOfYourChoice").'</td>';
print '</tr>';
print '</table>';
print '<div class="center">';
print '<input type="submit" name="save" class="button" value="'.$langs->trans("Save").'">';
print '</div>';
print '</form>';
print '<br><br>';
/*
// Define $urlwithroot
$urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root));
@ -106,26 +113,13 @@ $urlwithroot=$urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain
// Show message
$message='';
$url=$urlwithroot.'/api/index.php/login?login=<strong>auserlogin</strong>&password=<strong>thepassword</strong>[&reset=1]';
$message.=$langs->trans("UrlToGetKeyToUseAPIs").':<br>';
$url=$urlwithroot.'/ifttt/index.php?securekey='.$conf->global->IFTTT_DOLIBARR_ENDPOINT_SECUREKEY;
$message.=$langs->trans("UrlForIFTTT").':<br>';
$message.=img_picto('', 'object_globe.png').' '.$url;
print $message;
print '<br>';
print '<br>';
// Explorer
print '<u>'.$langs->trans("ApiExporerIs").':</u><br>';
if (dol_is_dir(DOL_DOCUMENT_ROOT.'/includes/restler/framework/Luracast/Restler/explorer'))
{
$url=DOL_MAIN_URL_ROOT.'/api/index.php/explorer';
print img_picto('', 'object_globe.png').' <a href="'.$url.'" target="_blank">'.$url."</a><br>\n";
}
else
{
print $langs->trans("NotAvailableWithThisDistribution");
}
*/
llxFooter();
$db->close();

View File

@ -0,0 +1,88 @@
<?php
/* Copyright (C) 2008-2010 Laurent Destailleur <eldy@users.sourceforge.net>
*
* 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 <http://www.gnu.org/licenses/>.
*/
/**
* \file htdocs/public/ifttt/index.php
* \ingroup ifttt
* \brief Page to IFTTT endpoint agenda
* http://127.0.0.1/dolibarr/public/ifttt/index.php?securekey=...
*/
if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL', '1');
if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU', '1'); // If there is no menu to show
if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML', '1'); // If we don't need to load the html.form.class.php
if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX', '1');
if (! defined('NOLOGIN')) define("NOLOGIN", 1); // This means this output page does not require to be logged.
if (! defined('NOCSRFCHECK')) define("NOCSRFCHECK", 1); // We accept to go on this page from external web site.
// This is a wrapper, so header is empty
/**
* Header function
*
* @return void
*/
function llxHeaderVierge()
{
print '<html><title>IFTTT API</title><body>';
}
/**
* Footer function
*
* @return void
*/
function llxFooterVierge()
{
print '</body></html>';
}
require '../../main.inc.php';
// Security check
if (empty($conf->ifttt->enabled)) accessforbidden('', 0, 0, 1);
// Check config
if (empty($conf->global->IFTTT_DOLIBARR_ENDPOINT_SECUREKEY))
{
$user->getrights();
llxHeaderVierge();
print '<div class="error">Module Agenda was not configured properly.</div>';
llxFooterVierge();
exit;
}
// Check exportkey
if (empty($_GET["securekey"]) || $conf->global->IFTTT_DOLIBARR_ENDPOINT_SECUREKEY != $_GET["securekey"])
{
$user->getrights();
llxHeaderVierge();
print '<div class="error">Bad value for securekey.</div>';
llxFooterVierge();
exit;
}
// Initialize technical object to manage hooks. Note that conf->hooks_modules contains array of hooks
$hookmanager->initHooks(array('iftttapi'));
llxHeaderVierge();
print '<div class="error">TODO</div>';
llxFooterVierge();