PluginProbe
WpStream – Live Streaming, Video on Demand, Pay Per View / 3.1.8
WpStream – Live Streaming, Video on Demand, Pay Per View v3.1.8
4.14.1 4.14.0 4.13.2 4.13.1 4.13 4.12.5 4.12.4 4.12.3 4.12.2 4.12.1 4.12 4.4.4 4.4.5 4.4.6 4.4.7 4.4.8 4.4.9 4.5 4.5.1 4.5.11 4.5.11.1 4.5.11.2 4.5.11.4 4.5.11.5 4.5.11.6 All 181 releases
wpstream / includes / class-wpstream-live-api-connection.php

class-wpstream-live-api-connection.php in WpStream – Live Streaming, Video on Demand, Pay Per View 3.1.8, at includes/class-wpstream-live-api-connection.php

803 lines 24.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 class Wpstream_Live_Api_Connection {
4
5
6
7
8 public function __construct() {
9 add_action( 'wp_ajax_wpstream_give_me_live_uri', array($this,'wpstream_give_me_live_uri') );
10 add_action( 'wp_ajax_wpstream_check_dns_sync', array($this,'wpstream_check_dns_sync') );
11 add_action( 'wp_ajax_wpstream_check_server_against_db', array($this,'wpstream_check_server_against_db') );
12 add_action( 'wp_ajax_wpstream_close_event', array($this,'wpstream_close_event') );
13 add_action( 'wp_ajax_wpstream_get_download_link', array($this,'wpstream_get_download_link') );
14 add_action( 'wp_ajax_wpstream_get_delete_file', array($this,'wpstream_get_delete_file') );
15 }
16
17 /**
18 * Check live stream in db
19 *
20 * @since 3.0.1
21 * returns live url
22 */
23 public function wpstream_check_server_against_db(){
24 $show_id = intval($_POST['show_id']);
25 $is_live = false;
26
27 $live_event_for_user = $this->wpstream_get_live_event_for_user();
28 if(isset($live_event_for_user[$show_id])) {
29 $is_live=true;
30 }
31
32 echo json_encode( array('islive' =>$is_live) );
33 exit();
34 }
35
36
37 /**
38 * Check server dns status
39 *
40 * @since 3.0.1
41 * returns live url
42 */
43 public function wpstream_check_dns_sync(){
44 $token = $this->wpstream_get_token();
45 $values_array=array(
46 "dns_change_id" => esc_html($_POST['change_id']),
47 );
48
49 $url=WPSTREAM_CLUBLINKSSL."://www.".WPSTREAM_CLUBLINK."/wp-json/rcapi/v1/checkdns/get/?access_token=".$token;
50 $arguments = array(
51 'method' => 'GET',
52 'timeout' => 45,
53 'redirection' => 5,
54 'httpversion' => '1.0',
55 'blocking' => true,
56 'headers' => array(),
57 'body' => $values_array,
58 'cookies' => array()
59 );
60
61 $response = wp_remote_post($url,$arguments);
62 $received_data = json_decode( wp_remote_retrieve_body($response) ,true);
63
64 if( isset($response['response']['code']) && $response['response']['code']=='200'){
65 print ($received_data);
66 }else{
67 // print 'failed connection';
68 }
69 die();
70 }
71
72
73
74
75
76
77
78 /**
79 * Request live url
80 *
81 * @since 3.0.1
82 * returns live url
83 */
84 public function wpstream_give_me_live_uri(){
85
86 check_ajax_referer( 'wpstream_start_event_nonce', 'security' );
87 $current_user = wp_get_current_user();
88 $allowded_html = array();
89 $userID = $current_user->ID;
90 $return_uri = '';
91
92
93 if(function_exists('wpstream_get_option') && intval(wpstream_get_option('allow_streaming_regular_users',''))==1 ){
94 if( !is_user_logged_in() ){
95 exit('okko xab1');
96 }
97 }else{
98 if( !current_user_can('administrator') ){
99 exit('okko xa1');
100 }
101 }
102
103
104
105 $show_id = intval ( $_POST['show_id'] );
106 $is_record = floatval( $_POST['is_record'] );
107
108
109
110 //prepare 3rd options
111 $is_fb = floatval( $_POST['is_fb'] );
112 $is_youtube = floatval( $_POST['is_youtube'] );
113 $is_twich = floatval( $_POST['is_twich'] );
114
115 if($is_youtube==1){
116 update_post_meta($show_id,'wpstream_youtube_rtmp',esc_html($_POST['youtube_rtmp']) );
117 }else{
118 update_post_meta($show_id,'wpstream_youtube_rtmp','' );
119 }
120
121 if($is_twich==1){
122 update_post_meta($show_id,'wpstream_twich_rtmp',esc_html($_POST['twich_rtmp']) );
123 }else{
124 update_post_meta($show_id,'wpstream_twich_rtmp','' );
125 }
126
127
128
129 ////////////////////////////////////
130
131 $event_data = $this->wpstream_request_live_stream_uri($show_id,$is_record,$userID);
132
133 if(is_array($event_data)){
134 $explode = explode('wpstream.net/', $event_data['live_uri']);
135 $uri = $explode[0].'wpstream.net/wpstream/';
136 $server_status_check =
137 $stream_key = trim(str_replace('wpstream/',' ',$explode[1]));
138
139
140 update_post_meta($show_id,'live_event_uri', $event_data['live_uri']);
141 update_post_meta($show_id,'live_event_stream_name', $event_data['carnat1']);
142 update_post_meta($show_id,'ip', $event_data['ip']);
143 update_post_meta($show_id,'live_event_carnat2', $event_data['carnat2']);
144
145
146 if( isset($event_data['dns_change_id']) && $event_data['dns_change_id']!='' ){
147
148 echo json_encode( array(
149 'sometihng' => 'mr',
150 'conected' => true,
151 'caster_url' => $event_data['webcaster_url'],
152 'live_uri' => $event_data['live_uri'] ,
153 'all_data' => $event_data,
154 'obs_uri' => $event_data['live_uri2'],
155 'obs_stream' => $stream_key,
156 'server_status_check' => 'http://'.$event_data['ip'].':8444' ,
157 'ip' => $event_data['ip'],
158 'subdomain_key' => $event_data['subdomain_key'],
159 'dns_change_id' => $event_data['dns_change_id']
160 )
161 );
162
163 }else{
164 echo json_encode( array(
165 'conected' => false,
166 'error' => 'Error 4176'// no aws server dns propagation
167 ));
168 }
169
170 }else{
171 echo json_encode( array(
172 'conected' => false,
173 'error' => $event_data
174 ));
175 }
176 die();
177 }
178
179
180
181
182
183 private function wpstream_request_live_stream_uri($show_id,$is_record,$request_by_userid){
184 $token = $this->wpstream_get_token();
185 $domain = parse_url ( get_site_url() );
186
187 $values_array=array(
188 "show_id" => $show_id,
189 "scheme" => $domain['scheme'],
190 "domain" => $domain['host'],
191 "domain_ip" => $_SERVER['SERVER_ADDR'],
192 "is_record" => $is_record,
193 "location" => get_home_url() ,
194 "request_by_userid" => $request_by_userid,
195 );
196
197 $url=WPSTREAM_CLUBLINKSSL."://www.".WPSTREAM_CLUBLINK."/wp-json/rcapi/v1/livestrem/new/?access_token=".$token;
198
199 $arguments = array(
200 'method' => 'GET',
201 'timeout' => 45,
202 'redirection' => 5,
203 'httpversion' => '1.0',
204 'blocking' => true,
205 'headers' => array(),
206 'body' => $values_array,
207 'cookies' => array()
208 );
209 $response = wp_remote_post($url,$arguments);
210 $received_data = json_decode( wp_remote_retrieve_body($response) ,true);
211
212
213 if( isset($response['response']['code']) && $response['response']['code']=='200'){
214 return ($received_data);
215 }else{
216 if($received_data['data']['status']=='401'){
217 return('You are not connected to wpstream.net! Please check your WpStream credentials! ');
218
219 }else{
220 return 'Failed to connect to WpStream. Please try again later.';
221 }
222
223 }
224
225 }
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249 /**
250 * Retrive auth token from tranzient
251 *
252 * @since 3.0.1
253 * returns token
254 */
255 public function wpstream_get_token(){
256 $token = get_transient('wpstream_token_request');
257 if ( false === $token || $token==='' ) {
258 $token = $this->wpstream_club_get_token();
259 set_transient( 'wpstream_token_request', $token ,600);
260 }
261
262 return $token;
263
264 }
265
266
267
268 /**
269 * Request auth token from wpstream.net
270 *
271 * @since 3.0.1
272 * returns token fron wpstream
273 */
274 protected function wpstream_club_get_token(){
275
276 $client_id = esc_html ( get_option('wpstream_api_key','') );
277 $client_secret = esc_html ( get_option('wpstream_api_secret_key','') );
278 $username = esc_html ( get_option('wpstream_api_username','') );
279 $password = esc_html ( get_option('wpstream_api_password','') );
280
281 if ( $username=='' || $password==''){
282 return;
283 }
284 $curl = curl_init();
285
286 curl_setopt_array($curl, array(
287 CURLOPT_URL => WPSTREAM_CLUBLINKSSL."://www.".WPSTREAM_CLUBLINK."/?oauth=token",
288 CURLOPT_RETURNTRANSFER => true,
289 CURLOPT_ENCODING => "",
290 CURLOPT_MAXREDIRS => 10,
291 CURLOPT_TIMEOUT => 30,
292 CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
293 CURLOPT_CUSTOMREQUEST => "POST",
294 CURLOPT_POSTFIELDS => "grant_type=password&username=".$username."&password=".$password."&client_id=qxZ6fCoOMj4cNK8SXRHa5nug6vnswlFWSF37hsW3&client_secret=L1fzLosJf9TlwnCCTZ5pkKmdqqkHShKEi0d4oFNE",
295 CURLOPT_HTTPHEADER => array(
296
297 "cache-control: no-cache",
298 "content-type: application/x-www-form-urlencoded",
299
300 ),
301 ));
302
303 $response = curl_exec($curl);
304 $err = curl_error($curl);
305
306
307
308 curl_close($curl);
309 $response= json_decode($response);
310
311 if(isset($response->access_token)){
312 return $response->access_token;
313 }else{
314 return;
315 }
316 }
317
318
319
320
321 /**
322 * Return admin package data
323 *
324 * @since 3.0.1
325 * returns pack data
326 */
327
328 public function wpstream_request_pack_data_per_user(){
329
330 if( !current_user_can('administrator') ){
331 exit('okko 1');
332 }
333 $token = $this->wpstream_get_token();
334 $values_array = array();
335 $url = WPSTREAM_CLUBLINKSSL."://www.".WPSTREAM_CLUBLINK."/wp-json/rcapi/v1/status/packdetails/?access_token=".$token;
336
337
338 $arguments = array(
339 'method' => 'GET',
340 'timeout' => 45,
341 'redirection' => 5,
342 'httpversion' => '1.0',
343 'blocking' => true,
344 'headers' => array(),
345 'body' => $values_array,
346 'cookies' => array()
347 );
348 $response = wp_remote_post($url,$arguments);
349 $received_data = json_decode( wp_remote_retrieve_body($response) ,true);
350
351
352
353 if( isset($response['response']['code']) && $response['response']['code']=='200'){
354 return ($received_data);
355 }else{
356 return 'failed connection';
357 }
358
359 }
360
361
362 /**
363 * Check Api Status
364 *
365 * @since 3.0.1
366 * returns true or false
367 */
368
369 function wpstream_client_check_api_status(){
370
371 $token= $this->wpstream_get_token();
372
373 $url=WPSTREAM_CLUBLINKSSL."://www.".WPSTREAM_CLUBLINK."/wp-json/rcapi/v1/status/?access_token=".$token;
374 $arguments = array(
375 'method' => 'GET',
376 'timeout' => 45,
377 'redirection' => 5,
378 'httpversion' => '1.0',
379 'blocking' => true,
380 'headers' => array(),
381 'cookies' => array()
382 );
383 $response = wp_remote_post($url,$arguments);
384 $body = wp_remote_retrieve_body($response);
385
386 if ( $body === true || $body ==='true'){
387 return true;
388 }else{
389 return false;
390 }
391 }
392
393 /**
394 * Start Get live events for users
395 *
396 * @since 3.0.1
397 * returns true or false
398 */
399 public function wpstream_get_live_event_for_user(){
400 $current_user = wp_get_current_user();
401 $allowded_html = array();
402 $userID = $current_user->ID;
403 $return_uri = '';
404
405 if(function_exists('wpstream_get_option') && intval(wpstream_get_option('allow_streaming_regular_users',''))==1 ){
406 if( !is_user_logged_in() ){
407 exit('okko mnb1');
408 }
409 }else{
410 if( !current_user_can('administrator') ){
411 exit('okko mn1');
412 }
413 }
414
415
416 $event_data = $this->wpstream_request_live_stream_for_user($userID);
417 return $event_data;
418 }
419
420
421
422
423
424
425
426
427
428 /**
429 * Start Get live events for users
430 *
431 * @since 3.0.1
432 * returns true or false
433 */
434 public function wpstream_request_live_stream_for_user($user_id){
435
436 if(function_exists('wpstream_get_option') && intval(wpstream_get_option('allow_streaming_regular_users',''))==1 ){
437 if( !is_user_logged_in() ){
438 exit('okko grt1z');
439 }
440 }else{
441 if( !current_user_can('administrator') ){
442 exit('okko grt1');
443 }
444 }
445
446
447 $domain = parse_url ( get_site_url() );
448 $token= $this->wpstream_get_token();
449
450 $values_array=array(
451 "show_id" => $user_id,
452 "scheme" => $domain['scheme'],
453 "domain" => $domain['host'],
454 "domain_ip" => $_SERVER['SERVER_ADDR']
455 );
456
457
458
459 $url=WPSTREAM_CLUBLINKSSL."://www.".WPSTREAM_CLUBLINK."/wp-json/rcapi/v1/livestrem/peruser/?access_token=".$token;
460
461
462 $arguments = array(
463 'method' => 'GET',
464 'timeout' => 45,
465 'redirection' => 5,
466 'httpversion' => '1.0',
467 'blocking' => true,
468 'headers' => array(),
469 'body' => $values_array,
470 'cookies' => array()
471 );
472 $response = wp_remote_post($url,$arguments);
473 $received_data = json_decode( wp_remote_retrieve_body($response) ,true);
474
475 if(is_wp_error($response)){
476 return 'failed connection';
477 }
478 if( isset($response['response']['code']) && $response['response']['code']=='200'){
479 return ($received_data);
480 }else{
481 return 'failed connection';
482 }
483
484 }
485
486
487
488
489 /**
490 * Delete event
491 *
492 * @since 3.0.1
493 * returns noda
494 */
495
496 public function wpstream_close_event(){
497 check_ajax_referer( 'wpstream_start_event_nonce', 'security' );
498 $current_user = wp_get_current_user();
499 $allowded_html = array();
500 $userID = $current_user->ID;
501 $return_uri = '';
502 if( !current_user_can('administrator') ){
503 exit('okko');
504 }
505
506 $show_id = intval($_POST['show_id']);
507 update_post_meta ($show_id,'event_passed',1);
508 die();
509 }
510
511
512 /**
513 * Get signed upload form data
514 *
515 * @since 3.0.1
516 * returns aws form
517 */
518 public function wpstream_get_signed_form_upload_data(){
519 if( !current_user_can('administrator') ){
520 exit('okko');
521 }
522
523 $token = $this->wpstream_get_token();
524 $values_array = array();
525 $url = WPSTREAM_CLUBLINKSSL."://www.".WPSTREAM_CLUBLINK."/wp-json/rcapi/v1/videos/get_upload_form/?access_token=".$token;
526
527
528 $arguments = array(
529 'method' => 'GET',
530 'timeout' => 45,
531 'redirection' => 5,
532 'httpversion' => '1.0',
533 'blocking' => true,
534 'headers' => array(),
535 'body' => $values_array,
536 'cookies' => array()
537 );
538 $response = wp_remote_post($url,$arguments);
539 $received_data = json_decode( wp_remote_retrieve_body($response) ,true);
540
541
542
543 if( isset($response['response']['code']) && $response['response']['code']=='200'){
544 return $received_data;
545 }else{
546 return 'failed connection';
547 }
548 }
549
550 /**
551 * Get video from storage- clear data for front end use
552 *
553 * @since 3.0.1
554 * returns aws data
555 */
556 public function wpstream_get_videos(){
557 if( !current_user_can('administrator') ){
558 exit('okko');
559 }
560 $token = $this->wpstream_get_token();
561 $values_array = array();
562 $url = WPSTREAM_CLUBLINKSSL."://www.".WPSTREAM_CLUBLINK."/wp-json/rcapi/v1/videos/get_list_row/?access_token=".$token;
563
564
565 $arguments = array(
566 'method' => 'GET',
567 'timeout' => 45,
568 'redirection' => 5,
569 'httpversion' => '1.0',
570 'blocking' => true,
571 'headers' => array(),
572 'body' => $values_array,
573 'cookies' => array()
574 );
575 $response = wp_remote_post($url,$arguments);
576 $received_data = json_decode( wp_remote_retrieve_body($response) ,true);
577
578
579
580 if( isset($response['response']['code']) && $response['response']['code']=='200'){
581 $video_options=array();
582 foreach ($received_data as $key=>$videos){
583 $video_options[$videos['video_name_storage']]=$videos['video_name_storage'].'';
584 }
585
586 return $video_options;
587 }else{
588 return 'failed connection';
589 }
590
591
592
593
594 }
595
596
597
598 /**
599 * Get video from storage- raw data
600 *
601 * @since 3.0.1
602 * returns aws data
603 */
604 public function wpstream_get_videos_from_storage_raw_data( ){
605
606 if( !current_user_can('administrator') ){
607 exit('okko');
608 }
609 $token = $this->wpstream_get_token();
610 $values_array = array();
611 $url = WPSTREAM_CLUBLINKSSL."://www.".WPSTREAM_CLUBLINK."/wp-json/rcapi/v1/videos/get_list_row/?access_token=".$token;
612
613
614 $arguments = array(
615 'method' => 'GET',
616 'timeout' => 45,
617 'redirection' => 5,
618 'httpversion' => '1.0',
619 'blocking' => true,
620 'headers' => array(),
621 'body' => $values_array,
622 'cookies' => array()
623 );
624 $response = wp_remote_post($url,$arguments);
625
626
627 $received_data = json_decode( wp_remote_retrieve_body($response) ,true);
628
629
630
631 if( isset($response['response']['code']) && $response['response']['code']=='200'){
632 return $received_data;
633 }else{
634 return 'failed connection';
635 }
636
637 }
638
639
640
641 /**
642 * Get download link from aws
643 *
644 * @since 3.0.1
645 * returns aws data
646 */
647
648 function wpstream_get_download_link(){
649 if( !current_user_can('administrator') ){
650 exit('okko get_download_link');
651 }
652
653 $video_name = sanitize_text_field($_POST['video_name']);
654 $token = $this->wpstream_get_token();
655 $values_array = array();
656 $values_array['video_name'] = $video_name;
657 $url = WPSTREAM_CLUBLINKSSL."://www.".WPSTREAM_CLUBLINK."/wp-json/rcapi/v1/videos/get_download_link/?access_token=".$token;
658
659
660 $arguments = array(
661 'method' => 'GET',
662 'timeout' => 45,
663 'redirection' => 5,
664 'httpversion' => '1.0',
665 'blocking' => true,
666 'headers' => array(),
667 'body' => $values_array,
668 'cookies' => array()
669 );
670 $response = wp_remote_post($url,$arguments);
671 $received_data = json_decode( wp_remote_retrieve_body($response) ,true);
672
673 if( isset($response['response']['code']) && $response['response']['code']=='200'){
674 print trim($received_data);
675 }else{
676 return 'failed connection';
677 }
678 exit();
679 }
680
681
682 /**
683 * Delete file from storage
684 *
685 * @since 3.0.1
686 *
687 */
688 public function wpstream_get_delete_file(){
689 if( !current_user_can('administrator') ){
690 exit('okko get_delete_file');
691 }
692
693 $video_name = esc_html($_POST['video_name']);
694 $token = $this->wpstream_get_token();
695 $values_array = array();
696 $values_array['video_name'] = $video_name;
697 $url = WPSTREAM_CLUBLINKSSL."://www.".WPSTREAM_CLUBLINK."/wp-json/rcapi/v1/videos/get_delete_file/?access_token=".$token;
698
699
700 $arguments = array(
701 'method' => 'GET',
702 'timeout' => 45,
703 'redirection' => 5,
704 'httpversion' => '1.0',
705 'blocking' => true,
706 'headers' => array(),
707 'body' => $values_array,
708 'cookies' => array()
709 );
710 $response = wp_remote_post($url,$arguments);
711 $received_data = json_decode( wp_remote_retrieve_body($response) ,true);
712
713
714 if( isset($response['response']['code']) && $response['response']['code']=='200'){
715 print $received_data;
716 }else{
717 return 'failed connection';
718 }
719 exit();
720
721
722 }
723
724 /**
725 * check if stream is live
726 *
727 * @since 3.0.1
728 *
729 */
730 public function wpstream_is_is_live($product_id){
731
732 $token = $this->wpstream_get_token();
733
734 $values_array=array(
735 "show_id" => $product_id,
736 );
737 $url=WPSTREAM_CLUBLINKSSL."://www.".WPSTREAM_CLUBLINK."/wp-json/rcapi/v1/livestrem/checklive/?access_token=".$token;
738
739
740 $arguments = array(
741 'method' => 'GET',
742 'timeout' => 45,
743 'redirection' => 5,
744 'httpversion' => '1.0',
745 'blocking' => true,
746 'headers' => array(),
747 'body' => $values_array,
748 'cookies' => array()
749 );
750 $response = wp_remote_post($url,$arguments);
751 $received_data = json_decode( wp_remote_retrieve_body($response) ,true);
752
753 if(is_wp_error($response)){
754 return 'failed connection';
755 }
756 if( isset($response['response']['code']) && $response['response']['code']=='200'){
757 return ($received_data);
758 }else{
759 return 'failed connection';
760 }
761
762 }
763
764 /**
765 * get server ip for live streaming
766 *
767 * @since 3.0.1
768 *
769 */
770 public function wpstream_get_live_stream_server($current_user,$streamname){
771
772 $token = $this->wpstream_get_token();
773 $values_array = array();
774 $values_array['new_stream'] = $streamname;
775
776 $url = WPSTREAM_CLUBLINKSSL."://www.".WPSTREAM_CLUBLINK."/wp-json/rcapi/v1/livestrem/get_server_ip/?access_token=".$token;
777
778
779 $arguments = array(
780 'method' => 'GET',
781 'timeout' => 45,
782 'redirection' => 5,
783 'httpversion' => '1.0',
784 'blocking' => true,
785 'headers' => array(),
786 'body' => $values_array,
787 'cookies' => array()
788 );
789 $response = wp_remote_post($url,$arguments);
790
791
792 $received_data = json_decode( wp_remote_retrieve_body($response) ,true);
793
794 if( isset($response['response']['code']) && $response['response']['code']=='200'){
795 return trim($received_data);
796 }else{
797 return 'failed connection';
798 }
799 exit();
800
801 }
802
803 }// end class