| 1 | <?php |
|---|
| 2 | |
|---|
| 3 | /** |
|---|
| 4 | * Jlog |
|---|
| 5 | * |
|---|
| 6 | * This program is free software; you can redistribute it and/or modify |
|---|
| 7 | * it under the terms of the GNU General Public License as published by |
|---|
| 8 | * the Free Software Foundation; either version 2 of the License, or |
|---|
| 9 | * (at your option) any later version. |
|---|
| 10 | * |
|---|
| 11 | * This program is distributed in the hope that it will be useful, |
|---|
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 14 | * GNU General Public License for more details. |
|---|
| 15 | * |
|---|
| 16 | * You should have received a copy of the GNU General Public License |
|---|
| 17 | * along with this program; if not, write to the Free Software |
|---|
| 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|---|
| 19 | * |
|---|
| 20 | * $HeadURL$ |
|---|
| 21 | * $Rev$ |
|---|
| 22 | * $Author$ |
|---|
| 23 | * $Date$ |
|---|
| 24 | **/ |
|---|
| 25 | |
|---|
| 26 | if(file_exists(dirname( __FILE__ ).DIRECTORY_SEPARATOR.'personal'.DIRECTORY_SEPARATOR.'settings.inc.php')) { |
|---|
| 27 | die("The setup has already been sucessfull!"); |
|---|
| 28 | } |
|---|
| 29 | |
|---|
| 30 | // derzeit gibt es noch etliche E_NOTICE-Meldungen in JLog, deshalb: |
|---|
| 31 | error_reporting(E_ALL ^ E_NOTICE); |
|---|
| 32 | header("Content-Type: text/html; charset=UTF-8"); |
|---|
| 33 | |
|---|
| 34 | |
|---|
| 35 | define("JLOG_NEW_VERSION", '1.1.0'); |
|---|
| 36 | define("JLOG_SETUP", true); |
|---|
| 37 | define("JLOG_ADMIN", false); |
|---|
| 38 | $basepath = dirname( __FILE__ ).DIRECTORY_SEPARATOR; |
|---|
| 39 | |
|---|
| 40 | // defining to avoid notifications |
|---|
| 41 | define("JLOG_WEBSITE", $_SERVER["HTTP_HOST"]); |
|---|
| 42 | define("JLOG_PATH", dirname("http://".$_SERVER["HTTP_HOST"].$_SERVER["SCRIPT_NAME"])); |
|---|
| 43 | |
|---|
| 44 | // read prefered language from browser |
|---|
| 45 | $dir = opendir('.'.DIRECTORY_SEPARATOR.'lang'); |
|---|
| 46 | $languages = array(); |
|---|
| 47 | while(($file = readdir($dir)) !== false) { |
|---|
| 48 | if($file == '.' OR $file == '..') continue; |
|---|
| 49 | if(!preg_match('/lang\.([a-zA-z0-9]+)\.inc\.php/', $file, $matches)) continue; |
|---|
| 50 | $languages[] = $matches[1]; |
|---|
| 51 | } |
|---|
| 52 | if(!empty($_GET['lang'])) { |
|---|
| 53 | $lang = $_GET['lang']; |
|---|
| 54 | } else { |
|---|
| 55 | $lang = getlang($languages, 'de'); |
|---|
| 56 | } |
|---|
| 57 | define('JLOG_LANGUAGE', $lang); |
|---|
| 58 | |
|---|
| 59 | // load required scripts and libraries |
|---|
| 60 | require('.'.DIRECTORY_SEPARATOR.'lang'.DIRECTORY_SEPARATOR.'lang.'.$lang.'.inc.php'); |
|---|
| 61 | require('.'.DIRECTORY_SEPARATOR.'lang'.DIRECTORY_SEPARATOR.'lang-admin.'.$lang.'.inc.php'); |
|---|
| 62 | require('.'.DIRECTORY_SEPARATOR.'scripts'.DIRECTORY_SEPARATOR.'database.class.php'); |
|---|
| 63 | require('.'.DIRECTORY_SEPARATOR.'scripts'.DIRECTORY_SEPARATOR.'general.func.php'); |
|---|
| 64 | require('.'.DIRECTORY_SEPARATOR.'scripts'.DIRECTORY_SEPARATOR.'settings.class.php'); |
|---|
| 65 | require('.'.DIRECTORY_SEPARATOR.'scripts'.DIRECTORY_SEPARATOR.'url_syntax.php'); |
|---|
| 66 | require('.'.DIRECTORY_SEPARATOR.'scripts'.DIRECTORY_SEPARATOR.'version.inc.php'); |
|---|
| 67 | |
|---|
| 68 | define("JLOG_NEW_VERSION", JLOG_SOFTWARE_VERSION); |
|---|
| 69 | define("JLOG_PHPV", JLOG_SOFTWARE_PHPV); |
|---|
| 70 | define("JLOG_MYSQLV", JLOG_SOFTWARE_MYSQLV); |
|---|
| 71 | |
|---|
| 72 | $errors = array(); |
|---|
| 73 | |
|---|
| 74 | $l['admin']['submit'] = $l['admin']['s_install']; |
|---|
| 75 | $setup = new Settings($l); |
|---|
| 76 | |
|---|
| 77 | if($_POST) { |
|---|
| 78 | $setup->get_userdata(strip($_POST)); |
|---|
| 79 | |
|---|
| 80 | // validate user entry |
|---|
| 81 | if(count($errors = $setup->validate()) == 0) { |
|---|
| 82 | define("JLOG_BASEPATH", $setup->put_data('basepath')); |
|---|
| 83 | if(is_writable(JLOG_BASEPATH.'personal'.DIRECTORY_SEPARATOR)) { |
|---|
| 84 | $c .= "<ul>\n"; |
|---|
| 85 | |
|---|
| 86 | // build some MySQL tables |
|---|
| 87 | if(count($errors = create_mysql_tables($setup->put_data(false))) == 0) { |
|---|
| 88 | $c .= "<li>".$l['admin']['s_tables_ok']."</li>\n"; |
|---|
| 89 | |
|---|
| 90 | // create and chmod on some directories and files |
|---|
| 91 | if(count($errors = do_personal()) == 0) { |
|---|
| 92 | $c .= "<li>".$l['admin']['s_personal_ok']."</li>\n"; |
|---|
| 93 | |
|---|
| 94 | // build settings.inc.php |
|---|
| 95 | if(count($errors = $setup->do_settings()) == 0) $c .= "<li>".$l['admin']['master_ok']."</li>\n"; |
|---|
| 96 | } |
|---|
| 97 | $c .= "</ul>"; |
|---|
| 98 | } |
|---|
| 99 | } |
|---|
| 100 | else { |
|---|
| 101 | $errors[] = $l['admin']['s_personal_not_wrtbl']; |
|---|
| 102 | } |
|---|
| 103 | } |
|---|
| 104 | if(count($errors) > 0) { |
|---|
| 105 | $c .= error_output($errors); |
|---|
| 106 | $c .= $setup->form_output(); |
|---|
| 107 | } |
|---|
| 108 | else $c .= "<h2>".$l['admin']['s_ready_head']."</h2>"."<p style='text-align: left;'>".$l['admin']['s_ready']."</p>"; |
|---|
| 109 | } |
|---|
| 110 | else { |
|---|
| 111 | // validate PHP and MySQL versions |
|---|
| 112 | if(!version_compare(phpversion(), JLOG_PHPV, ">=") == 1) $errors[] = $l['admin']['s_phpv_tolow']; |
|---|
| 113 | if(!is_writable($basepath.'personal'.DIRECTORY_SEPARATOR)) $errors[] = $l['admin']['s_personal_not_wrtbl']; |
|---|
| 114 | if(!is_writable($basepath.'img'.DIRECTORY_SEPARATOR)) $errors[] = $l['admin']['s_img_not_wrtbl']; |
|---|
| 115 | |
|---|
| 116 | if(empty($errors)) { |
|---|
| 117 | // output form |
|---|
| 118 | $setup->get_sugestiondata(); |
|---|
| 119 | $c .= $setup->form_output(); |
|---|
| 120 | } |
|---|
| 121 | else $c .= error_output($errors); |
|---|
| 122 | } |
|---|
| 123 | |
|---|
| 124 | echo do_htmlpage($c); |
|---|
| 125 | |
|---|
| 126 | |
|---|
| 127 | |
|---|
| 128 | |
|---|
| 129 | |
|---|
| 130 | #### some needed functions for the setup #### |
|---|
| 131 | |
|---|
| 132 | function create_mysql_tables($data) { |
|---|
| 133 | # returns false if all tables were created, if not returns the $errors array |
|---|
| 134 | |
|---|
| 135 | $sql['content'] = ' |
|---|
| 136 | CREATE TABLE `'.$data['jlog_db_prefix'].'content` ( |
|---|
| 137 | id int(11) auto_increment, |
|---|
| 138 | url varchar(200), |
|---|
| 139 | topic varchar(255), |
|---|
| 140 | date datetime, |
|---|
| 141 | teaser mediumtext, |
|---|
| 142 | teaserpic varchar(10), |
|---|
| 143 | teaserpiconblog tinyint(1), |
|---|
| 144 | keywords varchar(255), |
|---|
| 145 | content longtext, |
|---|
| 146 | comments tinyint(1) default \'1\', |
|---|
| 147 | allowpingback tinyint(1) default \'1\', |
|---|
| 148 | section varchar(10) default \'weblog\', |
|---|
| 149 | UNIQUE KEY id (id), |
|---|
| 150 | FULLTEXT KEY content_index (content, topic, teaser, keywords) |
|---|
| 151 | ) TYPE=MyISAM CHARACTER SET utf8;'; |
|---|
| 152 | |
|---|
| 153 | $sql['comments'] = ' |
|---|
| 154 | CREATE TABLE `'.$data["jlog_db_prefix"].'comments` ( |
|---|
| 155 | id int(11) auto_increment, |
|---|
| 156 | sid varchar(35), |
|---|
| 157 | name varchar(255), |
|---|
| 158 | city varchar(255), |
|---|
| 159 | email varchar(255), |
|---|
| 160 | homepage varchar(255), |
|---|
| 161 | content mediumtext, |
|---|
| 162 | date datetime, |
|---|
| 163 | reference int(11), |
|---|
| 164 | mail_by_comment tinyint(1), |
|---|
| 165 | type varchar(30) default \'\', |
|---|
| 166 | PRIMARY KEY (id), |
|---|
| 167 | UNIQUE KEY sid (sid), |
|---|
| 168 | FULLTEXT KEY comments_index ( name, city, email, homepage, content ) |
|---|
| 169 | ) TYPE=MyISAM CHARACTER SET utf8;'; |
|---|
| 170 | |
|---|
| 171 | $sql['categories'] = ' |
|---|
| 172 | CREATE TABLE `'.$data["jlog_db_prefix"].'categories` ( |
|---|
| 173 | id tinyint(4) auto_increment, |
|---|
| 174 | name tinytext, |
|---|
| 175 | url varchar(100), |
|---|
| 176 | description text, |
|---|
| 177 | UNIQUE KEY id (id), |
|---|
| 178 | UNIQUE KEY url (url) |
|---|
| 179 | ) TYPE=MyISAM CHARACTER SET utf8;'; |
|---|
| 180 | |
|---|
| 181 | $sql['catassign'] = ' |
|---|
| 182 | CREATE TABLE `'.$data["jlog_db_prefix"].'catassign` ( |
|---|
| 183 | content_id int(11), |
|---|
| 184 | cat_id tinyint(4) |
|---|
| 185 | ) TYPE=MyISAM CHARACTER SET utf8;'; |
|---|
| 186 | |
|---|
| 187 | $sql['attributes'] = ' |
|---|
| 188 | CREATE TABLE `'.$data["jlog_db_prefix"].'attributes` ( |
|---|
| 189 | id int(10) unsigned NOT NULL auto_increment, |
|---|
| 190 | entry_id int(10) unsigned NOT NULL default \'0\', |
|---|
| 191 | name varchar(120) NOT NULL default \'\', |
|---|
| 192 | value varchar(250) NOT NULL default \'\', |
|---|
| 193 | PRIMARY KEY (id), |
|---|
| 194 | KEY entry_id (entry_id) |
|---|
| 195 | ) TYPE=MyISAM CHARACTER SET utf8;'; |
|---|
| 196 | |
|---|
| 197 | global $l; |
|---|
| 198 | |
|---|
| 199 | if(!@mysql_connect($data['jlog_db_url'], $data['jlog_db_user'], $data['jlog_db_pwd'])) $errors[] = "Falsche Zugangsdaten | ".mysql_error(); |
|---|
| 200 | elseif(!@mysql_select_db($data['jlog_db'])) $errors[] = "Datenbank ".$data['jlog_db']." extistiert nicht".mysql_error(); |
|---|
| 201 | elseif(!version_compare(mysql_get_server_info(), JLOG_MYSQLV, ">=") == 1) $errors[] = $l['admin']['s_mysqlv_tolow']; |
|---|
| 202 | else { |
|---|
| 203 | new Query("SET NAMES utf8"); |
|---|
| 204 | $create['content'] = new Query($sql['content']); |
|---|
| 205 | if($create['content']->error()) $errors[] = "MySQL <pre>".$create['content']->getError()."</pre>"; |
|---|
| 206 | $create['comments'] = new Query($sql['comments']); |
|---|
| 207 | if($create['comments']->error()) $errors[] = "MySQL <pre>".$create['comments']->getError()."</pre>"; |
|---|
| 208 | $create['categories'] = new Query($sql['categories']); |
|---|
| 209 | if($create['categories']->error()) $errors[] = "MySQL <pre>".$create['categories']->getError()."</pre>"; |
|---|
| 210 | $create['catassign'] = new Query($sql['catassign']); |
|---|
| 211 | if($create['catassign']->error()) $errors[] = "MySQL <pre>".$create['catassign']->getError()."</pre>"; |
|---|
| 212 | $create['attributes'] = new Query($sql['attributes']); |
|---|
| 213 | if($create['attributes']->error()) $errors[] = "MySQL <pre>".$create['attributes']->getError()."</pre>"; |
|---|
| 214 | } |
|---|
| 215 | |
|---|
| 216 | return $errors; |
|---|
| 217 | } |
|---|
| 218 | |
|---|
| 219 | function do_personal() { |
|---|
| 220 | # returns true if all files and dirs could be generated |
|---|
| 221 | # if not returns the $errors array |
|---|
| 222 | |
|---|
| 223 | global $l; |
|---|
| 224 | |
|---|
| 225 | // make some dirs |
|---|
| 226 | $oldmask = umask(0); |
|---|
| 227 | |
|---|
| 228 | // make some files |
|---|
| 229 | if(!fopen(JLOG_BASEPATH."personal".DIRECTORY_SEPARATOR."settings.inc.php", "w")) $errors[] = $l['admin']['s_problem_fwrite']." /personal/settings.inc.php"; |
|---|
| 230 | if(!fopen(JLOG_BASEPATH."personal".DIRECTORY_SEPARATOR."rss.xml", "w")) $errors[] = $l['admin']['s_problem_fwrite']." /personal/rss.xml"; |
|---|
| 231 | if(!fopen(JLOG_BASEPATH."personal".DIRECTORY_SEPARATOR."rss-full.xml", "w")) $errors[] = $l['admin']['s_problem_fwrite']." /personal/rss-full.xml"; |
|---|
| 232 | if(!fopen(JLOG_BASEPATH."personal".DIRECTORY_SEPARATOR."subcurrent.inc", "w")) $errors[] = $l['admin']['s_problem_fwrite']." /personal/subcurrent.inc"; |
|---|
| 233 | |
|---|
| 234 | // chmod 666 so that the user have the ability to delete/write to this files |
|---|
| 235 | if(!chmod(JLOG_BASEPATH."personal".DIRECTORY_SEPARATOR."settings.inc.php", 0666)) $errors[] = $l['admin']['s_problem_chmod']." /personal/settings.inc.php"; |
|---|
| 236 | if(!chmod(JLOG_BASEPATH."personal".DIRECTORY_SEPARATOR."rss.xml", 0666)) $errors[] = $l['admin']['s_problem_chmod']." /personal/rss.xml"; |
|---|
| 237 | if(!chmod(JLOG_BASEPATH."personal".DIRECTORY_SEPARATOR."rss-full.xml", 0666)) $errors[] = $l['admin']['s_problem_chmod']." /personal/rss-full.xml"; |
|---|
| 238 | if(!chmod(JLOG_BASEPATH."personal".DIRECTORY_SEPARATOR."subcurrent.inc", 0666)) $errors[] = $l['admin']['s_problem_chmod']." /personal/subcurrent.inc"; |
|---|
| 239 | |
|---|
| 240 | umask($oldmask); |
|---|
| 241 | |
|---|
| 242 | return $errors; |
|---|
| 243 | } |
|---|
| 244 | |
|---|
| 245 | function do_htmlpage($content) { |
|---|
| 246 | |
|---|
| 247 | return '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" |
|---|
| 248 | "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> |
|---|
| 249 | <html xmlns="http://www.w3.org/1999/xhtml"> |
|---|
| 250 | <title>SETUP Jlog ' . JLOG_NEW_VERSION . '</title> |
|---|
| 251 | <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> |
|---|
| 252 | <link rel="stylesheet" href="scripts/css/admin.css" type="text/css" /> |
|---|
| 253 | <style type="text/css"> |
|---|
| 254 | body { |
|---|
| 255 | background: #F3F3F3; |
|---|
| 256 | color: black; |
|---|
| 257 | font-family: verdana, sans-serif; |
|---|
| 258 | font-size: 100.01%; |
|---|
| 259 | } |
|---|
| 260 | #container { |
|---|
| 261 | font-size: 0.9em; |
|---|
| 262 | background: white; |
|---|
| 263 | padding: 20px; |
|---|
| 264 | margin: 1em auto; |
|---|
| 265 | border: 1px solid #aaa; |
|---|
| 266 | width: 600px; |
|---|
| 267 | } |
|---|
| 268 | h1 { |
|---|
| 269 | font-family: georgia, "Times New Roman", Times, sans-serif; |
|---|
| 270 | font-size: 80px; |
|---|
| 271 | margin: 0 0 0 30px; |
|---|
| 272 | } |
|---|
| 273 | #logo { float: right; } |
|---|
| 274 | h2 { margin: 1.5em 0 0.3em 0; font-weight: normal; clear: right; } |
|---|
| 275 | .ok { color: green; } |
|---|
| 276 | .notok, .error { color: red; } |
|---|
| 277 | table { border-spacing: 0.5em; } |
|---|
| 278 | fieldset { padding: 1em; border: 1px solid #ccc; clear: both; margin-top: 1em; } |
|---|
| 279 | legend { font-weight: bold; padding: 0 1em; } |
|---|
| 280 | .button { font-size: 3em; } |
|---|
| 281 | p { text-align: center; } |
|---|
| 282 | fieldset p { text-align: left; } |
|---|
| 283 | a img { border: none; } |
|---|
| 284 | </style> |
|---|
| 285 | </head> |
|---|
| 286 | <body> |
|---|
| 287 | <div id="container"> |
|---|
| 288 | <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> |
|---|
| 289 | '.$content.' |
|---|
| 290 | </div> |
|---|
| 291 | </body> |
|---|
| 292 | </html>'; |
|---|
| 293 | } |
|---|
| 294 | |
|---|
| 295 | function getlang ($allowed, $default) { |
|---|
| 296 | $string = $_SERVER['HTTP_ACCEPT_LANGUAGE']; |
|---|
| 297 | if (empty($string)) { |
|---|
| 298 | return $default; |
|---|
| 299 | } |
|---|
| 300 | |
|---|
| 301 | $accepted_languages = preg_split('/,\s*/', $string); |
|---|
| 302 | |
|---|
| 303 | $cur_l = $default; |
|---|
| 304 | $cur_q = 0; |
|---|
| 305 | |
|---|
| 306 | foreach ($accepted_languages as $accepted_language) { |
|---|
| 307 | $res = preg_match ('/^([a-z]{1,8}(?:-[a-z]{1,8})*)'. |
|---|
| 308 | '(?:;\s*q=(0(?:\.[0-9]{1,3})?|1(?:\.0{1,3})?))?$/i', $accepted_language, $matches); |
|---|
| 309 | |
|---|
| 310 | if (!$res) { |
|---|
| 311 | continue; |
|---|
| 312 | } |
|---|
| 313 | |
|---|
| 314 | $lang_code = explode ('-', $matches[1]); |
|---|
| 315 | |
|---|
| 316 | if (isset($matches[2])) { |
|---|
| 317 | $lang_quality = (float)$matches[2]; |
|---|
| 318 | } else { |
|---|
| 319 | $lang_quality = 1.0; |
|---|
| 320 | } |
|---|
| 321 | |
|---|
| 322 | while (count ($lang_code)) { |
|---|
| 323 | if (in_array (strtolower (join ('-', $lang_code)), $allowed)) { |
|---|
| 324 | if ($lang_quality > $cur_q) { |
|---|
| 325 | $cur_l = strtolower (join ('-', $lang_code)); |
|---|
| 326 | $cur_q = $lang_quality; |
|---|
| 327 | break; |
|---|
| 328 | } |
|---|
| 329 | } |
|---|
| 330 | array_pop ($lang_code); |
|---|
| 331 | } |
|---|
| 332 | } |
|---|
| 333 | |
|---|
| 334 | return $cur_l; |
|---|
| 335 | } |
|---|
| 336 | |
|---|
| 337 | // eof |
|---|
| 338 | |
|---|