| View previous topic :: View next topic |
| Author |
Message |
Pauschi Voice
Joined: 03 Sep 2019 Posts: 11
|
Posted: Sun Aug 09, 2020 11:35 am Post subject: "Visit" URL with command .pizza |
|
|
Hello,
im looking for a easy and simple TCL script, that can be triggered by @(Operators) only:
When a Operator writes:
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  |
|
| Back to top |
|
 |
CrazyCat Revered One

Joined: 13 Jan 2002 Posts: 1032 Location: France
|
Posted: Sun Aug 09, 2020 6:59 pm Post subject: |
|
|
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 |
|
 |
Pauschi Voice
Joined: 03 Sep 2019 Posts: 11
|
Posted: Mon Aug 10, 2020 12:15 pm Post subject: |
|
|
Thank you very much for answering.
I'll check it out and let you know if its working
yeah it was a example URL
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 |
|
 |
CrazyCat Revered One

Joined: 13 Jan 2002 Posts: 1032 Location: France
|
Posted: Mon Aug 10, 2020 3:03 pm Post subject: |
|
|
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 |
|
 |
Pauschi Voice
Joined: 03 Sep 2019 Posts: 11
|
Posted: Mon Aug 10, 2020 3:19 pm Post subject: |
|
|
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 |
|
 |
ComputerTech Master

Joined: 22 Feb 2020 Posts: 393
|
Posted: Mon Aug 10, 2020 10:17 pm Post subject: |
|
|
Like this
| 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  _________________ ComputerTech |
|
| Back to top |
|
 |
CrazyCat Revered One

Joined: 13 Jan 2002 Posts: 1032 Location: France
|
Posted: Tue Aug 11, 2020 2:32 am Post subject: |
|
|
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 |
|
 |
Pauschi Voice
Joined: 03 Sep 2019 Posts: 11
|
Posted: Tue Aug 11, 2020 2:35 am Post subject: |
|
|
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 |
|
 |
CrazyCat Revered One

Joined: 13 Jan 2002 Posts: 1032 Location: France
|
Posted: Tue Aug 11, 2020 3:44 am Post subject: |
|
|
Sure there is a way
| 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 |
|
 |
Pauschi Voice
Joined: 03 Sep 2019 Posts: 11
|
Posted: Tue Aug 11, 2020 9:22 am Post subject: |
|
|
| 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 |
|
 |
CrazyCat Revered One

Joined: 13 Jan 2002 Posts: 1032 Location: France
|
Posted: Tue Aug 11, 2020 9:36 am Post subject: |
|
|
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 |
|
 |
ComputerTech Master

Joined: 22 Feb 2020 Posts: 393
|
Posted: Tue Aug 11, 2020 10:08 am Post subject: |
|
|
Nice code CrazyCat
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  _________________ ComputerTech |
|
| Back to top |
|
 |
Pauschi Voice
Joined: 03 Sep 2019 Posts: 11
|
Posted: Wed Aug 12, 2020 8:27 am Post subject: |
|
|
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 |
|
 |
CrazyCat Revered One

Joined: 13 Jan 2002 Posts: 1032 Location: France
|
Posted: Wed Aug 12, 2020 5:57 pm Post subject: |
|
|
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  _________________ 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 |
|
 |
caesar Mint Rubber

Joined: 14 Oct 2001 Posts: 3741 Location: Mint Factory
|
Posted: Thu Aug 13, 2020 12:32 am Post subject: |
|
|
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 |
|
 |
|