@@ -17,92 +17,92 @@ |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | |
| 24 | 24 | function action_api_transmettre_dist($arg = null) { |
| 25 | 25 | |
| 26 | - // Obtenir l'argument 'id_auteur/cle/format/fond' |
|
| 27 | - if (is_null($arg)) { |
|
| 28 | - $arg = _request('arg'); |
|
| 29 | - } |
|
| 30 | - |
|
| 31 | - $args = explode('/', $arg); |
|
| 32 | - |
|
| 33 | - if (count($args) !== 4) { |
|
| 34 | - action_api_transmettre_fail($arg); |
|
| 35 | - } |
|
| 36 | - |
|
| 37 | - [$id_auteur, $cle, $format, $fond] = $args; |
|
| 38 | - $id_auteur = intval($id_auteur); |
|
| 39 | - |
|
| 40 | - if (preg_match(',[^\w\\.-],', $format)) { |
|
| 41 | - action_api_transmettre_fail("format $format ??"); |
|
| 42 | - } |
|
| 43 | - if (preg_match(',[^\w\\.-],', $fond)) { |
|
| 44 | - action_api_transmettre_fail("fond $fond ??"); |
|
| 45 | - } |
|
| 46 | - |
|
| 47 | - // verifier la cle |
|
| 48 | - //[(#ENV{id,0}|securiser_acces{#ENV{cle}, voirstats, #ENV{op}, #ENV{args}}|?{1,0})] |
|
| 49 | - //[(#ENV{id,0}|securiser_acces{#ENV{cle}, voirstats, #ENV{op}, #ENV{args}}|?{1,0})] |
|
| 50 | - |
|
| 51 | - $qs = $_SERVER['QUERY_STRING']; |
|
| 52 | - // retirer action et arg de la qs |
|
| 53 | - $contexte = []; |
|
| 54 | - parse_str($qs, $contexte); |
|
| 55 | - foreach ($contexte as $k => $v) { |
|
| 56 | - if (in_array($k, ['action', 'arg', 'var_mode'])) { |
|
| 57 | - unset($contexte[$k]); |
|
| 58 | - } |
|
| 59 | - } |
|
| 60 | - $qs = http_build_query($contexte); |
|
| 61 | - include_spip('inc/acces'); |
|
| 62 | - if (!securiser_acces_low_sec(intval($id_auteur), $cle, "transmettre/$format", $fond, $qs)) { |
|
| 63 | - // si le autoriser low_sec n'est pas bon, on peut valider l'appel si l'auteur est identifie |
|
| 64 | - include_spip('inc/autoriser'); |
|
| 65 | - $autoriser_type = preg_replace(',\W+,', '', "_{$format}{$fond}"); |
|
| 66 | - if ( |
|
| 67 | - !$id_auteur |
|
| 68 | - or empty($GLOBALS['visiteur_session']['id_auteur']) |
|
| 69 | - or $GLOBALS['visiteur_session']['id_auteur'] != $id_auteur |
|
| 70 | - or !autoriser('transmettre', $autoriser_type, $id_auteur) |
|
| 71 | - ) { |
|
| 72 | - action_api_transmettre_fail("auth QS $qs ??"); |
|
| 73 | - } |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - $contexte['id_auteur'] = $id_auteur; |
|
| 77 | - |
|
| 78 | - $fond = "transmettre/$format/$fond"; |
|
| 79 | - |
|
| 80 | - if (!trouver_fond($fond)) { |
|
| 81 | - $fond = "prive/$fond"; |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - if (!trouver_fond($fond)) { |
|
| 85 | - action_api_transmettre_fail("fond $fond ??"); |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - $res = recuperer_fond($fond, $contexte, ['raw' => true]); |
|
| 89 | - if (!empty($res['entetes'])) { |
|
| 90 | - foreach ($res['entetes'] as $h => $v) { |
|
| 91 | - header("$h: $v"); |
|
| 92 | - } |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - $res = ltrim($res['texte']); |
|
| 96 | - if (empty($res)) { |
|
| 97 | - spip_log("$arg $qs resultat vide", 'transmettre' . _LOG_INFO_IMPORTANTE); |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - echo $res; |
|
| 101 | - exit(); |
|
| 26 | + // Obtenir l'argument 'id_auteur/cle/format/fond' |
|
| 27 | + if (is_null($arg)) { |
|
| 28 | + $arg = _request('arg'); |
|
| 29 | + } |
|
| 30 | + |
|
| 31 | + $args = explode('/', $arg); |
|
| 32 | + |
|
| 33 | + if (count($args) !== 4) { |
|
| 34 | + action_api_transmettre_fail($arg); |
|
| 35 | + } |
|
| 36 | + |
|
| 37 | + [$id_auteur, $cle, $format, $fond] = $args; |
|
| 38 | + $id_auteur = intval($id_auteur); |
|
| 39 | + |
|
| 40 | + if (preg_match(',[^\w\\.-],', $format)) { |
|
| 41 | + action_api_transmettre_fail("format $format ??"); |
|
| 42 | + } |
|
| 43 | + if (preg_match(',[^\w\\.-],', $fond)) { |
|
| 44 | + action_api_transmettre_fail("fond $fond ??"); |
|
| 45 | + } |
|
| 46 | + |
|
| 47 | + // verifier la cle |
|
| 48 | + //[(#ENV{id,0}|securiser_acces{#ENV{cle}, voirstats, #ENV{op}, #ENV{args}}|?{1,0})] |
|
| 49 | + //[(#ENV{id,0}|securiser_acces{#ENV{cle}, voirstats, #ENV{op}, #ENV{args}}|?{1,0})] |
|
| 50 | + |
|
| 51 | + $qs = $_SERVER['QUERY_STRING']; |
|
| 52 | + // retirer action et arg de la qs |
|
| 53 | + $contexte = []; |
|
| 54 | + parse_str($qs, $contexte); |
|
| 55 | + foreach ($contexte as $k => $v) { |
|
| 56 | + if (in_array($k, ['action', 'arg', 'var_mode'])) { |
|
| 57 | + unset($contexte[$k]); |
|
| 58 | + } |
|
| 59 | + } |
|
| 60 | + $qs = http_build_query($contexte); |
|
| 61 | + include_spip('inc/acces'); |
|
| 62 | + if (!securiser_acces_low_sec(intval($id_auteur), $cle, "transmettre/$format", $fond, $qs)) { |
|
| 63 | + // si le autoriser low_sec n'est pas bon, on peut valider l'appel si l'auteur est identifie |
|
| 64 | + include_spip('inc/autoriser'); |
|
| 65 | + $autoriser_type = preg_replace(',\W+,', '', "_{$format}{$fond}"); |
|
| 66 | + if ( |
|
| 67 | + !$id_auteur |
|
| 68 | + or empty($GLOBALS['visiteur_session']['id_auteur']) |
|
| 69 | + or $GLOBALS['visiteur_session']['id_auteur'] != $id_auteur |
|
| 70 | + or !autoriser('transmettre', $autoriser_type, $id_auteur) |
|
| 71 | + ) { |
|
| 72 | + action_api_transmettre_fail("auth QS $qs ??"); |
|
| 73 | + } |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + $contexte['id_auteur'] = $id_auteur; |
|
| 77 | + |
|
| 78 | + $fond = "transmettre/$format/$fond"; |
|
| 79 | + |
|
| 80 | + if (!trouver_fond($fond)) { |
|
| 81 | + $fond = "prive/$fond"; |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + if (!trouver_fond($fond)) { |
|
| 85 | + action_api_transmettre_fail("fond $fond ??"); |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + $res = recuperer_fond($fond, $contexte, ['raw' => true]); |
|
| 89 | + if (!empty($res['entetes'])) { |
|
| 90 | + foreach ($res['entetes'] as $h => $v) { |
|
| 91 | + header("$h: $v"); |
|
| 92 | + } |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + $res = ltrim($res['texte']); |
|
| 96 | + if (empty($res)) { |
|
| 97 | + spip_log("$arg $qs resultat vide", 'transmettre' . _LOG_INFO_IMPORTANTE); |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + echo $res; |
|
| 101 | + exit(); |
|
| 102 | 102 | } |
| 103 | 103 | |
| 104 | 104 | function action_api_transmettre_fail($arg) { |
| 105 | - include_spip('inc/minipres'); |
|
| 106 | - echo minipres(_T('info_acces_interdit'), $arg); |
|
| 107 | - exit; |
|
| 105 | + include_spip('inc/minipres'); |
|
| 106 | + echo minipres(_T('info_acces_interdit'), $arg); |
|
| 107 | + exit; |
|
| 108 | 108 | } |