Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/php
- <?php
- $night_int = 20;
- $day = intval(date('w'));
- $hour = intval(date('G'));
- $min = intval(date('i', time() + 10));
- echo(date('r')."\n");
- if (in_array($day, array(0, 6)) || ($hour < 9) || ($hour > 17)) {
- if ($min % $night_int) {
- echo("off-hours, skipping..\n");
- exit(0);
- }
- }
- $hdl = mysql_connect('localhost', 'user', 'pass');
- mysql_select_db('mydb', $hdl);
- $prefs = array();
- $q = "SELECT * FROM prefs WHERE (name IN ('site_pass', 'site_cookie'))";
- $r = mysql_query($q, $hdl);
- while ($a = mysql_fetch_assoc($r)) {
- $prefs[$a['name']] = $a['value'];
- }
- $sfd = fsockopen('www.coldfusioncoderz.com', 80);
- $resp = http('/users/list.php');
- $tmp = explode('<div class="content_area">', $resp);
- $users = array();
- for ($i = 1; $i < count($tmp); $i++) {
- $pos1 = strpos($tmp[$i], '<a href="/users/') + 18;
- $pos2 = strpos($tmp[$i], '.php">', $pos1);
- $pos3 = strpos($tmp[$i], 'uid=', $pos2) + 7;
- $pos4 = strpos($tmp[$i], '&', $pos3);
- $pos5 = strpos($tmp[$i], '"', $pos3);
- if (!$pos4 || ($pos5 < $pos4)) {
- $pos4 = $pos5;
- }
- $name = substr($tmp[$i], $pos1, ($pos2 - $pos1));
- $id = substr($tmp[$i], $pos3, ($pos4 - $pos3));
- $users[$name] = $id;
- }
- if (!count($users)) {
- echo("could not find any users, bailing..\n");
- exit(1);
- }
- $q = "SELECT * FROM user_alerts";
- $r = mysql_query($q, $hdl);
- $tmp = array();
- while ($a = mysql_fetch_assoc($r)) {
- if (isset($users[$a['user']])) {
- unset($users[$a['user']]);
- $tmp[] = $a;
- } else {
- $del = "DELETE FROM user_alerts WHERE (user = '" . mysql_escape_string($a['user']) . "')";
- mysql_query($del, $hdl);
- }
- }
- foreach ($users as $user => $uid) {
- $ins = "INSERT INTO user_alerts (user, user_id) VALUES ('" . mysql_escape_string($user) . "', '" . mysql_escape_string($uid) . "')";
- mysql_query($ins, $hdl);
- $tmp[] = array('user' => $user, 'user_id' => $uid, 'last_activity' => 0);
- }
- $users = $tmp;
- foreach ($users as $user) {
- $url = '/activity.php&uid=' . $user['user_id'];
- $data = http($url);
- $data = explode('<div class="user_activity_class"><a href="', $data);
- $acts = array();
- $last_act = 0;
- for ($i = 1; $i < count($data); $i++) {
- $pos = strpos($data[$i], '"');
- $tmp = substr($data[$i], 0, $pos);
- $act_id = intval(substr($tmp, (strrpos($tmp, '#') + 1)));
- if (!$last_act) {
- $last_act = $act_id;
- }
- if (!$user['last_activity'] || ($act_id == $user['last_activity'])) {
- break;
- }
- activity_alert($user['user'], $tmp);
- }
- if ($user['last_activity'] != $last_act) {
- $upd = "UPDATE user_alerts SET last_activity = '" . mysql_escape_string($last_act) . "' WHERE (user = '" . mysql_escape_string($user['user']) . "')";
- mysql_query($upd, $hdl);
- }
- }
- function activity_alert($user, $act)
- {
- static $sfd;
- if (!is_resource($sfd)) {
- $sfd = fsockopen('localhost', 66670);
- }
- $msg = "RAW PRIVMSG #ColdFusionCoderz :Activity Alert! $user has done $act\r\n";
- echo($msg);
- fwrite($sfd, $msg);
- }
- function http($url, $post = array(), $is_login = false)
- {
- if (!isset($GLOBALS['prefs']['site_cookie']) && !$is_login) {
- login();
- }
- $type = count($post) ? 'POST' : 'GET';
- $req = array(
- $type . ' ' . $url . ' HTTP/1.1',
- 'Host: www.coldfusioncoderz.com',
- 'Keep-Alive: 300',
- 'Connection: keep-alive',
- );
- if (isset($GLOBALS['prefs']['site_cookie'])) {
- $req[] = 'Cookie: ' . $GLOBALS['prefs']['site_cookie'];
- }
- if (count($post)) {
- $post_data = '';
- foreach ($post as $k => $v) {
- $post_data .= urlencode($k) . '=' . urlencode($v) . '&';
- }
- $post_data = substr($post_data, 0, -1);
- $req[] = 'Content-Type: application/x-www-form-urlencoded';
- $req[] = 'Content-length: ' . strlen($post_data);
- $req[] = "\r\n" . $post_data;
- }
- $req = implode("\r\n", $req) . "\r\n\r\n";
- fwrite($GLOBALS['sfd'], $req);
- $resp = '';
- $chunked = false;
- $length = 0;
- while (1) {
- $tmp = fgets($GLOBALS['sfd']);
- $resp .= $tmp;
- if (!$length && !$chunked) {
- $lower = strtolower($tmp);
- if (strpos($lower, 'content-length') !== false) {
- $length = intval(substr($lower, 15));
- } else if (strpos($lower, 'transfer-encoding: chunked')) {
- $chunked = true;
- }
- }
- if (!trim($tmp)) {
- break;
- }
- }
- $read = 0;
- $to_read = 65000;
- while (1) {
- if ($length) {
- while ($read < $length) {
- $t = $length - $read;
- if ($t < $to_read) {
- $to_read = $t;
- }
- $s = fread($GLOBALS['sfd'], $to_read);
- $read += strlen($s);
- $resp .= $s;
- }
- $length = 0;
- } else if ($chunked) {
- $length = hexdec(trim(fgets($GLOBALS['sfd'])));
- $read = 0;
- $to_read = 65000;
- } else {
- sleep(1);
- fwrite($GLOBALS['sfd'], "\r\n");
- return $resp;
- }
- }
- }
- function login()
- {
- $post = array(
- 'username' => 'cold_fusion_rockz',
- 'password' => $GLOBALS['prefs']['site_pass'],
- );
- $login = http('/login.php', $post, true);
- if (!strpos($login, 'PHPSESSID=')) {
- echo("no cookie got on login!\n");
- exit(1);
- }
- $tmp = explode('Set-Cookie: PHPSESSID=', $login);
- $tmp2 = explode(';', $tmp[1]);
- $cookie = "PHPSESSID=" . $tmp2[0];
- $del = "DELETE FROM prefs WHERE (name = 'site_cookie')";
- mysql_query($del, $GLOBALS['hdl']);
- $ins = "INSERT INTO prefs (name, value) VALUES ('site_cookie', '" . mysql_escape_string($cookie) . "')";
- mysql_query($ins, $GLOBALS['hdl']);
- $GLOBALS['prefs']['site_cookie'] = $cookie;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement