<?php require_once('../../Connections/netboxManagerMitru.php'); ?>
<?
//phpinfo();
date_default_timezone_set('America/La_Paz');
$hora=date("H:i");
echo($hora."<br><br>");
?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

mysql_select_db($database_netboxManagerMitru, $netboxManagerMitru);
$query_APs = "SELECT * from ap_location where apl_reset_time='$hora'";
$APs = mysql_query($query_APs, $netboxManagerMitru) or die(mysql_error());
//$row_APs = mysql_fetch_assoc($APs);
$totalRows_APs = mysql_num_rows($APs);
?>
<?
function restartPort($switch, $user, $password, $puerto)
	{
	$connection = ssh2_connect($switch, 22); 
	ssh2_auth_password($connection,$user,$password);
	$stdio_stream = ssh2_shell($connection); 
	fwrite($stdio_stream,"configure terminal\n"); 
	sleep(1); 
	fwrite($stdio_stream,"interface ".$puerto."\n"); 
	sleep(1); 
	fwrite($stdio_stream,"power inline never\n"); 
	sleep(10); 
	fwrite($stdio_stream,"power inline auto\n"); 
	sleep(1); 
	fwrite($stdio_stream,"end\n"); 
	sleep(1); 
	fwrite($stdio_stream,"exit\n"); 
	sleep(1); 
	$output=stream_get_contents($stdio_stream);
	$output=str_replace("\n", "<br>", $output);
	return $output;
	}
?>
<?php while ($row_APs = mysql_fetch_assoc($APs)) { ?>
<?
echo(restartPort($row_APs['apl_sw_ip'], $row_APs['apl_sw_user'], $row_APs['apl_sw_pswd'], $row_APs['apl_port']));
echo("<br>-----------<br>");
?>
<?php }  ?>
<?php
mysql_free_result($APs);
?>
