now with stats
1 parent 1826379 commit 804483f0f51d0d6af9ab5877a5286b2bee465256
root authored on 6 Aug 2021
Showing 2 changed files
View
10
README.md
 
Bot to connect badge to IRC for sharing and validating codes
 
simply git clone this repo
 
make sure you have the correct interface at top of script (default is /dev/ttyACM0)
 
````
php bot.php
```
(thanks to SkarDude)
 
the device cannot be busy when running this script, i.e. kill your screen sessions!
 
If your badge is generating short hashes this will automagically fix that.
 
If you want to see your badge stats type in the IRC channel:
 
```
!stats <rand>
```
(replacing rand with your badge's random ID generated when running the script)
View
82
bot.php
$fixedCode .= substr($code, 9);
$fixedCode .= substr($code, 16, strlen($code));
return $fixedCode;
}
function get_stats_connected(){
global $badgeInterface;
$serial = new PhpSerial;
$serial->deviceSet($badgeInterface);
$serial->confBaudRate(9600);
$serial->deviceOpen('w+');
stream_set_timeout($serial->_dHandle, 3);
$serial->sendMessage("\r\n\r\n5\r\n\r\n");
$devResponse = $serial->readPort();
$serial->deviceClose();
 
$toReturn = trim(preg_replace('/\s+/', ' ', $devResponse));
$toReturn = trim(string_between_two_string($toReturn, 'Number of Badges Connected: ', 'Badge Types'));
//echo $toReturn; // DEBUG
 
return $toReturn;
}
function get_stats_signal(){
global $badgeInterface;
$serial = new PhpSerial;
$serial->deviceSet($badgeInterface);
$serial->confBaudRate(9600);
$serial->deviceOpen('w+');
stream_set_timeout($serial->_dHandle, 3);
$serial->sendMessage("\r\n\r\n5\r\n\r\n");
$devResponse = $serial->readPort();
$serial->deviceClose();
 
$toReturn = trim(preg_replace('/\s+/', ' ', $devResponse));
$toReturn = trim(string_between_two_string($toReturn, 'Shared the Signal: ', 'Thank you'));
//echo $toReturn; // DEBUG
 
return $toReturn;
}
function string_between_two_string($str, $starting_word, $ending_word){
$subtring_start = strpos($str, $starting_word);
$subtring_start += strlen($starting_word);
$size = strpos($str, $ending_word, $subtring_start) - $subtring_start;
return substr($str, $subtring_start, $size);
}
 
$rand = substr(str_shuffle(str_repeat($x='0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', ceil(8/strlen($x)) )),1,8);
 
// announce self to channel
$myCode = get_own_code();
$myCode = (strlen($myCode) == 31) ? short_code($myCode) : $myCode;
if(!isset($myCode) || $myCode == "")
die("Please contact 0xRoM on discord for help fixing this issue!");
 
$badgeConn = get_stats_connected();
$badgeSig = get_stats_signal();
echo "[+] connected: $badgeConn, Sig shared: $badgeSig\n";
 
$socket = fsockopen("ice.uplinkcorp.net", 6667);
// Send auth info
// fputs($socket, "PASS " . $password . "\n");
array_push($collected, $ex[4]); // add to replied array
 
$myCode = get_own_code();
$myCode = (strlen($myCode) == 31) ? short_code($myCode) : $myCode;
 
fputs($socket, "PRIVMSG #theSignal :!req " . $rand . " " . $myCode . "\n");
echo "[+] replied to ".$ex[4]."\n";
}else{echo "[-] invalid code\n";}
}else{echo "[-] already exchanged\n";}
}else{echo "[-] no code\n";}
}else{echo "[-] no name\n";}
}else{ echo "[-] invalid code\n"; }
}else{ echo "[-] already exchanged\n"; }
}else{ echo "[-] no code\n"; }
}else{ echo "[-] no name\n"; }
}
if ($command == ":!rsp") {
if ($ex[4] == $rand && isset($ex[5]) && $ex[5] <> ""){ // response is for this bot
get_code($ex[5]);
echo "[+] got response from ".$ex[4]."\n";
}else{echo "[-] not for me\n";}
if ($ex[4] == $rand){ // response is for this bot
if(isset($ex[5]) && $ex[5] <> ""){ // code for me
get_code($ex[5]);
echo "[+] got response from ".$ex[4]."\n";
}else{ echo "[-] no code set\n"; }
}else{ echo "[-] not for me\n"; }
}
if ($command == ":!stats") {
if (trim($ex[4]) === $rand){ // response is for this bot
$badgeConn = get_stats_connected();
$badgeSig = get_stats_signal();
echo "[+] connected: $badgeConn, Sig shared: $badgeSig\n";
fputs($socket, "PRIVMSG #theSignal :Connected = $badgeConn, Sig shared = $badgeSig\n");
}else{ echo "[-] not for me \n".$ex[4]."\n$rand\n"; }
}
}
}
}
Buy Me A Coffee