Source for file index.php
Documentation is available at index.php
#################################################
# This file is part of VFront.
# VFront is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# VFront is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
* VFront Web Installer - Utility di installazione dell'applicazione VFront
* Caratteristiche richieste: PHP5.x , MySQL 5.x, php_mysqli
* Oppure: PHP5.x , Postgres 8.x, php_pgsql
* @subpackage VFront_Web_Installer
* @author M.Marcello Verona
* @copyright 2007 M.Marcello Verona
* @license http://www.gnu.org/licenses/gpl.html GNU Public License
* @desc Esce dall'installazione
header("Location: ". $_SERVER['PHP_SELF']);
* @desc Esegue i GRANT necessari per il nuovo utente
* @param bool $return_only_sql
function grant($return_only_sql= false){
if($db1['dbtype']== 'mysql'){
$sql_user= "CREATE USER {$db1['user']}@{$db1['host']} IDENTIFIED BY '{$db1['passw']}'; ";
$sql[]= "GRANT SELECT, INSERT, UPDATE, DELETE ON {$db1['frontend']}.* TO '{$db1['user']}'@{$db1['host']} IDENTIFIED BY '{$db1['passw']}';";
$sql[]= "GRANT SELECT, INSERT, UPDATE, DELETE, SHOW VIEW ON {$db1['dbname']}.* TO '{$db1['user']}'@{$db1['host']} IDENTIFIED BY '{$db1['passw']}';";
else if ($db1['dbtype']== 'postgres'){
$sql_user= "CREATE USER {$db1['user']} WITH PASSWORD '{$db1['passw']}'; ";
// diritto d'uso dello schema frontend
$sql[]= "GRANT USAGE ON SCHEMA {$db1['frontend']} TO {$db1['user']};";
// diritto d'uso dello schema information_schema
$sql[]= "GRANT USAGE ON SCHEMA information_schema TO {$db1['user']};";
// diritto d'uso dello schema pg_catalog
$sql[]= "GRANT USAGE ON SCHEMA pg_catalog TO {$db1['user']};";
// prendi le tabelle dei due schemi
$q_tab= pg_query($link,"SELECT table_schema || '.' || table_name FROM information_schema.tables WHERE table_schema IN ('{$db1['dbname']}','{$db1['frontend']}')");
while($RS_tab= pg_fetch_row($q_tab)){
$sql[]= "GRANT SELECT, INSERT, UPDATE, DELETE, REFERENCES ON ". $RS_tab[0]. " TO {$db1['user']};";
// prendi le tabelle dell'information_schema
$q_tab= pg_query($link,"SELECT table_schema || '.' || table_name FROM information_schema.tables WHERE table_schema='information_schema'; ");
while($RS_tab= pg_fetch_row($q_tab)){
$sql[]= "GRANT SELECT ON ". $RS_tab[0]. " TO {$db1['user']};";
// prendi le funzioni dei due schemi
$q_func= pg_query($link,"select 'GRANT EXECUTE ON FUNCTION '||n.nspname||'.'||p.proname||'('||oidvectortypes(p.proargtypes)||') TO {$db1['user']};' from pg_proc p, pg_namespace n where n.oid = p.pronamespace and n.nspname IN ('{$db1['dbname']}','{$db1['frontend']}');");
while($RS_func= pg_fetch_row($q_func)){
// prendi le sequenze dei due schemi
$q_seq= pg_query($link,"select 'GRANT ALL ON '||n.nspname||'.'||c.relname||' TO {$db1['user']};' from pg_class c, pg_namespace n where n.oid = c.relnamespace and c.relkind IN ('S') and n.nspname in ('{$db1['dbname']}','{$db1['frontend']}');");
while($RS_seq= pg_fetch_row($q_seq)){
return $sql_user. "\n". implode("\n",$sql);
if($db1['dbtype']== 'mysql'){
$q_user= @mysqli_query($link,$sql_user);
for($i= 0;$i< count($sql);$i++ )
$q= mysqli_query($link,$sql[$i]) or die(mysqli_error($link));
return mysqli_affected_rows($link);
elseif($db1['dbtype']== 'postgres'){
$q_user= @pg_query($link,$sql_user);
for($i= 0;$i< count($sql);$i++ )
$q= pg_query($link,$sql[$i]) or die(pg_errormessage($link));
return pg_affected_rows($q);
* @desc Genera il codice HTML da mostrare a fine installazione
echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">
<head><title>Installazione Vfront</title>
<style type=\"text/css\">
echo "<h1>Installazione completata!</h1>
<p>Vai alla pagina di login ed accedi con l'email e la password da te specificate.</p>
<a href=\"../index.php\">Vai al login</a>\n";
echo "<h1>Errore nella creazione dell'utente!</h1>
<p>Prova a creare manualmente l'utente nella tabella <em>utente</em> specificando livello = 3 e gruppo = 0</p>
<a href=\"../index.php\">Vai al login</a>\n";
echo "</body>\n</html>\n";
* @desc Genera il codice HTML da mostrare a inizio installazione
echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">
<head><title>Installazione Vfront</title>
<style type=\"text/css\">
<script type=\"text/javascript\">
document.getElementById('host').disabled= (n) ? true:false;
document.getElementById('user').disabled= (n) ? true:false;
document.getElementById('passw').disabled= (n) ? true:false;
document.getElementById('port').disabled= (n) ? true:false;
echo openLayout1('Installazione VFront');*/
echo "<h1>Installazione VFRONT - Introduzione</h1>\n";
echo "<p><strong>Benvenuti all'installazione di VFront!</strong></p>\n";
echo "<div class=\"par\">Questa procedura installerà l'applicazione nel server.
<li>Per installare l'applicazione è necessario innanzitutto <b>modificare il file conf</b>.
Questo si trova nella directory <em>/conf</em> ma può essere spostato in una directory non sottoposta a browsing.<br />
Se non l'hai già fatto interrompi la lettura e modifica il file di configurazione.<br />
(Per maggiori informazioni sul file conf si legga il file README)<br /><br />
L'installazione di VFront leggerà i parametri del file di configurazione e svolgerà diverse operazioni:<br />
- Creazione del database per il frontend<br />
- Creazione dell'utente richiesto<br />
- Inserimento di alcuni dati per l'inizializzazione<br />
<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>
<li>L'installazione da ora avviene in maniera automatica e consta in tre passi:
<li>Richiesta della posizione del file conf sul filesystem</li>
<li>Creazione delle tabelle e dell'eventuale database di frontend, se non è già stato creato.</li>
<li>Creazione di un primo amministratore per VFront</li>
<h2>Dopo l'installazione</h2>
<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>
<p>Per sincronizzare VFront con il database andare su Amministrazione -> Gestione Registri -> Inizializza Registri</p>
<p>Per una panoramica dell'installazione di VFront andare su Amministrazione -> Varie -> Test impostazioni VFront Registri</p>
<div style=\"text-align:center;\"><p style=\"font-size:1.6em;\" > <a href=\"?install1\">Procedi con l'installazione</a> </p></div>
echo "</body>\n</html>\n";
echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">
<head><title>Installazione Vfront</title>
<style type=\"text/css\">
<script type=\"text/javascript\">
document.getElementById('host').disabled= (n) ? true:false;
document.getElementById('user').disabled= (n) ? true:false;
document.getElementById('passw').disabled= (n) ? true:false;
document.getElementById('port').disabled= (n) ? true:false;
echo "<h1>Installazione VFRONT - Passo 1 di 3</h1>\n";
if(isset ($_GET['nofileconn'])){
echo "<p style=\"color:red\">Il file indicato è inesistente o inaccessibile</p>";
if(isset ($_GET['nofileconn_or'])){
echo "<p style=\"color:red\">Il file indicato non sembra essere il file di configurazione!</p>";
<form action=\"". $_SERVER['PHP_SELF']. "?conf\" method=\"post\" >
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 />
<em>Nota: utilizzare lo slash normale (/) anche in ambiente Windows</em>
<input type=\"submit\" name=\"Invia\" value=\" Procedi \" />
* Funzione che analizza la presenza di gruppi nel DB di VFront
// cerca tabella gruppi e verifica che ce ne sia almeno 1 (lo 0)
$sql_gruppi= "SELECT * FROM {$db1['frontend']}.gruppo ORDER BY gid ASC LIMIT 1";
* Funzione di test per la generazione di una tabella.
* Serve a testare il diritto CREATE, mediante la creazione di una tabella di nome pseudocasuale
if($db1['dbtype']== 'postgres'){
$q_test= @pg_query($link,"CREATE TABLE {$db1['dbname']}.$nome_tabella (id_test int2 NOT NULL, PRIMARY KEY (id_test));");
$q_test= @mysqli_query($link,"CREATE TABLE {$db1['dbname']}.$nome_tabella (id_test int(11) NOT NULL, PRIMARY KEY (id_test)) ENGINE=InnoDB DEFAULT CHARSET=latin1;");
if($db1['dbtype']== 'postgres'){
$q_test2= @pg_query($link,"DROP TABLE {$db1['dbname']}.$nome_tabella ");
$q_test2= @mysqli_query($link,"DROP TABLE {$db1['dbname']}.$nome_tabella ");
* @desc Crea il DB e le tabelle
if($db1['dbtype']== 'mysql'){
if(!is_file("./vfront.mysql.sql.php")){
die("Impossibile leggere il file di origine dati SQL. Procedura interrotta.");
require_once("./vfront.mysql.sql.php");
if(!is_file("./vfront.postgres.sql.php")){
die("Impossibile leggere il file di origine dati SQL. Procedura interrotta.");
require_once("./vfront.postgres.sql.php");
if($db1['dbtype']== 'mysql'){
$sql_creadb= "CREATE DATABASE IF NOT EXISTS ". $db1['frontend'];
$q0= @vmsql_query($sql_creadb,$link) or die("Impossibile creare il database {$db1['frontend']}");
$q_use0= vmsql_query("USE ". $db1['frontend'],$link) or die("Impossibile utilizzare il database {$db1['frontend']} con comando USE");
elseif($db1['dbtype']== 'postgres'){
// $sql_creadb= "CREATE SCHEMA \"frontend\" AUTHORIZATION \"postgres\"";
// $q0=@vmsql_query($sql_creadb,$link) or die("Impossibile creare lo schema {$db1['frontend']}");
for($i= 0;$i< count($SQL_DEFINITION);$i++ ){
$q_creatabelle= vmsql_query($SQL_DEFINITION[$i],$link) or ($errore= 1);
$xerr= ($db1['dbtype']== 'mysql') ? mysqli_error($link) : pg_errormessage($link);
die("$xerr<br /> Impossibile creare le tabelle nel database {$db1['frontend']}");
if($db1['dbtype']== 'mysql'){
$q_use0= vmsql_query("USE ". $db1['dbname'],$link) or die("Impossibile utilizzare il database {$db1['dbname']} con comando USE");
if(isset ($_POST['grant_user']) && $_POST['grant_user']== 1){
* @desc Funzione per la generazione della pagina di creazione primo utente
global $link,$db1, $conf_auth;
echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">
<head><title>Installazione Vfront</title>
<style type=\"text/css\">
<script type=\"text/javascript\" src=\"../js/yav/yav.js\" ></script>
<script type=\"text/javascript\" src=\"../js/yav/yav-config-it.js\" ></script>
<script type=\"text/javascript\" >
rules[0]='email|required|Inserire una email';
rules[1]='passw1|minlength|6|La password deve essere di almeno 6 caratteri';
rules[2]='passw1|equal|\$passw2|Le due password non sembrano coincidere';
rules[3]='nome|required|Inserire un nome';
rules[4]='cognome|required|Inserire un cognome';
echo "<h1>Installazione VFRONT - Passo 3 di 3</h1>\n";
echo "<h2>Creazione dell'utente amministratore</h2>\n";
// analizza se il login è richiesto anche esternamente
if($conf_auth['tipo_external_auth']!= ''){
echo "<p>Attenzione! E' stato impostato un sistema di autenticazione tramite archivio esterno ("
. $conf_auth['tipo_external_auth']. "), pertanto la creazione dell'amministratore non è possibile.<br />
Accedere direttamente al sistema una volta con dati presenti sull'archivio ". $conf_auth['tipo_external_auth']. " specificato
e modificare a mano il livello dell'utente da 1 (utente semplice) a 3 (amministratore).</p>";
echo "<p><a href=\"../index.php\">Accedi al login</a></p>\n";
echo "<p>Inserisci adesso i dati per l'utente amministratore</p>\n";
echo "<form action=\"?crea_admin\" method=\"post\" name=\"f1\" onsubmit=\"return performCheck('f1', rules,'classic');\">
<label for=\"email\">Email:</label><br />
<input type=\"text\" size=\"42\" value=\"\" name=\"email\" id=\"email\" /><br /><br />
<label for=\"passw1\">Password:</label><br />
<input type=\"password\" size=\"42\" value=\"\" name=\"passw1\" id=\"passw1\" /><br /><br />
<label for=\"passw2\">Ripeti la password:</label><br />
<input type=\"password\" size=\"42\" value=\"\" name=\"passw2\" id=\"passw2\" /><br /><br />
<label for=\"nome\">Nome:</label><br />
<input type=\"text\" size=\"42\" value=\"\" name=\"nome\" id=\"nome\" /><br /><br />
<label for=\"cognome\">Cognome:</label><br />
<input type=\"text\" size=\"42\" value=\"\" name=\"cognome\" id=\"cognome\" /><br /><br />
<input type=\"submit\" value=\" Registra dati\" name=\"invia\" />
echo "</body>\n</html>\n";
* @desc Funzione di creazione primo utente
require_once("../inc/func.comuni.php");
require_once("../inc/vmsql.". $db1['dbtype']. ".php");
$sql= sprintf("INSERT INTO {$db1['frontend']}.utente (nick, passwd, email, livello, gid, data_ins, nome, cognome) VALUES
('%s', '%s','%s', %d, %d, '%s', '%s', '%s')",
header("Location: ". $_SERVER['PHP_SELF']. "?install_ok");
header("Location: ". $_SERVER['PHP_SELF']. "?install_ko");
if(isset ($_POST['file_connessione'])){
if(is_file($_POST['file_connessione'])){
// ma è proprio il file di connessione?
// provo a cercare almeno la variabile db1
$file_conn= join('',file($_POST['file_connessione']));
if(!ereg('db1\[\'frontend\'\]=',$file_conn)){
header("Location: ". $_SERVER['PHP_SELF']. "?install1&nofileconn_or");
$_SESSION['file_connessione']= $_POST['file_connessione'];
header("Location: ". $_SERVER['PHP_SELF']);
header("Location: ". $_SERVER['PHP_SELF']. "?install1&nofileconn");
// SE ESISTE IL FILE DI CONNESSIONE IN SESSIONE
if(isset ($_SESSION['file_connessione']) && is_file($_SESSION['file_connessione'])){
require_once($_SESSION['file_connessione']);
require_once("../ inc/ vmsql.{ $db1['dbtype']}. php");
if($db1['dbtype']== 'mysql')
$link = @mysqli_connect($db1['host'],$db1['user'],$db1['passw'],$db1['dbname'],$db1['port']);
$link = @pg_connect("host={$db1['host']} port={$db1['port']} dbname={$db1['postgres_dbname']} user={$db1['user']} password={$db1['passw']}");
$utente_collegabile= ($link) ? true: false;
else if(isset ($_GET['install1'])){
##################################################
if(isset ($_GET['install_db'])){
if($_POST['tipo_link']=== '0'){
// Installa con utente di default
if($db1['dbtype']== 'mysql')
$link = @mysqli_connect($db1['host'],$db1['user'],$db1['passw'],$db1['dbname'],$db1['port']);
else if($db1['dbtype']== 'postgres')
$link = @pg_connect("host={$db1['host']} port={$db1['port']} dbname={$db1['postgres_dbname']} user={$db1['user']} password={$db1['passw']}");
header("Location: ". $_SERVER['PHP_SELF']. "?err=1");
if($db1['dbtype']== 'mysql')
$link = @mysqli_connect($_POST['host'],$_POST['user'],$_POST['passw'],$db1['dbname'],$_POST['port']);
else if($db1['dbtype']== 'postgres')
$link = @pg_connect("host={$_POST['host']} port={$_POST['port']} dbname={$db1['postgres_dbname']} user={$_POST['user']} password={$_POST['passw']}");
// testa la creazione di tabelle
header("Location: ". $_SERVER['PHP_SELF']. "?err=2");
header("Location: index.php?crea_utente_admin");
#############################################
#############################################
if(isset ($_GET['crea_admin']) && count($_POST)> 0){
else if(isset ($_GET['install_ok'])){
else if(isset ($_GET['esci'])){
else if(isset ($_GET['install_ko'])){
include_once("./ vfront.{ $db1['dbtype']}. sql. php");
echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">
<head><title>Installazione Vfront</title>
<style type=\"text/css\">
@import \"../js/highlight/sample.css\";
<script type=\"text/javascript\" src=\"../js/mostra_nascondi_id.js\"></script>
<script type=\"text/javascript\" src=\"../js/highlight/highlight.js\"></script>
<script type=\"text/javascript\">
document.getElementById('host').disabled= (n) ? true:false;
document.getElementById('user').disabled= (n) ? true:false;
document.getElementById('passw').disabled= (n) ? true:false;
document.getElementById('port').disabled= (n) ? true:false;
initHighlightingOnLoad('sql');
echo "<h1>Installazione VFRONT - Passo 2 di 3</h1>\n";
// errori di connessione:
case 1: echo "<span style=\"color:red\"><b>Attenzione! Procedura interrotta</b>. Inserire una connessione per l'installazione</span>\n";
case 2: echo "<span style=\"color:red\">Impossibile creare tabelle con i diritti dell'utente indicato</span>\n";
<p>Qualora non si disponesse di diritti sufficienti a fa una installazione automatica, <br />si volesse installare manualmente<br />
oppure semplicemente si volesse andare a vedere che cosa l'installazione sta per fare sul vostro server,<br />
si può aprire <span class=\"fakelink\" onclick=\"mostra_nascondi('boxsql');\">questo box</span></p>\n";
echo "<div id=\"boxsql\" style=\"display:none\">\n";
echo "<pre><code class=\"sql\">\n";
echo "<h2>Installazione del DB Vfront</h2>
Le tabelle saranno inserite nel database segnalato nel file CONF <strong>". $db1['frontend']. "</strong><br />
Qualora non esistesse si cercherà di crearlo se si possiedono i diritti.
<h3>Inserire i dati di un utente che possa creare tabelle ed utenti (ad es. root) </h3>
<form action=\"". $_SERVER['PHP_SELF']. "?install_db\" method=\"post\" >
$PORTA = ($db1['dbtype']== 'mysql') ? "3306" : "5432";
$UT_DEFAULT = ($db1['dbtype']== 'mysql') ? "root" : "postgres";
<input type=\"hidden\" name=\"tipo_link\" id=\"tl1\" value=\"1\" />
<p><strong>Inserire i dati di un utente con diritti di scrittura sul database:</strong><br /><br />
host: <input type=\"text\" name=\"host\" id=\"host\" value=\"localhost\" /><br />
user: <input type=\"text\" name=\"user\" id=\"user\" value=\"$UT_DEFAULT\" /><br />
password: <input type=\"password\" name=\"passw\" id=\"passw\" value=\"\" /><br />
porta: <input type=\"text\" name=\"port\" id=\"port\" value=\"$PORTA\" /><br />
<input type=\"hidden\" name=\"tipo_link\" id=\"tl1\" value=\"1\" />
host: <input type=\"text\" name=\"host\" id=\"host\" value=\"localhost\" /><br />
user: <input type=\"text\" name=\"user\" id=\"user\" value=\"root\" /><br />
password: <input type=\"password\" name=\"passw\" id=\"passw\" value=\"\" /><br />
porta: <input type=\"text\" name=\"port\" id=\"port\" value=\"$PORTA\" /><br />
<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 />
<input type=\"radio\" name=\"grant_user\" id=\"g1\" value=\"0\" /> Imposta i diritti successivamente in maniera manuale<br />
<input type=\"submit\" name=\"Invia\" value=\" Procedi \" />
<input type=\"button\" name=\"esci\" value=\" Esci dall'installazione \" onclick=\"location.href='?esci'\"/>
else if(isset ($_GET['crea_utente_admin'])){
// schermata di creazione amministratore
echo "<p><b>Attenzione!</b> Questa istanza di Vfront sembra già stata installata.</p>
<p>Procedura interrotta.</p>";
|