-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathconnect.php
More file actions
executable file
·88 lines (82 loc) · 2.23 KB
/
Copy pathconnect.php
File metadata and controls
executable file
·88 lines (82 loc) · 2.23 KB
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
<?php
//#########################################################
// Part of project php-IRC-js
//
// connect.php - connect to server and send commands
//
// Author: Mario Chorvath - Bedna
// Start 2016
//
// Licence GNU General Public License
// Version 2
// http://www.gnu.org/licenses/old-licenses/gpl-2.0.en.html
//#########################################################
// Settings
$ircServer = "irc.freenode.net";
$ircPort = "6667";
$ircChannel = "#KERNEL_ULTRAS";
// Set variables
$loop = "loop";
// Set unlimite execution time
set_time_limit(0);
// Connect to server
$ircSocket = pfsockopen ($ircServer, $ircPort, $eN, $eS);
// If socket open
if ($ircSocket) {
// Login bot
fwrite ($ircSocket, "USER KU-bot127c 0 lol :Kubo137c\r\n");
fwrite ($ircSocket, "NICK KU-bot137c\r\n");
// Join to channel
fwrite ($ircSocket, "JOIN " . $ircChannel . "\r\n");
// Send message to channel
fwrite ($ircSocket, "PRIVMSG #KERNEL_ULTRAS :Im here\r\n");
// Open file "server_response.txt" for write
$handle = fopen ("server_response.txt", "w");
// Open file for logs
$handle_log = fopen ("log.txt", "w");
// Write log
fwrite ($handle_log, "FIRST\n");
while (1) {
// Write log
fwrite ($handle_log, "MAIN\n");
// Read command from file "send"
if (file_exists ("send")) {
// Read command
$command = file_get_contents ("send");
// Remove file
unlink ("send");
// Timeout "for sure"
sleep (1);
// Write command to socket
fwrite ($ircSocket, "$command"."\r\n");
// Flush command to socket
flush ();
// Write log
fwrite ($handle_log, "SEND :$command\n");
}
// If IRC server send message to client
while ($data = fgets ($ircSocket, 128)) {
// fwrite ($handle_log, "DATA :".$data."\n");
fwrite ($handle_log, "READ\n");
// Separate all data by space
$exData = explode (' ', $data);
// Send PONG back to the server
if ($exData[0] == "PING") {
// Write log
fwrite ($handle_log, "PING :".$exData[1]."\n");
// Write PONG to server
fwrite ($ircSocket, "PONG ".$exData[1]."\r\n");
}
// If response other than PING
else {
// Write response to file "server_response.txt"
fwrite ($handle, nl2br ($data));
}
}
}
}
// If error on connection
else {
echo $eS . ": " . $eN;
}
?>