-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
5387 lines (4286 loc) · 169 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
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 /*<!DOCTYPE html>
<html class="no-js">
<head>
<style>
.ng-cloak, [ng-cloak], ng-cloak {display: none !important;}
</style>
</head>
<body class="ng-cloak">
<script>
window.addEventListener('DOMContentLoaded', async function(){
//const DOCSTRING = document.documentElement.innerHTML;
const DOCSTRING = await(await fetch(window.location.href)).text();
((q, w,d, ERRORTEMPLATE, STUBDOC, htmlNodes)=>{
var s=d.createElement('script');
s.setAttribute('src', 'https://cdn.startdir.de/webfan.js?cdn=https://cdn.startdir.de&?' + q);
s.async='defer';
s.onload=()=>{
document.querySelector('body').innerHTML = ERRORTEMPLATE;
w.frdlweb.ready(async()=>{
(await require('frdlweb')).Webfan.EventEmitter.DEFAULT.once('ready:loop',async ()=>{
const mm = await require('mimemessage');
const separatorIndex = Math.max(
STUBDOC.indexOf(atob("X19oYWx0X2NvbXBpbGVyKCk7")),
STUBDOC.indexOf(atob("X19oYWx0X2NvbXBpbGVy"))
);
var MIME;
var PHPSTUB = STUBDOC.substr(0, separatorIndex);
var parsedString = STUBDOC.substr(separatorIndex //+ atob("X19oYWx0X2NvbXBpbGVyKCk7").length
, STUBDOC.length);
while( 'M' !== parsedString.substr(0,1) && 'C' !== parsedString.substr(0,1) ){
parsedString = parsedString.substr(1);
}
while( '-' !== parsedString.substr(-1) ){
parsedString = parsedString.slice(0,-1);
}
parsedString = parsedString.replace(/(\<\!\-\-\?php)/, '<?php').trim();
// var blobx = new Blob([parsedString], { type: 'text/plain;charset=utf-8' });
// var url = window.URL.createObjectURL(blobx); // ! createObjectURL
var url = 'data:multipart/mixed; charset=utf-8,' + encodeURIComponent(parsedString);
MIME = mm.parse(parsedString);
if(!MIME){
MIME = mm.parse(await(await fetch(url)).text());
}
if(!MIME){
MIME = mm.parse(parsedString);
}
console.log('MIME', MIME);
window.frdlweb.defaultdomain = host => {
(async (host)=>{
var c = await fetch('https://cdn.webfan.de/~'
// + self.origin.split(/\:\/\//).pop()
+'.@@domain@@'
+'./run/web+fan:'+self.origin.split(/\:\/\//).pop()
+ ':449'
+'/@webfan3/io4/index.html');
document.open( );
document.write( (await c.text()).replace(/(\@\@domain\@\@)/g, host) );
document.close( );
})(host);
};
document.querySelector('body').innerHTML += `
<p>
<button onclick="window.frdlweb.defaultdomain(self.location.host);" class="btn btn-warning">Default Domain anzeigen</button>
</p>
`; //add defaultdomain button
});
});
};
d.head.prepend(s);
})('DEBUG.enabled=true&website.consent.ads=false&website.worker.enabled=false', window, document,
`
<h1 class="error" style="color:red;">PHP is not available at ${location.host} ... ${location.pathname}</h1>
[<a href="https://webfan.de/apps/webmaster/">Goto Webfan Webmaster Installer Tools...</a>]
<br />
<h1 class="error" style="color:red;background:url(https://cdn.webfan.de/ajax-loader_2.gif) no-repeat;">Loading the Webfat HTML Workspace...</h1>
`,
DOCSTRING,
document.querySelectorAll('html')
);
});
</script>
</body>
</html>
<!--
* This script can be used to generate "self-executing" .php Files.
* https://github.com/frdl/mime-stub
* Dowload an example implementation at https://webfan.de/install/
* https://raw.githubusercontent.com/frdlweb/webfat/main/public/index.php
** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
**
* Copyright (c) 2020, Till Wehowski
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of frdl/webfan nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY frdl/webfan ''AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL frdl/webfan BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
** includes edited version of:
* https://github.com/Riverline/multipart-parser
*
* Class Part
* @package Riverline\MultiPartParser
*
* Copyright (c) 2015-2016 Romain Cambien
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the Software
* is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
* - edited by webfan.de
*/
namespace{
(static function () : void {
if(defined('___BLOCK_WEBFAN_MIME_VM_RUNNING_STUB___'))return;
$fileparts = explode('.', basename(__FILE__));
define('___BLOCK_WEBFAN_MIME_VM_RUNNING_STUB___', !in_array(basename(__FILE__), [
'index.php',
'init.php',
'io4.php',
'in.php',
'out.php',
'console.php',
'progress.php',
'poll.php',
'webhook.php',
'cron.php',
'ajax.php',
'api.php',
'public.php',
'test.php',
'install.php',
'setup.php',
'info.php',
'webfan.php',
'remote.php',
'sw.js.php',
'service-worker.php',
__DIR__ === $_SERVER['DOCUMENT_ROOT'] ? 'endpoint.php' : basename(__DIR__).'.php',
]) && !(
in_array($fileparts[0], [
'webfan',
'webfat',
'frdl',
__DIR__ === $_SERVER['DOCUMENT_ROOT'] ? 'public' : basename(__DIR__),
__DIR__ === $_SERVER['DOCUMENT_ROOT'] ? 'public-www' : basename(__DIR__).'-www',
])
&& (count($fileparts) > 2 && in_array($fileparts['test'===$fileparts[1]?2:1], [
'index',
'endpoint',
'server',
'api',
'install',
'uninstall',
'setup',
'update',
'workspace',
'remote-workspace',
'test',
])
)
)
);
})();
}
namespace{
if ( !function_exists('sys_get_temp_dir')) {
function sys_get_temp_dir() {
if (!empty($_ENV['TMP'])) { return realpath($_ENV['TMP']); }
if (!empty($_ENV['TMPDIR'])) { return realpath( $_ENV['TMPDIR']); }
if (!empty($_ENV['TEMP'])) { return realpath( $_ENV['TEMP']); }
$tempfile=tempnam(__FILE__,'');
if (file_exists($tempfile)) {
unlink($tempfile);
return realpath(dirname($tempfile));
}
return null;
}
}
}
namespace{
if ( !function_exists('spl_object_id')) {
function spl_object_id($object) {
return spl_object_hash($object);
}
}
}
namespace Frdlweb\Contract\Autoload{
if (!\interface_exists(CodebaseInterface::class, false)) {
interface CodebaseInterface
{
const ALL_CHANNELS = '*';
const ENDPOINT_DEFAULT = 'RemoteApiBaseUrl';
const ENDPOINT_PROVIDER_IDENTITY_CENTRAL = 'io4.pid.central';
const ENDPOINT_WEBFAT_CENTRAL = 'io4.webfat.central';
const ENDPOINT_REMOTE_PUBLIC = 'io4.workspace.public';
const ENDPOINT_REMOTE_PRIVATE = 'io4.workspace.private';
const ENDPOINT_WORKSPACE_REMOTE = 'io4.workspace.remote';
const ENDPOINT_INSTALLER_REMOTE = 'io4.installer.remote';
const ENDPOINT_PROXY_OBJECT_REMOTE = 'io4.proxy-object.remote';
const ENDPOINT_CONTAINER_REMOTE = 'io4.container.remote';
const ENDPOINT_CONFIG_REMOTE = 'io4.config.remote';
const ENDPOINT_MODULES_WEBFANSCRIPT_REMOTE = 'RemoteModulesBaseUrl';
const ENDPOINT_AUTOLOADER_PSR4_REMOTE = 'RemotePsr4UrlTemplate';
const ENDPOINT_UDAP = 'io4.udap';
const ENDPOINT_RDAP = 'io4.rdap';
const ENDPOINT_OIDIP = 'io4.rdap';
const CHANNEL_LATEST = 'latest';
const CHANNEL_STABLE = 'stable';
const CHANNEL_FALLBACK = 'fallback';
const CHANNEL_TEST = 'test';
const CHANNELS =[
self::CHANNEL_LATEST => self::CHANNEL_LATEST,
self::CHANNEL_STABLE => self::CHANNEL_STABLE,
self::CHANNEL_FALLBACK => self::CHANNEL_FALLBACK,
self::CHANNEL_TEST => self::CHANNEL_TEST,
];
const DEFAULT_ENDPOINT_NAMES =[
self::ENDPOINT_DEFAULT,
self::ENDPOINT_PROVIDER_IDENTITY_CENTRAL,
self::ENDPOINT_WEBFAT_CENTRAL,
self::ENDPOINT_REMOTE_PUBLIC,
//self::ENDPOINT_REMOTE_PRIVATE,
self::ENDPOINT_WORKSPACE_REMOTE,
self::ENDPOINT_INSTALLER_REMOTE,
self::ENDPOINT_MODULES_WEBFANSCRIPT_REMOTE,
self::ENDPOINT_PROXY_OBJECT_REMOTE,
self::ENDPOINT_CONTAINER_REMOTE,
self::ENDPOINT_AUTOLOADER_PSR4_REMOTE,
self::ENDPOINT_UDAP,
self::ENDPOINT_RDAP,
self::ENDPOINT_OIDIP,
self::ENDPOINT_CONFIG_REMOTE,
];
public function loadUpdateChannel(mixed $StubRunner = null) : string;
public function getRemoteApiBaseUrl(?string $serviceEndpoint = self::ENDPOINT_DEFAULT) : string|bool;
public function setUpdateChannel(string $channel);
public function getUpdateChannel() : string;
public function getRemotePsr4UrlTemplate() : string;
public function getRemoteModulesBaseUrl() : string;
public function getServiceEndpoints() : array;
public function getServiceEndpointNames() : array;
public function setServiceEndpoints(array $serviceEndpoints) : CodebaseInterface;
public function setServiceEndpoint(string $serviceEndpointName,
string|\Closure|\callable $baseUrl,
?string $channel = self::ALL_CHANNELS) : CodebaseInterface;
}
}
}
namespace Frdlweb\Contract\Autoload{
if (!interface_exists(LoaderInterface::class)) {
interface LoaderInterface {
public function register(bool $prepend = false);
}
}
}//ns Frdlweb\Contract\Autoload
namespace frdlweb{
use Frdlweb\Contract\Autoload\LoaderInterface;
use Psr\Container\ContainerInterface;
use Laminas\Json\Server\Server;
use ProxyManager\Factory\RemoteObject\Adapter\JsonRpc;
use ProxyManager\Factory\RemoteObjectFactory;
use Laminas\Http\Client\Adapter\Exception\RuntimeException;
use Laminas\Json\Server\Client;
if (!\interface_exists(StubItemInterface::class, false)) {
interface StubItemInterface
{
public function getMimeType();
public function getName() ;
public function getFileName();
public function isFile();
public function getParts();
public function getPartsByName( $name);
public function addFile( $type = 'application/x-httpd-php', $disposition = 'php', $code= '', $file = '', $name= '');
public function isMultiPart();
public function getBody($reEncode = false, &$encoding = null);
public function __toString();
}
}
if (!\interface_exists(StubInterface::class, false)) {
interface StubInterface
{
public function init (?string $scope = null) : ?string;
//public function moduleLocation(?string $location = null);
public function installTo(string $location, bool $forceCreateDirectory = false, $mod = 0755) : object;
public function isIndex(bool $onlyIfFirstFileCall = true) : bool;
public function install(?array $params = [] ) : bool|array;
public function uninstall(?array $params = [] ) : bool|array;
public function setDownloadSource(string $source);
public function isIndexRequest() : bool;
public function runAsIndex(?bool $showErrorPageReturnBoolean = true) : bool|object;
}
}
if (!\interface_exists(StubAsFactoryInterface::class, false)) {
interface StubAsFactoryInterface
{
//nette/php-generatror
public function getAsGeneratedPhpSource($id=null, $classes=[], $params = []
, $options = [] //autoloader,cache,.... e.g.
, $generator=null
,?\Psr\Container\ContainerInterface $container = null
, ?bool $throw = false);
public function load(string $file, ?string $as = null) : object;
public function getAsContainer(?string $factoryId=null, ?array $definitions = [], ?array $options = []) : \Psr\Container\ContainerInterface;
public function getAsStub(string $id) : object|bool;
public function setStubIndexPhp(string $id, string $code, ?string $toFile = null) : bool;
public function getAsFacade($alias, $proxy, string $id = null,string $namespace = null
,?\Psr\Container\ContainerInterface $container = null
, ?bool $throw = false) : bool;
public function getAsRemoteObjectProxy(string $class, ?string $url = null, ?ContainerInterface $container=null);
public function getAsLazyLoadingValueHolderProxy(string $class, $initializer);
public function withFacades(?string $baseNamespace = '', ?string $namespace = '*');
}
}
if (!\interface_exists(StubRunnerInterface::class, false)) {
interface StubRunnerInterface extends StubInterface
{
public function instance(?object $instance = null) : object;
// public function loginRootUser($username = null, $password = null) : bool;
// public function isRootUser() : bool;
public function getStubVM() : StubHelperInterface;
public function getStub() : StubItemInterface;
public function __invoke() :?StubHelperInterface;
public function hugVM(?StubHelperInterface $MimeVM);
public function getInvoker();
public function getShield();
public function autoloading() : void;
public function config(?array $config = null, $trys = 0) : array;
public function configVersion(?array $config = null, $trys = 0) : array;
public function getCodebase() :?\Frdlweb\Contract\Autoload\CodebaseInterface;
public function getFrdlwebWorkspaceDirectory() : string;
public function getWebrootConfigDirectory() : string;
public function getApplicationsDirectory() : string;
public function getRemoteAutoloader(?array $configVersion = null, ?array $config = null, ?\Frdlweb\Contract\Autoload\CodebaseInterface $codebase = null) : LoaderInterface;
public function autoUpdateStub(string | bool $update = null, string $newVersion = null, string $url = null);
}
}
if (!\interface_exists(StubModuleInterface::class, false)) {
interface StubModuleInterface extends StubInterface
{
public function autoload( ) : object;
}
}
if (!\interface_exists(StubHelperInterface::class, false)) {
interface StubHelperInterface
{
public function runStubs($stubs=null);
public function addPhpStub($code, $file = null);
public function addWebfile($path, $contents, $contentType = 'application/x-httpd-php', $n = 'php');
public function addClassfile($class, $contents);
public function get_file($part, $file, $name);
public function Autoload($class);
public function __toString();
public function __invoke();
public function __call($name, $arguments);
public function getFileAttachment($file = null, $offset = null, ?bool $throw = true);
public function hugRunner(mixed $runner);
public function getRunner();
//public function _run_php_1(StubItemInterface $part, $class = null, ?bool $lint = null);
}
}
}//namespace frdlweb
namespace PSX\Sandbox{
if(!function_exists('\PSX\Sandbox\runIsolate')){
function runIsolate($file, $context, ?bool $doRequire = true){
if(\class_exists(\Webfan\Sandbox\Runtime::class)){
return \Webfan\Sandbox\Runtime::runIsolate($file, $context, $doRequire);
}else{
return (static function ($context, $file, $doRequire) {
extract($context);
return false === $doRequire
? include $file
: require $file;
})($context, $file, $doRequire);
}
}
}
}
/**
namespace DI{
* Exception for the Container
if (!\class_exists(DependencyException::class, false)) {
class DependencyException extends \Exception
{
}
}
}
*/
namespace frdl\patch{
if (!\class_exists(RelativePath::class, false)) {
/**
* Simple relative path normalizer utility.
*
* The utility was inspired by PHP's realPath function, though that required the given path to exist, RelativePath does not.
*
* Particularly useful is you need to parse and normalize paths gathered from for instance URL's and HTML pages.
*
* These functions are also included in Zip and ZipStream classes version 1.23 onwards on PHPClasses.org.
* http://www.phpclasses.org/package/6110 and http://www.phpclasses.org/package/6616 respectively.
*
* License: GNU LGPL, Attribution required for commercial implementations, requested for everything else.
*
* @author A. Grandt <php@grandt.com>
* @copyright 2011 A. Grandt
* @license GNU LGPL, Attribution required for commercial implementations, requested for everything else.
* @link http://www.phpclasses.org/package/6844
* @version 1.01
*/
//mentioned here: https://webfan.de/install/
class RelativePath {
const VERSION = 1.01;
public static function rel($from, $to, $separator = \DIRECTORY_SEPARATOR)
{
$from = str_replace(array('/', '\\'), $separator, $from);
$to = str_replace(array('/', '\\'), $separator, $to);
$arFrom = explode($separator, rtrim($from, $separator));
$arTo = explode($separator, rtrim($to, $separator));
while(count($arFrom) && count($arTo) && ($arFrom[0] == $arTo[0]))
{
array_shift($arFrom);
array_shift($arTo);
}
return str_pad("", count($arFrom) * 3, '..'.$separator).implode($separator, $arTo);
}
/**
* Join $file to $dir path, and clean up any excess slashes.
*
* @author A. Grandt <php@grandt.com>
* @author Greg Kappatos
*
* @param string $dir
* @param string $file
*
* @return string Joined path, with the correct forward slash dir separator.
*/
public static function pathJoin($dir, $file) {
return \RelativePath::getRelativePath(
$dir . (empty($dir) || empty($file) ? '' : DIRECTORY_SEPARATOR) . $file
);
}
/**
* Clean up a path, removing any unnecessary elements such as /./, // or redundant ../ segments.
* If the path starts with a "/", it is deemed an absolute path and any /../ in the beginning is stripped off.
* The returned path will not end in a "/".
*
* @param String $path The path to clean up
* @return String the clean path
*/
public static function getRelativePath($path) {
$path = preg_replace("#/+\.?/+#", "/", str_replace("\\", "/", $path));
$dirs = explode("/", rtrim(preg_replace('#^(\./)+#', '', $path), '/'));
$offset = 0;
$sub = 0;
$subOffset = 0;
$root = "";
if (empty($dirs[0])) {
$root = "/";
$dirs = array_splice($dirs, 1);
} else if (preg_match("#[A-Za-z]:#", $dirs[0])) {
$root = strtoupper($dirs[0]) . "/";
$dirs = array_splice($dirs, 1);
}
$newDirs = array();
foreach ($dirs as $dir) {
if ($dir !== "..") {
$subOffset--;
$newDirs[++$offset] = $dir;
} else {
$subOffset++;
if (--$offset < 0) {
$offset = 0;
if ($subOffset > $sub) {
$sub++;
}
}
}
}
if (empty($root)) {
$root = str_repeat("../", $sub);
}
return $root . implode("/", array_slice($newDirs, 0, $offset));
}
}
}
}
namespace frdl\patch{
use frdl\patch\RelativePath;
/**
* Return relative path between two sources
* @param $from
* @param $to
* @param string $separator
* @return string
*/
function relPath($from, $to, $separator = \DIRECTORY_SEPARATOR)
{
return RelativePath::rel($from, $to, $separator);
}
}
namespace Spatie\Once{
use Countable;
use WeakMap;
if(!class_exists(Cache::class)){
class Cache implements Countable
{
protected static self $cache;
public WeakMap $values;
protected bool $enabled = true;
public static function getInstance(): static
{
return static::$cache ??= new static;
}
protected function __construct()
{
$this->values = new WeakMap();
}
public function has(object $object, string $backtraceHash): bool
{
if (! isset($this->values[$object])) {
return false;
}
return array_key_exists($backtraceHash, $this->values[$object]);
}
public function get($object, string $backtraceHash): mixed
{
return $this->values[$object][$backtraceHash];
}
public function set(object $object, string $backtraceHash, mixed $value): void
{
$cached = $this->values[$object] ?? [];
$cached[$backtraceHash] = $value;
$this->values[$object] = $cached;
}
public function forget(object $object): void
{
unset($this->values[$object]);
}
public function flush(): self
{
$this->values = new WeakMap();
return $this;
}
public function enable(): self
{
$this->enabled = true;
return $this;
}
public function disable(): self
{
$this->enabled = false;
return $this;
}
public function isEnabled(): bool
{
return $this->enabled;
}
public function count(): int
{
return count($this->values);
}
}
}//if(!class_exists(Cache::class)){
if(!class_exists(Backtrace::class)){
class Backtrace
{
protected array $trace;
protected array $zeroStack;
public function __construct(array $trace)
{
$this->trace = $trace[1];
$this->zeroStack = $trace[0];
}
public function getArguments(): array
{
return $this->trace['args'];
}
public function getFunctionName(): string
{
return $this->trace['function'];
}
public function getObjectName(): ?string
{
return $this->trace['class'] ?? null;
}
public function getObject(): mixed
{
if ($this->globalFunction()) {
return $this->zeroStack['file'];
}
return $this->staticCall() ? $this->trace['class'] : $this->trace['object'];
}
public function getHash(): string
{
$normalizedArguments = array_map(function ($argument) {
return is_object($argument) ? spl_object_hash($argument) : $argument;
}, $this->getArguments());
$prefix = $this->getObjectName() . $this->getFunctionName();
if (str_contains($prefix, '{closure}')) {
$prefix = $this->zeroStack['line'];
}
return md5($prefix.serialize($normalizedArguments));
}
protected function staticCall(): bool
{
return $this->trace['type'] === '::';
}
protected function globalFunction(): bool
{
return ! isset($this->trace['type']);
}
}
}//if(!class_exists(Backtrace::class)){
}//ns Spatie\Once
namespace frdl\booting{
use Spatie\Once\Backtrace;
use Spatie\Once\Cache;
/**
* once by:
* https://github.com/spatie/once
*/
function once(callable $callback): mixed
{
$trace = debug_backtrace(
\DEBUG_BACKTRACE_PROVIDE_OBJECT, 2
);
$backtrace = new Backtrace($trace);
if ($backtrace->getFunctionName() === 'eval') {
return call_user_func($callback);
}
$object = $backtrace->getObject();
$hash = $backtrace->getHash();
$cache = Cache::getInstance();
if (is_string($object)) {
$object = $cache;
}
if (! $cache->isEnabled()) {
return call_user_func($callback, $backtrace->getArguments());
}
if (! $cache->has($object, $hash)) {
$result = call_user_func($callback, $backtrace->getArguments());
$cache->set($object, $hash, $result);
}
return $cache->get($object, $hash);
}
function getFormFromRequestHelper(string $message = '',
bool $autosubmit = true,
$delay = 0,
$request = null){
$vars = (null===$request)
? $_POST
: $request->getParsedBody();
$target = (null===$request)
? $_SERVER['REQUEST_URI']
: $request->getUri();
$method = (null===$request)
? $_SERVER['REQUEST_METHOD']
: $request->getMethod();
$vars = (array)$vars;
$id = 'idr'.str_pad(time(), 32, mt_rand(0,(int)9), \STR_PAD_LEFT).str_pad(mt_rand(1,(int)9999999999), 16, mt_rand(0,(int)9), \STR_PAD_LEFT);
$html = $message;
$html.='<form id="'.$id.'" action="'.$target.'" method="'.$method.'">';
foreach($vars as $n => $v){
$html.='<input type="hidden" name="'.$n.'" value="'.strip_tags($v).'" />';
}
if(true !== $autosubmit){
$html.='<button class="btn btn-primary" onclick="document.getElementById(\''.$id.'\').submit();">Reload this page and retry request</button>';
}
$html.='</form>';
if(true === $autosubmit){
$html.='<p class="btn-info" style="color:red;background:url(https://io4.xyz.webfan3.de/assets/ajax-loader_2.gif) no-repeat;">Reloading...</p>';
$html.='<script>';
if(0<$delay){
$html.='(()=>{';
}
$html.='setTimeout(()=>{document.getElementById(\''.$id.'\').submit();}, '.($delay * 1000).')';
if(0<$delay){
$html.='})();';
}
$html.='</script>';
}
return $html;
}
}
namespace Webfan\Webfat\App{
use LogicException;
use Exception;
use IvoPetkov\HTML5DOMDocument;
if(!class_exists(ResolvableLogicException::class)){
class ResolvableLogicException extends LogicException
{
const URL_TEMPLATE = 'https://webfan.de/apps/registry/?goto=%s';
//const URL_FORM_TEMPLATE = 'https://webfan.de/apps/webmaster/1.3.6.1.4.1.37553.8.1.8.8.91397908338147/setup?instance=%2$s&errorinfo=%1$s';
const URL_FORM_TEMPLATE = 'https://webfan.de/apps/webmaster/1.3.6.1.4.1.37553.8.1.8.8.91397908338147/setup?instance=%2$s&errorinfo=%1$s';
const LINK_TEXT = '<strong>Help</strong> | Documentation | Infolink';
public $dom = null;
public $infos = [];
public $mainMessage;
public $formLink;
public static $urlformtemplate = null;
/**
* example (from Webfan\Webfat\App\Kernel) :
throw new ResolvableException(
'circuit:1.3.6.1.4.1.37553.8.1.8.8.1958965301.2=Environment variable FRDL_BUILD_FLAVOR must be set!'
.'|circuit:1.3.6.1.4.1.37553.8.1.8.8.1958965301.2=FRDL_BUILD_FLAVOR must be one of 1.3.6.1.4.1.37553.8.1.8.1.1089085 or 1.3.6.1.4.1.37553.8.1.8.1.575874'
.'|php:'.get_class($this).'=Thrown by the Kernel Class'
.'@FRDL_BUILD_FLAVOR not valid'
);
*/
public function __construct(
string $message = "",
int $code = 0,
int $severity = \E_ERROR,
?string $filename = null,
?int $line = null,
?Throwable $previous = null
) {
$args = func_get_args();
$this->infos = [];
$i = explode('@', $message, 3);
if(count($i)<2){
$i[]='';
$i[]='';
}elseif(count($i)<3){
$i[]='';
}
list($INFOS, $message, $formLink) = $i;
if(empty($message)){
$message = $INFOS;
$INFOS = '';
}
$formLink =(is_string(self::$urlformtemplate)) ? self::$urlformtemplate : self::URL_FORM_TEMPLATE;
$this->formLink = $formLink;
$informationObjects = preg_split("/([\,\;\|\+])/", $INFOS);
foreach($informationObjects as $info){
@list($infoID, $text) = explode('=', $info, 2);
$this->infos[]=[$infoID, $text];
}
// $this->dom = $this->html(false, $message, $formLink);
//$args[0] = $this->html(true, $message, $formLink);
$args[0] = $this->html(-1, $message, $formLink);
//$args[0] =$this->dom->saveHTML();
$this->mainMessage =$message;
parent::__construct(...$args);
}
public function html($asText = -1,$message = null, $formLink= null): mixed //HTML5DOMDocument|string
{
$info = [
'message'=> str_replace([\sys_get_temp_dir(),
getenv('HOME'),
$_SERVER['DOCUMENT_ROOT'],
],
['/{$tmp}',
'~',
'/$PUBLIC/www'], $message ? $message : $this->mainMessage),
'infos' => $this->infos,
/*
'client' => [
'host'=>$_SERVER['HTTP_HOST'],
'uri' => $_SERVER['REQUEST_URI'],
],
*/
];
$istance = urlencode(base64_encode(json_encode([
'host'=>$_SERVER['HTTP_HOST'],
'uri' => $_SERVER['REQUEST_URI'],
])));
$info = urlencode(base64_encode(json_encode($info)));
$hash = sha1($info);
$h = '';
$h.='<style>[ng-cloak], [data-ng-cloak], [x-ng-cloak], .ng-cloak, .x-ng-cloak{ display:none;}</style>';
$h .= '<table style="width:100%;">';
$h .= '<tr>';
$h .= '<th>';
$h .= '<h1 class="btn-danger">';
$h .= $message ? $message : $this->mainMessage;
$h .= '</h1>';
$h .= '</th>';
$h .= '<th>';
$h .= '<i>';
$h .= sprintf('Line %d in file %s', $this->getLine(), str_replace(getenv('HOME'), '',
str_replace([\sys_get_temp_dir(),
getenv('HOME'),
$_SERVER['DOCUMENT_ROOT'],
],
['/{$tmp}',
'~',
'/$PUBLIC/www'], $this->getFile())
));
$h .= '</i>';
$h .= '</th>';
$h .= '</tr>';
if(!isset($_GET['errorinfo'])){
$h .= '<tr>';
$h .= '<th colspan="2">';
$h .= '<h1 class="btn-info">';
$h .= '<a href="'