Advertisement
Guest User

malicious_script

a guest
Jul 27th, 2017
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.53 KB | None | 0 0
  1. <?php
  2. global $wp;
  3. global $bp;
  4.  
  5. function makeEmpAvatar($url, $user_id)
  6. {
  7.  
  8.     $site_url           = site_url();
  9.     $upload_dir         = wp_upload_dir();
  10.     $jobavatars_dirname = $upload_dir['basedir'] . "/wp-jobhunt-users";
  11.     wp_mkdir_p($jobavatars_dirname);
  12.  
  13.     $ar_filename  = explode("/", $url);
  14.     $tmp_filename = array_pop($ar_filename);
  15.     $filename_dir = $ar_filename[count($ar_filename) - 1];
  16.  
  17.     $hshd_name = stp_filename_hash($tmp_filename, $filename_dir);
  18.  
  19.     $source = $url;
  20.     $ch     = curl_init();
  21.     curl_setopt($ch, CURLOPT_URL, $source);
  22.     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  23.     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  24.     $data  = curl_exec($ch);
  25.     $error = curl_error($ch);
  26.     curl_close($ch);
  27.     echo $error;
  28.  
  29.     $destination = $jobavatars_dirname . '/' . $hshd_name;
  30.     $file        = fopen($destination, "w+");
  31.     fputs($file, $data);
  32.     fclose($file);
  33.  
  34.     $file_url = $upload_dir['baseurl'] . "/wp-jobhunt-users/" . $hshd_name;
  35.  
  36.     /*INSERTING INTO MEDIALIBRARY*/
  37.  
  38.     // $filename should be the path to a file in the upload directory.
  39.     $filename = $destination;
  40.  
  41.     // Check the type of file. We'll use this as the 'post_mime_type'.
  42.     $filetype = wp_check_filetype(basename($filename), null);
  43.  
  44.     // Get the path to the upload directory.
  45.     $wp_upload_dir = wp_upload_dir();
  46.  
  47.     // Prepare an array of post data for the attachment.
  48.     $attachment = array(
  49.         'guid'           => $file_url,
  50.         'post_mime_type' => $filetype['type'],
  51.         'post_title'     => preg_replace('/\.[^.]+$/', '', basename($filename)),
  52.         'post_content'   => '',
  53.         //'post_author'    => $user_id,
  54.         'post_status'    => 'inherit',
  55.     );
  56.  
  57.     // Insert the attachment.
  58.     $attach_id = wp_insert_attachment($attachment, $filename, 0);
  59.  
  60.     // Make sure that this file is included, as wp_generate_attachment_metadata() depends on it.
  61.     require_once ABSPATH . 'wp-admin/includes/image.php';
  62.  
  63.     // Generate the metadata for the attachment, and update the database record.
  64.     $attach_data = wp_generate_attachment_metadata($attach_id, $filename);
  65.     wp_update_attachment_metadata($attach_id, $attach_data);
  66.     /*END INSERTING INTO MEDIALIBRARY*/
  67.  
  68.     $info            = pathinfo($hshd_name);
  69.     $avatar_filename = basename($hshd_name, '.' . $info['extension']);
  70.  
  71.     $ava_thumb = $avatar_filename . "-270x203." . $info['extension'];
  72.  
  73.     update_user_meta($user_id, 'user_img', $ava_thumb);
  74.  
  75.     return $ava_thumb;
  76. }
  77.  
  78. function get_remote_employers()
  79. {
  80.     $url = "https://api.utmn.ru/prof/companies/";
  81.     $ch  = curl_init();
  82.     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  83.     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  84.     curl_setopt($ch, CURLOPT_URL, $url);
  85.     $result = curl_exec($ch);
  86.  
  87.     curl_close($ch);
  88.     $res = json_decode($result);
  89.  
  90.     //create_success_category();
  91.  
  92.     $cntr = 0;
  93.     foreach ($res as $key => $user) {
  94.  
  95.         $random_password = wp_generate_password(12, false);
  96.         //$login           = substr(trnslt($user->name), 0, 1) . "." . trnslt($user->last_name);
  97.         $tmp_login   = trnslt($user->work_company);
  98.         $ar_tmp_login = explode(" ", $tmp_login);
  99.         if (count($ar_tmp_login)>1) {
  100.             $login = $user->work_email;
  101.         }else{
  102.             $login = $tmp_login;
  103.         }
  104.         $user_id = wp_create_user($login, $random_password, $user->work_email);
  105.  
  106.         $args = array(
  107.             'ID'           => $user_id,
  108.             //'display_name' => $user->name." ".$user->last_name,
  109.             'display_name' => $user->work_company,
  110.             'first_name'   => $user->name,
  111.             'last_name'    => $user->last_name,
  112.             'role'         => 'cs_employer',
  113.         );
  114.         wp_update_user($args);
  115.  
  116.         update_user_meta($user_id, 'cs_user_last_activity_date', time());
  117.         update_user_meta($user_id, 'cs_user_status', 'active');
  118.         update_user_meta($user_id, 'cs_phone_number', $user->work_phone);
  119.         update_user_meta($user_id, 'cs_work_company', $user->work_company);
  120.         update_user_meta($user_id, 'site_url', $user->work_www);
  121.         update_user_meta($user_id, 'description', $user->work_profile);
  122.         update_user_meta($user_id, 'position', $user->work_position);
  123.         update_user_meta($user_id, 'remote_id', $user->id);
  124.  
  125.         $url = $user->work_logo;
  126.         makeEmpAvatar($url, $user_id);
  127.  
  128.         $cntr++;
  129.         echo "User created. User Id #" . $user_id . "\n";
  130.  
  131.  
  132.     }
  133. }
  134.  
  135. get_remote_employers();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement