-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.php
221 lines (201 loc) · 6.38 KB
/
main.php
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
<?php
set_time_limit(0);
if(@$child != true)
{
$server = "irc.freenode.net";
$connection = fsockopen($server,6667); //connect
$channels = array("#wenetapls","#hexley","##fuck-you","#jurgenbot");
$self = $_SERVER['PHP_SELF'];
$nick = "s0m3b0t";
fputs ($connection, "USER {$nick} {$nick} {$nick} http://leetfiles.com\n");
fputs ($connection, "NICK {$nick}\n");
foreach($channels as $channel)
{
echo "Joining {$channel}\n";
fputs ($connection, "JOIN {$channel}\n");
}
}
//stream_set_blocking($connection,0);
//$we = fopen ("php://stdin","r"); // enable cli input
//stream_set_blocking($we,0);
while(1)
{
/*$mydata = fgets($we);
if($mydata)
{
fputs($connection, "{$mydata}\n"); // check for input on the CLI and send them
}*/
while($data = fgets($connection)){ // check for messages on the irc side
echo $data;
flush();
$data = str_replace("\n","",str_replace("\r","",$data));
$a1 = explode(' ', $data);
$a2 = explode(':', @$a1[3]);
$a3 = explode('@', @$a1[0]);
$a4 = explode('!', @$a3[0]);
$a5 = explode(':', @$a4[0]);
$a6 = explode(':', @$data);
$command = @substr($a1[3],1); // remove the :
$argco = sizeof($a1)-4; // argument count
$arga = Array(); for($i = 4;$i<sizeof($a1);$i++) { $arga[] = $a1[$i]; }// argument array
$args = implode($arga," "); // argument string
$user = @$a5[1];
$channel = @$a1[2];
$hostmask = @$a3[1];
$irccloud_uid = @$a4[1];
$rawcmd = @$a1[1];
if($a1[0] == "PING"){fputs($connection, "PONG ".$a1[1]."\n");} // respond to pings from the irc server
/***
commands section
***/
if($rawcmd == "INVITE") // follow invites
{
fputs($connection,"JOIN {$command}\n");
fputs($connection,"PRIVMSG {$command} :Hello, {$user} invited me to join this channel.\n");
}
//////////////////
if($command == "test")
{
fputs($connection,"PRIVMSG {$channel} :{$user}: u r of #tester\n");
}
///////////////////
if($command == "!say")
{
fputs($connection,"PRIVMSG {$channel} :{$args}\n");
}
///////////////////
if($command == $nick . ":") // if someone says {$nick}: something
{
if($arga[0] == "stfu")
{
fputs($connection,"PRIVMSG {$channel} :{$user}: Please don't insult me. I am a harmless bot.\n");
}
}
//////////////////
if($command == "!restart") // the second or third fork always results in a 'Hangup: 1', idk but it works.
{
if(function_exists("pcntl_fork"))
{
echo "Trying to fork." . PHP_EOL;
$pid = pcntl_fork();
if ($pid == -1)
{
fputs($connection,"PRIVMSG {$channel} :Error forking.\n");
echo "Couldn't fork." . PHP_EOL;
}
elseif($pid)
{
// still parent
echo "Still parent. Making ready for rebooting." . PHP_EOL;
fputs($connection,"PRIVMSG {$channel} :Restarting. Notice this goes \002seamlessly\002\n");
if(@$child == true)
{
echo "Child is {$pid}. Killing parent." . PHP_EOL;
posix_kill(posix_getpid(), SIGHUP);
}
else
{
echo "Wating for child with PID {$pid}" . PHP_EOL;
pcntl_wait($a);
echo $a . PHP_EOL;
posix_kill(posix_getpid(), SIGHUP);
}
}
else
{
// running as child
echo "Successfully forked, we are the child." . PHP_EOL;
$me = file($self);
unset($me[0]);
$me = implode(PHP_EOL,$me);
if(get_resource_type($connection) != "Unknown")
{
echo "Reusing existing connection.\n";
$child = true;
}
eval($me);
}
}
else
{
fputs($connection,"PRIVMSG {$channel} :ERROR: function pcntl_fork doesn't exist.\n");
}
}
/////////////////
if($command == "!quit")
{
if($hostmask == "unaffiliated/idaniel")
{
fputs($connection,"QUIT :bye\n");
}
else
{
echo "{$user}@{$hostmask} with the uid: {$irccloud_uid} wanted to kill me :(\n";
fputs($connection,"PRIVMSG {$channel} :{$user} haz no #permission.\n");
}
}
///////////////
if($command == "!source") // dirty but I wanna get this working quickly
{
$ssum = md5_file($self);
if($ssum != file_get_contents("md5"))
{
file_put_contents("md5",$ssum);
$cmd = popen("leetfiles-cli php={$self}","r"); // not smartest way, I know. https://github.com/danieltroger/leetfiles-cli since jq made this session cookie shit.....
$ret = Array();
while(!feof($cmd))
{
$line = fgets($cmd);
$ret[] = $line;
echo $line;
}
$url = substr($ret[sizeof($ret)-2],5,-4);
fclose($cmd);
if(substr($url,0,4) == "http")
{
fputs($connection,"PRIVMSG {$channel} :{$user}: View my source at {$url}\n");
file_put_contents("link",$url);
}
else
{
fputs($connection,"PRIVMSG {$channel} :{$user}: Sorry, something went wrong.\n");
}
}
else
{
fputs($connection,"PRIVMSG {$channel} :{$user}: View my source at " . file_get_contents("link") . "\n");
}
}
//////////////////
if($command == "!join")
{
foreach($arga as $chan)
{
fputs($connection,"JOIN {$chan}\n");
if(str_replace("\r","",$channel) == $nick)
{
fputs($connection,"PRIVMSG {$chan} :{$user} PM'ed me to join here.\n");
}
else
{
fputs($connection,"PRIVMSG {$chan} :{$user} in {$channel} wanted me to join here.\n");
}
}
}
/////////////////
if($command == "!part")
{
fputs($connection,"PART {$channel}\n");
}
/////////////////
/***
end of commands section
***/
if(strpos($data,"ERROR :Closing Link: ") !== false || @$data[0] == "E")
{
fclose($connection);
die("Disconnected.\n");
}
}
}
?>