<?php
// полезные проверки
  function rep($strin) {
      if(!empty($strin)) {
       $in_wrd = array("select","update","insert","delete","truncate","create","drop","where","and"," or ","like","`","&amp;quote;","ascii","substring","between","union");
       $out_wrd = array("CELECT","APDATE","ENSERT","TELETE","DRUNCATE","GREATE","TROP","VHERE","ANND"," AR ","LICKE","&lsquo;","&quote;","ASKII","SUBSTRINK","BEETWEEN","UNNION");
       $strin = trim($strin);
       $strin = htmlspecialchars(stripslashes($strin));
       $strin = str_ireplace($in_wrd,$out_wrd,$strin);
       return $strin;
      }
   }

// выводим ошибки
function puterror($tema,$message) {
  if(!empty($tema)) {echo ("<table align='center' border='0'><tr><td><img alt='stop' src='../skins/".$tema."/stop.png' /></td><td align='left'><span class='bold_it'>".$message."</span></td></tr></table>");}
   else {echo ("<table align='center' border='0'><tr><td><img alt='stop' src='../skins/base/stop.png' /></td><td align='left'><span class='bold_it'>".$message."</span></td></tr></table>");}
 }

  function puterror2($tema,$message) {
     if(!empty($tema)) {echo ("<table align='center' border='0'><tr><td><img alt='stop' src='skins/".$tema."/stop.png' /></td><td align='left'><span class='bold_it'>".$message."</span></td></tr></table>");}
      else {echo ("<table align='center' border='0'><tr><td><img alt='stop' src='skins/base/stop.png' /></td><td align='left'><span class='bold_it'>".$message."</span></td></tr></table>");}
  }

  function puterrorclr($message)
  {
    echo("<table align='center' border='0'><tr align='center' ><td><img alt='stop' align=middle src='../skins/base/stop.png'></td></tr><tr align='center' ><td><span class='bold_it'>".$message."</span></td></tr></table>");
    exit();
  }

  function puterrorclr2($message)
  {
    echo("<table align='center' border='0'><tr align='center' ><td><img alt='stop' align=middle src='skins/base/stop.png'></td></tr><tr align='center' ><td><span class='bold_it'>".$message."</span></td></tr></table>");
    exit();
  }

function putwait($tema,$message) {
  if(!empty($tema)) {echo ("<table align='center' border='0'><tr><td><img alt='stop' src='../skins/".$tema."/chronometer.png' /></td><td align='left'><span class='bold_it'>".$message."</span></td></tr></table>");}
   else {echo ("<table align='center' border='0'><tr><td><img alt='stop' src='../skins/base/chronometer.png' /></td><td align='left'><span class='bold_it'>".$message."</span></td></tr></table>");}
 }

function putwait2($tema,$message) {
  if(!empty($tema)) {echo ("<table align='center' border='0'><tr><td><img alt='stop' src='skins/".$tema."/chronometer.png' /></td><td align='left'><span class='bold_it'>".$message."</span></td></tr></table>");}
   else {echo ("<table align='center' border='0'><tr><td><img alt='stop' src='skins/base/chronometer.png' /></td><td align='left'><span class='bold_it'>".$message."</span></td></tr></table>");}
 }
# Wake on LAN - (c) HotKey@spr.at, upgraded by Murzik
# Modified by Allan Barizo http://www.hackernotcracker.com
# Modified by perepugun
function WakeOnLan($addr,$mac,$socket_number) {
  $addr_byte = explode(':',$mac);
  $hw_addr = '';
  for($a=0; $a <6; $a++) {$hw_addr .= chr(hexdec($addr_byte[$a]));}
  $msg = chr(255).chr(255).chr(255).chr(255).chr(255).chr(255);
  for($a = 1; $a <= 16; $a++) {$msg .= $hw_addr;}
  // send it to the broadcast address using UDP
  // SQL_BROADCAST option isn't help!!
  $s = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
  if($s == false) {
	echo "Error creating socket!\n";
	echo "Error code is ".socket_last_error($s)." - ".socket_strerror(socket_last_error($s));
	return FALSE;
	}
  else {
	// setting a broadcast option to socket:
        // for windows
        // $opt_ret = socket_set_option($s, SOL_SOCKET, SO_BROADCAST, 1);
	$opt_ret = socket_set_option($s, 1, 6, TRUE);
	if($opt_ret <0) {
	  echo "setsockopt() failed, error: ".strerror($opt_ret)."\n";
	  return FALSE;
	  }
	if(socket_sendto($s, $msg, strlen($msg), 0, $addr, $socket_number)) {
	  echo "Magic Packet on address ".$addr." successfully sended!<br />";
	  socket_close($s);
	  return TRUE;
	  }
	else {
	  echo "Magic packet failed!";
	  return FALSE;
	  }
	}
  }
  // Проверка наличия обновлений
  function update_check($url,$proxy) {
     if(!empty($url)) {
      if(trim($proxy) !== "") {
       $opts = array('http' => array('proxy' => $proxy, 'request_fulluri' => true));
       $context = stream_context_create($opts);
       $open_upd_file = file_get_contents($url, false, $context);
       } else {$open_upd_file = file_get_contents($url);}
        if(!$open_upd_file) {$upd_line = "";}
         else {$upd_line = $open_upd_file;}
         //fclose($open_upd_file);
         return $upd_line;
         }
    }
?>