Back to top

Autore Topic: Quesito per i guru del php: conversione JosObfuscator  (Letto 1666 volte)

Offline sali40

  • Global Moderator
  • Instancabile
  • ********
  • Post: 4791
  • Sesso: Maschio
    • Mostra profilo
Non so se conoscete JosObfuscator. Secondo me è l'unica vera difesa contro gli spambot che recuperano indirizzi e-mail dalle pagine web. Costruito come mambot per la versione 1.0, ho tentato la conversione per la versione 1.5
Devo dire che per le mie esigenze (visto che non ho alcuna intenzione di disabilitarlo) funziona a meraviglia, ma avrei avuto il piacere di condividerlo, visto che non è ancora stato convertito dall'autore (nè pare ne abbia intenzione). Il punto è che se si disabilita, i segnaposto
Codice: [Seleziona]
{joso}{/joso} diventano visibili.
Questo il codice originale:
Codice: [Seleziona]
<?php
// no direct access
//Copyright http://www.josxp.com
//ChangeLoge  Winword Bug Fix

defined'_VALID_MOS' ) or die( 'Restricted access' );

$_MAMBOTS->registerFunction'onPrepareContent''botJosObfuscator' );

function 
botJosObfuscator$published, &$row, &$params$page=) {
$regex '%\{joso\}(.*?)\{/joso\}%si';
*
if ($published==0) {
*
$row->text preg_replace$regex""$row->text );
*
return true;
*
}
$josStyle "<style media=\"screen\">\n";
$josStyle .= "span.joshide { display:none; }\n";
$josStyle .= "</style>";
$row->text $josStyle preg_replace_callback$regex'JosObfuscator_Replacer'$row->text );
}

function 
JosObfuscator_Replacer$matches ) {
$regex '/\>(.*?)\</si';
return '<span class="joshide">[JosObfuscator] </span>' str_replace('<jos>'''preg_replace_callback$regex'JosObfuscator_Replacer_TAG''<jos>' $matches[1] . '<jos>')) ;
}

function 
JosObfuscator_Replacer_TAG$matches ) {
$regex '/\;(.*?)\&/si';
$raw preg_replace_callback$regex'JosObfuscator_Replacer_AMP'';' $matches[1] . '&');
$raw substr($raw1strlen($raw)-2);
   
$txt '>' $raw '<';
return $txt;
}


function 
JosObfuscator_Replacer_AMP$matches ) {
   
return ';' JosObfuscator_Hash($matches[1]) . '&';
}

function 
JosObfuscator_Hash($word) {
$rtnVal '';
for ($i=0$i strlen($word); $i++) {
$rtnVal .= JosRandChars() . $word{$i};
}
return $rtnVal;
}

function 
JosRandChars() {
$rndNumber rand(15);
$rtnVal '';
for ($i=1$i<= $rndNumber$i++) {
$rtnVal .= JosRandChar();
}
return '<span class="joshide">' $rtnVal '</span>';
}

function 
JosRandChar() {
$rnd 38;
while ( ($rnd == 38) || ($rnd == 39) || ($rnd == 60) || ($rnd == 32) || ($rnd == 92) ) {
$rnd rand(35126);
}
return  chr($rnd);
}

?>

Questo il codice come da me modificato:
Codice: [Seleziona]
<?php
// no direct access
//Copyright http://www.josxp.com
//ChangeLoge Winword Bug Fix

defined'_JEXEC' ) or die( 'Direct Access to this location is not allowed.' );
$mainframe->registerEvent'onPrepareContent''botJosObfuscator' );


function 
botJosObfuscator( &$row, &$params$page=0  ) {

//Access the database
   
$db =& JFactory::getDBO();

//Check whether the bot should process or not
if ( JString::strpos$row->text'joso' ) === false ) {
return true;
}

//Get plugin info
        
$plugin =& JPluginHelper::getPlugin'content''josobfuscator' );

//Search for this tag in the content
        
$regex '%\{joso\}(.*?)\{/joso\}%is';
        
//Access the parameters
$pluginParams = new JParameter$plugin->params );

 
//Check whether plugin has been unpublished
* if ( !$pluginParams->get'enabled') ) {
*
$row->text preg_replace$regex""$row->text );
*
return true;
*
}

$josStyle "<style media=\"screen\">\n";
$josStyle .= "span.joshide { display:none; }\n";
$josStyle .= "</style>";

$row->text $josStyle preg_replace_callback$regex'JosObfuscator_Replacer'$row->text );
}

function 
JosObfuscator_Replacer$matches ) {
$regex '/\>(.*?)\</si';
return '<span class="joshide">[JosObfuscator] </span>' str_replace('<jos>'''preg_replace_callback$regex'JosObfuscator_Replacer_TAG''<jos>' $matches[1] . '<jos>')) ;
}

function 
JosObfuscator_Replacer_TAG$matches ) {
$regex '/\;(.*?)\&/is';



$raw preg_replace_callback$regex'JosObfuscator_Replacer_AMP'';' $matches[1] . '&');
$raw substr($raw1strlen($raw)-2);
   
$txt '>' $raw '<';
return $txt;
}


function 
JosObfuscator_Replacer_AMP$matches ) {
   
return ';' JosObfuscator_Hash($matches[1]) . '&';
}

function 
JosObfuscator_Hash($word) {
$rtnVal '';
for ($i=0$i strlen($word); $i++) {
$rtnVal .= JosRandChars() . $word{$i};
}
return $rtnVal;
}

function 
JosRandChars() {
$rndNumber rand(15);
$rtnVal '';
for ($i=1$i<= $rndNumber$i++) {
$rtnVal .= JosRandChar();
}
return '<span class="joshide">' $rtnVal '</span>';
}

function 
JosRandChar() {
$rnd 38;
while ( ($rnd == 38) || ($rnd == 39) || ($rnd == 60) || ($rnd == 32) || ($rnd == 92) ) {
$rnd rand(35126);
}
return  chr($rnd);
}

?>

ovviamente ho modificato l'xml.

Il plugin assume il nome 'josobfuscator'

Qualcuno può dirmi dove ho commesso l'errore? Con '*' ho segnato la parte della funzione che dovrebbe "stripare" i segnaposto nel caso di disabilitazione del plugin.

Offline = odino =

  • Instancabile
  • ******
  • Post: 5696
  • Sesso: Maschio
  • "In realtà li trasforma in menomati" Danzel
    • Mostra profilo
Re: Quesito per i guru del php: conversione JosObfuscator
« Risposta #1 il: 06 Ago 2008, 08:40:07 »
Ciao Sali,

perchè non provi a inserire due variabili:

Codice: [Seleziona]
$off_1 = '<!--';
$off_2 = '-->';

che vengano scritte da un ciclo if quando il plugin è disattivato ( e quindi relativa variabile abbia un determinato valore... )


 



Web Design Bolzano Kreatif