PageRenderTime 27ms CodeModel.GetById 7ms RepoModel.GetById 0ms app.codeStats 0ms

/INSTALL/user.inc

https://code.google.com/p/nuked-klan/
PHP | 100 lines | 94 code | 6 blank | 0 comment | 19 complexity | bd4710177c9c20e235738d21fa52ad43 MD5 | raw file
Possible License(s): GPL-3.0, BSD-3-Clause, GPL-2.0, LGPL-3.0, LGPL-2.1
  1. <?php
  2. function nk_hash($hash, $pass, $decal = null){
  3. $builder = '';
  4. $decal = $decal === null?rand(0, 15):$decal;
  5. $pass = sha1($pass);
  6. for ($i = 0; $i < strlen($pass) * 2; $i++){
  7. if ($i % 2 == 0){
  8. $builder .= $pass[$i / 2];
  9. }
  10. else{
  11. $builder .= substr($hash , ($i / 2 + $decal) % 20, 1);
  12. }
  13. }
  14. return '#'.dechex($decal).md5($builder);
  15. }
  16. function saveConfig($type){
  17. if($type == 'install'){
  18. $_SESSION['hash'] = addslashes(@sha1(uniqid(''), true));
  19. $pass = nk_hash($_SESSION['hash'] , $_REQUEST['pass']);
  20. $date = time();
  21. $ip = $_SERVER['REMOTE_ADDR'];
  22. $taille = 20;
  23. $lettres = "abCdefGhijklmNopqrstUvwXyz0123456789";
  24. srand(time());
  25. $pseudo = htmlentities($_REQUEST['pseudo'], ENT_QUOTES);
  26. $user_id = '';
  27. for ($i=0;$i<$taille;$i++){
  28. $user_id .= substr($lettres,(rand()%(strlen($lettres))), 1);
  29. }
  30. $mail = $_REQUEST['mail'];
  31. mysql_query('TRUNCATE TABLE `'.$_SESSION['db_prefix'].'_users`');
  32. mysql_query("INSERT INTO `".$_SESSION['db_prefix']."_users` VALUES ('".$user_id."', '', '', '', '', '', '" .$pseudo."', '".$mail."', '', '', '', '', '', '', '".$pass."', 9, '".$date."', '', '', '', '', 1, 'France.gif', '', '', '', '0')");
  33. mysql_query("INSERT INTO `".$_SESSION['db_prefix']."_news` VALUES (1, 1, '"._FIRSTNEWSTITLE."', '".$pseudo."', '".$user_id."', '"._FIRSTNEWSCONTENT."', '', '".$date."', '', '')");
  34. mysql_query("INSERT INTO `".$_SESSION['db_prefix']."_shoutbox` VALUES (1, '".$pseudo. "', '".$ip."', '" . _FIRSTNEWSTITLE . "', '".$date."')");
  35. mysql_query("UPDATE `".$_SESSION['db_prefix']."_config` SET value = '".$mail."' WHERE name = 'contact_mail'");
  36. mysql_query("UPDATE `".$_SESSION['db_prefix']."_config` SET value = '".$mail."' WHERE name = 'mail'");
  37. }
  38. if (@extension_loaded('zlib') && !@ini_get('zlib.output_compression') && @phpversion() >= "4.0.4" && stripos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip')) define('GZIP_COMPRESS', 'true');
  39. else define('GZIP_COMPRESS', 'false');
  40. $content="<?php\n"
  41. . "//-------------------------------------------------------------------------//\n"
  42. . "// Nuked-KlaN - PHP Portal //\n"
  43. . "// http://www.nuked-klan.org //\n"
  44. . "//-------------------------------------------------------------------------//\n"
  45. . "// This program is free software. you can redistribute it and/or modify //\n"
  46. . "// it under the terms of the GNU General Public License as published by //\n"
  47. . "// the Free Software Foundation; either version 2 of the License. //\n"
  48. . "//-------------------------------------------------------------------------//\n"
  49. . "\$nk_version = '1.7.9';\n"
  50. . "\n"
  51. . "\$global['db_host'] = '".$_SESSION['host']."';\n"
  52. . "\$global['db_user'] = '".$_SESSION['user']."';\n"
  53. . "\$global['db_pass'] = '".$_SESSION['pass']."';\n"
  54. . "\$global['db_name'] = '".$_SESSION['db_name']."';\n"
  55. . "\$db_prefix = '".$_SESSION['db_prefix']."';\n"
  56. . "\n"
  57. . "define('NK_INSTALLED', true);\n"
  58. . "define('NK_OPEN', true);\n"
  59. . "define('NK_GZIP', " . GZIP_COMPRESS . ");\n"
  60. . "// NE PAS SUPPRIMER! / DO NOT DELETE\n"
  61. . "define('HASHKEY', '".$_SESSION['hash']."');\n"
  62. . "\n"
  63. . "?>";
  64. $path = dirname(dirname(__FILE__)).'/';
  65. @chmod ($path.'conf.inc.php', 0666);
  66. @chmod ($path, 0755);
  67. $errors = 0;
  68. $_SESSION['content'] = $content;
  69. if (is_writable($path.'conf.inc.php') || (!file_exists($path.'conf.inc.php') && is_writable($path))){
  70. try{
  71. $fp = @fopen($path.'conf.inc.php', 'w');
  72. if(!@fwrite($fp, $content)) $errors++;
  73. if(!@fclose($fp)) $errors++;
  74. if(!@chmod($path.'conf.inc.php', 0644)) throw new Exception ('CHMOD');
  75. if(!@copy($path.'conf.inc.php', $path.'config_save_'.date('%Y%m%d%H%i').'.php')) throw new Exception ('COPY');
  76. }
  77. catch(exception $e){
  78. $_SESSION['content_web'] = nl2br(htmlentities($content));
  79. return $e->getMessage();
  80. }
  81. if($errors > 0){
  82. $_SESSION['content_web'] = nl2br(htmlentities($content));
  83. return 'CONF.INC';
  84. }
  85. else{
  86. return true;
  87. }
  88. }
  89. else{
  90. $_SESSION['content_web'] = nl2br(htmlentities($content));
  91. return 'CONF.INC';
  92. }
  93. }
  94. ?>