<?php
include($_SERVER['DOCUMENT_ROOT'] .'/script/HeaderInc.php');
if('XMLHttpRequest' == $_SERVER['HTTP_X_REQUESTED_WITH'] && true === isset($_SESSION['SessionAuth']['id']) && 0 < $_SESSION['SessionAuth']['id']) {
  if(true === isset($_POST['portscanner_name']) && '' != $_POST['portscanner_name'] && true === isset($_POST['portscanner_b']) && true === is_numeric($_POST['portscanner_b'])){
    require_once("Net_Portscan/Portscan.php");
    $ArrPortScanner = array();
    if(true === isset($_POST['portscanner_e']) && true === is_numeric($_POST['portscanner_e'])){
      $result = Net_Portscan::checkPortRange($_POST['portscanner_name'], $_POST['portscanner_b'], $_POST['portscanner_e']);
      foreach ($result as $port => $element) {
        if ($element == NET_PORTSCAN_SERVICE_FOUND) {
          $ArrPortScanner[$port] = Net_Portscan::getService($port);
        }
      }
    }
    else{
      if (Net_Portscan::checkPort($_POST['portscanner_name'], $_POST['portscanner_b']) == NET_PORTSCAN_SERVICE_FOUND) {
        $ArrPortScanner[$_POST['portscanner_b']] = Net_Portscan::getService($_POST['portscanner_b']);
      }
    }
    if (true === is_array($ArrPortScanner) && 1 <= count($ArrPortScanner)){
      $smarty->assign('Arr', $ArrPortScanner);
      $VarReturn = $smarty->fetch('Utils/PortScanner/Result.tpl');
    }
    else{
      $VarReturn = $MS_SP->Sp_LangMessage['warning']['WarnSearchResultEmpty'];
    }
  }
  else{
    $VarReturn = $MS_SP->Sp_LangMessage['error']['ErrSettingWrong'];
  }
}
else{
  $VarReturn = $MS_SP->Sp_LangMessage['error']['ErrFuncAccessDenied'];
}
echo $VarReturn;
include($_SERVER['DOCUMENT_ROOT'] .'/script/FooterInc.php');
?>