egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

"Visit" URL with command .pizza
Goto page 1, 2  Next
 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Requests
View previous topic :: View next topic  
Author Message
Pauschi
Voice


Joined: 03 Sep 2019
Posts: 11

PostPosted: Sun Aug 09, 2020 11:35 am    Post subject: "Visit" URL with command .pizza Reply with quote

Hello,

im looking for a easy and simple TCL script, that can be triggered by @(Operators) only:
When a Operator writes:

Code:
.pizza


in the Channel #pizza, it shall open up a connection to website
Code:
http://google.de/pizza.php?user=$IRC_NICKNAME

in the background and respond with the Website's content.

$IRC_Nickname in the URL should be the irc-username that triggered the .pizza command.

Im unable to find such easy script in the WWW yet. Hopefully someone is able to help me!

Thanks Smile
Back to top
View user's profile Send private message
CrazyCat
Revered One


Joined: 13 Jan 2002
Posts: 1032
Location: France

PostPosted: Sun Aug 09, 2020 6:59 pm    Post subject: Reply with quote

Well, I'm not sure that http://google.de/pizza.php will return anything else than a 404 error...
Btw, requesting a http page is really simple:
Code:
bind pub -|o ".pizza" pizzame

package require http

proc pizzame {nick host handle chan text} {
   set tok [::http::geturl "http://google.de/pizza.php?user=$nick"]
   set data [::http::data $tok]
   putserv "PRIVMSG $chan :$data"
}

_________________
https://www.eggdrop.fr - French IRC network
Offer me a coffee - Do not ask me help in PM, we are a community.
Back to top
View user's profile Send private message Visit poster's website
Pauschi
Voice


Joined: 03 Sep 2019
Posts: 11

PostPosted: Mon Aug 10, 2020 12:15 pm    Post subject: Reply with quote

Thank you very much for answering.

I'll check it out and let you know if its working Smile

yeah it was a example URL Smile

EDIT: Somehow the bot is not responding :/

It worked with:

bind pub - ".pizza" pizzame

but not with

bind pub -|o ".pizza" pizzame
Back to top
View user's profile Send private message
CrazyCat
Revered One


Joined: 13 Jan 2002
Posts: 1032
Location: France

PostPosted: Mon Aug 10, 2020 3:03 pm    Post subject: Reply with quote

It depends on what you mean when you say it must be triggered by operator.

If it's channel operator in the eggdrop' userlist, my bind was right.
If it's being opped in the channel, your bind is right but you have to add a check at the begin of the procedure:
Code:
if {![isop $nick $chan]} { return 1 }

_________________
https://www.eggdrop.fr - French IRC network
Offer me a coffee - Do not ask me help in PM, we are a community.
Back to top
View user's profile Send private message Visit poster's website
Pauschi
Voice


Joined: 03 Sep 2019
Posts: 11

PostPosted: Mon Aug 10, 2020 3:19 pm    Post subject: Reply with quote

All OPS and VOICE users in the channel should be allowed to do it.


if {![isop $nick $chan]} { return 1 }


Where do i need to set this? ;P
Back to top
View user's profile Send private message
ComputerTech
Master


Joined: 22 Feb 2020
Posts: 393

PostPosted: Mon Aug 10, 2020 10:17 pm    Post subject: Reply with quote

Like this Smile

Code:

bind pub - ".pizza" pizzame   

package require http   

proc pizzame {nick host handle chan text} {     
if {![isop $nick $chan]} { return 1 }
set tok [::http::geturl "http://google.de/pizza.php?user=$nick"]   
set data [::http::data $tok]     
putserv "PRIVMSG $chan :$data" 
  }

when CrazyCat says procedure, he means basically the proc

Code:

proc pizzame {nick host handle chan text} {    << Proc


Pauschi wrote:
All OPS and VOICE users in the channel should be allowed to do it.


if {![isop $nick $chan]} { return 1 }


Where do i need to set this? ;P


the above code will Only allow channel op's to use the command, there is also..
Code:

if {![isvoice $nick $chan]} { return 1 }

if you prefer that Smile
_________________
ComputerTech
Back to top
View user's profile Send private message Send e-mail Visit poster's website
CrazyCat
Revered One


Joined: 13 Jan 2002
Posts: 1032
Location: France

PostPosted: Tue Aug 11, 2020 2:32 am    Post subject: Reply with quote

Thanks ComputerTech.

@Pauschi: if you want to have it working for voice and ops (add halfop to), the final script is:
Code:
bind pub - ".pizza" pizzame

set desturl "http://google.de/pizza.php"
package require http

proc pizzame {nick host handle chan text} {
   if { ![isop $nick $chan] && ![ishalfop $nick $chan] && ![isvoice $nick $chan] } { return 1 }
   set query [::http::formatQuery user $nick]
   set tok [::http::geturl $::desturl -query $query]
   set data [::http::data $tok]
   putserv "PRIVMSG $chan :$data"
}


Notice that it won't work with https url.
_________________
https://www.eggdrop.fr - French IRC network
Offer me a coffee - Do not ask me help in PM, we are a community.
Back to top
View user's profile Send private message Visit poster's website
Pauschi
Voice


Joined: 03 Sep 2019
Posts: 11

PostPosted: Tue Aug 11, 2020 2:35 am    Post subject: Reply with quote

Thank you guys, appreciate your work and help!

Ive just learned that https links sadly dont work.

Theres no way to avoid this?
Back to top
View user's profile Send private message
CrazyCat
Revered One


Joined: 13 Jan 2002
Posts: 1032
Location: France

PostPosted: Tue Aug 11, 2020 3:44 am    Post subject: Reply with quote

Sure there is a way Smile
Code:
bind pub - ".pizza" pizzame

set desturl "http://google.de/pizza.php"

package require http
package require tls

proc pizzame {nick host handle chan text} {
   if { ![isop $nick $chan] && ![ishalfop $nick $chan] && ![isvoice $nick $chan] } { return 1 }
   if { [string match "https://*" $::desturl] } {
      ::http::register https 443 [list ::tls::socket -autoservername true]
      set https 1
   } else {
      set https 0
   }
   set query [::http::formatQuery user $nick]
   set tok [::http::geturl $::desturl -query $query]
   set data [::http::data $tok]
   if { $https == 1 } { ::http::unregister https }
   putserv "PRIVMSG $chan :$data"
}


I made the script adaptative to url scheme, but you can have troubles with tls handshake, depending on the url you want to access.
_________________
https://www.eggdrop.fr - French IRC network
Offer me a coffee - Do not ask me help in PM, we are a community.
Back to top
View user's profile Send private message Visit poster's website
Pauschi
Voice


Joined: 03 Sep 2019
Posts: 11

PostPosted: Tue Aug 11, 2020 9:22 am    Post subject: Reply with quote

CrazyCat wrote:
Thanks ComputerTech.

@Pauschi: if you want to have it working for voice and ops (add halfop to), the final script is:
Code:
bind pub - ".pizza" pizzame

set desturl "http://google.de/pizza.php"
package require http

proc pizzame {nick host handle chan text} {
   if { ![isop $nick $chan] && ![ishalfop $nick $chan] && ![isvoice $nick $chan] } { return 1 }
   set query [::http::formatQuery user $nick]
   set tok [::http::geturl $::desturl -query $query]
   set data [::http::data $tok]
   putserv "PRIVMSG $chan :$data"
}


Notice that it won't work with https url.


Thanks! Im using this script because i better skip the HTTPS thing, since its not working with the servers configuration (https force is on there).

However, i tried setting this URL =>

set desturl "http://google.de/pizza.php?user=$nick"

its not using the $nick (IRC Nickname) with this way
Back to top
View user's profile Send private message
CrazyCat
Revered One


Joined: 13 Jan 2002
Posts: 1032
Location: France

PostPosted: Tue Aug 11, 2020 9:36 am    Post subject: Reply with quote

You may try to understand the script and how it works.
desturl is setted at the beginning, before the proc is called, so adding "user=$nick" is an error because there is no $nick variable setted yet.

In the proc, I create the query (things coming after the ? in url), so:
Code:
set query [::http::formatQuery user $nick]
set tok [::http::geturl $::desturl -query $query]
will create:
http://google.de/pizza.php?user=<$nick> (<$nick> is the user doing .pizza)

The interest of this is that if you have special characters in $nick, they will be adapted. And if you need to post rather than get, it's managed by the http call.
_________________
https://www.eggdrop.fr - French IRC network
Offer me a coffee - Do not ask me help in PM, we are a community.
Back to top
View user's profile Send private message Visit poster's website
ComputerTech
Master


Joined: 22 Feb 2020
Posts: 393

PostPosted: Tue Aug 11, 2020 10:08 am    Post subject: Reply with quote

Nice code CrazyCat Very Happy

I like the way you did this
Code:

if { ![isop $nick $chan] && ![ishalfop $nick $chan] && ![isvoice $nick $chan] } { return 1 }

I will use that for my code from now on Very Happy
_________________
ComputerTech
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Pauschi
Voice


Joined: 03 Sep 2019
Posts: 11

PostPosted: Wed Aug 12, 2020 8:27 am    Post subject: Reply with quote

Thanks Again CrazyCat!

When i check my Apache2 Logs,
only pizza.php gets triggered, without ?user=<$nick>

Code:
"POST /pizza.php HTTP/1.1" 200 220 "-" "Tcl http client package 2.7.13"


pizza.php:

Code:
<?php

$user = $_GET['user'];

$gesamt = file_get_contents("bier_$user.txt");

    if (in_array($_GET['user'], ['Thomas', 'h4']))
 {
echo "$user: Biere insgesamt: $gesamt"; die;

}else{

echo "Keine Berechtigung, Junge."; die;

 die; }

?>
Back to top
View user's profile Send private message
CrazyCat
Revered One


Joined: 13 Jan 2002
Posts: 1032
Location: France

PostPosted: Wed Aug 12, 2020 5:57 pm    Post subject: Reply with quote

Log is clear: data are sent with POST, not GET.
So, adapt your php if you can (post is more secure than get) or modify the script to force usage of get:
Code:
set tok [::http::geturl $::desturl -method "GET" -query $query]


P.S.: I hope your PHP is just a POC, because you use depreciated things, too much die, ... really bad code Smile
_________________
https://www.eggdrop.fr - French IRC network
Offer me a coffee - Do not ask me help in PM, we are a community.
Back to top
View user's profile Send private message Visit poster's website
caesar
Mint Rubber


Joined: 14 Oct 2001
Posts: 3741
Location: Mint Factory

PostPosted: Thu Aug 13, 2020 12:32 am    Post subject: Reply with quote

Since he has if-else there no need for die actually.
_________________
Once the game is over, the king and the pawn go back in the same box.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Requests All times are GMT - 4 Hours
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber