For some reason my bot wont private message a % of people on the IRC Channel. Here is my script:
<?php
$ircServer = "///";
$ircPort = "6667";
$ircChannel = "#bots";
set_time_limit(0);
$msg = $_POST['message'];
$pr = $_POST['percentage'];
$pr /= 100;
$ircSocket = fsockopen($ircServer, $ircPort, $eN, $eS);
if ($ircSocket)
{
fwrite($ircSocket, "USER Lost rawr.test lol :code\n");
fwrite($ircSocket, "NICK Rawr" . rand() . "\n");
fwrite($ircSocket, "JOIN " . $ircChannel . "\n");
while(1)
{
while($data = fgets($ircSocket, 128))
{
echo nl2br($data);
flush();
// Separate all data
$exData = explode(' ', $data);
// Send PONG back to the server
if($exData[0] == "PING")
{
fwrite($ircSocket, "PONG ".$exData[1]."\n");
}
}
echo $eS . ": " . $eN;
}
shuffle($users);
$size = count($users);
$target = $size * $pr;
$target = $round($target);
for ($i = 0; $i <= $target; $i++) {
fwrite($ircSocket, "PRIVMSG " . $users[$i] . " :" . $msg . "\n");
}
}
?>
Here is the log on what I recieve:
:StatServ!stats#Mazzzzz.com PRIVMSG Rawr30566 :VERSION
I have even tried removing the Post data and replaced this part with this:
$msg = $_POST['message'];
With
$msg = hello;
The other people on the channel does not get a private message.
Is this your entire script? $users isn't set to anything; you probably meant to set it to an array of usernames. $round also isn't set; you probably meant to just call the built-in round() function. If you add a debugging line in the for loop you can at least tell which users (if any) should be getting messages:
for ($i = 0; $i <= $target; $i++) {
echo "Sending message to ${users[$i]}\n";
fwrite($ircSocket, "PRIVMSG " . $users[$i] . " :" . $msg . "\n");
}
The IRC protocol stuff looks right. The receive log you were worried about doesn't have anything to do with it; StatServ on the IRC server is sending your bot a CTCP VERSION request. Normally clients respond with their name and version, and StatServ probably logs it so opers can see what clients are common on the network
Related
this is the issue, i write a php socket, it work as a daemon, every time, and i have a client side, the client connect but every 30 seconds client automaticaly disconnect, it is happening because socket do not send himself a line (ka();) every 30 seconds, the (ka();) line is readed by the client and keep a constant conection, i have tried making a function inside the socket, so every 30 seconds write (ka();), but it does not work, it work wrong, it show the (ka();) if the client send something to the socket, if client side do not send anything the socket do not sent the anything.
the socket work has a daemon CLI windows and the client side is just javascript, when the socket is running, can be accesed directly by navigator and read what client send, if the client do not send anything, the socket need write the (ka();) line, so it is readed by client side and keep conection and so indefinitely.
this is the socket script
error_reporting(1);
ini_set('display_errors', '1');
define('CON_IP', '127.0.0.1');
define('CON_PORT', 1000);
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
$max_clients = MAX_CLIENTS;
socket_set_option($socket, SOL_SOCKET, SO_REUSEADDR, 1);
socket_bind($socket, CON_IP, CON_PORT);
socket_listen($socket, $max_clients);
$clients = array(
'0' => array(
'socket' => $socket
)
);
echo "Server running....\n\n";
echo "Server Started on : " . date('Y-m-d H:i:s') . "\n";
echo "Listening on : " . CON_IP . " port " . CON_PORT . "\n";
echo ".... awaiting connections ...\n\n";
$session = (TRUE);
while ($session === TRUE) {
$read[0] = $socket;
for ($i = 1; $i < count($clients) + 1; ++$i) {
if ($clients[$i] != NULL) {
$read[$i + 1] = $clients[$i]['socket'];
}
}
$ready = socket_select($read, $write = NULL, $except = NULL, $tv_sec = NULL);
if (in_array($socket, $read)) {
for ($i = 1; $i < $max_clients + 1; ++$i) {
if (!isset($clients[$i])) {
$clients[$i]['socket'] = socket_accept($socket);
socket_getpeername($clients[$i]['socket'], $RemoteAddr, $RemotePort);
$clients[$i]['ipadd'] = $RemoteAddr . ':' . $RemotePort;
echo 'Incoming connection from ' . $clients[$i]['ipadd'] . "]\r\n";
break;
} elseif ($i == $max_clients - 1) {
echo 'Clients Overload!' . "\r\n";
}
if ($ready < 1) {
continue;
}
}
}
for ($i = 1; $i < $max_clients + 1; ++$i) {
if (in_array($clients[$i]['socket'], $read)) {
if (!$client[$i]['iframe']) {
$data = #socket_read($clients[$i]['socket'], 1024, PHP_BINARY_READ);
}
if (substr($data, 0, 3) == 'GET' || substr($data, 0, 4) == 'POST' || substr($data, 0, 4) == 'OPTI') {
$clients[$i]['iframe'] = true;
echo 'Incoming connection from browser [' . $clients[$i]['ipadd'] . "]\r\n";
socket_write($clients[$i]['socket'], "HTTP/1.1 200 OK\r\n");
socket_write($clients[$i]['socket'], "Content-Type: text/html; charset=utf-8;\r\n");
socket_write($clients[$i]['socket'], "Cache-Control: private\r\n\r\n");
for ($z = 0; $z < 4096; $z++)
$Brk = ("\n");
$html = ('<!DOCTYPE html>' . $Brk);
$html .= ('<html>' . $Brk);
$html .= ('<head>' . $Brk);
$html .= ('</head>' . $Brk);
$html .= ('<body>' . $Brk);
$html .= ('<script>' . $Brk);
$html .= ('function recv(packets){}' . $Brk);
$html .= ('</script>' . $Brk);
$html .= ('</body>' . $Brk);
socket_write($clients[$i]['socket'], $html);
} else {
if (trim($data) != '' && strlen(str_replace(' ', '', trim($data))) > 1) {
$msgs = ($data);
}
}
if ($data === FALSE) {
echo 'Incoming disconnection of ' . $clients[$i]['ipadd'] . "]\r\n";
unset($clients[$i]);
continue;
}
$data = trim($data);
if (!empty($data)) {
//LOGS
if ($msgs) {
$ClientDumpLog = fopen('log/InputToSocket.txt', "a");
fwrite($ClientDumpLog, "$msgs\n");
fclose($ClientDumpLog);
}
//
for ($j = 1; $j < $max_clients + 1; ++$j) {
if (isset($clients[$j]['socket']) and ($msgs !== NULL)) {
echo ('[' . $clients[$i]['ipadd'] . '] OK!' . "\r\n");
socket_write($clients[$j]['socket'], '<script>' . $msgs . "</script>\r\n");
}
}
break;
}
}
}
}
EDIT:
this solution, i think it was, but no, this code block, to test, writed after this line:
for ($j = 1; $j < $max_clients + 1; ++$j) {
$last_time = time();
while(true) {
if(time()-$last_time > 10) {
echo ('[' . $clients[$i]['ipadd'] . '] KA!' . "\r\n");
socket_write($clients[$j]['socket'], "ka();\r\n");
$last_time = time();
}
}
when i put this code, when the socket start, it show every (chosed time) in cli (KA!), when i access by navigator it show the (ka();) line too, but when the client side send something it never show, is like the (ka) line or what the client send, but no both at the same time.
somebody know some function or solution to make it work?
You have to override the maximum execution time setting of php.ini. You should not change it within php.ini - you rather should change it on top of your code:
<?php
set_time_limit(0);
//... your fancy code here...
I am having this below code, It is work perfectly. But am having a small issue messuring the "$username_index" count.
the main idea of my code is following:
having accounts.txt [92 lines] usernames:pass format.
having usernames.txt [99999 lines] usernames format.
It will login to account1, then it will add 95 usernames, then next account2 , then add next 95 usernames.
But some accounts are giving response "Too many add friends". In this case response, I will skip the account and go to next.
But below code will contiue to the next 95!, so its skip 95 from usernames!
I want it contiue adding where the left username from skipped account.
I want it as soon it will login to the next account AND CONTIUING ADD THE NEXT LINE OF USERNAMES! no need to jump to next 95 username to add!
Example how i want it:
login account1
add username1
add username2
ERROR APPEARS!
login account2
add username3
add username4
add username5
add username6
error appears!
login account3
add username7
add username8
etc..
Current Code:
$username_index = 0;
while(true) { // This is our while.. yes but this not for login()!
try {
$names = readFromFile("usernames.txt", 95, $username_index);
if(count($names) <= 0)
break;
sleep(1);
$fuckc = 0;
foreach($names as $name){
$ans = $API->addFriend($name);
$var_response = $ans->getMessage();
if (strpos($var_response, 'too many friends!') !== false) {
printf("[!] Too many friends!, Skipping account now.\n");
break;
}
if (strpos($var_response, 'Sorry') === false) {
$fuckc++;
printf("[+]" . "[" . date("h:i:s") . "]" . "[" . $fuckc . "] " . "response: " . $var_response . "\n");
//printf("[" . $fuckc . "] " . "response: " . $var_response . "\n");
}
//sleep(SLEEP_TIME);
}
$username_index += 95;
$API->logout();
//rotate_proxy();
$API = null;
//sleep(waiting);
//$results = $findFriends->getResults();
if (!isset($results) || count($results) == 0) {
if(!login()) die("Could not find a valid account.\n");
}
} catch(Exception $e){
echo $e->getMessage() . "\n";
if(!login()) die("Could not find a valid account.\n");
}
}
Edited again : the counter $username_index only increasse when $var_response is not "too many friends!" :
$username_index = 0;
while(true) { // This is our while.. yes but this not for login()!
try {
$names = readFromFile("usernames.txt", 95, $username_index);
if(count($names) <= 0)
break;
sleep(1);
$fuckc = 0;
foreach($names as $name){
$ans = $API->addFriend($name);
$var_response = $ans->getMessage();
if (strpos($var_response, 'too many friends!') !== false) {
printf("[!] Too many friends!, Skipping account now.\n");
break;
}
else $username_index++; //◄■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
if (strpos($var_response, 'Sorry') === false) {
$fuckc++;
printf("[+]" . "[" . date("h:i:s") . "]" . "[" . $fuckc . "] " .
"response: " . $var_response . "\n");
//printf("[" . $fuckc . "] " . "response: " . $var_response . "\n");
}
//sleep(SLEEP_TIME);
}
// $username_index += 95; //◄■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
$API->logout();
//rotate_proxy();
$API = null;
//sleep(waiting);
//$results = $findFriends->getResults();
if (!isset($results) || count($results) == 0) {
if(!login()) die("Could not find a valid account.\n");
}
} catch(Exception $e){
echo $e->getMessage() . "\n";
if(!login()) die("Could not find a valid account.\n");
}
}
I seem to be having a weird issue when attempting to run pthreads in php. I'm currently attempting to use the threads to manage additional calling of other php scripts, but my program is exiting prematurely, whenever I attempt to use Mutex::unlock. I've tried re-installing different versions of 64 bit pthreads as well as tested examples (of which, the mutex here works ). I think it may be a problem with popen. Has anyone hit this error before or know of a good way to debug it?
The code I'm using is as follows:
<?php
class lockedThread extends Thread {
public function __construct($func, $megalog, $mutex){
$numargs = func_num_args();
$this->megalog = $megalog;
$this->func = $func;
if ($numargs == 3) {
$this->mutex = array($mutex);
} else {
$arg_list = func_get_args();
$this->mutex = array_slice($arg_list, 2);
}
}
public function run() {
echo "Beginning " . $this->func . " \n";
for ($i = 0; $i < count($this->mutex); $i++) {
$locked = Mutex::lock($this->mutex[$i]);
while($locked == false) {
sleep(0.5);
$locked = Mutex::lock($this->mutex[$i]);
}
printf($this->getThreadId() . " acquired lock " . $this->mutex[$i] . "\n");
}
$this->res = popen("php Functions/" . $this->func . ".php"
. " >> logs/" . $this->func . ".log", 'r');
printf("closing " . $this->func . ": " . pclose($this->res) . "\n");
for ($i = count($this->mutex) - 1; $i >= 0; $i -= 1) {
printf($this->getThreadId() . " attempting to release lock " . $this->mutex[$i] . "\n");
Mutex::unlock($this->mutex[$i]);
echo $this->getThreadId() . " released lock " . $this->mutex[$i] . "\n";
}
echo "really closing " . $this->func . "\n";
}
}
}
// Create the mutex. Note, the connections mutex will always come first
$connMutex = Mutex::create(true);
$eventMutex = Mutex::create(true);
$workers["checkRecurrence"] = new lockedThread("checkRecurrence", $megalog, $eventMutex);
$workers["checkRecurrence"]->start();
echo "checkRecurrence is " . $workers["checkRecurrence"]->getThreadId() . "\n";
$workers["checkDeletion"] = new lockedThread("checkDeletion", $megalog, $eventMutex);
$workers["checkDeletion"]->start();
echo "checkDeletion is " . $workers["checkDeletion"]->getThreadId() . "\n";
echo "Unlocking conn: " . Mutex::unlock($connMutex) . "\n";
echo "Unlocking event: " . Mutex::unlock($eventMutex) . "\n";
foreach($workers as $i=>$worker) {
echo "Joining $i \n";
while ($worker->join() === false) {
echo "Attempt of $i \n";
}
echo "Joined $i \n";
}
sleep(1);
echo "Finishing destruction of workers!\n";
/* please remember to destroy mutex and condition variables */
Mutex::destroy($connMutex);
Mutex::destroy($eventMutex);
The logs I'm getting are:
"C:\wamp\bin\php\php5.5.12\php.exe" "C:\wamp\www\hang\PHPAutomation\index.php"
Beginning checkRecurrence
checkRecurrence is 8576
Beginning checkDeletion
checkDeletion is 9144
Started all workers
Unlocking conn: 1
Unlocking event: 1
Joining checkRecurrence
8576 acquired lock 52687024
closing checkRecurrence: 0
8576 attempting to release lock 52687024
Done.
A user over at w3schools forums assisted me with some code on using IMAP functions to check my mail inbox on a private server and do what i like with it, i created my own set of functions for posting the e-mail content to a MySQL table.
Could somebody help me find a solution to how can i open the e-mail inbox, check for e-mails in the inbox (There will be only one there because previous emails will be automatically deleted. Define the open e-mail message as $open_email_msg
Allow me to initiate my set of commands for posting the e-mail to a MySQL table, then delete the e-mail and close the inbox?
This is the code the person assisted me with:
<?php
$now = time(); // current time
$mailbox = '{192.168.150.11:143/imap/novalidate-cert}'; // see http://www.php.net/manual/en/function.imap-open.php
$mbox = imap_open($mailbox, 'username', 'password'); // log in to mail server
if (!$mbox)
echo ('Failed opening mailbox<br>' . print_r(imap_errors(), true)); // remove the print_r for production use
else
{
$box = imap_check($mbox); // get the inbox
for ($imap_idx = 1; $imap_idx <= $box->Nmsgs; $imap_idx++) // loop through the messages
{
$headers = imap_headerinfo($mbox, $imap_idx); // http://www.php.net/manual/en/function.imap-headerinfo.php
$raw_headers = imap_fetchheader($mbox, $imap_idx); // http://www.php.net/manual/en/function.imap-fetchheader.php
$selected_headers = '';
$text_part = '';
$html_part = '';
$original_message = imap_body($mbox, $imap_idx); // save the copy of the entire thing, attachments and all
// build selected headers string
for ($ii = 0; $ii < count($headers->from); $ii++)
$selected_headers .= 'From: ' . $headers->from[$ii]->mailbox . '#' . $headers->from[$ii]->host . "\n";
for ($ii = 0; $ii < count($headers->to); $ii++)
$selected_headers .= 'To: ' . $headers->to[$ii]->mailbox . '#' . $headers->to[$ii]->host . "\n";
for ($ii = 0; $ii < count($headers->cc); $ii++)
$selected_headers .= 'Cc: ' . $headers->cc[$ii]->mailbox . '#' . $headers->cc[$ii]->host . "\n";
for ($ii = 0; $ii < count($headers->bcc); $ii++)
$selected_headers .= 'Bcc: ' . $headers->bcc[$ii]->mailbox . '#' . $headers->bcc[$ii]->host . "\n";
if (!empty($headers->date))
$selected_headers .= 'Date: ' . $headers->date . "\n";
if (!empty($headers->subject))
$selected_headers .= 'Subject: ' . $headers->subject . "\n";
// see below; getMsg uses global variables
getMsg($mbox, $imap_idx);
$text_part = $plainmsg; // text portion of the email
$html_part = $htmlmsg; // html portion of the email
// check for text portion first
$msg_text = trim(strip_tags($plainmsg
Try this code to read emails.
$username="yourusername#yourmailhost.com";
$password="yourPassword123!";
$hostname="{imap.hostinger.com:993/imap/ssl}INBOX";
$imap=imap_open($hostname,$username,$password) or die('Cannot connect: '.imap_last_error());
$message_count = imap_num_msg($imap);
echo "<b>$message_count messages</b><br>";
for ($i = 1; $i <= $message_count; ++$i){
$header = imap_header($imap, $i);
$body = imap_fetchbody($imap, $i, '2');
$prettydate = date("jS F Y", $header->udate);
if(isset($header->from[0]->personal)){
$personal = $header->from[0]->personal;
}else{
$personal = $header->from[0]->mailbox;
}
$subject=$header->Subject;
$email = "$personal <{$header->from[0]->mailbox}#{$header->from[0]->host}>";
echo "On $prettydate, $email said \"$body\".\n";
echo '<br><br>';
}
print_r(imap_errors());
imap_close($imap);
I believe this link will help you as I used this myself and this is properly working for me.
There you can register and download the code, using it is simple.
Or what you can do if you want to get the information of header only is:
$mbox = imap_open("{xyz#abc.com:995/pop3/ssl/novalidate-cert}INBOX", 'abc#xyz.com', 'pass')
or die("can't connect: " . imap_last_error());
$MC = imap_check($mbox);
$result = imap_fetch_overview($mbox,"1:{$MC->Nmsgs}",0);
foreach ($result as $overview) {
echo "#{$overview->msgno} ({$overview->date}) - From: {$overview->from}
{$overview->subject}\n";
echo "<br>";
}
I have been figuring about and trying to make my IRC bot send private messages to % of users on the channel however it's not working.
Here is my script, you will understand it when you see it:
<?php
/**
* Configuration.
* Pretty self-explanatory
*/
$ircServer = "//";
$ircPort = "6667";
$ircChannel = "#//";
set_time_limit(0);
$msg = $_POST['message'];
$pr = $_POST['percentage'];
$pr /= 100;
$ircSocket = fsockopen($ircServer, $ircPort, $eN, $eS);
if ($ircSocket)
{
fwrite($ircSocket, "USER Lost rawr.test lol :code\n");
fwrite($ircSocket, "NICK Rawr" . rand() . "\n");
fwrite($ircSocket, "JOIN " . $ircChannel . "\n");
while(1)
{
while($data = fgets($ircSocket, 128))
{
echo nl2br($data);
flush();
// Separate all data
$exData = explode(' ', $data);
// Send PONG back to the server
if($exData[0] == "PING")
{
fwrite($ircSocket, "PONG ".$exData[1]."\n");
}
}
echo $eS . ": " . $eN;
}
shuffle($users);
$size = count($users);
$target = $size * $pr;
$target = $round($target);
for ($i = 0; $i <= $target; $i++) {
fwrite($ircSocket, "PRIVMSG " . $users[$i] . " :" . $msg . "\n");
}
?>
Evertime I try re-coding it here is the error: Parse error: syntax error, unexpected $end in C:\xampp\htdocs\irc.php on line 55
I am trying to make a percentage system that will shuffle the % of users on the IRC channel to private message a set % on the shuffle system.
unexpected $end means it reached the end of the file and all your blocks ({}) weren't closed. It's right, you have more open braces than close braces; you forgot to close one somewhere. Based on the indenting, I think you meant to close your inner while loop right after the if statement:
while(1)
{
while($data = fgets($ircSocket, 128))
{
echo nl2br($data);
flush();
// Separate all data
$exData = explode(' ', $data);
// Send PONG back to the server
if($exData[0] == "PING")
{
fwrite($ircSocket, "PONG ".$exData[1]."\n");
}
} // <-- THIS IS NEW
}
Just from skimming the code, I don't see anything obviously wrong with the approach, but I didn't actually try it
you forget the '}' for
if ($ircSocket) {