Advertisement
Guest User

Untitled

a guest
Jan 26th, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.29 KB | None | 0 0
  1. <?php
  2.  
  3. namespace Console\Commands;
  4.  
  5. use Carbon\Carbon;
  6. use Dapphp\TorUtils\ControlClient;
  7. use Dapphp\TorUtils\TorCurlWrapper;
  8. use Illuminate\Console\Command;
  9. use Illuminate\Support\Facades\DB;
  10.  
  11. class TorUrls extends Command
  12. {
  13. protected $name = 'command:tor_urls';
  14. private $offers = [];
  15.  
  16.  
  17. public function handle()
  18. {
  19. $this->offers = $this->getIntlOffers();
  20.  
  21. foreach($this->offers as $o) {
  22. $tracking_url = $o->tracking_url;
  23. $target_system = $o->target_system;
  24. $camp_id = $o->id;
  25. $country = $o->country;
  26.  
  27. $testURL = $this->resolveIntlURL($tracking_url, $target_system, $country);
  28. $end_url = sql_quote($testURL);
  29. }
  30.  
  31. $this->testIntlOffers();
  32.  
  33. }
  34.  
  35. public function testIntlOffers()
  36. {
  37. $urlData = [];
  38. //resolve tracking_url. Use to update test_url and compare with ending_url which was inital resolved URL
  39. foreach ($testQuery as $t) {
  40. $url = $t->tracking_url;
  41. $camp_id = $t->camp_id;
  42. $target_system = $t->target_system;
  43. $ending_url = $t->ending_url;
  44. $country = $t->country;
  45.  
  46. $testURL = $this->resolveIntlURL($url, $target_system, $country);
  47. }
  48. }
  49.  
  50. public function getIntlOffers()
  51. {
  52. echo "getting all Intl offers";
  53. return DB::table('campaigns AS c')
  54. ->select('c.url',)
  55. ->where('o.country', '<>', 'US')
  56. ->get();
  57. }
  58.  
  59. public static function resolveIntlURL($tracking, $target, $country)
  60. {
  61. echo " ------------";
  62. echo "I am about to connect to Control Client";
  63. $tc = new ControlClient();
  64.  
  65. $tc->connect();
  66. $tc->authenticate('');
  67.  
  68. $country = '{' . $country . '}';
  69. $tc->setConf(['ExitNodes' => $country]); //set Tor config to use exit node from whichever country
  70.  
  71. //curl wrapped through Tor SOCK5 proxy
  72. $curl = new TorCurlWrapper();
  73. $windows_os = [10, 11, 12, 13, 18, 19];
  74. if (in_array($target, $windows_os)) { //Windows
  75. $curl->setopt(CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:40.0) Gecko/20100101 Firefox/40.1');
  76. } else if ($target == 20) { //Mac
  77. $curl->setopt(CURLOPT_USERAGENT, 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.85 Safari/537.36');
  78. } else if ($target == 30 || $target == 40) { //Android or any mobile
  79. $curl->setopt(CURLOPT_USERAGENT, 'Mozilla/5.0 (Linux; Android 4.0.4; Galaxy Nexus Build/IMM76B) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.133 Mobile Safari/535.19');
  80. } else if ($target == 50 || $target == 51) { //iPhone
  81. $curl->setopt(CURLOPT_USERAGENT, 'Mozilla/5.0 (iPhone; CPU iPhone OS 5_0 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A334 Safari/7534.48.3');
  82. } else if ($target == 52) { //ipad
  83. $curl->setopt(CURLOPT_USERAGENT, 'Mozilla/5.0 (iPad; CPU OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A5355d Safari/8536.25');
  84. } else {
  85. $curl->setopt(CURLOPT_USERAGENT, 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.85 Safari/537.36');
  86. }
  87.  
  88. if($curl->httpGet($tracking)) {
  89. $resolvedURL = $curl->getInfo()['url'];
  90. }
  91. else {
  92. $resolvedURL = "broken";
  93. }
  94. return $resolvedURL;
  95. }
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement