Advertisement
Guest User

Untitled

a guest
Dec 10th, 2016
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.83 KB | None | 0 0
  1. <?php
  2.  
  3. require ("cijfercheck_pass.php");
  4. include ("postmessage.php");
  5. include 'vendor/autoload.php';
  6.  
  7. $ch = curl_init();
  8. curl_setopt($ch, CURLOPT_URL, 'https://rapid.deltion.nl/user/login/');
  9. curl_setopt($ch, CURLOPT_POSTFIELDS,'username='.urlencode($login_email).'&password='.urlencode($login_pass).'&login=Login');
  10. curl_setopt($ch, CURLOPT_POST, 1);
  11. curl_setopt($ch, CURLOPT_HEADER, 0);
  12. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  13. curl_setopt($ch, CURLOPT_COOKIEJAR, "/tmp/my_cookies.txt");
  14. curl_setopt($ch, CURLOPT_COOKIEFILE, "/tmp/my_cookies.txt");
  15. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  16. curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.3) Gecko/20070309 Firefox/2.0.0.3");
  17. curl_setopt($ch, CURLOPT_REFERER, "https://rapid.deltion.nl/student/info/");
  18. $page = curl_exec($ch);
  19.  
  20. curl_setopt($ch, CURLOPT_URL,'https://rapid.deltion.nl/student/pdfresultaten/id/97041344/Luuk%20Wuijster.pdf');
  21. curl_setopt($ch, CURLOPT_POSTFIELDS,'btnresultatenpdf='.urlencode('pdf resultaten'));
  22. curl_setopt($ch, CURLOPT_POST, 1);
  23. curl_setopt($ch, CURLOPT_COOKIEFILE, "/tmp/my_cookies.txt");
  24. $result = curl_exec($ch);
  25. curl_close($ch);
  26.  
  27. $destination = dirname(__FILE__) . '/pdf/temp.pdf';
  28. $file = fopen($destination, "w+");
  29. fputs($file, $result);
  30. fclose($file);
  31.  
  32. function logdata($body){
  33.     $time = date("d-m-Y H:i:s");
  34.     $file = 'cijfercheck.log';
  35.     $current = file_get_contents($file);
  36.     $current .= "[${time}] ${body} \n";
  37.     file_put_contents($file, $current);
  38. }
  39.  
  40. if (file_exists('pdf/temp.pdf')) {
  41.     logdata("temp.pdf gedownload van rapid.deltion.nl");
  42. } else {
  43.     logdata("ERROR: kon temp.pdf niet downloaden van rapid.deltion.nl");
  44.     die();
  45. }
  46.  
  47. $parser = new \Smalot\PdfParser\Parser();
  48. $pdf1 = $parser->parseFile('pdf/cijferlijst.pdf');
  49. $pdf2 = $parser->parseFile('pdf/temp.pdf');
  50.  
  51. $string1 = $pdf1->getText();
  52. $string2 = $pdf2->getText();
  53.  
  54. $nospace1 = str_replace(' ', '', $string1);
  55. $nospace2 = str_replace(' ', '', $string2);
  56.  
  57. $arr1 = explode(':', $nospace1);
  58. $arr2 = explode(':', $nospace2);
  59.  
  60. $check = $arr1[5];
  61. $temp = $arr2[5];
  62.  
  63. if (!empty($temp) OR !empty($check)) {
  64.     logdata("pdf omgezet naar een array");
  65. } else {
  66.     logdata("ERROR: was niet mogelijk om pdf om te zetten naar array");
  67.     die();
  68. }
  69.  
  70. if($check == $temp){
  71.  
  72.     if(unlink('pdf/temp.pdf')){
  73.         logdata("temp.pdf is verwijderd");
  74.     } else {
  75.         logdata("ERROR: kon temp.pdf niet verwijderen");
  76.         die();
  77.     }
  78.  
  79. } else {
  80.     if(unlink('pdf/cijferlijst.pdf') && rename('pdf/temp.pdf', 'pdf/cijferlijst.pdf')){
  81.         logdata("cijferlijst.pdf is verwijderd en temp.pdf is hernoemt naar cijferlijst.pdf");
  82.         PostToSlack();
  83.     } else {
  84.         logdata("ERROR: kon cijferlijst.pdf niet verwijderen en/of kon temp.pdf niet hernoemen naar cijferlijst.pdf");
  85.     }
  86.  
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement