PageRenderTime 29ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/cronplus.php

https://github.com/b123400/Auto-readdaily
PHP | 309 lines | 262 code | 45 blank | 2 comment | 44 complexity | 4c6f8bfc9334a92bcb08f89b5d98f847 MD5 | raw file
  1. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  2. <title>@@</title>
  3. <SCRIPT language=JavaScript1.2>
  4. //change 1 to another integer to alter the scroll speed. Greater is faster
  5. var speed=20
  6. var currentpos=0,alt=1,curpos1=0,curpos2=-1
  7. function initialize(){
  8. startit()
  9. }
  10. function scrollwindow(){
  11. if (document.all &&
  12. !document.getElementById)
  13. temp=document.body.scrollTop
  14. else
  15. temp=window.pageYOffset
  16. if (alt==0)
  17. alt=2
  18. else
  19. alt=1
  20. if (alt==0)
  21. curpos1=temp
  22. else
  23. curpos2=temp
  24. if (document.all)
  25. currentpos=document.body.scrollTop+speed
  26. else
  27. currentpos=window.pageYOffset+speed
  28. window.scroll(0,currentpos)
  29. }
  30. function startit(){
  31. forwardInterval =setInterval("scrollwindow()",50)
  32. }
  33. function stopinterval(){
  34. clearInterval (forwardInterval);
  35. document.title=":)";
  36. }
  37. initialize();
  38. window.onload=stopinterval
  39. </SCRIPT>
  40. <?php
  41. include 'do_function.php';
  42. $username = "YOUR MYSQL USERNAME";
  43. $password = "YOUR MYSQL PASSWORD";
  44. $hostname = "localhost"; //you know what this is:)
  45. $dbname="YOUR DATABASE NAME";
  46. $db_table_name="TABLE NAME";
  47. $user_arr = array();
  48. $pwd_arr = array();
  49. $school_arr = array();
  50. $name_arr = array();
  51. $f_user_arr = array();
  52. $f_pwd_arr = array();
  53. $f_school_arr = array();
  54. $f_name_arr = array();
  55. $dbuser_handle = mysql_connect($hostname, $username, $password)
  56. or die("Unable to connect to MySQL");
  57. $selected = mysql_select_db($dbname,$dbuser_handle)
  58. or die("Could not select examples");
  59. $result=mysql_query("SELECT * FROM ".$db_table_name);
  60. $i=0;
  61. while($row = mysql_fetch_array($result)){
  62. $f_user_arr[$i] = $row['id'];
  63. $f_pwd_arr[$i] = $row['pwd'];
  64. $f_school_arr[$i] = $row['school'];
  65. $f_name_arr[$i] = $row['user'];
  66. $i++;
  67. }
  68. mysql_close($dbuser_handle);
  69. $user_arr = $f_user_arr;
  70. shuffle($user_arr);
  71. $i=0;
  72. while($i<sizeof($f_user_arr)){
  73. $pwd_arr[$i]=$f_pwd_arr[array_search($user_arr[$i], $f_user_arr)];
  74. $school_arr[$i]=$f_school_arr[array_search($user_arr[$i], $f_user_arr)];
  75. $name_arr[$i]=$f_name_arr[array_search($user_arr[$i], $f_user_arr)];
  76. $i++;
  77. }
  78. function search_string($start , $end , $from, $number=1){
  79. if($number<1){
  80. $number=1;
  81. }
  82. $from = trim(str_replace("\r\n","",$from));
  83. $i = 0;
  84. $ans = $from;
  85. if(!stristr($ans , $start)){
  86. return false;
  87. }
  88. while($i<$number){
  89. if(stristr($ans , $start)){
  90. $ans = stristr($ans , $start);
  91. $ans = substr($ans, strlen($start));
  92. }
  93. $i++;
  94. }
  95. if(strpos($ans, $end)){
  96. $pos = strpos($ans, $end);
  97. $ans = substr($ans, 0, $pos);
  98. }
  99. if(isset($ans) && $ans != "" ){
  100. return trim(str_replace("\r\n","",$ans));
  101. }else{
  102. return false;
  103. }
  104. }
  105. function search_from_end($end, $start, $from){
  106. $ans = $from;
  107. if(strpos($ans, $end)){
  108. $pos = strpos($ans, $end);
  109. $ans = substr($ans, 0, $pos);
  110. $ans = strrchr($ans, $start);
  111. }
  112. return $ans;
  113. }
  114. $ch = curl_init();
  115. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  116. curl_setopt($ch, CURLOPT_URL, $url);
  117. curl_setopt($ch, CURLOPT_POST, true);
  118. $af = curl_init();
  119. curl_setopt($af, CURLOPT_RETURNTRANSFER, 1);
  120. $got_answer = false;
  121. $tried_user = 0;
  122. for($i=0 ; $i<sizeof($user_arr) ; $i++){
  123. if(!$got_answer){
  124. $now_user = $user_arr[$i];
  125. $now_pwd = $pwd_arr[$i];
  126. $now_school = $school_arr[$i];
  127. $url="http://prof-ho.appspot.com/login";
  128. $query="orgNo=".$now_school."&loginId=".$now_user."&passwd=".$now_pwd;
  129. curl_setopt($ch, CURLOPT_POSTFIELDS, $query);
  130. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  131. curl_setopt($ch, CURLOPT_URL, $url);
  132. curl_setopt($ch, CURLOPT_POST, true);
  133. echo "user: ".$name_arr[$i]."<BR />";
  134. $result = curl_exec($ch);
  135. $retried=0;
  136. while(!search_string("Status", "OK", $result)&&$retried<3){
  137. echo $name_arr[$i].' timeout..重試, message:'.$result.'<BR />';
  138. curl_setopt($ch, CURLOPT_POSTFIELDS, $query);
  139. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  140. curl_setopt($ch, CURLOPT_URL, $url);
  141. curl_setopt($ch, CURLOPT_POST, true);
  142. $result = curl_exec($ch);
  143. $retried++;
  144. }
  145. if(search_string("<title>","</title>", $result,1) == "failure" ||search_string("<title>","</title>", $result,1) == "A passage A day"){
  146. echo "登入不能";
  147. if(search_string('<font color="#FF0000">',"</font>", $result)){
  148. echo ",".search_string('<font color="#FF0000">',"</font>", $result)."<BR />";
  149. }
  150. }elseif(search_string("<title>","</title>", $result,1) == "每日一篇"){
  151. $hex = search_string("jsessionid=",'"', $result,1);
  152. $url = "http://www.prof-ho.com/rdcn/student/readArticle.do;jsessionid=".$hex."?series=5";
  153. curl_setopt($af, CURLOPT_URL, $url);
  154. curl_setopt($af, CURLOPT_RETURNTRANSFER, 1);
  155. $result = curl_exec($af);
  156. if(search_string('<font color="#FF0000">', "</font>", $result) != "你已經成功讀過這篇文章,不能再提交。" && search_string('<font color="#FF0000">', "</font>", $result) != "你已經讀完當天文章,不能再提交。"){
  157. for($j=0 ; $j<3 ; $j++){
  158. $n = $j+1;
  159. $z=1+$j*4;
  160. $y = 1+$n*4;
  161. $x = 0;
  162. while($z< $y){
  163. $this_q = search_string('<td align="right" background="../images/tbbg.jpg">','</tr>',$result,$z);
  164. echo "<BR />".$this_q;
  165. if(!$got_answer){
  166. if(search_string('<input type="radio" name="answer[',']',$this_q) == 0){
  167. if($tried_user==0){
  168. $question0[$x] = search_string('<td align="left" background="../images/tbbg.jpg">','</td>',$this_q);
  169. $answer0[$x] = search_string(']" value="','"',$this_q);
  170. }else{
  171. $f_question0[$x] = search_string('<td align="left" background="../images/tbbg.jpg">','</td>',$this_q);
  172. $f_answer0[$x] = search_string(']" value="','"',$this_q);
  173. $answer0[array_search($f_question0[$x], $question0)] = $f_answer0[$x];
  174. }
  175. }
  176. if(search_string('<input type="radio" name="answer[',']',$this_q) == 1){
  177. if($tried_user==0){
  178. $question1[$x] = search_string('<td align="left" background="../images/tbbg.jpg">','</td>',$this_q);
  179. $answer1[$x] = search_string(']" value="','"',$this_q);
  180. }else{
  181. $f_question1[$x] = search_string('<td align="left" background="../images/tbbg.jpg">','</td>',$this_q);
  182. $f_answer1[$x] = search_string(']" value="','"',$this_q);
  183. $answer1[array_search($f_question1[$x], $question1)] = $f_answer1[$x];
  184. }
  185. }
  186. if(search_string('<input type="radio" name="answer[',']',$this_q) == 2){
  187. if($tried_user==0){
  188. $question2[$x] = search_string('<td align="left" background="../images/tbbg.jpg">','</td>',$this_q);
  189. echo 'question2['.$x.'] is : '.search_string('<td align="left" background="../images/tbbg.jpg">','</td>',$this_q)."<BR />";
  190. $answer2[$x] = search_string(']" value="','"',$this_q);
  191. echo 'answer2['.$x.'] is : '.search_string(']" value="','"',$this_q)."<BR />";
  192. }else{
  193. $f_question2[$x] = search_string('<td align="left" background="../images/tbbg.jpg">','</td>',$this_q);
  194. $f_answer2[$x] = search_string(']" value="','"',$this_q);
  195. $answer2[array_search($f_question2[$x], $question2)] = $f_answer2[$x];
  196. }
  197. }
  198. }
  199. $x++;
  200. $z++;
  201. }
  202. }
  203. $url="http://www.prof-ho.com/rdcn/student/replyArticle.do;jsessionid=".$hex;
  204. $j =0;
  205. while($j<4){
  206. if(!$got_answer){
  207. $query='series=5&answer[0]='.$answer0[$tried_user].'&answer[1]='.$answer1[$tried_user].'&answer[2]='.$answer2[$j];
  208. echo '<BR />'.$query;
  209. echo '<BR />a....series=5&answer[0]='.$question0[$tried_user].'&answer[1]='.$question1[$tried_user].'&answer[2]='.$question2[$j];
  210. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  211. curl_setopt($ch, CURLOPT_URL, $url);
  212. curl_setopt($ch, CURLOPT_POST, true);
  213. curl_setopt($ch, CURLOPT_POSTFIELDS, $query);
  214. $result = curl_exec($ch);
  215. if(search_string("<title>" , "</title>" , $result) == "prompt"){
  216. echo search_string('<font color="#FF0000">' , '</font>' , $result)."<BR />";
  217. }
  218. if(search_string("<title>" , "</title>" , $result) == "failure"){
  219. echo search_string('<font color="#FF0000">' , '</font>' , $result)."<BR />";
  220. }
  221. if(search_string('<p align="center">' , '</p>' , $result) == "請為這篇文章的作者打分"){
  222. echo "哇,搞掂左!<BR />";
  223. if(!$got_answer){
  224. $good_0 = $question0[$tried_user];
  225. $good_1 = $question1[$tried_user];
  226. $good_2 = $question2[$j];
  227. $good_user = $now_user;
  228. }
  229. $got_answer = true;
  230. }
  231. }
  232. $j++;
  233. }
  234. $tried_user++;
  235. }else{
  236. echo $name_arr[$i]." did it... <BR />";
  237. }
  238. }else{
  239. echo "好像有點問題...<BR />除錯用訊息:".$result;
  240. }
  241. }
  242. }
  243. if($got_answer){
  244. echo "哇,搞掂左!<BR />";
  245. echo "現在去幫其他同學做...這一頁可能會load耐d,請耐心等等!唔好關閉!<BR />";
  246. $dbuser_handle = mysql_connect($hostname, $username, $password)
  247. or die("Unable to connect to MySQL");
  248. $selected = mysql_select_db($dbname,$dbuser_handle)
  249. or die("Could not select examples");
  250. $result=mysql_query("SELECT * FROM ".$db_table_name." WHERE activated=1");
  251. while($row = mysql_fetch_array($result)){
  252. if($row['id']!=$good_user){
  253. echo "現在開始幫".$row['user']."做...<BR />";
  254. echo "結果是:".doBatchSubmit($row['school'],$row['id'],$row['pwd'],$good_0,$good_1,$good_2)."<BR />";
  255. }else{
  256. echo "跳過".$row['user'].">已經做了<BR />";
  257. }
  258. //}
  259. }
  260. mysql_close($dbuser_handle);
  261. }
  262. curl_close($af);
  263. curl_close($ch);
  264. ?>