Advertisement
Guest User

morbiuswilters

a guest
Apr 30th, 2008
357
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 7.10 KB | None | 0 0
  1. #!/usr/bin/php
  2. <?php
  3.  
  4. $night_int = 20;
  5.  
  6. $day = intval(date('w'));
  7. $hour = intval(date('G'));
  8. $min = intval(date('i', time() + 10));
  9.  
  10. echo(date('r')."\n");
  11.  
  12. if (in_array($day, array(0, 6)) || ($hour < 9) || ($hour > 17)) {
  13.         if ($min % $night_int) {
  14.                 echo("off-hours, skipping..\n");
  15.                 exit(0);
  16.         }
  17. }
  18.  
  19. $hdl = mysql_connect('localhost', 'user', 'pass');
  20. mysql_select_db('mydb', $hdl);
  21.  
  22. $prefs = array();
  23.  
  24. $q = "SELECT * FROM prefs WHERE (name IN ('site_pass', 'site_cookie'))";
  25. $r = mysql_query($q, $hdl);
  26.  
  27. while ($a = mysql_fetch_assoc($r)) {
  28.         $prefs[$a['name']] = $a['value'];
  29. }
  30.  
  31. $sfd = fsockopen('www.coldfusioncoderz.com', 80);
  32.  
  33. $resp = http('/users/list.php');
  34.  
  35. $tmp = explode('<div class="content_area">', $resp);
  36.  
  37. $users = array();
  38.  
  39. for ($i = 1; $i < count($tmp); $i++) {
  40.         $pos1 = strpos($tmp[$i], '<a href="/users/') + 18;
  41.         $pos2 = strpos($tmp[$i], '.php">', $pos1);
  42.         $pos3 = strpos($tmp[$i], 'uid=', $pos2) + 7;
  43.         $pos4 = strpos($tmp[$i], '&', $pos3);
  44.         $pos5 = strpos($tmp[$i], '"', $pos3);
  45.  
  46.         if (!$pos4 || ($pos5 < $pos4)) {
  47.                 $pos4 = $pos5;
  48.         }
  49.  
  50.         $name = substr($tmp[$i], $pos1, ($pos2 - $pos1));
  51.         $id = substr($tmp[$i], $pos3, ($pos4 - $pos3));
  52.  
  53.         $users[$name] = $id;
  54. }
  55.  
  56. if (!count($users)) {
  57.         echo("could not find any users, bailing..\n");
  58.         exit(1);
  59. }
  60.  
  61. $q = "SELECT * FROM user_alerts";
  62. $r = mysql_query($q, $hdl);
  63.  
  64. $tmp = array();
  65.  
  66. while ($a = mysql_fetch_assoc($r)) {
  67.         if (isset($users[$a['user']])) {
  68.                 unset($users[$a['user']]);
  69.                 $tmp[] = $a;
  70.         } else {
  71.                 $del = "DELETE FROM user_alerts WHERE (user = '" . mysql_escape_string($a['user']) . "')";
  72.                 mysql_query($del, $hdl);
  73.         }
  74. }
  75.  
  76. foreach ($users as $user => $uid) {
  77.         $ins = "INSERT INTO user_alerts (user, user_id) VALUES ('" . mysql_escape_string($user) . "', '" . mysql_escape_string($uid) . "')";
  78.         mysql_query($ins, $hdl);
  79.         $tmp[] = array('user' => $user, 'user_id' => $uid, 'last_activity' => 0);
  80. }
  81.  
  82. $users = $tmp;
  83.  
  84. foreach ($users as $user) {
  85.         $url = '/activity.php&uid=' . $user['user_id'];
  86.         $data = http($url);
  87.         $data = explode('<div class="user_activity_class"><a href="', $data);
  88.  
  89.         $acts = array();
  90.         $last_act = 0;
  91.  
  92.         for ($i = 1; $i < count($data); $i++) {
  93.                 $pos = strpos($data[$i], '"');
  94.                 $tmp = substr($data[$i], 0, $pos);
  95.                 $act_id = intval(substr($tmp, (strrpos($tmp, '#') + 1)));
  96.  
  97.                 if (!$last_act) {
  98.                         $last_act = $act_id;
  99.                 }
  100.  
  101.                 if (!$user['last_activity'] || ($act_id == $user['last_activity'])) {
  102.                         break;
  103.                 }
  104.  
  105.                 activity_alert($user['user'], $tmp);
  106.         }
  107.  
  108.         if ($user['last_activity'] != $last_act) {
  109.                 $upd = "UPDATE user_alerts SET last_activity = '" . mysql_escape_string($last_act) . "' WHERE (user = '" . mysql_escape_string($user['user']) . "')";
  110.                 mysql_query($upd, $hdl);
  111.         }
  112. }
  113.  
  114.  
  115.  
  116. function activity_alert($user, $act)
  117. {
  118.  
  119.         static $sfd;
  120.  
  121.         if (!is_resource($sfd)) {
  122.                 $sfd = fsockopen('localhost', 66670);
  123.         }
  124.  
  125.         $msg = "RAW PRIVMSG #ColdFusionCoderz :Activity Alert! $user has done $act\r\n";
  126.  
  127.         echo($msg);
  128.  
  129.         fwrite($sfd, $msg);
  130.  
  131. }
  132.  
  133. function http($url, $post = array(), $is_login = false)
  134. {
  135.  
  136.         if (!isset($GLOBALS['prefs']['site_cookie']) && !$is_login) {
  137.                 login();
  138.         }
  139.  
  140.         $type = count($post) ? 'POST' : 'GET';
  141.  
  142.         $req = array(
  143.                 $type . ' ' . $url . ' HTTP/1.1',
  144.                 'Host: www.coldfusioncoderz.com',
  145.                 'Keep-Alive: 300',
  146.                 'Connection: keep-alive',
  147.         );
  148.  
  149.         if (isset($GLOBALS['prefs']['site_cookie'])) {
  150.                 $req[] = 'Cookie: ' . $GLOBALS['prefs']['site_cookie'];
  151.         }
  152.  
  153.         if (count($post)) {
  154.                 $post_data = '';
  155.  
  156.                 foreach ($post as $k => $v) {
  157.                         $post_data .= urlencode($k) . '=' . urlencode($v) . '&';
  158.                 }
  159.  
  160.                 $post_data = substr($post_data, 0, -1);
  161.  
  162.                 $req[] = 'Content-Type: application/x-www-form-urlencoded';
  163.                 $req[] = 'Content-length: ' . strlen($post_data);
  164.                 $req[] = "\r\n" . $post_data;
  165.         }
  166.  
  167.         $req = implode("\r\n", $req) . "\r\n\r\n";
  168.  
  169.         fwrite($GLOBALS['sfd'], $req);
  170.  
  171.         $resp = '';
  172.         $chunked = false;
  173.         $length = 0;
  174.  
  175.         while (1) {
  176.                 $tmp = fgets($GLOBALS['sfd']);
  177.                 $resp .= $tmp;
  178.  
  179.                 if (!$length && !$chunked) {
  180.                         $lower = strtolower($tmp);
  181.  
  182.                         if (strpos($lower, 'content-length') !== false) {
  183.                                 $length = intval(substr($lower, 15));
  184.                         } else if (strpos($lower, 'transfer-encoding: chunked')) {
  185.                                 $chunked = true;
  186.                         }
  187.                 }
  188.  
  189.                 if (!trim($tmp)) {
  190.                         break;
  191.                 }
  192.         }
  193.  
  194.         $read = 0;
  195.         $to_read = 65000;
  196.  
  197.         while (1) {
  198.                 if ($length) {
  199.                         while ($read < $length) {
  200.                                 $t = $length - $read;
  201.  
  202.                                 if ($t < $to_read) {
  203.                                         $to_read = $t;
  204.                                 }
  205.  
  206.                                 $s = fread($GLOBALS['sfd'], $to_read);
  207.                                 $read += strlen($s);
  208.                                 $resp .= $s;
  209.                         }
  210.  
  211.                         $length = 0;
  212.                 } else if ($chunked) {
  213.                         $length = hexdec(trim(fgets($GLOBALS['sfd'])));
  214.                         $read = 0;
  215.                         $to_read = 65000;
  216.                 } else {
  217.                         sleep(1);
  218.                         fwrite($GLOBALS['sfd'], "\r\n");
  219.                         return $resp;
  220.                 }
  221.         }
  222.  
  223. }
  224. function login()
  225. {
  226.  
  227.         $post = array(
  228.             'username' => 'cold_fusion_rockz',
  229.             'password'        => $GLOBALS['prefs']['site_pass'],
  230.         );
  231.  
  232.         $login = http('/login.php', $post, true);
  233.  
  234.         if (!strpos($login, 'PHPSESSID=')) {
  235.                 echo("no cookie got on login!\n");
  236.                 exit(1);
  237.         }
  238.  
  239.         $tmp = explode('Set-Cookie: PHPSESSID=', $login);
  240.         $tmp2 = explode(';', $tmp[1]);
  241.  
  242.         $cookie = "PHPSESSID=" . $tmp2[0];
  243.  
  244.         $del = "DELETE FROM prefs WHERE (name = 'site_cookie')";
  245.         mysql_query($del, $GLOBALS['hdl']);
  246.         $ins = "INSERT INTO prefs (name, value) VALUES ('site_cookie', '" . mysql_escape_string($cookie) . "')";
  247.         mysql_query($ins, $GLOBALS['hdl']);
  248.  
  249.         $GLOBALS['prefs']['site_cookie'] = $cookie;
  250.  
  251. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement