Advertisement
Guest User

Untitled

a guest
Apr 29th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.03 KB | None | 0 0
  1. <?
  2.  
  3. #protection for sql injection by anakin - php5.pl
  4. $arrArguments = array();
  5. $intArgumentIndex = 0;
  6. function parseArgument($arrMatches) {
  7. global $arrArguments, $intArgumentIndex;
  8. $strMatch = $arrMatches[0];
  9. $strArgument = @$arrArguments[$intArgumentIndex++];
  10. if($strMatch=='%s' || $strMatch=='%m' || $strMatch=='%x'){
  11. if (get_magic_quotes_gpc()){
  12. $strArgument = stripslashes($strArgument);
  13. }
  14. }
  15. switch ($strMatch){
  16. case '%d': return (int)$strArgument;
  17. case '%f': return (float)$strArgument;
  18. case '%s': return '"'.mysql_real_escape_string($strArgument).'"';
  19. case '%m': return '"'.ubcode_add(mysql_real_escape_string($strArgument)).'"';
  20. case '%x': return '"'.comm_emo(mysql_real_escape_string($strArgument)).'"';
  21. case '%b': return (int)((bool)$strArgument);
  22. }
  23. }
  24.  
  25. function SQL($strSql) {
  26. global $arrArguments, $intArgumentIndex;
  27. $arrArgs = func_get_args();
  28. array_shift($arrArgs);
  29. $arrArguments = $arrArgs;
  30. $intArgumentIndex = 0;
  31. return preg_replace_callback('/(%[fdsbmx])/', 'parseArgument', $strSql);
  32. }
  33.  
  34. Function query($file,$function,$line,$qry,$typ=1){
  35. $rsl = @mysql_query($qry);
  36. $errno = mysql_errno();
  37. if($errno==0){
  38. return $rsl;
  39. }else{
  40. //turn off errors mailing when there is no mail or there are errors: 1016 {table doesnt exists} 2013 {lost connection with DB} 1053 {restart DB} 1045 {cannot connect with database wrong lg/ps} 1226 {User 'xxx' has exceeded the 'max_questions' resource}
  41. # if(strlen(ERROR_MAIL)>0 && $errno!=1016 && $errno!=2013 && $errno!=1053 && $errno!=1045 && $errno!=1226){
  42. $message = "FILE: ".$file."\nFUNCTION: ".$function."\nLINE: ".$line."\n\nQUERY: ".$qry."\nERROR:".mysql_error()."\nERR NO.:".$errno."\n";
  43. if(is_array($_POST)){
  44. if(count($_POST)>0){
  45. $message .= "\n".'$_POST'."\n";
  46. foreach($_POST as $ky=>$vl) $message .= "\n".$ky.'=>'.$vl;
  47. }
  48. }
  49. if(is_array($_GET)){
  50. if(count($_GET)>0){
  51. $message .= "\n".'$_GET'."\n";
  52. foreach($_GET as $ky=>$vl) $message .= "\n".$ky.'=>'.$vl;
  53. }
  54. }
  55. $message .= "\nIP:".$_SERVER['REMOTE_ADDR']."\nREQUEST:".$_SERVER['REQUEST_URI']."\nREFERER:".$_SERVER['HTTP_REFERER'];
  56. echo nl2br($message);
  57. # if(@mail(ERROR_MAIL, 'error', $message, "From: error@{$_SERVER['SERVER_NAME']}\r\n")){
  58. # if($typ==1) echo 'Error sent to author.';
  59. # }else{
  60. # echo 'Server can\'t send mail, please send message bellow manually on address <a href="mailto:'.ERROR_MAIL.'">'.ERROR_MAIL.'</a><br/><div class="italic">'.nl2br($message).'</div>';
  61. # }
  62. # }
  63. if($typ==1) exit;
  64. else return 'ER';
  65. }
  66. }
  67.  
  68. Function file_upl($plik_nazwa,$file_big,$big_ext,$dim_big='',$rozszerzenia='',$komunikat=0,$miniatura=0,$miniatura_nazwa='',$file_sml='',$sml_ext='',$dim_sml='',$proporcje=1){
  69. //change extenstion string case
  70. $big_ext = strtolower($big_ext);
  71. $sml_ext = strtolower($sml_ext);
  72. //check if file size is bigger then 0
  73. if($file_big['size']>0){
  74. //check if file extension is accaptable
  75. if(is_array($rozszerzenia)){
  76. if(!in_array($big_ext,$rozszerzenia)){
  77. if($komunikat) print('Rodzaj przes³anego pliku jest niedozwolony.<br />');
  78. return 0;
  79. }
  80. }
  81. #przeniesienie pliku z katalogu tymczasowego do wskazanego miejsca
  82. move_uploaded_file($file_big['tmp_name'],$plik_nazwa);
  83. #zmienienie uprawnieñ dostêpu do pliku
  84. chmod($plik_nazwa, 0755);
  85. if(file_exists($plik_nazwa)) $rtr = 1;
  86. if($komunikat){
  87. if(file_exists($plik_nazwa)) print('Plik dodany.<br />'); else print('Problem z dodaniem pliku.<br />');
  88. }
  89. }
  90. #sprawdzenie czy zosta³a wys³ana miniatura i dodanie jej do katalogu z miniaturami
  91. if($miniatura==1 || $miniatura==2){
  92. if($file_sml['size']>0){
  93. move_uploaded_file($file_sml['tmp_name'], $miniatura_nazwa);
  94. chmod($miniatura_nazwa, 0755);
  95. if(file_exists($miniatura_nazwa)) $rtr = 1;
  96. if($komunikat){
  97. if(file_exists($miniatura_nazwa)) print('Miniatura dodana.<br />'); else print('Problem z dodaniem miniatury.<br />');
  98. }
  99. }elseif($file_big['size']>0){
  100. if($miniatura==1){
  101. $sml_ext = $big_ext;
  102. $sml_ext = $big_ext;
  103. //przypisanie nazwy, rozszerzenia i katalogow z bigfile
  104. }
  105. $exp = explode(':',$dim_sml);
  106. $max_width = $exp[0];
  107. $max_height = $exp[1];
  108. #pobranie wymiarów du¿ego pliku
  109. if($proporcje==1){
  110. $size = GetImageSize($plik_nazwa);
  111. $width = $size[0];
  112. $height = $size[1];
  113. #ustalenie warto¶ci o które trzeba bêdzie pomniejszyæ zdjêcie
  114. $x_ratio = $max_width/$width;
  115. $y_ratio = $max_height/$height;
  116. #sprawdzenie które parametry trzeba zmieniæ
  117. if(($width<=$max_width) && ($height<=$max_height)){
  118. $new_width = $width;
  119. $new_height = $height;
  120. }elseif(($x_ratio*$height)<$max_height){
  121. $new_width = $max_width;
  122. $new_height = ceil($x_ratio*$height);
  123. }else{
  124. $new_width = ceil($y_ratio*$width);
  125. $new_height = $max_height;
  126. }
  127. }else{
  128. $new_width = $max_width;
  129. $new_height = $max_height;
  130. }
  131. #pobranie nazwy pliku i katalogu dla powiekszenia i miniatury
  132. $poz = strrpos($plik_nazwa, '/')+1;
  133. $plik = substr($plik_nazwa,$poz);
  134. $katalog = substr($plik_nazwa,0,$poz);
  135. $poz2 = strrpos($miniatura_nazwa, '/')+1;
  136. $plik2 = substr($miniatura_nazwa,$poz2);
  137. $katalog2 = substr($miniatura_nazwa,0,$poz2);
  138. #tworzenie miniatury
  139. $imageEditor = new ImageEditor($plik, $katalog);
  140. $imageEditor->resize($new_width, $new_height);
  141. $imageEditor->outputFile($plik2, $katalog2);
  142. if(file_exists($miniatura_nazwa)) $rtr = 1;
  143. if($komunikat==1){
  144. if(file_exists($miniatura_nazwa)) print('Miniatura utworzona.<br /><img src="'.$miniatura_nazwa.'"><br />'); else print('Problem z utworzeniem miniatury.<br />');
  145. }
  146. }
  147. }
  148. return $rtr;
  149. }
  150.  
  151. Function array_norm($array,$value){
  152. foreach($array as $vl){
  153. $return .= '<option';
  154. if($vl==$value) $return .= ' selected';
  155. $return .= '>'.$vl.'</option>';
  156. }
  157. return $return;
  158. }
  159.  
  160. Function array_assoc($array,$value){
  161. foreach($array as $ky=>$vl){
  162. $return .= '<option value="'.$ky.'"';
  163. if($ky==$value) $return .= ' selected';
  164. $return .= '>'.$vl.'</option>';
  165. }
  166. return $return;
  167. }
  168.  
  169. Function massoc_opt($array,$value){
  170. if(is_array($value)) $typ = 1; else $typ = 2;
  171. foreach($array as $ky=>$vl){
  172. $return .= '<option value="'.$ky.'"';
  173. if($typ==1){
  174. if(in_array($ky, $value)) $return .= ' selected';
  175. }else{
  176. if($ky==$value) $return .= ' selected';
  177. }
  178. $return .= '>'.$vl.'</option>';
  179. }
  180. return $return;
  181. }
  182.  
  183. Function radio_list($name,$array,$value,$spacer){
  184. foreach($array as $ky=>$vl){
  185. $str .= '<input type="radio" name="'.$name.'" value="'.$ky.'"';
  186. if($ky==$value) $str .= ' checked';
  187. $str .= ' /> '.$vl.$spacer;
  188. }
  189. return $str;
  190. }
  191.  
  192. Function checkbox_assoc($name,$array,$value,$spacer){
  193. foreach($array as $ky=>$vl){
  194. $str .= '<input type="checkbox" name="'.$name.'" value="'.$ky.'"';
  195. if($ky==$value) $str .= ' checked';
  196. $str .= '> '.$vl.$spacer;
  197. }
  198. return $str;
  199. }
  200.  
  201. Function intoDB($vl,$typ=''){
  202.  
  203. switch($typ){
  204. # case '%d': return (int)$vl;
  205. # case 'I': return '"'.mysql_real_escape_string($vl).'"';
  206. # case '%m': return '"'.ubcode_add(mysql_real_escape_string(nl2br($vl))).'"';
  207. # case '%x': return '"'.comm_emo(mysql_real_escape_string(nl2br($vl))).'"';
  208. case 'N': return SQL('%d', $vl);
  209. case 'F': return SQL('%f', $vl);
  210. default: return SQL('%s', $vl);
  211. }
  212. }
  213.  
  214. Function intoForm($vl,$type=1){
  215. if(get_magic_quotes_gpc()){
  216. $vl = stripslashes($vl);
  217. }
  218. if($type==1) $vl = htmlspecialchars($vl);
  219. return $vl;
  220. }
  221.  
  222. Function intoBrowser($vl,$type=1){
  223. if(get_magic_quotes_gpc()){
  224. $vl = stripslashes($vl);
  225. }
  226. if($type==1) $vl = htmlspecialchars($vl);
  227. return $vl;
  228. }
  229.  
  230. Function sqlGetKey($rsl){
  231. $row = mysql_fetch_assoc($rsl);
  232. if(mysql_num_rows($rsl)>0){
  233. foreach($row as $k=>$v){
  234. $ky = $k; break(0);
  235. }
  236. mysql_data_seek($rsl,0);
  237. }
  238. return $ky;
  239. }
  240.  
  241. Function getArray($inf,$gType=''){
  242. if(!$inf) return;
  243. $aType = 'X';
  244. $iType = gettype($inf);
  245. if(is_array($inf)) return $inf;
  246. elseif($iType=='resource' || eregi('SELECT(.*)FROM', $inf)){
  247. if($iType!='resource'){
  248. $rsl = query(__FILE__,__FUNCTION__,__LINE__,$inf,0);
  249. $cols = substr_count($inf, ',')+1;
  250. if($gType=='A') $ky = sqlGetKey($rsl);
  251. }else{
  252. $rsl = $inf;
  253. $ky = sqlGetKey($rsl);
  254. }
  255. $inf = array();
  256. if($gType=='A'){
  257. while($row=mysql_fetch_assoc($rsl)){
  258. $vl = $row[$ky];
  259. $aType = 'A';
  260. array_shift($row);
  261. $inf[$vl] = $row;
  262. }
  263. }else{
  264. while($row=mysql_fetch_row($rsl)){
  265. if(!$type){
  266. if($cols==2){
  267. $type = 2;
  268. $aType = 'A';
  269. }else $aType = 'N';
  270. }
  271. if($type==2) $inf[$row[0]] = $row[1];
  272. else $inf[] = $row[0];
  273. }
  274. }
  275. }else{
  276. $inf = explode("\n", $inf);
  277. $aType = 'N';
  278. }
  279. $return = array($inf,$aType);
  280. return $return;
  281. }
  282.  
  283. Function qry_into_array($qry,$rsl='',$typ='N'){
  284. if($typ=='A'){
  285. $qry = str_ireplace('SELECT ', '', $qry);
  286. $ky = trim(substr($qry, 0, strpos($qry, ',')));
  287. while($row=mysql_fetch_assoc($rsl)){
  288. $vl = $row[$ky];
  289. array_shift($row);
  290. $array[$vl] = $row;
  291. }
  292. }
  293. return $array;
  294. }
  295.  
  296. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement