| [ Index ] |
PHP Cross Reference of Nuke-Evolution v2.0.5 |
[Summary view] [Print] [Text view]
1 <?php 2 /*======================================================================= 3 Nuke-Evolution Basic: Enhanced PHP-Nuke Web Portal System 4 =======================================================================*/ 5 6 /************************************************************************ 7 Nuke-Evolution: Advanced Installer 8 ============================================ 9 Copyright (c) 2005 by The Nuke-Evolution Team 10 11 Filename : functions.php 12 Author : JeFFb68CAM (www.Evo-Mods.com) 13 Version : 1.0.0 14 Date : 11.05.2005 (mm.dd.yyyy) 15 16 Notes : You may NOT use this installer for your own 17 needs or script. It is written specifically 18 for Nuke-Evolution. 19 ************************************************************************/ 20 21 #Global vars. 22 define("IN_PHPBB", true); 23 $data_file = "install/data.txt"; 24 if(!$open_data = @fopen($data_file, "r")) { 25 echo $install_lang['data_error']; 26 exit; 27 } 28 $data = @fread($open_data, @filesize($data_file)); 29 @fclose($open_data); 30 list($required_files, $chmods) = explode("\n###", $data); 31 32 $required_files = explode("\n", $required_files); 33 $chmods = explode("\n", $chmods); 34 if(!$directory_mode) { 35 $directory_mode = 0755; 36 } else { 37 $directory_mode = 0777; } 38 if (!$file_mode) { 39 $file_mode = 0666; 40 } else { $file_mode = 0644; } 41 function message($message, $die=false) { 42 global $install_lang; 43 if ($die) { 44 die("<table id=menu border=\"1\" width=\"100%\">" 45 ."<th id=test align=\"center\">" . $install_lang['die_message'] . "</th>" 46 ."<tr><td align=\"center\"><strong>" . $message . "</strong></td></tr>" 47 ."</table><br />"); 48 } else { 49 echo("<table id=menu border=\"1\" width=\"100%\">" 50 ."<th id=test align=\"center\">" . $install_lang['general_message'] . "</th>" 51 ."<tr><td align=\"center\"><strong>" . $message . "</strong></td></tr>" 52 ."</table><br />"); 53 } 54 } 55 function generate_config() { 56 global $directory_mode, $file_mode, $install_lang, $next_step; 57 58 if(@is_file('config.php')) { 59 @unlink('config.php'); 60 } 61 62 $filename = "install/config_blank.php"; 63 if(!$handle = @fopen ($filename, "r")) 64 { 65 $message = $install_lang['cant_open'] . " $filename"; 66 message($message); 67 } 68 $contents = @fread ($handle, filesize ($filename)); 69 @fclose ($handle); 70 71 $contents = str_replace("%dbhost%", $_SESSION['dbhost'], $contents); 72 $contents = str_replace("%dbname%", $_SESSION['dbname'], $contents); 73 $contents = str_replace("%dbuname%", $_SESSION['dbuser'], $contents); 74 $contents = str_replace("%dbpass%", $_SESSION['dbpass'], $contents); 75 $contents = str_replace("%prefix%", $_SESSION['prefix'], $contents); 76 $contents = str_replace("%user_prefix%", $_SESSION['user_prefix'], $contents); 77 $contents = str_replace("%dbtype%", $_SESSION['dbtype'], $contents); 78 79 $filename = "config.php"; 80 81 if(!@touch ($filename)) { 82 $DownloadData = true; 83 } 84 @chmod($filename, $directory_mode); 85 if (@is_writable($filename)) 86 { 87 if (!$handle = @fopen($filename, 'a')) 88 { 89 $message = $install_lang['cant_open'] . " $filename"; 90 return $message; 91 } 92 93 if (!@fwrite($handle, $contents)) 94 { 95 $message = $install_lang['cantwrite'] . " $filename"; 96 return $message; 97 } 98 @fclose($handle); 99 } else { 100 $_SESSION['configData'] = $contents; 101 echo("<input type='hidden' name='download_file' value='1'>" 102 ."<tr><th id=test align=\"center\">" . $install_lang['general_message'] . "</th></tr>" 103 ."<tr><td align=\"center\"><strong>" . $install_lang['config_failed'] . "</strong></td></tr>" 104 ."<tr><td align=\"center\"><input type='submit' value='Download Config File'><input type=hidden name=step value=\"".$next_step."\"><input type='submit' name='continue' value=\"" . $install_lang['continue'] . " $next_step\"></td></tr>"); 105 return false; 106 } 107 108 return true; 109 } 110 function chmod_files() { 111 global $directory_mode, $file_mode, $install_lang, $chmods; 112 113 foreach ($chmods as $file) { 114 $file = explode(" ", $file); 115 $perm = $file[1]; 116 $perm = str_replace("[", "", str_replace("]", "", $perm)); 117 $file = $file[0]; 118 if (!empty($file) && !empty($perm)) { 119 if(!(substr($file,strlen($file)-1)=='/') && !@is_file($file)) { 120 $message .="<tr><td align=\"center\">$file - <font color=red>" . $install_lang['is_missing'] . "</font></td></tr>"; 121 $failed = true; 122 continue; 123 } 124 $permission = "0".$perm; 125 if (!@chmod($file, intval($permission,8))) { 126 $message .="<tr><td align=\"center\">$file - <font color=red>" . $install_lang['failed'] . "</font> CHMOD:($perm)</td></tr>"; 127 $failed = true; 128 } else { 129 $message .="<tr><td align=\"center\">($perm) $file - <font color=green>" . $install_lang['success'] . "</font></td></tr>"; 130 } 131 } 132 } 133 if ($failed) { 134 $message .="<tr><td align=\"center\"><font color=red>" . $install_lang['chmod_failed'] . "</font></td></tr>"; 135 } 136 return $message; 137 } 138 function check_required_files() { 139 global $install_lang, $required_files; 140 141 foreach($required_files as $file) { 142 $file = @trim($file); 143 #looping to make sure all required files are there.. 144 if (!is_file($file)) { 145 $message .= $install_lang['thefile'] . " \"" . $file . "\" " . $install_lang['is_missing']; 146 } 147 } 148 #End the loop, check to see if any errors. 149 if ($message) { 150 message($message, true); 151 } 152 return; 153 } 154 155 function make_step_list() { 156 global $step, $step_a, $install_lang; 157 158 while(list($step_num, $label) = each($step_a)) { 159 if ($step_num < $step) { 160 $show .= "<strike>$label</strike><hr />"; 161 } elseif ($step == $step_num) { 162 $show .= "<strong>$label</strong><hr />"; 163 } else { 164 $show .="$label<hr />"; 165 } 166 } 167 return $show; 168 } 169 function validate_data($post) { 170 global $step, $next_step, $install_lang, $server_check; 171 172 $dbhost = ($_POST['dbhost']) ? $_POST['dbhost'] : $error .= "<tr><td align=\"center\"><font color=red>" . $install_lang['dbhost_error'] . "</font></td></tr>"; 173 $dbname = ($_POST['dbname']) ? $_POST['dbname'] : $error .= "<tr><td align=\"center\"><font color=red>" . $install_lang['dbname_error'] . "</font></td></tr>"; 174 $dbuser = ($_POST['dbuser']) ? $_POST['dbuser'] : $error .= "<tr><td align=\"center\"><font color=red>" . $install_lang['dbuser_error'] . "</font></td></tr>"; 175 $dbpass = ($_POST['dbpass']) ? $_POST['dbpass'] : ''; 176 $prefix = ($_POST['prefix']) ? $_POST['prefix'] : $error .= "<tr><td align=\"center\"><font color=red>" . $install_lang['prefix_error'] . "</font></td></tr>"; 177 $user_prefix = ($_POST['user_prefix']) ? $_POST['user_prefix'] : $error .= "<tr><td align=\"center\"><font color=red>" . $install_lang['uprefix_error'] . "</font></td></tr>"; 178 $dbtype = ($_POST['dbtype'] ) ? $_POST['dbtype'] : $error .= "<tr><td align=\"center\"><font color=red>" . $install_lang['dbtype_error'] . "</font></td></tr>"; 179 if ($error) { 180 $error .="<tr><td align=\"center\"><input type=hidden name=step value=$next_step><input type=submit name=submit value=\"" . $install_lang['continue'] . " $next_step\" disabled></td></tr>"; 181 return $error; 182 } 183 184 if (!($server_check = @mysql_connect($dbhost, $dbuser, $dbpass))) { 185 $error .= "<tr><td align=\"center\"><font color=red>" . $install_lang['connection_failed'] . "</font></td></tr>"; 186 } 187 188 if (!(@mysql_select_db($dbname))) { 189 $error .= "<tr><td align=\"center\"><font color=red>" . $install_lang['connection_failed2'] . "</font></td></tr>"; 190 } 191 //@mysql_close($server_check); 192 193 if ($error) { 194 $error .="<tr><td align=\"center\"><input type=hidden name=step value=$next_step><input type=submit name=submit value=\"" . $install_lang['continue'] . " $next_step\" disabled></td></tr>"; 195 return $error; 196 } 197 198 $_SESSION['dbhost'] = $dbhost; 199 $_SESSION['dbname'] = $dbname; 200 $_SESSION['dbuser'] = $dbuser; 201 $_SESSION['dbpass'] = $dbpass; 202 $_SESSION['prefix'] = $prefix; 203 $_SESSION['user_prefix'] = $user_prefix; 204 $_SESSION['dbtype'] = $dbtype; 205 206 if (generate_config()) { 207 $message .= "<tr><td align=\"center\"><font color=green>" . $install_lang['config_success'] . "</font></td></tr>"; 208 $message .= "<tr><td align=\"center\"><font color=green>" . $install_lang['data_success'] . "</font></td></tr>"; 209 $message .="<tr><td align=\"center\"> <input type=hidden name=step value=$next_step> <input type=submit name=submit value=\"" . $install_lang['continue'] . " $next_step\" ></td></tr>"; 210 } else { 211 //$message .= "<tr><td align=\"center\"><font color=red>" . $install_lang['config_failed'] . "</font></td></tr>"; 212 } 213 214 return $message; 215 } 216 function server_check() { 217 global $install_lang, $server_check; 218 219 $sql_ver = @mysql_get_server_info(); 220 221 if(!empty($sql_ver)) { 222 if(intval(substr($sql_ver,0,1)) <= 3) { 223 $error .= "<tr><td align=\"center\">" . $install_lang['mysql_incorrect'] . "</td></tr>"; 224 } 225 } 226 227 if (isset($_SESSION['dbtype'])) { 228 if ($_SESSION['dbtype'] != "mysql") { 229 $message .= "<tr><td align=\"center\"><font color=red>" . $install_lang['dbtype_que'] . "</td></tr>"; 230 } 231 } 232 if (!isset($_SESSION['dbname']) || !isset($_SESSION['dbuser']) || !isset($_SESSION['dbpass']) || !isset($_SESSION['prefix']) || !isset($_SESSION['user_prefix']) || !isset($_SESSION['dbhost'])) { 233 $message .= "<tr><td align=\"center\"><font color=red>" . $install_lang['session_lost'] . "</td></tr>"; 234 } 235 236 237 if(substr(PHPVERS,0,1) < "4") { 238 $message .= "<tr><td align=\"center\"><font color=red>" . $install_lang['php_ver'] . " " .PHPVERS ."</td></tr>"; 239 } 240 if (empty($message)) { 241 $message .= "<tr><td align=\"center\"><font color=green>" . $install_lang['checks_good'] . "</td></tr>"; 242 } 243 @mysql_close($server_check); 244 return $message; 245 } 246 247 function do_sql($install_file) { 248 global $nuke_name, $next_step, $step, $install_lang, $prefix, $user_prefix; 249 250 if(!$handle = @fopen ($install_file, "r")) 251 { 252 $message = $install_lang['cant_open'] . " ".$install_file; 253 return $message; 254 } 255 $contents = @fread ($handle, filesize ($install_file)); 256 @fclose ($handle); 257 $filename = $install_file; 258 259 $filesize = filesize($filename); 260 $file_position = isset($HTTP_GET_VARS['pos']) ? $HTTP_GET_VARS['pos'] : 0; 261 $errors = isset($HTTP_GET_VARS['ignore_errors']) ? 0 : 1; 262 263 if (!$fp = @fopen($filename,'rb')) 264 { 265 echo $install_lang['cant_open'] . " $filename"; 266 } 267 268 $buffer = ''; 269 $inside_quote = 0; 270 $quote_inside = ''; 271 $started_query = 0; 272 $data_buffer = ''; 273 $last_char = "\n"; 274 275 @fseek($fp,$file_position); 276 277 while ((!feof($fp) || strlen($buffer))) 278 { 279 do 280 { 281 if (!strlen($buffer)) 282 { 283 $buffer .= fread ($fp,1024); 284 } 285 286 $current_char = $buffer[0]; 287 $buffer = substr($buffer, 1); 288 289 if ($started_query) 290 { 291 $data_buffer .= $current_char; 292 } 293 elseif (preg_match("/[A-Za-z]/i",$current_char) && $last_char == "\n") 294 { 295 $started_query = 1; 296 $data_buffer = $current_char; 297 } 298 else 299 { 300 $last_char = $current_char; 301 } 302 } while (!$started_query && (!feof($fp) || strlen($buffer))); 303 if ($inside_quote && $current_char == $quote_inside && $last_char != '\\') 304 { 305 $inside_quote = 0; 306 } 307 elseif ($current_char == '\\' && $last_char == '\\') 308 { 309 $current_char = ''; 310 } 311 elseif (!$inside_quote && ($current_char == '"' || $current_char == '`' || $current_char == '\'')) 312 { 313 $inside_quote = 1; 314 $quote_inside = $current_char; 315 } 316 elseif (!$inside_quote && $current_char == ';') 317 { 318 if($user_prefix != "nuke" && !empty($user_prefix)) { 319 $data_buffer = str_replace("`nuke_users`", "`" . $user_prefix . "_users`", $data_buffer); 320 } 321 if($prefix != "nuke" && !empty($prefix)) { 322 $data_buffer = str_replace("`nuke_", "`".$prefix."_", $data_buffer); 323 } 324 325 @mysql_query($data_buffer); 326 327 if ($errors && mysql_errno()) 328 { 329 $message .= "<tr><td align=\"center\"><font color=red>" . $install_lang['sql_error'] . mysql_errno().": ".mysql_error()."<br />".$data_buffer."</td></tr>"; 330 } 331 $data_buffer = ''; 332 $last_char = "\n"; 333 $started_query = 0; 334 } 335 336 $last_char = $current_char; 337 } 338 $new_position = ftell($fp) - strlen($buffer) - strlen($data_buffer); 339 340 @fclose($fp); 341 342 if (empty($message)) { 343 $message = "<tr><td align=\"center\"><strong><font color='green'>" . $install_lang['install_success'] . "</font></strong></td></tr><tr><td align=center><input type=hidden name=step value=$next_step><input type=submit name=confirm value=\"" . $install_lang['configure'] . "\"></td></tr>"; 344 } else { 345 $message .= "<tr><td align=center><input type=hidden name=step value=$next_step><input type=submit name=confirm value=\"" . $install_lang['configure'] . "\" disabled></td></tr>"; 346 } 347 return $message; 348 } 349 function site_form($display = 1) { 350 global $install_lang, $HTTP_POST_VARS; 351 352 $sql = "SELECT * 353 FROM " . $_SESSION['prefix'] . "_bbconfig"; 354 355 if(!$result = mysql_query($sql)) 356 { 357 $error .= "<tr><td align=center>" . $install_lang['get_config_error'] . mysql_error() . "</td></tr>"; 358 } 359 360 while( $row = @mysql_fetch_assoc($result) ) 361 { 362 $config_name = $row['config_name']; 363 $config_value = $row['config_value']; 364 $default_config[$config_name] = isset($HTTP_POST_VARS['submit']) ? str_replace("'", "\'", $config_value) : $config_value; 365 366 $new[$config_name] = ( isset($HTTP_POST_VARS[$config_name]) ) ? $HTTP_POST_VARS[$config_name] : $default_config[$config_name]; 367 368 if ($config_name == 'cookie_name') 369 { 370 $cookie_name = str_replace('.', '_', $new['cookie_name']); 371 } 372 373 if( isset($HTTP_POST_VARS['submit']) ) 374 { 375 $sql = "UPDATE " . $_SESSION['prefix'] . "_bbconfig SET 376 config_value = '" . str_replace("\'", "''", $new[$config_name]) . "' 377 WHERE config_name = '$config_name'"; 378 if( !mysql_query($sql) ) 379 { 380 $error .="<tr><td align=center>" . $install_lang['update_fail'] . " $config_name <br />" . mysql_error() . "</td></tr>"; 381 return $error; 382 } 383 if($config_name == "server_name") { 384 $sql = "UPDATE " . $_SESSION['prefix'] . "_config SET 385 nukeurl = 'http://" . str_replace("\'", "''", $new[$config_name]) . "'"; 386 if( !mysql_query($sql) ) 387 { 388 $error .="<tr><td align=center>" . $install_lang['update_fail'] . " $config_name <br />" . mysql_error() . "</td></tr>"; 389 return $error; 390 } 391 } 392 } 393 } 394 if (!empty($display)) { 395 $form .=" <tr><td align=\"center\" width=50%><strong>" . $install_lang['sitename'] . "</strong></td> <td align=\"center\" width=50%><input type=text length=60 value=\"http://".$_SERVER["SERVER_NAME"]."\" name=\"sitename\"></td></tr>"; 396 397 $form .=" <tr><td align=\"center\" width=50%><strong>" . $install_lang['sitedescr'] . "</strong></td> <td align=\"center\" width=50%><input type=text length=60 value=\"$new[site_desc]\" name=\"site_desc\"></td></tr>"; 398 399 $form .=" <tr><td align=\"center\" width=50%><strong>" . $install_lang['cookie_name'] . "</strong></td> <td align=\"center\" width=50%><input type=text length=60 value=\"$new[cookie_name]\" name=\"cookie_name\"></td></tr>"; 400 401 $form .=" <tr><td align=\"center\" width=50%><strong>" . $install_lang['cookie_path'] . "</strong></td> <td align=\"center\" width=50%><input type=text length=60 value=\"$new[cookie_path]\" name=\"cookie_path\"></td></tr>"; 402 $form .=" <tr><td align=\"center\" width=50%><strong>" . $install_lang['cookie_domain'] . "</strong></td> <td align=\"center\" width=50%><input type=text length=60 value=\"".$_SERVER["HTTP_HOST"]."\" name=\"cookie_domain\"></td></tr>"; 403 $namechange_checked = ($new['allow_namechange']) ? "checked" : ""; 404 $namechange_not_checked = (!$new['allow_namechange']) ? "checked" : ""; 405 $form .=" <tr><td align=\"center\" width=50%><strong>" . $install_lang['namechange'] . "</strong></td> <td align=\"center\" width=50%>" . $install_lang['yes'] . " <input type=radio value=\"1\" name=\"allow_namechange\" $namechange_checked> " . $install_lang['no'] . " <input type=radio value=\"0\" name=allow_namechange $namechange_not_checked></td></tr>"; 406 $form .=" <tr><td align=\"center\" width=50%><strong>" . $install_lang['email_sig'] . "</strong></td> <td align=\"center\" width=50%><textarea name=board_email_sig>$new[board_email_sig]</textarea></td></tr>"; 407 408 $form .=" <tr><td align=\"center\" width=50%><strong>" . $install_lang['site_email'] . "</strong></td> <td align=\"center\" width=50%><input type=text name=\"board_email\" value=\"".$new[board_email]."\"></td></tr>"; 409 $form .=" <tr><td align=\"center\" width=50%><strong>" . $install_lang['default_lang'] . "</strong></td> <td align=\"center\" width=50%>" . language_select('english', 'default_lang') . "</td></tr>"; 410 $form .=" <tr><td align=\"center\" width=50%><strong>" . $install_lang['server_name'] . "</strong></td> <td align=\"center\" width=50%><input type=text name=\"server_name\" value=\"".$_SERVER["SERVER_NAME"]."\"></td></tr>"; 411 $form .=" <tr><td align=\"center\" width=50%><strong>" . $install_lang['server_port']. "</strong></td> <td align=\"center\" width=50%><input type=text name=\"server_port\" value=\"".$new[server_port]."\"></td></tr>"; 412 413 return $form; 414 } else { 415 return; 416 } 417 } 418 419 ?>