@@ -10,228 +10,228 @@ |
||
| 10 | 10 | \***************************************************************************/ |
| 11 | 11 | |
| 12 | 12 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 13 | - return; |
|
| 13 | + return; |
|
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | include_spip('inc/install'); |
| 17 | 17 | |
| 18 | 18 | function formulaires_declarer_bases_charger_dist() { |
| 19 | 19 | |
| 20 | - if (!autoriser('detruire')) { |
|
| 21 | - return false; |
|
| 22 | - } |
|
| 23 | - |
|
| 24 | - [$adresse_db, $login_db, $pass_db, $sel, $server_db] = analyse_fichier_connection(_FILE_CONNECT); |
|
| 25 | - |
|
| 26 | - $deja = bases_referencees(_FILE_CONNECT); |
|
| 27 | - // proposer un nom de connect si pas encore saisi |
|
| 28 | - $nom_connect = ''; |
|
| 29 | - if (defined('_DECLARER_CHOIX_DB')) { |
|
| 30 | - $nom_connect = _DECLARER_CHOIX_DB; |
|
| 31 | - $n = ''; |
|
| 32 | - while (in_array($nom_connect . $n, $deja)) { |
|
| 33 | - $n = ($n ? $n + 1 : 1); |
|
| 34 | - } |
|
| 35 | - $nom_connect = $nom_connect . $n; |
|
| 36 | - } |
|
| 37 | - |
|
| 38 | - $valeurs = [ |
|
| 39 | - '_etapes' => 3, |
|
| 40 | - '_bases_deja' => $deja, |
|
| 41 | - '_bases_prop' => defined('_DECLARER_SERVEUR_DB') ? liste_bases(_DECLARER_SERVEUR_DB) : '', |
|
| 42 | - '_tables' => (defined('_DECLARER_SERVEUR_DB') and defined('_DECLARER_CHOIX_DB')) ? |
|
| 43 | - $tables = sql_alltable('%', _DECLARER_SERVEUR_DB) |
|
| 44 | - : |
|
| 45 | - [], |
|
| 46 | - 'main_db' => '', |
|
| 47 | - '_serveurs' => liste_serveurs(), |
|
| 48 | - 'sql_serveur_db' => 'sqlite3', // valeur par defaut |
|
| 49 | - 'adresse_db' => $adresse_db, |
|
| 50 | - 'login_db' => '', |
|
| 51 | - 'pass_db' => '', |
|
| 52 | - 'choix_db' => '', |
|
| 53 | - 'table_new' => '', |
|
| 54 | - 'nom_connect' => $nom_connect, |
|
| 55 | - ]; |
|
| 56 | - |
|
| 57 | - return $valeurs; |
|
| 20 | + if (!autoriser('detruire')) { |
|
| 21 | + return false; |
|
| 22 | + } |
|
| 23 | + |
|
| 24 | + [$adresse_db, $login_db, $pass_db, $sel, $server_db] = analyse_fichier_connection(_FILE_CONNECT); |
|
| 25 | + |
|
| 26 | + $deja = bases_referencees(_FILE_CONNECT); |
|
| 27 | + // proposer un nom de connect si pas encore saisi |
|
| 28 | + $nom_connect = ''; |
|
| 29 | + if (defined('_DECLARER_CHOIX_DB')) { |
|
| 30 | + $nom_connect = _DECLARER_CHOIX_DB; |
|
| 31 | + $n = ''; |
|
| 32 | + while (in_array($nom_connect . $n, $deja)) { |
|
| 33 | + $n = ($n ? $n + 1 : 1); |
|
| 34 | + } |
|
| 35 | + $nom_connect = $nom_connect . $n; |
|
| 36 | + } |
|
| 37 | + |
|
| 38 | + $valeurs = [ |
|
| 39 | + '_etapes' => 3, |
|
| 40 | + '_bases_deja' => $deja, |
|
| 41 | + '_bases_prop' => defined('_DECLARER_SERVEUR_DB') ? liste_bases(_DECLARER_SERVEUR_DB) : '', |
|
| 42 | + '_tables' => (defined('_DECLARER_SERVEUR_DB') and defined('_DECLARER_CHOIX_DB')) ? |
|
| 43 | + $tables = sql_alltable('%', _DECLARER_SERVEUR_DB) |
|
| 44 | + : |
|
| 45 | + [], |
|
| 46 | + 'main_db' => '', |
|
| 47 | + '_serveurs' => liste_serveurs(), |
|
| 48 | + 'sql_serveur_db' => 'sqlite3', // valeur par defaut |
|
| 49 | + 'adresse_db' => $adresse_db, |
|
| 50 | + 'login_db' => '', |
|
| 51 | + 'pass_db' => '', |
|
| 52 | + 'choix_db' => '', |
|
| 53 | + 'table_new' => '', |
|
| 54 | + 'nom_connect' => $nom_connect, |
|
| 55 | + ]; |
|
| 56 | + |
|
| 57 | + return $valeurs; |
|
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | function liste_serveurs() { |
| 61 | - $options = []; |
|
| 62 | - $dir = _DIR_RESTREINT . 'req/'; |
|
| 63 | - $d = opendir($dir); |
|
| 64 | - if (!$d) { |
|
| 65 | - return []; |
|
| 66 | - } |
|
| 67 | - while ($f = readdir($d)) { |
|
| 68 | - if ( |
|
| 69 | - (preg_match('/^(.*)[.]php$/', $f, $s)) |
|
| 70 | - and is_readable($f = $dir . $f) |
|
| 71 | - ) { |
|
| 72 | - require_once($f); |
|
| 73 | - $s = $s[1]; |
|
| 74 | - $v = 'spip_versions_' . $s; |
|
| 75 | - if (function_exists($v) and $v()) { |
|
| 76 | - $options[$s] = "install_select_type_$s"; |
|
| 77 | - } else { |
|
| 78 | - spip_log("$s: portage indisponible"); |
|
| 79 | - } |
|
| 80 | - } |
|
| 81 | - } |
|
| 82 | - ksort($options); |
|
| 83 | - |
|
| 84 | - return $options; |
|
| 61 | + $options = []; |
|
| 62 | + $dir = _DIR_RESTREINT . 'req/'; |
|
| 63 | + $d = opendir($dir); |
|
| 64 | + if (!$d) { |
|
| 65 | + return []; |
|
| 66 | + } |
|
| 67 | + while ($f = readdir($d)) { |
|
| 68 | + if ( |
|
| 69 | + (preg_match('/^(.*)[.]php$/', $f, $s)) |
|
| 70 | + and is_readable($f = $dir . $f) |
|
| 71 | + ) { |
|
| 72 | + require_once($f); |
|
| 73 | + $s = $s[1]; |
|
| 74 | + $v = 'spip_versions_' . $s; |
|
| 75 | + if (function_exists($v) and $v()) { |
|
| 76 | + $options[$s] = "install_select_type_$s"; |
|
| 77 | + } else { |
|
| 78 | + spip_log("$s: portage indisponible"); |
|
| 79 | + } |
|
| 80 | + } |
|
| 81 | + } |
|
| 82 | + ksort($options); |
|
| 83 | + |
|
| 84 | + return $options; |
|
| 85 | 85 | } |
| 86 | 86 | |
| 87 | 87 | function liste_bases($server_db) { |
| 88 | - if ( |
|
| 89 | - is_null($server_db) |
|
| 90 | - or !$result = sql_listdbs($server_db) |
|
| 91 | - ) { |
|
| 92 | - return ''; |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - $noms = []; |
|
| 96 | - |
|
| 97 | - // si sqlite : result est deja un tableau |
|
| 98 | - if (is_array($result)) { |
|
| 99 | - $noms = $result; |
|
| 100 | - } else { |
|
| 101 | - while ($row = sql_fetch($result, $server_db)) { |
|
| 102 | - $noms[] = reset($row); |
|
| 103 | - } |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - return $noms; |
|
| 88 | + if ( |
|
| 89 | + is_null($server_db) |
|
| 90 | + or !$result = sql_listdbs($server_db) |
|
| 91 | + ) { |
|
| 92 | + return ''; |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + $noms = []; |
|
| 96 | + |
|
| 97 | + // si sqlite : result est deja un tableau |
|
| 98 | + if (is_array($result)) { |
|
| 99 | + $noms = $result; |
|
| 100 | + } else { |
|
| 101 | + while ($row = sql_fetch($result, $server_db)) { |
|
| 102 | + $noms[] = reset($row); |
|
| 103 | + } |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + return $noms; |
|
| 107 | 107 | } |
| 108 | 108 | |
| 109 | 109 | function formulaires_declarer_bases_verifier_1_dist() { |
| 110 | - $erreurs = []; |
|
| 111 | - [$def_adresse_db, $def_login_db, $def_pass_db, $sel_db, $def_serveur_db] = analyse_fichier_connection(_FILE_CONNECT); |
|
| 112 | - |
|
| 113 | - if (!$adresse_db = _request('adresse_db')) { |
|
| 114 | - if (defined('_INSTALL_HOST_DB')) { |
|
| 115 | - $adresse_db = _INSTALL_HOST_DB; |
|
| 116 | - } else { |
|
| 117 | - $adresse_db = $def_adresse_db; |
|
| 118 | - } |
|
| 119 | - } |
|
| 120 | - if (!$serveur_db = _request('sql_serveur_db')) { |
|
| 121 | - if (defined('_INSTALL_SERVER_DB')) { |
|
| 122 | - $serveur_db = _INSTALL_SERVER_DB; |
|
| 123 | - } else { |
|
| 124 | - $serveur_db = $def_serveur_db; |
|
| 125 | - } |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - $login_db = $pass_db = ''; |
|
| 129 | - if (!preg_match(',^sqlite,i', $serveur_db)) { |
|
| 130 | - if (!$login_db = _request('login_db')) { |
|
| 131 | - if (defined('_INSTALL_USER_DB')) { |
|
| 132 | - $login_db = _INSTALL_USER_DB; |
|
| 133 | - } else { |
|
| 134 | - $login_db = $def_login_db; |
|
| 135 | - } |
|
| 136 | - } |
|
| 137 | - if (!$pass_db = _request('pass_db')) { |
|
| 138 | - if (defined('_INSTALL_PASS_DB')) { |
|
| 139 | - $pass_db = _INSTALL_PASS_DB; |
|
| 140 | - } else { |
|
| 141 | - $pass_db = $def_pass_db; |
|
| 142 | - } |
|
| 143 | - } |
|
| 144 | - } |
|
| 145 | - |
|
| 146 | - $link = spip_connect_db($adresse_db, '', $login_db, $pass_db, '@test@', $serveur_db); |
|
| 147 | - if ($link) { |
|
| 148 | - $GLOBALS['connexions'][$serveur_db][$GLOBALS['spip_sql_version']] = $GLOBALS['spip_' . $serveur_db . '_functions_' . $GLOBALS['spip_sql_version']]; |
|
| 149 | - $GLOBALS['connexions'][$serveur_db] = $link; |
|
| 150 | - define('_DECLARER_SERVEUR_DB', $serveur_db); |
|
| 151 | - define('_DECLARER_ADRESSE_DB', $adresse_db); |
|
| 152 | - define('_DECLARER_LOGIN_DB', $login_db); |
|
| 153 | - define('_DECLARER_PASS_DB', $pass_db); |
|
| 154 | - // si on est sur le meme serveur que connect.php |
|
| 155 | - // indiquer quelle est la db utilisee pour l'exclure des choix possibles |
|
| 156 | - if ($serveur_db == $def_serveur_db and $adresse_db == $def_adresse_db) { |
|
| 157 | - set_request('main_db', $sel_db); |
|
| 158 | - } else { |
|
| 159 | - set_request('main_db', ''); |
|
| 160 | - } |
|
| 161 | - } else { |
|
| 162 | - $erreurs['message_erreur'] = _T('avis_connexion_echec_1'); |
|
| 163 | - } |
|
| 164 | - |
|
| 165 | - return $erreurs; |
|
| 110 | + $erreurs = []; |
|
| 111 | + [$def_adresse_db, $def_login_db, $def_pass_db, $sel_db, $def_serveur_db] = analyse_fichier_connection(_FILE_CONNECT); |
|
| 112 | + |
|
| 113 | + if (!$adresse_db = _request('adresse_db')) { |
|
| 114 | + if (defined('_INSTALL_HOST_DB')) { |
|
| 115 | + $adresse_db = _INSTALL_HOST_DB; |
|
| 116 | + } else { |
|
| 117 | + $adresse_db = $def_adresse_db; |
|
| 118 | + } |
|
| 119 | + } |
|
| 120 | + if (!$serveur_db = _request('sql_serveur_db')) { |
|
| 121 | + if (defined('_INSTALL_SERVER_DB')) { |
|
| 122 | + $serveur_db = _INSTALL_SERVER_DB; |
|
| 123 | + } else { |
|
| 124 | + $serveur_db = $def_serveur_db; |
|
| 125 | + } |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + $login_db = $pass_db = ''; |
|
| 129 | + if (!preg_match(',^sqlite,i', $serveur_db)) { |
|
| 130 | + if (!$login_db = _request('login_db')) { |
|
| 131 | + if (defined('_INSTALL_USER_DB')) { |
|
| 132 | + $login_db = _INSTALL_USER_DB; |
|
| 133 | + } else { |
|
| 134 | + $login_db = $def_login_db; |
|
| 135 | + } |
|
| 136 | + } |
|
| 137 | + if (!$pass_db = _request('pass_db')) { |
|
| 138 | + if (defined('_INSTALL_PASS_DB')) { |
|
| 139 | + $pass_db = _INSTALL_PASS_DB; |
|
| 140 | + } else { |
|
| 141 | + $pass_db = $def_pass_db; |
|
| 142 | + } |
|
| 143 | + } |
|
| 144 | + } |
|
| 145 | + |
|
| 146 | + $link = spip_connect_db($adresse_db, '', $login_db, $pass_db, '@test@', $serveur_db); |
|
| 147 | + if ($link) { |
|
| 148 | + $GLOBALS['connexions'][$serveur_db][$GLOBALS['spip_sql_version']] = $GLOBALS['spip_' . $serveur_db . '_functions_' . $GLOBALS['spip_sql_version']]; |
|
| 149 | + $GLOBALS['connexions'][$serveur_db] = $link; |
|
| 150 | + define('_DECLARER_SERVEUR_DB', $serveur_db); |
|
| 151 | + define('_DECLARER_ADRESSE_DB', $adresse_db); |
|
| 152 | + define('_DECLARER_LOGIN_DB', $login_db); |
|
| 153 | + define('_DECLARER_PASS_DB', $pass_db); |
|
| 154 | + // si on est sur le meme serveur que connect.php |
|
| 155 | + // indiquer quelle est la db utilisee pour l'exclure des choix possibles |
|
| 156 | + if ($serveur_db == $def_serveur_db and $adresse_db == $def_adresse_db) { |
|
| 157 | + set_request('main_db', $sel_db); |
|
| 158 | + } else { |
|
| 159 | + set_request('main_db', ''); |
|
| 160 | + } |
|
| 161 | + } else { |
|
| 162 | + $erreurs['message_erreur'] = _T('avis_connexion_echec_1'); |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + return $erreurs; |
|
| 166 | 166 | } |
| 167 | 167 | |
| 168 | 168 | function formulaires_declarer_bases_verifier_2_dist() { |
| 169 | - $erreurs = []; |
|
| 170 | - $choix_db = _request('choix_db'); |
|
| 171 | - if ($choix_db == '-1') { |
|
| 172 | - $choix_db = _request('table_new'); |
|
| 173 | - } |
|
| 174 | - if (!$choix_db) { |
|
| 175 | - $erreurs['choix_db'] = _T('info_obligatoire'); |
|
| 176 | - } else { |
|
| 177 | - define('_ECRIRE_INSTALL', 1); // hackons sqlite |
|
| 178 | - if (!sql_selectdb($choix_db, _DECLARER_SERVEUR_DB)) { |
|
| 179 | - $erreurs['choix_db'] = _T('avis_base_inaccessible', ['base' => $choix_db]); |
|
| 180 | - } else { |
|
| 181 | - define('_DECLARER_CHOIX_DB', $choix_db); |
|
| 182 | - } |
|
| 183 | - } |
|
| 184 | - |
|
| 185 | - return $erreurs; |
|
| 169 | + $erreurs = []; |
|
| 170 | + $choix_db = _request('choix_db'); |
|
| 171 | + if ($choix_db == '-1') { |
|
| 172 | + $choix_db = _request('table_new'); |
|
| 173 | + } |
|
| 174 | + if (!$choix_db) { |
|
| 175 | + $erreurs['choix_db'] = _T('info_obligatoire'); |
|
| 176 | + } else { |
|
| 177 | + define('_ECRIRE_INSTALL', 1); // hackons sqlite |
|
| 178 | + if (!sql_selectdb($choix_db, _DECLARER_SERVEUR_DB)) { |
|
| 179 | + $erreurs['choix_db'] = _T('avis_base_inaccessible', ['base' => $choix_db]); |
|
| 180 | + } else { |
|
| 181 | + define('_DECLARER_CHOIX_DB', $choix_db); |
|
| 182 | + } |
|
| 183 | + } |
|
| 184 | + |
|
| 185 | + return $erreurs; |
|
| 186 | 186 | } |
| 187 | 187 | |
| 188 | 188 | function formulaires_declarer_bases_verifier_3_dist() { |
| 189 | - $erreurs = []; |
|
| 190 | - $nom_connect = _request('nom_connect'); |
|
| 191 | - if (!$nom_connect) { |
|
| 192 | - $erreurs['nom_connect'] = _T('info_obligatoire'); |
|
| 193 | - } else { |
|
| 194 | - // securite : le nom doit etre un mot sans caracteres speciaux |
|
| 195 | - $f = preg_replace(',[^\w],', '', $nom_connect); |
|
| 196 | - if ($f !== $nom_connect) { |
|
| 197 | - $erreurs['nom_connect'] = _T('erreur_nom_connect_incorrect'); |
|
| 198 | - } elseif (file_exists(_DIR_CONNECT . $nom_connect . '.php')) { |
|
| 199 | - $erreurs['nom_connect'] = _T('erreur_connect_deja_existant'); |
|
| 200 | - } else { |
|
| 201 | - define('_DECLARER_NOM_CONNECT', $nom_connect); |
|
| 202 | - } |
|
| 203 | - } |
|
| 204 | - |
|
| 205 | - return $erreurs; |
|
| 189 | + $erreurs = []; |
|
| 190 | + $nom_connect = _request('nom_connect'); |
|
| 191 | + if (!$nom_connect) { |
|
| 192 | + $erreurs['nom_connect'] = _T('info_obligatoire'); |
|
| 193 | + } else { |
|
| 194 | + // securite : le nom doit etre un mot sans caracteres speciaux |
|
| 195 | + $f = preg_replace(',[^\w],', '', $nom_connect); |
|
| 196 | + if ($f !== $nom_connect) { |
|
| 197 | + $erreurs['nom_connect'] = _T('erreur_nom_connect_incorrect'); |
|
| 198 | + } elseif (file_exists(_DIR_CONNECT . $nom_connect . '.php')) { |
|
| 199 | + $erreurs['nom_connect'] = _T('erreur_connect_deja_existant'); |
|
| 200 | + } else { |
|
| 201 | + define('_DECLARER_NOM_CONNECT', $nom_connect); |
|
| 202 | + } |
|
| 203 | + } |
|
| 204 | + |
|
| 205 | + return $erreurs; |
|
| 206 | 206 | } |
| 207 | 207 | |
| 208 | 208 | function formulaires_declarer_bases_traiter_dist() { |
| 209 | 209 | |
| 210 | - $adresse_db = _DECLARER_ADRESSE_DB; |
|
| 211 | - if (preg_match(',(.*):(.*),', $adresse_db, $r)) { |
|
| 212 | - [, $adresse_db, $port] = $r; |
|
| 213 | - } else { |
|
| 214 | - $port = ''; |
|
| 215 | - } |
|
| 216 | - |
|
| 217 | - $server_db = addcslashes(_DECLARER_SERVEUR_DB, "'\\"); |
|
| 218 | - |
|
| 219 | - $conn = install_mode_appel($server_db) |
|
| 220 | - . install_connexion( |
|
| 221 | - $adresse_db, |
|
| 222 | - $port, |
|
| 223 | - _DECLARER_LOGIN_DB, |
|
| 224 | - _DECLARER_PASS_DB, |
|
| 225 | - _DECLARER_CHOIX_DB, |
|
| 226 | - _DECLARER_SERVEUR_DB, |
|
| 227 | - '', |
|
| 228 | - '', |
|
| 229 | - '' |
|
| 230 | - ); |
|
| 231 | - |
|
| 232 | - install_fichier_connexion(_DIR_CONNECT . _DECLARER_NOM_CONNECT . '.php', $conn); |
|
| 233 | - |
|
| 234 | - return [ |
|
| 235 | - 'message_ok' => _T('install_connect_ok', ['connect' => '<strong>' . _DECLARER_NOM_CONNECT . '</strong>']) |
|
| 236 | - ]; |
|
| 210 | + $adresse_db = _DECLARER_ADRESSE_DB; |
|
| 211 | + if (preg_match(',(.*):(.*),', $adresse_db, $r)) { |
|
| 212 | + [, $adresse_db, $port] = $r; |
|
| 213 | + } else { |
|
| 214 | + $port = ''; |
|
| 215 | + } |
|
| 216 | + |
|
| 217 | + $server_db = addcslashes(_DECLARER_SERVEUR_DB, "'\\"); |
|
| 218 | + |
|
| 219 | + $conn = install_mode_appel($server_db) |
|
| 220 | + . install_connexion( |
|
| 221 | + $adresse_db, |
|
| 222 | + $port, |
|
| 223 | + _DECLARER_LOGIN_DB, |
|
| 224 | + _DECLARER_PASS_DB, |
|
| 225 | + _DECLARER_CHOIX_DB, |
|
| 226 | + _DECLARER_SERVEUR_DB, |
|
| 227 | + '', |
|
| 228 | + '', |
|
| 229 | + '' |
|
| 230 | + ); |
|
| 231 | + |
|
| 232 | + install_fichier_connexion(_DIR_CONNECT . _DECLARER_NOM_CONNECT . '.php', $conn); |
|
| 233 | + |
|
| 234 | + return [ |
|
| 235 | + 'message_ok' => _T('install_connect_ok', ['connect' => '<strong>' . _DECLARER_NOM_CONNECT . '</strong>']) |
|
| 236 | + ]; |
|
| 237 | 237 | } |