Pages vues depuis 25/05/2001 : 104 311 468
Index du forum »» Pour débuter »» afficher un scrip en php dans un bloc
<?php
/*
Copyright (C) 2004 Niklas Håkansson <niklas.hk@telia.com>
Mod by Timo Meyer-Franke <www.forum.meyer-franke.de.vu>
This script is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public.
If you want to change the HTML layout then only alter in functions
getTSInfo() and setTSUsers(). No other functions need to altered.
*/
!include! "common.php";
/*****************************************************
* Telnet Connection
*****************************************************/
function TSConn($ip,$port,$tPort)
{
$result = "";
$err = array();
if(strlen($ip)>4 and strlen($tPort)>2 and strlen($port)>2) {
$fp = fsockopen($ip, $tPort, $errno, $errstr, 30);
if($fp) {
fputs($fp, "sel ".$port."\n");
fputs($fp, "si\n");
fputs($fp, "quit\n");
while(!feof($fp)) {
$out .= fgets($fp, 1024);
}
$out = str_replace("[TS]", "", $out);
$out = str_replace("\n", "", $out);
$data = explode("\t", $out);
$err = explode(",", $data[0]);
}
}
if(strlen($err[0])>6) $result = "true";
return $result;
}
/*****************************************************
* User information
*****************************************************/
function getTSChannelUsers($ip,$port,$tPort)
{
$uArray = array();
$innerArray = array();
$out = "";
$j = 0;
$k = 0;
$fp = fsockopen($ip, $tPort, $errno, $errstr, 30);
if($fp) {
fputs($fp, "pl ".$port."\n");
fputs($fp, "quit\n");
while(!feof($fp)) {
$out .= fgets($fp, 1024);
}
$out = str_replace("[TS]", "", $out);
$out = str_replace("loginname", "loginname\t", $out);
$data = explode("\t", $out);
$num = count($data);
for($i=0;$i<count($data);$i++) {
$innerArray[$j] = $data[$i];
if($j>=15)
{
$uArray[$k]=$innerArray;
$j = 0;
$k = $k+1;
} else {
$j++;
}
}
fclose($fp);
}
return $uArray;
}
/*****************************************************
* Get all channels
*****************************************************/
function getChannels($ip,$port,$tPort)
{
$cArray = array();
$out = "";
$j = 0;
$k = 0;
$fp = fsockopen($ip, $tPort, $errno, $errstr, 30);
if($fp) {
fputs($fp, "cl ".$port."\n");
fputs($fp, "quit\n");
while(!feof($fp)) {
$out .= fgets($fp, 1024);
}
$out = str_replace("[TS]", "", $out);
$out = str_replace("\n", "\t", $out);
$data = explode("\t", $out);
$num = count($data);
for($i=0;$i<count($data);$i++) {
if($i>=10) {
$innerArray[$j] = $data[$i];
if($j>=8)
{
$cArray[$k]=$innerArray;
$j = 0;
$k = $k+1;
} else {
$j++;
}
}
}
fclose($fp);
}
return $cArray;
}
/*****************************************************
* Set used ID:s
*****************************************************/
function usedID($usedArray,$id)
{
$ok = true;
for($i=0;$i<count($usedArray);$i++)
{
if($usedArray[$i]==$id) {
$ok = false;
}
}
return $ok;
}
/*****************************************************
* Get channel name
*****************************************************/
function getChannelName($id,$ip,$port,$tPort)
{
$name = "Uknown";
$cArray = getChannels($ip,$port,$tPort);
for($i=0;$i<count($cArray);$i++)
{
$innerArray=$cArray[$i];
if($innerArray[0]==$id)
$name = removeChar($innerArray[5]);
}
return $name;
}
/*****************************************************
* Channel sorting by name
*****************************************************/
function newSort($cArray)
{
$tmpArray = array();
$newArray = array();
for($i=0;$i<count($cArray);$i++)
{
$innerArray = $cArray[$i];
$tmpArray[count($tmpArray)] = $innerArray[5];
}
sort($tmpArray);
for($i=0;$i<count($tmpArray);$i++)
{
for($j=0;$j<count($cArray);$j++)
{
$innerArray = $cArray[$j];
if($tmpArray[$i] == $innerArray[5])
{
$thisArray[0] = $innerArray[0];
$thisArray[1] = $innerArray[5];
$thisArray[2] = $innerArray[2];
$thisArray[3] = $innerArray[3];
$newArray[count($newArray)] = $thisArray;
}
}
}
return $newArray;
}
/*****************************************************
* Channel and user info
*****************************************************/
function getTSChannelInfo($ip,$port,$tPort)
{
$uArray = getTSChannelUsers($ip,$port,$tPort);
$pcArray = array();
$ccArray = array();
$thisArray = array();
$listArray = array();
$usedArray = array();
$cArray = getChannels($ip,$port,$tPort);
$z = 0;
$x = 0;
for($i=0;$i<count($cArray);$i++)
{
$innerArray=$cArray[$i];
$listArray[$i]=$innerArray[3];
}
sort($listArray);
$cArray = newSort($cArray);
for($i=0;$i<count($listArray);$i++)
{
for($j=0;$j<count($cArray);$j++)
{
$innArray=$cArray[$j];
if($innArray[3]==$listArray[$i] and usedID($usedArray,$innArray[0]))
{
if($innArray[2]==-1)
{
$thisArray[0] = $innArray[0];
$thisArray[1] = $innArray[1];
$thisArray[2] = $innArray[2];
$pcArray[$z] = $thisArray;
$usedArray[count($usedArray)] = $innArray[0];
$z++;
}
else
{
$thisArray[0] = $innArray[0];
$thisArray[1] = $innArray[1];
$thisArray[2] = $innArray[2];
$ccArray[$x] = $thisArray;
$usedArray[count($usedArray)] = $innArray[0];
$x++;
}
}
}
}
for($i=0;$i<count($pcArray);$i++) {
$innerArray=$pcArray[$i];
echo "<tr>\n";
echo " <td><img src=\"tsicons/channel.gif\" width=\"14\" height=\"15\" border=\"0\"></td>\n";
echo " <td class=\"bread\"><a href=\"!javascript!:LoginFenster('login.php?cName=".removeChar($innerArray[1])."')\" class=\"wrapCell\" !onclick!=\"vMenu(this,1,1)\" !onblur!=\"vMenu(this,0,1)\" !onmouse!over=\"!javascript!:window.status=''; return true;\"> ".removeChar($innerArray[1])."<font> ".getFlags($innerArray[0],$ip,$port,$tPort)."</font></a></td>\n";
echo "</tr>\n";
for($j=0;$j<count($ccArray);$j++) {
$innerCCArray=$ccArray[$j];
if($innerArray[0]==$innerCCArray[2]) {
echo "<tr>\n";
echo " <td></td>\n";
echo " <td class=\"bread\">\n";
echo " <table cellpadding=\"1\" cellspacing=\"0\">\n";
echo " <tr>\n";
echo " <td><img src=\"tsicons/channel.gif\" width=\"14\" height=\"15\" border=\"0\"></td>\n";
echo " <td class=\"bread\"><a href=\"!javascript!:LoginFenster('login.php?cName=".removeChar($innerCCArray[1])."')\" class=\"wrapCell\" !onclick!=\"vMenu(this,1,1)\" !onblur!=\"vMenu(this,0,1)\" !onmouse!over=\"!javascript!:window.status=''; return true;\"><font> ".removeChar($innerCCArray[1])." </font></a></td>\n";
echo " </tr>\n";
for($p=1;$p<count($uArray);$p++) {
$innerUArray=$uArray[$p];
if($innerCCArray[0]==$innerUArray[1])
{
echo " <tr>\n";
echo " <td></td>\n";
echo " <td>\n";
echo " <table cellpadding=\"1\" cellspacing=\"0\">\n";
echo " <tr>\n";
echo " <td>".setUserStatus($innerUArray[12])."</td>\n";
echo " <td class=\"bread\"> ".removeChar($innerUArray[14])."<font> (".setPPriv($innerUArray[11])."".setCPriv($innerUArray[10]).") </font></td>\n";
echo " </tr>\n";
echo " </table>\n";
echo " </td>\n";
echo " </tr>\n";
}
}
echo " </table>\n";
echo "</tr>\n";
}
}
for($k=1;$k<count($uArray);$k++) {
$innerUArray=$uArray[$k];
if($innerArray[0]==$innerUArray[1]) {
echo "<tr>\n";
echo " <td></td>\n";
echo " <td class=\"bread\">\n";
echo " <table cellpadding=\"1\" cellspacing=\"0\">\n";
echo " <tr>\n";
echo " <td>".setUserStatus($innerUArray[12])."</td>\n";
echo " <td class=\"bread\"> ".removeChar($innerUArray[14])."</b><font> (".setPPriv($innerUArray[11])."".setCPriv($innerUArray[10]).") </font></td>\n";
echo " </tr>\n";
echo " </table>\n";
echo "</tr>\n";
}
}
}
}
/*****************************************************
* Channel flags
*****************************************************/
function getFlags($cid,$ip,$port,$tPort)
{
$out = "";
$flag = "U";
$cArray = array();
$j = 0;
$k = 0;
$fp = fsockopen($ip, $tPort, $errno, $errstr, 30);
if($fp) {
fputs($fp, "cl ".$port."\n");
fputs($fp, "si\n");
fputs($fp, "quit\n");
while(!feof($fp)) {
$out .= fgets($fp, 1024);
}
fclose($fp);
$out = str_replace("[TS]", "", $out);
$out = str_replace("\n", "\t", $out);
$data = explode("\t", $out);
$num = count($data);
for($i=0;$i<count($data);$i++) {
if($i>=10) {
$innerArray[$j] = $data[$i];
if($j>=8)
{
$cArray[$k]=$innerArray;
$j = 0;
$k = $k+1;
} else {
$j++;
}
}
}
for($i=0;$i<count($cArray);$i++) {
$innArray = $cArray[$i];
if($cid==$innArray[0])
{
$cid = setChannelFlags($innArray[6]);
}
}
}
return $cid;
}
/*****************************************************
* Channel default info
*****************************************************/
function defaultInfo($ip,$tPort,$port)
{
$out = "";
$html = "";
$fp = fsockopen($ip, $tPort, $errno, $errstr, 30);
if($fp) {
fputs($fp, "sel ".$port."\n");
fputs($fp, "si\n");
fputs($fp, "quit\n");
while(!feof($fp)) {
$out .= fgets($fp, 1024);
}
$out = str_replace("[TS]", "", $out);
$out = str_replace("OK", "", $out);
$out = trim($out);
$name=substr($out,indexOf($out,"server_name="),strlen($out));
$name=substr($name,0,indexOf($name,"server_platform=")-strlen("server_platform="));
$os=substr($out,indexOf($out,"server_platform="),strlen($out));
$os=substr($os,0,indexOf($os,"server_welcomemessage=")-strlen("server_welcomemessage="));
$tsType=substr($out,indexOf($out,"server_clan_server="),strlen($out));
$tsType=substr($tsType,0,indexOf($tsType,"server_udpport=")-strlen("