@@ -7,7 +7,7 @@ discard block |
||
| 7 | 7 | signer:请求构造链 |
| 8 | 8 | handler:结果处理链 |
| 9 | 9 | */ |
| 10 | -class API{ |
|
| 10 | +class API { |
|
| 11 | 11 | public static $API = array( |
| 12 | 12 | "getService"=>array( |
| 13 | 13 | "redirect"=>"listBuckets" |
@@ -73,7 +73,7 @@ discard block |
||
| 73 | 73 | "needBucket"=>TRUE, |
| 74 | 74 | "needObject"=>FALSE, |
| 75 | 75 | "signer"=>"DefaultUserAgentSigner->DefaultContentTypeSigner->HeaderAuthSigner", |
| 76 | - "queryParams"=>array("Options->prefix","Options->delimiter","Options->marker","Options->max-keys"), |
|
| 76 | + "queryParams"=>array("Options->prefix", "Options->delimiter", "Options->marker", "Options->max-keys"), |
|
| 77 | 77 | "handler"=>"ErrorResponseHandler->ListObjectsHandler" |
| 78 | 78 | ), |
| 79 | 79 | "getBucketAcl" => array( |
@@ -113,7 +113,7 @@ discard block |
||
| 113 | 113 | "needBucket"=>TRUE, |
| 114 | 114 | "needObject"=>FALSE, |
| 115 | 115 | "subResource"=>"uploads", |
| 116 | - "queryParams"=>array("Options->max-uploads","Options->key-marker","Options->prefix","Options->upload-id-marker","Options->delimiter"), |
|
| 116 | + "queryParams"=>array("Options->max-uploads", "Options->key-marker", "Options->prefix", "Options->upload-id-marker", "Options->delimiter"), |
|
| 117 | 117 | "signer"=>"DefaultUserAgentSigner->DefaultContentTypeSigner->HeaderAuthSigner", |
| 118 | 118 | "handler"=>"ErrorResponseHandler->ListMutipartUploadsHandler" |
| 119 | 119 | ), |
@@ -212,7 +212,7 @@ discard block |
||
| 212 | 212 | "method"=>"PUT", |
| 213 | 213 | "needBucket"=>TRUE, |
| 214 | 214 | "needObject"=>TRUE, |
| 215 | - "queryParams"=>array("!Options->uploadId","!Options->partNumber"), |
|
| 215 | + "queryParams"=>array("!Options->uploadId", "!Options->partNumber"), |
|
| 216 | 216 | //这个请求没有body,所以使用了ContentLengthSigner->ContentMD5Signer而没用ObjectMetaSigner |
| 217 | 217 | "signer"=>"DefaultUserAgentSigner->ACLSigner->StreamContentTypeSigner->ContentLengthSigner->ContentMD5Signer->SSECSigner->StreamUploadSigner->HeaderAuthSigner", |
| 218 | 218 | "handler"=>"ErrorResponseHandler->UploadHandler" |
@@ -229,7 +229,7 @@ discard block |
||
| 229 | 229 | "method"=>"GET", |
| 230 | 230 | "needBucket"=>TRUE, |
| 231 | 231 | "needObject"=>TRUE, |
| 232 | - "queryParams"=>array("!Options->uploadId","Options->max-parts","Options->part-number-marker"), |
|
| 232 | + "queryParams"=>array("!Options->uploadId", "Options->max-parts", "Options->part-number-marker"), |
|
| 233 | 233 | "signer"=>"DefaultUserAgentSigner->DefaultContentTypeSigner->HeaderAuthSigner", |
| 234 | 234 | "handler"=>"ErrorResponseHandler->ListPartsHandler" |
| 235 | 235 | ), |
@@ -246,7 +246,7 @@ discard block |
||
| 246 | 246 | "method"=>"Method", |
| 247 | 247 | "needBucket"=>FALSE, |
| 248 | 248 | "needObject"=>FALSE, |
| 249 | - "queryParams"=>array("!Options->Expires","Options->*"), |
|
| 249 | + "queryParams"=>array("!Options->Expires", "Options->*"), |
|
| 250 | 250 | "signer"=>"AllHeaderSigner->QueryAuthSigner", |
| 251 | 251 | ), |
| 252 | 252 | "putAdp"=>array( |
@@ -261,7 +261,7 @@ discard block |
||
| 261 | 261 | "method"=>"GET", |
| 262 | 262 | "needBucket"=>FALSE, |
| 263 | 263 | "needObject"=>TRUE, |
| 264 | - "objectPostion"=>"TaskID",//专门为这个接口定义的属性 |
|
| 264 | + "objectPostion"=>"TaskID", //专门为这个接口定义的属性 |
|
| 265 | 265 | "subResource"=>"queryadp", |
| 266 | 266 | "signer"=>"DefaultUserAgentSigner", |
| 267 | 267 | "handler"=>"ErrorResponseHandler->AdpHandler" |
@@ -1,66 +1,66 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | require_once KS3_API_PATH.DIRECTORY_SEPARATOR."exceptions".DIRECTORY_SEPARATOR."Exceptions.php"; |
| 3 | 3 | |
| 4 | -interface Handler{ |
|
| 4 | +interface Handler { |
|
| 5 | 5 | public function handle(ResponseCore $response); |
| 6 | 6 | } |
| 7 | -class ErrorResponseHandler implements Handler{ |
|
| 8 | - public function handle(ResponseCore $response){ |
|
| 7 | +class ErrorResponseHandler implements Handler { |
|
| 8 | + public function handle(ResponseCore $response) { |
|
| 9 | 9 | $code = $response->status; |
| 10 | - if($code >= 400){ |
|
| 10 | + if ($code >= 400) { |
|
| 11 | 11 | $exception = new Ks3ServiceException(); |
| 12 | - $exception->statusCode=$code; |
|
| 13 | - if(!empty($response->body)){ |
|
| 12 | + $exception->statusCode = $code; |
|
| 13 | + if (!empty($response->body)) { |
|
| 14 | 14 | $xml = new SimpleXMLElement($response->body); |
| 15 | 15 | $exception ->requestId = $xml->RequestId->__toString(); |
| 16 | 16 | $exception->errorCode = $xml->Code->__toString(); |
| 17 | - $exception->errorMessage=$xml->Message->__toString(); |
|
| 18 | - $exception->resource=$xml->Resource->__toString(); |
|
| 17 | + $exception->errorMessage = $xml->Message->__toString(); |
|
| 18 | + $exception->resource = $xml->Resource->__toString(); |
|
| 19 | 19 | } |
| 20 | 20 | throw $exception; |
| 21 | - }else{ |
|
| 21 | + }else { |
|
| 22 | 22 | return $response; |
| 23 | 23 | } |
| 24 | 24 | } |
| 25 | 25 | } |
| 26 | -class ListBucketsHandler implements Handler{ |
|
| 26 | +class ListBucketsHandler implements Handler { |
|
| 27 | 27 | |
| 28 | - public function handle(ResponseCore $response){ |
|
| 28 | + public function handle(ResponseCore $response) { |
|
| 29 | 29 | $result = array(); |
| 30 | 30 | $xml = new SimpleXMLElement($response->body); |
| 31 | 31 | foreach ($xml->Buckets->Bucket as $bucketXml) { |
| 32 | 32 | $bucket = array(); |
| 33 | 33 | foreach ($bucketXml->children() as $key => $value) { |
| 34 | - $bucket[$key]=$value->__toString(); |
|
| 34 | + $bucket[$key] = $value->__toString(); |
|
| 35 | 35 | } |
| 36 | 36 | array_push($result, $bucket); |
| 37 | 37 | } |
| 38 | 38 | return $result; |
| 39 | 39 | } |
| 40 | 40 | } |
| 41 | -class ListObjectsHandler implements Handler{ |
|
| 42 | - public function handle(ResponseCore $response){ |
|
| 41 | +class ListObjectsHandler implements Handler { |
|
| 42 | + public function handle(ResponseCore $response) { |
|
| 43 | 43 | $result = array(); |
| 44 | 44 | $xml = new SimpleXMLElement($response->body); |
| 45 | - $result["Name"]=$xml->Name->__toString(); |
|
| 46 | - $result["Prefix"]=$xml->Prefix->__toString(); |
|
| 47 | - $result["Marker"]=$xml->Marker->__toString(); |
|
| 48 | - $result["Delimiter"]=$xml->Delimiter->__toString(); |
|
| 49 | - $result["MaxKeys"]=$xml->MaxKeys->__toString(); |
|
| 50 | - $result["IsTruncated"]=$xml->IsTruncated->__toString(); |
|
| 51 | - $result["NextMarker"]=$xml->NextMarker->__toString(); |
|
| 45 | + $result["Name"] = $xml->Name->__toString(); |
|
| 46 | + $result["Prefix"] = $xml->Prefix->__toString(); |
|
| 47 | + $result["Marker"] = $xml->Marker->__toString(); |
|
| 48 | + $result["Delimiter"] = $xml->Delimiter->__toString(); |
|
| 49 | + $result["MaxKeys"] = $xml->MaxKeys->__toString(); |
|
| 50 | + $result["IsTruncated"] = $xml->IsTruncated->__toString(); |
|
| 51 | + $result["NextMarker"] = $xml->NextMarker->__toString(); |
|
| 52 | 52 | $contents = array(); |
| 53 | 53 | foreach ($xml->Contents as $contentXml) { |
| 54 | 54 | $content = array(); |
| 55 | 55 | foreach ($contentXml->children() as $key => $value) { |
| 56 | 56 | $owner = array(); |
| 57 | - if($key === "Owner"){ |
|
| 57 | + if ($key === "Owner") { |
|
| 58 | 58 | foreach ($value->children() as $ownerkey => $ownervalue) { |
| 59 | - $owner[$ownerkey]=$ownervalue->__toString(); |
|
| 59 | + $owner[$ownerkey] = $ownervalue->__toString(); |
|
| 60 | 60 | } |
| 61 | 61 | $content["Owner"] = $owner; |
| 62 | - }else{ |
|
| 63 | - $content[$key]=$value->__toString(); |
|
| 62 | + }else { |
|
| 63 | + $content[$key] = $value->__toString(); |
|
| 64 | 64 | } |
| 65 | 65 | } |
| 66 | 66 | array_push($contents, $content); |
@@ -77,62 +77,62 @@ discard block |
||
| 77 | 77 | return $result; |
| 78 | 78 | } |
| 79 | 79 | } |
| 80 | -class GetBucketCORSHandler implements Handler{ |
|
| 81 | - public function handle(ResponseCore $response){ |
|
| 80 | +class GetBucketCORSHandler implements Handler { |
|
| 81 | + public function handle(ResponseCore $response) { |
|
| 82 | 82 | $xml = new SimpleXMLElement($response->body); |
| 83 | 83 | $cors = array(); |
| 84 | 84 | foreach ($xml->CORSRule as $rule) { |
| 85 | 85 | $acors = array(); |
| 86 | 86 | foreach ($rule as $key => $value) { |
| 87 | - if($key === "MaxAgeSeconds") |
|
| 87 | + if ($key === "MaxAgeSeconds") |
|
| 88 | 88 | { |
| 89 | 89 | $acors[$key] = $value->__toString(); |
| 90 | - }else{ |
|
| 91 | - if(!isset($acors[$key])){ |
|
| 90 | + }else { |
|
| 91 | + if (!isset($acors[$key])) { |
|
| 92 | 92 | $acors[$key] = array(); |
| 93 | 93 | } |
| 94 | - array_push($acors[$key],$value->__toString()); |
|
| 94 | + array_push($acors[$key], $value->__toString()); |
|
| 95 | 95 | } |
| 96 | 96 | } |
| 97 | - array_push($cors,$acors); |
|
| 97 | + array_push($cors, $acors); |
|
| 98 | 98 | } |
| 99 | 99 | return $cors; |
| 100 | 100 | } |
| 101 | 101 | } |
| 102 | -class GetBucketLocationHandler implements Handler{ |
|
| 103 | - public function handle(ResponseCore $response){ |
|
| 102 | +class GetBucketLocationHandler implements Handler { |
|
| 103 | + public function handle(ResponseCore $response) { |
|
| 104 | 104 | $xml = new SimpleXMLElement($response->body); |
| 105 | 105 | $location = $xml->__toString(); |
| 106 | 106 | |
| 107 | 107 | return $location; |
| 108 | 108 | } |
| 109 | 109 | } |
| 110 | -class GetBucketLoggingHandler implements Handler{ |
|
| 111 | - public function handle(ResponseCore $response){ |
|
| 110 | +class GetBucketLoggingHandler implements Handler { |
|
| 111 | + public function handle(ResponseCore $response) { |
|
| 112 | 112 | $logging = array(); |
| 113 | 113 | $xml = new SimpleXMLElement($response->body); |
| 114 | 114 | $loggingXml = $xml->LoggingEnabled; |
| 115 | - if($loggingXml&&$loggingXml!==NULL) |
|
| 115 | + if ($loggingXml && $loggingXml !== NULL) |
|
| 116 | 116 | { |
| 117 | 117 | foreach ($loggingXml->children() as $key => $value) { |
| 118 | 118 | $logging["Enable"] = TRUE; |
| 119 | 119 | $logging[$key] = $value->__toString(); |
| 120 | 120 | } |
| 121 | - }else{ |
|
| 121 | + }else { |
|
| 122 | 122 | $logging["Enable"] = FALSE; |
| 123 | 123 | } |
| 124 | 124 | return $logging; |
| 125 | 125 | } |
| 126 | 126 | } |
| 127 | -class ObjectMetaHandler implements Handler{ |
|
| 128 | - public function handle(ResponseCore $response){ |
|
| 127 | +class ObjectMetaHandler implements Handler { |
|
| 128 | + public function handle(ResponseCore $response) { |
|
| 129 | 129 | $ObjectMeta = array(); |
| 130 | 130 | $UserMeta = array(); |
| 131 | 131 | foreach ($response->header as $key => $value) { |
| 132 | - if (substr(strtolower($key), 0, 10) === Consts::$UserMetaPrefix){ |
|
| 133 | - $UserMeta[$key]=$value; |
|
| 134 | - }else if(isset(Consts::$ResponseObjectMeta[strtolower($key)])){ |
|
| 135 | - $ObjectMeta[Consts::$ResponseObjectMeta[strtolower($key)]]=$value; |
|
| 132 | + if (substr(strtolower($key), 0, 10) === Consts::$UserMetaPrefix) { |
|
| 133 | + $UserMeta[$key] = $value; |
|
| 134 | + }else if (isset(Consts::$ResponseObjectMeta[strtolower($key)])) { |
|
| 135 | + $ObjectMeta[Consts::$ResponseObjectMeta[strtolower($key)]] = $value; |
|
| 136 | 136 | } |
| 137 | 137 | } |
| 138 | 138 | $Meta = array( |
@@ -142,15 +142,15 @@ discard block |
||
| 142 | 142 | return $Meta; |
| 143 | 143 | } |
| 144 | 144 | } |
| 145 | -class getObjectHandler implements Handler{ |
|
| 146 | - public function handle(ResponseCore $response){ |
|
| 145 | +class getObjectHandler implements Handler { |
|
| 146 | + public function handle(ResponseCore $response) { |
|
| 147 | 147 | $ObjectMeta = array(); |
| 148 | 148 | $UserMeta = array(); |
| 149 | 149 | foreach ($response->header as $key => $value) { |
| 150 | - if (substr(strtolower($key), 0, 10) === Consts::$UserMetaPrefix){ |
|
| 151 | - $UserMeta[$key]=$value; |
|
| 152 | - }else if(isset(Consts::$ResponseObjectMeta[strtolower($key)])){ |
|
| 153 | - $ObjectMeta[Consts::$ResponseObjectMeta[strtolower($key)]]=$value; |
|
| 150 | + if (substr(strtolower($key), 0, 10) === Consts::$UserMetaPrefix) { |
|
| 151 | + $UserMeta[$key] = $value; |
|
| 152 | + }else if (isset(Consts::$ResponseObjectMeta[strtolower($key)])) { |
|
| 153 | + $ObjectMeta[Consts::$ResponseObjectMeta[strtolower($key)]] = $value; |
|
| 154 | 154 | } |
| 155 | 155 | } |
| 156 | 156 | $Meta = array( |
@@ -164,21 +164,21 @@ discard block |
||
| 164 | 164 | return $ks3Object; |
| 165 | 165 | } |
| 166 | 166 | } |
| 167 | -class CopyHandler implements Handler{ |
|
| 168 | - public function handle(ResponseCore $response){ |
|
| 167 | +class CopyHandler implements Handler { |
|
| 168 | + public function handle(ResponseCore $response) { |
|
| 169 | 169 | $headers = array(); |
| 170 | 170 | |
| 171 | 171 | foreach ($response->header as $key => $value) { |
| 172 | - if(isset(Consts::$SSEHandler[strtolower($key)])&&!empty($value)){ |
|
| 173 | - $headers[Consts::$SSEHandler[strtolower($key)]]=$value; |
|
| 172 | + if (isset(Consts::$SSEHandler[strtolower($key)]) && !empty($value)) { |
|
| 173 | + $headers[Consts::$SSEHandler[strtolower($key)]] = $value; |
|
| 174 | 174 | } |
| 175 | 175 | } |
| 176 | 176 | |
| 177 | 177 | return $headers; |
| 178 | 178 | } |
| 179 | 179 | } |
| 180 | -class InitMultipartUploadHandler implements Handler{ |
|
| 181 | - public function handle(ResponseCore $response){ |
|
| 180 | +class InitMultipartUploadHandler implements Handler { |
|
| 181 | + public function handle(ResponseCore $response) { |
|
| 182 | 182 | $upload = array(); |
| 183 | 183 | $xml = new SimpleXMLElement($response->body); |
| 184 | 184 | foreach ($xml->children() as $key => $value) { |
@@ -186,27 +186,27 @@ discard block |
||
| 186 | 186 | } |
| 187 | 187 | |
| 188 | 188 | foreach ($response->header as $key => $value) { |
| 189 | - if(isset(Consts::$SSEHandler[strtolower($key)])&&!empty($value)){ |
|
| 190 | - $upload[Consts::$SSEHandler[strtolower($key)]]=$value; |
|
| 189 | + if (isset(Consts::$SSEHandler[strtolower($key)]) && !empty($value)) { |
|
| 190 | + $upload[Consts::$SSEHandler[strtolower($key)]] = $value; |
|
| 191 | 191 | } |
| 192 | 192 | } |
| 193 | 193 | |
| 194 | 194 | return $upload; |
| 195 | 195 | } |
| 196 | 196 | } |
| 197 | -class ListPartsHandler implements Handler{ |
|
| 198 | - public function handle(ResponseCore $response){ |
|
| 197 | +class ListPartsHandler implements Handler { |
|
| 198 | + public function handle(ResponseCore $response) { |
|
| 199 | 199 | $listParts = array(); |
| 200 | 200 | $xml = new SimpleXMLElement($response->body); |
| 201 | 201 | |
| 202 | - $listParts["Bucket"]=$xml->Bucket->__toString(); |
|
| 203 | - $listParts["Key"]=$xml->Key->__toString(); |
|
| 204 | - $listParts["UploadId"]=$xml->UploadId->__toString(); |
|
| 205 | - $listParts["StorageClass"]=$xml->StorageClass->__toString(); |
|
| 206 | - $listParts["PartNumberMarker"]=$xml->PartNumberMarker->__toString(); |
|
| 207 | - $listParts["NextPartNumberMarker"]=$xml->NextPartNumberMarker->__toString(); |
|
| 208 | - $listParts["MaxParts"]=$xml->MaxParts->__toString(); |
|
| 209 | - $listParts["IsTruncated"]=$xml->IsTruncated->__toString(); |
|
| 202 | + $listParts["Bucket"] = $xml->Bucket->__toString(); |
|
| 203 | + $listParts["Key"] = $xml->Key->__toString(); |
|
| 204 | + $listParts["UploadId"] = $xml->UploadId->__toString(); |
|
| 205 | + $listParts["StorageClass"] = $xml->StorageClass->__toString(); |
|
| 206 | + $listParts["PartNumberMarker"] = $xml->PartNumberMarker->__toString(); |
|
| 207 | + $listParts["NextPartNumberMarker"] = $xml->NextPartNumberMarker->__toString(); |
|
| 208 | + $listParts["MaxParts"] = $xml->MaxParts->__toString(); |
|
| 209 | + $listParts["IsTruncated"] = $xml->IsTruncated->__toString(); |
|
| 210 | 210 | |
| 211 | 211 | $initer = array(); |
| 212 | 212 | $owner = array(); |
@@ -218,7 +218,7 @@ discard block |
||
| 218 | 218 | $owner[$key] = $value->__toString(); |
| 219 | 219 | } |
| 220 | 220 | $listParts["Owner"] = $owner; |
| 221 | - $listParts["Initiator"]=$initer; |
|
| 221 | + $listParts["Initiator"] = $initer; |
|
| 222 | 222 | |
| 223 | 223 | $parts = array(); |
| 224 | 224 | foreach ($xml->Part as $partxml) { |
@@ -226,25 +226,25 @@ discard block |
||
| 226 | 226 | foreach ($partxml->children() as $key => $value) { |
| 227 | 227 | $part[$key] = $value->__toString(); |
| 228 | 228 | } |
| 229 | - array_push($parts,$part); |
|
| 229 | + array_push($parts, $part); |
|
| 230 | 230 | } |
| 231 | 231 | $listParts["Parts"] = $parts; |
| 232 | 232 | return $listParts; |
| 233 | 233 | } |
| 234 | 234 | } |
| 235 | -class UploadHandler implements Handler{ |
|
| 236 | - public function handle(ResponseCore $response){ |
|
| 235 | +class UploadHandler implements Handler { |
|
| 236 | + public function handle(ResponseCore $response) { |
|
| 237 | 237 | $Headers = array(); |
| 238 | 238 | foreach ($response->header as $key => $value) { |
| 239 | - if(isset(Consts::$UploadHandler[strtolower($key)])&&!empty($value)){ |
|
| 240 | - $Headers[Consts::$UploadHandler[strtolower($key)]]=$value; |
|
| 239 | + if (isset(Consts::$UploadHandler[strtolower($key)]) && !empty($value)) { |
|
| 240 | + $Headers[Consts::$UploadHandler[strtolower($key)]] = $value; |
|
| 241 | 241 | } |
| 242 | 242 | } |
| 243 | 243 | return $Headers; |
| 244 | 244 | } |
| 245 | 245 | } |
| 246 | -class GetAclHandler implements Handler{ |
|
| 247 | - public function handle(ResponseCore $response){ |
|
| 246 | +class GetAclHandler implements Handler { |
|
| 247 | + public function handle(ResponseCore $response) { |
|
| 248 | 248 | $hasread = FALSE; |
| 249 | 249 | $haswrite = FALSE; |
| 250 | 250 | $xml = new SimpleXMLElement($response->body); |
@@ -254,88 +254,88 @@ discard block |
||
| 254 | 254 | $hasURI = FALSE; |
| 255 | 255 | $grantee = $grant->Grantee; |
| 256 | 256 | foreach ($grantee->children() as $key => $value) { |
| 257 | - if($key === "URI"&&$value->__toString() === Consts::$Grantee_Group_All){ |
|
| 257 | + if ($key === "URI" && $value->__toString() === Consts::$Grantee_Group_All) { |
|
| 258 | 258 | $hasURI = TRUE; |
| 259 | 259 | } |
| 260 | 260 | } |
| 261 | - if($hasURI){ |
|
| 262 | - if($permission===Consts::$Permission_Read){ |
|
| 261 | + if ($hasURI) { |
|
| 262 | + if ($permission === Consts::$Permission_Read) { |
|
| 263 | 263 | $hasread = TRUE; |
| 264 | - }elseif($permission===Consts::$Permission_Write){ |
|
| 264 | + }elseif ($permission === Consts::$Permission_Write) { |
|
| 265 | 265 | $haswrite = TRUE; |
| 266 | 266 | } |
| 267 | 267 | } |
| 268 | 268 | } |
| 269 | - if($hasread&&$haswrite){ |
|
| 269 | + if ($hasread && $haswrite) { |
|
| 270 | 270 | return "public-read-write"; |
| 271 | - }else{ |
|
| 272 | - if($hasread) |
|
| 271 | + }else { |
|
| 272 | + if ($hasread) |
|
| 273 | 273 | return "public-read"; |
| 274 | 274 | else |
| 275 | 275 | return "private"; |
| 276 | 276 | } |
| 277 | 277 | } |
| 278 | 278 | } |
| 279 | -class ListMutipartUploadsHandler implements Handler{ |
|
| 280 | - public function handle(ResponseCore $response){ |
|
| 279 | +class ListMutipartUploadsHandler implements Handler { |
|
| 280 | + public function handle(ResponseCore $response) { |
|
| 281 | 281 | $mutiUploads = array(); |
| 282 | 282 | $xml = new SimpleXMLElement($response->body); |
| 283 | 283 | |
| 284 | - $mutiUploads["Bucket"]=$xml->Bucket->__toString(); |
|
| 285 | - $mutiUploads["KeyMarker"]=$xml->KeyMarker->__toString(); |
|
| 286 | - $mutiUploads["UploadIdMarker"]=$xml->UploadIdMarker->__toString(); |
|
| 287 | - $mutiUploads["NextKeyMarker"]=$xml->NextKeyMarker->__toString(); |
|
| 288 | - $mutiUploads["NextUploadIdMarker"]=$xml->NextUploadIdMarker->__toString(); |
|
| 289 | - $mutiUploads["MaxUploads"]=$xml->MaxUploads->__toString(); |
|
| 290 | - $mutiUploads["IsTruncated"]=$xml->IsTruncated->__toString(); |
|
| 284 | + $mutiUploads["Bucket"] = $xml->Bucket->__toString(); |
|
| 285 | + $mutiUploads["KeyMarker"] = $xml->KeyMarker->__toString(); |
|
| 286 | + $mutiUploads["UploadIdMarker"] = $xml->UploadIdMarker->__toString(); |
|
| 287 | + $mutiUploads["NextKeyMarker"] = $xml->NextKeyMarker->__toString(); |
|
| 288 | + $mutiUploads["NextUploadIdMarker"] = $xml->NextUploadIdMarker->__toString(); |
|
| 289 | + $mutiUploads["MaxUploads"] = $xml->MaxUploads->__toString(); |
|
| 290 | + $mutiUploads["IsTruncated"] = $xml->IsTruncated->__toString(); |
|
| 291 | 291 | |
| 292 | 292 | |
| 293 | 293 | $uploads = array(); |
| 294 | 294 | foreach ($xml->Upload as $uploadxml) { |
| 295 | 295 | $upload = array(); |
| 296 | 296 | foreach ($uploadxml->children() as $key => $value) { |
| 297 | - if($key === "Initiator"){ |
|
| 297 | + if ($key === "Initiator") { |
|
| 298 | 298 | $initer = array(); |
| 299 | 299 | foreach ($value->children() as $key1 => $value1) { |
| 300 | 300 | $initer[$key1] = $value1->__toString(); |
| 301 | 301 | } |
| 302 | 302 | $upload["Initiator"] = $initer; |
| 303 | - }elseif($key === "Owner"){ |
|
| 303 | + }elseif ($key === "Owner") { |
|
| 304 | 304 | $owner = array(); |
| 305 | 305 | foreach ($value->children() as $key1 => $value1) { |
| 306 | 306 | $owner[$key1] = $value1->__toString(); |
| 307 | 307 | } |
| 308 | 308 | $upload["Owner"] = $owner; |
| 309 | - }else{ |
|
| 309 | + }else { |
|
| 310 | 310 | $upload[$key] = $value->__toString(); |
| 311 | 311 | } |
| 312 | 312 | } |
| 313 | - array_push($uploads,$upload); |
|
| 313 | + array_push($uploads, $upload); |
|
| 314 | 314 | } |
| 315 | 315 | $mutiUploads["Uploads"] = $uploads; |
| 316 | 316 | return $mutiUploads; |
| 317 | 317 | } |
| 318 | 318 | } |
| 319 | -class AdpHandler implements Handler{ |
|
| 320 | - public function handle(ResponseCore $response){ |
|
| 319 | +class AdpHandler implements Handler { |
|
| 320 | + public function handle(ResponseCore $response) { |
|
| 321 | 321 | return $response->body; |
| 322 | 322 | } |
| 323 | 323 | } |
| 324 | -class BooleanHandler implements Handler{ |
|
| 325 | - public function handle(ResponseCore $response){ |
|
| 326 | - if($response->isOk()){ |
|
| 324 | +class BooleanHandler implements Handler { |
|
| 325 | + public function handle(ResponseCore $response) { |
|
| 326 | + if ($response->isOk()) { |
|
| 327 | 327 | return TRUE; |
| 328 | - }else{ |
|
| 328 | + }else { |
|
| 329 | 329 | return FALSE; |
| 330 | 330 | } |
| 331 | 331 | } |
| 332 | 332 | } |
| 333 | -class ExistsHandler implements Handler{ |
|
| 334 | - public function handle(ResponseCore $response){ |
|
| 333 | +class ExistsHandler implements Handler { |
|
| 334 | + public function handle(ResponseCore $response) { |
|
| 335 | 335 | $status = $response->status; |
| 336 | - if($status === 404){ |
|
| 336 | + if ($status === 404) { |
|
| 337 | 337 | return FALSE; |
| 338 | - }else{ |
|
| 338 | + }else { |
|
| 339 | 339 | return TRUE; |
| 340 | 340 | } |
| 341 | 341 | } |
@@ -387,7 +387,7 @@ discard block |
||
| 387 | 387 | |
| 388 | 388 | if ($position !== false && $position >= 0) |
| 389 | 389 | { |
| 390 | - $size = $stats['size'] - $position; |
|
| 390 | + $size = $stats['size']-$position; |
|
| 391 | 391 | } |
| 392 | 392 | } |
| 393 | 393 | } |
@@ -462,7 +462,7 @@ discard block |
||
| 462 | 462 | */ |
| 463 | 463 | public function set_seek_position($position) |
| 464 | 464 | { |
| 465 | - $this->seek_position = isset($position) ? (integer) $position : null; |
|
| 465 | + $this->seek_position = isset($position) ? (integer)$position : null; |
|
| 466 | 466 | |
| 467 | 467 | return $this; |
| 468 | 468 | } |
@@ -533,7 +533,7 @@ discard block |
||
| 533 | 533 | // Execute callback function |
| 534 | 534 | if ($this->registered_streaming_read_callback) |
| 535 | 535 | { |
| 536 | - return $this->registered_streaming_read_callback->streaming_read_callback($curl_handle, $file_handle, $length,$this->read_stream,$this->seek_position); |
|
| 536 | + return $this->registered_streaming_read_callback->streaming_read_callback($curl_handle, $file_handle, $length, $this->read_stream, $this->seek_position); |
|
| 537 | 537 | } |
| 538 | 538 | // Once we've sent as much as we're supposed to send... |
| 539 | 539 | if ($this->read_stream_read >= $this->read_stream_size) |
@@ -551,7 +551,7 @@ discard block |
||
| 551 | 551 | } |
| 552 | 552 | } |
| 553 | 553 | |
| 554 | - $read = fread($this->read_stream, min($this->read_stream_size - $this->read_stream_read, $length)); // Remaining upload data or cURL's requested chunk size |
|
| 554 | + $read = fread($this->read_stream, min($this->read_stream_size-$this->read_stream_read, $length)); // Remaining upload data or cURL's requested chunk size |
|
| 555 | 555 | $this->read_stream_read += strlen($read); |
| 556 | 556 | |
| 557 | 557 | $out = $read === false ? '' : $read; |
@@ -568,8 +568,8 @@ discard block |
||
| 568 | 568 | */ |
| 569 | 569 | public function streaming_write_callback($curl_handle, $data) |
| 570 | 570 | { |
| 571 | - if ($this->registered_streaming_write_callback){ |
|
| 572 | - return $this->registered_streaming_write_callback->streaming_write_callback($curl_handle,$data,$this->write_stream); |
|
| 571 | + if ($this->registered_streaming_write_callback) { |
|
| 572 | + return $this->registered_streaming_write_callback->streaming_write_callback($curl_handle, $data, $this->write_stream); |
|
| 573 | 573 | } |
| 574 | 574 | $length = strlen($data); |
| 575 | 575 | $written_total = 0; |
@@ -631,7 +631,7 @@ discard block |
||
| 631 | 631 | // chmod the file as 0755 |
| 632 | 632 | if ($this->cacert_location === true) |
| 633 | 633 | { |
| 634 | - curl_setopt($curl_handle, CURLOPT_CAINFO, dirname(__FILE__) . '/cacert.pem'); |
|
| 634 | + curl_setopt($curl_handle, CURLOPT_CAINFO, dirname(__FILE__).'/cacert.pem'); |
|
| 635 | 635 | } |
| 636 | 636 | elseif (is_string($this->cacert_location)) |
| 637 | 637 | { |
@@ -656,12 +656,12 @@ discard block |
||
| 656 | 656 | curl_setopt($curl_handle, CURLOPT_HTTPPROXYTUNNEL, true); |
| 657 | 657 | |
| 658 | 658 | $host = $this->proxy['host']; |
| 659 | - $host .= ($this->proxy['port']) ? ':' . $this->proxy['port'] : ''; |
|
| 659 | + $host .= ($this->proxy['port']) ? ':'.$this->proxy['port'] : ''; |
|
| 660 | 660 | curl_setopt($curl_handle, CURLOPT_PROXY, $host); |
| 661 | 661 | |
| 662 | 662 | if (isset($this->proxy['user']) && isset($this->proxy['pass'])) |
| 663 | 663 | { |
| 664 | - curl_setopt($curl_handle, CURLOPT_PROXYUSERPWD, $this->proxy['user'] . ':' . $this->proxy['pass']); |
|
| 664 | + curl_setopt($curl_handle, CURLOPT_PROXYUSERPWD, $this->proxy['user'].':'.$this->proxy['pass']); |
|
| 665 | 665 | } |
| 666 | 666 | } |
| 667 | 667 | |
@@ -669,7 +669,7 @@ discard block |
||
| 669 | 669 | if ($this->username && $this->password) |
| 670 | 670 | { |
| 671 | 671 | curl_setopt($curl_handle, CURLOPT_HTTPAUTH, CURLAUTH_ANY); |
| 672 | - curl_setopt($curl_handle, CURLOPT_USERPWD, $this->username . ':' . $this->password); |
|
| 672 | + curl_setopt($curl_handle, CURLOPT_USERPWD, $this->username.':'.$this->password); |
|
| 673 | 673 | } |
| 674 | 674 | |
| 675 | 675 | // Handle the encoding if we can. |
@@ -685,7 +685,7 @@ discard block |
||
| 685 | 685 | |
| 686 | 686 | foreach ($this->request_headers as $k => $v) |
| 687 | 687 | { |
| 688 | - $temp_headers[] = $k . ': ' . $v; |
|
| 688 | + $temp_headers[] = $k.': '.$v; |
|
| 689 | 689 | } |
| 690 | 690 | |
| 691 | 691 | curl_setopt($curl_handle, CURLOPT_HTTPHEADER, $temp_headers); |
@@ -787,7 +787,7 @@ discard block |
||
| 787 | 787 | foreach ($this->response_headers as $header) |
| 788 | 788 | { |
| 789 | 789 | $kv = explode(': ', $header); |
| 790 | - $header_assoc[strtolower($kv[0])] = isset($kv[1])?$kv[1]:''; |
|
| 790 | + $header_assoc[strtolower($kv[0])] = isset($kv[1]) ? $kv[1] : ''; |
|
| 791 | 791 | } |
| 792 | 792 | |
| 793 | 793 | // Reset the headers to the appropriate property. |
@@ -820,7 +820,7 @@ discard block |
||
| 820 | 820 | |
| 821 | 821 | if ($this->response === false) |
| 822 | 822 | { |
| 823 | - throw new RequestCore_Exception('cURL resource: ' . (string) $curl_handle . '; cURL error: ' . curl_error($curl_handle) . ' (' . curl_errno($curl_handle) . ')'); |
|
| 823 | + throw new RequestCore_Exception('cURL resource: '.(string)$curl_handle.'; cURL error: '.curl_error($curl_handle).' ('.curl_errno($curl_handle).')'); |
|
| 824 | 824 | } |
| 825 | 825 | |
| 826 | 826 | $parsed_response = $this->process_response($curl_handle, $this->response); |
@@ -893,13 +893,13 @@ discard block |
||
| 893 | 893 | // Since curl_errno() isn't reliable for handles that were in multirequests, we check the 'result' of the info read, which contains the curl error number, (listed here http://curl.haxx.se/libcurl/c/libcurl-errors.html ) |
| 894 | 894 | if ($done['result'] > 0) |
| 895 | 895 | { |
| 896 | - throw new RequestCore_Exception('cURL resource: ' . (string) $done['handle'] . '; cURL error: ' . curl_error($done['handle']) . ' (' . $done['result'] . ')'); |
|
| 896 | + throw new RequestCore_Exception('cURL resource: '.(string)$done['handle'].'; cURL error: '.curl_error($done['handle']).' ('.$done['result'].')'); |
|
| 897 | 897 | } |
| 898 | 898 | |
| 899 | 899 | // Because curl_multi_info_read() might return more than one message about a request, we check to see if this request is already in our array of completed requests |
| 900 | - elseif (!isset($to_process[(int) $done['handle']])) |
|
| 900 | + elseif (!isset($to_process[(int)$done['handle']])) |
|
| 901 | 901 | { |
| 902 | - $to_process[(int) $done['handle']] = $done; |
|
| 902 | + $to_process[(int)$done['handle']] = $done; |
|
| 903 | 903 | } |
| 904 | 904 | } |
| 905 | 905 | |
@@ -1,7 +1,7 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | //使用客户端加密的方式上传下载文件 |
| 3 | 3 | //检测API路径 |
| 4 | -if(!defined('KS3_API_PATH')) |
|
| 4 | +if (!defined('KS3_API_PATH')) |
|
| 5 | 5 | define('KS3_API_PATH', dirname(__FILE__)); |
| 6 | 6 | require_once KS3_API_PATH.DIRECTORY_SEPARATOR."Ks3Client.class.php"; |
| 7 | 7 | require_once KS3_API_PATH.DIRECTORY_SEPARATOR."encryption".DIRECTORY_SEPARATOR."EncryptionUtil.php"; |
@@ -9,88 +9,88 @@ discard block |
||
| 9 | 9 | |
| 10 | 10 | //加密模式 |
| 11 | 11 | //暂时仅支持EO,使用AES/CBC/PKCS5Padding算法对数据进行加密 |
| 12 | -if(!defined("ENCRYPTPTION_MODE")) |
|
| 13 | -define("ENCRYPTPTION_MODE","EO"); |
|
| 12 | +if (!defined("ENCRYPTPTION_MODE")) |
|
| 13 | +define("ENCRYPTPTION_MODE", "EO"); |
|
| 14 | 14 | //加密信息存储模式,暂时支持 ObjectMetadata和InstructionFile |
| 15 | 15 | //ObjectMetadata:存在用户元数据中 |
| 16 | 16 | //InstructionFile:存在一个.instruction文件中 |
| 17 | -if(!defined("ENCRYPTPTION_STORAGE_MODE")) |
|
| 18 | -define("ENCRYPTPTION_STORAGE_MODE","ObjectMetadata"); |
|
| 17 | +if (!defined("ENCRYPTPTION_STORAGE_MODE")) |
|
| 18 | +define("ENCRYPTPTION_STORAGE_MODE", "ObjectMetadata"); |
|
| 19 | 19 | |
| 20 | 20 | |
| 21 | -if(function_exists('get_loaded_extensions')){ |
|
| 21 | +if (function_exists('get_loaded_extensions')) { |
|
| 22 | 22 | //检测mcrypt,openssl扩展 |
| 23 | 23 | $extensions = get_loaded_extensions(); |
| 24 | - if($extensions){ |
|
| 25 | - if(!in_array('mcrypt', $extensions)){ |
|
| 24 | + if ($extensions) { |
|
| 25 | + if (!in_array('mcrypt', $extensions)) { |
|
| 26 | 26 | throw new Ks3ClientException("please install mcrypt extension"); |
| 27 | 27 | } |
| 28 | - if(!in_array('openssl', $extensions)){ |
|
| 28 | + if (!in_array('openssl', $extensions)) { |
|
| 29 | 29 | throw new Ks3ClientException("please install openssl extension"); |
| 30 | 30 | } |
| 31 | - }else{ |
|
| 31 | + }else { |
|
| 32 | 32 | throw new Ks3ClientException("please install extensions"); |
| 33 | 33 | } |
| 34 | -}else{ |
|
| 34 | +}else { |
|
| 35 | 35 | throw new Ks3ClientException(); |
| 36 | 36 | } |
| 37 | -class Ks3EncryptionClient extends Ks3Client{ |
|
| 37 | +class Ks3EncryptionClient extends Ks3Client { |
|
| 38 | 38 | private $encryptionHandler = NULL; |
| 39 | 39 | //用户提供的主密钥,可以是对称秘钥或非对称秘钥(array,分别是公钥和私钥) |
| 40 | 40 | private $encryptionMaterials = NULL; |
| 41 | 41 | |
| 42 | - public function __construct($accessKey, $secretKey,$encryptionMaterials, $endpoint = NULL ){ |
|
| 43 | - parent::__construct($accessKey,$secretKey,$endpoint); |
|
| 44 | - if(is_array($encryptionMaterials)){ |
|
| 45 | - if(count($encryptionMaterials)==2){ |
|
| 42 | + public function __construct($accessKey, $secretKey, $encryptionMaterials, $endpoint = NULL) { |
|
| 43 | + parent::__construct($accessKey, $secretKey, $endpoint); |
|
| 44 | + if (is_array($encryptionMaterials)) { |
|
| 45 | + if (count($encryptionMaterials) == 2) { |
|
| 46 | 46 | $pk = openssl_pkey_get_public($encryptionMaterials[0]); |
| 47 | 47 | $sk = openssl_pkey_get_private($encryptionMaterials[1]); |
| 48 | - if(!$pk) |
|
| 48 | + if (!$pk) |
|
| 49 | 49 | throw new Ks3ClientException("invalid RSA public key,you can generate key use openssl"); |
| 50 | - if(!$sk) |
|
| 50 | + if (!$sk) |
|
| 51 | 51 | throw new Ks3ClientException("invalid RSA private key,you can generate key use openssl"); |
| 52 | - $encryptionMaterials = array($pk,$sk); |
|
| 53 | - }else{ |
|
| 52 | + $encryptionMaterials = array($pk, $sk); |
|
| 53 | + }else { |
|
| 54 | 54 | throw new Ks3ClientException("encryptionMaterials should be string or an array of size 2"); |
| 55 | 55 | } |
| 56 | 56 | } |
| 57 | - $ks3client = new Ks3Client($accessKey,$secretKey,$endpoint); |
|
| 57 | + $ks3client = new Ks3Client($accessKey, $secretKey, $endpoint); |
|
| 58 | 58 | $this->encryptionMaterials = $encryptionMaterials; |
| 59 | - if(ENCRYPTPTION_MODE == "EO"){ |
|
| 60 | - $this->encryptionHandler = new EncryptionEO($ks3client,$encryptionMaterials); |
|
| 59 | + if (ENCRYPTPTION_MODE == "EO") { |
|
| 60 | + $this->encryptionHandler = new EncryptionEO($ks3client, $encryptionMaterials); |
|
| 61 | 61 | }elseif (ENCRYPTPTION_MODE == "AE") { |
| 62 | 62 | throw new Ks3ClientException("Authenticated encryption will be supported in the futher"); |
| 63 | 63 | } |
| 64 | - else{ |
|
| 64 | + else { |
|
| 65 | 65 | throw new Ks3ClientException("unsupported encryption mode :".ENCRYPTPTION_MODE); |
| 66 | 66 | } |
| 67 | - if(ENCRYPTPTION_STORAGE_MODE != "ObjectMetadata"&&ENCRYPTPTION_STORAGE_MODE!="InstructionFile"){ |
|
| 67 | + if (ENCRYPTPTION_STORAGE_MODE != "ObjectMetadata" && ENCRYPTPTION_STORAGE_MODE != "InstructionFile") { |
|
| 68 | 68 | throw new Ks3ClientException("unsupported encryption storage mode :".ENCRYPTPTION_STORAGE_MODE); |
| 69 | 69 | } |
| 70 | 70 | } |
| 71 | 71 | |
| 72 | - public function putObjectByContent($args=array()){ |
|
| 72 | + public function putObjectByContent($args = array()) { |
|
| 73 | 73 | return $this->encryptionHandler->putObjectByContentSecurely($args); |
| 74 | 74 | } |
| 75 | - public function putObjectByFile($args=array()){ |
|
| 75 | + public function putObjectByFile($args = array()) { |
|
| 76 | 76 | return $this->encryptionHandler->putObjectByFileSecurely($args); |
| 77 | 77 | } |
| 78 | - public function getObject($args=array()){ |
|
| 78 | + public function getObject($args = array()) { |
|
| 79 | 79 | return $this->encryptionHandler->getObjectSecurely($args); |
| 80 | 80 | } |
| 81 | - public function initMultipartUpload($args=array()){ |
|
| 81 | + public function initMultipartUpload($args = array()) { |
|
| 82 | 82 | return $this->encryptionHandler->initMultipartUploadSecurely($args); |
| 83 | 83 | } |
| 84 | - public function uploadPart($args=array()){ |
|
| 84 | + public function uploadPart($args = array()) { |
|
| 85 | 85 | return $this->encryptionHandler->uploadPartSecurely($args); |
| 86 | 86 | } |
| 87 | - public function abortMultipartUpload($args=array()){ |
|
| 87 | + public function abortMultipartUpload($args = array()) { |
|
| 88 | 88 | return $this->encryptionHandler->abortMultipartUploadSecurely($args); |
| 89 | 89 | } |
| 90 | - public function completeMultipartUpload($args=array()){ |
|
| 90 | + public function completeMultipartUpload($args = array()) { |
|
| 91 | 91 | return $this->encryptionHandler->completeMultipartUploadSecurely($args); |
| 92 | 92 | } |
| 93 | - public function deleteObject($args=array()){ |
|
| 93 | + public function deleteObject($args = array()) { |
|
| 94 | 94 | $result = parent::deleteObject($args); |
| 95 | 95 | $args["Key"] = $args["Key"].EncryptionUtil::$INSTRUCTION_SUFFIX; |
| 96 | 96 | try { |
@@ -100,17 +100,17 @@ discard block |
||
| 100 | 100 | } |
| 101 | 101 | return $result; |
| 102 | 102 | } |
| 103 | - public function copyObject($args=array()){ |
|
| 104 | - if(parent::objectExists(array( |
|
| 103 | + public function copyObject($args = array()) { |
|
| 104 | + if (parent::objectExists(array( |
|
| 105 | 105 | "Bucket"=>$args["Bucket"], |
| 106 | 106 | "Key"=>$args["Key"] |
| 107 | - ))){ |
|
| 107 | + ))) { |
|
| 108 | 108 | throw new Ks3ClientException("copy object faild,destination object exists"); |
| 109 | 109 | } |
| 110 | - if(parent::objectExists(array( |
|
| 110 | + if (parent::objectExists(array( |
|
| 111 | 111 | "Bucket"=>$args["CopySource"]["Bucket"], |
| 112 | 112 | "Key"=>$args["CopySource"]["Key"].EncryptionUtil::$INSTRUCTION_SUFFIX |
| 113 | - ))){ |
|
| 113 | + ))) { |
|
| 114 | 114 | parent::copyObject( |
| 115 | 115 | array( |
| 116 | 116 | "Bucket"=>$args["Bucket"], |
@@ -2,9 +2,9 @@ discard block |
||
| 2 | 2 | //更加详细的表单上传请参考js sdk |
| 3 | 3 | require_once "../Ks3Client.class.php"; |
| 4 | 4 | |
| 5 | -$client = new Ks3Client("",""); |
|
| 5 | +$client = new Ks3Client("", ""); |
|
| 6 | 6 | $bucket_name = "phpsdktestlijunwei"; |
| 7 | -if(!$client->bucketExists(array("Bucket"=>$bucket_name))){ |
|
| 7 | +if (!$client->bucketExists(array("Bucket"=>$bucket_name))) { |
|
| 8 | 8 | $client->createBucket(array("Bucket"=>$bucket_name)); |
| 9 | 9 | } |
| 10 | 10 | |
@@ -24,7 +24,7 @@ discard block |
||
| 24 | 24 | $unknowData = array( |
| 25 | 25 | "random" |
| 26 | 26 | ); |
| 27 | -$result = $client->postObject($bucket_name,$postData,$unknowData); |
|
| 27 | +$result = $client->postObject($bucket_name, $postData, $unknowData); |
|
| 28 | 28 | print_r($result); |
| 29 | 29 | |
| 30 | 30 | ?> |
@@ -33,14 +33,14 @@ discard block |
||
| 33 | 33 | <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> |
| 34 | 34 | </head> |
| 35 | 35 | <body> |
| 36 | -<form action="<?php echo $host_uri;?>" method="post" enctype="multipart/form-data"> |
|
| 37 | -Key to upload: <input type="input" name="key" value="<?php echo $key;?>" /><br /> |
|
| 38 | -<input type="hidden" name="success_action_redirect" value="<?php echo $redirect;?>" /> |
|
| 36 | +<form action="<?php echo $host_uri; ?>" method="post" enctype="multipart/form-data"> |
|
| 37 | +Key to upload: <input type="input" name="key" value="<?php echo $key; ?>" /><br /> |
|
| 38 | +<input type="hidden" name="success_action_redirect" value="<?php echo $redirect; ?>" /> |
|
| 39 | 39 | <input type="hidden" name="Content-Type" value="text/html" /> |
| 40 | 40 | <input type="hidden" name="random" value="vfegf34egf3" /> |
| 41 | -<input type="hidden" name="KSSAccessKeyId" value="<?php echo $result["KSSAccessKeyId"];?>" /> |
|
| 42 | -<input type="hidden" name="Policy" value="<?php echo $result["Policy"];?>" /> |
|
| 43 | -<input type="hidden" name="Signature" value="<?php echo $result["Signature"];?>" /> |
|
| 41 | +<input type="hidden" name="KSSAccessKeyId" value="<?php echo $result["KSSAccessKeyId"]; ?>" /> |
|
| 42 | +<input type="hidden" name="Policy" value="<?php echo $result["Policy"]; ?>" /> |
|
| 43 | +<input type="hidden" name="Signature" value="<?php echo $result["Signature"]; ?>" /> |
|
| 44 | 44 | File: <input type="file" name="file" /> <br /> |
| 45 | 45 | <!-- The elements after this will be ignored --> |
| 46 | 46 | <input type="submit" name="submit" value="Upload to KSS S3" /> |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -define("ENCRYPTPTION_STORAGE_MODE","ObjectMetadata"); |
|
| 2 | +define("ENCRYPTPTION_STORAGE_MODE", "ObjectMetadata"); |
|
| 3 | 3 | require_once "../Ks3EncryptionClient.class.php"; |
| 4 | 4 | require_once "../Ks3Client.class.php"; |
| 5 | 5 | $bucket = "test-encryption"; |
@@ -7,16 +7,16 @@ discard block |
||
| 7 | 7 | |
| 8 | 8 | $filename = "secret.key"; |
| 9 | 9 | $handle = fopen($filename, "r"); |
| 10 | -$contents = fread($handle, filesize ($filename)); |
|
| 10 | +$contents = fread($handle, filesize($filename)); |
|
| 11 | 11 | fclose($handle); |
| 12 | 12 | |
| 13 | -$client = new Ks3EncryptionClient("lMQTr0hNlMpB0iOk/i+x","D4CsYLs75JcWEjbiI22zR3P7kJ/+5B1qdEje7A7I",$contents); |
|
| 14 | -putObjectByContentAndGetObjectUsingMeta($client,$bucket,$keyprefix); |
|
| 15 | -putObjectByFileAndGetObjectUsingMeta($client,$bucket,$keyprefix); |
|
| 16 | -multipartUpload($client,$bucket,$keyprefix); |
|
| 13 | +$client = new Ks3EncryptionClient("lMQTr0hNlMpB0iOk/i+x", "D4CsYLs75JcWEjbiI22zR3P7kJ/+5B1qdEje7A7I", $contents); |
|
| 14 | +putObjectByContentAndGetObjectUsingMeta($client, $bucket, $keyprefix); |
|
| 15 | +putObjectByFileAndGetObjectUsingMeta($client, $bucket, $keyprefix); |
|
| 16 | +multipartUpload($client, $bucket, $keyprefix); |
|
| 17 | 17 | |
| 18 | -function putObjectByContentAndGetObjectUsingMeta($client,$bucket,$keyprefix){ |
|
| 19 | - for($i = 45 ;$i < 60;$i++){ |
|
| 18 | +function putObjectByContentAndGetObjectUsingMeta($client, $bucket, $keyprefix) { |
|
| 19 | + for ($i = 45; $i < 60; $i++) { |
|
| 20 | 20 | |
| 21 | 21 | $content = EncryptionUtil::genereateOnceUsedKey($i); |
| 22 | 22 | |
@@ -27,11 +27,11 @@ discard block |
||
| 27 | 27 | "Content"=>$content |
| 28 | 28 | ); |
| 29 | 29 | $client->putObjectByContent($args); |
| 30 | - rangeGetAndCheckMd5($client,$bucket,$keyprefix."EOMeta", |
|
| 31 | - "D://testdown/down",base64_encode(md5($args["Content"]))); |
|
| 30 | + rangeGetAndCheckMd5($client, $bucket, $keyprefix."EOMeta", |
|
| 31 | + "D://testdown/down", base64_encode(md5($args["Content"]))); |
|
| 32 | 32 | } |
| 33 | 33 | } |
| 34 | -function putObjectByFileAndGetObjectUsingMeta($client,$bucket,$keyprefix){ |
|
| 34 | +function putObjectByFileAndGetObjectUsingMeta($client, $bucket, $keyprefix) { |
|
| 35 | 35 | |
| 36 | 36 | $args = array( |
| 37 | 37 | "Bucket"=>$bucket, |
@@ -42,39 +42,39 @@ discard block |
||
| 42 | 42 | ) |
| 43 | 43 | ); |
| 44 | 44 | $client->putObjectByFile($args); |
| 45 | - rangeGetAndCheckMd5($client,$bucket,$keyprefix."EOMeta", |
|
| 46 | - "D://testdown/down",base64_encode(md5_file("D://IMG.jpg"))); |
|
| 45 | + rangeGetAndCheckMd5($client, $bucket, $keyprefix."EOMeta", |
|
| 46 | + "D://testdown/down", base64_encode(md5_file("D://IMG.jpg"))); |
|
| 47 | 47 | } |
| 48 | -function multipartUpload($client,$bucket,$keyprefix){ |
|
| 48 | +function multipartUpload($client, $bucket, $keyprefix) { |
|
| 49 | 49 | //初始化分开上传,获取uploadid |
| 50 | 50 | $args = array( |
| 51 | 51 | "Bucket"=>$bucket, |
| 52 | 52 | "Key"=>$keyprefix."EOMeta", |
| 53 | 53 | ); |
| 54 | 54 | $uploadid = $client->initMultipartUpload($args); |
| 55 | - $uploadid = $uploadid["UploadId"];//获取到uploadid |
|
| 55 | + $uploadid = $uploadid["UploadId"]; //获取到uploadid |
|
| 56 | 56 | //开始上传 |
| 57 | 57 | |
| 58 | - $file = "D://IMG.jpg";//要上传的文件 |
|
| 58 | + $file = "D://IMG.jpg"; //要上传的文件 |
|
| 59 | 59 | $partsize = 1024*100; |
| 60 | - $resource = fopen($file,"r"); |
|
| 60 | + $resource = fopen($file, "r"); |
|
| 61 | 61 | $stat = fstat($resource); |
| 62 | - $total = $stat["size"];//获取文件的总大小 |
|
| 62 | + $total = $stat["size"]; //获取文件的总大小 |
|
| 63 | 63 | fclose($resource); |
| 64 | - $count = (int)(($total-1)/$partsize)+1;//计算文件需要分几块上传 |
|
| 65 | - for($i = 0;$i < $count;$i++){ |
|
| 64 | + $count = (int)(($total-1)/$partsize)+1; //计算文件需要分几块上传 |
|
| 65 | + for ($i = 0; $i < $count; $i++) { |
|
| 66 | 66 | //依次上传每一块 |
| 67 | 67 | echo "upload".$i."\r\n"; |
| 68 | - $args=array( |
|
| 68 | + $args = array( |
|
| 69 | 69 | "Bucket"=>$bucket, |
| 70 | 70 | "Key"=>$keyprefix."EOMeta", |
| 71 | - "LastPart"=>($i===$count-1), |
|
| 71 | + "LastPart"=>($i === $count-1), |
|
| 72 | 72 | "Options"=>array( |
| 73 | 73 | "partNumber"=>$i+1, |
| 74 | 74 | "uploadId"=>$uploadid |
| 75 | 75 | ), |
| 76 | 76 | "ObjectMeta"=>array( |
| 77 | - "Content-Length"=>min($partsize,$total-$partsize*$i)//每次上传$partsize大小 |
|
| 77 | + "Content-Length"=>min($partsize, $total-$partsize*$i)//每次上传$partsize大小 |
|
| 78 | 78 | ), |
| 79 | 79 | "Content"=>array( |
| 80 | 80 | "content"=>$file, |
@@ -84,9 +84,9 @@ discard block |
||
| 84 | 84 | $etag = $client->uploadPart($args); |
| 85 | 85 | $etag = $etag["ETag"]; |
| 86 | 86 | } |
| 87 | - $parts = $client->listParts(array("Bucket"=>$bucket,"Key"=>$keyprefix."EOMeta","Options"=>array("uploadId"=>$uploadid))); |
|
| 87 | + $parts = $client->listParts(array("Bucket"=>$bucket, "Key"=>$keyprefix."EOMeta", "Options"=>array("uploadId"=>$uploadid))); |
|
| 88 | 88 | //结束上传 |
| 89 | - $args=array( |
|
| 89 | + $args = array( |
|
| 90 | 90 | "Bucket"=>$bucket, |
| 91 | 91 | "Key"=>$keyprefix."EOMeta", |
| 92 | 92 | "Options"=>array("uploadId"=>$uploadid), |
@@ -94,21 +94,21 @@ discard block |
||
| 94 | 94 | ); |
| 95 | 95 | $result = $client->completeMultipartUpload($args); |
| 96 | 96 | |
| 97 | - rangeGetAndCheckMd5($client,$bucket,$keyprefix."EOMeta", |
|
| 98 | - "D://testdown/down",base64_encode(md5_file("D://IMG.jpg"))); |
|
| 97 | + rangeGetAndCheckMd5($client, $bucket, $keyprefix."EOMeta", |
|
| 98 | + "D://testdown/down", base64_encode(md5_file("D://IMG.jpg"))); |
|
| 99 | 99 | } |
| 100 | -function rangeGetAndCheckMd5($client,$bucket,$key,$file,$expectedMd5){ |
|
| 101 | - $args = array("Bucket"=>$bucket,"Key"=>$key); |
|
| 100 | +function rangeGetAndCheckMd5($client, $bucket, $key, $file, $expectedMd5) { |
|
| 101 | + $args = array("Bucket"=>$bucket, "Key"=>$key); |
|
| 102 | 102 | $meta = $client->getObjectMeta($args); |
| 103 | 103 | $contentlength = $meta["ObjectMeta"]["Content-Length"]; |
| 104 | 104 | |
| 105 | 105 | $filelist = array(); |
| 106 | 106 | |
| 107 | - for($begin = 0;$begin <$contentlength;){ |
|
| 108 | - $index = rand((int)($contentlength/20),(int)($contentlength/10)); |
|
| 109 | - $range = array("start"=>$begin,"end"=>$begin+$index); |
|
| 107 | + for ($begin = 0; $begin < $contentlength;) { |
|
| 108 | + $index = rand((int)($contentlength/20), (int)($contentlength/10)); |
|
| 109 | + $range = array("start"=>$begin, "end"=>$begin+$index); |
|
| 110 | 110 | $destFile = $file.$begin."-".($begin+$index); |
| 111 | - array_push($filelist,$destFile); |
|
| 111 | + array_push($filelist, $destFile); |
|
| 112 | 112 | $begin += ($index+1); |
| 113 | 113 | $args = array( |
| 114 | 114 | "Bucket"=>$bucket, |
@@ -120,17 +120,17 @@ discard block |
||
| 120 | 120 | } |
| 121 | 121 | |
| 122 | 122 | foreach ($filelist as $key => $value) { |
| 123 | - $handle = fopen($value,"r"); |
|
| 123 | + $handle = fopen($value, "r"); |
|
| 124 | 124 | $size = filesize($value); |
| 125 | - if($size > 0){ |
|
| 126 | - $content = fread($handle,$size); |
|
| 127 | - file_put_contents($file,$content,FILE_APPEND); |
|
| 125 | + if ($size > 0) { |
|
| 126 | + $content = fread($handle, $size); |
|
| 127 | + file_put_contents($file, $content, FILE_APPEND); |
|
| 128 | 128 | } |
| 129 | 129 | fclose($handle); |
| 130 | 130 | @unlink($value); |
| 131 | 131 | } |
| 132 | 132 | $md5 = base64_encode(md5_file($file)); |
| 133 | - if($md5 != $expectedMd5) |
|
| 133 | + if ($md5 != $expectedMd5) |
|
| 134 | 134 | throw new Exception("file md5 check error expected ".$expectedMd5." ,actual ".$md5, 1); |
| 135 | 135 | @unlink($file); |
| 136 | 136 | } |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -define("ENCRYPTPTION_STORAGE_MODE","InstructionFile"); |
|
| 2 | +define("ENCRYPTPTION_STORAGE_MODE", "InstructionFile"); |
|
| 3 | 3 | require_once "../Ks3EncryptionClient.class.php"; |
| 4 | 4 | require_once "../Ks3Client.class.php"; |
| 5 | 5 | $bucket = "test-encryption"; |
@@ -7,17 +7,17 @@ discard block |
||
| 7 | 7 | |
| 8 | 8 | $filename = "secret.key"; |
| 9 | 9 | $handle = fopen($filename, "r"); |
| 10 | -$contents = fread($handle, filesize ($filename)); |
|
| 10 | +$contents = fread($handle, filesize($filename)); |
|
| 11 | 11 | fclose($handle); |
| 12 | 12 | |
| 13 | -$client = new Ks3EncryptionClient("lMQTr0hNlMpB0iOk/i+x","D4CsYLs75JcWEjbiI22zR3P7kJ/+5B1qdEje7A7I",$contents); |
|
| 14 | -putObjectByContentAndGetObjectUsingInstruction($client,$bucket,$keyprefix); |
|
| 15 | -putObjectByFileAndGetObjectUsingFile($client,$bucket,$keyprefix); |
|
| 16 | -multipartUpload($client,$bucket,$keyprefix); |
|
| 17 | -copyAnddeleteObject($client,$bucket,$keyprefix); |
|
| 13 | +$client = new Ks3EncryptionClient("lMQTr0hNlMpB0iOk/i+x", "D4CsYLs75JcWEjbiI22zR3P7kJ/+5B1qdEje7A7I", $contents); |
|
| 14 | +putObjectByContentAndGetObjectUsingInstruction($client, $bucket, $keyprefix); |
|
| 15 | +putObjectByFileAndGetObjectUsingFile($client, $bucket, $keyprefix); |
|
| 16 | +multipartUpload($client, $bucket, $keyprefix); |
|
| 17 | +copyAnddeleteObject($client, $bucket, $keyprefix); |
|
| 18 | 18 | |
| 19 | -function putObjectByContentAndGetObjectUsingInstruction($client,$bucket,$keyprefix){ |
|
| 20 | - $content = EncryptionUtil::genereateOnceUsedKey(rand(100,1000)); |
|
| 19 | +function putObjectByContentAndGetObjectUsingInstruction($client, $bucket, $keyprefix) { |
|
| 20 | + $content = EncryptionUtil::genereateOnceUsedKey(rand(100, 1000)); |
|
| 21 | 21 | $args = array( |
| 22 | 22 | "Bucket"=>$bucket, |
| 23 | 23 | "Key"=>$keyprefix."EOFile", |
@@ -25,10 +25,10 @@ discard block |
||
| 25 | 25 | "Content"=>$content |
| 26 | 26 | ); |
| 27 | 27 | $client->putObjectByContent($args); |
| 28 | - rangeGetAndCheckMd5($client,$bucket,$keyprefix."EOFile", |
|
| 29 | - "D://testdown/down",base64_encode(md5($args["Content"]))); |
|
| 28 | + rangeGetAndCheckMd5($client, $bucket, $keyprefix."EOFile", |
|
| 29 | + "D://testdown/down", base64_encode(md5($args["Content"]))); |
|
| 30 | 30 | } |
| 31 | -function putObjectByFileAndGetObjectUsingFile($client,$bucket,$keyprefix){ |
|
| 31 | +function putObjectByFileAndGetObjectUsingFile($client, $bucket, $keyprefix) { |
|
| 32 | 32 | |
| 33 | 33 | $args = array( |
| 34 | 34 | "Bucket"=>$bucket, |
@@ -39,39 +39,39 @@ discard block |
||
| 39 | 39 | ) |
| 40 | 40 | ); |
| 41 | 41 | $client->putObjectByFile($args); |
| 42 | - rangeGetAndCheckMd5($client,$bucket,$keyprefix."EOFile", |
|
| 43 | - "D://testdown/down",base64_encode(md5_file("D://IMG.jpg"))); |
|
| 42 | + rangeGetAndCheckMd5($client, $bucket, $keyprefix."EOFile", |
|
| 43 | + "D://testdown/down", base64_encode(md5_file("D://IMG.jpg"))); |
|
| 44 | 44 | } |
| 45 | -function multipartUpload($client,$bucket,$keyprefix){ |
|
| 45 | +function multipartUpload($client, $bucket, $keyprefix) { |
|
| 46 | 46 | //初始化分开上传,获取uploadid |
| 47 | 47 | $args = array( |
| 48 | 48 | "Bucket"=>$bucket, |
| 49 | 49 | "Key"=>$keyprefix."EOFile", |
| 50 | 50 | ); |
| 51 | 51 | $uploadid = $client->initMultipartUpload($args); |
| 52 | - $uploadid = $uploadid["UploadId"];//获取到uploadid |
|
| 52 | + $uploadid = $uploadid["UploadId"]; //获取到uploadid |
|
| 53 | 53 | //开始上传 |
| 54 | 54 | |
| 55 | - $file = "D://IMG.jpg";//要上传的文件 |
|
| 55 | + $file = "D://IMG.jpg"; //要上传的文件 |
|
| 56 | 56 | $partsize = 1024*100; |
| 57 | - $resource = fopen($file,"r"); |
|
| 57 | + $resource = fopen($file, "r"); |
|
| 58 | 58 | $stat = fstat($resource); |
| 59 | - $total = $stat["size"];//获取文件的总大小 |
|
| 59 | + $total = $stat["size"]; //获取文件的总大小 |
|
| 60 | 60 | fclose($resource); |
| 61 | - $count = (int)(($total-1)/$partsize)+1;//计算文件需要分几块上传 |
|
| 62 | - for($i = 0;$i < $count;$i++){ |
|
| 61 | + $count = (int)(($total-1)/$partsize)+1; //计算文件需要分几块上传 |
|
| 62 | + for ($i = 0; $i < $count; $i++) { |
|
| 63 | 63 | //依次上传每一块 |
| 64 | 64 | echo "upload".$i."\r\n"; |
| 65 | - $args=array( |
|
| 65 | + $args = array( |
|
| 66 | 66 | "Bucket"=>$bucket, |
| 67 | 67 | "Key"=>$keyprefix."EOFile", |
| 68 | - "LastPart"=>($i===$count-1), |
|
| 68 | + "LastPart"=>($i === $count-1), |
|
| 69 | 69 | "Options"=>array( |
| 70 | 70 | "partNumber"=>$i+1, |
| 71 | 71 | "uploadId"=>$uploadid |
| 72 | 72 | ), |
| 73 | 73 | "ObjectMeta"=>array( |
| 74 | - "Content-Length"=>min($partsize,$total-$partsize*$i)//每次上传$partsize大小 |
|
| 74 | + "Content-Length"=>min($partsize, $total-$partsize*$i)//每次上传$partsize大小 |
|
| 75 | 75 | ), |
| 76 | 76 | "Content"=>array( |
| 77 | 77 | "content"=>$file, |
@@ -81,9 +81,9 @@ discard block |
||
| 81 | 81 | $etag = $client->uploadPart($args); |
| 82 | 82 | $etag = $etag["ETag"]; |
| 83 | 83 | } |
| 84 | - $parts = $client->listParts(array("Bucket"=>$bucket,"Key"=>$keyprefix."EOFile","Options"=>array("uploadId"=>$uploadid))); |
|
| 84 | + $parts = $client->listParts(array("Bucket"=>$bucket, "Key"=>$keyprefix."EOFile", "Options"=>array("uploadId"=>$uploadid))); |
|
| 85 | 85 | //结束上传 |
| 86 | - $args=array( |
|
| 86 | + $args = array( |
|
| 87 | 87 | "Bucket"=>$bucket, |
| 88 | 88 | "Key"=>$keyprefix."EOFile", |
| 89 | 89 | "Options"=>array("uploadId"=>$uploadid), |
@@ -91,11 +91,11 @@ discard block |
||
| 91 | 91 | ); |
| 92 | 92 | $result = $client->completeMultipartUpload($args); |
| 93 | 93 | |
| 94 | - rangeGetAndCheckMd5($client,$bucket,$keyprefix."EOFile", |
|
| 95 | - "D://testdown/down",base64_encode(md5_file("D://IMG.jpg"))); |
|
| 94 | + rangeGetAndCheckMd5($client, $bucket, $keyprefix."EOFile", |
|
| 95 | + "D://testdown/down", base64_encode(md5_file("D://IMG.jpg"))); |
|
| 96 | 96 | } |
| 97 | -function copyAnddeleteObject($client,$bucket,$keyprefix){ |
|
| 98 | - $content = EncryptionUtil::genereateOnceUsedKey(rand(100,1000)); |
|
| 97 | +function copyAnddeleteObject($client, $bucket, $keyprefix) { |
|
| 98 | + $content = EncryptionUtil::genereateOnceUsedKey(rand(100, 1000)); |
|
| 99 | 99 | $args = array( |
| 100 | 100 | "Bucket"=>$bucket, |
| 101 | 101 | "Key"=>$keyprefix."EOFile", |
@@ -104,10 +104,10 @@ discard block |
||
| 104 | 104 | ); |
| 105 | 105 | $client->putObjectByContent($args); |
| 106 | 106 | |
| 107 | - if($client->objectExists(array("Bucket"=>$bucket,"Key"=>$keyprefix."EOFileCopy"))) |
|
| 108 | - $client->deleteObject(array("Bucket"=>$bucket,"Key"=>$keyprefix."EOFileCopy")); |
|
| 109 | - if($client->objectExists(array("Bucket"=>$bucket,"Key"=>$keyprefix."EOFileCopy.instruction"))) |
|
| 110 | - $client->deleteObject(array("Bucket"=>$bucket,"Key"=>$keyprefix."EOFileCopy.instruction")); |
|
| 107 | + if ($client->objectExists(array("Bucket"=>$bucket, "Key"=>$keyprefix."EOFileCopy"))) |
|
| 108 | + $client->deleteObject(array("Bucket"=>$bucket, "Key"=>$keyprefix."EOFileCopy")); |
|
| 109 | + if ($client->objectExists(array("Bucket"=>$bucket, "Key"=>$keyprefix."EOFileCopy.instruction"))) |
|
| 110 | + $client->deleteObject(array("Bucket"=>$bucket, "Key"=>$keyprefix."EOFileCopy.instruction")); |
|
| 111 | 111 | |
| 112 | 112 | $copyReq = array( |
| 113 | 113 | "Bucket"=>$bucket, |
@@ -119,30 +119,30 @@ discard block |
||
| 119 | 119 | ); |
| 120 | 120 | $client->copyObject($copyReq); |
| 121 | 121 | |
| 122 | - if(!$client->objectExists(array("Bucket"=>$bucket,"Key"=>$keyprefix."EOFileCopy"))) |
|
| 122 | + if (!$client->objectExists(array("Bucket"=>$bucket, "Key"=>$keyprefix."EOFileCopy"))) |
|
| 123 | 123 | throw new Exception("not found ".$keyprefix."EOFileCopy"); |
| 124 | - if(!$client->objectExists(array("Bucket"=>$bucket,"Key"=>$keyprefix."EOFileCopy.instruction"))) |
|
| 124 | + if (!$client->objectExists(array("Bucket"=>$bucket, "Key"=>$keyprefix."EOFileCopy.instruction"))) |
|
| 125 | 125 | throw new Exception("not found ".$keyprefix."EOFileCopy.instruction"); |
| 126 | 126 | |
| 127 | - $client->deleteObject(array("Bucket"=>$bucket,"Key"=>$keyprefix."EOFileCopy")); |
|
| 127 | + $client->deleteObject(array("Bucket"=>$bucket, "Key"=>$keyprefix."EOFileCopy")); |
|
| 128 | 128 | |
| 129 | - if($client->objectExists(array("Bucket"=>$bucket,"Key"=>$keyprefix."EOFileCopy"))) |
|
| 129 | + if ($client->objectExists(array("Bucket"=>$bucket, "Key"=>$keyprefix."EOFileCopy"))) |
|
| 130 | 130 | throw new Exception("found ".$keyprefix."EOFileCopy"); |
| 131 | - if($client->objectExists(array("Bucket"=>$bucket,"Key"=>$keyprefix."EOFileCopy.instruction"))) |
|
| 131 | + if ($client->objectExists(array("Bucket"=>$bucket, "Key"=>$keyprefix."EOFileCopy.instruction"))) |
|
| 132 | 132 | throw new Exception("found ".$keyprefix."EOFileCopy.instruction"); |
| 133 | 133 | } |
| 134 | -function rangeGetAndCheckMd5($client,$bucket,$key,$file,$expectedMd5){ |
|
| 135 | - $args = array("Bucket"=>$bucket,"Key"=>$key); |
|
| 134 | +function rangeGetAndCheckMd5($client, $bucket, $key, $file, $expectedMd5) { |
|
| 135 | + $args = array("Bucket"=>$bucket, "Key"=>$key); |
|
| 136 | 136 | $meta = $client->getObjectMeta($args); |
| 137 | 137 | $contentlength = $meta["ObjectMeta"]["Content-Length"]; |
| 138 | 138 | |
| 139 | 139 | $filelist = array(); |
| 140 | 140 | |
| 141 | - for($begin = 0;$begin <$contentlength;){ |
|
| 142 | - $index = rand((int)($contentlength/20),(int)($contentlength/10)); |
|
| 143 | - $range = array("start"=>$begin,"end"=>$begin+$index); |
|
| 141 | + for ($begin = 0; $begin < $contentlength;) { |
|
| 142 | + $index = rand((int)($contentlength/20), (int)($contentlength/10)); |
|
| 143 | + $range = array("start"=>$begin, "end"=>$begin+$index); |
|
| 144 | 144 | $destFile = $file.$begin."-".($begin+$index); |
| 145 | - array_push($filelist,$destFile); |
|
| 145 | + array_push($filelist, $destFile); |
|
| 146 | 146 | $begin += ($index+1); |
| 147 | 147 | $args = array( |
| 148 | 148 | "Bucket"=>$bucket, |
@@ -154,17 +154,17 @@ discard block |
||
| 154 | 154 | } |
| 155 | 155 | |
| 156 | 156 | foreach ($filelist as $key => $value) { |
| 157 | - $handle = fopen($value,"r"); |
|
| 157 | + $handle = fopen($value, "r"); |
|
| 158 | 158 | $size = filesize($value); |
| 159 | - if($size > 0){ |
|
| 160 | - $content = fread($handle,$size); |
|
| 161 | - file_put_contents($file,$content,FILE_APPEND); |
|
| 159 | + if ($size > 0) { |
|
| 160 | + $content = fread($handle, $size); |
|
| 161 | + file_put_contents($file, $content, FILE_APPEND); |
|
| 162 | 162 | } |
| 163 | 163 | fclose($handle); |
| 164 | 164 | @unlink($value); |
| 165 | 165 | } |
| 166 | 166 | $md5 = base64_encode(md5_file($file)); |
| 167 | - if($md5 != $expectedMd5) |
|
| 167 | + if ($md5 != $expectedMd5) |
|
| 168 | 168 | throw new Exception("file md5 check error expected ".$expectedMd5." ,actual ".$md5, 1); |
| 169 | 169 | @unlink($file); |
| 170 | 170 | } |
@@ -2,7 +2,7 @@ discard block |
||
| 2 | 2 | require_once "../Ks3Client.class.php"; |
| 3 | 3 | require_once "../core/Utils.class.php"; |
| 4 | 4 | |
| 5 | -$client = new Ks3Client("","","kss.ksyun.com");//!!第三个参数endpoint需要对应bucket所在region!! 详见http://ks3.ksyun.com/doc/api/index.html Region(区域)一节 |
|
| 5 | +$client = new Ks3Client("", "", "kss.ksyun.com"); //!!第三个参数endpoint需要对应bucket所在region!! 详见http://ks3.ksyun.com/doc/api/index.html Region(区域)一节 |
|
| 6 | 6 | //print_r(listBuckets($client)); |
| 7 | 7 | //print_r(deleteBucket($client)); |
| 8 | 8 | //print_r(deleteBucketCORS($client)); |
@@ -32,16 +32,16 @@ discard block |
||
| 32 | 32 | //print_r(multipartUploadWithAdpAndCallBack($client)); |
| 33 | 33 | //print_r(putAdp($client)); |
| 34 | 34 | //print_r(postObject($client)); |
| 35 | -function listBuckets($client){ |
|
| 35 | +function listBuckets($client) { |
|
| 36 | 36 | return $client->listBuckets(); |
| 37 | 37 | } |
| 38 | -function deleteBucket($client){ |
|
| 38 | +function deleteBucket($client) { |
|
| 39 | 39 | return $client->deleteBucket(array("Bucket"=>"ksc-scm")); |
| 40 | 40 | } |
| 41 | -function deleteBucketCORS($client){ |
|
| 41 | +function deleteBucketCORS($client) { |
|
| 42 | 42 | return $client->deleteBucketCORS(array("Bucket"=>"ksc-scm")); |
| 43 | 43 | } |
| 44 | -function listObjects($client){ |
|
| 44 | +function listObjects($client) { |
|
| 45 | 45 | $args = array( |
| 46 | 46 | "Bucket"=>"lijunwei.test", |
| 47 | 47 | "Options"=>array( |
@@ -53,49 +53,49 @@ discard block |
||
| 53 | 53 | ); |
| 54 | 54 | return $client->listObjects($args); |
| 55 | 55 | } |
| 56 | -function getBucketAcl($client){ |
|
| 56 | +function getBucketAcl($client) { |
|
| 57 | 57 | return $client->getBucketAcl(array("Bucket"=>"aaphp")); |
| 58 | 58 | } |
| 59 | -function getBucketCORS($client){ |
|
| 59 | +function getBucketCORS($client) { |
|
| 60 | 60 | return $client->getBucketCORS(array("Bucket"=>"ksc-scm")); |
| 61 | 61 | } |
| 62 | -function getBucketLocation($client){ |
|
| 62 | +function getBucketLocation($client) { |
|
| 63 | 63 | return $client->getBucketLocation(array("Bucket"=>"ksc-scm")); |
| 64 | 64 | } |
| 65 | -function getBucketLogging($client){ |
|
| 65 | +function getBucketLogging($client) { |
|
| 66 | 66 | return $client->getBucketLogging(array("Bucket"=>"ksc-scm")); |
| 67 | 67 | } |
| 68 | -function bucketExists($client){ |
|
| 68 | +function bucketExists($client) { |
|
| 69 | 69 | $args = array("Bucket"=>"ksc-scm"); |
| 70 | 70 | return $client->bucketExists($args); |
| 71 | 71 | } |
| 72 | -function createBucket($client){ |
|
| 72 | +function createBucket($client) { |
|
| 73 | 73 | $args = array( |
| 74 | 74 | "Bucket"=>"ksc-scm", |
| 75 | 75 | "ACL"=>"private" |
| 76 | 76 | ); |
| 77 | 77 | return $client->createBucket($args); |
| 78 | 78 | } |
| 79 | -function setBucketAcl($client){ |
|
| 79 | +function setBucketAcl($client) { |
|
| 80 | 80 | $args = array( |
| 81 | 81 | "Bucket"=>"ksc-scm", |
| 82 | 82 | "ACL"=>"private" |
| 83 | 83 | ); |
| 84 | 84 | return $client->setBucketAcl($args); |
| 85 | 85 | } |
| 86 | -function setBucketCORS($client){ |
|
| 86 | +function setBucketCORS($client) { |
|
| 87 | 87 | $args = array( |
| 88 | 88 | "Bucket"=>"ksc-scm", |
| 89 | 89 | "CORS"=>array( |
| 90 | 90 | array( |
| 91 | - "AllowedMethod"=>array("GET","PUT"), |
|
| 91 | + "AllowedMethod"=>array("GET", "PUT"), |
|
| 92 | 92 | "AllowedOrigin"=>array("http://www.kingsoft.com"), |
| 93 | 93 | "AllowedHeader"=>array("*"), |
| 94 | 94 | "ExposeHeader"=>array("*"), |
| 95 | 95 | "MaxAgeSeconds"=>10 |
| 96 | 96 | ), |
| 97 | 97 | array( |
| 98 | - "AllowedMethod"=>array("GET","PUT"), |
|
| 98 | + "AllowedMethod"=>array("GET", "PUT"), |
|
| 99 | 99 | "AllowedOrigin"=>array("*"), |
| 100 | 100 | "AllowedHeader"=>array("*"), |
| 101 | 101 | "ExposeHeader"=>array("*"), |
@@ -105,7 +105,7 @@ discard block |
||
| 105 | 105 | ); |
| 106 | 106 | return $client->setBucketCORS($args); |
| 107 | 107 | } |
| 108 | -function setBucketLogging($client){ |
|
| 108 | +function setBucketLogging($client) { |
|
| 109 | 109 | $args = array( |
| 110 | 110 | "Bucket"=>"ksc-scm", |
| 111 | 111 | "BucketLogging"=>array( |
@@ -116,21 +116,21 @@ discard block |
||
| 116 | 116 | ); |
| 117 | 117 | return $client->setBucketLogging($args); |
| 118 | 118 | } |
| 119 | -function deleteObject($client){ |
|
| 119 | +function deleteObject($client) { |
|
| 120 | 120 | $args = array( |
| 121 | 121 | "Bucket"=>"ksc-scm", |
| 122 | 122 | "Key"=>"123.pdf" |
| 123 | 123 | ); |
| 124 | 124 | return $client->deleteObject($args); |
| 125 | 125 | } |
| 126 | -function deleteObjects($client){ |
|
| 126 | +function deleteObjects($client) { |
|
| 127 | 127 | $args = array( |
| 128 | 128 | "Bucket"=>"ksc-scm", |
| 129 | - "DeleteKeys"=>array("copy/test.zip","copy/123.doc") |
|
| 129 | + "DeleteKeys"=>array("copy/test.zip", "copy/123.doc") |
|
| 130 | 130 | ); |
| 131 | 131 | return $client->deleteObjects($args); |
| 132 | 132 | } |
| 133 | -function getObject($client){ |
|
| 133 | +function getObject($client) { |
|
| 134 | 134 | $args = array( |
| 135 | 135 | "Bucket"=>"aaphp", |
| 136 | 136 | "Key"=>"multi.exe", |
@@ -142,28 +142,28 @@ discard block |
||
| 142 | 142 | ); |
| 143 | 143 | return $client->getObject($args); |
| 144 | 144 | } |
| 145 | -function getObjectAcl($client){ |
|
| 145 | +function getObjectAcl($client) { |
|
| 146 | 146 | $args = array( |
| 147 | 147 | "Bucket"=>"aaphp", |
| 148 | 148 | "Key"=>"multi.exe" |
| 149 | 149 | ); |
| 150 | 150 | return $client->getObjectAcl($args); |
| 151 | 151 | } |
| 152 | -function objectExists($client){ |
|
| 152 | +function objectExists($client) { |
|
| 153 | 153 | $args = array( |
| 154 | 154 | "Bucket"=>"ksc-scm", |
| 155 | 155 | "Key"=>"123.pdf" |
| 156 | 156 | ); |
| 157 | 157 | return $client->objectExists($args); |
| 158 | 158 | } |
| 159 | -function getObjectMeta($client){ |
|
| 159 | +function getObjectMeta($client) { |
|
| 160 | 160 | $args = array( |
| 161 | 161 | "Bucket"=>"aaphp", |
| 162 | 162 | "Key"=>"test.zip" |
| 163 | 163 | ); |
| 164 | 164 | return $client->getObjectMeta($args); |
| 165 | 165 | } |
| 166 | -function setObjectAcl($client){ |
|
| 166 | +function setObjectAcl($client) { |
|
| 167 | 167 | $args = array( |
| 168 | 168 | "Bucket"=>"aaphp", |
| 169 | 169 | "Key"=>"test.zip", |
@@ -171,7 +171,7 @@ discard block |
||
| 171 | 171 | ); |
| 172 | 172 | return $client->setObjectAcl($args); |
| 173 | 173 | } |
| 174 | -function copyObject($client){ |
|
| 174 | +function copyObject($client) { |
|
| 175 | 175 | $args = array( |
| 176 | 176 | "Bucket"=>"aaphp", |
| 177 | 177 | "Key"=>"copy/test.zip", |
@@ -182,10 +182,10 @@ discard block |
||
| 182 | 182 | ); |
| 183 | 183 | return $client->copyObject($args); |
| 184 | 184 | } |
| 185 | -function putObjectByFile($client){ |
|
| 185 | +function putObjectByFile($client) { |
|
| 186 | 186 | $file = "D://phpput"; |
| 187 | - if(Utils::chk_chinese($file)){ |
|
| 188 | - $file = iconv('utf-8','gbk',$file); |
|
| 187 | + if (Utils::chk_chinese($file)) { |
|
| 188 | + $file = iconv('utf-8', 'gbk', $file); |
|
| 189 | 189 | } |
| 190 | 190 | $content = $file; |
| 191 | 191 | $args = array( |
@@ -193,7 +193,7 @@ discard block |
||
| 193 | 193 | "Key"=>"stream_upload1.txt", |
| 194 | 194 | "ACL"=>"public-read", |
| 195 | 195 | "ObjectMeta"=>array( |
| 196 | - "Content-Type"=>"image/jpg",//只传0-10字节, |
|
| 196 | + "Content-Type"=>"image/jpg", //只传0-10字节, |
|
| 197 | 197 | ), |
| 198 | 198 | "Content"=>array( |
| 199 | 199 | "content"=>$file, |
@@ -202,7 +202,7 @@ discard block |
||
| 202 | 202 | ); |
| 203 | 203 | return $client->putObjectByFile($args); |
| 204 | 204 | } |
| 205 | -function multipartUpload($client){ |
|
| 205 | +function multipartUpload($client) { |
|
| 206 | 206 | $args = array( |
| 207 | 207 | "Bucket"=>"aaphp", |
| 208 | 208 | "Key"=>"multi.zip", |
@@ -220,16 +220,16 @@ discard block |
||
| 220 | 220 | //开始上传 |
| 221 | 221 | |
| 222 | 222 | $file = "D://新建文件夹.rar"; |
| 223 | - if(Utils::chk_chinese($file)){ |
|
| 224 | - $file = iconv('utf-8','gbk',$file); |
|
| 223 | + if (Utils::chk_chinese($file)) { |
|
| 224 | + $file = iconv('utf-8', 'gbk', $file); |
|
| 225 | 225 | } |
| 226 | 226 | $total = Utils::getFileSize($file); |
| 227 | 227 | $partsize = 1024*1024*5; |
| 228 | 228 | $count = (int)(($total-1)/$partsize)+1; |
| 229 | 229 | echo $count."\r\n"; |
| 230 | - for($i = 0;$i < $count;$i++){ |
|
| 230 | + for ($i = 0; $i < $count; $i++) { |
|
| 231 | 231 | echo "upload".$i."\r\n"; |
| 232 | - $args=array( |
|
| 232 | + $args = array( |
|
| 233 | 233 | "Bucket"=>"aaphp", |
| 234 | 234 | "Key"=>"multi.zip", |
| 235 | 235 | "Options"=>array( |
@@ -248,10 +248,10 @@ discard block |
||
| 248 | 248 | print_r($etag); |
| 249 | 249 | $etag = $etag["ETag"]; |
| 250 | 250 | } |
| 251 | - $parts = $client->listParts(array("Bucket"=>"aaphp","Key"=>"multi.zip","Options"=>array("uploadId"=>$uploadid))); |
|
| 251 | + $parts = $client->listParts(array("Bucket"=>"aaphp", "Key"=>"multi.zip", "Options"=>array("uploadId"=>$uploadid))); |
|
| 252 | 252 | print_r($parts); |
| 253 | 253 | //结束上传 |
| 254 | - $args=array( |
|
| 254 | + $args = array( |
|
| 255 | 255 | "Bucket"=>"aaphp", |
| 256 | 256 | "Key"=>"multi.zip", |
| 257 | 257 | "Options"=>array("uploadId"=>$uploadid), |
@@ -260,16 +260,16 @@ discard block |
||
| 260 | 260 | $result = $client->completeMultipartUpload($args); |
| 261 | 261 | print_r($result); |
| 262 | 262 | } |
| 263 | -function abortMultipartUpload($client){ |
|
| 264 | - $args=array( |
|
| 263 | +function abortMultipartUpload($client) { |
|
| 264 | + $args = array( |
|
| 265 | 265 | "Bucket"=>"aaphp", |
| 266 | 266 | "Key"=>"multi.zip", |
| 267 | 267 | "Options"=>array("uploadId"=>"1234") |
| 268 | 268 | ); |
| 269 | 269 | return $client->abortMultipartUpload($args); |
| 270 | 270 | } |
| 271 | -function generatePresignedUrl($client){ |
|
| 272 | - $args=array( |
|
| 271 | +function generatePresignedUrl($client) { |
|
| 272 | + $args = array( |
|
| 273 | 273 | "Bucket"=>"aaphp", |
| 274 | 274 | "Key"=>"multi.zip", |
| 275 | 275 | "Options"=>array( |
@@ -279,7 +279,7 @@ discard block |
||
| 279 | 279 | ); |
| 280 | 280 | return $client->generatePresignedUrl($args); |
| 281 | 281 | } |
| 282 | -function putObjectWithAdpAndCallBack($client){ |
|
| 282 | +function putObjectWithAdpAndCallBack($client) { |
|
| 283 | 283 | $content = "D://野生动物.3gp"; |
| 284 | 284 | $args = array( |
| 285 | 285 | "Bucket"=>"aaphp", |
@@ -299,13 +299,13 @@ discard block |
||
| 299 | 299 | ), |
| 300 | 300 | "CallBack"=>array( |
| 301 | 301 | "Url"=>"http://10.4.2.38:19090/", |
| 302 | - "BodyMagicVariables"=>array("bucket"=>"bucket","key"=>"key"), |
|
| 302 | + "BodyMagicVariables"=>array("bucket"=>"bucket", "key"=>"key"), |
|
| 303 | 303 | "BodyVariables"=>array("name"=>"lijunwei") |
| 304 | 304 | ) |
| 305 | 305 | ); |
| 306 | 306 | return $client->putObjectByFile($args); |
| 307 | 307 | } |
| 308 | -function multipartUploadWithAdpAndCallBack($client){ |
|
| 308 | +function multipartUploadWithAdpAndCallBack($client) { |
|
| 309 | 309 | $args = array( |
| 310 | 310 | "Bucket"=>"aaphp", |
| 311 | 311 | "Key"=>"multi.zip", |
@@ -323,16 +323,16 @@ discard block |
||
| 323 | 323 | //开始上传 |
| 324 | 324 | |
| 325 | 325 | $file = "D://野生动物.3gp"; |
| 326 | - if(Utils::chk_chinese($file)){ |
|
| 327 | - $file = iconv('utf-8','gbk',$file); |
|
| 326 | + if (Utils::chk_chinese($file)) { |
|
| 327 | + $file = iconv('utf-8', 'gbk', $file); |
|
| 328 | 328 | } |
| 329 | 329 | $partsize = 1024*1024*5; |
| 330 | 330 | $total = Utils::getFileSize($file); |
| 331 | 331 | $count = (int)(($total-1)/$partsize)+1; |
| 332 | 332 | echo $count."\r\n"; |
| 333 | - for($i = 0;$i < $count;$i++){ |
|
| 333 | + for ($i = 0; $i < $count; $i++) { |
|
| 334 | 334 | echo "upload".$i."\r\n"; |
| 335 | - $args=array( |
|
| 335 | + $args = array( |
|
| 336 | 336 | "Bucket"=>"aaphp", |
| 337 | 337 | "Key"=>"multi.zip", |
| 338 | 338 | "Options"=>array( |
@@ -351,10 +351,10 @@ discard block |
||
| 351 | 351 | print_r($etag); |
| 352 | 352 | $etag = $etag["ETag"]; |
| 353 | 353 | } |
| 354 | - $parts = $client->listParts(array("Bucket"=>"aaphp","Key"=>"multi.zip","Options"=>array("uploadId"=>$uploadid))); |
|
| 354 | + $parts = $client->listParts(array("Bucket"=>"aaphp", "Key"=>"multi.zip", "Options"=>array("uploadId"=>$uploadid))); |
|
| 355 | 355 | print_r($parts); |
| 356 | 356 | //结束上传 |
| 357 | - $args=array( |
|
| 357 | + $args = array( |
|
| 358 | 358 | "Bucket"=>"aaphp", |
| 359 | 359 | "Key"=>"multi.zip", |
| 360 | 360 | "Options"=>array("uploadId"=>$uploadid), |
@@ -370,7 +370,7 @@ discard block |
||
| 370 | 370 | ), |
| 371 | 371 | "CallBack"=>array( |
| 372 | 372 | "Url"=>"http://10.4.2.38:19090/", |
| 373 | - "BodyMagicVariables"=>array("bucket"=>"bucket","key"=>"key"), |
|
| 373 | + "BodyMagicVariables"=>array("bucket"=>"bucket", "key"=>"key"), |
|
| 374 | 374 | "BodyVariables"=>array("name"=>"lijunwei") |
| 375 | 375 | ) |
| 376 | 376 | ); |
@@ -380,8 +380,8 @@ discard block |
||
| 380 | 380 | $task = $client->getAdp(array("TaskID"=>$taskid)); |
| 381 | 381 | print_r($task); |
| 382 | 382 | } |
| 383 | -function putAdp($client){ |
|
| 384 | - $args=array( |
|
| 383 | +function putAdp($client) { |
|
| 384 | + $args = array( |
|
| 385 | 385 | "Bucket"=>"aaphp", |
| 386 | 386 | "Key"=>"multi.zip", |
| 387 | 387 | "Adp"=>array( |
@@ -400,14 +400,14 @@ discard block |
||
| 400 | 400 | $task = $client->getAdp(array("TaskID"=>$taskid)); |
| 401 | 401 | print_r($task); |
| 402 | 402 | } |
| 403 | -function postObject($client){ |
|
| 403 | +function postObject($client) { |
|
| 404 | 404 | |
| 405 | 405 | $postData = array( |
| 406 | 406 | "key"=>"~!@\\#$\%^&*()_+-=qw", |
| 407 | 407 | "acl"=>"public-read" |
| 408 | 408 | ); |
| 409 | - $unKnowData=array("122","334"); |
|
| 409 | + $unKnowData = array("122", "334"); |
|
| 410 | 410 | |
| 411 | - print_r($client->postObject("ksc-scm",$postData,$unKnowData)); |
|
| 411 | + print_r($client->postObject("ksc-scm", $postData, $unKnowData)); |
|
| 412 | 412 | } |
| 413 | 413 | ?> |
@@ -1,7 +1,7 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -class EncryptionUtil{ |
|
| 2 | +class EncryptionUtil { |
|
| 3 | 3 | public static $INSTRUCTION_SUFFIX = ".instruction"; |
| 4 | - public static function genereateOnceUsedKey($length=32){ |
|
| 4 | + public static function genereateOnceUsedKey($length = 32) { |
|
| 5 | 5 | $randpwd = ""; |
| 6 | 6 | for ($i = 0; $i < $length; $i++) |
| 7 | 7 | { |
@@ -9,24 +9,24 @@ discard block |
||
| 9 | 9 | } |
| 10 | 10 | return $randpwd; |
| 11 | 11 | } |
| 12 | - public static function encode_AES_ECB($data,$secret_key){ |
|
| 13 | - $td = mcrypt_module_open(MCRYPT_RIJNDAEL_128,'',MCRYPT_MODE_ECB,''); |
|
| 12 | + public static function encode_AES_ECB($data, $secret_key) { |
|
| 13 | + $td = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', MCRYPT_MODE_ECB, ''); |
|
| 14 | 14 | |
| 15 | - $blocksize = mcrypt_get_block_size(MCRYPT_RIJNDAEL_128,MCRYPT_MODE_ECB); |
|
| 16 | - $pad = $blocksize - (strlen($data) % $blocksize); |
|
| 17 | - $data = $data . str_repeat(chr($pad), $pad); |
|
| 15 | + $blocksize = mcrypt_get_block_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_ECB); |
|
| 16 | + $pad = $blocksize-(strlen($data)%$blocksize); |
|
| 17 | + $data = $data.str_repeat(chr($pad), $pad); |
|
| 18 | 18 | |
| 19 | - $iv = mcrypt_create_iv (mcrypt_enc_get_iv_size($td), MCRYPT_RAND); |
|
| 20 | - mcrypt_generic_init($td,$secret_key,$iv); |
|
| 21 | - $encrypted = mcrypt_generic($td,$data); |
|
| 19 | + $iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($td), MCRYPT_RAND); |
|
| 20 | + mcrypt_generic_init($td, $secret_key, $iv); |
|
| 21 | + $encrypted = mcrypt_generic($td, $data); |
|
| 22 | 22 | mcrypt_generic_deinit($td); |
| 23 | 23 | return $encrypted; |
| 24 | 24 | } |
| 25 | - public static function decode_AES_ECB($data,$secret_key){ |
|
| 26 | - $td = mcrypt_module_open(MCRYPT_RIJNDAEL_128,'',MCRYPT_MODE_ECB,''); |
|
| 27 | - $iv = mcrypt_create_iv (mcrypt_enc_get_iv_size($td), MCRYPT_RAND); |
|
| 28 | - mcrypt_generic_init($td,$secret_key,$iv); |
|
| 29 | - $data = mdecrypt_generic($td,$data); |
|
| 25 | + public static function decode_AES_ECB($data, $secret_key) { |
|
| 26 | + $td = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', MCRYPT_MODE_ECB, ''); |
|
| 27 | + $iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($td), MCRYPT_RAND); |
|
| 28 | + mcrypt_generic_init($td, $secret_key, $iv); |
|
| 29 | + $data = mdecrypt_generic($td, $data); |
|
| 30 | 30 | mcrypt_generic_deinit($td); |
| 31 | 31 | mcrypt_module_close($td); |
| 32 | 32 | |
@@ -36,155 +36,155 @@ discard block |
||
| 36 | 36 | |
| 37 | 37 | return trim($data); |
| 38 | 38 | } |
| 39 | - public static function getKeyEncryptionAlgm($encryptionMaterials){ |
|
| 40 | - if(is_array($encryptionMaterials)){ |
|
| 39 | + public static function getKeyEncryptionAlgm($encryptionMaterials) { |
|
| 40 | + if (is_array($encryptionMaterials)) { |
|
| 41 | 41 | return "RSA"; |
| 42 | - }else{ |
|
| 42 | + }else { |
|
| 43 | 43 | return "AES"; |
| 44 | 44 | } |
| 45 | 45 | } |
| 46 | - public static function getAdjustedRange($range,$blocksize){ |
|
| 46 | + public static function getAdjustedRange($range, $blocksize) { |
|
| 47 | 47 | $a = $range["start"]; |
| 48 | 48 | $b = $range["end"]; |
| 49 | - $a = $a - ($a%$blocksize)-$blocksize; |
|
| 50 | - if($a < 0) |
|
| 49 | + $a = $a-($a%$blocksize)-$blocksize; |
|
| 50 | + if ($a < 0) |
|
| 51 | 51 | $a = 0; |
| 52 | 52 | |
| 53 | 53 | $b = $b+$blocksize-$b%$blocksize+$blocksize; |
| 54 | 54 | |
| 55 | - return array("start"=>$a,"end"=>$b); |
|
| 55 | + return array("start"=>$a, "end"=>$b); |
|
| 56 | 56 | } |
| 57 | - public static function encodeCek($encryptionMaterials,$cek){ |
|
| 57 | + public static function encodeCek($encryptionMaterials, $cek) { |
|
| 58 | 58 | $encrypKeyAlg = EncryptionUtil::getKeyEncryptionAlgm($encryptionMaterials); |
| 59 | - if($encrypKeyAlg === "AES"){ |
|
| 59 | + if ($encrypKeyAlg === "AES") { |
|
| 60 | 60 | $secretKey = $encryptionMaterials; |
| 61 | - $encryptedSek = EncryptionUtil::encode_AES_ECB($cek,$secretKey); |
|
| 62 | - if(empty($encryptedSek)) |
|
| 61 | + $encryptedSek = EncryptionUtil::encode_AES_ECB($cek, $secretKey); |
|
| 62 | + if (empty($encryptedSek)) |
|
| 63 | 63 | throw new Ks3ClientException("can not encode cek useing AES"); |
| 64 | - }else if($encrypKeyAlg === "RSA"){ |
|
| 64 | + }else if ($encrypKeyAlg === "RSA") { |
|
| 65 | 65 | $encryptedSek = ""; |
| 66 | - openssl_public_encrypt($cek,$encryptedSek, $encryptionMaterials[0]); |
|
| 67 | - if(empty($encryptedSek)) |
|
| 66 | + openssl_public_encrypt($cek, $encryptedSek, $encryptionMaterials[0]); |
|
| 67 | + if (empty($encryptedSek)) |
|
| 68 | 68 | throw new Ks3ClientException("can not encode cek useing RSA"); |
| 69 | 69 | } |
| 70 | 70 | return $encryptedSek; |
| 71 | 71 | } |
| 72 | - public static function decodeCek($encryptionMaterials,$cekEncrypted){ |
|
| 72 | + public static function decodeCek($encryptionMaterials, $cekEncrypted) { |
|
| 73 | 73 | $encrypKeyAlg = EncryptionUtil::getKeyEncryptionAlgm($encryptionMaterials); |
| 74 | - if($encrypKeyAlg === "AES"){ |
|
| 74 | + if ($encrypKeyAlg === "AES") { |
|
| 75 | 75 | $secretKey = $encryptionMaterials; |
| 76 | - $cek = EncryptionUtil::decode_AES_ECB($cekEncrypted,$secretKey); |
|
| 77 | - if(empty($cek)) |
|
| 76 | + $cek = EncryptionUtil::decode_AES_ECB($cekEncrypted, $secretKey); |
|
| 77 | + if (empty($cek)) |
|
| 78 | 78 | throw new Ks3ClientException("can not decode cek useing AES,secret key maybe not correct"); |
| 79 | - }else if($encrypKeyAlg === "RSA"){ |
|
| 79 | + }else if ($encrypKeyAlg === "RSA") { |
|
| 80 | 80 | $cek = ""; |
| 81 | - openssl_private_decrypt($cekEncrypted,$cek, $encryptionMaterials[1]); |
|
| 82 | - if(empty($cek)) |
|
| 81 | + openssl_private_decrypt($cekEncrypted, $cek, $encryptionMaterials[1]); |
|
| 82 | + if (empty($cek)) |
|
| 83 | 83 | throw new Ks3ClientException("can not decode cek useing RSA,public/private key pair maybe not correct"); |
| 84 | 84 | } |
| 85 | 85 | return $cek; |
| 86 | 86 | } |
| 87 | - public static function getPKCS5EncrypedLength($length,$blocksize){ |
|
| 88 | - $pad = $blocksize - $length%$blocksize; |
|
| 87 | + public static function getPKCS5EncrypedLength($length, $blocksize) { |
|
| 88 | + $pad = $blocksize-$length%$blocksize; |
|
| 89 | 89 | return $length+$pad; |
| 90 | 90 | } |
| 91 | 91 | //pkcs5填充 |
| 92 | - public static function PKCS5Padding($data,$blocksize){ |
|
| 93 | - $pad = $blocksize - strlen($data)%$blocksize; |
|
| 94 | - for($i = 0;$i < $pad;$i++){ |
|
| 95 | - $data.= chr($pad); |
|
| 92 | + public static function PKCS5Padding($data, $blocksize) { |
|
| 93 | + $pad = $blocksize-strlen($data)%$blocksize; |
|
| 94 | + for ($i = 0; $i < $pad; $i++) { |
|
| 95 | + $data .= chr($pad); |
|
| 96 | 96 | } |
| 97 | 97 | return $data; |
| 98 | 98 | } |
| 99 | - public static function updateContentMD5Header($req){ |
|
| 100 | - if(!is_array($req)) |
|
| 99 | + public static function updateContentMD5Header($req) { |
|
| 100 | + if (!is_array($req)) |
|
| 101 | 101 | return $req; |
| 102 | - if(isset($req["ObjectMeta"])){ |
|
| 102 | + if (isset($req["ObjectMeta"])) { |
|
| 103 | 103 | $meta = $req["ObjectMeta"]; |
| 104 | - }else{ |
|
| 104 | + }else { |
|
| 105 | 105 | return $req; |
| 106 | 106 | } |
| 107 | - if(is_array($meta) && isset($meta["Content-MD5"])){ |
|
| 107 | + if (is_array($meta) && isset($meta["Content-MD5"])) { |
|
| 108 | 108 | $md5 = $meta["Content-MD5"]; |
| 109 | - }else{ |
|
| 109 | + }else { |
|
| 110 | 110 | return $req; |
| 111 | 111 | } |
| 112 | - if(empty($md5)){ |
|
| 112 | + if (empty($md5)) { |
|
| 113 | 113 | return $req; |
| 114 | - }else{ |
|
| 114 | + }else { |
|
| 115 | 115 | $req["ObjectMeta"]["Content-MD5"] = NULL; |
| 116 | 116 | $req["UserMeta"]["x-kss-meta-x-kss-unencrypted-content-md5"] = $md5; |
| 117 | 117 | } |
| 118 | 118 | return $req; |
| 119 | 119 | } |
| 120 | - public static function metaTextLength($req){ |
|
| 121 | - if(!is_array($req)) |
|
| 120 | + public static function metaTextLength($req) { |
|
| 121 | + if (!is_array($req)) |
|
| 122 | 122 | return -1; |
| 123 | - if(isset($req["ObjectMeta"])){ |
|
| 123 | + if (isset($req["ObjectMeta"])) { |
|
| 124 | 124 | $meta = $req["ObjectMeta"]; |
| 125 | - }else{ |
|
| 125 | + }else { |
|
| 126 | 126 | return -1; |
| 127 | 127 | } |
| 128 | - if(is_array($meta) && isset($meta["Content-Length"])){ |
|
| 128 | + if (is_array($meta) && isset($meta["Content-Length"])) { |
|
| 129 | 129 | $length = $meta["Content-Length"]; |
| 130 | 130 | return $length; |
| 131 | 131 | }else |
| 132 | 132 | return -1; |
| 133 | 133 | } |
| 134 | - public static function plainTextLength($args){ |
|
| 135 | - if(isset($args["Content"])){ |
|
| 136 | - if(is_array($args["Content"])){ |
|
| 134 | + public static function plainTextLength($args) { |
|
| 135 | + if (isset($args["Content"])) { |
|
| 136 | + if (is_array($args["Content"])) { |
|
| 137 | 137 | $content = $args["Content"]["content"]; |
| 138 | 138 | $seek_position = 0; |
| 139 | 139 | $resourceLength = 0; |
| 140 | 140 | $length = -1; |
| 141 | 141 | $isFile = FALSE; |
| 142 | 142 | |
| 143 | - if (!is_resource($content)){ |
|
| 143 | + if (!is_resource($content)) { |
|
| 144 | 144 | $isFile = TRUE; |
| 145 | 145 | //如果之前用户已经转化为GBK则不转换 |
| 146 | - if(Utils::chk_chinese($content)&&!Utils::check_char($content)){ |
|
| 147 | - $content = iconv('utf-8','gbk',$content); |
|
| 146 | + if (Utils::chk_chinese($content) && !Utils::check_char($content)) { |
|
| 147 | + $content = iconv('utf-8', 'gbk', $content); |
|
| 148 | 148 | } |
| 149 | - if(!file_exists($content)) |
|
| 149 | + if (!file_exists($content)) |
|
| 150 | 150 | throw new Ks3ClientException("the specified file does not exist "); |
| 151 | 151 | $length = Utils::getFileSize($content); |
| 152 | - $content = fopen($content,"r"); |
|
| 153 | - }else{ |
|
| 152 | + $content = fopen($content, "r"); |
|
| 153 | + }else { |
|
| 154 | 154 | $stats = fstat($content); |
| 155 | - if ($stats && $stats["size"] >= 0){ |
|
| 155 | + if ($stats && $stats["size"] >= 0) { |
|
| 156 | 156 | $length = $stats["size"]; |
| 157 | 157 | } |
| 158 | 158 | } |
| 159 | 159 | $resourceLength = $length; |
| 160 | 160 | //优先取用户设置seek_position,没有的话取ftell |
| 161 | - if(isset($args["Content"]["seek_position"])&&$args["Content"]["seek_position"]>0){ |
|
| 161 | + if (isset($args["Content"]["seek_position"]) && $args["Content"]["seek_position"] > 0) { |
|
| 162 | 162 | $seek_position = $args["Content"]["seek_position"]; |
| 163 | - }else if(!$isFile){ |
|
| 163 | + }else if (!$isFile) { |
|
| 164 | 164 | $seek_position = ftell($content); |
| 165 | - if($seek_position<0) |
|
| 165 | + if ($seek_position < 0) |
|
| 166 | 166 | $seek_position = 0; |
| 167 | - fseek($content,0); |
|
| 167 | + fseek($content, 0); |
|
| 168 | 168 | } |
| 169 | 169 | |
| 170 | 170 | $lengthInMeta = -1; |
| 171 | - if(isset($args["ObjectMeta"]["Content-Length"])){ |
|
| 171 | + if (isset($args["ObjectMeta"]["Content-Length"])) { |
|
| 172 | 172 | $lengthInMeta = $args["ObjectMeta"]["Content-Length"]; |
| 173 | 173 | } |
| 174 | - if($lengthInMeta > 0){ |
|
| 174 | + if ($lengthInMeta > 0) { |
|
| 175 | 175 | $length = $lengthInMeta; |
| 176 | - }else if($resourceLength > 0){ |
|
| 176 | + }else if ($resourceLength > 0) { |
|
| 177 | 177 | //根据seek_position计算实际长度 |
| 178 | - $length = $resourceLength - $seek_position; |
|
| 178 | + $length = $resourceLength-$seek_position; |
|
| 179 | 179 | } |
| 180 | - if($length <= 0) |
|
| 180 | + if ($length <= 0) |
|
| 181 | 181 | throw new Ks3ClientException("calculate content length failed,unexpected contetn length ".$length); |
| 182 | 182 | return $length; |
| 183 | - }else{ |
|
| 183 | + }else { |
|
| 184 | 184 | $content = $args["Content"]; |
| 185 | 185 | $lengthInMeta = EncryptionUtil::metaTextLength($args); |
| 186 | 186 | $length = strlen($content); |
| 187 | - if($length<$lengthInMeta||$lengthInMeta <= 0) |
|
| 187 | + if ($length < $lengthInMeta || $lengthInMeta <= 0) |
|
| 188 | 188 | return $length; |
| 189 | 189 | else |
| 190 | 190 | return $lengthInMeta; |
@@ -192,14 +192,14 @@ discard block |
||
| 192 | 192 | } |
| 193 | 193 | return -1; |
| 194 | 194 | } |
| 195 | - public static function initMultipartUploadContext($initResult,$iv,$cek,$encryptedCek,$matdesc="{}"){ |
|
| 195 | + public static function initMultipartUploadContext($initResult, $iv, $cek, $encryptedCek, $matdesc = "{}") { |
|
| 196 | 196 | $cacheDir = KS3_API_PATH.DIRECTORY_SEPARATOR."cache".DIRECTORY_SEPARATOR; |
| 197 | 197 | $encryptionDir = KS3_API_PATH.DIRECTORY_SEPARATOR."cache".DIRECTORY_SEPARATOR."encryption".DIRECTORY_SEPARATOR; |
| 198 | - if(!is_dir($cacheDir)) |
|
| 198 | + if (!is_dir($cacheDir)) |
|
| 199 | 199 | mkdir($cacheDir); |
| 200 | - if(!is_dir($encryptionDir)) |
|
| 200 | + if (!is_dir($encryptionDir)) |
|
| 201 | 201 | mkdir($encryptionDir); |
| 202 | - if(is_array($matdesc)){ |
|
| 202 | + if (is_array($matdesc)) { |
|
| 203 | 203 | $matdesc = json_encode($matdesc); |
| 204 | 204 | } |
| 205 | 205 | $initResult["firstIv"] = base64_encode($iv); |
@@ -213,7 +213,7 @@ discard block |
||
| 213 | 213 | fwrite($file, $json); |
| 214 | 214 | fclose($file); |
| 215 | 215 | } |
| 216 | - public static function updateMultipartUploadContext($UploadId,$iv,$lastPart = FALSE){ |
|
| 216 | + public static function updateMultipartUploadContext($UploadId, $iv, $lastPart = FALSE) { |
|
| 217 | 217 | $encryptionDir = KS3_API_PATH.DIRECTORY_SEPARATOR."cache".DIRECTORY_SEPARATOR."encryption".DIRECTORY_SEPARATOR; |
| 218 | 218 | $content = EncryptionUtil::getMultipartUploadContext($UploadId); |
| 219 | 219 | $content["nextIv"] = base64_encode($iv); |
@@ -223,32 +223,32 @@ discard block |
||
| 223 | 223 | fwrite($file, $json); |
| 224 | 224 | fclose($file); |
| 225 | 225 | } |
| 226 | - public static function getMultipartUploadContext($UploadId){ |
|
| 226 | + public static function getMultipartUploadContext($UploadId) { |
|
| 227 | 227 | $encryptionDir = KS3_API_PATH.DIRECTORY_SEPARATOR."cache".DIRECTORY_SEPARATOR."encryption".DIRECTORY_SEPARATOR; |
| 228 | - if(!EncryptionUtil::multipartUploadContextExists($UploadId)) |
|
| 228 | + if (!EncryptionUtil::multipartUploadContextExists($UploadId)) |
|
| 229 | 229 | throw new Ks3ClientException("can not found multipart upload context in cache dir"); |
| 230 | 230 | $jsonString = file_get_contents($encryptionDir.$UploadId); |
| 231 | - $arry = json_decode($jsonString,TRUE); |
|
| 231 | + $arry = json_decode($jsonString, TRUE); |
|
| 232 | 232 | return $arry; |
| 233 | 233 | } |
| 234 | - public static function deleteMultipartUploadContext($UploadId){ |
|
| 234 | + public static function deleteMultipartUploadContext($UploadId) { |
|
| 235 | 235 | $encryptionDir = KS3_API_PATH.DIRECTORY_SEPARATOR."cache".DIRECTORY_SEPARATOR."encryption".DIRECTORY_SEPARATOR; |
| 236 | 236 | @unlink($encryptionDir.$UploadId); |
| 237 | 237 | } |
| 238 | - public static function multipartUploadContextExists($UploadId){ |
|
| 238 | + public static function multipartUploadContextExists($UploadId) { |
|
| 239 | 239 | $encryptionDir = KS3_API_PATH.DIRECTORY_SEPARATOR."cache".DIRECTORY_SEPARATOR."encryption".DIRECTORY_SEPARATOR; |
| 240 | 240 | return file_exists($encryptionDir.$UploadId); |
| 241 | 241 | } |
| 242 | - public static function openfile($path,$mode){ |
|
| 242 | + public static function openfile($path, $mode) { |
|
| 243 | 243 | $file = fopen($path, $mode); |
| 244 | - if($file) |
|
| 244 | + if ($file) |
|
| 245 | 245 | return $file; |
| 246 | 246 | else |
| 247 | 247 | throw new Ks3ClientException("open file ".$path." error"); |
| 248 | 248 | } |
| 249 | 249 | //matdesc为字符串或array数据类型。 |
| 250 | - public static function createInstructionFile($bucket,$key,$cek,$iv,$matdesc="{}"){ |
|
| 251 | - if(is_array($matdesc)){ |
|
| 250 | + public static function createInstructionFile($bucket, $key, $cek, $iv, $matdesc = "{}") { |
|
| 251 | + if (is_array($matdesc)) { |
|
| 252 | 252 | $matdesc = json_encode($matdesc); |
| 253 | 253 | } |
| 254 | 254 | $key = $key.EncryptionUtil::$INSTRUCTION_SUFFIX; |
@@ -269,9 +269,9 @@ discard block |
||
| 269 | 269 | ); |
| 270 | 270 | return $req; |
| 271 | 271 | } |
| 272 | - public static function isInstructionFile($s3Object){ |
|
| 272 | + public static function isInstructionFile($s3Object) { |
|
| 273 | 273 | $meta = $s3Object["Meta"]; |
| 274 | - if(isset($meta["UserMeta"]["x-kss-meta-x-kss-crypto-instr-file"])) |
|
| 274 | + if (isset($meta["UserMeta"]["x-kss-meta-x-kss-crypto-instr-file"])) |
|
| 275 | 275 | return TRUE; |
| 276 | 276 | return FALSE; |
| 277 | 277 | } |