-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.php
451 lines (343 loc) · 13.3 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
<?php
use cAc\GcsWrapper, Google\Cloud\ServiceBuilder;
$b = '';
$p = '';
$a = '';
$result = null;
$ops = array(
1 => 'Generate Object Only',
2 => 'Add ACL Entity to Bucket',
3 => 'Remove ACL Entity from Bucket',
4 => 'Get ACL Roles for Entity from Bucket',
5 => 'Update ACL Entity Role for Bucket',
6 => 'Upload File to Bucket',
7 => 'Upload Large (>5MB) File to Bucket',
8 => 'Combine 2 Files in Bucket',
9 => 'Get all Objects in Bucket',
10 => 'Get Bucket Info',
11 => 'Get Default ACL Roles for Objects',
12 => 'Add Default ACL Role for Objects',
13 => 'Remove Default ACL Role for Objects',
14 => 'Update Default ACL Role for Objects',
15 => 'Check if Object(s) Exists',
16 => 'Get Object(s) Info',
17 => 'Download Object(s) as File',
// 18 => 'Rename Object',
// 19 => 'Delete Object',
// 20 => 'Delete Bucket'
);
if( isset( $_POST['submit'] ) && "Submit" === $_POST['submit'] ) {
if( isset( $_POST['projectid'] ) && isset( $_POST['bucketid'] ) && isset( $_POST['jsonkey'] ) ) {
$b = $_POST['bucketid'];
$p = $_POST['projectid'];
$a = isset( $_POST['action'] ) ? intval( $_POST['action'] ) : 1;
require_once( __DIR__ . '/GcsWrapper.php' );
$storage_test = new cAc\GcsWrapper\GoogleCloudStorage( $p, $_POST['jsonkey'], $b );
switch( $a ) {
case 1:
break;
case 2:
if( isset( $_POST['aclEntityType'] ) && isset( $_POST['aclEntityValue'] ) && isset( $_POST['aclRole'] ) ) {
if ('allUsers' !== $_POST['aclEntityType'] && 'allAuthenticatedUsers' !== $_POST['aclEntityType']) {
$entity = $_POST['aclEntityType'] . $_POST['aclEntityValue'];
}
else {
$entity = $_POST['aclEntityType'];
}
$role = $_POST['aclRole'];
$result = $storage_test->bucket_acl_entity_add( $entity, $role );
}
break;
case 3:
if( isset( $_POST['aclEntityType'] ) && isset( $_POST['aclEntityValue'] ) ) {
if ('allUsers' !== $_POST['aclEntityType'] && 'allAuthenticatedUsers' !== $_POST['aclEntityType'] ) {
$entity = $_POST['aclEntityType'] . $_POST['aclEntityValue'];
}
else {
$entity = $_POST['aclEntityType'];
}
$result = $storage_test->bucket_acl_entity_remove( $entity );
}
break;
case 4:
if( isset( $_POST['aclEntityType'] ) && isset( $_POST['aclEntityValue'] ) ) {
if ('allUsers' !== $_POST['aclEntityType'] && 'allAuthenticatedUsers' !== $_POST['aclEntityType']) {
$entity = $_POST['aclEntityType'] . $_POST['aclEntityValue'];
}
else {
$entity = $_POST['aclEntityType'];
}
$result = $storage_test->bucket_acl_entity_get( $entity );
}
break;
case 5:
if( isset( $_POST['aclEntityType'] ) && isset( $_POST['aclEntityValue'] ) && isset( $_POST['aclRole'] ) ) {
if ('allUsers' !== $_POST['aclEntityType'] && 'allAuthenticatedUsers' !== $_POST['aclEntityType']) {
$entity = $_POST['aclEntityType'] . $_POST['aclEntityValue'];
}
else {
$entity = $_POST['aclEntityType'];
}
$role = $_POST['aclRole'];
$result = $storage_test->bucket_acl_entity_update( $entity, $role );
}
break;
case 6:
if( isset( $_FILES['fileUpload'] ) && isset( $_POST['predefinedAcl'] ) ) {
$target_dir = "uploads/";
$target_file = $target_dir . basename($_FILES["fileUpload"]["name"]);
$fileType = pathinfo($target_file,PATHINFO_EXTENSION);
if (move_uploaded_file($_FILES["fileUpload"]["tmp_name"], $target_file)) {
$uploadThis = fopen( $target_file, 'r' );
$result = $storage_test->bucket_upload_object( $uploadThis, $_FILES["fileUpload"]["name"], false, $permissions = $_POST['predefinedAcl'] );
}
else {
$result = "Sorry, there was an error uploading your file.
"
. print_r( $_FILES, true );
}
}
else {
$result = "Required Field(s) empty.";
}
break;
case 7:
if( isset( $_FILES['fileUpload'] ) && isset( $_POST['predefinedAcl'] ) ) {
$target_dir = "uploads/";
$target_file = $target_dir . basename($_FILES["fileUpload"]["name"]);
$fileType = pathinfo($target_file,PATHINFO_EXTENSION);
if (move_uploaded_file($_FILES["fileUpload"]["tmp_name"], $target_file)) {
$uploadThis = fopen( $target_file, 'r' );
$result = $storage_test->bucket_upload_large_object( $uploadThis, $_FILES["fileUpload"]["name"], false, $permissions = $_POST['predefinedAcl'] );
}
else {
$result = "Sorry, there was an error uploading your file.
"
. print_r( $_FILES, true );
}
}
else {
$result = "Required Field(s) empty.";
}
break;
case 8:
if( isset( $_POST['objectOne'] ) && isset( $_POST['objectTwo'] ) ) {
$object_one_exists = $storage_test->object_exists( $_POST['objectOne'] );
$object_two_exists = $storage_test->object_exists( $_POST['objectTwo'] );
if ( $object_one_exists && $object_two_exists ) {
$ext = '.' . array_pop( explode( '.', $_POST['objectTwo'] ) );
$file_name = str_replace( $ext, '', $_POST['objectOne'] ) . '_' . str_replace( $ext, '', $_POST['objectTwo'] ) . $ext;
$result = $storage_test->bucket_object_concatenate( $_POST['objectOne'], $_POST['objectTwo'], $file_name );
}
else {
$result = 'An object doesn\'t exist:
Object 1 :
' . print_r( $object_one_exists, true ) .'
Object 2 :
' . print_r( $object_two_exists, true );
}
}
break;
case 9:
$result = $storage_test->bucket_get_objects();
break;
case 10:
$result = $storage_test->bucket_get_info();
break;
case 11:
$result = $storage_test->bucket_default_acl_entity_get();
break;
case 12:
if( isset( $_POST['aclEntityType'] ) && isset( $_POST['aclEntityValue'] ) && isset( $_POST['aclRole'] ) ) {
if ('allUsers' !== $_POST['aclEntityType'] && 'allAuthenticatedUsers' !== $_POST['aclEntityType']) {
$entity = $_POST['aclEntityType'] . $_POST['aclEntityValue'];
}
else {
$entity = $_POST['aclEntityType'];
}
$role = $_POST['aclRole'];
$result = $storage_test->bucket_default_acl_entity_add( $entity, $role );
}
break;
case 13:
if( isset( $_POST['aclEntityType'] ) && isset( $_POST['aclEntityValue'] ) ) {
if ('allUsers' !== $_POST['aclEntityType'] && 'allAuthenticatedUsers' !== $_POST['aclEntityType'] ) {
$entity = $_POST['aclEntityType'] . $_POST['aclEntityValue'];
}
else {
$entity = $_POST['aclEntityType'];
}
$result = $storage_test->bucket_default_acl_entity_remove( $entity );
}
break;
case 14:
if( isset( $_POST['aclEntityType'] ) && isset( $_POST['aclEntityValue'] ) && isset( $_POST['aclRole'] ) ) {
if ('allUsers' !== $_POST['aclEntityType'] && 'allAuthenticatedUsers' !== $_POST['aclEntityType']) {
$entity = $_POST['aclEntityType'] . $_POST['aclEntityValue'];
}
else {
$entity = $_POST['aclEntityType'];
}
$role = $_POST['aclRole'];
$result = $storage_test->bucket_default_acl_entity_update( $entity, $role );
}
break;
case 15:
$result_one = '';
$result_two = '';
if( isset( $_POST['objectOne'] ) ) {
$result_one = $_POST['objectOne'] . ' exists: ' . $storage_test->object_exists( $_POST['objectOne'] );
}
if( isset( $_POST['objectTwo'] ) ) {
$result_two = $_POST['objectTwo'] . ' exists: ' . $storage_test->object_exists( $_POST['objectTwo'] );
}
if( !( isset( $_POST['objectOne'] ) ) && !( isset( $_POST['objectTwo'] ) ) ) {
$result = 'An object isn\'t set.';
}
else {
$result = $result_one . '
' . $result_two;
}
break;
case 16:
$result_one = '';
$result_two = '';
if( isset( $_POST['objectOne'] ) && $storage_test->object_exists( $_POST['objectOne'] ) {
$result_one = $_POST['objectOne'] . ' info:
' . $storage_test->object_get_info() );
}
if( isset( $_POST['objectTwo'] ) && $storage_test->object_exists( $_POST['objectTwo'] ) {
$result_two = $_POST['objectTwo'] . ' exists:
' . $storage_test->object_get_info() );
}
if( !( isset( $_POST['objectOne'] ) ) && !( isset( $_POST['objectTwo'] ) ) ) {
$result = 'No object is selected.';
}
else {
$result = $result_one . '
' . $result_two;
}
break;
case 17:
$result_one = '';
$result_two = '';
$path = '~/';
if( isset( $_POST['objectOne'] ) && $storage_test->object_exists( $_POST['objectOne'] ) {
$destination = $path . $_POST['objectOne'];
$dl_one = $this->$object->downloadToFile( $destination );
$result_one = $_POST['objectOne'] . ' downloaded to ' . $destination . ': ' . $dl_one;
}
if( isset( $_POST['objectTwo'] ) && $storage_test->object_exists( $_POST['objectTwo'] ) {
$destination = $path . $_POST['objectTwo'];
$dl_two = $this->$object->downloadToFile( $destination );
$result_two = $_POST['objectTwo'] . ' downloaded to ' . $destination . ': ' . $dl_two;
}
if( !( isset( $_POST['objectOne'] ) ) && !( isset( $_POST['objectTwo'] ) ) ) {
$result = 'No object is selected for download.';
}
else {
$result = $result_one . '
' . $result_two;
}
break;
}
}
}
?>
<!-- jQuery -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<script src="js/test.js"></script>
<header class="container">
<h1>GCS Wrapper Test</h1>
<p>Enter the Project ID, Bucket ID, and content of the json file generated by Google's IAM, then submit to get results</p>
</header>
<content class="container">
<form id="gcs-test-form" class="form-horizontal" method="post" enctype="multipart/form-data">
<fieldset>
<!-- Form Name -->
<legend>Test GCS</legend>
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" for="projectid">Project ID</label>
<div class="col-md-4">
<input id="projectid" name="projectid" type="text" placeholder="project-12345" class="form-control input-md" <?php echo empty( $p ) ? '' : 'value="' . $p . '"'?> >
<span class="help-block">enter the id, not the name</span>
</div>
</div>
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" for="bucketid">Bucket ID</label>
<div class="col-md-4">
<input id="bucketid" name="bucketid" type="text" placeholder="your-bucket-id" class="form-control input-md" <?php echo empty( $b ) ? '' : 'value="' . $b . '"'?> >
<span class="help-block">enter the unique identifier for the bucket</span>
</div>
</div>
<!-- Textarea -->
<div class="form-group">
<label class="col-md-4 control-label" for="jsonkey">JSON Key Content</label>
<div class="col-md-4">
<textarea class="form-control" id="jsonkey" name="jsonkey"><?php echo isset( $_POST['jsonkey'] ) ? $_POST['jsonkey'] : '' ?></textarea>
</div>
</div>
<!-- Select Basic -->
<div id="action-select" class="form-group">
<label class="col-md-4 control-label" for="action">Select an Operation</label>
<div class="col-md-4">
<select id="action" name="action" class="form-control">
<?php
foreach( $ops as $key=>$value ) {
$checked = '';
if( $key === $a ) {
$checked = ' selected="selected"';
}
echo '<option value="' . $key . '"' . $checked . '>' . $value . '</option>';
}
?>
</select>
</div>
</div>
<div class="form-group">
<div class="col-md-4 col-md-offset-4">
<input type="submit" class="form-control btn btn-primary" id="submit" name="submit" value="Submit"/>
</div>
</div>
</fieldset>
</form>
<div class="row">
<div id="post-values" class="col-md-6 col-md-offset-3">
<h2>Project: <?php echo $p; ?></h2>
<h2>Bucket: <?php echo $b; ?></h2>
<h2>Operation: <?php echo $ops[$a]; ?></h2>
</div>
</div>
<div class="row">
<div id="post-values" class="col-md-6 col-md-offset-3">
<h2><button class="btn btn-primary" type="button" data-toggle="collapse" data-target="#showObject" aria-expanded="false" aria-controls="collapseExample">Full Object Output</button></h2>
<p id="showObject" class="collapse"><?php print_r( $storage_test ); ?></p>
</div>
</div>
</content>
<footer class="container">
<div class="errors">
<?php
if( isset( $storage_test ) ) {
echo '<h2>Errors:</h2><pre>';
print_r( $storage_test->errors );
echo '</pre>';
}
?>
</div>
<div class="result">
<?php
if (!empty( $result ) ) {
echo '<h2>Result:</h2><pre>';
print_r( $result );
echo '</pre>';
}
?>
</div>
</footer>