webservice/library/WsScore/WsScore.php
2010-11-25 16:51:05 +00:00

126 lines
5.5 KiB
PHP

<?php
require_once 'Metier/insee/classMInsee.php';
require_once 'Metier/insee/classMSirene.php';
require_once 'Metier/partenaires/classMBilans.php';
require_once 'Metier/partenaires/classMBourse.php';
require_once 'Metier/partenaires/classMLiens.php';
require_once 'Metier/partenaires/classMTva.php';
require_once 'Metier/partenaires/classMMap.php';
require_once 'Metier/partenaires/classMGreffes.php';
require_once 'Metier/partenaires/classMPrivileges.php';
require_once 'Metier/scores/classMFinancier.php';
require_once 'Metier/scores/classMSolvabilite.php';
require_once 'Metier/tmp/configMRatios.php';
require_once 'framework/mail/sendMail.php';
class WsScore
{
protected $dbConfig; //Configuration BDD Zend
protected $tabInfoUser; //Stockage des informations utilisateurs
public function __construt()
{
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));
$dbConfig = new Zend_Config_Ini(APPLICATION_PATH .
'/configs/databases.ini', APPLICATION_ENV);
$this->dbConfig = $dbConfig->db;
}
/**
* Retourne une erreur soap lors d'une mauvaise authentification
* @throws SoapFault
*/
protected function authenticate()
{
if (!$this->checkAuth($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW'], $_SERVER['REMOTE_ADDR']))
{
throw new SoapFault('900','Identifiant ou mot de passe incorrect !');
exit;
}
}
/**
* checkAuth
* @param string $login
* @param string $password
* @param string $ipConnexion
* @return boolean
*/
protected function checkAuth($login, $password, $ipConnexion)
{
$iDbCrm = new WDB('sdv1');
$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;
$this->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];
$this->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;
}
}