From: Pascal Corpet Date: Fri, 27 May 2005 14:14:41 +0000 (+0000) Subject: synchro ax reparee X-Git-Tag: xorg/old~103 X-Git-Url: http://git.polytechnique.org/?a=commitdiff_plain;h=38d37c94a9dca58bd9004957bd64f7bdb7b28e30;p=platal.git synchro ax reparee git-archimport-id: opensource@polytechnique.org--2005/platal--mainline--0.9--patch-659 --- diff --git a/include/synchro_ax.inc.php b/include/synchro_ax.inc.php index 5c7876e..4317f1f 100644 --- a/include/synchro_ax.inc.php +++ b/include/synchro_ax.inc.php @@ -26,8 +26,7 @@ require_once('user.func.inc.php'); function get_user_ax($uid, $raw=false) { - require_once('webservices/manageurs.inc.php'); - require_once('webservices/manageurs.client.inc.php'); + require_once('webservices/ax/client.inc'); global $globals; @@ -37,93 +36,62 @@ function get_user_ax($uid, $raw=false) WHERE u.user_id = {?}", $uid); $matricule_ax = $res->fetchOneCell(); - $array = get_annuaire_infos(2, $matricule_ax, 0); + $ancien = recupere_infos_ancien($matricule_ax); $userax = Array(); $userax['matricule_ax'] = $matricule_ax; $userax['uid'] = $uid; - $ancien = $array['dump']['ancien']; - $userax['nom'] = $ancien[0]; - // ancien1 = ? - $userax['nom_usage'] = ($ancien[2] != $ancien[0])?$ancien[2]:""; - // ancien3 = ? - $userax['prenom'] = $ancien[4]; - $userax['sexe'] = ($ancien[5] != 'M')?1:0; - $userax['promo'] = $ancien[6]; - // ancien7 = Type de membre à l'AX - // ancien8 = dernière année de cotisation - $userax['nationalite'] = $ancien[9]; + $userax['nom'] = $ancien->Nom_patr(); + $userax['nom_usage'] = $ancien->Nom_usuel(); + if ($userax['nom_usage'] == $userax['nom']) $userax['nom_usage'] = ''; + $userax['prenom'] = $ancien->Prenom(); + $userax['sexe'] = ($ancien->Civilite() != 'M')?1:0; + $userax['promo'] = $ancien->Promo(); + $userax['nationalite'] = $ancien->Nationalite(); if ($userax['nationalite'] == 'F') $userax['nationalite'] = 'Français'; - // ancien10 = ? - // ancine11 = ? - $userax['date'] = substr($ancien[12], 0, 10); - $userax['mobile'] = $array['cell']; - if ($ancien[13] == 'D' || $ancien[13] == 'Z') { + //$userax['date'] = substr($ancien[12], 0, 10); + $userax['mobile'] = $ancien->Mobile(0); + if ($ancien->Corps() == 'D' || $ancien->Corps() == 'Z') { $userax['applis_join'] = "pas un corps"; } else { - $userax['applis_join'] = "Corps ".$ancien[13]." - ".$ancien[14]; + $userax['applis_join'] = "Corps ".$ancien->Corps()." - ".$ancien->Grade(); } - // ancien15 = login AX - // ancien16 = ? - // ancien17 = prenom.nom - $userax['adr_pro'] = array(); - if (is_array($array['dump']['pro'])) { - foreach ($array['dump']['pro'] as $job) { - // job0 = code identifiant de l'entreprise - $jobax['entreprise'] = $job[1]; - // job2 = comme job1 (peut etre plus court pour les noms longs) - // job4 = sigle de l'entreprise - // job5 = maj de l'adresse pro - $jobax['fonction'] = $job[6]; - // job7 = ? peut être id de l'adresse dans la base AX - // job8 = matricule AX - // job9 = type d'adresse PRO = professionelle - $jobax['adr1'] = $job[10]; - $jobax['adr2'] = $job[11]; - $jobax['adr3'] = $job[12]; - $jobax['cp'] = $job[13]; - $jobax['ville'] = $job[14]; - // job15 = ? - // job16 = ? - $jobax['pays'] = $job[17]; - // job18 = ? - $jobax['tel'] = $job[19]; - $jobax['fax'] = $job[20]; - // job21 = f ? - // job22 = ? - // job23 = date de mise à jour de l'adresse - // job24 = ? - $userax['adr_pro'][] = $jobax; - } + + for ($i = 0; $i < $ancien->Num_Activite(); $i++) { + $jobax = array(); + $jobax['entreprise'] = $ancien->Entreprise($i); + $jobax['fonction'] = $ancien->Fonction($i); + $jobax['adr1'] = $ancien->Adresse_act_adresse1($i); + $jobax['adr2'] = $ancien->Adresse_act_adresse2($i); + $jobax['adr3'] = $ancien->Adresse_act_adresse3($i); + $jobax['cp'] = $ancien->Adresse_act_code_pst($i); + $jobax['ville'] = $ancien->Adresse_act_ville($i); + $jobax['region'] = $ancien->Adresse_act_etat_region($i); + $jobax['pays'] = $ancien->Adresse_act_pays($i); + $jobax['tel'] = $ancien->Adresse_act_tel($i); + $jobax['fax'] = $ancien->Adresse_act_fax($i); + $jobax['mobile'] = $ancien->Adresse_act_mobile($i); + $userax['adr_pro'][] = $jobax; } $userax['adr'] = array(); - if (is_array($array['dump']['adresse'])) { - foreach ($array['dump']['adresse'] as $adr) { - // adr0 : ? - // adr1 = matricule ax - // adr2 = type d'adresse P = personnelle - $adrax['adr1'] = $adr[3]; - $adrax['adr2'] = $adr[4]; - $adrax['adr3'] = $adr[5]; - $adrax['cp'] = $adr[6]; - $adrax['ville'] = $adr[7]; - // adr8 = ? - // adr9 = ? - $adrax['pays'] = $adr[10]; - // adr 11 = ? - $adrax['tel'] = $adr[12]; - $adrax['fax'] = $adr[13]; - // adr 14 = t ? - // adr15 = ? - // adr 16 = date de mise a jour - $userax['adr'][] = $adrax; - } + foreach ($array['dump']['adresse'] as $adr) { + $adrax = array(); + $adrax['adr1'] = $ancien->Adresse1($i); + $adrax['adr2'] = $ancien->Adresse2($i); + $adrax['adr3'] = $ancien->Adresse3($i); + $adrax['cp'] = $ancien->Code_pst($i); + $adrax['ville'] = $ancien->Ville($i); + $adrax['region'] = $ancien->Etat_region($i); + $adrax['pays'] = $ancien->Pays($i); + $adrax['tel'] = $ancien->Tel($i); + $adrax['fax'] = $ancien->Fax($i); + $userax['adr'][] = $adrax; } if ($raw) { - $userax['raw'] = $array; + $userax['raw'] = $ancien; } return $userax; diff --git a/include/webservices/ax/client.inc b/include/webservices/ax/client.inc new file mode 100755 index 0000000..8a77c0a --- /dev/null +++ b/include/webservices/ax/client.inc @@ -0,0 +1,415 @@ +'') + { + foreach ($aa as $k=>$v) + $this->$k = $aa[$k]; + } + } + function Ajout_adresse ($adresse,$i) { + $this->ADRESSE[$i] = $adresse; + $this->NUM_ADRESSE++; + } + function Ajout_activite ($activite,$i) { + $this->ACTIVITE[$i] = $activite; + $this->NUM_ACTIVITE++; + } + function Ajout_formation ($formation,$i) { + $this->FORMATION[$i] = $formation; + $this->NUM_FORMATION++; + } + function Ajout_erreur ($erreur) { + $this->Erreur = $erreur; + } + function Erreur() { + return $this->Erreur; + } + function Nom_patr() { + return $this->NOM_PATR; + } + function Part_nom() { + return $this->PART_NOM; + } + function Prenom() { + return $this->PRENOM; + } + function Nom_usuel() { + return $this->NOM_USUEL; + } + function Part_nomus() { + return $this->PART_NOMUS; + } + function Nom_complet() { + return $this->NOM_COMPLET; + } + function Civilite() { + return $this->CIVILITE; + } + function Grade() { + return $this->GRADE; + } + function Corps() { + return $this->CORPS; + } + function Corps_Libelle() { + return $this->CORPS_LIBELLE; + } + function Promo() { + return $this->PROMO; + } + function Nationalite() { + return $this->NATIONALITE; + } + function Email() { + return $this->EMAIL; + } + function Adresse_type($i) { + return $this->ADRESSE[$i]->TYPE; + } + function Adresse1($i) { + return $this->ADRESSE[$i]->ADRESS1; + } + function Adresse2($i) { + return $this->ADRESSE[$i]->ADRESS2; + } + function Adresse3($i) { + return $this->ADRESSE[$i]->ADRESS3; + } + function Code_pst($i) { + return $this->ADRESSE[$i]->CODE_PST; + } + function Ville($i) { + return $this->ADRESSE[$i]->VILLE; + } + function Zip_cedex($i) { + return $this->ADRESSE[$i]->ZIPCEDEX; + } + function Etat_region($i) { + return $this->ADRESSE[$i]->ETATREGION; + } + function Pays($i) { + return $this->ADRESSE[$i]->PAYS; + } + function Mobile($i) { + return $this->ADRESSE[$i]->MOBILE; + } + function Tel($i) { + return $this->ADRESSE[$i]->TEL; + } + function Fax($i) { + return $this->ADRESSE[$i]->FAX; + } + function Num_adresse() { + return $this->NUM_ADRESSE; + } + function Entreprise($i) { + return $this->ACTIVITE[$i]->ENTREPRISE;; + } + function Raison_sociale($i) { + return $this->ACTIVITE[$i]->RAISON_SOCIALE; + } + function Fonction($i) { + return $this->ACTIVITE[$i]->FONCTION; + } + function Adresse_act_type($i) { + return $this->ACTIVITE[$i]->TYPE; + } + function Adresse_act_adresse1($i) { + return $this->ACTIVITE[$i]->ADRESS1; + } + function Adresse_act_adresse2($i) { + return $this->ACTIVITE[$i]->ADRESS2; + } + function Adresse_act_adresse3($i) { + return $this->ACTIVITE[$i]->ADRESS3; + } + function Adresse_act_code_pst($i) { + return $this->ACTIVITE[$i]->CODE_PST; + } + function Adresse_act_ville($i) { + return $this->ACTIVITE[$i]->VILLE; + } + function Adresse_act_zip_cedex($i) { + return $this->ACTIVITE[$i]->ZIPCEDEX; + } + function Adresse_act_etat_region($i) { + return $this->ACTIVITE[$i]->ETATREGION; + } + function Adresse_act_pays($i) { + return $this->ACTIVITE[$i]->PAYS; + } + function Adresse_act_mobile($i) { + return $this->ACTIVITE[$i]->MOBILE; + } + function Adresse_act_tel($i) { + return $this->ACTIVITE[$i]->TEL; + } + function Adresse_act_fax($i) { + return $this->ACTIVITE[$i]->FAX; + } + function Num_activite() { + return $this->NUM_ACTIVITE; + } + function Formation($i) { + return $this->FORMATION[$i]->LIBELLE; + } + function Num_formation() { + return $this->NUM_FORMATION; + } + } + + class Adresse { + var $TYPE; + var $ADRESS1; + var $ADRESS2; + var $ADRESS3; + var $CODE_PST; + var $VILLE; + var $ZIPCEDEX; + var $ETATREGION; + var $PAYS; + var $MOBILE; + var $TEL; + var $FAX; + + function Adresse ($aa) { + foreach ($aa as $k=>$v) + $this->$k = $aa[$k]; + } + } + + class Activite { + var $ENTREPRISE; + var $RAISON_SOCIALE; + var $FONCTION; + var $TYPE; + var $ADRESS1; + var $ADRESS2; + var $ADRESS3; + var $CODE_PST; + var $VILLE; + var $ZIPCEDEX; + var $ETATREGION; + var $PAYS; + var $MOBILE; + var $TEL; + var $FAX; + + function Activite ($aa) { + foreach ($aa as $k=>$v) + $this->$k = $aa[$k]; + } + } + + class Formation { + var $LIBELLE; + + function Formation ($aa) { + foreach ($aa as $k=>$v) + $this->$k = $aa[$k]; + } + } + + function xml_get_children($vals, &$i) { + $children = array(); + if (isset($vals[$i]['value'])) $children[] = $vals[$i]['value']; + + while (++$i < count($vals)) { + switch ($vals[$i]['type']) { + case 'cdata': + $children[] = $vals[$i]['value']; + break; + + case 'complete': + $children[] = array( + 'tag' => $vals[$i]['tag'], + 'attributes' => isset($vals[$i]['attributes'])? + $vals[$i]['attributes'] : null, + 'value' => $vals[$i]['value'], + ); + break; + + case 'open': + $children[] = array( + 'tag' => $vals[$i]['tag'], + 'attributes' => isset($vals[$i]['attributes'])? + $vals[$i]['attributes'] : null, + 'children' => xml_get_children($vals, $i), + ); + break; + + case 'close': + return $children; + } + } + } + + //fonction principale de récupération des données de l'ancien + //à indiquer: matricule de l'ancien + function recupere_infos_ancien($AX_MATRICULE) + { + include('config.inc'); + + $id =13;//13 params persos ancien + $id_ad = 11; //12 params adresse + $id_ac = 14; //15 params adresse + $id_fo = 1; //1 params fonction + + $erreur = ""; + + // Génération d'un identifiant de "session" inter-serveurs + $id_session = md5 (uniqid (rand())); + + // Connexion au serveur pour lui fournir l'identifiant et lui demander un challenge + $challenge = file_get_contents ($nom_script_renvoi_challenge."?id_session=".urlencode($id_session)); + if ($challenge == 'ERROR') + { + $erreur = "Erreur lors de la demande du challenge"; + } + else + { + // On va relire la clé privée (codée) + $privkeypass = $phrase; + $pkey_txt = file_get_contents ($chemin_cle_privee); + if (($pkey_res = openssl_pkey_get_private($pkey_txt, $privkeypass)) == false) + { + $erreur = "Erreur lors de l'ouverture de la clé privée"; + } + else + { + // Signature du challenge (cryptage avec clé privée) + if ( openssl_private_encrypt($challenge, $response, $pkey_res) == false ) + { + $erreur = "Erreur lors du cryptage du challenge avec la clé privée"; + } + else + { + // Signature du login (cryptage avec clé privée) + if ( openssl_private_encrypt($AX_MATRICULE, $AX_MATRICULE_CRYPTE, $pkey_res) == false ) + { + $erreur = "Erreur lors du cryptage du matricule avec la clé privée"; + } + else + { + // Envoi de la réponse au serveur avec l'identifiant de l'ancien dont on veut récupérer les infos + $reponse_serveur .= file_get_contents ($nom_script_renvoi_infos."?id_session=".urlencode($id_session)."&AX_MATRICULE_CRYPTE=".urlencode($AX_MATRICULE_CRYPTE)."&response=".urlencode($response)); + + $parser = xml_parser_create(); + xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0); + xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1); + xml_parse_into_struct($parser, $reponse_serveur, $vals, $index); + xml_parser_free($parser); + + $tree = array(); + $tree[] = array( + 'tag' => $vals[0]['tag'], + 'attributes' => isset($vals[0]['attributes'])? + $vals[0]['attributes'] : null, + 'children' => xml_get_children($vals, $i = 0), + ); + + for ($i=0; $i < $id; $i++) + { + $val_ancien[$tree[0]['children'][0]['children'][$i]['tag']] = $tree[0]['children'][0]['children'][$i]['value']; + } + + $Ancien_renvoye = new Ancien($val_ancien); + + //adresse while pour nbre d'adresses + $num_ad = 0; + while ($tree[0]['children'][0]['children'][$id]['tag'] == 'ADRESSE') + { + for ($i=0; $i <= $id_ad; $i++) + { + $val_adresse[$tree[0]['children'][0]['children'][$id]['children'][$i]['tag']] = $tree[0]['children'][0]['children'][$id]['children'][$i]['value']; + } + + $Adresse_renvoyee = new Adresse($val_adresse); + $Ancien_renvoye->Ajout_adresse($Adresse_renvoyee,$num_ad); + + //prochaine adresse + $num_ad = $num_ad + 1; + $id = $id+1; + } + + //idem pour activité + $num_ac = 0; + while ($tree[0]['children'][0]['children'][$id]['tag'] == 'ACTIVITE') + { + for ($i=0; $i <= $id_ac; $i++) + { + $val_activite[$tree[0]['children'][0]['children'][$id]['children'][$i]['tag']] = $tree[0]['children'][0]['children'][$id]['children'][$i]['value']; + + for ($j=0; $j <= $id_ad; $j++) + { + $val_activite[$tree[0]['children'][0]['children'][$id]['children'][$i]['children'][$j]['tag']] = $tree[0]['children'][0]['children'][$id]['children'][$i]['children'][$j]['value']; + } + } + + $Activite_renvoyee = new Activite($val_activite); + $Ancien_renvoye->Ajout_activite($Activite_renvoyee,$num_ac); + + //prochaine activité + $num_ac = $num_ac + 1; + $id = $id+1; + } + //idem pour formation + $num_fo = 0; + while ($tree[0]['children'][0]['children'][$id]['tag'] == 'FORMATION') + { + for ($i=0; $i <= $id_fo; $i++) + { + $val_formation[$tree[0]['children'][0]['children'][$id]['children'][$i]['tag']] = $tree[0]['children'][0]['children'][$id]['children'][$i]['value']; + } + + $Formation_renvoyee = new Formation($val_formation); + $Ancien_renvoye->Ajout_formation($Formation_renvoyee,$num_fo); + + //prochaine formation + $num_fo = $num_fo + 1; + $id = $id+1; + } + } + } + } + } + + //erreur indiquée + if ($erreur) //erreur ici + { + $Ancien_renvoye = new Ancien(''); + $Ancien_renvoye->Ajout_erreur($erreur); + } + else + { //renvoyée par le fichier serveur_renvoie_infos + $Ancien_renvoye->Ajout_erreur($tree[0]['children'][1]['value']); + } + + return $Ancien_renvoye; + } + +?> diff --git a/include/webservices/ax/config.inc b/include/webservices/ax/config.inc new file mode 100755 index 0000000..88b9813 --- /dev/null +++ b/include/webservices/ax/config.inc @@ -0,0 +1,13 @@ +spoolroot."/configs/cle_privee_ax.pem"; + //phrase cryptant la clé privée + $phrase = $globals->webservice->pass_ax; +// "Cryptage de la cle pour polytechnique.org"; + + //paramètres serveurs + $nom_script_renvoi_challenge = $globals->webservice->host_ax."serveur_genere_challenge.php"; + $nom_script_renvoi_infos = $globals->webservice->host_ax."serveur_renvoie_infos_ancien_direct.php"; +?> diff --git a/include/webservices/ax/dtd_ancien.dtd b/include/webservices/ax/dtd_ancien.dtd new file mode 100755 index 0000000..c3d1598 --- /dev/null +++ b/include/webservices/ax/dtd_ancien.dtd @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file