This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

Request: Announcement from PHP.

Requests for complete scripts or modifications/fixes for scripts you didn't write. Response not guaranteed, and no thread bumping!
Post Reply
v
vsoemlio
Voice
Posts: 4
Joined: Sun Feb 18, 2007 11:48 am

Request: Announcement from PHP.

Post by vsoemlio »

Hello

I'm making a website, and when the PHP-script add's a new entry to the database, I want to have a snippet in the PHP that send a msg to my eggdrop.

Can someone make a easy script with a password protection. Also, the php needs to send a password to verify.

Thanks :)

Edit: Sorry for misunderstandings, but I'm actually requesting a TCL-script to communicate with PHP.

I have this PHP-script:

Code: Select all

<?php
$botip = "127.0.0.1";
$botport = "22739";

$socket = fsockopen ($botip, $botport, $error, $errorstr, 60);

$line = "Hei";

if ( $socket ) {
	while ( !feof($socket) ) {
		$str = fgets($socket, 4096);
		
		if ( strcmp($str, "go") ) {
				#$out .= substr( $str, strlen($control)+1 );
				fputs($socket, $line . "\n");
		}
	}
}

 fclose($socket);


?>
And this tcl script:

Code: Select all

listen 22739 script listener pub
 
proc listener {idx} {
   control $idx listenerin
   putdcc $idx "go\n"
}
 
proc listenerin {idx args} {
   putlog $args
   putserv "PRIVMSG #chan : $args"
}
When I run the php-script I got this in log:

Code: Select all

[17:44] Telnet connection: localhost/39894
[17:44] Timeout/EOF ident connection
[17:44] Hei
Why timeout?

I want to compare a password-string the php script sends to tcl in the tcl script, and only allow scripts with the correct password.
Last edited by vsoemlio on Thu Feb 07, 2008 12:45 pm, edited 3 times in total.
t
tueb
Halfop
Posts: 76
Joined: Thu Oct 04, 2007 6:09 am
Location: #quiz.de @ irc.gamesurge.net
Contact:

Post by tueb »

hi,

maybe this script helps you. it opens a telnet-conenction to your bot:

Code: Select all

<?
$telnet = new telnet();

$fp = $telnet->connect();
$telnet->write("telnet-nick");
$telnet->write("telnet-pass");
$telnet->write(".msg #wheretosay whattosay");

$telnet->disconnect();


/*
$Id: telnet.class.php,v 1.2 2004/03/22 10:01:35 mb Exp $

Originally written by Marc Ennaji (in french),
modified by Matthias Blaser <mb@adfinis.ch>

- translated most function- and variable names from french to english
- added get_buffer-method to get results of the last command
  sent to server
- added hack to get socket_strerror working on old systems

You can find the original class which this translation is based on
on this url: http://px.sklar.com/code.html?id=634

The original class includes a small documentation about using it
in your own applications, but be aware, all functions are in french there, this
one is partly translated.
*/

// hack to get socket_strerror working on old systems
if(!function_exists("socket_strerror")){
    function socket_strerror($sh){
        if(function_exists("strerror")){
            return strerror($sh);
        } else {
            return false;
        }
    }
}

// telnet class
define ("TELNET_ERROR", 0);
define ("TELNET_OK", 1);
define ("TELNET_ASK_CONFIRMATION", 2);
define ("LIBELLE_CONFIRMATION", "[confirm]");

class telnet {

    var $socket  = NULL;
    var $host = "89.110.157.240";
    var $port = "33335";
    var $error = "";
    var $codeError = "";
    var $prompt = "\$ ";
    var $log = NULL;  // file handle
    var $repertoireLog= "";
    var $nomFichierLog = "";
    var $test;

    var $buffer = "";

    //------------------------------------------------------------------------
    function connect(){
        $this->socket = fsockopen($this->host,$this->port);

        if (!$this->socket){
            $this->error = "unable to open a telnet connection: " . socket_strerror($this->socket) . "\n";
            return TELNET_ERROR;
        }

        socket_set_timeout($this->socket,10,0);
        return TELNET_OK;
    }

    //------------------------------------------------------------------------
    function read_to($chaine){
        $NULL = chr(0);
        $IAC = chr(255);
        $buf = '';

        if (!$this->socket){
            $this->error = "telnet socket is not open";
            return TELNET_ERROR;
        }

        while (1){
            $c = $this->getc();

            if ($c === false){
             // plus de caracteres a lire sur la socket
                if ($this->contientErreur($buf)){
                    return TELNET_ERROR;
                }

                $this->error = " Couldn't find the requested : '" . $chaine . "', it was not in the data returned from server : '" . $buf . "'" ;
                $this->logger($this->error);
                return TELNET_ERROR;
            }

            if ($c == $NULL || $c == "\021"){
                continue;
            }

            if ($c == $IAC){
                // Interpreted As Command
                $c = $this->getc();

                if ($c != $IAC){
                    // car le 'vrai' caractere 255 est doubl. pour le differencier du IAC
                    if (! $this->negocierOptionTelnet($c)){
                        return TELNET_ERROR;
                    } else {
                        continue;
                    }
                }

            }

            $buf .= $c;

            // append current char to global buffer
            $this->buffer .= $c;

            // indiquer . l'utilisateur de la classe qu'il a une demande de confirmation
            if (substr($buf,strlen($buf)-strlen(LIBELLE_CONFIRMATION)) == LIBELLE_CONFIRMATION){
                $this->logger($this->getDernieresLignes($buf));
                return TELNET_ASK_CONFIRMATION;
            }

            if ((substr($buf,strlen($buf)-strlen($chaine))) == $chaine){
                // on a trouve la chaine attendue

                $this->logger($this->getDernieresLignes($buf));

                if ($this->contientErreur($buf)){
                    return TELNET_ERROR;
                } else {
                    return TELNET_OK;
                }
            }
        }
    }

    //------------------------------------------------------------------------
    function getc(){
        return fgetc($this->socket);
    }

    //------------------------------------------------------------------------
    function get_buffer(){
        $buf = $this->buffer;

        // cut last line (is always prompt)
        $buf = explode("\n", $buf);
        unset($buf[count($buf)-1]);
        $buf = join("\n",$buf);
        return trim($buf);
    }

    //------------------------------------------------------------------------
    function negocierOptionTelnet($commande){
        // on negocie des options minimales

        $IAC = chr(255);
        $DONT = chr(254);
        $DO = chr(253);
        $WONT = chr(252);
        $WILL = chr(251);

        if (($commande == $DO) || ($commande == $DONT)){
            $opt = $this->getc();
            //echo "wont ".ord($opt)."\n";
            fwrite($this->socket,$IAC.$WONT.$opt);
        } else if (($commande == $WILL) || ($commande == $WONT)) {
            $opt = fgetc($this->socket);
            //echo "dont ".ord($opt)."\n";
            fwrite($this->socket,$IAC.$DONT.$opt);
        } else {
            $this->error = "Error : unknown command ".ord($commande)."\n";
            return false;
        }

        return true;
    }

    //------------------------------------------------------------------------
    function write($buffer, $valeurLoggee = "", $ajouterfinLigne = true){

        // clear buffer from last command
        $this->buffer = "";

        if (! $this->socket){
            $this->error = "telnet socket is not open";
            return TELNET_ERROR;
        }

        if ($ajouterfinLigne){
            $buffer .= "\n";
        }

        if (fwrite($this->socket,$buffer) < 0){
            $this->error = "error writing to socket";
            return TELNET_ERROR;
        }

        if ($valeurLoggee != ""){
            // cacher les valeurs confidentielles dans la log (mots de passe...)
            $buffer = $valeurLoggee . "\n";
        }

        if (! $ajouterfinLigne){
            // dans la log (mais pas sur la socket), rajouter tout de meme le caractere de fin de ligne
            $buffer .= "\n";
        }

        $this->logger("> " .$buffer);

        return TELNET_OK;
    }

    //------------------------------------------------------------------------
    function disconnect(){
        if ($this->socket){
            if (! fclose($this->socket)){
                $this->error = "error while closing telnet socket";
                return TELNET_ERROR;
            }

            $this->socket = NULL;
        }

        $this->setLog(false,"");
        return TELNET_OK;
    }

    //------------------------------------------------------------------------
    function contientErreur($buf){
        $messagesErreurs[] = "nvalid";       // Invalid input, ...
        $messagesErreurs[] = "o specified";  // No specified atm, ...
        $messagesErreurs[] = "nknown";       // Unknown profile, ...
        $messagesErreurs[] = "o such file or directory"; // sauvegarde dans un repertoire inexistant
        $messagesErreurs[] = "llegal";       // illegal file name, ...

        foreach ($messagesErreurs as $erreur){
            if (strpos ($buf, $erreur) === false)
                continue;

                // une erreur est d.tect.e
                $this->error =  "Un message d'erreur a .t. d.tect. dans la r.ponse de l'h.te distant : " .
                    "<BR><BR>" . $this->getDernieresLignes($buf,"<BR>") . "<BR>";

                return true;
            }

        return false;
    }

    //------------------------------------------------------------------------
    function wait_prompt(){
        return $this->read_to($this->prompt);
    }

    //------------------------------------------------------------------------
    function set_prompt($s){
        $this->prompt = $s;
        return TELNET_OK;
    }

    //------------------------------------------------------------------------
    function set_host($s){
        $this->host = $s;
    }

    //------------------------------------------------------------------------
    function set_port($s){
        $this->port = $s;
    }

    //------------------------------------------------------------------------
    function get_last_error(){
        return $this->error;
    }

    //------------------------------------------------------------------------
    function setLog($activerLog, $traitement){

        if ($this->log && $activerLog){
            return TELNET_OK;
        }

        if ($activerLog){
            $this->repertoireLog =  "/log/" . date("m");

            // repertoire mensuel inexistant ?
            if (! file_exists($this->repertoireLog)){
                if (mkdir($this->repertoireLog, 0700) === false){
                    $this->error = "Impossible de cr.er le repertoire de log " .  $this->repertoireLog;
                    return TELNET_ERROR;
                }
            }

            global $HTTP_SERVER_VARS;

            $this->nomFichierLog =     date("d") . "_" .
                date("H:i:s") . "_" .

            $traitement . "_" .
                $HTTP_SERVER_VARS["PHP_AUTH_USER"]
                . ".log";

            $this->log = fopen($this->repertoireLog . "/" . $this->nomFichierLog,"a");

            if (empty($this->log)){
                $this->error = "Impossible de cr.er le fichier de log " . $this->nomFichierLog;
                return TELNET_ERROR;
            }

            $this->logger("----------------------------------------------\r\n");
            $this->logger("D.but de la log de l'utilisateur " . $HTTP_SERVER_VARS["PHP_AUTH_USER"] .
                ", adresse IP " . $HTTP_SERVER_VARS["REMOTE_ADDR"] . "\r\n");

            $this->logger("Connexion telnet sur " . $this->host . ", port " . $this->port . "\r\n");
            $this->logger("Date : " . date("d-m-Y").  "  . " . date("H:i:s") . "\r\n");
            $this->logger("Type de traitement effectu. : " . $traitement . "\r\n");
            $this->logger("----------------------------------------------\r\n");
            return TELNET_OK;

        } else {
            if ($this->log){
                $this->logger("----------------------------------------------\r\n");
                $this->logger("Fin de la log\r\n");

                fflush($this->log);

                if (! fclose($this->log)){
                    $this->error = "erreur a la fermeture du fichier de log";
                    return TELNET_ERROR;
                }

                $this->log = NULL;
            }

            return TELNET_OK;
        }
    }

    //------------------------------------------------------------------------
    function logger($s){
        if ($this->log){
            fwrite($this->log, $s);
        }
    }

    //------------------------------------------------------------------------
    function getDernieresLignes($s, $separateur="\n"){
        // une reponse telnet contient (en principe) en premiere ligne l'echo de la commande utilisateur.
        // cette methode renvoie tout sauf la premiere ligne, afin de ne pas polluer les logs telnet

        $lignes = split("\n",$s);
        $resultat = "";
        $premiereLigne = true;

        while(list($key, $data) = each($lignes)){
            if ($premiereLigne){
                $premiereLigne = false;
            } else {
                if ($data != ""){
                    $resultat .= $data . $separateur;
                }
            }
        }

        $resultat == substr($resultat,strlen($resultat)-1); // enlever le dernier caractere de fin de ligne

        return $resultat;
    }

    //------------------------------------------------------------------------
}   //    Fin de la classe
?> 
#Quiz.de @ irc.GameSurge.net
JavaChat
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

This forum is intended for Eggdrops and Eggdrop Tcl scripting. PHP is not supported here, you'll have to seek help in a forum related to PHP.

Edit: It seems there has been a misunderstanding, it's not clear that you're requesting a Tcl-script from your initial post. I suggest you elaborate more on what you want your Eggdrop to do.
Post Reply