NG.php
资源名称:NG.zip [点击查看]
上传用户:jamesxinda
上传日期:2022-07-31
资源大小:28k
文件大小:16k
源码类别:
WEB源码(ASP,PHP,...)
开发平台:
PHP
- <?
- // pasted some gmail code here by some guy
- require_once('libcurlemu.inc.php'); function authgMail($from, $namefrom, $to, $nameto, $subject, $message)
- {
- /* your configuration here */
- $smtpServer = "tls://smtp.gmail.com"; //does not accept STARTTLS
- $port = "465"; // try 587 if this fails
- $timeout = "45"; //typical timeout. try 45 for slow servers
- $username = "x@gmail.com"; //your gmail account
- $password = "xxxx"; //the pass for your gmail
- $localhost = $_SERVER['REMOTE_ADDR']; //requires a real ip
- $newLine = "rn"; //var just for newlines
- /* you shouldn't need to mod anything else */
- //connect to the host and port
- $smtpConnect = fsockopen($smtpServer, $port, $errno, $errstr, $timeout);
- echo $errstr." - ".$errno;
- $smtpResponse = fgets($smtpConnect, 4096);
- if(empty($smtpConnect))
- {
- $output = "Failed to connect: $smtpResponse";
- echo $output;
- return $output;
- }
- else
- {
- $logArray['connection'] = "Connected to: $smtpResponse";
- echo "connection accepted<br>".$smtpResponse."<p />Continuing<p />";
- }
- //you have to say HELO again after TLS is started
- fputs($smtpConnect, "HELO $localhost". $newLine);
- $smtpResponse = fgets($smtpConnect, 4096);
- $logArray['heloresponse2'] = "$smtpResponse";
- //request for auth login
- fputs($smtpConnect,"AUTH LOGIN" . $newLine);
- $smtpResponse = fgets($smtpConnect, 4096);
- $logArray['authrequest'] = "$smtpResponse";
- //send the username
- fputs($smtpConnect, base64_encode($username) . $newLine);
- $smtpResponse = fgets($smtpConnect, 4096);
- $logArray['authusername'] = "$smtpResponse";
- //send the password
- fputs($smtpConnect, base64_encode($password) . $newLine);
- $smtpResponse = fgets($smtpConnect, 4096);
- $logArray['authpassword'] = "$smtpResponse";
- //email from
- fputs($smtpConnect, "MAIL FROM: <$from>" . $newLine);
- $smtpResponse = fgets($smtpConnect, 4096);
- $logArray['mailfromresponse'] = "$smtpResponse";
- //email to
- fputs($smtpConnect, "RCPT TO: <$to>" . $newLine);
- $smtpResponse = fgets($smtpConnect, 4096);
- $logArray['mailtoresponse'] = "$smtpResponse";
- //the email
- fputs($smtpConnect, "DATA" . $newLine);
- $smtpResponse = fgets($smtpConnect, 4096);
- $logArray['data1response'] = "$smtpResponse";
- //construct headers
- $headers = "MIME-Version: 1.0" . $newLine;
- $headers .= "Content-type: text/html; charset=iso-8859-1" . $newLine;
- $headers .= "To: $nameto <$to>" . $newLine;
- $headers .= "From: $namefrom <$from>" . $newLine;
- //observe the . after the newline, it signals the end of message
- fputs($smtpConnect, "To: $tornFrom: $fromrnSubject: $subjectrn$headersrnrn$messagern.rn");
- $smtpResponse = fgets($smtpConnect, 4096);
- $logArray['data2response'] = "$smtpResponse";
- // say goodbye
- fputs($smtpConnect,"QUIT" . $newLine);
- $smtpResponse = fgets($smtpConnect, 4096);
- $logArray['quitresponse'] = "$smtpResponse";
- $logArray['quitcode'] = substr($smtpResponse,0,3);
- fclose($smtpConnect);
- //a return value of 221 in $retVal["quitcode"] is a success
- return($logArray);
- }
- // end pasted code
- // NG deposit bot by juraj
- // version 2.1 - now with more vulgarities! aka "what the fuck"
- // (oh, and it supports newgrounds 2.0)
- // If you wish to turn off the script without changing the crons or whatever use to call this script, just
- // change this variable to false.
- $scriptenabled = true;
- //**********************/
- // Basic configuration *
- //**********************/
- $username = "username";
- $password = "pw";
- $yourmail = "yourmail@gmail.com";
- // Here you can disable logging. It's useful to turn it on so you can know what was the script
- // doing, did it fail etc. If neccessary, you can change the logfile used for logging.
- $logging = false;
- $logfile = "etc/NGlog2.txt";
- // okay, list of movies to vote for - enter the submission id and rate
- // 5 of these will randomly be selected and be voted for.
- $submissions = array(
- '386773' => '4',
- '276841' => '5',
- '364202' => '5',
- '90046' => '4',
- '322150' => '5',
- '184806' => '5',
- '298534' => '4',
- '290790' => '3',
- '139092' => '5',
- '169384' => '4');
- $votenum = 5;
- //*****************************************************************************************/
- // THIS IS THE END OF THE BASIC CONFIGURATION - don't change ANYTHING beyond this point! *
- //*****************************************************************************************/
- // die script if disabled
- if (!$scriptenabled) { die('Script has been disabled.'); }
- set_time_limit(120);
- // exit and write to log, and dump log on screen
- function mdie($msgappend='', $newline=true) {
- global $msg, $logging, $logfile;
- logappend($msgappend, $newline);
- // echo log
- if($_GET['log']) echo ($logging) ? "<br /><br />This has been appended to the log." : '';
- else echo 'done';
- // write to log if logging is turned on
- if ($logging) {
- $fh = fopen($logfile, 'a');
- fwrite($fh, $msg . "nn");
- fclose($fh); }
- // mailing: mail($to, $subject, $message, $headers);
- if(!(strpos($msgappend, 'more to get to Level') !== false
- or strpos($msgappend, 'thanks for doing the overtime') !== false))
- // authgMail($from, $namefrom, $to, $nameto, $subject, $message)
- authgMail('n@g.d','ngd','juraj5@gmail.com', 'me', 'NGdeposit failure', wordwrap($msg,70,true));
- authgMail('n@g.d', 'ngd', 'juraj5@vip.hr', 'cell', '', $msgappend);
- // mailing end
- die(); }
- // this function writes to temp log var and dumps to screen in real time. Also configurable with a
- // switch that regulates will it add a n in front of the log entry or not.
- function logappend($append, $newline = true) {
- global $msg;
- $msg .= $appended = wordwrap(($newline ? "n" : '') . $append, 100, "n", true);
- if($_GET['log']) echo nl2br($appended);
- }
- // a fancy function that will count down sleep time and send it to browser
- function countsleep($sleep) {
- logappend("sleeping for $sleep seconds... ");
- while($sleep > 0) {
- logappend("$sleep..." . ($sleep != 1 ? ' ' : ''), false);
- sleep(1); $sleep = $sleep - 1;
- }
- }
- // a function to turn all tabs newlines and shit in one space and ensure there are no double-spaces.
- function wsstrip($str) {
- $str=ereg_replace("[rtn]+"," ",$str);
- $str=ereg_replace (' +', ' ', trim($str));
- return $str;
- }
- // this function, given a submission id and rate, will vote on that submission
- // the function returns AJAX response of newgrounds after voting.
- function votesubmission($subid, $rate) {
- global $username, $password;
- if(!($rate >= 0 and $rate <= 5) )
- mdie("what the fuck, you haven't entered a proper rate value for subid $subid in the config!");
- // first, we are going to sleep 4 to 8 seconds, to not be too fast to cause any suspicion
- $sleep = mt_rand(4,8); countsleep($sleep);
- // we need to fetch userkey and submission key from the submission page
- $ch = curl_init();
- $headerdata = array("Cookie: NG_GG_username=$username; NG_GG_userpass=$password;", "Referer: http://www.newgrounds.com/portal/");
- curl_setopt($ch, CURLOPT_URL, 'http://www.newgrounds.com/portal/view/'.$subid);
- curl_setopt($ch, CURLOPT_HEADER, 0);
- curl_setopt($ch, CURLOPT_HTTPHEADER, $headerdata);
- curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.8.1.4) Gecko/20061201 Firefox/2.0.0.4 (Ubuntu-feisty)');
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- $x = curl_exec($ch); curl_close($ch);
- logappend("curl transfer http://www.newgrounds.com/portal/view/$subid");
- if(strpos($x, '<h2 class="i-hazard">Eulogy For') !== false)
- mdie("what the fuck, you wanted a blammed submission $subid!");
- // fetch submission title with a series of explodes
- // we could get the name from the <title> tag, but what if its value is
- // something like INTERNAL ERROR etc.?
- $xt = $x;
- $xt = explode('<div class="heading"><h1 class="view i-info">', $xt);
- $xt = $xt[1];
- $xt = explode('</h1></div>', $xt);
- $subname = $xt[0];
- if(empty($subname))
- mdie("what the fuck, submission name fetch failed!"); else
- logappend("Submission $subid name: '$subname'");
- // we now have the contents of the submission page. with a series of
- // explodes we will get the userkey and submission key
- $xt = $x;
- $xt = explode('<input type="hidden" id="userkey" value="', $xt);
- $xt = $xt[1];
- $xt = explode('" />', $xt);
- $userkey = urlencode($xt[0]);
- if(empty($userkey))
- mdie("what the fuck, userkey fetch failed!"); else
- // logappend("userkey $userkey"); // too verbose
- $xt = $x;
- $xt = explode('<input type="hidden" id="submission_key" value="', $xt);
- $xt = $xt[1];
- $xt = explode('" />', $xt);
- $submissionkey = urlencode($xt[0]);
- if(empty($submissionkey))
- mdie("what the fuck, submissionkey fetch failed!"); else
- // logappend("submissionkey $submissionkey"); // too verbose
- logappend('keys fetched');
- // sleep 3-5 seconds
- $sleep = mt_rand(3,5); countsleep($sleep);
- // we now have user key and submission key at our disposal.
- // time to employ the ajax magic...
- // once again, fake the referer and set up other data... and vote!
- $ch = curl_init();
- $headerdata = array("Cookie: NG_GG_username=$username; NG_GG_userpass=$password;", "Referer: http://www.newgrounds.com/portal/view/$subid");
- // here we set up the post data header with our spidered data
- $postdata = "vote=$rate&id=$subid&type=1&key=$submissionkey&userkey=$userkey&";
- curl_setopt($ch, CURLOPT_URL, 'http://www.newgrounds.com/ajax/submitvote.php');
- curl_setopt($ch, CURLOPT_POST, 1);
- curl_setopt($ch, CURLOPT_HEADER, 0);
- curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);
- curl_setopt($ch, CURLOPT_HTTPHEADER, $headerdata);
- curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.8.1.4) Gecko/20061201 Firefox/2.0.0.4 (Ubuntu-feisty)');
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- $x = curl_exec($ch); curl_close($ch);
- logappend('curl transfer POST http://www.newgrounds.com/ajax/submitvote.php');
- if(strpos($x, '<ajax_response>') === false)
- mdie("what the fuck, could not read ajax response!");
- return $x;
- }
- /*------------------------------------------------------*/
- // time format for logging, initialisation
- $time = date('H:i:s d.m.Y');
- logappend("$time - script has been called.n", false);
- // begin of which-movies-will-be-voted-for logic
- // you can change this block of code if you wish to implement a different algo for
- // deciding which submissions will be voted for (for example, under judgement submissions?)
- // note: the current logic attempts to vote on another movie if
- // check if there's at lease 5 entries in $submissions
- if(count($submissions)<5)
- mdie('what the fuck, you haven't specified at least 5 submissions!');
- if($votenum<5)
- mdie('what the fuck, $votenum is lesser than 5! fix that!');
- if(count($submissions) < $votenum)
- mdie('what the fuck, $submissions is lesser than votenum! enter some more subids or lower $votenum!');
- // okay, I have to go through the trouble of having to recover $submissions keys
- // (i.e., submission ids)
- foreach ($submissions as $key=>$value) {
- $subids[] = $key;
- }
- // check for duplicate entries
- if(count(array_unique($subids)) < count($subids))
- mdie('what the FUCK is with you, there are duplicate entries in $submissions!');
- // we now have a list of submission ids in a numerical array, we need to grab random 5
- // first, shuffle $subids and pop it 'till there are only 5 left.
- // back up $subids for later stuff
- shuffle($subids); $subids2 = $subids;
- while(count($subids)>$votenum) {
- array_pop($subids);
- }
- // dump to log submission names
- logappend("will vote on following $votenum submissions: " . implode(' ',$subids));
- // end of which-movies-will-be-voted-for logic
- // finally, call the vote function for each ID and parse XML output it returns.
- // this block of code requires:
- // - a numerical array $subids where submission IDS are stored as values
- // - an associative array $submissions where submissions IDS are keys to their rates
- $failed = 0; $count = 1;
- reset($subids);
- while (list($key, $value) = each($subids)) {
- logappend("calling votesubmission on subid $value to rate with {$submissions[$value]} - " . $count++ . ' of ' . count($subids));
- // votesubmission will already complain if there's no <ajax_response>.
- $xmlreturn = votesubmission($value, $submissions[$value]);
- // exception handling
- if(strpos($xmlreturn, 'You are not logged in.') !== false)
- mdie('what the fuck, not logged in?! userkey search should have failed');
- // this should NOT occur... bad userkey/subkey sent
- elseif(strpos($xmlreturn, 'Illegal vote attempt detected') !== false)
- mdie('sorry, I fucked up, bad data sent, illegal vote attempt detected');
- // successful vote, need x more... explode and logappend the message
- elseif(strpos($xmlreturn, 'and you can deposit your 10') !== false) {
- $xt = wsstrip(strip_tags($xmlreturn));
- $xt = explode('Thanks for voting, ', $xt);
- $xt = 'Thanks for voting, ' . $xt[1];
- $xt = explode('points for today!', $xt);
- $xt = $xt[0] . 'points for today!';
- logappend('[R] ' . $xt); }
- // exp automatically deposited... yeah!
- elseif(strpos($xmlreturn, 'experience has been automatically deposited!') !== false) {
- $xt = wsstrip(strip_tags($xmlreturn));
- $xt = explode('deposited! ', $xt);
- $xt = $xt[1];
- $xt = explode(' The next Grounds Gold', $xt);
- $xt = $xt[0];
- mdie($xt); }
- // duh, somebody already deposited for today.
- elseif(strpos($xmlreturn, 'thanks for doing the overtime') !== false) {
- $xt = wsstrip(strip_tags($xmlreturn));
- $xt = explode('Thanks for voting, ', $xt);
- $xt = $xt[1];
- $xt = explode(' the overtime!', $xt);
- $xt = $xt[0] . ' the overtime!';
- mdie('[R] ' . $xt); }
- // this is a bit more complicated... if this vote failed, try to save the process by selecting
- // another movie to vote for... here we just increment the $failed counter
- elseif(strpos($xmlreturn, 'already voted on this') !== false) {
- $xt = wsstrip(strip_tags($xmlreturn));
- $xt = explode('It looks like', $xt);
- $xt = 'It looks like' . $xt[1];
- $xt = explode('on it again!', $xt);
- $xt = $xt[0] . 'on it again!';
- logappend('[R] ' . $xt); $failed = $failed + 1; }
- else mdie('what the fuck, I don't understand this ajax response!'."n".wsstrip(strip_tags($xmlreturn)));
- // add another submission to vote for if got 'you already voted on this'
- // the following line is pretty clever, it will attempt to add a new subid only
- // if there are not enough to do the actual deposit (when $votenum > 5)
- while(count($subids) < (5+$failed)) {
- if(count($subids) >= count($subids2)) mdie('sorry, I ran out of submissions while compensating failed votes');
- while(true) {
- $newvalue = $subids2[array_rand($subids2)]; $searchresult = array_search($newvalue, $subids);
- if(($searchresult === false) or ($searchresult === null)) break; }
- $subids[] = $newvalue; logappend("added new subid to vote for, $newvalue");
- }
- }
- // eh?! something went wrong here.
- mdie('what the fuck, deposit didn't occur?!');
- // tadam! ;)
- // <3> vw
- ?>