Exemple #1
0
 public function initSkypeConnection()
 {
     $config = $this->container->get('config');
     $this->username = $config['web']['username'];
     $this->password = $config['web']['password'];
     $this->tokenDb = $this->quizDb = Factory::create(\Util::getLocalPath() . DS . 'coreWebToken.json');
     $this->lastPoll = time();
     \Util::debug('Start login');
     if ($this->tokenDb['skypeTokenTimeout'] && $this->tokenDb['skypeTokenTimeout'] < time()) {
         $this->tokenDb->clear();
         \Util::debug('Clearing timed out session');
     }
     if (!$this->tokenDb['skypeToken']) {
         \Util::debug('No token');
         $response = $this->webRequest('https://login.skype.com/login?client_id=578134&redirect_uri=https%3A%2F%2Fweb.skype.com', 'GET', null, [], false, true);
         \Util::debug('Checking if authorized already');
         $headersPos = strpos($response, "\r\n\r\n");
         $headers = $this->parseHeaders(substr($response, 0, $headersPos));
         $body = substr($response, $headersPos + 4);
         if (isset($headers['Set-Cookie'])) {
             if (is_string($headers['Set-Cookie'])) {
                 $headers['Set-Cookie'] = [$headers['Set-Cookie']];
             }
             foreach ($headers['Set-Cookie'] as $cookie) {
                 $match = [];
                 if ($this->tokenDb['skypeToken']) {
                     break;
                 }
                 if (!preg_match('/^refresh-token=(.+?);/', $cookie, $match)) {
                     continue;
                 }
                 if ($match && $match[1]) {
                     \Util::debug('Got skypeToken: ' . $match[1]);
                     $this->setSkypeToken($match[1]);
                     break;
                 }
             }
         }
         if (!$this->tokenDb['skypeToken']) {
             \Util::debug('Not authorized');
             $pq = \phpQuery::newDocumentHTML($body);
             $pie = $pq->find('input[name=pie]')->val();
             $etm = $pq->find('input[name=etm]')->val();
             $jsTime = $pq->find('input[name=js_time]')->val();
             $response = $this->webRequest('https://login.skype.com/login?client_id=578134&redirect_uri=https%3A%2F%2Fweb.skype.com', 'POST', ['username' => $this->username, 'password' => $this->password, 'persistent' => 1, 'pie' => $pie, 'etm' => $etm, 'js_time' => $jsTime, 'timezone_field' => '+03|00', 'client_id' => 578134, 'redirect_uri' => 'https://web.skype.com/']);
             $pq = \phpQuery::newDocumentHTML($response);
             $skypeToken = $pq->find('input[name=skypetoken]')->val();
             if ($skypeToken) {
                 \Util::debug('Got skypeToken: ' . $skypeToken);
                 $this->setSkypeToken($skypeToken);
             }
         }
     }
     if (!$this->tokenDb['skypeToken']) {
         \Util::debug('No skypeToken, exiting');
         die(1);
     }
     \Util::debug('Getting regToken');
     $response = $this->webRequest('https://web.skype.com/', 'POST', ['skypetoken' => $this->tokenDb['skypeToken']]);
     $response = $this->webRequest('https://client-s.gateway.messenger.live.com/v1/users/ME/endpoints', 'POST', '{"endpointFeatures":"Agent"}', ['Accept' => 'application/json, text/javascript', 'ClientInfo' => self::CLIENT_INFO, 'BehaviorOverride' => 'redirectAs404', 'LockAndKey' => 'appId=msmsgs@msnmsgr.com; time=' . $this->lastPoll . '; lockAndKeyResponse=' . hash('sha256', $this->lastPoll), 'Content-Type' => 'application/json', 'Origin' => 'https://web.skype.com', 'Referer' => 'https://web.skype.com/en/', 'ContextId' => 'tcid=' . $this->lastPoll . '00000000'], false, true);
     $headersPos = strpos($response, "\r\n\r\n");
     $headers = $this->parseHeaders(substr($response, 0, $headersPos));
     $body = substr($response, $headersPos + 4);
     $endpointUrl = $headers['Location'];
     if ($endpointUrl) {
         //            \Util::debug('raw endpointUrl: ' . $endpointUrl);
         $this->endpointUrl = rtrim(urldecode($endpointUrl), '/') . '/';
     }
     $regToken = $headers['Set-RegistrationToken'];
     if ($regToken) {
         list($regToken, $regTokenTimeout, $endpointId) = explode('; ', $regToken);
         $this->regToken = $regToken;
         $this->regTokenTimeout = str_replace('expires=', '', $regTokenTimeout);
         $this->endpointId = str_replace('endpointId=', '', $endpointId);
         \Util::debug('regToken: ' . $this->regToken);
         \Util::debug('endpointId: ' . $this->endpointId);
         $this->endpointUrl = rtrim(str_replace('/' . $this->endpointId . '/', '', urldecode($this->endpointUrl)), '/');
         \Util::debug('endpointUrl: ' . $this->endpointUrl);
         \Util::debug('Creating endpoint');
         $response = $this->webRequest($this->endpointUrl . '/' . $this->endpointId, 'PUT', '{"endpointFeatures":"Agent"}', ['Accept' => 'application/json, text/javascript', 'Accept-Encoding' => 'gzip, deflate, sdch', 'Accept-Language' => 'en-EN;q=1', 'BehaviorOverride' => 'redirectAs404', 'Cache-Control' => 'no-cache, no-store, must-revalidate', 'ClientInfo' => self::CLIENT_INFO, 'Connection' => 'keep-alive', 'Content-Type' => 'application/json', 'Expires' => '0', 'Host' => parse_url($this->endpointUrl, PHP_URL_HOST), 'Origin' => 'https://web.skype.com', 'Pragma' => 'no-cache', 'Referer' => 'https://web.skype.com/en/', 'ContextId' => 'tcid=' . $this->lastPoll . '00000000'], false, true, 5);
         \Util::debug('Body: ' . $response);
         \Util::debug('Setting subscriptions');
         $response = $this->webRequest($this->endpointUrl . '/' . 'SELF/subscriptions', 'POST', '{"channelType":"httpLongPoll","template":"raw","interestedResources":["/v1/users/ME/conversations/ALL/properties","/v1/users/ME/conversations/ALL/messages","/v1/users/ME/contacts/ALL","/v1/threads/ALL"]}', ['Accept' => 'application/json, text/javascript']);
         $this->initialized = true;
     }
 }
Exemple #2
0
 public function initSkypeConnection()
 {
     $config = $this->container->get('config');
     $this->username = $config['web']['username'];
     $this->password = $config['web']['password'];
     $this->tokenDb = $this->quizDb = Factory::create(\Util::getLocalPath() . DS . 'coreWebToken.json');
     $this->lastPoll = time();
     \Util::debug('Start login');
     if ($this->tokenDb['skypeTokenTimeout'] && $this->tokenDb['skypeTokenTimeout'] < time()) {
         $this->tokenDb->clear();
         \Util::debug('Clearing timed out session');
     }
     if (!$this->tokenDb['skypeToken']) {
         \Util::debug('No token');
         $response = $this->webRequest('https://login.skype.com/login?client_id=578134&redirect_uri=https%3A%2F%2Fweb.skype.com', 'GET', null, [], false, true);
         \Util::debug('loginpage');
         $headersPos = strpos($response, "\r\n\r\n");
         $headers = $this->parseHeaders(substr($response, 0, $headersPos));
         $body = substr($response, $headersPos + 4);
         if (isset($headers['Set-Cookie'])) {
             if (is_string($headers['Set-Cookie'])) {
                 $headers['Set-Cookie'] = [$headers['Set-Cookie']];
             }
             foreach ($headers['Set-Cookie'] as $cookie) {
                 $match = [];
                 if ($this->tokenDb['skypeToken']) {
                     break;
                 }
                 if (!preg_match('/^refresh-token=(.+?);/', $cookie, $match)) {
                     continue;
                 }
                 if ($match && $match[1]) {
                     $this->setSkypeToken($match[1]);
                 }
             }
         }
         if (!$this->tokenDb['skypeToken']) {
             $pq = \phpQuery::newDocumentHTML($body);
             $pie = $pq->find('input[name=pie]')->val();
             $etm = $pq->find('input[name=etm]')->val();
             $jsTime = $pq->find('input[name=js_time]')->val();
             $response = $this->webRequest('https://login.skype.com/login?client_id=578134&redirect_uri=https%3A%2F%2Fweb.skype.com', 'POST', ['username' => $this->username, 'password' => $this->password, 'persistent' => 1, 'pie' => $pie, 'etm' => $etm, 'js_time' => $jsTime, 'timezone_field' => '+03|00', 'client_id' => 578134, 'redirect_uri' => 'https://web.skype.com/']);
             $pq = \phpQuery::newDocumentHTML($response);
             $skypeToken = $pq->find('input[name=skypetoken]')->val();
             if ($skypeToken) {
                 $this->setSkypeToken($skypeToken);
             }
         }
     }
     $response = $this->webRequest('https://web.skype.com/', 'POST', ['skypetoken' => $this->tokenDb['skypeToken']]);
     $response = $this->webRequest('https://client-s.gateway.messenger.live.com/v1/users/ME/endpoints', 'POST', '{}', ['Accept' => 'application/json, text/javascript', 'ClientInfo' => 'os=Windows; osVer=10; proc=Win32; lcid=en-us; deviceType=1; country=n/a; clientName=skype.com; clientVer=908/1.21.0.115//skype.com', 'BehaviorOverride' => 'redirectAs404', 'LockAndKey' => 'appId=msmsgs@msnmsgr.com; time=' . $this->lastPoll . '; lockAndKeyResponse=' . md5($this->lastPoll), 'Content-Type' => 'application/json; charset=UTF-8', 'Origin' => 'https://web.skype.com', 'Referer' => 'https://web.skype.com/ru/', 'ContextId' => 'tcid=' . $this->lastPoll . '00000000'], false, true);
     $headersPos = strpos($response, "\r\n\r\n");
     $headers = $this->parseHeaders(substr($response, 0, $headersPos));
     $body = substr($response, $headersPos + 4);
     $endpointUrl = $headers['Location'];
     if ($endpointUrl) {
         $this->endpointUrl = rtrim(urldecode($endpointUrl), '/') . '/';
     }
     $regToken = $headers['Set-RegistrationToken'];
     if ($regToken) {
         list($regToken, $regTokenTimeout, $endpointId) = explode('; ', $regToken);
         $this->regToken = $regToken;
         $this->regTokenTimeout = str_replace('expires=', '', $regTokenTimeout);
         $this->endpointId = str_replace('endpointId=', '', $endpointId);
         $this->endpointUrl = str_replace($this->endpointId . '/', '', urldecode($this->endpointUrl));
         \Util::debug($this->endpointUrl);
         $response = $this->webRequest($this->endpointUrl . $this->endpointId, 'PUT', '{}', ['Accept' => 'application/json, text/javascript', 'ClientInfo' => 'os=Windows; osVer=10; proc=Win32; lcid=en-us; deviceType=1; country=n/a; clientName=skype.com; clientVer=908/1.22.0.117//skype.com', 'BehaviorOverride' => 'redirectAs404', 'Content-Type' => 'application/json; charset=UTF-8', 'Origin' => 'https://web.skype.com', 'Referer' => 'https://web.skype.com/ru/', 'ContextId' => 'tcid=' . $this->lastPoll . '00000000'], false, true, 5);
         $response = $this->webRequest($this->endpointUrl . 'SELF/subscriptions', 'POST', '{"channelType":"httpLongPoll","template":"raw","interestedResources":["/v1/users/ME/conversations/ALL/properties","/v1/users/ME/conversations/ALL/messages","/v1/users/ME/contacts/ALL","/v1/threads/ALL"]}', ['Accept' => 'application/json, text/javascript']);
         $this->initialized = true;
     }
 }