BlackBoard (http://www.black-board.net/index.php)
- Design, Programmierung & Entwicklung (http://www.black-board.net/board.php?boardid=55)
-- Projekte (http://www.black-board.net/board.php?boardid=108)
--- PHP IRC-Notify für neue Posts (http://www.black-board.net/thread.php?threadid=9014)


Geschrieben von Zirias am 09.12.2002 um 22:51:

  IRC-Notify für neue Posts

IRC-Notify für neue Posts auf der Projekt-Seite

So, ich habe gestern und heute was zusammengestrickt, dass mein Bot im Channel Bescheid sagt, wenn es einen neuen Post gibt. Falls es jemanden interessiert, hier kommt der Source smile

1. Das eggdrop-Modul (die Dateien müssen in src/mod/remote.mod liegen, dann den bot neu compilieren. in der config "loadmodule remote" hinzufügen)

Makefile:
code:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
# Makefile for src/mod/remote.mod/

srcdir = .


doofus:
        @echo ""
        @echo "Let's try this from the right directory..."
        @echo ""
        @cd ../../../ && make

static: ../remote.o

modules: ../../../remote.$(MOD_EXT)

../remote.o:
        $(CC) $(CFLAGS) $(CPPFLAGS) -DMAKING_MODS -c $(srcdir)/remote.c
        @rm -f ../remote.o
        mv remote.o ../

../../../remote.$(MOD_EXT): ../remote.o
        $(LD) -o ../../../remote.$(MOD_EXT) ../remote.o
        $(STRIP) ../../../remote.$(MOD_EXT)

depend:
        $(CC) $(CFLAGS) $(CPPFLAGS) -MM $(srcdir)/remote.c > .depend

clean:
        @rm -f .depend *.o *.$(MOD_EXT) *~
distclean: clean

#safety hash
../remote.o: .././remote.mod/remote.c ../../../src/mod/module.h \
 ../../../src/main.h ../../../src/lang.h ../../../src/eggdrop.h \
 ../../../src/flags.h ../../../src/proto.h ../../../lush.h \
 ../../../src/misc_file.h ../../../src/cmdt.h ../../../src/tclegg.h \
 ../../../src/tclhash.h ../../../src/chan.h ../../../src/users.h \
 ../../../src/compat/compat.h ../../../src/compat/inet_aton.h \
 ../../../src/compat/snprintf.h ../../../src/compat/memset.h \
 ../../../src/compat/memcpy.h ../../../src/compat/strcasecmp.h \
 ../../../src/mod/modvals.h ../../../src/tandem.h


remote.c:
code:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
#define MODULE_NAME "remote"

/* remote.c V0.1
 *
 * Eggdrop module 12/2002 by Zirias
 *
 * This module just listens on a socket for lines to put on the IRC-server
 * The socket is protected by a password.
 * Very handy if you want to have any other software give messages in a
 * channel through your bot. Just make it send the password followed by a
 * newline-character and then the line for IRC to the socket.
 *
 * ATTENTION, there is no syntax checking at all. Your program has to provide
 * a correct IRC protocol line like
 * 
 * PRIVMSG #chan :this is just an example
 *
 * For now, the password has to be set in this source file. Maybe this will
 * be changed.
 */

// Config:

#define PORT 12345
#define PASS "Password"

// End Config

#define MAKING_REMOTE

#include "src/mod/module.h"

#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <unistd.h>
#include <fcntl.h>

static Function *global = NULL;

static int remote_sock, remote_conn, cl_len;
static struct sockaddr_in cl_addr, svr_addr;
static char buffer[1024];

static int remote_expmem() {
        return 0;
}

static void remote_report(int idx, int details) {
}

static int readline(int fd, char *buf, int maxlen, int to_sec, int to_usec) {
        fd_set rfds;
        struct timeval tv;
        char *ptr=buf;
        int i=0;

        FD_ZERO(&rfds);
        FD_SET(fd,&rfds);
        tv.tv_sec=to_sec;
        tv.tv_usec=to_usec;
        while (i<maxlen) {
                if (select(fd+1,&rfds,NULL,NULL,&tv)<1) { i=-1; break; }
                i++;
                do recv(fd,ptr,1,0); while (*ptr=='\r');
                if (*ptr=='\n') {
                        *ptr='\0';
                        break;
                }
                ptr++;
        }
        return i;
}

static void remote_data() {
        if ((remote_conn=accept(remote_sock,(struct sockaddr *)&cl_addr, &cl_len))>0) {
                if (readline(remote_conn,(char *)&buffer,1023,3,0)>0) {
                        if (strcmp(PASS,(char *)&buffer)==0) {
                                if (readline(remote_conn,(char *)&buffer,1023,3,0)>0) {
                                        dprintf(DP_SERVER,"%s\n",(char *)&buffer);
                                }
                        }
                }
                close(remote_conn);
        }
}

static char *remote_close() {
        del_hook(HOOK_SECONDLY,(Function) remote_data);
        close(remote_sock);
        return NULL;
}

EXPORT_SCOPE char *remote_start();

static Function remote_table[] = {
        (Function) remote_start,
        (Function) remote_close,
        (Function) remote_expmem,
        (Function) remote_report,
};

char *remote_start(Function *func_table) {
        int socket_flags;
        global = func_table;
        module_register(MODULE_NAME,remote_table,0,1);
        if ((remote_sock=socket(AF_INET, SOCK_STREAM, 0))<0) {
                return "socket()";
        } else {
                socket_flags=fcntl(remote_sock,F_GETFL);
                socket_flags|=O_NONBLOCK;
                fcntl(remote_sock,F_SETFL,socket_flags);
                svr_addr.sin_family=AF_INET;
                svr_addr.sin_addr.s_addr=htonl(INADDR_ANY);
                svr_addr.sin_port=htons(PORT);
                if (bind(remote_sock,(struct sockaddr *)&svr_addr, sizeof(svr_addr))<0) {
                        return "bind()";
                } else {
                        add_hook(HOOK_SECONDLY,(Function) remote_data);
                        listen(remote_sock,5);
                        return NULL;
                }
        }
}


Dieses Modul ist universell einsetzbar, es nimmt einfach Zeilen an und sendet sie an den IRC-Server.


2. Der Board-Hack:

Hier müssen 2 files gepatcht werden:
code:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
--- wbb-org/addreply.php        2002-12-09 22:45:38.000000000 +0100
+++ wbb/addreply.php    2002-12-09 16:14:42.000000000 +0100
@@ -3,6 +3,9 @@
 
 require("./global.php");
 require("./acp/lib/class_parse.php");
+//IRC-Notify-Hack by Zirias:
+require("./irc_notify.php");
+//END Hack.
 
 if(!isset($threadid)) eval("error("".$tpl->get("error_falselink")."");");
@@ -53,6 +56,9 @@
    $postid = $db->insert_id();
+   //IRC-Notify-Hack by Zirias:
+   irc_notify($wbbuserdata['username'],$postid,$threadid);
+   //END Hack.
    if($attachment_id) {
--- wbb-org/newthread.php       2002-12-09 22:45:54.000000000 +0100
+++ wbb/newthread.php   2002-12-09 16:13:55.000000000 +0100
@@ -2,6 +2,9 @@
 $filename="newthread.php";
 
 require("./global.php");
+//IRC-Notify-Hack by Zirias:
+require("./irc_notify.php");
+//END Hack.
 
 if($_REQUEST['action']=="announce") {
@@ -106,6 +109,9 @@
    $postid=$db->insert_id();
+   //IRC-Notify-Hack by Zirias:
+   irc_notify($wbbuserdata['username'],$postid,$threadid);
+   //END Hack.


und dazu kommt das eigentliche notify-script
irc_notify.php:
code:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
<?php

/* irc_notify.php
 * 12/2002 by Zirias
 *
 * announces new threads in IRC via an eggdrop using my remote module
 */

//Config:

$thread_url="http://my.boards.host.net/thread.php";
$egg_host="my.bots.host.net";
$egg_port="12345";
$egg_pass="Password";
$channel="#mychan";

//END Config.

function irc_notify($poster,$postid,$threadid) {
        global $thread_url,$egg_host,$egg_port,$egg_pass,$channel,$db,$n;
        $thread=$db->query_first("SELECT topic,boardid FROM bb".$n."_threads WHERE threadid=".$threadid);
        $board=$db->query_first("SELECT title,invisible FROM bb".$n."_boards WHERE boardid=".$thread['boardid']);
        $trans=array_flip(get_html_translation_table(HTML_ENTITIES));
        $boardname=strtr($board['title'],$trans);
        $threadname=strtr($thread['topic'],$trans);
        if ($board['invisible']==0) {
                if ($fp=fsockopen($egg_host,$egg_port,$errno,$errstr,30)) {
                        fputs($fp,$egg_pass."\r\n");
                        fputs($fp,"PRIVMSG $channel :Neuer Post von \037$poster\037: ");
                        fputs($fp,"$thread_url?postid=$postid#post$postid ");
                        fputs($fp,"\002Forum\002: $boardname ");
                        fputs($fp,"\002Thread\002: $threadname\r\n");
                        fclose($fp);
                }
        }
}

?>


Greets, Ziri



Geschrieben von [DS]-=Pencil=- am 10.12.2002 um 18:37:

 

also ich würde auch gerne so ein newsbot haben, aber ich weiss trotz der "ausführlichen" erklärungen nicht wie ich das machen solltraurig

ich will die überschrift der news von http://www.rtcw-prison.de dann erscheinen lassen wenn neue news vorhanden sind

das soll dann so aussehen
Zitat:

rtcw-prison.de Neue News | Headline


naja wäre schön wenn ihr mir helfen könntet.. ich will den in #rtcw-prison(qnet) einfügen

Hope you help

unglücklich



Geschrieben von Zirias am 11.12.2002 um 03:17:

 

Das Eggdrop-Modul kannst du 1:1 übernehmen, die Scripte auf deiner Seite musst du entsprechend anpassen. Sie müssen dem Bot etwa folgendes (auf den im Modul konfigurierten Port) liefern:
code:
1:
2:
Password
PRIVMSG #channel :Neue bla ....


Greets, Ziri



Geschrieben von grobi2 am 19.02.2003 um 23:01:

 

Hallo alle zusammen,

liest sich ja genial..leider habe ich hier nur nen Windrop zu laufen. Besteht irgendwie die Möglichkeit, das auch mit nem Windrop in die Gänge zu bekommen ?

Benutze derzeit den Windrop 1.6.13

l.g.

grobi2



Geschrieben von Zirias am 21.02.2003 um 19:31:

 

Das Modul ist nicht allzugroß ... musst du eben selbst von BSD-Sockets auf WinSock umschreiben. Soweit die Idee, auf die jeder selber kommen kann. Umsetzen werde ichs sicher nicht, ich programmier nicht gern für Windows.



Geschrieben von grobi2 am 22.02.2003 um 14:48:

 

Hallo Zirias,

danke für die Antwort, auch wenns mir nicht wirklich hilft, da ich NULL Plan vom coden habe Baby

Vieleicht erbarmt sich ja jemand, und setzt es für nen auf Windows aufgesetzten Apache Server um smile )

l.g.

grobi



Geschrieben von Compuholic am 22.02.2003 um 14:58:

 

Das hat doch mit dem Apache-Server nix zu tun, zumindest soweit ich das hier sehen kann. Ich kenne Eggdrop nicht. Ich schätzemal, das der Bot ein StandAlone Programm ist und sich nicht irgendwelche anderen Programme bedient.

Läuft Eggdrop überhaupt auf Windows? Wenn ja, sind die Windows-Sourcen überhaupt verfügbar? Der PHP-Code benötigt ka keinerlei Anpassung. Ansonsten könnte ich mich ja mal in ein paar freien Stunden dahinterklemmen.



Geschrieben von LX am 22.02.2003 um 15:15:

Pfeil

Zitat:
Original von Compuholic
Das hat doch mit dem Apache-Server nix zu tun, zumindest soweit ich das hier sehen kann. Ich kenne Eggdrop nicht. Ich schätzemal, das der Bot ein StandAlone Programm ist und sich nicht irgendwelche anderen Programme bedient.
Korrekt. Eggdrop braucht keinen Webserver um zu laufen.

Zitat:
Läuft Eggdrop überhaupt auf Windows?
Windrop ist ein CygWin-Port von Eggdrop.



Geschrieben von HarryP am 24.02.2003 um 12:26:

 

Hallo.....brauche etwas hilfe!!
Habe probleme beim Compilieren!!!! geschockt

Ich habe die Datein in src/mod/remote.mod wie beschrieben abgelegt

nach ./configure und "make" stelle ich aber immer wieder fest das er alle module erstellt sind , ausser das "remote modul"

Muß das noch irgendwo eingetragen werden das auch das Verzeichnis remote.mod compiliert wird????

es hat den anschein das er dieses Verzeichnis überspringt.....

Danke für Hilfe!!!!

MFG
HarryP



Geschrieben von LX am 24.02.2003 um 12:52:

Pfeil

Du musst nichts weiter eintragen, aber offenbar hast du zwischen "./configure" und "make" den Schritt "make config" ausgelassen, in dem du definierst, welche Module kompiliert werden sollen.



Geschrieben von HarryP am 26.02.2003 um 15:56:

 

Hallo

Ja,das war tatsächlich der Fehler....leider läuft mein Modul immer noch nicht....aber er hat zumindest schon mal versucht es zu kompilieren.....aus Zeitgründen komm ich leider nicht zum Fehlersuchen.
Aber danke für die Hilfe!!!!

MFG
HarryP



Geschrieben von HarryP am 26.02.2003 um 19:13:

 

ja da bin ich doch schon wieder...jetzt habe ich das Problem das mein bot beim compilieren einen Fehler ausspuckt

Diese Fehlermeldung gibt er an:
Entering directory `/home/HarryP/eggdrop1.6.12.ipv6/src/mod/remote.mod'
Makefile:7: *** missing separator. Stop.

Leider weiß ich jetzt nicht was ihm zu seinem Glück fehlt verwirrt
Vielleicht eine Idee???
die Datein des ordners remote werde ich mal zur einsicht hier hinterlegen .
Viele liebe Grüße von der Nordsee
HarryP



Geschrieben von LX am 26.02.2003 um 19:30:

Achtung

Füge dort, wo sie in Zirias' Beitrag auch stehen, TABs ins Makefile ein, die werden benötigt. Beachte, dass es echte TABs sein müssen, nicht 8 Spaces o.ä.



Geschrieben von HarryP am 27.02.2003 um 13:57:

 

Hallo Lx!!!

Wollt nur noch eben schnell posten das der Bot nu läuft....jetzt werde ich mich mal an die anderen Datein machen.....trotzdem hoffe ich das ich net mehr so schnell auf meinen "shell-Account " muß....
Linux werde ich lieber anderen Leuten überlassen
Eine Frage hätt ich aber noch....wieso sind diese "TABS" so wichtig.....weil ja sonst oft in anderen Programiersprachen leerzeichen einfach ignoriert werden

MFG
HarryP



Geschrieben von LX am 27.02.2003 um 14:24:

Pfeil

Das was im Makefile steht ist ja keine Programmiersprache, das sind lediglich die Anweisungen an make, wie mit dem was in dem Verzeichnis gefunden wird, vorzugehen ist. Die TABs werden hier offenbar benötigt, um die einzelnen Abschnitte voneinander abzugrenzen, genaueres müsste ich aber auch erst nachschauen Augenzwinkern



Geschrieben von HarryP am 27.02.2003 um 16:17:

 

unglücklich unglücklich .....habe ich mich zu früh gefreut....er hat das wohl kompiliert...ohne Fehlermeldung ....aber beim starten vom bot kommt jetzt....

Eggdrop v1.6.12 (C) 1997 Robey Pointer (C) 2002 Eggheads
[16:09] --- Loading eggdrop v1.6.12 (Thu Feb 27 2003)
[16:09] Module loaded: dns
[16:09] Module loaded: channels
[16:09] Module loaded: server
[16:09] Module loaded: ctcp
[16:09] Module loaded: irc
[16:09] Module loaded: notes (with lang support)
[16:09] Module loaded: console (with lang support)
[16:09] Module loaded: blowfish
[16:09] Can't load modules remote: bind()
[16:09] Listening at telnet port 3333 (all)
[16:09] Module loaded: uptime
[16:09] Userinfo TCL v1.07 loaded (URL BF GF IRL EMAIL DOB PHONE ICQ).
[16:09] use '.help userinfo' for commands.


STARTING BOT IN USERFILE CREATION MODE.
Telnet to the bot and enter 'NEW' as your nickname.
OR go to IRC and type: /msg Harrybot hello
This will make the bot recognize you as the master.


ich weiß natürlich nicht was bind bedeutet.....
MFG



Geschrieben von Zirias am 28.02.2003 um 12:22:

 

das heißt, dass bind() fehlgeschlagen ist, das ist die Funktion, die den Port reserviert. Wenn du den Bot nicht als root laufen lässt (was absolut NICHT zu empfehlen ist) musst du einen Port >1024 nehmen, die unteren Ports darf nämlich nur root. Also im Source ändern und nochmal compilieren.



Geschrieben von HarryP am 28.02.2003 um 13:09:

 

Vielen Dank!!!
Werde es probieren....(das ding is mein neues Hobby großes Grinsen )....jeden Abend eine Stunde.....aber es hat mir schon einiges an Wissen gebracht...dank Eurer Hilfe......werde weiter berichten.....

Würde der bot auch diese Fehlermeldung ausgeben wenn ich die files fürs Board noch net eingebaut habe??verwirrt Das ist nämlich der Fall...dachte erst den bot und dann den rest großes Grinsen )

Ach ja und dann habe ich (glaube bei WBB.info) gelesen das das bei Hosteurope wegen einer Firewall net funzt...(der eggdrop läuft aber bei shellplanet) weiß da hier jemand genaues????

Danke!!!!!

MFG
HarryP



Geschrieben von LX am 28.02.2003 um 14:59:

 

Zitat:
Original von HarryP
Würde der bot auch diese Fehlermeldung ausgeben wenn ich die files fürs Board noch net eingebaut habe??verwirrt Das ist nämlich der Fall...dachte erst den bot und dann den rest großes Grinsen )
Nope, das hat damit nichts zu tun. Das remote-Skript lässt den Bot lediglich an einem bestimmten Port auf Eingaben horchen, die er dann in einen Channel durchgibt. Ob da nun letztendlich Eingaben kommen oder nicht ist egal.



Geschrieben von HarryP am 28.02.2003 um 17:30:

 

Ich dacht Port 12345 würde da auch gehen...tut er aber offensichtlich net ...jetzt mit einem 4stelligen Port

Das ergebnis:
[17:05] Module loaded: remote
[17:05] Module loaded: notes (with lang support)
[17:05] Module loaded: console (with lang support)
[17:05] Module loaded: seen
[17:05] Module loaded: blowfish
[17:05] Module loaded: assoc (with lang support)

Ich hoffe das ich es geschafft habe.... großes Grinsen

Mfg
HarryP


Forensoftware: Burning Board 2.3.6, entwickelt von WoltLab GmbH