phpDocumentor VFront
VFront_Web_Installer
[ class tree: VFront ] [ index: VFront ] [ all elements ]

Source for file index.php

Documentation is available at index.php

  1. <?php
  2.  
  3. #################################################
  4. #
  5. #     This file is part of VFront.
  6. #
  7. #    VFront is free software; you can redistribute it and/or modify
  8. #    it under the terms of the GNU General Public License as published by
  9. #    the Free Software Foundation; either version 2 of the License, or
  10. #    any later version.
  11. #
  12. #    VFront is distributed in the hope that it will be useful,
  13. #    but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. #    GNU General Public License for more details.
  16. #
  17. #    You should have received a copy of the GNU General Public License
  18. #    along with this program.  If not, see <http://www.gnu.org/licenses/>.
  19. #
  20.  
  21. /**
  22.  * VFront Web Installer - Utility di installazione dell'applicazione VFront
  23.  * Caratteristiche richieste: PHP5.x , MySQL 5.x, php_mysqli
  24.  * Oppure: PHP5.x , Postgres 8.x, php_pgsql
  25.  * @package VFront
  26.  * @subpackage VFront_Web_Installer
  27.  * @author M.Marcello Verona
  28.  * @copyright 2007 M.Marcello Verona
  29.  * @version 0.90
  30.  * @license http://www.gnu.org/licenses/gpl.html GNU Public License
  31.  */
  32.  
  33.  
  34.  
  35. /**
  36.  * @desc Esce dall'installazione
  37.  *
  38.  */
  39. function esci(){
  40.     
  41.     session_destroy();
  42.     header("Location: ".$_SERVER['PHP_SELF']);
  43.     exit;
  44. }
  45.  
  46.  
  47.  
  48. /**
  49.  * @desc Esegue i GRANT necessari per il nuovo utente
  50.  * @param bool $return_only_sql 
  51.  * @return int 
  52.  */
  53. function grant($return_only_sql=false){
  54.     
  55.     global $db1$link;
  56.     
  57.     if($db1['dbtype']=='mysql'){
  58.         
  59.         $sql_user"CREATE USER {$db1['user']}@{$db1['host']} IDENTIFIED BY '{$db1['passw']}'; ";
  60.         
  61.         $sql[]"GRANT SELECTINSERTUPDATEDELETE ON {$db1['frontend']}.* TO '{$db1['user']}'@{$db1['host']} IDENTIFIED BY '{$db1['passw']}';";
  62.         $sql[]"GRANT SELECTINSERTUPDATEDELETESHOW VIEW ON {$db1['dbname']}.* TO '{$db1['user']}'@{$db1['host']} IDENTIFIED BY '{$db1['passw']}';";
  63.     }
  64.     else if ($db1['dbtype']=='postgres'){
  65.         
  66.         
  67.         // crea l'utente
  68.         $sql_user"CREATE USER {$db1['user']} WITH PASSWORD '{$db1['passw']}'; ";
  69.         
  70.         // diritto d'uso dello schema frontend
  71.         $sql[]="GRANT USAGE ON SCHEMA {$db1['frontend']} TO {$db1['user']};";
  72.         
  73.         
  74.         // diritto d'uso dello schema information_schema
  75.         $sql[]="GRANT USAGE ON SCHEMA information_schema TO {$db1['user']};";
  76.         
  77.         // diritto d'uso dello schema pg_catalog
  78.         $sql[]="GRANT USAGE ON SCHEMA pg_catalog TO {$db1['user']};";
  79.                 
  80.         
  81.         // prendi le tabelle dei due schemi
  82.         $q_tab=pg_query($link,"SELECT table_schema || '.' || table_name FROM information_schema.tables WHERE table_schema IN ('{$db1['dbname']}','{$db1['frontend']}')");
  83.         
  84.         while($RS_tab=pg_fetch_row($q_tab)){
  85.             
  86.             $sql[]="GRANT SELECT, INSERT, UPDATE, DELETE, REFERENCES ON ".$RS_tab[0]." TO {$db1['user']};";
  87.         }
  88.         
  89.         // prendi le tabelle dell'information_schema
  90.         $q_tab=pg_query($link,"SELECT table_schema || '.' || table_name FROM information_schema.tables WHERE table_schema='information_schema'; ");
  91.         
  92.         while($RS_tab=pg_fetch_row($q_tab)){
  93.             
  94.             $sql[]="GRANT SELECT ON ".$RS_tab[0]." TO {$db1['user']};";
  95.         }
  96.         
  97.         
  98.         // prendi le funzioni dei due schemi
  99.         $q_func=pg_query($link,"select 'GRANT EXECUTE ON FUNCTION '||n.nspname||'.'||p.proname||'('||oidvectortypes(p.proargtypes)||') TO {$db1['user']};' from pg_proc ppg_namespace n where n.oid = p.pronamespace and n.nspname IN ('{$db1['dbname']}','{$db1['frontend']}');");
  100.         
  101.         while($RS_func=pg_fetch_row($q_func)){
  102.             
  103.             $sql[]=$RS_func[0];
  104.         }
  105.         
  106.         
  107.         // prendi le sequenze dei due schemi
  108.         $q_seq=pg_query($link,"select 'GRANT ALL ON '||n.nspname||'.'||c.relname||' TO {$db1['user']};' from pg_class cpg_namespace n where n.oid = c.relnamespace and c.relkind IN ('S') and n.nspname in ('{$db1['dbname']}','{$db1['frontend']}');");
  109.         
  110.         while($RS_seq=pg_fetch_row($q_seq)){
  111.             
  112.             $sql[]=$RS_seq[0];
  113.         }
  114.     }
  115.     
  116.  
  117.     if($return_only_sql){
  118.         
  119.         return $sql_user."\n".implode("\n",$sql);
  120.     }
  121.     
  122.     if($db1['dbtype']=='mysql'){
  123.     
  124.         $q_user=@mysqli_query($link,$sql_user);
  125.         
  126.         for($i=0;$i<count($sql);$i++)
  127.             $q=mysqli_query($link,$sql[$i]or die(mysqli_error($link));
  128.         
  129.         return mysqli_affected_rows($link);
  130.         
  131.     }
  132.     elseif($db1['dbtype']=='postgres'){
  133.         
  134.         $q_user=@pg_query($link,$sql_user);
  135.         
  136.         for($i=0;$i<count($sql);$i++)
  137.             $q=pg_query($link,$sql[$i]or die(pg_errormessage($link));
  138.         
  139.         return pg_affected_rows($q);
  140.     }
  141.     
  142. }
  143.  
  144.  
  145.  
  146. /**
  147.  * @desc Genera il codice HTML da mostrare a fine installazione
  148.  * @param bool $esito 
  149.  * @return string HTML
  150.  */
  151. function installazione_completata($esito){
  152.     
  153.     echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">
  154. <html>
  155.     <head><title>Installazione Vfront</title>
  156.     <style type=\"text/css\">
  157.         @import \"install.css\";
  158.     </style>
  159.     </head>
  160.     <body>\n";
  161.     
  162.     if($esito){
  163.     
  164.         echo "<h1>Installazione completata!</h1>
  165.         <p>Vai alla pagina di login ed accedi con l'email e la password da te specificate.</p>
  166.         <a href=\"../index.php\">Vai al login</a>\n";
  167.     
  168.     }
  169.     else{
  170.     
  171.         echo "<h1>Errore nella creazione dell'utente!</h1>
  172.         <p>Prova a creare manualmente l'utente nella tabella <em>utente</em> specificando livello = 3 e gruppo = 0</p>
  173.         <a href=\"../index.php\">Vai al login</a>\n";
  174.     
  175.     }
  176.     
  177.     echo "</body>\n</html>\n";
  178. }
  179.  
  180.  
  181. /**
  182.  * @desc Genera il codice HTML da mostrare a inizio installazione
  183.  * @return string HTML
  184.  */
  185. function introduzione(){
  186.     
  187.     echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">
  188. <html>
  189.     <head><title>Installazione Vfront</title>
  190.     <style type=\"text/css\">
  191.         @import \"install.css\";
  192.     </style>
  193.     <script type=\"text/javascript\">
  194.     
  195.     function ut(n){
  196.         
  197.         
  198.         document.getElementById('host').disabled= (n) ? true:false;
  199.         document.getElementById('user').disabled= (n) ? true:false;
  200.         document.getElementById('passw').disabled= (n) ? true:false;
  201.         document.getElementById('port').disabled= (n) ? true:false;
  202.     
  203.     }
  204.     
  205.     
  206.     </script>
  207.     </head>
  208.     <body>\n";
  209.     
  210.     
  211.     /*
  212.     
  213.     
  214.     
  215.     echo openLayout1('Installazione VFront');*/
  216.     
  217.     
  218.     echo "<h1>Installazione VFRONT - Introduzione</h1>\n";
  219.     
  220.     
  221.     echo "<p><strong>Benvenuti all'installazione di VFront!</strong></p>\n";
  222.     echo "<div class=\"par\">Questa procedura installer&agrave; l'applicazione nel server. 
  223.     
  224.     <ol>
  225.     <li>Per installare l'applicazione &egrave; necessario innanzitutto <b>modificare il file conf</b>.
  226.     Questo si trova nella directory <em>/conf</em> ma pu&ograve; essere spostato in una directory non sottoposta a browsing.<br />
  227.     Se non l'hai gi&agrave; fatto interrompi la lettura e modifica il file di configurazione.<br />
  228.     (Per maggiori informazioni sul file conf si legga il file README)<br /><br />
  229.     L'installazione di VFront legger&agrave; i parametri del file di configurazione e svolger&agrave; diverse operazioni:<br />
  230.     - Creazione del database per il frontend<br />
  231.     - Creazione dell'utente richiesto<br />
  232.     - Inserimento di alcuni dati per l'inizializzazione<br />
  233.     </li>
  234.     
  235.     <li>E' necessario poi <b>modificare il file <em>/inc/conn.php</em></b> per includere il file di configurazione, specificando il path reale<br /></li>
  236.     
  237.     
  238.     <li>L'installazione da ora avviene in maniera automatica e consta in tre passi:
  239.     
  240.         <ol>    
  241.             <li>Richiesta della posizione del file conf sul filesystem</li>
  242.             <li>Creazione delle tabelle e dell'eventuale database di frontend, se non &egrave; gi&agrave; stato creato.</li>
  243.             <li>Creazione di un primo amministratore per VFront</li>
  244.         </ol>
  245.     </li>
  246.     
  247.     </ol>
  248.     
  249.     <h2>Dopo l'installazione</h2>
  250.     
  251.     <p>Alla fine della procedura si suggerisce di cancellare la cartella <em>/_install</em> nella quale sono presenti questi script, per ragioni di sicurezza.</p>
  252.     
  253.     <p>Per sincronizzare VFront con il database andare su Amministrazione -&gt; Gestione Registri -&gt; Inizializza Registri</p>
  254.     
  255.     <p>Per una panoramica dell'installazione di VFront andare su Amministrazione -&gt; Varie -&gt; Test impostazioni VFront Registri</p>
  256.     
  257.     <div style=\"text-align:center;\"><p style=\"font-size:1.6em;\" > <a href=\"?install1\">Procedi con l'installazione</a> </p></div>
  258.     
  259.     </div>\n";
  260.     
  261.     echo "</body>\n</html>\n";
  262. }
  263.     
  264.     
  265.     
  266.     
  267.  
  268.     echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">
  269. <html>
  270.     <head><title>Installazione Vfront</title>
  271.     <style type=\"text/css\">
  272.         @import \"install.css\";
  273.     </style>
  274.     <script type=\"text/javascript\">
  275.     
  276.     function ut(n){
  277.         
  278.         
  279.         document.getElementById('host').disabled= (n) ? true:false;
  280.         document.getElementById('user').disabled= (n) ? true:false;
  281.         document.getElementById('passw').disabled= (n) ? true:false;
  282.         document.getElementById('port').disabled= (n) ? true:false;
  283.     
  284.     }
  285.     
  286.     
  287.     </script>
  288.     </head>
  289.     <body>\n";
  290.     
  291.     
  292.     echo "<h1>Installazione VFRONT - Passo 1 di 3</h1>\n";
  293.     
  294.     if(isset($_GET['nofileconn'])){
  295.         
  296.         echo "<p style=\"color:red\">Il file indicato &egrave; inesistente o inaccessibile</p>";
  297.     }
  298.  
  299.     if(isset($_GET['nofileconn_or'])){
  300.         
  301.         echo "<p style=\"color:red\">Il file indicato non sembra essere il file di configurazione!</p>";
  302.     }
  303.  
  304.     echo "
  305.     <form action=\"".$_SERVER['PHP_SELF']."?conf\" method=\"post\" >
  306.     
  307.  
  308.     <p>
  309.         Inserire il percorso completo del file di configurazione (ad esempio <em>/var/www/html/vfront/conf/conf.vfront.php</em>) : <br /><input type=\"text\" name=\"file_connessione\" id=\"file_connessione\" value=\"\" size=\"80\" /><br />
  310.         <em>Nota: utilizzare lo slash normale (/) anche in ambiente Windows</em>
  311.         
  312.     </p>
  313.     
  314.     
  315.         <input type=\"submit\" name=\"Invia\" value=\" Procedi \" />
  316.     
  317.     
  318.     
  319.     
  320.     </form>\n";
  321.     
  322.     
  323.     echo "</body>\n</html>";
  324.     
  325.     
  326.     exit;
  327.     
  328. }
  329.  
  330. /**
  331.  * Funzione che analizza la presenza di gruppi nel DB di VFront
  332.  *
  333.  * @return bool 
  334.  */
  335.     
  336.     global $link,$db1;
  337.     
  338.     
  339.     $GR=false;
  340.     
  341.     
  342.     // cerca tabella gruppi e verifica che ce ne sia almeno 1 (lo 0)
  343.     $sql_gruppi="SELECT * FROM {$db1['frontend']}.gruppo ORDER BY gid ASC LIMIT 1";
  344.     
  345.     $test_q_gruppi=vmsql_try($sql_gruppi,$link);
  346.     
  347.     if(!$test_q_gruppi){
  348.         
  349.         $GR=true;
  350.     }
  351.     else{
  352.         $q_gruppi=vmsql_query($sql_gruppi,$link);
  353.         
  354.         $n_gruppi=vmsql_num_rows($q_gruppi);
  355.  
  356.         if($n_gruppi==0){
  357.             $RSg=vmsql_fetch_assoc($q_gruppi);
  358.             $GR=true;
  359.         }
  360.     
  361.     }
  362.     
  363.     
  364.     
  365.     return $GR;
  366.     
  367. }
  368.  
  369.  
  370.  
  371.  
  372. /**
  373.  * Funzione di test per la generazione di una tabella.
  374.  * Serve a testare il diritto CREATE, mediante la creazione di una tabella di nome pseudocasuale
  375.  *
  376.  * @return bool 
  377.  */
  378. function test_crea_tabella(){
  379.     
  380.     global $link,$db1;
  381.     
  382.     // nome casuale
  383.     $nome_tabella="a".md5(time());
  384.         
  385.     
  386.     if($db1['dbtype']=='postgres'){
  387.         $q_test=@pg_query($link,"CREATE TABLE {$db1['dbname']}.$nome_tabella (id_test int2 NOT NULLPRIMARY KEY (id_test));");
  388.     }else// Mysql
  389.         $q_test=@mysqli_query($link,"CREATE TABLE {$db1['dbname']}.$nome_tabella (id_test int(11) NOT NULLPRIMARY KEY  (id_test)) ENGINE=InnoDB DEFAULT CHARSET=latin1;");        
  390.     }
  391.     
  392.     
  393.     if($q_test){
  394.         
  395.         if($db1['dbtype']=='postgres'){
  396.             $q_test2=@pg_query($link,"DROP TABLE {$db1['dbname']}.$nome_tabella ");
  397.         }
  398.         else// mysql
  399.             $q_test2=@mysqli_query($link,"DROP TABLE {$db1['dbname']}.$nome_tabella ");
  400.         }
  401.         return true;
  402.     }
  403.     else{
  404.         
  405.         return false;
  406.     }
  407.     
  408. }
  409.  
  410. /**
  411.  * @desc Crea il DB e le tabelle
  412.  *
  413.  */
  414. function crea_db_vfront(){
  415.     
  416.     global $link,$db1;
  417.     if($db1['dbtype']=='mysql'){
  418.         
  419.         if(!is_file("./vfront.mysql.sql.php")){
  420.             
  421.             die("Impossibile leggere il file di origine dati SQL. Procedura interrotta.");
  422.         }
  423.         
  424.         require_once("./vfront.mysql.sql.php");
  425.     }
  426.     else{
  427.         
  428.         if(!is_file("./vfront.postgres.sql.php")){
  429.             
  430.             die("Impossibile leggere il file di origine dati SQL. Procedura interrotta.");
  431.         }
  432.         
  433.         require_once("./vfront.postgres.sql.php");
  434.         
  435.     }
  436.     
  437.     // crea il database
  438.     if($db1['dbtype']=='mysql'){
  439.         $sql_creadb=  "CREATE DATABASE IF NOT EXISTS ".$db1['frontend'];
  440.         
  441.         $q0=@vmsql_query($sql_creadb,$linkor die("Impossibile creare il database {$db1['frontend']}");
  442.     
  443.         $q_use0=vmsql_query("USE ".$db1['frontend'],$linkor die("Impossibile utilizzare il database {$db1['frontend']} con comando USE");
  444.     
  445.     }
  446.     elseif($db1['dbtype']=='postgres'){
  447.         
  448. //        $sql_creadb=  "CREATE SCHEMA \"frontend\" AUTHORIZATION \"postgres\"";
  449.         
  450. //        $q0=@vmsql_query($sql_creadb,$link) or die("Impossibile creare lo schema {$db1['frontend']}");
  451.         
  452.     }
  453.     
  454.  
  455.  
  456.  
  457.     
  458.     
  459.     
  460.     $errore=0;
  461.     
  462.     for($i=0;$i<count($SQL_DEFINITION);$i++){
  463.         $q_creatabellevmsql_query($SQL_DEFINITION[$i],$linkor ($errore=1);
  464.  
  465.         if($errore==1){
  466.             $xerr=($db1['dbtype']=='mysql'mysqli_error($linkpg_errormessage($link);
  467.             vmsql_query("ROLLBACK",$link);
  468.             die("$xerr<br /> Impossibile creare le tabelle nel database {$db1['frontend']}");
  469.         }
  470.         
  471.     }
  472.     
  473.     if($db1['dbtype']=='mysql'){
  474.         $q_use0=vmsql_query("USE ".$db1['dbname'],$linkor die("Impossibile utilizzare il database {$db1['dbname']} con comando USE");
  475.     }
  476.     
  477.     if(isset($_POST['grant_user']&& $_POST['grant_user']==1){
  478.         
  479.         $esito_grant=grant();
  480.     }
  481.     
  482.     
  483. }
  484.  
  485.  
  486.  
  487.  
  488.  
  489. /**
  490.  * @desc Funzione per la generazione della pagina di creazione primo utente
  491.  *
  492.  */
  493. function crea_utente_admin(){
  494.     
  495.     global $link,$db1$conf_auth;
  496.     
  497.     
  498.     echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">
  499. <html>
  500.     <head><title>Installazione Vfront</title>
  501.     <style type=\"text/css\">
  502.         @import \"install.css\";
  503.     </style>
  504.     <script type=\"text/javascript\" src=\"../js/yav/yav.js\" ></script>
  505.     <script type=\"text/javascript\" src=\"../js/yav/yav-config-it.js\" ></script>
  506.     <script type=\"text/javascript\" >
  507.     
  508.     var rules= new Array();
  509.     
  510.     rules[0]='email|required|Inserire una email';
  511.     rules[1]='passw1|minlength|6|La password deve essere di almeno 6 caratteri';
  512.     rules[2]='passw1|equal|\$passw2|Le due password non sembrano coincidere';
  513.     rules[3]='nome|required|Inserire un nome';
  514.     rules[4]='cognome|required|Inserire un cognome';
  515.     
  516.     </script>
  517.     </head>
  518.     
  519.     <body>\n";
  520.     
  521.     echo "<h1>Installazione VFRONT - Passo 3 di 3</h1>\n";
  522.     
  523.     echo "<h2>Creazione dell'utente amministratore</h2>\n";
  524.     
  525.     // analizza se il login è richiesto anche esternamente
  526.     
  527.     if($conf_auth['tipo_external_auth']!=''){
  528.         
  529.         echo "<p>Attenzione! E' stato impostato un sistema di autenticazione tramite archivio esterno ("
  530.              .$conf_auth['tipo_external_auth']."), pertanto la creazione dell'amministratore non &egrave; possibile.<br />
  531.              Accedere direttamente al sistema una volta con dati presenti sull'archivio  ".$conf_auth['tipo_external_auth']." specificato
  532.              e modificare a mano il livello dell'utente da 1 (utente semplice) a 3 (amministratore).</p>";
  533.         
  534.         echo "<p><a href=\"../index.php\">Accedi al login</a></p>\n";
  535.     }
  536.     
  537.     else{
  538.     
  539.     echo "<p>Inserisci adesso i dati per l'utente amministratore</p>\n";
  540.     
  541.     echo "<form action=\"?crea_admin\" method=\"post\" name=\"f1\" onsubmit=\"return performCheck('f1', rules,'classic');\">
  542.         
  543.         <label for=\"email\">Email:</label><br />
  544.         <input type=\"text\" size=\"42\" value=\"\" name=\"email\" id=\"email\" /><br /><br />
  545.         
  546.         <label for=\"passw1\">Password:</label><br />
  547.         <input type=\"password\" size=\"42\" value=\"\" name=\"passw1\" id=\"passw1\" /><br /><br />
  548.         
  549.         <label for=\"passw2\">Ripeti la password:</label><br />
  550.         <input type=\"password\" size=\"42\" value=\"\" name=\"passw2\" id=\"passw2\" /><br /><br />
  551.         
  552.         <label for=\"nome\">Nome:</label><br />
  553.         <input type=\"text\" size=\"42\" value=\"\" name=\"nome\" id=\"nome\" /><br /><br />
  554.         
  555.         <label for=\"cognome\">Cognome:</label><br />
  556.         <input type=\"text\" size=\"42\" value=\"\" name=\"cognome\" id=\"cognome\" /><br /><br />
  557.         
  558.         
  559.         <input type=\"submit\" value=\" Registra dati\" name=\"invia\"  />
  560.     
  561.     </form>\n";
  562.     
  563.     }
  564.     
  565.     echo "</body>\n</html>\n";
  566.     
  567.     exit;
  568.     
  569. }
  570.  
  571.  
  572.  
  573.  
  574.  
  575. /**
  576.  * @desc Funzione di creazione primo utente
  577.  *
  578.  */
  579.     
  580.     global $link$db1;
  581.     
  582.     require_once("../inc/func.comuni.php");
  583.     require_once("../inc/vmsql.".$db1['dbtype'].".php");
  584.     
  585.     $_dati=pulisci_dom($_POST);
  586.     
  587.     $sql=sprintf("INSERT INTO {$db1['frontend']}.utente (nickpasswdemaillivellogiddata_insnomecognomeVALUES 
  588.                   ('%s', '%s','%s', %d, %d, '%s', '%s', '%s')",
  589.                 $_dati['email'],
  590.                 md5($_dati['passw1']),
  591.                 $_dati['email'],
  592.                 3,
  593.                 0,
  594.                 date("Y-m-d"),
  595.                 $_dati['nome'],
  596.                 $_dati['cognome']
  597.                 );
  598.             
  599.     $q=vmsql_query($sql,$link);
  600.     
  601.     if(vmsql_affected_rows($link,$q)==1){
  602.         header("Location: ".$_SERVER['PHP_SELF']."?install_ok");
  603.         exit;
  604.     }
  605.     else{
  606.         header("Location: ".$_SERVER['PHP_SELF']."?install_ko");
  607.         exit;
  608.     }
  609.     
  610. }
  611.  
  612.  
  613.  
  614.  
  615.  
  616. if(isset($_POST['file_connessione'])){
  617.     
  618.     if(is_file($_POST['file_connessione'])){
  619.         
  620.         
  621.         // ma è proprio il file di connessione?
  622.         // provo a cercare almeno la variabile db1
  623.         
  624.         $file_conn=join('',file($_POST['file_connessione']));
  625.         
  626.         if(!ereg('db1\[\'frontend\'\]=',$file_conn)){
  627.             
  628.             header("Location: ".$_SERVER['PHP_SELF']."?install1&nofileconn_or");
  629.             exit;
  630.         }
  631.         
  632.         
  633.         $_SESSION['file_connessione']=$_POST['file_connessione'];
  634.         header("Location: ".$_SERVER['PHP_SELF']);
  635.         exit;
  636.     }
  637.     else{
  638.         
  639.         header("Location: ".$_SERVER['PHP_SELF']."?install1&nofileconn");
  640.         exit;
  641.     }
  642. }
  643.  
  644.  
  645. // SE ESISTE IL FILE DI CONNESSIONE IN SESSIONE
  646. if(isset($_SESSION['file_connessione']&& is_file($_SESSION['file_connessione'])){
  647.     
  648.     require_once($_SESSION['file_connessione']);
  649.     
  650.     require_once("../inc/vmsql.{$db1['dbtype']}.php");
  651.     
  652.     if($db1['dbtype']=='mysql')
  653.         $link @mysqli_connect($db1['host'],$db1['user'],$db1['passw'],$db1['dbname'],$db1['port']);
  654.     else
  655.         $link @pg_connect("host={$db1['host']} port={$db1['port']} dbname={$db1['postgres_dbname']} user={$db1['user']} password={$db1['passw']}");
  656.     
  657.     $utente_collegabile($linktrue:false;
  658.     
  659.     
  660. }
  661. else if(isset($_GET['install1'])){
  662.     
  663.     exit;
  664. }
  665. else{
  666.     
  667.     introduzione();
  668.     exit;
  669. }
  670.  
  671.  
  672.  
  673. ##################################################
  674. #
  675. #    REGISTRAZIONE del DB
  676. #
  677.  
  678.  
  679.  
  680.  
  681. if(isset($_GET['install_db'])){
  682.     
  683. //    print_r($_POST);
  684.     
  685.     if($_POST['tipo_link']==='0'){
  686.         
  687.         // Installa con utente di default
  688.         if($db1['dbtype']=='mysql')
  689.             $link @mysqli_connect($db1['host'],$db1['user'],$db1['passw'],$db1['dbname'],$db1['port']);
  690.         else if($db1['dbtype']=='postgres')
  691.             $link @pg_connect("host={$db1['host']} port={$db1['port']} dbname={$db1['postgres_dbname']} user={$db1['user']} password={$db1['passw']}");
  692.     
  693.         
  694.         header("Location: ".$_SERVER['PHP_SELF']."?err=1");
  695.         exit;
  696.     }
  697.     else{
  698.         if($db1['dbtype']=='mysql')
  699.             $link @mysqli_connect($_POST['host'],$_POST['user'],$_POST['passw'],$db1['dbname'],$_POST['port']);
  700.         else if($db1['dbtype']=='postgres')
  701.             $link @pg_connect("host={$_POST['host']} port={$_POST['port']} dbname={$db1['postgres_dbname']} user={$_POST['user']} password={$_POST['passw']}");
  702.     
  703.         
  704.     }
  705.  
  706.     
  707.     // testa la creazione di tabelle
  708.     
  709.     if(!test_crea_tabella()){
  710.         
  711.         header("Location: ".$_SERVER['PHP_SELF']."?err=2");
  712.         exit;
  713.         
  714.     }
  715.     else{
  716.         
  717.         
  718.         crea_db_vfront();
  719.     }
  720.     
  721.     header("Location: index.php?crea_utente_admin");
  722.     exit;
  723.     
  724. }
  725.  
  726.  
  727.  
  728.  
  729.  
  730.  
  731. #############################################
  732. #
  733. #    PROCEDURA STANDARD
  734. #
  735. #############################################
  736.  
  737. if(isset($_GET['crea_admin']&& count($_POST)>0){
  738.     
  739.     exit;
  740. }
  741.  
  742. else if(isset($_GET['install_ok'])){
  743.     
  744.     exit;
  745.     
  746.     
  747. }
  748.  
  749. else if(isset($_GET['esci'])){
  750.     
  751.     esci();
  752.     exit;
  753.     
  754.     
  755. }
  756.  
  757. else if(isset($_GET['install_ko'])){
  758.     
  759.     installazione_completata(false);
  760.     exit;
  761.     
  762.     
  763. }
  764.  
  765.     
  766.     include_once("./vfront.{$db1['dbtype']}.sql.php");
  767.     
  768.     echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">
  769. <html>
  770.     <head><title>Installazione Vfront</title>
  771.     <style type=\"text/css\">
  772.         @import \"install.css\";
  773.         @import \"../js/highlight/sample.css\";
  774.     </style>
  775.     
  776.     <script type=\"text/javascript\" src=\"../js/mostra_nascondi_id.js\"></script>
  777.     <script type=\"text/javascript\" src=\"../js/highlight/highlight.js\"></script>
  778.     <script type=\"text/javascript\">
  779.     
  780.     function ut(n){
  781.         
  782.         
  783.         document.getElementById('host').disabled= (n) ? true:false;
  784.         document.getElementById('user').disabled= (n) ? true:false;
  785.         document.getElementById('passw').disabled= (n) ? true:false;
  786.         document.getElementById('port').disabled= (n) ? true:false;
  787.     
  788.     }
  789.     
  790.      initHighlightingOnLoad('sql');
  791.     
  792.     </script>
  793.     
  794.     </head>
  795.     <body>\n";
  796.     
  797.     echo "<h1>Installazione VFRONT - Passo 2 di 3</h1>\n";
  798.     
  799.     
  800.     // errori di connessione:
  801.  
  802.     if(isset($_GET['err'])){
  803.         
  804.         switch ($_GET['err']){
  805.             
  806.             case 1: echo "<span style=\"color:red\"><b>Attenzione! Procedura interrotta</b>. Inserire una connessione per l'installazione</span>\n";
  807.             break;
  808.             
  809.             case 2: echo "<span style=\"color:red\">Impossibile creare tabelle con i diritti dell'utente indicato</span>\n";
  810.             break;
  811.             
  812.             
  813.             
  814.         }
  815.     
  816.     }
  817.     
  818.     
  819.     
  820.     
  821.     
  822.     
  823.     
  824.     
  825.     
  826.     echo "
  827.     <p>Qualora non si disponesse di diritti sufficienti a fa una installazione automatica, <br />si volesse installare manualmente<br />
  828.     oppure semplicemente si volesse andare a vedere che cosa l'installazione sta per fare sul vostro server,<br />
  829.      si pu&ograve; aprire <span class=\"fakelink\" onclick=\"mostra_nascondi('boxsql');\">questo box</span></p>\n";
  830.     
  831.     
  832.     echo "<div id=\"boxsql\" style=\"display:none\">\n";
  833.     echo "<pre><code class=\"sql\">\n";
  834.     echo implode("",$SQL_DEFINITION);
  835.     echo "</code></pre>\n";
  836.     echo "</div>\n";
  837.     
  838.     echo "<h2>Installazione del DB Vfront</h2>
  839.     
  840.     
  841.     <p>
  842.     Le tabelle saranno inserite nel database segnalato nel file CONF <strong>".$db1['frontend']."</strong><br />
  843.     Qualora non esistesse si cercher&agrave; di crearlo se si possiedono i diritti.
  844.     </p>
  845.     
  846.     <h3>Inserire i dati di un utente che possa creare tabelle ed utenti (ad es. root) </h3>
  847.     
  848.     <form action=\"".$_SERVER['PHP_SELF']."?install_db\" method=\"post\" >
  849.     
  850.     
  851.     ";
  852.     
  853.     $PORTA ($db1['dbtype']=='mysql'"3306" "5432";
  854.     
  855.     $UT_DEFAULT =($db1['dbtype']=='mysql'"root" "postgres";
  856.     
  857.     if($utente_collegabile){
  858.         
  859.             echo "
  860.             <input type=\"hidden\" name=\"tipo_link\" id=\"tl1\" value=\"1\"  /> 
  861.         
  862.         <p><strong>Inserire i dati di un utente con diritti di scrittura sul database:</strong><br /><br />
  863.             host: <input type=\"text\" name=\"host\" id=\"host\" value=\"localhost\" /><br />
  864.             user: <input type=\"text\" name=\"user\" id=\"user\" value=\"$UT_DEFAULT\" /><br />
  865.             password: <input type=\"password\" name=\"passw\" id=\"passw\" value=\"\" /><br />
  866.             porta: <input type=\"text\" name=\"port\" id=\"port\" value=\"$PORTA\" /><br />
  867.         </p>
  868.         
  869.         ";
  870.     }
  871.     else{
  872.         
  873.         
  874.         echo "
  875.             <input type=\"hidden\" name=\"tipo_link\" id=\"tl1\" value=\"1\" />
  876.         
  877.         <p>
  878.             host: <input type=\"text\" name=\"host\" id=\"host\" value=\"localhost\"  /><br />
  879.             user: <input type=\"text\" name=\"user\" id=\"user\" value=\"root\" /><br />
  880.             password: <input type=\"password\" name=\"passw\" id=\"passw\" value=\"\"  /><br />
  881.             porta: <input type=\"text\" name=\"port\" id=\"port\" value=\"$PORTA\" /><br />
  882.         </p>
  883.         
  884.         ";
  885.     }
  886.     
  887.     
  888.     echo "
  889.     <p>
  890.         <input type=\"radio\" name=\"grant_user\" id=\"g0\" value=\"1\"  checked=\"checked\" /> Attribuisci ad operazione avvenuta i diritti d'uso per VFRONT all'utente <b>".$db1['user']."</b> su questo DB (si devono avere diritti GRANT) <br />
  891.         <input type=\"radio\" name=\"grant_user\" id=\"g1\" value=\"0\"  /> Imposta i diritti successivamente in maniera manuale<br />
  892.     </p>
  893.     
  894.     
  895.     <input type=\"submit\" name=\"Invia\" value=\" Procedi \" />
  896.     
  897.     <input type=\"button\" name=\"esci\" value=\" Esci dall'installazione \" onclick=\"location.href='?esci'\"/>
  898.     
  899.     </form>
  900.     
  901.     </body>
  902.     </html>";
  903.     
  904.     
  905. }
  906.  
  907. else if(isset($_GET['crea_utente_admin'])){
  908.     
  909.     // schermata di creazione amministratore
  910.     
  911. }
  912.  
  913.  
  914. else{
  915.     
  916.     echo "<p><b>Attenzione!</b> Questa istanza di Vfront sembra gi&agrave; stata installata.</p>
  917.     <p>Procedura interrotta.</p>";
  918.     
  919. }
  920.  
  921.  
  922. ?>

Documentation generated on Sat, 22 Sep 2007 11:50:49 +0200 by phpDocumentor 1.4.0a2