Advertisement
Guest User

Processing page

a guest
Feb 14th, 2015
303
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 8.31 KB | None | 0 0
  1. if($_SERVER["REQUEST_METHOD"] == "POST" && $_GET['direct'] == "login"){ //session hash required
  2. //for reference, $_MONITORED is a sanitized session, and $_SPIN/$_DATA and $_FILTERED are sanitized post and get queries respectively
  3.  
  4.  
  5. $mas1 = mysqli_query($db_main, "SELECT * FROM users WHERE username='$_DATA[usernorm]'"); //call it
  6. $mas2 = mysqli_fetch_assoc($mas1);
  7. foreach($mas2 as $keyn => $valuen){
  8. $mn[$keyn] = $valuen;
  9. }      
  10.  
  11. $nick = hash('sha512',$mn['salt'] . $_SPIN['pwrdnorm']);
  12. $gravy = substr($nick, 0, 40);  //make a nice meal
  13.  
  14. /*criteria to stop XSS and brute force attacks:
  15. - Stop consequent logins at X
  16. - filter characters
  17.  
  18. in this case I am going to have a reset of all login_attempt logs in the database each refresh after an hour from the last login attempt. I should probably set it to where you could only have one login attempt per hour on an account if you failed logging in more than 5 times within an hour. That's a little paranoid though
  19. */    
  20.  //reset login attempts
  21.    
  22. $difference = (time() - strtotime($mas2['login_att_last']));
  23. $dialdown = round($difference / 3600);
  24. if($difference >= 18000) {$dialdown = 0; }
  25. mysqli_query($db_main, "UPDATE users SET login_attempts='$dialdown' WHERE username='$mas2[username]'");    
  26.  
  27.                
  28.  
  29. if($mas2['login_attempts'] < 5){  
  30. if(compare_dz($gravy,$mn['password'])){ //successful log in    
  31. $_SESSION['login_q'] = $_SPIN['usernorm'];
  32. $_SESSION['salt_q'] = $mn['password'];
  33. $_SESSION['db_query'] = "user login";
  34. setcookie("limbooo[0]", "k", time()+1);
  35. /*  */ redir_process("Location: index.php?phase=2"); /*  */
  36. }else{
  37.  
  38. if($mas1){ //login attempts for valid usernames    
  39. $mas3 = ($mas2['login_attempts'] == "0") ? "1" : $mas2['login_attempts']+1;
  40. $mas4 = mysqli_real_escape_string($db_main, $mas3);
  41.  
  42. $ns = mysqli_query($db_main, "UPDATE users SET login_attempts=".$mas4.",login_att_last=now() WHERE username='$mas2[username]'"); // for some weird reason login_attempts is getting edited too  
  43.  
  44. if(!$ns){
  45. $_SESSION['que_em'] = mysqli_error($db_main);
  46. }
  47. $_SESSION['log_num'] = $mas3;
  48. setcookie("inc_ombination", "Incorrect user/password combination", time()+1);      
  49. }
  50.  
  51.  $_SESSION['error' .rand(56,1515)] = extraurl();
  52. }
  53.    
  54.  
  55. }else{setcookie("inc_ombination", "This account is temporarily locked. Please wait no more than an hour to log in again.", time()+1);
  56.  
  57. /*  */ redir_process("Location: index.php"); /*  */
  58. $_SESSION['error' .rand(56,1515)] = extraurl();      //Don't want to get it further than that. Such lazy
  59. }
  60.  
  61.  mysqli_free_result($mas1);
  62. }
  63.  
  64. if($_SERVER["REQUEST_METHOD"] == "POST" && $_GET['direct'] == "new_post"){ //actual posts
  65.  
  66. if(count($_SPIN) > 30){  $_SESSION['error' .rand(56,1515)] = "Nice try DDOS's at ".extraurl();
  67. redir_process("Location:index.php");}   //counter against ddos's
  68. foreach($_SPIN as $key => $value){             //check for all the snowglobes they want to post in
  69. if(preg_match("#^sg[_]#",$key) && $_SPIN[$key] == "on"){  $matched[$key] = preg_replace("/^sg_([-_A-Za-z0-9]+)$/","$2",$key);                                              
  70. if(!isset($snowglobes)){$snowglobes = $matched[$key];}else{$snowglobes = $snowglobes . "," . $matched[$key];}}         }
  71. //snowglobe settings are by default for each individual snowglobe's setting, snowglobe permissions are custom and set by its admin or moderators.
  72. //has to be a valid post. At least one snowglobe, and not match the default text or be empty. If it's a reply, i'll set it accordingly
  73. //access_type under snowglobe permissions will be matched with id under snowglobe settings
  74. if(isset($snowglobes) || isset($_SPIN['parent_comment'])){  //check to see if it's either a new thread or a comment
  75. // $pass_check = mysqli_query($db_main, "SELECT * FROM ")
  76. $_SPIN['tcha1'] = isset($_SPIN['tcha1']) ? $_SPIN['tcha1'] : " ";
  77. $thread_nick = mysqli_real_escape_string($db_main,strtolower(substr(preg_replace("#[^_A-Za-z 0-9-]#","",preg_replace("# #","_",$_SPIN['tcha1'])), 0, 50)));
  78. $topic_hash = mysqli_real_escape_string($db_main,substr(sha1(microtime()),0,10));
  79. $_SESSION['db_query'] = "posted content-anything";
  80.  setcookie("limbooo[0]", "k", time()+1);  
  81. if(isset($snowglobes)){//if posting a new thread
  82. //check sg_settings first
  83. //for each one
  84.  
  85. foreach($matched as $key => $value){    $ze = preg_match("#^[-_A-Za-z0-9]{4,}$#",$value);
  86.  
  87. if($value == "1" || $ze === 1){
  88.  
  89. if($ze === 1){ //check for snowglobe permissions
  90. $snowglobe_search = mysqli_query($db_main,"SELECT * FROM snowglobes WHERE sg_name='".hack_free($value)."'");
  91. if(mysqli_num_rows($snowglobe_search) > 0){$sg_details = mysqli_fetch_assoc($snowglobe_search);
  92. if($sg_details['sg_privacy'] == "private"){  //cross-reference to a snowglobe permission
  93. $sg_perm_check = mysqli_query($db_main, "SELECT * FROM sg_permissions WHERE granted_by='".hack_free($value)."' AND towhom='$_MONITORED[login_q]' AND (snowglobe_access = 'root admin' OR snowglobe_access = 'normal snowglobe')");
  94. if(mysqli_num_rows($sg_perm_check) == 0){redir_process("Location:index.php");}
  95.  
  96. }
  97. }else{redir_process("Location:index.php");}
  98. }
  99.  
  100.  
  101.  //users posting into their own snowglobe
  102.  
  103. if((preg_match("#^(.){3,150}$#", $_SPIN['tcha1']) === 0) || strlen($_SPIN['tcha2']) > 65335 || ($_POST['tcha1'] == $nx['17']) || $_POST['tcha2'] == $nx['18']){ $_SESSION['error' .rand(56,1515)] = extraurl();/*  */ redir_process("Location:index.php"); /*  */  }
  104.  
  105.  
  106.  
  107. $post_submission = mysqli_query($db_main, "INSERT INTO posts(content,cnttype,forwhom,parent,postid,stamptime,bywhom,title,thread_nick,topic_hash) VALUES('$_DATA[tcha2]','1','self','0','0',CURRENT_TIMESTAMP,'$_MONITORED[login_q]','$_DATA[tcha1]','$thread_nick','$topic_hash')");      if($post_submission){
  108.  
  109. if(isset($_SPIN['poll_question'],$_SPIN['choice_addition'],$_SPIN['choice_selection'])){    //check if a poll was set
  110. $topic_search = mysqli_query($db_main, "SELECT * FROM posts WHERE bywhom='$_MONITORED[login_q]' ORDER BY stamptime DESC LIMIT 0,2");
  111. $search_dt = mysqli_fetch_assoc($topic_search);
  112. mysqli_query($db_main, "INSERT INTO polls(post_id_root,value,define_set) VALUES($search_dt[postid],'$_DATA[poll_question]','question')");
  113.  
  114. mysqli_query($db_main, "INSERT into polls(post_id_root,value,define_set) VALUES($search_dt[postid],'$_DATA[choice_selection]','choice_selection');");
  115.  
  116. mysqli_query($db_main, "INSERT into polls(post_id_root,value,define_set) VALUES($search_dt[postid],'$_DATA[choice_addition]','choice_addition');");
  117.  
  118. foreach($_DATA as $key => $value){
  119. if(preg_match("#^poll_choice([0-9]+)#",$key)){
  120. mysqli_query($db_main,"INSERT INTO polls(post_id_root,value,define_set) VALUES($search_dt[postid],'$value','poll_choice')");
  121. }}
  122.  
  123. }                  
  124.  
  125.        
  126.          }else{    echo mysqli_error($db_main);  }    
  127. }
  128.  
  129. }  
  130.  
  131. }      
  132.  
  133. if(isset($_SPIN['parent_comment'])){
  134. $tree_roots = mysqli_query($db_main, "SELECT * FROM posts WHERE postid='$_SPIN[parent_comment]'");
  135. $piece = mysqli_fetch_assoc($tree_roots);      //get parent of post. Just to recheck, ya know. That's right! For the settings! My goodness I work like a turtle.
  136. if($piece['settings'] > 4){  $_SESSION['error' .rand(56,1515)] = extraurl();mysqli_free_result($tree_roots);/*  */ redir_process("Location:index.php"); /*  */ }
  137.  
  138. $post_async = mysqli_query($db_main, "SELECT * FROM posts WHERE bywhom='$_MONITORED[login_q]' ORDER BY stamptime DESC LIMIT 0,10");
  139. $async_dt = mysqli_fetch_assoc($post_async); //get latest post for whatever reference you must.
  140.  
  141.  
  142. $post_nip = mysqli_query($db_main, "INSERT INTO posts(content,cnttype,forwhom,parent,postid,stamptime,bywhom,title,thread_nick,topic_hash,thread_id)
  143. VALUES('$_SPIN[tcha2]','2','n-a','$piece[postid]','0',CURRENT_TIMESTAMP,'$_MONITORED[login_q]','$_SPIN[tcha1]','$thread_nick','$topic_hash','$_DATA[thread_id]');");
  144. if($post_nip){mysqli_free_result($tree_roots);redir_process("Location:index.php?phase=2"); /*  */
  145.  
  146.  
  147. }else{
  148.  
  149. echo mysqli_error($db_main);
  150.  
  151. }
  152. }
  153.  /*  */ redir_process("Location:index.php?phase=2"); /*  */  
  154. }else{                                 $_SESSION['error' .rand(56,1515)] = "Failed to recognize snowglobe/reply parent at ". extraurl();
  155.  /*  */ redir_process("Location:index.php"); /*  */
  156. }
  157.  
  158. }            
  159.  
  160. }else{if(isset($_GET['verify']) && $_GET['verify'] !== $_SESSION['temp_n']){  $_SESSION['error' .rand(56,1515)] = "Failed session hash at ".extraurl();
  161.  /*  */ redir_process("Location:index.php"); /*  */  
  162. }}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement