webservice/html/ws2/index.php
2010-11-29 14:17:26 +00:00

197 lines
8.3 KiB
PHP

<?
error_reporting(E_ALL ^ E_NOTICE);
define ('DATETIME', date('YmdHis'));
define ('DATE', substr(DATETIME,0,8));
define ('TIME', substr(DATETIME,8,6));
define ('DATE_LISIBLE', substr(DATETIME,6,2).'/'.substr(DATETIME,4,2).'/'.substr(DATETIME,0,4));
define ('TIME_LISIBLE', substr(DATETIME,8,2).':'.substr(DATETIME,10,2).':'.substr(DATETIME,12,2));
/**
* Inclusion du fichier de configuration des includes Métiers de S&D
*/
include '/var/www/includes/config.php';
/**
* Inclusion du Framework
*/
if( !defined('FWK_PATH') )
include '/var/www/framework/fwk.php';
include_once('WsEntreprise.php');
global $tabInfoUser;
global $iDbCrm;
$iDbCrm=new WDB('sdv1');
function checkAuth($login, $password, $ipConnexion) {
global $iDbCrm;
global $tabInfoUser;
$rep=$iDbCrm->select(//'utilisateurs', 'login, id, email, password, idClient, typeCompte, filtre_ip, civilite, nom, prenom, tel, fax, mobile, profil, raisonSociale, siret, adrNum, adrIndRep, adrTypeVoie, adrLibVoie, adrCp, adrVille, adrComp, tel, fax, mobile, pref, profil, dateInscription, dateValidation, nombreConnexions, dateDerniereConnexion, droits, referenceParDefaut, nbReponses, formatMail, dateDebutCompte, dateFinCompte, maxFicheId', "login='$login' AND actif=1", true, MYSQL_ASSOC);
'utilisateurs u, clients c',
'u.login, u.id, u.email, u.password, u.idClient, u.typeCompte, u.actif, u.filtre_ip, u.civilite, u.nom, u.prenom, u.tel, u.fax, u.mobile, u.profil, u.raisonSociale, u.siret, u.adrNum, u.adrIndRep, u.adrTypeVoie, u.adrLibVoie, u.adrCp, u.adrVille, u.adrComp, u.tel, u.fax, u.mobile, u.pref, u.profil, u.dateInscription, u.dateValidation, u.nombreConnexions, u.dateDerniereConnexion, u.droits, u.referenceParDefaut, u.nbReponses, u.formatMail, u.dateDebutCompte, u.dateFinCompte, u.maxFicheId, c.droits AS droitsClients, c.timeout',
"u.login='$login' AND u.idClient=c.id AND u.actif=1 AND u.deleted=0 AND c.actif='Oui'",
true, MYSQL_ASSOC);
$tabRep=$rep[0];
if (count($rep)>0) {
if ($tabRep['password']==$password ||
$tabRep['password']==md5($password) ||
$password==md5($login.'|'.$tabRep['password']) ||
(substr($password,0,7)=='iponly:' && checkPlagesIp($tabRep['filtre_ip'], substr($password,7)))) // Controle par IP
{
$timeOutSec=$tabRep['timeout']*60;
if ($timeOutSec==0) $timeOutSec=1800;
$tabInfoUser=array( 'login'=> $login,
'id'=> $tabRep['id'],
'email'=> $tabRep['email'],
'typeCompte'=> $tabRep['typeCompte'],
'idClient'=> $tabRep['idClient'],
'filtre_ip'=> $tabRep['filtre_ip'],
'ipPasserelle'=> '',
'ipConnexion'=> $ipConnexion,
'civilite'=> $tabRep['civilite'],
'nom'=> $tabRep['nom'],
'prenom'=> $tabRep['prenom'],
'raisonSociale'=> $tabRep['raisonSociale'],
'siret'=> $tabRep['siret'],
'adrNum'=> $tabRep['adrNum'],
'adrIndRep'=> $tabRep['adrIndRep'],
'adrTypeVoie'=> $tabRep['adrTypeVoie'],
'adrLibVoie'=> $tabRep['adrLibVoie'],
'adrCp'=> $tabRep['adrCp'],
'adrVille'=> $tabRep['adrVille'],
'adrComp'=> $tabRep['adrComp'],
'tel'=> $tabRep['tel'],
'fax'=> $tabRep['fax'],
'mobile'=> $tabRep['mobile'],
'pref'=> $tabRep['pref'],
'profil'=> $tabRep['profil'],
'dateInscription'=> $tabRep['dateInscription'],
'dateValidation'=> $tabRep['dateValidation'],
'nombreConnexions'=> $tabRep['nombreConnexions'],
'dateDerniereConnexion'=> $tabRep['dateDerniereConnexion'],
'droits'=> $tabRep['droits'],
'droitsClients'=> $tabRep['droitsClients'],
'timeout'=> $timeOutSec,
'nbReponses'=> $tabRep['nbReponses'],
'formatMail'=> $tabRep['formatMail'],
'referenceParDefaut'=> $tabRep['referenceParDefaut'],
'dateDebutCompte'=> $tabRep['dateDebutCompte'],
'dateFinCompte'=> $tabRep['dateFinCompte'],
'maxFicheId'=> $tabRep['maxFicheId'],
);
$tabTmp=$iDbCrm->select('clients', 'typeScore', 'id='.$tabRep['idClient'], true, MYSQL_ASSOC);
$tabRep=$tabTmp[0];
$tabInfoUser['typeScore']=$tabRep['typeScore'];
debugLog('W',"CheckAuth $login/$password OK", __LINE__,__FILE__, __FUNCTION__, __CLASS__);
return true;
}
debugLog('W',"CheckAuth $login/$password incorrect (IP=$ipConnexion)", __LINE__,__FILE__, __FUNCTION__, __CLASS__);
return false;
}
debugLog('W',"CheckAuth $login/$password inexistant ou inactif (IP=$ipConnexion)", __LINE__,__FILE__, __FUNCTION__, __CLASS__);
return false;
}
ini_set("soap.wsdl_cache_enabled", "0");
/*
$server = new SoapServer(null, array('uri' => "http://test-uri/"));
$server->addFunction('rechercheAsso');
$server->addFunction('identiteAsso');
if ($_SERVER['REQUEST_METHOD']=='POST')
$server->handle();
else
die('WebService Association de scores et décisions');
*/
// On tente d'instancier la classe soapServer
// Si cela s'avère impossible, on lève une exception
try {/*array('trace' => false
,'exceptions' => false
,'proxy_host' => "monproxy"
,'proxy_port' => monport
,'local_cert' => "conf/clientCert.pem"
,'passphrase' => "monpassword"
)
);*/
$server = new SoapServer(null, array('uri' => "http://viete.scores-decisions.com/",
'soap_version' => SOAP_1_1,
'encoding' =>'UTF-8',
'style' => SOAP_RPC,
'use' => SOAP_ENCODED,
));
//"etab.wsdl", array('trace' => 1, 'soap_version' => SOAP_1_1));//(null, array('uri' => "http://test-uri/"));//
// On définit la classe qui va gérer les requètes SOAP
$server -> setclass('WsEntreprise');
} catch (Exception $e) {
debugLog('E','Exception : '.$e,__LINE__,__FILE__, __FUNCTION__, __CLASS__);
echo $e;
}
// La méthode POST a été utilisée pour appeller cette page.
// On suppose donc qu'une requète a été envoyée, on la gère
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
if (checkAuth($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW'], $_SERVER['REMOTE_ADDR']))
//if ($_SERVER['PHP_AUTH_USER']=='TEST' && $_SERVER['PHP_AUTH_PW']=='prout')
$server->handle();
else {
$server->fault('900', 'Identifiant ou mot de passe incorrect');
debugLog('W','Couple Identifiant/Mot de passe incorrect ('.$_SERVER['PHP_AUTH_USER'].'/'.$_SERVER['PHP_AUTH_PW'].')',__LINE__,__FILE__, __FUNCTION__, __CLASS__);
}
//$server->fault('999', 'Service indisponible');
}
// sinon, on affiche une liste des méthodes que peut gérer ce serveur
elseif ($_SERVER['REMOTE_ADDR']=='83.206.102.217' && isset($_REQUEST['wsdl'])) {
echo 'wsdl';
debugLog('N','Accès en GET au WebService WSDL',__LINE__,__FILE__, __FUNCTION__, __CLASS__);
}
else {
echo '<strong>This SOAP server can handle following functions : </strong>';
echo '<ul>';
$str=file_get_contents('./WsEntreprise.php');
// die($str);
foreach($server -> getFunctions() as $func) {
preg_match('#\/\*\*([^\/]*)\*\/(?:\s+)function(?: +|\()'.$func.'#sU', $str, $matches);
if (!preg_match('/@nodoc/i', $matches[1])) {
$tabFunc[$func]=$matches[1];
echo '<li><a href="#'.$func.'">' , $func , '</a></li>';
}
// <a href="[^>]+">[^<]+</a>`';
//print_r($matches);
}
debugLog('N','Accès en GET au WebService',__LINE__,__FILE__, __FUNCTION__, __CLASS__);
?></ul>
<hr/>
<table>
<? foreach($tabFunc as $func=>$infos)
{ //if (!preg_match('/@nodoc/i', $infos)) {
?><tr><td><b><u><a name="<?=$func?>"><?=$func?></a></u></b></td></tr>
<tr><td><pre><?=strtr(htmlentities($infos),array( '@param'=>'Param&egrave;tre',
'@return'=>'Retourne ',
'$'=>'', '*'=>''
))?></pre></td></tr><?
}//}
echo '</table>';
}
function wsLog($service, $siret='', $ref='') {
if (strlen($siret)==14) {
$siren=substr($siret,0,9);
$nic=substr($siret,9,5);
} elseif (strlen($siret)==9) {
$siren=$siret;
$nic='';
}
global $iDbCrm, $tabInfoUser;
$tabInsert=array( 'login'=>$tabInfoUser['login'],
'page'=>$service,
'siren'=>$siren,
'nic'=>$nic,
'params'=>$ref);
$rep=$iDbCrm->insert('logs', $tabInsert);
}
?>