PluginProbe
WpStream – Live Streaming, Video on Demand, Pay Per View / 3.0.1
WpStream – Live Streaming, Video on Demand, Pay Per View v3.0.1
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.0.1, at includes/class-wpstream-live-api-connection.php

793 lines 24.5 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 'error' =>'No dns change id'
166 ));
167 }
168
169 }else{
170 echo json_encode( array(
171 'error' =>'no answer'
172 ));
173 }
174 die();
175 }
176
177
178
179
180
181 private function wpstream_request_live_stream_uri($show_id,$is_record,$request_by_userid){
182 $token = $this->wpstream_get_token();
183 $domain = parse_url ( get_site_url() );
184
185 $values_array=array(
186 "show_id" => $show_id,
187 "scheme" => $domain['scheme'],
188 "domain" => $domain['host'],
189 "domain_ip" => $_SERVER['SERVER_ADDR'],
190 "is_record" => $is_record,
191 "location" => get_home_url() ,
192 "request_by_userid" => $request_by_userid,
193 );
194
195 $url=WPSTREAM_CLUBLINKSSL."://www.".WPSTREAM_CLUBLINK."/wp-json/rcapi/v1/livestrem/new/?access_token=".$token;
196
197 $arguments = array(
198 'method' => 'GET',
199 'timeout' => 45,
200 'redirection' => 5,
201 'httpversion' => '1.0',
202 'blocking' => true,
203 'headers' => array(),
204 'body' => $values_array,
205 'cookies' => array()
206 );
207 $response = wp_remote_post($url,$arguments);
208 $received_data = json_decode( wp_remote_retrieve_body($response) ,true);
209
210
211 if( isset($response['response']['code']) && $response['response']['code']=='200'){
212 return ($received_data);
213 }else{
214 return 'failed connection';
215 }
216
217 }
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241 /**
242 * Retrive auth token from tranzient
243 *
244 * @since 3.0.1
245 * returns token
246 */
247 public function wpstream_get_token(){
248 $token = get_transient('wpstream_token_request');
249 if ( false === $token || $token==='' ) {
250 $token = $this->wpstream_club_get_token();
251 set_transient( 'wpstream_token_request', $token ,600);
252 }
253
254 return $token;
255
256 }
257
258
259
260 /**
261 * Request auth token from wpstream.net
262 *
263 * @since 3.0.1
264 * returns token fron wpstream
265 */
266 protected function wpstream_club_get_token(){
267
268 $client_id = esc_html ( get_option('wpstream_api_key','') );
269 $client_secret = esc_html ( get_option('wpstream_api_secret_key','') );
270 $username = esc_html ( get_option('wpstream_api_username','') );
271 $password = esc_html ( get_option('wpstream_api_password','') );
272
273 if ( $username=='' || $password==''){
274 return;
275 }
276 $curl = curl_init();
277
278 curl_setopt_array($curl, array(
279 CURLOPT_URL => WPSTREAM_CLUBLINKSSL."://www.".WPSTREAM_CLUBLINK."/?oauth=token",
280 CURLOPT_RETURNTRANSFER => true,
281 CURLOPT_ENCODING => "",
282 CURLOPT_MAXREDIRS => 10,
283 CURLOPT_TIMEOUT => 30,
284 CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
285 CURLOPT_CUSTOMREQUEST => "POST",
286 CURLOPT_POSTFIELDS => "grant_type=password&username=".$username."&password=".$password,
287 CURLOPT_HTTPHEADER => array(
288 "authorization: Basic ". base64_encode( '$client_id' . ':' . '$client_secret' ),
289 "cache-control: no-cache",
290 "content-type: application/x-www-form-urlencoded",
291 "postman-token: 3d65984a-9f80-a881-5fe9-59717126687e"
292 ),
293 ));
294
295 $response = curl_exec($curl);
296 $err = curl_error($curl);
297
298 curl_close($curl);
299 $response= json_decode($response);
300
301 if(isset($response->access_token)){
302 return $response->access_token;
303 }else{
304 return;
305 }
306 }
307
308
309
310
311 /**
312 * Return admin package data
313 *
314 * @since 3.0.1
315 * returns pack data
316 */
317
318 public function wpstream_request_pack_data_per_user(){
319
320 if( !current_user_can('administrator') ){
321 exit('okko 1');
322 }
323 $token = $this->wpstream_get_token();
324 $values_array = array();
325 $url = WPSTREAM_CLUBLINKSSL."://www.".WPSTREAM_CLUBLINK."/wp-json/rcapi/v1/status/packdetails/?access_token=".$token;
326
327
328 $arguments = array(
329 'method' => 'GET',
330 'timeout' => 45,
331 'redirection' => 5,
332 'httpversion' => '1.0',
333 'blocking' => true,
334 'headers' => array(),
335 'body' => $values_array,
336 'cookies' => array()
337 );
338 $response = wp_remote_post($url,$arguments);
339 $received_data = json_decode( wp_remote_retrieve_body($response) ,true);
340
341
342
343 if( isset($response['response']['code']) && $response['response']['code']=='200'){
344 return ($received_data);
345 }else{
346 return 'failed connection';
347 }
348
349 }
350
351
352 /**
353 * Check Api Status
354 *
355 * @since 3.0.1
356 * returns true or false
357 */
358
359 function wpstream_client_check_api_status(){
360
361 $token= $this->wpstream_get_token();
362
363 $url=WPSTREAM_CLUBLINKSSL."://www.".WPSTREAM_CLUBLINK."/wp-json/rcapi/v1/status/?access_token=".$token;
364 $arguments = array(
365 'method' => 'GET',
366 'timeout' => 45,
367 'redirection' => 5,
368 'httpversion' => '1.0',
369 'blocking' => true,
370 'headers' => array(),
371 'cookies' => array()
372 );
373 $response = wp_remote_post($url,$arguments);
374 $body = wp_remote_retrieve_body($response);
375
376 if ( $body === true || $body ==='true'){
377 return true;
378 }else{
379 return false;
380 }
381 }
382
383 /**
384 * Start Get live events for users
385 *
386 * @since 3.0.1
387 * returns true or false
388 */
389 public function wpstream_get_live_event_for_user(){
390 $current_user = wp_get_current_user();
391 $allowded_html = array();
392 $userID = $current_user->ID;
393 $return_uri = '';
394
395 if(function_exists('wpstream_get_option') && intval(wpstream_get_option('allow_streaming_regular_users',''))==1 ){
396 if( !is_user_logged_in() ){
397 exit('okko mnb1');
398 }
399 }else{
400 if( !current_user_can('administrator') ){
401 exit('okko mn1');
402 }
403 }
404
405
406 $event_data = $this->wpstream_request_live_stream_for_user($userID);
407 return $event_data;
408 }
409
410
411
412
413
414
415
416
417
418 /**
419 * Start Get live events for users
420 *
421 * @since 3.0.1
422 * returns true or false
423 */
424 public function wpstream_request_live_stream_for_user($user_id){
425
426 if(function_exists('wpstream_get_option') && intval(wpstream_get_option('allow_streaming_regular_users',''))==1 ){
427 if( !is_user_logged_in() ){
428 exit('okko grt1z');
429 }
430 }else{
431 if( !current_user_can('administrator') ){
432 exit('okko grt1');
433 }
434 }
435
436
437 $domain = parse_url ( get_site_url() );
438 $token= $this->wpstream_get_token();
439
440 $values_array=array(
441 "show_id" => $user_id,
442 "scheme" => $domain['scheme'],
443 "domain" => $domain['host'],
444 "domain_ip" => $_SERVER['SERVER_ADDR']
445 );
446
447
448
449 $url=WPSTREAM_CLUBLINKSSL."://www.".WPSTREAM_CLUBLINK."/wp-json/rcapi/v1/livestrem/peruser/?access_token=".$token;
450
451
452 $arguments = array(
453 'method' => 'GET',
454 'timeout' => 45,
455 'redirection' => 5,
456 'httpversion' => '1.0',
457 'blocking' => true,
458 'headers' => array(),
459 'body' => $values_array,
460 'cookies' => array()
461 );
462 $response = wp_remote_post($url,$arguments);
463 $received_data = json_decode( wp_remote_retrieve_body($response) ,true);
464
465 if(is_wp_error($response)){
466 return 'failed connection';
467 }
468 if( isset($response['response']['code']) && $response['response']['code']=='200'){
469 return ($received_data);
470 }else{
471 return 'failed connection';
472 }
473
474 }
475
476
477
478
479 /**
480 * Delete event
481 *
482 * @since 3.0.1
483 * returns noda
484 */
485
486 public function wpstream_close_event(){
487 check_ajax_referer( 'wpstream_start_event_nonce', 'security' );
488 $current_user = wp_get_current_user();
489 $allowded_html = array();
490 $userID = $current_user->ID;
491 $return_uri = '';
492 if( !current_user_can('administrator') ){
493 exit('okko');
494 }
495
496 $show_id = intval($_POST['show_id']);
497 update_post_meta ($show_id,'event_passed',1);
498 die();
499 }
500
501
502 /**
503 * Get signed upload form data
504 *
505 * @since 3.0.1
506 * returns aws form
507 */
508 public function wpstream_get_signed_form_upload_data(){
509 if( !current_user_can('administrator') ){
510 exit('okko');
511 }
512
513 $token = $this->wpstream_get_token();
514 $values_array = array();
515 $url = WPSTREAM_CLUBLINKSSL."://www.".WPSTREAM_CLUBLINK."/wp-json/rcapi/v1/videos/get_upload_form/?access_token=".$token;
516
517
518 $arguments = array(
519 'method' => 'GET',
520 'timeout' => 45,
521 'redirection' => 5,
522 'httpversion' => '1.0',
523 'blocking' => true,
524 'headers' => array(),
525 'body' => $values_array,
526 'cookies' => array()
527 );
528 $response = wp_remote_post($url,$arguments);
529 $received_data = json_decode( wp_remote_retrieve_body($response) ,true);
530
531
532
533 if( isset($response['response']['code']) && $response['response']['code']=='200'){
534 return $received_data;
535 }else{
536 return 'failed connection';
537 }
538 }
539
540 /**
541 * Get video from storage- clear data for front end use
542 *
543 * @since 3.0.1
544 * returns aws data
545 */
546 public function wpstream_get_videos(){
547 if( !current_user_can('administrator') ){
548 exit('okko');
549 }
550 $token = $this->wpstream_get_token();
551 $values_array = array();
552 $url = WPSTREAM_CLUBLINKSSL."://www.".WPSTREAM_CLUBLINK."/wp-json/rcapi/v1/videos/get_list_row/?access_token=".$token;
553
554
555 $arguments = array(
556 'method' => 'GET',
557 'timeout' => 45,
558 'redirection' => 5,
559 'httpversion' => '1.0',
560 'blocking' => true,
561 'headers' => array(),
562 'body' => $values_array,
563 'cookies' => array()
564 );
565 $response = wp_remote_post($url,$arguments);
566 $received_data = json_decode( wp_remote_retrieve_body($response) ,true);
567
568
569
570 if( isset($response['response']['code']) && $response['response']['code']=='200'){
571 $video_options=array();
572 foreach ($received_data as $key=>$videos){
573 $video_options[$videos['video_name_storage']]=$videos['video_name_storage'].'';
574 }
575
576 return $video_options;
577 }else{
578 return 'failed connection';
579 }
580
581
582
583
584 }
585
586
587
588 /**
589 * Get video from storage- raw data
590 *
591 * @since 3.0.1
592 * returns aws data
593 */
594 public function wpstream_get_videos_from_storage_raw_data( ){
595
596 if( !current_user_can('administrator') ){
597 exit('okko');
598 }
599 $token = $this->wpstream_get_token();
600 $values_array = array();
601 $url = WPSTREAM_CLUBLINKSSL."://www.".WPSTREAM_CLUBLINK."/wp-json/rcapi/v1/videos/get_list_row/?access_token=".$token;
602
603
604 $arguments = array(
605 'method' => 'GET',
606 'timeout' => 45,
607 'redirection' => 5,
608 'httpversion' => '1.0',
609 'blocking' => true,
610 'headers' => array(),
611 'body' => $values_array,
612 'cookies' => array()
613 );
614 $response = wp_remote_post($url,$arguments);
615
616
617 $received_data = json_decode( wp_remote_retrieve_body($response) ,true);
618
619
620
621 if( isset($response['response']['code']) && $response['response']['code']=='200'){
622 return $received_data;
623 }else{
624 return 'failed connection';
625 }
626
627 }
628
629
630
631 /**
632 * Get download link from aws
633 *
634 * @since 3.0.1
635 * returns aws data
636 */
637
638 function wpstream_get_download_link(){
639 if( !current_user_can('administrator') ){
640 exit('okko get_download_link');
641 }
642
643 $video_name = sanitize_text_field($_POST['video_name']);
644 $token = $this->wpstream_get_token();
645 $values_array = array();
646 $values_array['video_name'] = $video_name;
647 $url = WPSTREAM_CLUBLINKSSL."://www.".WPSTREAM_CLUBLINK."/wp-json/rcapi/v1/videos/get_download_link/?access_token=".$token;
648
649
650 $arguments = array(
651 'method' => 'GET',
652 'timeout' => 45,
653 'redirection' => 5,
654 'httpversion' => '1.0',
655 'blocking' => true,
656 'headers' => array(),
657 'body' => $values_array,
658 'cookies' => array()
659 );
660 $response = wp_remote_post($url,$arguments);
661 $received_data = json_decode( wp_remote_retrieve_body($response) ,true);
662
663 if( isset($response['response']['code']) && $response['response']['code']=='200'){
664 print trim($received_data);
665 }else{
666 return 'failed connection';
667 }
668 exit();
669 }
670
671
672 /**
673 * Delete file from storage
674 *
675 * @since 3.0.1
676 *
677 */
678 public function wpstream_get_delete_file(){
679 if( !current_user_can('administrator') ){
680 exit('okko get_delete_file');
681 }
682
683 $video_name = esc_html($_POST['video_name']);
684 $token = $this->wpstream_get_token();
685 $values_array = array();
686 $values_array['video_name'] = $video_name;
687 $url = WPSTREAM_CLUBLINKSSL."://www.".WPSTREAM_CLUBLINK."/wp-json/rcapi/v1/videos/get_delete_file/?access_token=".$token;
688
689
690 $arguments = array(
691 'method' => 'GET',
692 'timeout' => 45,
693 'redirection' => 5,
694 'httpversion' => '1.0',
695 'blocking' => true,
696 'headers' => array(),
697 'body' => $values_array,
698 'cookies' => array()
699 );
700 $response = wp_remote_post($url,$arguments);
701 $received_data = json_decode( wp_remote_retrieve_body($response) ,true);
702
703
704 if( isset($response['response']['code']) && $response['response']['code']=='200'){
705 print $received_data;
706 }else{
707 return 'failed connection';
708 }
709 exit();
710
711
712 }
713
714 /**
715 * check if stream is live
716 *
717 * @since 3.0.1
718 *
719 */
720 public function wpstream_is_is_live($product_id){
721
722 $token = $this->wpstream_get_token();
723
724 $values_array=array(
725 "show_id" => $product_id,
726 );
727 $url=WPSTREAM_CLUBLINKSSL."://www.".WPSTREAM_CLUBLINK."/wp-json/rcapi/v1/livestrem/checklive/?access_token=".$token;
728
729
730 $arguments = array(
731 'method' => 'GET',
732 'timeout' => 45,
733 'redirection' => 5,
734 'httpversion' => '1.0',
735 'blocking' => true,
736 'headers' => array(),
737 'body' => $values_array,
738 'cookies' => array()
739 );
740 $response = wp_remote_post($url,$arguments);
741 $received_data = json_decode( wp_remote_retrieve_body($response) ,true);
742
743 if(is_wp_error($response)){
744 return 'failed connection';
745 }
746 if( isset($response['response']['code']) && $response['response']['code']=='200'){
747 return ($received_data);
748 }else{
749 return 'failed connection';
750 }
751
752 }
753
754 /**
755 * get server ip for live streaming
756 *
757 * @since 3.0.1
758 *
759 */
760 public function wpstream_get_live_stream_server($current_user,$streamname){
761
762 $token = $this->wpstream_get_token();
763 $values_array = array();
764 $values_array['new_stream'] = $streamname;
765
766 $url = WPSTREAM_CLUBLINKSSL."://www.".WPSTREAM_CLUBLINK."/wp-json/rcapi/v1/livestrem/get_server_ip/?access_token=".$token;
767
768
769 $arguments = array(
770 'method' => 'GET',
771 'timeout' => 45,
772 'redirection' => 5,
773 'httpversion' => '1.0',
774 'blocking' => true,
775 'headers' => array(),
776 'body' => $values_array,
777 'cookies' => array()
778 );
779 $response = wp_remote_post($url,$arguments);
780
781
782 $received_data = json_decode( wp_remote_retrieve_body($response) ,true);
783
784 if( isset($response['response']['code']) && $response['response']['code']=='200'){
785 return trim($received_data);
786 }else{
787 return 'failed connection';
788 }
789 exit();
790
791 }
792
793 }// end class