135 018 YouTube!

Asterisk Instagram

Because I can :)

: , Asterisk Instagram? : , Asterisk PHP AGI , , , , API ?

, ( ) ? . , :) , just for fun .

, IP Asterisk. :)

AGI PHP

3 :

  1. instagram.php - , AGI CallerID, , Instagram;
  2. generate_pic.php - php , , ;
  3. pic.jpg - , ;

, pic.jpg :

   Asterisk  Instagram
! ! , 600x600.

, . \:

#!/usr/bin/php -q
<?php
error_reporting(0);
require('phpagi.php'); 
$agi = new AGI(); 
$cid = $agi->request['agi_callerid']; \  AGI       $cid;
copy(dirname( __FILE__ )."/pic.jpg", dirname( __FILE__ )."/picc.jpg"); \      ,    picc.jpg.     ;
$input = "http://192.168.1.2/insta/generate_pic.php?num=$cid&pic=../../home/admin/instagram/pic.jpg"; \   generate_pic.php,      num  ,    pic = ,  ,    .       .     /home/admin/instagram/pic.jpg      - ;
$output = dirname( __FILE__ )."/picc.jpg";
file_put_contents($output, file_get_contents($input)); \      picc.jpg,   ;
$image = dirname( __FILE__ )."/picc.jpg"; 
$date = date("Y-m-d H:i:s"); \    - . AGI      ,   ;
$text = "   $date   $cid"; \      Instagram;
function SendRequest($url, $post, $post_data, $user_agent, $cookies) {
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, 'https://instagram.com/api/v1/'.$url);
    curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
 
    if($post) {
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
    }
 
    if($cookies) {
        curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookies.txt');
    } else {
        curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookies.txt');
    }
 
    $response = curl_exec($ch);
    $http = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    curl_close($ch);
 
    return array($http, $response);
}
 
function GenerateGuid() {
    return sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
        mt_rand(0, 65535),
        mt_rand(0, 65535),
        mt_rand(0, 65535),
        mt_rand(16384, 20479),
        mt_rand(32768, 49151),
        mt_rand(0, 65535),
        mt_rand(0, 65535),
        mt_rand(0, 65535));
}
 
function GenerateUserAgent() {
    $resolutions = array('720x1280', '320x480', '480x800', '1024x768', '1280x720', '768x1024', '480x320');
    $versions = array('GT-N7000', 'SM-N9000', 'GT-I9220', 'GT-I9100');
    $dpis = array('120', '160', '320', '240');
 
    $ver = $versions[array_rand($versions)];
    $dpi = $dpis[array_rand($dpis)];
    $res = $resolutions[array_rand($resolutions)];
 
    return 'Instagram 4.'.mt_rand(1,2).'.'.mt_rand(0,2).' Android ('.mt_rand(10,11).'/'.mt_rand(1,3).'.'.mt_rand(3,5).'.'.mt_rand(0,5).'; '.$dpi.'; '.$res.'; samsung; '.$ver.'; '.$ver.'; smdkc210; en_US)';
}
 
function GenerateSignature($data) {
    return hash_hmac('sha256', $data, 'b4a23f5e39b5929e0666ac5de94c89d1618a2916');
}
 
function GetPostData($filename) {
    if(!$filename) {
        echo "The image doesn't exist ".$filename;
    } else {
        $post_data = array('device_timestamp' => time(),
            'photo' => '@'.$filename);
        return $post_data;
    }
}
 
 
function sendInstagramm($filename, $caption) //  ,    (   ,   )    ;
{
    $username = '___'; //         Instagram;
    $password = '___'; //         Instagram;
 
    $agent = GenerateUserAgent();
    $guid = GenerateGuid();
    $device_id = "android-" . $guid;
    $data = '{"device_id":"' . $device_id . '","guid":"' . $guid . '","username":"' . $username . '","password":"' . $password . '","Content-Type":"application/x-www-form-urlencoded; charset=UTF-8"}';
    $sig = GenerateSignature($data);
    $data = 'signed_body=' . $sig . '.' . urlencode($data) . '&ig_sig_key_version=4';
    $login = SendRequest('accounts/login/', true, $data, $agent, false);
    $text = '';
 
    if (strpos($login[1], "Sorry, an error occurred while processing this request.")) {
        $text .= "Request failed, there's a chance that this proxy/ip is blocked";
        return $text;
    }
 
    if (empty($login[1])) {
        $text .= "Empty response received from the server while trying to login";
        return $text;
    }
    $obj = @json_decode($login[1], true);
 
    if (empty($obj)) {
        $text .= "Could not decode the response" ;
        return $text;
    }
    $data = GetPostData($filename);
    $post = SendRequest('media/upload/', true, $data, $agent, true);
 
    if (empty($post[1])) {
        $text .= "Empty response received from the server while trying to post the image";
        return $text;
    }
    $obj = @json_decode($post[1], true);
 
    if (empty($obj)) {
        $text .= "Could not decode the response";
        return $text;
    }
    $status = $obj['status'];
 
    if ($status != 'ok') {
        $text .= "Status isn't okay";
        return $text;
    }
 
    $media_id = $obj['media_id'];
    $device_id = "android-" . $guid;
 
    $data = (object)array(
        'device_id' => $device_id,
        'guid' => $guid,
        'media_id' => $media_id,
        'caption' => trim($caption),
        'device_timestamp' => time(),
        'source_type' => '5',
        'filter_type' => '0',
        'extra' => '{}',
        'Content-Type' => 'application/x-www-form-urlencoded; charset=UTF-8',
    );
    $data = json_encode($data);
    $sig = GenerateSignature($data);
    $new_data = 'signed_body=' . $sig . '.' . urlencode($data) . '&ig_sig_key_version=4';
 
    $conf = SendRequest('media/configure/', true, $new_data, $agent, true);
	print_r ($conf);
 
    if (empty($conf[1])) {
        $text .= "Empty response received from the server while trying to configure the image";
    } else {
        if (strpos($conf[1], "login_required")) {
            $text .= "You are not logged in. There's a chance that the account is banned";
        } else {
            $obj = @json_decode($conf[1], true);
            $status = $obj['status'];
            if ($status != 'fail') {
                $text .= "Success";
            } else {
                $text .= 'Fail';
            }
        }
    }
    return $text;
}
sendInstagramm($image, $text); \   ;
unlink(dirname( __FILE__ )."/picc.jpg"); \       picc.jpg -      :);
?>
AGI
, .txt .php

. Instagram.php /var/lib/asterisk/agi-bin. WinSCP, . , SSH Asterisk :

dos2unix /var/lib/asterisk/agi-bin/instagram.php
chown asterisk:asterisk /var/lib/asterisk/agi-bin/instagram.php
chmod 775 /var/lib/asterisk/agi-bin/instagram.php

/home/admin/instagram/pic.jpg, , . .


PHP

. PHP. generate_pic.php ( ):

<?php 
function writeTextOnImage($filename, $text)  \ ,   ,     2 : ,        ;
{   
    $size_img = getimagesize($filename);  
    if ($size_img[2]==2)       $src_img = imagecreatefromjpeg($filename);  
    else if ($size_img[2]==1)  $src_img = imagecreatefromgif($filename);  
    else if ($size_img[2]==3)  $src_img = imagecreatefrompng($filename);    
    $color = imagecolorallocatealpha($src_img, 0, 0, 0, 0);  
    $font_file = "2211.ttf";  //  .ttf     ;
    $img_x = imagesx($src_img); 
    $img_y = imagesy($src_img);     
    $height_font = 28;
    $angle = 0;
    $box = imagettftext($src_img, $height_font, $angle, $img_x - 500, $img_y - 350, $color, $font_file, $text);  \       X  Y     ( $img_x - 500, $img_y - 350);
    if ($size_img[2]==2)  
    {  
        header ("Content-type: image/jpeg");  
        imagejpeg($src_img);  
    }  
    else if ($size_img[2]==1)  
    {  
        header ("Content-type: image/gif");  
        imagegif($src_img);  
    }  
    else if ($size_img[2]==3)  
    {  
        header ("Content-type: image/png");  
        imagepng($src_img);  
    }  
    return true;  
} 
$pic = $_GET['pic']; \    ;
$num = $_GET['num']; \   
$img = "../../$pic"; \    ,     ;
$date = date("Y-m-d H:i:s"); \  ;
writeTextOnImage($img, " : $num\n     :\n  $date\n\n\n\n      wiki.merionet.ru");  \  ;
?>

, Asterisk /var/www/html/insta. generate_pic.php 2211.ttf, :

. .
dos2unix /var/www/html/insta/generate_pic.php
chown asterisk:asterisk /var/www/html/insta/generate_pic.php
chown asterisk:asterisk /var/www/html/insta/2211.ttf
chmod 775 /var/www/html/insta/generate_pic.php
chmod 775 /var/www/html/insta/2211.ttf

instagram.php Asterisk. , :

exten => _.,n,AGI(instagram.php)

, . . . Instagram:

Asterisk    Instagram

, . :

Asterisk     Instagram

?


: