2013-11-28 05:31:09 +00:00
< ? php
2014-02-18 21:59:07 +00:00
/**
* Shimmie Installer
2014-02-22 20:36:52 +00:00
*
2014-02-18 21:59:07 +00:00
* @ package Shimmie
2015-08-09 11:14:28 +00:00
* @ copyright Copyright ( c ) 2007 - 2015 , Shish et al .
2016-05-19 15:07:20 +00:00
* @ author Shish [ webmaster at shishnet . org ], jgen [ jeffgenovy at gmail . com ]
2014-02-18 22:01:35 +00:00
* @ link http :// code . shishnet . org / shimmie2 /
2014-02-18 21:59:07 +00:00
* @ license http :// opensource . org / licenses / gpl - 2.0 . php GNU General Public License v2
2014-02-23 00:44:50 +00:00
*
2015-08-09 11:14:28 +00:00
* Initialise the database , check that folder
* permissions are set properly .
*
2016-05-19 14:40:44 +00:00
* This file should be independent of the database
2015-08-09 11:14:28 +00:00
* and other such things that aren ' t ready yet
2014-02-18 21:59:07 +00:00
*/
2013-11-28 05:31:09 +00:00
// TODO: Rewrite the entire installer and make it more readable.
ob_start ();
2015-08-09 14:40:20 +00:00
date_default_timezone_set ( 'UTC' );
2013-11-28 05:31:09 +00:00
?>
2012-06-26 22:37:29 +00:00
<! DOCTYPE html >
< html >
2008-01-26 13:14:30 +00:00
< head >
2008-01-27 15:33:59 +00:00
< title > Shimmie Installation </ title >
2016-05-19 14:45:14 +00:00
< link rel = " shortcut icon " href = " data:image/x-icon;base64,AAABAAIAICAAAAEAIACoEAAAJgAAABAQAAABAAgAaAUAAM4QAAAoAAAAIAAAAEAAAAABACAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA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oL/AAAA/wAAAP8AAAAAAAAAAAAAAAAAAAAAAAAA/wAAAP+IiIj/iIiI/4iIiP+IiIj/h4eH/4eHh/+Hh4f/h4eH/4eHh/+Hh4f/hoaG/4aGhv+Ghob/hoaG/4aGhv+Ghob/hYWF/4WFhf8AAAD/AAAA/4WFhf+FhYX/hISE/4SEhP8AAAD/AAAA/wAAAAAAAAAAAAAAAAAAAAAAAAD/AAAA/4qKiv+Kior/ioqK/4qKiv+Kior/iYmJ/4mJif+JiYn/iYmJ/4mJif+IiIj/iIiI/4iIiP+IiIj/iIiI/4iIiP+Hh4f/h4eH/wAAAP8AAAD/h4eH/4eHh/+Ghob/hoaG/wAAAP8AAAD/AAAAAAAAAAAAAAAAAAAAAAAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP99fX3/iYmJ/4iIiP+IiIj/AAAA/wAAAP8AAAAAAAAAAAAAAAAA
2016-05-19 14:40:44 +00:00
< style >
#installer {
background : #EEE;
font - family : " Arial " , sans - serif ;
font - size : 14 px ;
width : 512 px ;
margin : auto ;
margin - top : 16 px ;
border : 1 px solid black ;
border - radius : 16 px ;
}
2016-05-19 15:29:55 +00:00
#installer > .container {
padding : 5 px ;
}
2016-05-19 14:40:44 +00:00
#installer A {
text - decoration : none ;
}
#installer A:hover {
text - decoration : underline ;
}
#installer H1, #installer H3 {
background : #DDD;
text - align : center ;
margin : 0 px ;
padding : 2 px ;
}
#installer H1 {
border - bottom : 1 px solid black ;
border - radius : 16 px 16 px 0 px 0 px ;
}
#installer H3 {
border - bottom : 1 px solid black ;
}
</ style >
2016-05-11 15:50:39 +00:00
< script type = " text/javascript " src = " lib/vendor/js/jquery-1.12.3.min.js " ></ script >
2008-01-26 13:14:30 +00:00
</ head >
< body >
2016-05-19 15:50:05 +00:00
< ? php if ( FALSE ) { ?>
2012-06-26 22:37:29 +00:00
< div id = " installer " >
2008-01-26 13:14:30 +00:00
< h1 > Install Error </ h1 >
2016-05-19 15:29:55 +00:00
< div class = " container " >
< p > Shimmie needs to be run via a web server with PHP support -- you
appear to be either opening the file from your hard disk , or your
web server is mis - configured and doesn ' t know how to handle PHP files .</ p >
< p > If you ' ve installed a web server on your desktop PC , you probably
want to visit < a href = " http://localhost/ " > the local web server </ a >.< br />< br />
</ p >
</ div >
2008-01-26 13:14:30 +00:00
</ div >
2016-05-19 15:50:05 +00:00
< pre style = " display:none " >
2016-05-19 16:11:03 +00:00
< ? php } elseif ( ! file_exists ( " vendor/ " )) { ?>
< div id = " installer " >
< h1 > Install Error </ h1 >
< h3 > Warning : Composer vendor folder does not exist !</ h3 >
< div class = " container " >
< p > Shimmie is unable to find the composer vendor directory .< br >
Have you followed the composer setup instructions found in the < a href = " https://github.com/shish/shimmie2#installation-development " > README </ a > ? </>
< p > If you are not intending to do any development with Shimmie , it is highly recommend you use one of the pre - packaged releases found on < a href = " https://github.com/shish/shimmie2/releases " > Github </ a > instead .</ p >
</ div >
</ div >
< pre style = " display:none " >
2008-01-26 13:14:30 +00:00
< ? php }
2008-01-27 15:33:59 +00:00
assert_options ( ASSERT_ACTIVE , 1 );
assert_options ( ASSERT_BAIL , 1 );
2012-02-09 20:33:40 +00:00
/*
2014-02-22 20:36:52 +00:00
* Compute the path to the folder containing " install.php " and
2012-02-09 20:33:40 +00:00
* store it as the 'Shimmie Root' folder for later on .
*
* Example :
* __SHIMMIE_ROOT__ = '/var/www/shimmie2/'
*
*/
2012-03-31 15:28:54 +00:00
define ( '__SHIMMIE_ROOT__' , trim ( remove_trailing_slash ( dirname ( __FILE__ ))) . '/' );
2012-02-09 20:33:40 +00:00
// Pull in necessary files
require_once __SHIMMIE_ROOT__ . " core/util.inc.php " ;
2012-03-09 18:03:10 +00:00
require_once __SHIMMIE_ROOT__ . " core/exceptions.class.php " ;
2012-02-09 20:33:40 +00:00
require_once __SHIMMIE_ROOT__ . " core/database.class.php " ;
2013-11-28 05:31:09 +00:00
if ( is_readable ( " data/config/shimmie.conf.php " )) die ( " Shimmie is already installed. " );
2007-04-16 11:58:25 +00:00
do_install ();
// utilities {{{
2013-11-28 05:31:09 +00:00
// TODO: Can some of these be pushed into "core/util.inc.php" ?
2012-02-05 21:35:34 +00:00
/**
* Strips off any kind of slash at the end so as to normalise the path .
* @ param string $path Path to normalise .
* @ return string Path without trailing slash .
*/
function remove_trailing_slash ( $path ) {
if (( substr ( $path , - 1 ) === '/' ) || ( substr ( $path , - 1 ) === '\\' )) {
return substr ( $path , 0 , - 1 );
} else {
return $path ;
}
}
2007-04-16 11:58:25 +00:00
function check_gd_version () {
$gdversion = 0 ;
if ( function_exists ( 'gd_info' )){
$gd_info = gd_info ();
if ( substr_count ( $gd_info [ 'GD Version' ], '2.' )) {
$gdversion = 2 ;
} else if ( substr_count ( $gd_info [ 'GD Version' ], '1.' )) {
$gdversion = 1 ;
}
}
return $gdversion ;
}
2008-01-27 15:33:59 +00:00
function check_im_version () {
if ( ! ini_get ( 'safe_mode' )) {
$convert_check = exec ( " convert " );
}
return ( empty ( $convert_check ) ? 0 : 1 );
}
2010-03-15 05:30:37 +00:00
function eok ( $name , $value ) {
echo " <br> $name ... " ;
if ( $value ) {
echo " <font color='green'>ok</font> \n " ;
}
else {
echo " <font color='red'>failed</font> \n " ;
}
}
2007-04-16 11:58:25 +00:00
// }}}
2013-11-28 05:31:09 +00:00
2008-01-27 16:25:17 +00:00
function do_install () { // {{{
2012-06-26 22:37:29 +00:00
if ( file_exists ( " data/config/auto_install.conf.php " )) {
require_once " data/config/auto_install.conf.php " ;
2009-01-22 13:02:22 +00:00
}
2012-06-26 22:37:29 +00:00
else if ( @ $_POST [ " database_type " ] == " sqlite " && isset ( $_POST [ " database_name " ])) {
define ( 'DATABASE_DSN' , " sqlite: { $_POST [ " database_name " ] } " );
}
else if ( isset ( $_POST [ 'database_type' ]) && isset ( $_POST [ 'database_host' ]) && isset ( $_POST [ 'database_user' ]) && isset ( $_POST [ 'database_name' ])) {
define ( 'DATABASE_DSN' , " { $_POST [ 'database_type' ] } :user= { $_POST [ 'database_user' ] } ;password= { $_POST [ 'database_password' ] } ;host= { $_POST [ 'database_host' ] } ;dbname= { $_POST [ 'database_name' ] } " );
2007-04-16 11:58:25 +00:00
}
2008-01-27 16:25:17 +00:00
else {
2012-06-26 22:37:29 +00:00
ask_questions ();
2015-08-09 11:14:28 +00:00
return ;
2008-01-27 16:25:17 +00:00
}
2015-08-09 11:14:28 +00:00
define ( " DATABASE_KA " , true );
install_process ();
2008-01-27 16:25:17 +00:00
} // }}}
2013-11-28 05:31:09 +00:00
2012-06-26 22:37:29 +00:00
function ask_questions () { // {{{
$warnings = array ();
$errors = array ();
2009-07-15 21:17:53 +00:00
2008-01-27 15:33:59 +00:00
if ( check_gd_version () == 0 && check_im_version () == 0 ) {
2012-06-26 22:37:29 +00:00
$errors [] = "
No thumbnailers cound be found - install the imagemagick
tools ( or the PHP - GD library , of imagemagick is unavailable ) .
2012-03-09 22:27:12 +00:00
" ;
2007-04-16 11:58:25 +00:00
}
2012-06-26 22:37:29 +00:00
else if ( check_im_version () == 0 ) {
$warnings [] = "
The 'convert' command ( from the imagemagick package )
could not be found - PHP - GD can be used instead , but
the size of thumbnails will be limited .
2012-03-09 22:27:12 +00:00
" ;
2009-07-15 21:17:53 +00:00
}
2012-06-26 22:51:05 +00:00
$drivers = PDO :: getAvailableDrivers ();
2012-06-26 22:37:29 +00:00
if (
2012-06-26 22:51:05 +00:00
! in_array ( " mysql " , $drivers ) &&
! in_array ( " pgsql " , $drivers ) &&
2013-11-28 05:31:09 +00:00
2012-06-26 22:51:05 +00:00
! in_array ( " sqlite " , $drivers )
2012-06-26 22:37:29 +00:00
) {
$errors [] = "
No database connection library could be found ; shimmie needs
2012-06-26 22:51:05 +00:00
PDO with either Postgres , MySQL , or SQLite drivers
2012-06-26 22:37:29 +00:00
" ;
2007-04-16 11:58:25 +00:00
}
2012-06-26 22:51:05 +00:00
$db_m = in_array ( " mysql " , $drivers ) ? '<option value="mysql">MySQL</option>' : " " ;
$db_p = in_array ( " pgsql " , $drivers ) ? '<option value="pgsql">PostgreSQL</option>' : " " ;
$db_s = in_array ( " sqlite " , $drivers ) ? '<option value="sqlite">SQLite</option>' : " " ;
2012-06-26 22:37:29 +00:00
$warn_msg = $warnings ? " <h3>Warnings</h3> " . implode ( " \n <br> " , $warnings ) : " " ;
$err_msg = $errors ? " <h3>Errors</h3> " . implode ( " \n <br> " , $errors ) : " " ;
2007-04-16 11:58:25 +00:00
print <<< EOD
2012-06-26 22:37:29 +00:00
< div id = " installer " >
2008-01-26 13:14:30 +00:00
< h1 > Shimmie Installer </ h1 >
2016-05-19 15:29:55 +00:00
< div class = " container " >
$warn_msg
$err_msg
< h3 > Database Install </ h3 >
< form action = " install.php " method = " POST " >
< center >
< table class = 'form' >
< tr >
< th > Type :</ th >
< td >< select name = " database_type " id = " database_type " onchange = " update_qs(); " >
$db_m
$db_p
$db_s
</ select ></ td >
</ tr >
< tr class = " dbconf mysql pgsql " >
< th > Host :</ th >
< td >< input type = " text " name = " database_host " size = " 40 " value = " localhost " ></ td >
</ tr >
< tr class = " dbconf mysql pgsql " >
< th > Username :</ th >
< td >< input type = " text " name = " database_user " size = " 40 " ></ td >
</ tr >
< tr class = " dbconf mysql pgsql " >
< th > Password :</ th >
< td >< input type = " password " name = " database_password " size = " 40 " ></ td >
</ tr >
< tr class = " dbconf mysql pgsql sqlite " >
< th > DB & nbsp ; Name :</ th >
< td >< input type = " text " name = " database_name " size = " 40 " value = " shimmie " ></ td >
</ tr >
< tr >< td colspan = " 2 " >< input type = " submit " value = " Go! " ></ td ></ tr >
</ table >
</ center >
< script >
$ ( function () {
update_qs ();
});
function update_qs () {
$ ( " .dbconf " ) . hide ();
var seldb = $ ( " #database_type " ) . val () || " none " ;
$ ( " . " + seldb ) . show ();
}
</ script >
</ form >
< h3 > Help </ h3 >
< p class = " dbconf mysql pgsql " >
Please make sure the database you have chosen exists and is empty .< br >
The username provided must have access to create tables within the database .
</ p >
< p class = " dbconf sqlite " >
For SQLite the database name will be a filename on disk , relative to
where shimmie was installed .
</ p >
< p class = " dbconf none " >
Drivers can generally be downloaded with your OS package manager ;
for Debian / Ubuntu you want php5 - pgsql , php5 - mysql , or php5 - sqlite .
</ p >
</ div >
2008-01-26 13:14:30 +00:00
</ div >
2007-04-16 11:58:25 +00:00
EOD ;
2008-01-27 16:25:17 +00:00
} // }}}
2013-11-28 05:31:09 +00:00
/**
* This is where the install really takes place .
*/
2011-02-22 03:06:55 +00:00
function install_process () { // {{{
2010-03-15 04:31:28 +00:00
build_dirs ();
2011-02-22 03:06:55 +00:00
create_tables ();
insert_defaults ();
write_config ();
2007-04-16 11:58:25 +00:00
} // }}}
2013-11-28 05:31:09 +00:00
2011-02-22 03:06:55 +00:00
function create_tables () { // {{{
try {
$db = new Database ();
2014-02-22 20:36:52 +00:00
2012-04-18 04:55:39 +00:00
if ( $db -> count_tables () > 0 ) {
2013-11-28 05:31:09 +00:00
print <<< EOD
< div id = " installer " >
< h1 > Shimmie Installer </ h1 >
2016-05-19 16:11:03 +00:00
< h3 > Warning : The Database schema is not empty !</ h3 >
2016-05-19 15:29:55 +00:00
< div class = " container " >
< p > Please ensure that the database you are installing Shimmie with is empty before continuing .</ p >
< p > Once you have emptied the database of any tables , please hit 'refresh' to continue .</ p >
< br />< br />
</ div >
2013-11-28 05:31:09 +00:00
</ div >
EOD ;
2015-08-09 14:40:20 +00:00
exit ( 2 );
2012-04-09 20:43:12 +00:00
}
2014-02-22 20:36:52 +00:00
2011-02-22 03:06:55 +00:00
$db -> create_table ( " aliases " , "
2014-02-23 03:04:14 +00:00
oldtag VARCHAR ( 128 ) NOT NULL ,
2009-01-22 12:05:55 +00:00
newtag VARCHAR ( 128 ) NOT NULL ,
2014-02-23 03:04:14 +00:00
PRIMARY KEY ( oldtag )
2011-02-22 03:06:55 +00:00
" );
2014-02-23 03:04:14 +00:00
$db -> execute ( " CREATE INDEX aliases_newtag_idx ON aliases(newtag) " , array ());
2016-05-19 15:29:55 +00:00
2011-02-22 03:06:55 +00:00
$db -> create_table ( " config " , "
2014-02-23 03:04:14 +00:00
name VARCHAR ( 128 ) NOT NULL ,
value TEXT ,
PRIMARY KEY ( name )
2011-02-22 03:06:55 +00:00
" );
$db -> create_table ( " users " , "
2009-01-22 13:03:51 +00:00
id SCORE_AIPK ,
2009-01-22 13:42:44 +00:00
name VARCHAR ( 32 ) UNIQUE NOT NULL ,
2014-05-23 23:28:57 +00:00
pass VARCHAR ( 250 ),
2009-07-15 22:29:14 +00:00
joindate SCORE_DATETIME NOT NULL DEFAULT SCORE_NOW ,
2012-02-21 18:37:36 +00:00
class VARCHAR ( 32 ) NOT NULL DEFAULT 'user' ,
2014-02-23 03:04:14 +00:00
email VARCHAR ( 128 )
2011-02-22 03:06:55 +00:00
" );
2014-02-23 03:04:14 +00:00
$db -> execute ( " CREATE INDEX users_name_idx ON users(name) " , array ());
2016-05-19 15:29:55 +00:00
2011-02-22 03:06:55 +00:00
$db -> create_table ( " images " , "
2009-01-22 12:05:55 +00:00
id SCORE_AIPK ,
2009-01-22 13:03:51 +00:00
owner_id INTEGER NOT NULL ,
2009-01-22 12:05:55 +00:00
owner_ip SCORE_INET NOT NULL ,
filename VARCHAR ( 64 ) NOT NULL ,
filesize INTEGER NOT NULL ,
2009-01-22 13:42:44 +00:00
hash CHAR ( 32 ) UNIQUE NOT NULL ,
2009-01-22 12:05:55 +00:00
ext CHAR ( 4 ) NOT NULL ,
source VARCHAR ( 255 ),
width INTEGER NOT NULL ,
height INTEGER NOT NULL ,
2009-07-15 22:29:14 +00:00
posted SCORE_DATETIME NOT NULL DEFAULT SCORE_NOW ,
2009-01-24 11:59:51 +00:00
locked SCORE_BOOL NOT NULL DEFAULT SCORE_BOOL_N ,
2012-03-11 01:52:25 +00:00
FOREIGN KEY ( owner_id ) REFERENCES users ( id ) ON DELETE RESTRICT
2011-02-22 03:06:55 +00:00
" );
2014-02-23 03:04:14 +00:00
$db -> execute ( " CREATE INDEX images_owner_id_idx ON images(owner_id) " , array ());
$db -> execute ( " CREATE INDEX images_width_idx ON images(width) " , array ());
$db -> execute ( " CREATE INDEX images_height_idx ON images(height) " , array ());
$db -> execute ( " CREATE INDEX images_hash_idx ON images(hash) " , array ());
2016-05-19 15:29:55 +00:00
2011-02-22 03:06:55 +00:00
$db -> create_table ( " tags " , "
2009-01-22 12:05:55 +00:00
id SCORE_AIPK ,
2009-01-22 13:42:44 +00:00
tag VARCHAR ( 64 ) UNIQUE NOT NULL ,
2014-02-23 03:06:33 +00:00
count INTEGER NOT NULL DEFAULT 0
2011-02-22 03:06:55 +00:00
" );
2014-02-23 03:04:14 +00:00
$db -> execute ( " CREATE INDEX tags_tag_idx ON tags(tag) " , array ());
2016-05-19 15:29:55 +00:00
2011-02-22 03:06:55 +00:00
$db -> create_table ( " image_tags " , "
2009-01-22 13:03:51 +00:00
image_id INTEGER NOT NULL ,
tag_id INTEGER NOT NULL ,
2009-01-22 13:42:44 +00:00
UNIQUE ( image_id , tag_id ),
2012-03-11 01:52:25 +00:00
FOREIGN KEY ( image_id ) REFERENCES images ( id ) ON DELETE CASCADE ,
FOREIGN KEY ( tag_id ) REFERENCES tags ( id ) ON DELETE CASCADE
2011-02-22 03:06:55 +00:00
" );
2014-02-23 03:04:14 +00:00
$db -> execute ( " CREATE INDEX images_tags_image_id_idx ON image_tags(image_id) " , array ());
$db -> execute ( " CREATE INDEX images_tags_tag_id_idx ON image_tags(tag_id) " , array ());
2016-05-19 15:29:55 +00:00
2012-02-22 13:58:55 +00:00
$db -> execute ( " INSERT INTO config(name, value) VALUES('db_version', 11) " );
2012-06-26 23:08:51 +00:00
$db -> commit ();
2007-04-16 11:58:25 +00:00
}
2015-08-09 14:40:20 +00:00
catch ( PDOException $e ) {
2016-05-19 15:29:55 +00:00
handle_db_errors ( TRUE , " An error occurred while trying to create the database tables necessary for Shimmie. " , $e -> getMessage (), 3 );
} catch ( Exception $e ) {
handle_db_errors ( FALSE , " An unknown error occurred while trying to insert data into the database. " , $e -> getMessage (), 4 );
2008-01-27 16:25:17 +00:00
}
2011-02-22 03:06:55 +00:00
} // }}}
2013-11-28 05:31:09 +00:00
2011-02-22 03:06:55 +00:00
function insert_defaults () { // {{{
try {
$db = new Database ();
2014-02-22 20:36:52 +00:00
2012-02-21 18:37:36 +00:00
$db -> execute ( " INSERT INTO users(name, pass, joindate, class) VALUES(:name, :pass, now(), :class) " , Array ( " name " => 'Anonymous' , " pass " => null , " class " => 'anonymous' ));
2012-03-08 02:55:04 +00:00
$db -> execute ( " INSERT INTO config(name, value) VALUES(:name, :value) " , Array ( " name " => 'anon_id' , " value " => $db -> get_last_insert_id ( 'users_id_seq' )));
2008-01-27 16:25:17 +00:00
if ( check_im_version () > 0 ) {
2011-02-22 03:06:55 +00:00
$db -> execute ( " INSERT INTO config(name, value) VALUES(:name, :value) " , Array ( " name " => 'thumb_engine' , " value " => 'convert' ));
2008-01-27 16:25:17 +00:00
}
2012-06-26 23:08:51 +00:00
$db -> commit ();
2011-02-22 03:06:55 +00:00
}
2016-05-19 15:29:55 +00:00
catch ( PDOException $e ) {
handle_db_errors ( TRUE , " An error occurred while trying to insert data into the database. " , $e -> getMessage (), 5 );
2013-11-28 05:31:09 +00:00
}
2016-05-19 15:29:55 +00:00
catch ( Exception $e ) {
handle_db_errors ( FALSE , " An unknown error occurred while trying to insert data into the database. " , $e -> getMessage (), 6 );
2008-01-27 16:25:17 +00:00
}
} // }}}
2013-11-28 05:31:09 +00:00
2007-04-16 11:58:25 +00:00
function build_dirs () { // {{{
2010-03-15 04:31:28 +00:00
// *try* and make default dirs. Ignore any errors --
// if something is amiss, we'll tell the user later
if ( ! file_exists ( " images " )) @ mkdir ( " images " );
if ( ! file_exists ( " thumbs " )) @ mkdir ( " thumbs " );
if ( ! file_exists ( " data " ) ) @ mkdir ( " data " );
if ( ! is_writable ( " images " )) @ chmod ( " images " , 0755 );
if ( ! is_writable ( " thumbs " )) @ chmod ( " thumbs " , 0755 );
if ( ! is_writable ( " data " ) ) @ chmod ( " data " , 0755 );
2007-04-16 11:58:25 +00:00
2014-02-19 03:21:14 +00:00
// Clear file status cache before checking again.
clearstatcache ();
2014-02-22 20:36:52 +00:00
2007-04-16 11:58:25 +00:00
if (
2012-03-09 22:27:12 +00:00
! file_exists ( " images " ) || ! file_exists ( " thumbs " ) || ! file_exists ( " data " ) ||
! is_writable ( " images " ) || ! is_writable ( " thumbs " ) || ! is_writable ( " data " )
2007-04-16 11:58:25 +00:00
) {
2012-03-09 22:27:12 +00:00
print "
2013-11-28 05:31:09 +00:00
< div id = 'installer' >
< h1 > Shimmie Installer </ h1 >
< h3 > Directory Permissions Error :</ h3 >
2016-05-19 16:11:03 +00:00
< div class = 'container' >
< p > Shimmie needs to make three folders in it 's directory, ' < i > images </ i > ', ' < i > thumbs </ i > ', and ' < i > data </ i > ' , and they need to be writable by the PHP user .</ p >
< p > If you see this error , if probably means the folders are owned by you , and they need to be writable by the web server .</ p >
< p > PHP reports that it is currently running as user : " . $_ENV["USER"] . " ( " . $_SERVER["USER"] . " ) </ p >
< p > Once you have created these folders and / or changed the ownership of the shimmie folder , hit 'refresh' to continue .</ p >
< br />< br />
</ div >
2013-11-28 05:31:09 +00:00
</ div >
2012-03-09 22:27:12 +00:00
" ;
2015-08-09 14:40:20 +00:00
exit ( 7 );
2007-04-16 11:58:25 +00:00
}
} // }}}
2013-11-28 05:31:09 +00:00
2011-02-22 03:06:55 +00:00
function write_config () { // {{{
2012-01-31 05:35:20 +00:00
$file_content = '<' . '?php' . " \n " .
2012-02-13 21:09:34 +00:00
" define('DATABASE_DSN', ' " . DATABASE_DSN . " '); \n " .
2012-01-31 05:35:20 +00:00
'?' . '>' ;
2014-02-22 20:36:52 +00:00
2012-03-30 17:03:55 +00:00
if ( ! file_exists ( " data/config " )) {
mkdir ( " data/config " , 0755 , true );
2007-04-16 11:58:25 +00:00
}
2014-02-22 20:36:52 +00:00
2015-08-09 11:14:28 +00:00
if ( file_put_contents ( " data/config/shimmie.conf.php " , $file_content , LOCK_EX )) {
header ( " Location: index.php " );
print <<< EOD
< div id = " installer " >
< h1 > Shimmie Installer </ h1 >
< h3 > Things are OK \o /</ h3 >
2016-05-19 16:11:03 +00:00
< div class = " container " >
< p > If you aren ' t redirected , < a href = " index.php " > click here to Continue </ a >.
</ div >
2015-08-09 11:14:28 +00:00
</ div >
EOD ;
}
else {
2014-02-19 04:26:42 +00:00
$h_file_content = htmlentities ( $file_content );
2007-04-16 11:58:25 +00:00
print <<< EOD
2013-11-28 05:31:09 +00:00
< div id = " installer " >
< h1 > Shimmie Installer </ h1 >
< h3 > File Permissions Error :</ h3 >
2016-05-19 16:11:03 +00:00
< div class = " container " >
The web server isn ' t allowed to write to the config file ; please copy
the text below , save it as 'data/config/shimmie.conf.php' , and upload it into the shimmie
folder manually . Make sure that when you save it , there is no whitespace
before the " <?php " or after the " ?> "
< p >< textarea cols = " 80 " rows = " 2 " > $h_file_content </ textarea >
< p > Once done , < a href = " index.php " > click here to Continue </ a >.
< br />< br />
</ div >
2013-11-28 05:31:09 +00:00
</ div >
2007-04-16 11:58:25 +00:00
EOD ;
}
2015-08-09 11:14:28 +00:00
echo " \n " ;
2007-04-16 11:58:25 +00:00
} // }}}
2016-05-19 15:29:55 +00:00
function handle_db_errors ( /*bool*/ $isPDO , /*str*/ $errorMessage1 , /*str*/ $errorMessage2 , /*int*/ $exitCode ) {
$errorMessage1Extra = ( $isPDO ? " Please check and ensure that the database configuration options are all correct. " : " Please check the server log files for more information. " );
print <<< EOD
< div id = " installer " >
< h1 > Shimmie Installer </ h1 >
2016-05-19 16:11:03 +00:00
< h3 > Unknown Error :</ h3 >
2016-05-19 15:29:55 +00:00
< div class = " container " >
< p > { $errorMessage1 } </ p >
< p > { $errorMessage1Extra } </ p >
< p > { $errorMessage2 } </ p >
</ div >
</ div >
EOD ;
exit ( $exitCode );
}
2007-04-16 11:58:25 +00:00
?>
2008-01-27 15:33:59 +00:00
</ body >
</ html >