Вопрос про fsockopen

Morf

Guest
Вопрос про fsockopen

Наконец таки я разобрался в отправке сообщений на NNTP сервер, на локалке все работает четко, но вот на хостинге пишет:

Warning: fsockopen(): unable to connect to news.sochi.ru:119 in /home/avto/public_html/inc/nntp_fns.php on line 33

С чем это связано? из того что на локалке пашет делаю вывод, что скрипт рабочий, значит на хостинге это расценивается как спам? или запрещено использование функции fsockopen()?

что можно сказать
 

BRat

o_0
удаленные соединения разрешены в принципе? проверь возможно ли получение файла с любого другого сервера при помощи fopen;
 

XiMiK

Новичок
это значит, что хост скрипту не видно
возможно его в каком-нибудь сегменте обрезает firewall
или такого хота не существует :), но раз на локалке пашет, значит отпадает

пиши в тех поддержку
 

Alexandre

PHPПенсионер
unable to connect to news.sochi.ru:119
возможно его в каком-нибудь сегменте обрезает firewall
возможно 119 порт, числится в "списке опасных", по этому его могут закрыть
и вообще, "правилом хорошего тона" является доступ на сервак из вне только по 80 порту,
все остальное отсекается :)
 

Morf

Guest
Автор оригинала: Alexandre
возможно 119 порт, числится в "списке опасных", по этому его могут закрыть
и вообще, "правилом хорошего тона" является доступ на сервак из вне только по 80 порту,
все остальное отсекается :)
Вот такой вот скрипт, может в нем что-то не так?

PHP:
<?
function textwrap($text, $wrap=80, $break="\n"){
  $len = strlen($text);
  if ($len > $wrap) {
    $h = '';        // massaged text
    $lastWhite = 0; // position of last whitespace char
    $lastChar = 0;  // position of last char
    $lastBreak = 0; // position of last break
    // while there is text to process
    while ($lastChar < $len) {
      $char = substr($text, $lastChar, 1); // get the next character
      // if we are beyond the wrap boundry and there is a place to break
      if (($lastChar - $lastBreak > $wrap) && ($lastWhite > $lastBreak)) {
        $h .= substr($text, $lastBreak, ($lastWhite - $lastBreak)) . $break;
        $lastChar = $lastWhite + 1;
        $lastBreak = $lastChar;
      }
      // You may wish to include other characters as valid whitespace...
      if ($char == ' ' || $char == chr(13) || $char == chr(10)) {
        $lastWhite = $lastChar; // note the position of the last whitespace
      }
      $lastChar = $lastChar + 1; // advance the last character position by one
    }
    $h .= substr($text, $lastBreak); // build line
  } else {
    $h = $text; // in this case everything can fit on one line
  }
  return $h;
}


function OpenNNTPconnection($server,$port) {
  $ns=fsockopen($server,$port);
  $weg=lieszeile($ns);  // kill the first line
  if (substr($weg,0,2) != "20") {
    $ns=false;
    echo "<p>&#206;&#248;&#232;&#225;&#234;&#224;1</p>";
  } else {
    if ($ns != false) {
      fputs($ns,"mode reader\r\n");
      $weg=lieszeile($ns);  // and once more
      if (substr($weg,0,2) != "20") {
        $ns=false;
        echo "<p>&#206;&#248;&#232;&#225;&#234;&#224;2</p>";
      }
    }
    
  }
  if ($ns == false) echo "connection_failed";
  return $ns;
}



/*
 * read one line from the NNTP-server
 */

function lieszeile(&$von) {
  if ($von != false) {
    $t=ereg_replace("\r\n$","",fgets($von,100000));
    return $t;
  }
}

/*
 * Close a NNTP connection
 *
 * $von: the handle of the connection
 */
function closeNNTPconnection(&$von) {
  if ($von != false) {
    fputs($von,"quit\r\n");
    fclose($von);
  }
}

/*
 * Post an article to a newsgroup
 *
 * $subject: The Subject of the article
 * $from: The authors name and email of the article
 * $newsgroups: The groups to post to
 * $ref: The references of the article
 * $body: The article itself
 */
function post($subject,$from,$newsgroups,$ref,$body) {
  
  global $send_poster_host;
  flush();
  $ns=OpenNNTPconnection('news.sochi.ru','119');
  if ($ns != false) {
    fputs($ns,"post\r\n");
    $weg=lieszeile($ns);
    fputs($ns,"Subject: $subject\r\n");
    fputs($ns,"From: $from\r\n");
    fputs($ns,"Sender: $from\r\n");
    fputs($ns,"Newsgroups: $newsgroups\r\n");
    fputs($ns,"Content-Type: text/plain; charset=koi8-r\r\n");
    fputs($ns,"Content-Transfer-Encoding: 8bit\r\n");
    fputs($ns,"User-Agent: NewsPortal 0.23\r\n");
    if ($send_poster_host)
      fputs($ns,"X-HTTP-Posting-Host: ".gethostbyaddr(getenv("REMOTE_ADDR"))."\r\n");
    if ($ref!=false) fputs($ns,"References: $ref\r\n");
    if (isset($organization)) fputs($ns,"Organization: $organization\r\n");
    if ((isset($file_footer)) && ($file_footer!="")) {
      $footerfile=fopen($file_footer,"r");
      $body.="\n".fread($footerfile,filesize($file_footer));
      fclose($footerfile);
    }
    $body=ereg_replace("\r",'',$body);
    $body=str_replace("\n.\n","\n..\n",$body);
    $b=split("\n",$body);
    $body="";
    for ($i=0; $i<count($b); $i++) {
      if ((strpos(substr($b[$i],0,strpos($b[$i]," ")),">") != false ) | (strcmp(substr($b[$i],0,1),">") == 0)) {
        $body .= textwrap(stripSlashes($b[$i]),78,"\r\n")."\r\n";
      } else {
        $body .= textwrap(stripSlashes($b[$i]),74,"\r\n")."\r\n";
      }
    }

    //----- Aqui es donde podriamos anadir la cadena que deseamos, siguiendo al body ------//
    $linea1="---------------------------------------------------------------------------";
    $linea2="         Message has been Posted from [url]www.AvtoSochi.com.ru[/url]";
    $linea3="---------------------------------------------------------------------------";

    $body = $body."\n\n".$linea1."\n".$linea2."\n".$linea3."\n";
    //-------------------------------------------------------------------------------------//

    fputs($ns,"\r\n".$body."\r\n.\r\n");
    $message=lieszeile($ns);
    closeNNTPconnection($ns);
  } else {
    $message="post_failed";
  }
  return $message;
}

?>
-~{}~ 17.03.05 11:12:

Ну помогите же мне, я представил функцию отправки, она работает на локалке и не работает на хостинге, где копать?
что не правильно может быть, очень нада
 
Сверху