forked from jlubbers08/IPFS-Bridge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.php
1647 lines (1359 loc) · 58.9 KB
/
options.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
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
use Cloutier\PhpIpfsApi\IPFSFiles;
add_action( 'admin_menu', 'ipfs_add_admin_menu' );
add_action( 'admin_init', 'ipfs_settings_init' );
//require ("IPFS.php");
global $server,$gatewayPort,$APIPort,$GateWayLink;
function ipfs_add_admin_menu( ) {
add_menu_page( 'IPFS Bridge', 'IPFS Bridge', 'manage_options', 'ipfs_generator', 'ipfs_options_page' );
// add_options_page( 'IPFS Generator', 'IPFS Generator', 'manage_options', 'ipfs_generator', 'ipfs_options_page' );
//
}
function ipfs_settings_init( ) {
register_setting( 'pluginPage', 'ipfs_settings' );
add_settings_section(
'ipfs_pluginPage_section',
__( 'Adjust your IPFS Host settings here.', 'wordpress' ),
'ipfs_settings_section_callback',
'pluginPage'
);
add_settings_field(
'ipfs_server',
__( 'Hostname / IP', 'wordpress' ),
'ipfs_text_field_0_render',
'pluginPage',
'ipfs_pluginPage_section'
);
add_settings_field(
'ipfs_gateway_port',
__( 'Gateway Port', 'wordpress' ),
'ipfs_text_field_1_render',
'pluginPage',
'ipfs_pluginPage_section'
);
add_settings_field(
'ipfs_api_port',
__( 'API Port', 'wordpress' ),
'ipfs_text_field_2_render',
'pluginPage',
'ipfs_pluginPage_section'
);
add_settings_field(
'ipfs_display_link',
__( 'Display Link', 'wordpress' ),
'ipfs_text_field_3_render',
'pluginPage',
'ipfs_pluginPage_section'
);
add_settings_field(
'ipfs_checkbox_field_0',
__( 'Enable Logging', 'wordpress' ),
'ipfs_checkbox_field_0_render',
'pluginPage',
'ipfs_pluginPage_section'
);
add_settings_field(
'ipfs_checkbox_field_1_render',
__( 'Publish to IPNS', 'wordpress' ),
'ipfs_checkbox_field_1_render',
'pluginPage',
'ipfs_pluginPage_section'
);
add_settings_field(
'ipfs_gateway',
__( 'IPFS Gateway Root:</br>ex: https://gateway.ipfs.io', 'wordpress' ),
'ipfs_text_field_gateway_render',
'pluginPage',
'ipfs_pluginPage_section'
);
add_settings_field(
'ipns_publish_expiration',
__( 'IPNS Expiration (GMT): ', 'wordpress' ),
'ipfs_text_field_ipns_publish_expiration_render',
'pluginPage',
'ipfs_pluginPage_section'
);
add_settings_field(
'ipns_key_id',
__( 'IPNS Key Id: ', 'wordpress' ),
'ipfs_text_field_ipns_key_id_render',
'pluginPage',
'ipfs_pluginPage_section'
);
add_settings_field(
'ipns_name',
__( 'IPNS Key Name: ', 'wordpress' ),
'ipfs_text_field_ipns_name_render',
'pluginPage',
'ipfs_pluginPage_section'
);
}
//$settings['ipns_name'] = 'self';
//$settings{'ipns_key_id'} = '';
//$settings['ipns_publish_expiration'] = time();
function ipfs_text_field_0_render( ) {
$options = get_option( 'ipfs_settings' );
ipfs_logEvent($options);
?>
<input type='text' name='ipfs_settings[ipfs_server]' value='<?php echo $options['ipfs_server']; ?>'>
<?php
}
function ipfs_text_field_1_render( ) {
$options = get_option( 'ipfs_settings' );
?>
<input type='text' name='ipfs_settings[ipfs_gateway_port]' value='<?php echo $options['ipfs_gateway_port']; ?>'>
<?php
}
function ipfs_text_field_2_render( ) {
$options = get_option( 'ipfs_settings' );
?>
<input type='text' name='ipfs_settings[ipfs_api_port]' value='<?php echo $options['ipfs_api_port']; ?>'>
<?php
}
function ipfs_text_field_gateway_render( ) {
$options = get_option( 'ipfs_settings' );
?>
<input type='text' name='ipfs_settings[ipfs_gateway]' value='<?php echo $options['ipfs_gateway']; ?>'>
<?php
}
function ipfs_text_field_ipns_name_render( ) {
$options = get_option( 'ipfs_settings' );
?>
<input type='text' readonly name='ipfs_settings[ipns_name]' value='<?php echo $options['ipns_name']; ?>'>
<?php
}
function ipfs_text_field_ipns_key_id_render( ) {
$options = get_option( 'ipfs_settings' );
?>
<input type='text' readonly name='ipfs_settings[ipns_key_id]' value='<?php echo $options['ipns_key_id']; ?>'>
<?php
}
function ipfs_text_field_ipns_publish_expiration_render( ) {
$options = get_option( 'ipfs_settings' );
?>
<input type='text' readonly name='ipfs_settings[ipns_publish_expiration]' value='<?php echo $options['ipns_publish_expiration']; ?>'>
<?php
}
///$settings['ipns_name'] = 'self';
//$settings{'ipns_key_id'} = '';
//$settings['ipns_publish_expiration'] = time();
function ipfs_text_field_3_render( ) {
$options = get_option( 'ipfs_settings' );
?>
<input type='text' name='ipfs_settings[ipfs_display_link]' value='<?php echo $options['ipfs_display_link']; ?>'>
<?php
}
function ipfs_checkbox_field_0_render( ) {
$options = get_option( 'ipfs_settings' );
?>
<input type='checkbox' name='ipfs_settings[ipfs_logging]' <?php checked( $options['ipfs_logging'], 1 ); ?> value='1'>
<?php
}
function ipfs_checkbox_field_1_render( ) {
$options = get_option( 'ipfs_settings' );
?>
<input type='checkbox' name='ipfs_settings[publish_ipns]' <?php checked( $options['publish_ipns'], 1 ); ?> value='1'>
<?php
}
function ipfs_settings_section_callback( ) {
echo __( 'Host settings', 'wordpress' );}
function formatBytes($bytes, $precision = 2) {
$units = array('B', 'KB', 'MB', 'GB', 'TB');
$bytes = max($bytes, 0);
$pow = floor(($bytes ? log($bytes) : 0) / log(1024));
$pow = min($pow, count($units) - 1);
// ipfs_logEvent("Power: ". $pow);
// Uncomment one of the following alternatives
// $bytes /= pow(1024, $pow);
// $bytes /= (1 << (10 * $pow));
$return = $bytes/(1000**$pow);
return round($return, $precision) . ' ' . $units[$pow];
}
function getRepoStats(){
global $server,$gatewayPort,$APIPort;
$apiUrl = "http://$server:$APIPort/api/v0/repo/stat?human=true";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $apiUrl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 240);
$output = curl_exec($ch);
$response_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$code_category = substr($response_code, 0, 1);
if ($code_category == '5' OR $code_category == '4') {
$data = @json_decode($output, true);
if (!$data AND json_last_error() != JSON_ERROR_NONE) {
// throw new Exception("IPFS returned response code $response_code: ".substr($output, 0, 200), $response_code);
}
if (is_array($data)) {
if (isset($data['Code']) AND isset($data['Message'])) {
// throw new Exception("IPFS Error {$data['Code']}: {$data['Message']}", $response_code);
}
}
}
// ipfs_logEvent("Output: " . serialize($output));
$json = json_decode($output,true);
// ipfs_logEvent($json['RepoSize']);
// ipfs_logEvent("REPO SIZE: ".formatBytes($json['RepoSize']));
// handle empty response
if ($output === false) {
//throw new Exception("IPFS Error: No Response", 1);
}
curl_close($ch);
return $json;
}
function getVersion(){
global $server,$gatewayPort,$APIPort;
$apiUrl = "http://$server:$APIPort/api/v0/version";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $apiUrl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 240);
$output = curl_exec($ch);
$response_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$code_category = substr($response_code, 0, 1);
if ($code_category == '5' OR $code_category == '4') {
$data = @json_decode($output, true);
if (!$data AND json_last_error() != JSON_ERROR_NONE) {
//throw new Exception("IPFS returned response code $response_code: ".substr($output, 0, 200), $response_code);
}
if (is_array($data)) {
if (isset($data['Code']) AND isset($data['Message'])) {
//throw new Exception("IPFS Error {$data['Code']}: {$data['Message']}", $response_code);
}
}
}
// ipfs_logEvent("Output: " . serialize($output));
$json = json_decode($output,true);
// handle empty response
if ($output === false) {
//throw new Exception("IPFS Error: No Response", 1);
}
curl_close($ch);
return $json;
}
function ipfsGet($command){
global $server,$gatewayPort,$APIPort;
$apiUrl = "http://$server:$APIPort/api/v0/$command";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $apiUrl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 240);
$output = curl_exec($ch);
$response_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$code_category = substr($response_code, 0, 1);
if ($code_category == '5' OR $code_category == '4') {
$data = @json_decode($output, true);
if (!$data AND json_last_error() != JSON_ERROR_NONE) {
// throw new Exception("IPFS returned response code $response_code: ".substr($output, 0, 200), $response_code);
}
if (is_array($data)) {
if (isset($data['Code']) AND isset($data['Message'])) {
// throw new Exception("IPFS Error {$data['Code']}: {$data['Message']}", $response_code);
}
}
}
require_once ("function.php");
// ipfs_logEvent("Output: " . serialize($output));
$json = json_decode($output,true);
// handle empty response
if ($output === false) {
// throw new Exception("IPFS Error: No Response", 1);
}
curl_close($ch);
return $json;
}
function ipfs_options_page( ) {
$protocol = ((!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') || $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://";
$siteName = $protocol . $_SERVER['HTTP_HOST']
?>
<form action='options.php' method='post'>
<h2>IPFS Bridge Settings</h2>
<?php
global $filesAdded, $ipfs_db_version;
$pagesBuilt = get_option('ipfs_build_pages');
if( isset( $_GET[ 'panel' ] ) ) {
$active_tab = $_GET[ 'panel' ];
}
else{
$active_tab = "main_settings";
}
echo "<div id='activeBanner'>Active</br>Current Pages Built: $pagesBuilt</br>Files Added: $filesAdded";
echo '</div>';
echo '<div id="activeBanner">Database Version: '.$ipfs_db_version.'</div>';
echo "<h2 class=\"nav-tab-wrapper\">
<a href=\"?page=ipfs_generator&panel=main_settings\" class=\"nav-tab\">Main Settings</a>
<a href=\"?page=ipfs_generator&panel=Peers\" class=\"nav-tab\">Peers</a>
<a href=\"?page=ipfs_generator&panel=ipfs_FileManager\" class=\"nav-tab\">IPFS Files</a>
<a href=\"?page=ipfs_generator&panel=KeyManager\" class=\"nav-tab\">Key Manager</a>
<a href=\"?page=ipfs_generator&panel=ipfs_config\" class=\"nav-tab\">IPFS Config File</a>
<a href=\"?page=ipfs_generator&panel=ipfs_logs\" class=\"nav-tab\">View Logs</a>
<a href=\"?page=ipfs_generator&panel=ipfs_Database\" class=\"nav-tab\">Tools</a>";
if(get_site_url() == 'https://www.jefflubbers.com'){
echo '<a href="?page=ipfs_generator&panel=ipfs_DevArea" class="nav-tab">Dev</a>';
}
echo "</h2>";
if($active_tab == 'main_settings'){
ipfs_main_settings();
}
elseif($active_tab == 'ipfs_config'){
ipfs_config();
}
elseif($active_tab== 'Peers'){
ipfs_peers();
}elseif($active_tab== 'KeyManager'){
ipfs_KeyManager();
}
elseif($active_tab == 'ipfs_logs'){
ipfs_logManager();
}
elseif($active_tab == 'ipfs_FileManager'){
ipfs_FileManager();
}
elseif($active_tab == 'ipfs_Database'){
ipfs_Database();
}
elseif($active_tab == 'ipfs_DevArea'){
ipfs_DevArea();
}
?>
<style>
#ipfs_UpdateDB{
/*float:right;*/
}
.warning{
color:red;
}
#mainSettings{
width: 20%;
float:left;
}
#ipfsStats{
margin-left:50px;
width: 20%;
float:left;
}
#col3{
width:40%;
margin-left:5%;
float:left;
}
#configEditor{margin-left:50px;
width: 20%;
float:left;
}
#activeBanner{
background: #1e881a;
padding: 10px;
color: #ffffff;
font-size: 16pt;
line-height:21pt;
margin-right: 20px;
}
.logMessage{
width:85%;
}
.logDate{
width:130px;
}
#MainContainer {
max-width: 50%;
margin-left: 50%;
width: 100%;
align-content: center;
text-align: center;
}
</style>
<script>
var setPublishingKey = function(KeyName,keyId){
var data = {
"action":"setPublishingKey",
"keyName": KeyName,
"keyId":keyId
};
jQuery.post(ajaxurl,data,function(response){
response = response.substring(0, response.length - 1);
alert(response);
return false;
});
return false;
}
var createNewKey = function(){
var newName= document.getElementById('newKeyName').value;
newName = newName.replace(" ", "_")
var data = {
'action':"CreateNewKey",
'keyName':newName
}
jQuery.post(ajaxurl,data,function(response){
response = response.substring(0, response.length - 1);
alert(response);
return false;
});
return false;
}
var Activate = function () {
var data = {
'action': 'ActivateIPFS',
id: document.getElementById('licenseKey').value,
email: document.getElementById('email').value
};
// since 2.8 ajaxurl is always defined in the admin header and points to admin-ajax.php
jQuery.post(ajaxurl, data, function(response) {
var str = response;
str = str.substring(0, str.length - 1);
alert(str);
if(str.includes("License Key Valid")){
location.reload();
}
return false;
}
)
return false;
};
</script>
<script type="text/javascript" >
var my_action_javascript = function($) {
var data = {
'action': 'my_action',
};
// since 2.8 ajaxurl is always defined in the admin header and points to admin-ajax.php
jQuery.post(ajaxurl, data, function(response) {
//alert('Got this from the server: ' + response);
});
};
var updateConfigFile = function($) {
var configData = document.getElementById("configData").value;
// configData = JSON.parse(configData);
var data = {
'action': 'updateIPFSConfigFile',
'configData': configData
};
// since 2.8 ajaxurl is always defined in the admin header and points to admin-ajax.php
jQuery.post(ajaxurl, data, function(response) {
alert(response);
});
};
var runIPFSCommand = function($) {
var configData = document.getElementById("ipfsCommand").value;
// configData = JSON.parse(configData);
var data = {
'action': 'runIPFSCommand',
'ipfsCommand': configData
};
// since 2.8 ajaxurl is always defined in the admin header and points to admin-ajax.php
jQuery.post(ajaxurl, data, function(response) {
// alert(response);
//console.log(response)
var json = JSON.parse(response);
var x = JSON.stringify(json, " ", 2)
document.getElementById('ipfsCommandResponse').innerHTML = x;
});
};
function VerifyDb() {
var data = {
'action': 'ipfs_UpdateDB'
};
// since 2.8 ajaxurl is always defined in the admin header and points to admin-ajax.php
jQuery.post(ajaxurl, data, function(response) {
// alert(response);
//console.log(response)
document.getElementById('responseArea').innerHTML = response;
return false;
});
return false;
};
var exportLogsasCSV = function(){
//exportLogsasCSV
var data = {
'action': 'exportLogsasCSV',
};
// since 2.8 ajaxurl is always defined in the admin header and points to admin-ajax.php
jQuery.post(ajaxurl, data, function(response) {
var entries = csvToArray(response);
console.log(entries);
var today = new Date();
var lcFileName = "IPFS_BRIDGE_LOGS_" + today.toLocaleString().replace(", ","_").replace(" ","_");
exportToCsv(lcFileName+".csv",entries);
// link.click(); // This will download the data file named "my_data.csv".
return false;
// alert(response);
// response = response.substring(0, response.length - 1);
// var json = JSON.parse(response);
// var x = JSON.stringify(json, " ", 2)
// document.getElementById('ipfsCommandResponse').innerHTML = x;
});
}
//callCURL
function csvToArray(csvString){
// The array we're going to build
var csvArray = [];
// Break it into rows to start
var csvRows = csvString.split(/\n/);
// Take off the first line to get the headers, then split that into an array
var csvHeaders = csvRows.shift().split(',');
csvArray.push(csvHeaders);
// Loop through remaining rows
for(var rowIndex = 0; rowIndex < csvRows.length; ++rowIndex){
var csvParseString = csvRows[rowIndex];
csvParseString = csvParseString.substr(0,csvParseString.length-1);
csvParseString = csvParseString.substr(1);
// console.log(csvParseString);
var rowArray = csvParseString.split('","');
// console.log(rowArray);
// var rowArray = csvRows[rowIndex].split('";"');
csvArray.push(rowArray);
// // Create a new row object to store our data.
// var rowObject = csvArray[rowIndex] = {};
//
// // Then iterate through the remaining properties and use the headers as keys
// for(var propIndex = 0; propIndex < rowArray.length; ++propIndex){
// // Grab the value from the row array we're looping through...
// var propValue = rowArray[propIndex].replace(/^"|"$/g,'');
// // ...also grab the relevant header (the RegExp in both of these removes quotes)
// var propLabel = csvHeaders[propIndex].replace(/^"|"$/g,'');;
//
// rowObject[propLabel] = propValue;
// }
}
return csvArray;
}
function exportToCsv(filename, rows) {
var processRow = function (row) {
var finalVal = '';
for (var j = 0; j < row.length; j++) {
var innerValue = row[j] === null ? '' : row[j].toString();
if (row[j] instanceof Date) {
innerValue = row[j].toLocaleString();
};
var result = innerValue.replace(/"/g, '""');
if (result.search(/("|,|\n)/g) >= 0)
result = '"' + result + '"';
if (j > 0)
finalVal += ',';
finalVal += result;
}
return finalVal + '\n';
};
var csvFile = '';
for (var i = 0; i < rows.length; i++) {
csvFile += processRow(rows[i]);
}
var blob = new Blob([csvFile], { type: 'text/csv;charset=utf-8;' });
if (navigator.msSaveBlob) { // IE 10+
navigator.msSaveBlob(blob, filename);
} else {
var link = document.createElement("a");
if (link.download !== undefined) { // feature detection
// Browsers that support HTML5 download attribute
var url = URL.createObjectURL(blob);
link.setAttribute("href", url);
link.setAttribute("download", filename);
link.style.visibility = 'hidden';
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
}
}
}
</script>
<?php
function my_action_javascript() { ?>
<script type="text/javascript" >
var my_action_javascript = function($) {
var data = {
'action': 'my_action',
'whatever': 1234
};
// since 2.8 ajaxurl is always defined in the admin header and points to admin-ajax.php
jQuery.post(ajaxurl, data, function(response) {
alert('Got this from the server: ' + response)
});
});
$('#ipfs_UpdateDB').submit(function(event) {
event.preventDefault();
// ...
}
</script> <?php
}
}
add_action( 'wp_ajax_my_action', 'my_action' );
add_action( 'wp_ajax_updateIPFSConfigFile', 'updateIPFSConfigFile' );
function updateIPFSConfigFile(){
global $server,$gatewayPort,$APIPort;
ipfs_logEvent("Updating Config File.");
$tempfile = __DIR__."/ipfsCONFIG";
$ipfsConfigData = $_POST['configData'];
// ipfs_logEvent("DATE +== ".$_POST['configData']);
$ipfsConfigData = str_replace('\"', '"',$ipfsConfigData);
// foreach($_POST['configData'] as $key=> $value){
// ipfs_logEvent("Array:$key:$value" );
// if(gettype($value) == 'array'){
// foreach ($value as $subKey=>$subValue);
// ipfs_logEvent("Array: $subKey:$subValue");
// }
// }
// file_put_contents($tempfile,serialize($_POST['configData']));
file_put_contents($tempfile,$ipfsConfigData);
echo "IPFS Configuration Updated";
ipfs_logEvent("File Saved");
$ipfs = new IPFSFiles($server, $gatewayPort, $APIPort);
$ipfs->updateConfig($tempfile);
wp_die();
}
function ipfs_main_Settings(){
$ipfsStats = getRepoStats();
$ipfsVersion = getVersion();
$ipfsID = ipfsGet("id");
echo "<div id='mainSettings'>";
settings_fields( 'pluginPage' );
do_settings_sections( 'pluginPage' );
submit_button();
?>
<!-- <p class="submit">-->
<button name="reload" id="reload" class="button button-primary" onclick="my_action_javascript();" value="Trigger Build of IPFS Site" >Trigger Build of IPFS Site</button>
<!-- </p>-->
</form>
</div>
<div id="ipfsStats">
<h2>IPFS Information</h2>
<?php
echo "<p>Id: ". $ipfsID['ID']."</p>";
echo "<h3>Addresses</h3><ul>";
foreach($ipfsID["Addresses"] as $address){
echo "<li>Address: ".$address."</li>";
}
echo "</ul>";
echo "<p>Protocol Version: ". $ipfsID['ProtocolVersion']."</p>";
echo "<p>Version: ". $ipfsVersion['Version']."</p>";
echo "<p>Commit: ". $ipfsVersion['Commit']."</p>";
echo "<p>System: ". $ipfsVersion['System']."</p>";
echo "<p>Go Language Version: ". $ipfsVersion['Golang']."</p>";
echo "<p>Required Repo Version: ". $ipfsVersion['Repo']."</p>";
echo "<h2>Repo Stats</h2>";
echo "<p>Repo Size: ". formatBytes($ipfsStats['RepoSize'])."</p>";
echo "<p>Number of Objects: ". $ipfsStats['NumObjects']."</p>";
echo "<p>Repo Path: ". $ipfsStats['RepoPath']."</p>";
echo "<p>Repo Version: ". $ipfsStats['Version']."</p>";
echo "<p>Repo Max Storage: ".formatBytes($ipfsStats['StorageMax'])."</p>";
?>
</div>
<div id="col3">
<table style="width:100%;">
<tr>
<th style="float:left">
Ex: swarm/peers <button id="runIPFSCommand" class='button button-primary' onclick="runIPFSCommand(); return false;">Run IPFS Command</button>
</th>
</tr>
<tr>
<th style="float:left">IPFS API Command:
<input type="text" style="width:500px" id="ipfsCommand"></th>
</tr>
<tr>
<td colspan="2">
<pre id="ipfsCommandResponse"></pre>
</td>
</tr>
</table>
</div>
<?php
}
function ipfs_config(){
$ipfsConfig = ipfsGet("config/show");
ipfs_logEvent("Date == " . str_replace("\/","/",json_encode($ipfsConfig, JSON_PRETTY_PRINT)));
?>
<div id="configEditor">
<?php
echo "<h3>Config File - <font class='warning'>Edit at your won Risk!!!</font></h3>";
$Config = str_replace("\/","/",json_encode($ipfsConfig, JSON_PRETTY_PRINT));
echo "<textarea id='configData' cols='200' rows='30' >$Config</textarea>";
?>
<button class="button button-primary" onclick="updateConfigFile(); return false;" value="Update Config File" >Update Config File</button>
</div>
<?php
}
function ipfs_peers(){
$peers = ipfsGet("swarm/peers");
ipfs_logEvent(json_encode($peers, JSON_PRETTY_PRINT));
echo "<h3>".count($peers['Peers'])." - Peers</h3>";
echo "<ul>";
foreach ($peers['Peers'] as $peer){
echo "<li>".str_replace("\/","/", $peer["Addr"])."/";
if (!stristr($peer['Addr'],"p2p-circuit")){
echo "/".$peer["Peer"];
}
echo "</li>";
}
echo "</ul>";
}
function ipfs_KeyManager(){
$options = get_option( 'ipfs_settings' );
$keys = ipfsGet("key/list");
echo "<h3>Keys</h3>";
echo "<table>";
foreach ($keys['Keys'] as $key){
echo "<tr>";
$Name = $key['Name'];
if(!($Name == $options['ipns_name'])){
echo "<th><button style='margin-right:10px;' class='button button-primary' onClick='setPublishingKey("."\"".$Name.'","'.$key['Id'].'"'."); return false;'>Set to Active Key</button></th>";
}
else{
echo "<th></th>";
}
echo "<td><p>Name: ".$key['Name']."<br>Id: ".$key['Id']."</p></td></tr>";
}
echo "</table>";
?>
<table>
<tr>
<th>New Key Name: </th> <td><input type="text" id="newKeyName"></td>
</tr>
<tr><td colspan="2"><button class='button button-primary' onClick="createNewKey(); return false;">Create New Key</button></td></tr>
</table>
<?php
}
function my_action() {
global $wpdb; // this is how you get access to the database
wp_schedule_single_event( time()-60 , 'saveAllPages' );
wp_die(); // this is required to terminate immediately and return a proper response
}
function ipfs_logManager(){
global $wpdb, $logTable;
$logs = $wpdb->get_results("Select logTime, logMessage, codeLocation from $logTable ORDER BY ID DESC, logTime DESC LIMIT 500;", ARRAY_A );
?>
<h3>IPFS Bridge Logs</h3>
<button class='button button-primary' onClick="exportLogsasCSV(); return false;">Export Logs as CSV</button>
<table>
<tr>
<th>DateLogged</th>
<th>Message</th>
<th>Code Location</th>
</tr>
<?php
foreach($logs as $log){
echo "<tr>";
echo "<td class='logDate'>".$log['logTime']."</td>";
echo "<td class='logMessage'>".$log['logMessage']."</td>";
echo "<td>".$log['codeLocation']."</td>";
echo "</tr>";
}
?></table>
<?php
}
function ipfs_FileManager(){
global $filesTable, $wpdb, $GateWayLink;
$Files = $wpdb->get_results("Select * from $filesTable ORDER BY dateAdded DESC;", ARRAY_A );
?><div class="ipfsFiles">
<!-- <div style="height: 30px"><button class='button button-primary' >Upload Pending Files</button></div>-->
<table id="nodeFiles" class="fileFrame">
<tr id="fileHeaderRow"><th>Date Added</th><th>File Name</th><th>IPFS Hash</th></tr>
<tbody id="fileList">
<!-- <iframe src="www.jefflubbers.com" class="ipfsFiles fileFrame"></iframe>-->
<?php
foreach ($Files as $file){
$link = "$GateWayLink/ipfs/".$file['hash'];
echo'<tr class="fileRow">';
echo'<td style="text-align:right;">'.$file["dateAdded"].'</td><th>'.$file["filename"].'</th><td><a target="_blank" href="'.$link.'">/ipfs/'.$file["hash"].'</a></td></tr>';
}
?></tbody></table></div>
<?php
addUploader();
?>
<style>
.ipfsFiles{
width: 50%;
height:900px;
min-height:600px;
float:left;
overflow-y:scroll;
}
.fileFrame{
width: 100%;
min-height:600px;
max-height:600px;
}
tbody#fileList{
overflow-y:scroll;
/*overflow-y: auto*/
}
.fileRow{
height:30px;
border-bottom:1px solid #333333;
}
tr.fileRow:nth-child(even) {background: #CCC}
tr.fileRow:nth-child(odd) {background: #FFF}
</style>
<script>
var addIPFSFileToTable = function(file){
console.log("Add Called")
console.log(file);
//jsonFile = JSON.parse(file);
var html = '<tr class="fileRow">';
var link = "https://gateway.ipfs.io/ipfs/" + file.hash;
html = html + '<td style="text-align:right;">' + file.dateAdded + '</td><th>' + file.name + '</th><td><a target="_blank" href="' + link + '">/ipfs/' + file.hash + '</a></td></tr></tr>';
$('#fileList').prepend(html);
}
</script>
<?php
}
function addUploader(){
$path = plugin_dir_url(__FILE__).'uploader/index.html';
$path = plugin_dir_url(__FILE__);
//$path = plugin_dir_path
// $fileConetnts = file_get_contents($path);
// $fileConetnts = file_get_contents(__DIR__.'/uploader/indexmissingscriptsandCSS.html');
// //ipfs_logEvent($fileConetnts,"Options.AddUploader");
// echo $fileConetnts;
?>
<!-- <iframe class="ipfsFiles" src="--><?php //echo $path?><!--"></iframe>-->
<!-- --><?php //echo $path;?>
<!-- <link rel="stylesheet" href="--><?php //echo $path;?><!--uploader/assets/font-awesome.css" type="text/css"/>-->
<!-- <link rel="stylesheet" href="--><?php //echo $path;?><!--uploader/assets/theme.css" type="text/css"/>-->
<!-- <script src="--><?php //echo $path;?><!--uploader/assets/IpfsApi.js"></script>-->
<!-- <script src="--><?php //echo $path;?><!--uploader/assets/CustomJS.js"></script>-->
<!-- <script src="--><?php //echo $path;?><!--uploader/assets/jquery-3.js"></script>-->
<!-- <script src="--><?php //echo $path;?><!--uploader/assets/IPFSjs.js"></script>-->
<!-- <!-- Bootstrap styles -->-->
<!-- <!--<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">-->-->
<!-- <!-- Generic page styles -->-->
<!---->
<!-- <link rel="stylesheet" href="--><?php //echo $path;?><!--uploader/assets/bootstrap.css">-->
<!---->
<!-- <link href="--><?php //echo $path;?><!--uploader/assets/icon.css" rel="stylesheet">-->
<!-- <link rel="stylesheet" href="--><?php //echo $path;?><!--uploader/assets/style.css">-->
<!---->
<!-- <!-- blueimp Gallery styles -->-->
<!-- <link rel="stylesheet" href="--><?php //echo $path;?><!--uploader/assets/blueimp-gallery.css"/>-->
<!-- <!-- CSS to style the file input field as button and adjust the Bootstrap progress bars -->-->
<!-- <link rel="stylesheet" href=--><?php //echo $path;?><!--uploader/assets/jquery_002.css"/>-->
<!-- <link rel="stylesheet" href=--><?php //echo $path;?><!--uploader/assets/jquery_003.css"/>-->
<!---->
<!-- <!--<script src="assets/app.js"></script>-->-->
<!---->
<!-- <!-- The jQuery UI widget factory, can be omitted if jQuery UI is already included -->-->
<!-- <script src=--><?php //echo $path;?><!--uploader/assets/jquery_009.js"></script>-->
<!-- <!-- The Templates plugin is included to render the upload/download listings -->-->
<!-- <script src=--><?php //echo $path;?><!--uploader/assets/tmpl.js"></script>-->
<!-- <!-- The Load Image plugin is included for the preview images and image resizing functionality -->-->
<!-- <script src=--><?php //echo $path;?><!--uploader/assets/load-image.js"></script>-->
<!-- <!-- The Canvas to Blob plugin is included for image resizing functionality -->-->
<!-- <script src=--><?php //echo $path;?><!--uploader/assets/canvas-to-blob.js"></script>-->
<!-- <!-- Bootstrap JS is not required, but included for the responsive demo navigation -->-->
<!-- <!--<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>-->-->
<!-- <!-- blueimp Gallery script -->-->
<!-- <script src=--><?php //echo $path;?><!--uploader/assets/jquery_003.js"></script>-->
<!-- <!-- The Iframe Transport is required for browsers without support for XHR file uploads -->-->