| 1 | <?php |
|---|
| 2 | /* -- setup.php for Jlog |
|---|
| 3 | -- Please delete this file if you have done the setup |
|---|
| 4 | */ |
|---|
| 5 | |
|---|
| 6 | // derzeit gibt es noch etliche E_NOTICE-Meldungen in JLog, deshalb: |
|---|
| 7 | error_reporting(E_ALL ^ E_NOTICE); |
|---|
| 8 | |
|---|
| 9 | define("JLOG_NEW_VERSION", '1.0.2'); |
|---|
| 10 | define("JLOG_SETUP", true); |
|---|
| 11 | define("JLOG_PHPV", "4.1.1"); |
|---|
| 12 | define("JLOG_MYSQLV", "4.0.0"); |
|---|
| 13 | $basepath = dirname( __FILE__ ).DIRECTORY_SEPARATOR; |
|---|
| 14 | |
|---|
| 15 | // defining to avoid notifications |
|---|
| 16 | define("JLOG_WEBSITE", $_SERVER["HTTP_HOST"]); |
|---|
| 17 | define("JLOG_PATH", dirname("http://".$_SERVER["HTTP_HOST"].$_SERVER["PHP_SELF"])); |
|---|
| 18 | |
|---|
| 19 | require('.'.DIRECTORY_SEPARATOR.'lang'.DIRECTORY_SEPARATOR.'lang.inc.php'); |
|---|
| 20 | require('.'.DIRECTORY_SEPARATOR.'lang'.DIRECTORY_SEPARATOR.'lang-admin.inc.php'); |
|---|
| 21 | require('.'.DIRECTORY_SEPARATOR.'scripts'.DIRECTORY_SEPARATOR.'database.class.php'); |
|---|
| 22 | require('.'.DIRECTORY_SEPARATOR.'scripts'.DIRECTORY_SEPARATOR.'general.func.php'); |
|---|
| 23 | require('.'.DIRECTORY_SEPARATOR.'scripts'.DIRECTORY_SEPARATOR.'settings.class.php'); |
|---|
| 24 | require('.'.DIRECTORY_SEPARATOR.'scripts'.DIRECTORY_SEPARATOR.'url_syntax.php'); |
|---|
| 25 | $errors = array(); |
|---|
| 26 | |
|---|
| 27 | $l['admin']['submit'] = $l['admin']['s_install']; |
|---|
| 28 | $setup = new Settings($l); |
|---|
| 29 | |
|---|
| 30 | if($_POST) { |
|---|
| 31 | $setup->get_userdata(strip($_POST)); |
|---|
| 32 | |
|---|
| 33 | // validate user entry |
|---|
| 34 | if(count($errors = $setup->validate()) == 0) { |
|---|
| 35 | define("JLOG_BASEPATH", $setup->put_data('basepath')); |
|---|
| 36 | if(is_writable(JLOG_BASEPATH.'personal'.DIRECTORY_SEPARATOR)) { |
|---|
| 37 | $c .= "<ul>\n"; |
|---|
| 38 | |
|---|
| 39 | // build some MySQL tables |
|---|
| 40 | if(count($errors = create_mysql_tables($setup->put_data(false))) == 0) { |
|---|
| 41 | $c .= "<li>".$l['admin']['s_tables_ok']."</li>\n"; |
|---|
| 42 | |
|---|
| 43 | // create and chmod on some directories and files |
|---|
| 44 | if(count($errors = do_personal()) == 0) { |
|---|
| 45 | $c .= "<li>".$l['admin']['s_personal_ok']."</li>\n"; |
|---|
| 46 | |
|---|
| 47 | // build settings.php |
|---|
| 48 | if(count($errors = $setup->do_settings()) == 0) $c .= "<li>".$l['admin']['master_ok']."</li>\n"; |
|---|
| 49 | } |
|---|
| 50 | $c .= "</ul>"; |
|---|
| 51 | } |
|---|
| 52 | } |
|---|
| 53 | else { |
|---|
| 54 | $errors[] = $l['admin']['s_personal_not_wrtbl']; |
|---|
| 55 | } |
|---|
| 56 | } |
|---|
| 57 | if(count($errors) > 0) { |
|---|
| 58 | $c .= error_output($errors); |
|---|
| 59 | $c .= $setup->form_output(); |
|---|
| 60 | } |
|---|
| 61 | else $c .= "<h2>".$l['admin']['s_ready_head']."</h2>"."<p style='text-align: left;'>".$l['admin']['s_ready']."</p>"; |
|---|
| 62 | } |
|---|
| 63 | else { |
|---|
| 64 | // validate PHP and MySQL versions |
|---|
| 65 | if(!version_compare(phpversion(), JLOG_PHPV, ">=") == 1) $errors[] = $l['admin']['s_phpv_tolow']; |
|---|
| 66 | if(!is_writable($basepath.'personal'.DIRECTORY_SEPARATOR)) $errors[] = $l['admin']['s_personal_not_wrtbl']; |
|---|
| 67 | if(!is_writable($basepath.'img'.DIRECTORY_SEPARATOR)) $errors[] = $l['admin']['s_img_not_wrtbl']; |
|---|
| 68 | |
|---|
| 69 | if(empty($errors)) { |
|---|
| 70 | // output form |
|---|
| 71 | $setup->get_sugestiondata(); |
|---|
| 72 | $c .= $setup->form_output(); |
|---|
| 73 | } |
|---|
| 74 | else $c .= error_output($errors); |
|---|
| 75 | } |
|---|
| 76 | |
|---|
| 77 | echo do_htmlpage($c); |
|---|
| 78 | |
|---|
| 79 | |
|---|
| 80 | |
|---|
| 81 | |
|---|
| 82 | |
|---|
| 83 | #### some needed functions for the setup #### |
|---|
| 84 | |
|---|
| 85 | function create_mysql_tables($data) { |
|---|
| 86 | # returns false if all tables were created, if not returns the $errors array |
|---|
| 87 | |
|---|
| 88 | $sql['content'] = ' |
|---|
| 89 | CREATE TABLE `'.$data['jlog_db_prefix'].'content` ( |
|---|
| 90 | id int(11) auto_increment, |
|---|
| 91 | url varchar(200), |
|---|
| 92 | topic varchar(255), |
|---|
| 93 | date datetime, |
|---|
| 94 | teaser mediumtext, |
|---|
| 95 | teaserpic varchar(10), |
|---|
| 96 | teaserpiconblog tinyint(1), |
|---|
| 97 | keywords varchar(255), |
|---|
| 98 | content longtext, |
|---|
| 99 | comments tinyint(1) default \'1\', |
|---|
| 100 | allowpingback tinyint(1) default \'1\', |
|---|
| 101 | section varchar(10) default \'weblog\', |
|---|
| 102 | UNIQUE KEY id (id), |
|---|
| 103 | FULLTEXT KEY content_index (content, topic, teaser, keywords) |
|---|
| 104 | ) TYPE=MyISAM;'; |
|---|
| 105 | |
|---|
| 106 | $sql['comments'] = ' |
|---|
| 107 | CREATE TABLE `'.$data["jlog_db_prefix"].'comments` ( |
|---|
| 108 | id int(11) auto_increment, |
|---|
| 109 | sid varchar(35), |
|---|
| 110 | name varchar(255), |
|---|
| 111 | city varchar(255), |
|---|
| 112 | email varchar(255), |
|---|
| 113 | homepage varchar(255), |
|---|
| 114 | content mediumtext, |
|---|
| 115 | date datetime, |
|---|
| 116 | reference int(11), |
|---|
| 117 | mail_by_comment tinyint(1), |
|---|
| 118 | type varchar(30) default \'\', |
|---|
| 119 | PRIMARY KEY (id), |
|---|
| 120 | UNIQUE KEY sid (sid), |
|---|
| 121 | FULLTEXT KEY comments_index ( name, city, email, homepage, content ) |
|---|
| 122 | ) TYPE=MyISAM;'; |
|---|
| 123 | |
|---|
| 124 | $sql['categories'] = ' |
|---|
| 125 | CREATE TABLE `'.$data["jlog_db_prefix"].'categories` ( |
|---|
| 126 | id tinyint(4) auto_increment, |
|---|
| 127 | name tinytext, |
|---|
| 128 | url varchar(100), |
|---|
| 129 | description text, |
|---|
| 130 | UNIQUE KEY id (id), |
|---|
| 131 | UNIQUE KEY url (url) |
|---|
| 132 | ) TYPE=MyISAM;'; |
|---|
| 133 | |
|---|
| 134 | $sql['catassign'] = ' |
|---|
| 135 | CREATE TABLE `'.$data["jlog_db_prefix"].'catassign` ( |
|---|
| 136 | content_id int(11), |
|---|
| 137 | cat_id tinyint(4) |
|---|
| 138 | ) TYPE=MyISAM;'; |
|---|
| 139 | |
|---|
| 140 | $sql['attributes'] = ' |
|---|
| 141 | CREATE TABLE `'.$data["jlog_db_prefix"].'attributes` ( |
|---|
| 142 | id int(10) unsigned NOT NULL auto_increment, |
|---|
| 143 | entry_id int(10) unsigned NOT NULL default \'0\', |
|---|
| 144 | name varchar(120) NOT NULL default \'\', |
|---|
| 145 | value varchar(250) NOT NULL default \'\', |
|---|
| 146 | PRIMARY KEY (id), |
|---|
| 147 | KEY entry_id (entry_id) |
|---|
| 148 | ) TYPE=MyISAM;'; |
|---|
| 149 | |
|---|
| 150 | global $l; |
|---|
| 151 | |
|---|
| 152 | if(!@mysql_connect($data['jlog_db_url'], $data['jlog_db_user'], $data['jlog_db_pwd'])) $errors[] = "Falsche Zugangsdaten | ".mysql_error(); |
|---|
| 153 | elseif(!@mysql_select_db($data['jlog_db'])) $errors[] = "Datenbank ".$data['jlog_db']." extistiert nicht".mysql_error(); |
|---|
| 154 | elseif(!version_compare(mysql_get_server_info(), JLOG_MYSQLV, ">=") == 1) $errors[] = $l['admin']['s_mysqlv_tolow']; |
|---|
| 155 | else { |
|---|
| 156 | $create['content'] = new Query($sql['content']); |
|---|
| 157 | if($create['content']->error()) $errors[] = "MySQL <pre>".$create['content']->getError()."</pre>"; |
|---|
| 158 | $create['comments'] = new Query($sql['comments']); |
|---|
| 159 | if($create['comments']->error()) $errors[] = "MySQL <pre>".$create['comments']->getError()."</pre>"; |
|---|
| 160 | $create['categories'] = new Query($sql['categories']); |
|---|
| 161 | if($create['categories']->error()) $errors[] = "MySQL <pre>".$create['categories']->getError()."</pre>"; |
|---|
| 162 | $create['catassign'] = new Query($sql['catassign']); |
|---|
| 163 | if($create['catassign']->error()) $errors[] = "MySQL <pre>".$create['catassign']->getError()."</pre>"; |
|---|
| 164 | $create['attributes'] = new Query($sql['attributes']); |
|---|
| 165 | if($create['attributes']->error()) $errors[] = "MySQL <pre>".$create['attributes']->getError()."</pre>"; |
|---|
| 166 | } |
|---|
| 167 | |
|---|
| 168 | return $errors; |
|---|
| 169 | } |
|---|
| 170 | |
|---|
| 171 | function do_personal() { |
|---|
| 172 | # returns true if all files and dirs could be generated |
|---|
| 173 | # if not returns the $errors array |
|---|
| 174 | |
|---|
| 175 | global $l; |
|---|
| 176 | |
|---|
| 177 | // make some dirs |
|---|
| 178 | $oldmask = umask(0); |
|---|
| 179 | |
|---|
| 180 | // make some files |
|---|
| 181 | if(!fopen(JLOG_BASEPATH."personal".DIRECTORY_SEPARATOR."settings.inc.php", "w")) $errors[] = $l['admin']['s_problem_fwrite']." /personal/settings.inc.php"; |
|---|
| 182 | if(!fopen(JLOG_BASEPATH."personal".DIRECTORY_SEPARATOR."rss.xml", "w")) $errors[] = $l['admin']['s_problem_fwrite']." /personal/rss.xml"; |
|---|
| 183 | if(!fopen(JLOG_BASEPATH."personal".DIRECTORY_SEPARATOR."rss-full.xml", "w")) $errors[] = $l['admin']['s_problem_fwrite']." /personal/rss-full.xml"; |
|---|
| 184 | if(!fopen(JLOG_BASEPATH."personal".DIRECTORY_SEPARATOR."subcurrent.inc", "w")) $errors[] = $l['admin']['s_problem_fwrite']." /personal/subcurrent.inc"; |
|---|
| 185 | |
|---|
| 186 | // chmod 777 so that the user have the ability to delete/write to this files |
|---|
| 187 | if(!chmod(JLOG_BASEPATH."personal".DIRECTORY_SEPARATOR."settings.inc.php", 0666)) $errors[] = $l['admin']['s_problem_chmod']." /personal/settings.inc.php"; |
|---|
| 188 | if(!chmod(JLOG_BASEPATH."personal".DIRECTORY_SEPARATOR."rss.xml", 0666)) $errors[] = $l['admin']['s_problem_chmod']." /personal/rss.xml"; |
|---|
| 189 | if(!chmod(JLOG_BASEPATH."personal".DIRECTORY_SEPARATOR."rss-full.xml", 0666)) $errors[] = $l['admin']['s_problem_chmod']." /personal/rss-full.xml"; |
|---|
| 190 | if(!chmod(JLOG_BASEPATH."personal".DIRECTORY_SEPARATOR."subcurrent.inc", 0666)) $errors[] = $l['admin']['s_problem_chmod']." /personal/subcurrent.inc"; |
|---|
| 191 | |
|---|
| 192 | umask($oldmask); |
|---|
| 193 | |
|---|
| 194 | return $errors; |
|---|
| 195 | } |
|---|
| 196 | |
|---|
| 197 | function do_htmlpage($content) { |
|---|
| 198 | |
|---|
| 199 | return '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" |
|---|
| 200 | "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> |
|---|
| 201 | <html xmlns="http://www.w3.org/1999/xhtml"> |
|---|
| 202 | <title>SETUP Jlog ' . JLOG_NEW_VERSION . '</title> |
|---|
| 203 | <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> |
|---|
| 204 | <link rel="stylesheet" href="scripts/css/admin.css" type="text/css" /> |
|---|
| 205 | <style type="text/css"> |
|---|
| 206 | body { |
|---|
| 207 | background: #F3F3F3; |
|---|
| 208 | color: black; |
|---|
| 209 | font-family: verdana, sans-serif; |
|---|
| 210 | font-size: 100.01%; |
|---|
| 211 | } |
|---|
| 212 | #container { |
|---|
| 213 | font-size: 0.9em; |
|---|
| 214 | background: white; |
|---|
| 215 | padding: 20px; |
|---|
| 216 | margin: 1em auto; |
|---|
| 217 | border: 1px solid #aaa; |
|---|
| 218 | width: 600px; |
|---|
| 219 | } |
|---|
| 220 | h1 { |
|---|
| 221 | font-family: georgia, "Times New Roman", Times, sans-serif; |
|---|
| 222 | font-size: 80px; |
|---|
| 223 | margin: 0 0 0 30px; |
|---|
| 224 | } |
|---|
| 225 | #logo { float: right; } |
|---|
| 226 | h2 { margin: 1.5em 0 0.3em 0; font-weight: normal; clear: right; } |
|---|
| 227 | .ok { color: green; } |
|---|
| 228 | .notok, .error { color: red; } |
|---|
| 229 | table { border-spacing: 0.5em; } |
|---|
| 230 | fieldset { padding: 1em; border: 1px solid #ccc; clear: both; margin-top: 1em; } |
|---|
| 231 | legend { font-weight: bold; padding: 0 1em; } |
|---|
| 232 | .button { font-size: 3em; } |
|---|
| 233 | p { text-align: center; } |
|---|
| 234 | fieldset p { text-align: left; } |
|---|
| 235 | a img { border: none; } |
|---|
| 236 | </style> |
|---|
| 237 | </head> |
|---|
| 238 | <body> |
|---|
| 239 | <div id="container"> |
|---|
| 240 | <h1><a href="http://jeenaparadies.net/projects/jlog/" title="Jlog v'.JLOG_NEW_VERSION.'"><img id="logo" src="http://jeenaparadies.net/img/jlog-logo.png" style="width: 210px; height: 120px;" alt="Jlog" /></a> SETUP</h1> |
|---|
| 241 | '.$content.' |
|---|
| 242 | </div> |
|---|
| 243 | </body> |
|---|
| 244 | </html>'; |
|---|
| 245 | } |
|---|
| 246 | |
|---|
| 247 | ?> |
|---|