webservice/library/WsScore/WsScore.php

377 lines
12 KiB
PHP
Raw Normal View History

<?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 'framework/mail/sendMail.php';
class WsScore
{
protected $dbConfig; //Configuration BDD Zend
protected $tabInfoUser; //Stockage des informations utilisateurs
/**
* List all application IPs
* @var array
*/
protected $listApplicationIp = array (
'127.0.0.1', //Development, and WebService himself
'88.191.79.121', //Extranet
'78.31.45.206', //SDSL RAMBOUILLET
);
2010-12-02 16:34:55 +00:00
protected $listeDroits = array(
'KBIS' => 'Extrait RCS',
'ACTES' => 'Pièces officielles',
'IDPROCOL' => 'Fiche procédure collective',
'PRIVILEGES' => 'Privilèges',
'IPARI' => 'Investigation par l\'image IparI&copy;',
'MARQUES' => 'Marques déposées',
'INDISCORE' => 'indiScore&copy;',
'INDISCORE2' => 'Rapport synthetique',
'INDISCORE3' => 'Rapport complet',
2011-01-04 08:32:31 +00:00
'INDISCOREP' => 'indiScore+',
'INDISCORE2P' => 'Rapport synthetique+',
'INDISCORE3P' => 'Rapport complet+',
2010-12-02 16:34:55 +00:00
'SCORECSF' => 'Score CSF',
'EVENINSEE' => '&Eacute;vènements INSEE',
'AVISINSEE' => 'Avis de situation INSEE',
'SURVANNONCE' => 'Surveillance des annonces légales',
'SURVINSEE' => 'Surveillance des événements INSEE',
'SURVBILAN' => 'Surveillance des bilans',
'SURVSCORE' => 'Surveillance des événements sur le score',
'SURVACTES' => 'Surveillance des actes',
'SURVDIRIGEANTS'=> 'Surveillance des dirigeants',
'SURVPAIEMENTS' => 'Surveillance des paiements',
2012-05-23 12:41:00 +00:00
'SURVLIENS' => 'Surveillance des liens financiers',
2010-12-02 16:34:55 +00:00
'SURVPRIV' => 'Surveillance des privilèges',
'SURVLISTE' => 'Liste des surveillances',
'PORTEFEUILLE' => 'Portefeuille',
'INVESTIG' => 'Investigation',
'ENQUETEC' => 'Enquête commerciale',
'INTERNATIONAL' => 'Recherche Internationale',
'BDF' => 'Banque de France',
'MONPROFIL' => 'Mon profil',
'EDITION' => 'Mode Edition',
2011-05-25 10:20:05 +00:00
'UPLOADBILAN' => 'Saisie de bilan',
'DIRIGEANTSOP' => 'Liste des dirigeants opérationnels',
'RECHCSV' => 'Export des résultats de la recherche',
'HISTOBODACC' => 'Historique des annonces bodacc',
2012-03-29 13:06:29 +00:00
'AVISCREDIT' => 'Avis de crédit personnalisé',
2012-05-23 12:41:00 +00:00
'GROUPE' => 'Informations et organigramme du groupe',
2010-12-02 16:34:55 +00:00
);
protected $listePrefs = array(
2011-12-14 10:48:05 +00:00
'NAF4' => "Afficher les anciens NAF",
'NACE' => "Afficher les codes NACES",
'NEWS' => "Afficher les news Google&copy;",
'MAPPY' => "Afficher les fa&ccedil;ades d'immeubles",
'CARTES' => "Afficher les cartes et les plans",
'VOIRSURV' => "Afficher les entités sous surveillances",
'DEMANDEREF' => "Demande de référence par defaut",
'RECHREF' => "Afficher le formulaire de recherche par référence",
2010-12-02 16:34:55 +00:00
);
public $listError = array(
2012-05-23 12:41:00 +00:00
'0900' => "Identifiant ou mot de passe incorrect",
2012-06-13 19:26:51 +00:00
'0901' => "Accès WS non authorisé pour cet utilisateur",
'0902' => "Méthode non authorisée dans votre profil",
'0903' => "Période d'accès au service invalide",
'0904' => "Adresse IP Invalide",
2012-05-23 12:41:00 +00:00
'1010' => 'Siren invalide',
2011-06-22 07:50:04 +00:00
'1011' => 'Identifiant invalide',
'1020' => 'Siren inexistant',
2011-06-21 15:02:23 +00:00
'1021' => 'Type d\'identifiant inexistant',
'1030' => 'Aucun résultat pour ce siren en base',
2012-05-23 12:41:00 +00:00
'3000' => 'Service disponible',
2012-05-23 12:41:00 +00:00
'9000' => 'Service S&D indisponible',
'9001' => 'Service partenaire indisponible',
'9002' => 'Méthode provisoirement indisponible',
2011-02-03 14:04:40 +00:00
'9003' => 'Version du service désactivé',
'9004' => 'Version du service inexistant',
'9010' => 'Fichier indisponible',
'9020' => 'Requête incorrecte',
2012-05-23 12:41:00 +00:00
);
2012-05-23 12:41:00 +00:00
2010-12-02 16:34:55 +00:00
public function __construct()
{
2010-11-25 16:51:05 +00:00
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');
$this->dbConfig = $dbConfig->db;
}
2012-05-23 12:41:00 +00:00
protected function sendError($code)
{
$message = 'Erreur inconnue';
2011-02-02 15:30:33 +00:00
if (array_key_exists($code, $this->listError)){
$message = $this->listError[$code];
}
throw new SoapFault($code,$message);
exit;
}
2012-05-23 12:41:00 +00:00
2011-01-13 16:52:27 +00:00
/**
* Enregistre l'appel utilisateur à une méthode
* @param $service
* @param $siret
* @param $ref
* @return void
*/
protected function wsLog($service, $siret='', $ref='')
{
$iDbCrm = new WDB('sdv1');
2012-05-23 12:41:00 +00:00
2011-01-13 16:52:27 +00:00
if (strlen($siret)==14) {
$siren = substr($siret,0,9);
$nic = substr($siret,9,5);
2011-01-13 16:52:27 +00:00
} elseif (strlen($siret)==9) {
$siren=$siret;
$nic='';
}
2012-05-23 12:41:00 +00:00
//Is it a test
2012-01-09 14:06:29 +00:00
if ($this->tabInfoUser['clientTest']=='Oui' || $this->tabInfoUser['typeCompte']=='TEST') {
$test=1;
} else {
$test=0;
}
2012-05-23 12:41:00 +00:00
//Read if client as pricing for this service
$pricing = $iDbCrm->select('clientsTarif', 'login, service',
"log='".$service."' AND idClient=" . $this->tabInfoUser['idClient'] .
" AND (service='".$this->tabInfoUser['service']."' OR service='') AND (login='".$this->tabInfoUser['login']."' OR login='') ".
" ORDER BY service, login DESC LIMIT 1");
if ( count($pricing)>0 ) {
//Update count access to a service
$sql = "UPDATE logsCount SET conso=conso+1 WHERE jour=NOW() AND idClient=".$this->tabInfoUser['idClient'].
" AND service='".$pricing[0]['service']."' AND login='".$pricing[0]['login']."' AND log='".$service."'";
$iDbCrm->query($sql);
$updateOk = $iDbCrm->getAffectedRows();
//If not insert
if ($updateOk==0) {
$sql = "INSERT INTO logsCount (jour, idClient, service, login, log, conso) ".
"VALUES (NOW(), ".$this->tabInfoUser['idClient'].", '".$pricing[0]['service']."', '".$pricing[0]['login']."', '".$service."', 1) ";
$iDbCrm->query($sql);
}
}
$rs = '';
$cp = '';
$vil = '';
2012-05-23 12:41:00 +00:00
$tabRdvInsee = array();
2012-01-24 17:27:48 +00:00
if (in_array($service, array(
2012-05-23 12:41:00 +00:00
'identite',
'greffe_bilans',
'greffe_actes',
'liens',
'dirigeants',
'etablissements',
2012-05-23 12:41:00 +00:00
'dirigeantsOp',
'kbis',
2012-01-24 17:27:48 +00:00
'indiscore', 'indiscore2', 'indiscore3', 'rapport2', 'rapport3'))
) {
if (intval($siren)>1000 && intval($nic)>9) $strNic=" AND nic=$nic ";
elseif (intval($siren)==0 && $ref>0) $strNic=" AND id=$ref ";
elseif (intval($siren)>1000) $strNic=" AND siege=1 ORDER BY actif DESC, nic DESC ";
else return;
2012-05-23 12:41:00 +00:00
$rep = $iDbCrm->select('jo.etablissements',
'siren, nic, actif, siege, raisonSociale, adr_cp, adr_ville, source',
2012-01-09 14:06:29 +00:00
"siren=$siren $strNic", false, MYSQL_ASSOC);
$tabRep = $rep[0];
$rs = $tabRep['raisonSociale'];
$cp = $tabRep['adr_cp'];
$vil = $tabRep['adr_ville'];
$tabRdvInsee['source']=$tabRep['source'];
if ($tabRep['actif']==0)
$tabRdvInsee['actifInsee']=0;
elseif (intval($siren)>1000) {
$tabRdvInsee['actifInsee']=1;
$rep=$iDbCrm->select('jo.rncs_entrep', 'count(*) AS nb', "siren=$siren", false, MYSQL_ASSOC);
$tabRep=$rep[0];
if ($tabRep['nb']>0) $tabRdvInsee['source']=5;
}
}
2012-05-23 12:41:00 +00:00
$tabInsert = array(
'login' => $this->tabInfoUser['login'],
'idClient' => $this->tabInfoUser['idClient'],
'page' => $service,
'siren' => $siren,
'nic' => $nic,
'params' => $ref,
'test' => $test,
'raisonSociale' => $rs,
'cp' => $cp,
'ville' => $vil,
'ipClient' => $this->tabInfoUser['ipConnexion'],
2011-01-13 16:52:27 +00:00
);
$rep = $iDbCrm->insert('logs', array_merge($tabInsert,$tabRdvInsee), false, true);
2011-01-13 16:52:27 +00:00
}
/**
* Retourne une erreur soap lors d'une mauvaise authentification
* @throws SoapFault
*/
protected function authenticate()
{
2012-05-23 12:41:00 +00:00
$auth = $this->checkAuth($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW'], $_SERVER['REMOTE_ADDR']);
if ( $auth === false ) {
$this->sendError('0900');
} elseif ( $auth !== true ) {
$this->sendError($auth);
}
}
2012-05-23 12:41:00 +00:00
2011-01-06 16:26:46 +00:00
protected function permission($perm)
{
2011-01-25 09:28:28 +00:00
if ( !$this->checkPerm($perm) ){
$this->sendError('0902');
2011-01-06 16:26:46 +00:00
}
}
2012-05-23 12:41:00 +00:00
/**
* checkAccesWS
* @throws SoapFault
*/
protected function checkAccesWS()
{
//Vérifier que l'utilisateur à le droit accesWS (clients/utilisateurs)
$accesWs = $this->tabInfoUser['accesWS'];
if ($accesWs){
$this->sendError('0901');
}
}
/**
* checPerm
* @param string $perm
* @throws SoapFault
*/
protected function checkPerm($perm)
{
$droits = $this->tabInfoUser['droits'];
2011-01-06 16:26:46 +00:00
$output = false;
if ( preg_match('/\b'.$perm.'\b/i', $droits) ){
$output = true;
}
2011-01-06 16:26:46 +00:00
return $output;
}
2012-05-23 12:41:00 +00:00
/**
* checkAuth
* @param string $login
* @param string $password
* @param string $ipConnexion
* @return mixed
*/
protected function checkAuth($login, $password, $ipConnexion)
{
$iDbCrm = new WDB('sdv1');
$rep = $iDbCrm->select(
2011-12-12 09:35:01 +00:00
'utilisateurs u, clients c',
'u.login, u.id, u.email, u.password, u.idClient, u.typeCompte, u.actif, u.filtre_ip, u.profil,'.
' u.pref, u.rechRefType, u.profil, u.nombreConnexions, u.dateDerniereConnexion, u.droits,'.
' u.referenceParDefaut, u.nbReponses, u.formatMail, u.dateDebutCompte, u.dateFinCompte, u.accesWS,'.
' c.droits AS droitsClients, c.test AS clientTest, c.typeScore, c.timeout',
2011-12-12 09:35:01 +00:00
"u.login='$login' AND u.idClient=c.id AND u.actif=1 AND u.deleted=0 AND c.actif='Oui'",
false, MYSQL_ASSOC
2012-05-23 12:41:00 +00:00
);
if (count($rep)>0)
{
// Récupération des informations de connexion
2012-05-23 12:41:00 +00:00
$tabRep = $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))) )
{
2012-03-15 15:01:45 +00:00
$timeOutSec = $tabRep['timeout'];
if ($timeOutSec==0) $timeOutSec=1800;
2011-12-12 09:35:01 +00:00
$this->tabInfoUser = array(
'login' => $login,
'id' => $tabRep['id'],
'email' => $tabRep['email'],
'typeCompte' => $tabRep['typeCompte'],
'idClient' => $tabRep['idClient'],
'filtre_ip' => $tabRep['filtre_ip'],
'ipConnexion' => $ipConnexion,
'pref' => $tabRep['pref'],
'rechRefType' => $tabRep['rechRefType'],
'profil' => $tabRep['profil'],
'nombreConnexions' => $tabRep['nombreConnexions'],
'dateDerniereConnexion' => $tabRep['dateDerniereConnexion'],
'droits' => $tabRep['droits'],
'droitsClients' => $tabRep['droitsClients'],
'timeout' => $timeOutSec,
'clientTest' => $tabRep['clientTest'],
'typeScore' => $tabRep['typeScore'],
'nbReponses' => $tabRep['nbReponses'],
'formatMail' => $tabRep['formatMail'],
'referenceParDefaut' => $tabRep['referenceParDefaut'],
'dateDebutCompte' => $tabRep['dateDebutCompte'],
'dateFinCompte' => $tabRep['dateFinCompte'],
);
2012-05-23 12:41:00 +00:00
debugLog('W',"CheckAuth $login/$password OK", __LINE__,__FILE__, __FUNCTION__, __CLASS__);
/**
* Date de debut de compte
*/
if ( !empty($tabRep['dateDebutCompte']) && $tabRep['dateDebutCompte']!='0000-00-00' ) {
$today = mktime(0, 0, 0, date('m'), date('d'), date('Y'));
$dateDebutCompte = mktime(0, 0, 0, substr($tabRep['dateDebutCompte'],5,2), substr($tabRep['dateDebutCompte'],8,2), substr($tabRep['dateDebutCompte'],0,4));
if ( $today < $dateDebutCompte ) {
return '0903';
2012-05-23 12:41:00 +00:00
}
}
2012-05-23 12:41:00 +00:00
/**
* Date de fin de compte
*/
if ( !empty($tabRep['dateFinCompte']) && $tabRep['dateFinCompte']!='0000-00-00' ) {
$today = mktime(0, 0, 0, date('m'), date('d'), date('Y'));
$dateFinCompte = mktime(0, 0, 0, substr($tabRep['dateFinCompte'],5,2), substr($tabRep['dateFinCompte'],8,2), substr($tabRep['dateFinCompte'],0,4));
if ( $today > $dateFinCompte) {
return '0903';
2012-05-23 12:41:00 +00:00
}
}
2012-05-23 12:41:00 +00:00
/**
* Acces WS, block access to other apps
*/
if ($tabRep['accesWS']==1) {
if ( in_array($ipConnexion, $this->listApplicationIp) && $tabRep['idClient']!=1 ) {
file_put_contents('test.log', 'ERREUR', FILE_APPEND);
return '0901';
}
}
2012-05-23 12:41:00 +00:00
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;
}
}