<?php
/*
This file is part of DNP Script, an open source domain portfolio script.
Copyright (C) 2011 Robert Picard
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program 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 Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="stylesheet" href="style.css" />
<title>Install DNP Script</title>
<script>
<?php
if(file_exists('../config.php')){
echo '
window.onload=function(){
var e = install.elements;
for(i=0;i<e.length;i++){
e[i].disabled = true;
}
document.getElementById("form_message").innerHTML=\'<span class="message_warning">It appears that DNP Script has already been installed here. You should delete the /install directory now to keep your site secure.\';
document.getElementById("install").innerHTML="";
}';
}
?>
function validateForm(){
var f=document.forms["install"]["db_host"].value;
if(f==null || f==""){
document.getElementById("form_message").innerHTML = "<span class='message_warning'>The <b>database host</b> field is required.</span>";
return false;
}
var f=document.forms["install"]["db_user"].value;
if(f==null || f==""){
document.getElementById("form_message").innerHTML = "<span class='message_warning'>The <b>username</b> field is required.</span>";
return false;
}
var f=document.forms["install"]["db_name"].value;
if(f==null || f==""){
document.getElementById("form_message").innerHTML = "<span class='message_warning'>The <b>database name</b> field is required.</span>";
return false;
}
var f=document.forms["install"]["s_title"].value;
if(f==null || f==""){
document.getElementById("form_message").innerHTML = "<span class='message_warning'>The <b>site title</b> field is required.</span>";
return false;
}
var f=document.forms["install"]["s_description"].value;
if(f==null || f==""){
document.getElementById("form_message").innerHTML = "<span class='message_warning'>The <b>description</b> field is required.</span>";
return false;
}
var f=document.forms["install"]["s_pass"].value;
if(f==null || f==""){
document.getElementById("form_message").innerHTML = "<span class='message_warning'>The <b>admin password</b> field is required.</span>";
return false;
}
var f=document.forms["install"]["s_email"].value;
if(f==null || f==""){
document.getElementById("form_message").innerHTML = "<span class='message_warning'>The <b>admin email</b> field is required.</span>";
return false;
}
var x=document.forms["install"]["s_email"].value;
var atpos=x.indexOf("@");
var dotpos=x.lastIndexOf(".");
if( atpos<1 || dotpos<atpos+2 || dotpos+2>x.length){
document.getElementById("form_message").innerHTML = "<span class='message_warning'>The admin email you've entered doesn't appear to be a valid email address.</span>";
return false;
}
submitForm();
}
function testDb(){
if(window.XMLHttpRequest){
xmlhttp=new XMLHttpRequest();
}
else{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if(xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("database_test").innerHTML=xmlhttp.responseText;
}
}
var h=escape(document.forms["install"]["db_host"].value);
var u=escape(document.forms["install"]["db_user"].value);
var p=escape(document.forms["install"]["db_pass"].value);
xmlhttp.open("GET", "dbtest.php?h="+h+"&u="+u+"&p="+p, true);
xmlhttp.send();
}
function matchPass(){
var x=document.forms["install"]["s_pass"].value;
var y=document.forms["install"]["s_pass2"].value;
if(x==y && x!=null && x!="" && y!=null && y!=""){
document.getElementById("pass_match").innerHTML = "<span class='message_success'>The passwords you've entered <b>match</b>.</span>";
}
else if(x==null || y==null || x=="" || y==""){
document.getElementById("pass_match").innerHTML = "";
}
else{
document.getElementById("pass_match").innerHTML = "<span class='message_warning'>The passwords you've entered <b>do not match</b>.</span>";
}
}
function checkEmail(){
var x=document.forms["install"]["s_email"].value;
var atpos=x.indexOf("@");
var dotpos=x.lastIndexOf(".");
if(x=="" || x==null){
document.getElementById("check_email").innerHTML = "";
}
else if(atpos<1 || dotpos<atpos+2 || dotpos+2>x.length){
document.getElementById("check_email").innerHTML = "<span class='message_warning'>That doesn't appear to be a valid email address.</span>";
}
else if(document.getElementById("check_email").innerHTML !=null && document.getElementById("check_email").innerHTML !=""){
document.getElementById("check_email").innerHTML = "";
}
}
function submitForm(){
if(window.XMLHttpRequest){
xmlhttp=new XMLHttpRequest();
}
else{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if(xmlhttp.readyState==4 && xmlhttp.status==200)
{
if(xmlhttp.responseText == "<span class=\"message_success\">Congratulations! You\'ve successfully installed DNP Script. You should remove the /install directory from your server now. After that I recommend you get started in the <a href=\"../admin/\">Admin Panel</a> to configure the site. Thanks for using DNP Script!</span>"){
var e = install.elements;
for(i=0;i<e.length;i++){
e[i].disabled = true;
}
document.getElementById("database_test").innerHTML="";
document.getElementById("submit_section").innerHTML="";
}
document.getElementById("form_message").innerHTML=xmlhttp.responseText;
document.getElementById("pass_match").innerHTML="";
}
}
xmlhttp.open("POST", "install.php", true);
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlhttp.send(queryString());
}
function queryString(){
var form = document.forms["install"];
var e = install.elements;
for(i=0;i<e.length;i++){
if (i==0){
var qstr = e[i].name+"="+encodeURIComponent(e[i].value);
}
else {
qstr = qstr+"&"+e[i].name+"="+encodeURIComponent(e[i].value);
}
}
return qstr;
}
</script>
</head>
<body>
<div id="content">
<hgroup>
<h1>Install DNP Script</h1>
<h2 id="tagline">Use this form to install DNP Script on your server. Fields marked with an asterisk (*) are required.</h2>
</hgroup>
<p id="form_message"> </p>
<form name="install" id="install">
<section>
<h1>Database Information</h1>
<p>Host Name:</p>
<p class="description">Enter the host name for your database.*</p>
<input type="text" name="db_host" required/><br />
<p>Username:</p>
<p class="description">Enter the username for your database.*</p>
<input type="text" name="db_user" required/><br />
<p>Password:</p>
<p class="description">Enter the password for your database.</p>
<input type="password" name="db_pass" /><br />
<p id="database_test"><a href="#" onClick="testDb()">Try to connect</a></p>
<p>Database Name:</p>
<p class="description">If you are on shared hosting you probably need to prefix
the database name with your MySQL username.<br /><br />e.g. user_dnpscript*</p>
<input type="text" name="db_name" required/><br />
</section>
<section>
<h1>Site Configuration</h1>
<p>Site Title:</p>
<p class="description">Enter the title of your site.*</p>
<input type="text" name="s_title" maxlength="25" required/><br />
<p>Description:</p>
<p class="description">Enter a brief description of your site.*</p>
<input type="text" name="s_description" maxlength="255" required/><br />
<p>Admin Password:</p>
<p class="description">Think of a password and enter it twice.*</p>
<input type="password" name="s_pass" maxlength="25" required/>
<input type="password" name="s_pass2" maxlength="25" onBlur="matchPass()" required/><br />
<p id="pass_match"></p>
<p>Admin Email:</p>
<p class="description">Enter a valid email address to receive communications about your domains.*</p>
<input type="email" name="s_email" maxlength="255" onblur="checkEmail()" required/><br />
<p id="check_email"></p>
<p>Google Analytics:</p>
<p class="description">Enter your Google Analytics ID. It should be in the form of<br /> UA-XXXXXXXX-X.</p>
<input type="text" name="s_analytics" maxlength="20" /><br />
</section>
<section id="submit_section">
<h1>Submit</h1>
<span id="input_install"><a href="#" id="submit_install" onclick="validateForm()">Install DNP Script</a></span>
</section>
</form>
</div>
</body>
</html>