PluginProbe
FV Player 8 / trunk
FV Player 8 vtrunk
trunk 8.0.18 8.0.19 8.0.20 8.0.21 8.0.25 8.0.27 8.1 8.1.3
fv-player / models / linode-object-storage.class.php

linode-object-storage.class.php in FV Player 8 trunk, at models/linode-object-storage.class.php

161 lines 5.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 if ( ! defined( 'ABSPATH' ) ) {
4 exit;
5 }
6
7 if( !class_exists('FV_Player_Linode_Object_Storage') ) :
8
9 class FV_Player_Linode_Object_Storage extends FV_Player_CDN {
10
11 function __construct() {
12
13 if ( ! defined( 'ABSPATH' ) ) {
14 exit;
15 }
16
17 // TODO: What if FV Player is not yet loaded?
18 add_action( 'plugins_loaded', array( $this, 'include_linode_media_browser' ), 9 );
19 parent::__construct( array( 'key' => 'linode_object_storage', 'title' => 'Linode Object Storage') );
20 }
21
22 // includes the Digital Ocean Spaces handling class itself
23 public function include_linode_media_browser() {
24 if ( is_admin() && version_compare(phpversion(),'5.5.0') != -1 ) {
25 include( dirname( __FILE__ ) . '/linode-object-storage-browser.class.php' );
26 }
27 }
28
29 function get_endpoint() {
30 global $fv_fp;
31 $parsed = wp_parse_url( $fv_fp->_get_option( array($this->key,'endpoint' ) ) );
32
33 if( count($parsed) == 1 && !empty($parsed['path']) ) {
34 return $parsed['path'];
35
36 } else if( !empty($parsed['host']) ) {
37 return $parsed['host'];
38
39 }
40 return false;
41 }
42
43 function get_domains() {
44 global $fv_fp;
45 $space = $fv_fp->_get_option( array($this->key,'space' ) );
46 $endpoint = $this->get_endpoint();
47 if( $space && $endpoint ) {
48 return array( $space.'.'.$endpoint, $endpoint.'/'.$space );
49 }
50 return false;
51 }
52
53 function get_region() {
54 $parts = explode( '.', $this->get_endpoint() );
55 return $parts[0];
56 }
57
58 function get_secure_tokens() {
59 global $fv_fp;
60 return $fv_fp->_get_option( array($this->key,'key' ) ) && $fv_fp->_get_option( array($this->key,'secret' ) );
61 }
62
63 function options() {
64 // TODO: Fix width
65 // TODO: Add custom domain for CDN
66 global $fv_fp;
67 ?>
68 <table class="form-table2" style="margin: 5px; ">
69 <?php
70 $fv_fp->_get_input_text( array(
71 'key' => array($this->key,'space'),
72 'name' => 'Storage Name',
73 'first_td_class' => 'first'
74 ) );
75 $fv_fp->_get_input_text( array(
76 'key' => array($this->key,'endpoint'),
77 'name' => 'Endpoint'
78 ) );
79 $fv_fp->_get_input_text( array(
80 'key' => array($this->key,'key'),
81 'name' => 'Key'
82 ) );
83 $fv_fp->_get_input_text( array(
84 'key' => array($this->key,'secret'),
85 'name' => 'Secret',
86 'secret' => true
87 ) );
88 ?>
89 <tr>
90 <td colspan="4">
91 <a class="fv-wordpress-flowplayer-save button button-primary" href="#" style="margin-top: 2ex;"><?php esc_html_e( 'Save', 'fv-player' ); ?></a>
92 </td>
93 </tr>
94 </table>
95 <?php
96 }
97
98 function secure_link( $url, $secret, $ttl = false ) {
99 global $fv_fp;
100 $key = $fv_fp->_get_option( array($this->key,'key' ) );
101 $secret = $fv_fp->_get_option( array($this->key,'secret' ) );
102 $endpoint = $fv_fp->_get_option( array($this->key,'endpoint' ) );
103 $endpoint = explode('.',$endpoint);
104 $endpoint = $endpoint[0];
105
106 /*$path = preg_replace( '~.*?//.*?/~', '/', $url );
107 $expires = time() + ( $ttl ? $ttl : apply_filters('fv_player_secure_link_timeout', 900) );
108 $md5 = base64_encode(md5($path . $secret . $expires, true));
109 $md5 = strtr($md5, '+/', '-_');
110 $md5 = str_replace('=', '', $md5);
111 $url = str_replace( $path, $path."?token=".$md5."&expire=".$expires, $url );*/
112
113 $time = $ttl ? $ttl : apply_filters('fv_player_secure_link_timeout', 900);
114
115 $url_components = wp_parse_url($url);
116
117 $sXAMZDate = gmdate('Ymd\THis\Z');
118 $sDate = gmdate('Ymd');
119 $sCredentialScope = $sDate."/".$endpoint."/s3/aws4_request"; // todo: variable
120 $sSignedHeaders = "host";
121 $sXAMZCredential = urlencode( $key.'/'.$sCredentialScope);
122
123 // 1. http://docs.aws.amazon.com/general/latest/gr/sigv4-create-canonical-request.html
124 $sCanonicalRequest = "GET\n";
125 $sCanonicalRequest .= $url_components['path']."\n";
126 $sCanonicalRequest .= "X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=$sXAMZCredential&X-Amz-Date=$sXAMZDate&X-Amz-Expires=$time&X-Amz-SignedHeaders=$sSignedHeaders\n";
127 $sCanonicalRequest .= "host:".$url_components['host']."\n";
128 $sCanonicalRequest .= "\n$sSignedHeaders\n";
129 $sCanonicalRequest .= "UNSIGNED-PAYLOAD";
130
131 // 2. http://docs.aws.amazon.com/general/latest/gr/sigv4-create-string-to-sign.html
132 $sStringToSign = "AWS4-HMAC-SHA256\n";
133 $sStringToSign .= "$sXAMZDate\n";
134 $sStringToSign .= "$sCredentialScope\n";
135 $sStringToSign .= hash('sha256',$sCanonicalRequest);
136
137 // 3. http://docs.aws.amazon.com/general/latest/gr/sigv4-calculate-signature.html
138 $sSignature = hash_hmac('sha256', $sDate, "AWS4".$secret, true );
139 $sSignature = hash_hmac('sha256', $endpoint, $sSignature, true ); // todo: variable
140 $sSignature = hash_hmac('sha256', 's3', $sSignature, true );
141 $sSignature = hash_hmac('sha256', 'aws4_request', $sSignature, true );
142 $sSignature = hash_hmac('sha256', $sStringToSign, $sSignature );
143
144 // 4. http://docs.aws.amazon.com/general/latest/gr/sigv4-add-signature-to-request.html
145 $url .= "?X-Amz-Algorithm=AWS4-HMAC-SHA256";
146 $url .= "&X-Amz-Credential=$sXAMZCredential";
147 $url .= "&X-Amz-Date=$sXAMZDate";
148 $url .= "&X-Amz-Expires=$time";
149 $url .= "&X-Amz-SignedHeaders=$sSignedHeaders";
150 $url .= "&X-Amz-Signature=".$sSignature;
151
152 return $url;
153 }
154
155 }
156
157 global $FV_Player_Linode_Object_Storage;
158 $FV_Player_Linode_Object_Storage = new FV_Player_Linode_Object_Storage;
159
160 endif;
161