Commit 7c65b69da5bc5467560e73281b66b81bdc252974
1 parent
82cae5e7
Exists in
mysqli
and in
3 other branches
Correções e melhorias no script de configuração
Showing
1 changed file
with
51 additions
and
38 deletions
Show diff stats
instalar/index.php
... | ... | @@ -10,27 +10,36 @@ if ( (is_writable("../inc/config.php") and is_writable("../restrito/inc/config.p |
10 | 10 | if ($_SERVER['REQUEST_METHOD'] == "POST") { |
11 | 11 | $erro = false; |
12 | 12 | |
13 | + $nome = $_POST["nome"]; | |
14 | + $codigo = $_POST["codigo"]; | |
15 | + (substr($_POST["sitelink"], -1) != "/") ? $sitelink = $_POST["sitelink"]."/" : $sitelink = $_POST["sitelink"]; | |
16 | + if (substr($_POST["urlsistema"], -1) != "/") { | |
17 | + if ($_POST["urlsistema"] != "") { | |
18 | + $urlsistema = $_POST["urlsistema"]."/"; | |
19 | + } else { | |
20 | + $urlsistema = $sitelink; | |
21 | + } | |
22 | + } else { | |
23 | + $urlsistema = $_POST["urlsistema"]; | |
24 | + } | |
25 | + $dbhost = $_POST["dbhost"]; | |
26 | + $dbuser = $_POST["dbuser"]; | |
27 | + $dbpass = $_POST["dbpass"]; | |
28 | + $dbname = $_POST["dbname"]; | |
29 | + $phpmailer = $_POST["phpmailer"] == "phpmailer" ? "true" : "false"; | |
30 | + $smtphost = $_POST["smtpport"] != "" ? $_POST["smtphost"].":".$_POST["smtpport"] : $_POST["smtphost"]; | |
31 | + $smtpauth = $_POST["smtpauth"] == "smtpauth" ? "true" : "false"; | |
32 | + $smtpuser = $_POST["smtpuser"]; | |
33 | + $smtppwd = $_POST["smtppwd"]; | |
34 | + | |
35 | + | |
13 | 36 | // Verifica os campos obrigatórios |
14 | - if ($_POST["nome"] and $_POST["codigo"] and $_POST["sitelink"] and $_POST["urlsistema"] and | |
15 | - $_POST["dbhost"] and $_POST["dbuser"] and $_POST["dbpass"] and $_POST["dbname"] and | |
16 | - ((!$_POST["phpmailer"]) or ($_POST["smtphost"] and | |
17 | - (!($_POST["smtpauth"]) or ($_POST["smtpuser"] and $_POST["smtppwd"])) | |
37 | + if ($nome and $codigo and $sitelink and $urlsistema and | |
38 | + $dbhost and $dbuser and $dbpass and $dbname and | |
39 | + ((!$phpmailer) or ($smtphost and | |
40 | + (!($smtpauth) or ($smtpuser and $smtppwd)) | |
18 | 41 | )) |
19 | - ) { | |
20 | - $nome = $_POST["nome"]; | |
21 | - $codigo = $_POST["codigo"]; | |
22 | - ($_POST["sitelink"][strlen($_POST["sitelink"]-1)] != "/") ? $sitelink = $_POST["sitelink"]."/" : $sitelink = $_POST["sitelink"]; | |
23 | - ($_POST["urlsistema"][strlen($_POST["urlsistema"]-1)] != "/") ? $urlsistema = $_POST["urlsistema"]."/" : $urlsistema = $_POST["urlsistema"]; | |
24 | - $dbhost = $_POST["dbhost"]; | |
25 | - $dbuser = $_POST["dbuser"]; | |
26 | - $dbpass = $_POST["dbpass"]; | |
27 | - $dbname = $_POST["dbname"]; | |
28 | - $phpmailer = $_POST["phpmailer"] == "phpmailer" ? "true" : "false"; | |
29 | - $smtphost = $_POST["$smtpport"] != "" ? $_POST["smtphost"].":".$_POST["smtpport"] : $_POST["smtphost"]; | |
30 | - $smtpauth = $_POST["smtpauth"] == "smtpauth" ? "true" : "false"; | |
31 | - $smtpuser = $_POST["smtpuser"]; | |
32 | - $smtppwd = $_POST["smtppwd"]; | |
33 | - | |
42 | + ) { | |
34 | 43 | try { |
35 | 44 | $config = fopen("../inc/config.php", "w"); |
36 | 45 | fwrite($config, <<<CONF |
... | ... | @@ -112,20 +121,23 @@ CONF |
112 | 121 | ); |
113 | 122 | fclose($config); |
114 | 123 | } catch(Exceptipon $e) { |
115 | - $erro = "não foi possível escrever os arquivos de configuração ($e)"; | |
124 | + $erro = "não foi possível escrever os arquivos de configuração ($e)"; | |
116 | 125 | } |
117 | 126 | } else { |
118 | - $erro = "campos obrigatórios não preenchidos"; | |
127 | + $erro = "campos obrigatórios não preenchidos"; | |
119 | 128 | } |
120 | 129 | |
121 | 130 | // Se a configuração foi bem sucedida, passa à próxima etapa |
122 | 131 | if (!$erro) { |
123 | - header("Location: $urlsistemainstalar/bd.php"); | |
132 | + header("Location: ".$urlsistema."instalar/bd.php"); | |
124 | 133 | die(); |
125 | 134 | } else { |
126 | - echo "<script language='javascript'>alert('Erro na configuração do sistema: $erro.');</script>"; | |
135 | + echo "<script language='javascript'>e = document.createElement('span');e.innerHTML = 'Erro na configuração do sistema: $erro.';alert(e.textContent);</script>"; // Dessa maneira conseguimos exibir os caracteres especiais | |
127 | 136 | } |
128 | -} | |
137 | + } else { // GET | |
138 | + $nome = "e-SIC Livre"; | |
139 | + $codigo = "esiclivre"; | |
140 | + } | |
129 | 141 | |
130 | 142 | include("../inc/topo.php"); |
131 | 143 | |
... | ... | @@ -135,37 +147,38 @@ include("../inc/topo.php"); |
135 | 147 | <div id="principal"> |
136 | 148 | <h1>Instalação do e-SIC Livre</h1> |
137 | 149 | <h2>Passo 1 de 2</h2> |
150 | + <h3>Configuração do sistema</h3> | |
138 | 151 | <form action="index.php" method="post"> |
139 | 152 | <fieldset> |
140 | 153 | <legend>Informações do sistema</legend> |
141 | 154 | <table> |
142 | - <tr><td><label for="nome">Nome do sistema:<small>*</small></label></td><td><input type="text" name="nome" id="nome" value="e-SIC Livre"></td></tr> | |
143 | - <tr><td><label for="codigo">Código dos <em>cookies</em> de sessão:<small>*</small></label></td><td><input type="text" name="codigo" id="codigo" value="esiclivre"></td></tr> | |
144 | - <tr><td><label for="sitelink">URL do <em>site</em> principal:<small>*</small></label></td><td><input type="text" name="sitelink" id="sitelink" value=""></td></tr> | |
145 | - <tr><td><label for="urlsistema">URL da raiz do sistema:<small>*</small></label></td><td><input type="text" name="urlsistema" id="urlsistema" value=""></td></tr> | |
155 | + <tr><td><label for="nome">Nome do sistema:<small>*</small></label></td><td><input type="text" name="nome" id="nome" value="<?php echo $nome;?>"></td></tr> | |
156 | + <tr><td><label for="codigo">Código dos <em>cookies</em> de sessão:<small>*</small></label></td><td><input type="text" name="codigo" id="codigo" value="<?php echo $codigo;?>"></td></tr> | |
157 | + <tr><td><label for="sitelink">URL do <em>site</em> principal:<small>*</small></label></td><td><input type="text" name="sitelink" id="sitelink" value="<?php echo $sitelink;?>"></td></tr> | |
158 | + <tr><td><label for="urlsistema">URL da raiz do sistema:<small>*</small></label></td><td><input type="text" name="urlsistema" id="urlsistema" value="<?php echo $urlsistema;?>"></td></tr> | |
146 | 159 | </table> |
147 | 160 | </fieldset> |
148 | 161 | |
149 | 162 | <fieldset> |
150 | 163 | <legend>Banco de dados</legend> |
151 | 164 | <table> |
152 | - <tr><td><label for="dbhost">Endereço do servidor:<small>*</small></label></td><td><input type="text" name="dbhost" id="dbhost" value=""></td></tr> | |
153 | - <tr><td><label for="dbuser"></label>Usuário:<small>*</small></td><td><input type="text" name="dbuser" id="dbuser" value=""></td></tr> | |
154 | - <tr><td><label for="dbpass">Senha:<small>*</small></label></td><td><input type="password" name="dbpass" id="dbpass" value=""></td></tr> | |
155 | - <tr><td><label for="dbname">Nome do banco de dados:<small>*</small></label></td><td><input type="text" name="dbname" id="dbname" value=""></td></tr> | |
165 | + <tr><td><label for="dbhost">Endereço do servidor:<small>*</small></label></td><td><input type="text" name="dbhost" id="dbhost" value="<?php echo $dbhost;?>"></td></tr> | |
166 | + <tr><td><label for="dbuser"></label>Usuário:<small>*</small></td><td><input type="text" name="dbuser" id="dbuser" value="<?php echo $dbuser;?>"></td></tr> | |
167 | + <tr><td><label for="dbpass">Senha:<small>*</small></label></td><td><input type="password" name="dbpass" id="dbpass" value="<?php echo $dbpass;?>"></td></tr> | |
168 | + <tr><td><label for="dbname">Nome do banco de dados:<small>*</small></label></td><td><input type="text" name="dbname" id="dbname" value="<?php echo $dbname;?>"></td></tr> | |
156 | 169 | </table> |
157 | 170 | </fieldset> |
158 | 171 | |
159 | 172 | <fieldset> |
160 | 173 | <legend>Envio de e-mail</legend> |
161 | 174 | <table> |
162 | - <tr><td><label for="phpmailer">Usar o PHP Mailer?</label></td><td><input type="checkbox" name="phpmailer" id="phpmailer" value="phpmailer"></td></tr> | |
175 | + <tr><td><label for="phpmailer">Usar o PHP Mailer?</label></td><td><input type="checkbox" name="phpmailer" id="phpmailer" value="phpmailer" <?php if ($phpmailer != "") {echo "checked=\"true\"";}?>"></td></tr> | |
163 | 176 | <tr><td colspan="2">Se usar o PHP Mailer, preencha os campos a seguir:</td></tr> |
164 | - <tr><td><label for="smtphost">Servidor de e-mail:</label></td><td><input type="text" name="smtphost" id="smtphost" value=""></td></tr> | |
165 | - <tr><td><label for="smtpport"></label>Porta de SMTP:</td><td><input type="text" name="smtpport" id="smtpport" value=""></td></tr> | |
166 | - <tr><td><label for="smtpauth"></label>Necessário autenticar?</td><td><input type="checkbox" name="smtpauth" id="smtpauth" value="smtpauth"></td></tr> | |
167 | - <tr><td><label for="smtpuser"></label>Usuário do servidor de e-mail:</td><td><input type="text" name="smtpuser" id="smtpuser" value=""></td></tr> | |
168 | - <tr><td><label for="smtppwd"></label>Senha do usuário do servidor de e-mail:</td><td><input type="password" name="smtppwd" id="smtppwd" value=""></td></tr> | |
177 | + <tr><td><label for="smtphost">Servidor de e-mail:</label></td><td><input type="text" name="smtphost" id="smtphost" value="<?php echo $_POST["smtphost"];?>"></td></tr> | |
178 | + <tr><td><label for="smtpport"></label>Porta de SMTP:</td><td><input type="text" name="smtpport" id="smtpport" value="<?php echo $_POST["smtpport"];?>"></td></tr> | |
179 | + <tr><td><label for="smtpauth"></label>Necessário autenticar?</td><td><input type="checkbox" name="smtpauth" id="smtpauth" value="smtpauth" <?php if ($smtpauth != "") {echo "checked=\"true\"";}?>"></td></tr> | |
180 | + <tr><td><label for="smtpuser"></label>Usuário do servidor de e-mail:</td><td><input type="text" name="smtpuser" id="smtpuser" value="<?php echo $smtpuser;?>"></td></tr> | |
181 | + <tr><td><label for="smtppwd"></label>Senha do usuário do servidor de e-mail:</td><td><input type="password" name="smtppwd" id="smtppwd" value="<?php echo $smtppwd;?>"></td></tr> | |
169 | 182 | </table> |
170 | 183 | </fieldset> |
171 | 184 | <p><small>*Campos obrigatórios.</small></p> | ... | ... |