2014-02-17 21:30:36 +01:00
<! DOCTYPE html >
2014-06-21 15:27:18 +02:00
<!--
2014-11-08 14:36:19 +01:00
# Copyright (C) 2013-2014 Chaoyi Zha
# Polr is an open-source project licensed under the GPL.
# The above copyright notice and the following license are applicable to
# the entire project, unless explicitly defined otherwise.
# http://github.com/cydrobolt/polr
# This program 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 (at
# your option) any later version.
# See http://www.gnu.org/copyleft/gpl.html for the full text of the
# license.
#
2014-06-21 15:27:18 +02:00
-->
2014-02-17 21:30:36 +01:00
< html >
< head >
< meta charset = " UTF-8 " >
< title > Polr Setup </ title >
2014-11-08 14:36:19 +01:00
< link rel = " stylesheet " href = " install-bootstrap.css " />
2014-06-21 15:27:18 +02:00
< link rel = " stylesheet " href = " main.css " />
2014-02-17 21:30:36 +01:00
</ head >
2014-06-21 15:27:18 +02:00
< body style = " padding-top:60px " >
< div class = " navbar navbar-default navbar-fixed-top " >
2014-11-08 23:22:53 +01:00
< a class = " navbar-brand " href = " index.php " > Polr </ a >
2014-06-21 15:27:18 +02:00
</ div >
< div class = 'container-fluid push pushtop' style = " text-align: left " >
2014-11-08 14:36:19 +01:00
< span >< h1 style = " text-align:center " > Polr Setup </ h1 ></ span >< br >
2014-06-21 15:27:18 +02:00
< ? php
@ ( include ( 'config.php' ));
include ( 'version.php' );
require_once 'password.php' ;
2014-11-08 22:13:25 +01:00
date_default_timezone_set ( 'UTC' );
2014-06-21 15:27:18 +02:00
function rstr ( $length = 34 ) {
return substr ( str_shuffle ( " 0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ " ), 0 , $length );
2014-02-17 21:30:36 +01:00
}
2014-06-21 15:27:18 +02:00
if ( isset ( $ppass )) {
if ( ! isset ( $_POST [ 'pw' ])) {
require_once 'header.php' ;
echo " <h2>Enter setup password to proceed:</h2> " ;
echo " <form action='setup.php' method='post'><br><input class='form-control' type='password' name='pw' /><br><input type='submit' class='form-control' value='Log in' /></form> " ;
require_once 'footer.php' ;
die ();
} else if ( $pwf = password_verify ( $_POST [ 'pw' ], $ppass )) {
echo " " ;
} else {
require_once 'header.php' ;
echo " Wrong password<br> " ;
echo " <h2>Enter setup password to proceed:</h2> " ;
echo " <form action='setup.php' method='post'><br><input type='password' class='form-control' name='pw' /><br><input type='submit' class='form-control' value='Log in' /></form> " ;
require_once 'footer.php' ;
die ();
}
2014-02-17 21:30:36 +01:00
}
2014-06-21 15:27:18 +02:00
if ( isset ( $_POST [ 'dbserver' ])) {
$rstr = rstr ( 50 );
function hashpass ( $pass , $salt = " " ) {
if ( ! $salt ) {
$salt = rstr ( 60 );
}
2014-08-09 23:48:47 +02:00
$opts = array (
2014-06-21 15:27:18 +02:00
'cost' => 10 ,
'salt' => $salt
2014-08-09 23:48:47 +02:00
);
2014-06-21 15:27:18 +02:00
$hashed = password_hash ( $pass , PASSWORD_BCRYPT , $opts );
return $hashed ;
}
$nowdate = date ( 'F d Y' );
$data = ' < ? php
$host = " ' . $_POST['dbserver'] . ' " ; ' .
'$user="' . $_POST [ 'dbuser' ] . '";' .
'$passwd="' . $_POST [ 'dbpass' ] . '";' .
'$db="' . $_POST [ 'dbname' ] . '";' .
'$wsa = "' . $_POST [ 'appurl' ] . '";' .
'$wsn = "' . $_POST [ 'appname' ] . '";' .
'$wsb = "' . $nowdate . '";' .
'$ppass = \'' . hashpass ( $_POST [ 'protpass' ]) . '\';' .
'$ip = $_SERVER[\'REMOTE_ADDR\'];'
. '$hp = "' . sha1 ( rstr ( 30 )) . " \" ; "
2014-06-22 00:57:08 +02:00
. '$regtype = "' . $_POST [ 'reg' ] . " \" ; "
2014-06-21 15:27:18 +02:00
. '$path = "' . $_POST [ 'path' ] . " \" ; "
2014-11-08 21:27:14 +01:00
. '$fpass = ' . $_POST [ 'fpass' ] . " ; "
2014-06-21 15:27:18 +02:00
. '$theme = "' . $_POST [ 't' ] . " \" ; "
. '$ip = ' . $_POST [ 'ipfetch' ] . " ; " .
'$unstr = "' . $rstr . ' " ;
2014-02-17 21:30:36 +01:00
?> ';
2014-06-21 15:27:18 +02:00
$file = " config.php " ;
2014-02-17 21:30:36 +01:00
2014-06-21 15:27:18 +02:00
$handle = fopen ( $file , 'a' );
if ( fwrite ( $handle , $data ) === FALSE ) {
echo " Can not write to ( " . $file . " ) " ;
}
echo " Succesfully created config. " ;
fclose ( $handle );
2014-02-17 21:30:36 +01:00
require_once ( 'req.php' );
2014-06-21 15:27:18 +02:00
$path = $_POST [ 'path' ];
if ( strlen ( $path ) > 2 ) {
$data = " <IfModule mod_rewrite.c>
RewriteEngine On
2014-11-08 21:11:03 +01:00
RewriteRule ^ api $ / api . php [ L ]
RewriteRule ^ api / $ / api . php [ L ]
2014-06-21 15:27:18 +02:00
RewriteCond % { REQUEST_FILENAME } !- f
RewriteCond % { REQUEST_FILENAME } !- d
2014-11-08 21:11:03 +01:00
RewriteRule ^ ([ a - zA - Z0 - 9 ] + ) \ ? ([ a - zA - Z0 - 9 ] + ) $ / r . php ? u = $ 1 & lkey = $ 2 [ L , QSA ]
RewriteRule ^ ([ a - zA - Z0 - 9 ] + ) / ? $ / r . php ? u = $ 1 [ L , QSA ]
RewriteRule ^ t - ([ a - zA - Z0 - 9 ] + ) / ? $ / r . php ? u = t - $ 1 [ L , QSA ]
RewriteRule ^/ ? \ + ([ a - zA - Z0 - 9 ] + ) $ / stats . php ? bv = $ 1 [ L , QSA ]
2014-06-21 15:27:18 +02:00
</ IfModule >
" ;
$handle = fopen ( '.htaccess' , 'w' );
if ( fwrite ( $handle , $data ) === FALSE ) {
echo " Can not write to ( " . $file . " ) " ;
}
echo " Succesfully created htaccess (custom path) <br />. " ;
fclose ( $handle );
}
sqlrun ( '
CREATE TABLE `api` (
`valid` tinyint ( 1 ) NOT NULL ,
`email` varchar ( 50 ) NOT NULL ,
`apikey` varchar ( 70 ) NOT NULL ,
`quota` int ( 11 ) NOT NULL ,
PRIMARY KEY ( `apikey` ),
UNIQUE KEY `email` ( `email` ),
KEY `email_2` ( `email` ),
KEY `valid` ( `valid` ),
KEY `aindex` ( `valid` , `email` )
); ' );
2014-11-08 14:36:19 +01:00
sqlrun ( '
2014-06-21 15:27:18 +02:00
CREATE TABLE `auth` (
`username` varchar ( 50 ) NOT NULL ,
`password` text NOT NULL ,
`email` varchar ( 65 ) NOT NULL ,
`rkey` varchar ( 65 ) NOT NULL ,
`role` varchar ( 37 ) NOT NULL ,
`valid` tinyint ( 1 ) NOT NULL DEFAULT " 0 " ,
`uid` int ( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`theme` varchar ( 65 ) NOT NULL ,
`ip` tinytext NOT NULL ,
KEY `valid` ( `valid` ),
KEY `email3` ( `email` ),
KEY `username2` ( `username` )
); ' );
sqlrun ( '
CREATE TABLE `redirinfo` (
`rurl` varchar ( 80 ) NOT NULL ,
`rid` smallint ( 200 ) NOT NULL AUTO_INCREMENT ,
`baseval` varchar ( 30 ) NOT NULL ,
`ip` varchar ( 90 ) NOT NULL ,
`iscustom` varchar ( 4 ) NOT NULL ,
`user` tinytext NOT NULL ,
`date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ,
2014-11-08 16:10:31 +01:00
`country` varchar ( 10 ) NOT NULL ,
`lkey` tinytext NOT NULL ,
2014-06-21 15:27:18 +02:00
`clicks` int ( 11 ) NOT NULL ,
`pw` int ( 120 ) NOT NULL ,
`etc` text ,
`etc2` text ,
PRIMARY KEY ( `rid` ),
KEY `rurl` ( `rurl` ),
KEY `baseval` ( `baseval` ),
KEY `baseval_2` ( `baseval` ),
KEY `rurl_2` ( `rurl` ),
KEY `ip` ( `ip` ),
KEY `iscustom` ( `iscustom` ),
KEY `rurl_3` ( `rurl` , `rid` , `baseval` , `ip` , `iscustom` )
); ' );
sqlrun ( '
CREATE TABLE `redirinfo-temp` (
`rurl` varchar ( 80 ) NOT NULL ,
`rid` smallint ( 200 ) NOT NULL AUTO_INCREMENT ,
`baseval` varchar ( 30 ) NOT NULL ,
`ip` varchar ( 90 ) NOT NULL ,
`iscustom` varchar ( 4 ) NOT NULL ,
`user` tinytext NOT NULL ,
`date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ,
`country` tinytext NOT NULL ,
`theme` varchar ( 65 ) NOT NULL ,
`clicks` int ( 11 ) NOT NULL ,
`pw` int ( 120 ) NOT NULL ,
`etc` text ,
`etc2` text ,
PRIMARY KEY ( `rid` ),
KEY `rurl` ( `rurl` ),
KEY `baseval` ( `baseval` ),
KEY `baseval_2` ( `baseval` ),
KEY `rurl_2` ( `rurl` ),
KEY `ip` ( `ip` ),
KEY `iscustom` ( `iscustom` ),
KEY `rurl_3` ( `rurl` , `rid` , `baseval` , `ip` , `iscustom` )
); ' );
$acctpass = hashpass ( $_POST [ 'acctpass' ]);
$nr = sha1 ( rstr ( 50 ));
sqlrun ( " INSERT INTO auth (username,email,password,rkey,valid,role) VALUES (' { $_POST [ 'acct' ] } ','polr@admin.none',' { $acctpass } ',' { $nr } ','1','adm') " );
echo " You are now finished Polr Setup. You can now close this window, and login to your account <a href='index.php'>here</a> (login form @ top right). <br><br>If you need help, click <a href= \" http://webchat.freenode.net/?channels=#polr \" >here</a><br> "
. " <br><br><b>Clueless? Read the docs. <a href='https://github.com/Cydrobolt/polr/wiki'>https://github.com/Cydrobolt/polr/wiki</a></b> " ;
} else {
include ( 'version.php' );
2014-11-08 14:36:19 +01:00
echo " <form name= \" Config Creation \" style='margin:0 auto; width: 650px' method= \" post \" action= \" " . 'setup.php' . " \" > " ;
echo " Database Host: <input type= \" text \" class='form-control' style='width:650px' name= \" dbserver \" value= \" localhost \" ><br> " ;
echo " Database User: <input type= \" text \" class='form-control' style='width:650px' name= \" dbuser \" value= \" root \" ><br> " ;
echo " Database Pass: <input type= \" password \" class='form-control' style='width:650px' name= \" dbpass \" value= \" password \" ><br> " ;
echo " Database Name: <input type= \" text \" class='form-control' style='width:650px' name= \" dbname \" value= \" polr \" ><br> " ;
echo " Application Name: <input type= \" text \" class='form-control' style='width:650px' name= \" appname \" value= \" polr \" ><br> " ;
echo " Application URL (path to Polr, no http:// or www.) : <input type= \" text \" style='width:650px' class='form-control' name= \" appurl \" value= \" yoursite.com \" ><br> " ;
echo " Setup Access Password: <input type= \" text \" class='form-control' style='width:650px' name= \" protpass \" value= \" password123 \" ><br> " ;
echo " Admin Account: <input type= \" text \" class='form-control' style='width:650px' style='width:650px' name= \" acct \" value= \" polr \" ><br> " ;
echo " Admin Password: <input type= \" password \" style='width:650px' class='form-control' name= \" acctpass \" value= \" polr \" ><br> " ;
echo " Fetch ip through variable: <input type= \" text \" class='form-control' style='width:650px' name= \" ipfetch \" value= \" \$ _SERVER['REMOTE_ADDR'] \" ><br> " ;
echo " Registration: <select name='reg' style='width:650px' class='form-control'> "
2014-06-21 15:27:18 +02:00
. " <option value='none'>No registration</option> "
. " <option value='email'>Email verification required</option> "
. " <option value='free'>No email verification required</option> "
. " <option value='regulated'>New registrations must be approved (do not choose, future option)</option> "
. " </select><br /><br /> " ;
2014-11-08 21:27:14 +01:00
echo " Password Recovery (requires mail server): <select name='fpass' style='width:650px' class='form-control'> "
. " <option value='false'>No (default)</option> "
. " <option value='true'>Yes (could cause problems unless sgmail.php is properly set up)</option> "
. " </select><br /><br /> " ;
2014-11-08 14:36:19 +01:00
echo " Path relative to root (leave blank if /, if http://site.com/polr, then write /polr/): <input type= \" text \" class='form-control' style='width:650px' name= \" path \" value= \" /polr/ \" ><br> " ;
echo " Theme (choose wisely, click <a href='https://github.com/Cydrobolt/polr/wiki/Themes-Screenshots'>here</a> for screenshots: <select name='t' style='width:650px' class='form-control'> "
2014-11-08 23:22:53 +01:00
. " <option value=''>Modern (default)</option> "
2014-11-08 14:36:19 +01:00
. " <option value='//maxcdn.bootstrapcdn.com/bootswatch/3.3.0/cyborg/bootstrap.min.css'>Midnight Black</option> "
. " <option value='//maxcdn.bootstrapcdn.com/bootswatch/3.3.0/amelia/bootstrap.min.css'>Cheery</option> "
. " <option value='//maxcdn.bootstrapcdn.com/bootswatch/3.3.0/united/bootstrap.min.css'>Orange</option> "
. " <option value='//maxcdn.bootstrapcdn.com/bootswatch/3.3.0/simplex/bootstrap.min.css'>Crisp White</option> "
. " <option value='//maxcdn.bootstrapcdn.com/bootswatch/3.3.0/darkly/bootstrap.min.css'>Cloudy Night</option> "
. " <option value='//maxcdn.bootstrapcdn.com/bootswatch/3.3.0/cerulean/bootstrap.min.css'>Calm Skies</option> "
. " <option value='//maxcdn.bootstrapcdn.com/bootswatch/3.3.0/paper/bootstrap.min.css'>Android Material Design</option> "
. " <option value='//maxcdn.bootstrapcdn.com/bootswatch/3.3.0/superhero/bootstrap.min.css'>Blue Metro</option> "
. " <option value='//maxcdn.bootstrapcdn.com/bootswatch/3.3.0/sandstone/bootstrap.min.css'>Sandstone</option> "
. " <option value='//maxcdn.bootstrapcdn.com/bootswatch/3.3.0/cyborg/bootstrap.min.css'>Jet Black</option> "
. " <option value='//maxcdn.bootstrapcdn.com/bootswatch/3.3.0/lumen/bootstrap.min.css'>Newspaper</option> "
2014-06-21 15:27:18 +02:00
. " </select><br /><br /> " ;
if ( isset ( $_POST [ 'pw' ])) {
2014-02-17 21:30:36 +01:00
echo " <input type='hidden' value=' { $_POST [ 'pw' ] } ' name='pw' /> " ;
}
2014-11-08 14:36:19 +01:00
echo " <div id='buttons' style='text-align:center'> " ;
if ( isset ( $ppass )) {
echo " <input type= \" submit \" class= \" btn btn-success \" style='width:150px' value= \" Update \" > " ;
} else {
echo " <input type= \" submit \" class= \" btn btn-success \" style='width:150px' value= \" Install \" > " ;
}
echo " " ;
echo " <input type= \" reset \" value= \" Clear Fields \" class= \" btn btn-warning \" style='width:150px'> " ;
echo " </div> " ;
2014-06-21 15:27:18 +02:00
echo " </form> " ;
2014-11-08 14:36:19 +01:00
echo " <br><br></div><div class='container' style='text-align:center'> "
. " <p><b>Please read the README.md file located in the root Polr directory. It contains essential and indispensable troubleshooting, installation, and support materials. <b/></p> " ;
echo " <br><br>Polr is <a href='http://en.wikipedia.org/wiki/Open-source_software'>Open-Source software</a> licensed under the <a href='//www.gnu.org/copyleft/gpl.html'>GPL License</a>. By continuing to use Polr, you agree to the terms of the MIT License. " ;
echo " <div class=''>Polr Version $version released $reldate - <a href='//github.com/cydrobolt/polr'>Github</a></div></div><br><span style='padding-left:4%'>© Copyright $relyear Chaoyi Zha & <a href='https://github.com/Cydrobolt/polr/graphs/contributors'>Other Polr Contributors</a></span> " ;
2014-06-21 15:27:18 +02:00
}
?>
</ div >
2014-02-17 21:30:36 +01:00
</ body >
2014-08-09 23:48:47 +02:00
</ html >