From 48bba87abe7e8d78c48eaec2688509a9dfde7c4f Mon Sep 17 00:00:00 2001 From: Philipp Holzer Date: Sat, 18 May 2019 21:05:13 +0200 Subject: [PATCH 1/2] Move mod/probe to src/Module/Probe --- mod/probe.php | 37 ---------------- src/App/Router.php | 11 ++--- src/Module/{ => Diagnostic}/Babel.php | 2 +- .../{Feedtest.php => Diagnostic/Feed.php} | 4 +- src/Module/{ => Diagnostic}/ItemBody.php | 2 +- .../ItemSource.php} | 4 +- src/Module/{ => Diagnostic}/Localtime.php | 2 +- src/Module/Diagnostic/Probe.php | 43 +++++++++++++++++++ src/Module/{ => Diagnostic}/WebFinger.php | 4 +- view/templates/probe.tpl | 24 +++++++++++ 10 files changed, 81 insertions(+), 52 deletions(-) delete mode 100644 mod/probe.php rename src/Module/{ => Diagnostic}/Babel.php (99%) rename src/Module/{Feedtest.php => Diagnostic/Feed.php} (94%) rename src/Module/{ => Diagnostic}/ItemBody.php (95%) rename src/Module/{Itemsource.php => Diagnostic/ItemSource.php} (93%) rename src/Module/{ => Diagnostic}/Localtime.php (97%) create mode 100644 src/Module/Diagnostic/Probe.php rename src/Module/{ => Diagnostic}/WebFinger.php (93%) create mode 100644 view/templates/probe.tpl diff --git a/mod/probe.php b/mod/probe.php deleted file mode 100644 index 7fc3a9289..000000000 --- a/mod/probe.php +++ /dev/null @@ -1,37 +0,0 @@ -httpdesc = L10n::t("Public access denied."); - throw $e; - } - - $o = '
'; - $o .= '

Probe Diagnostic

'; - - $o .= '
'; - $o .= 'Lookup address: '; - $o .= '
'; - - $o .= '

'; - - if (!empty($_GET['addr'])) { - $addr = trim($_GET['addr']); - $res = Probe::uri($addr, "", 0, false); - $o .= '
';
-		$o .= str_replace("\n", '
', print_r($res, true)); - $o .= '
'; - } - $o .= '
'; - - return $o; -} diff --git a/src/App/Router.php b/src/App/Router.php index 373bb1c32..ddb3dbdfe 100644 --- a/src/App/Router.php +++ b/src/App/Router.php @@ -92,7 +92,7 @@ class Router $this->routeCollector->addRoute(['GET'], '/allfriends/{id:\d+}', Module\AllFriends::class); $this->routeCollector->addRoute(['GET'], '/apps', Module\Apps::class); $this->routeCollector->addRoute(['GET'], '/attach/{item:\d+}', Module\Attach::class); - $this->routeCollector->addRoute(['GET'], '/babel', Module\Babel::class); + $this->routeCollector->addRoute(['GET'], '/babel', Module\Diagnostic\Babel::class); $this->routeCollector->addRoute(['GET'], '/bookmarklet', Module\Bookmarklet::class); $this->routeCollector->addGroup('/contact', function (RouteCollector $collector) { $collector->addRoute(['GET'], '[/]', Module\Contact::class); @@ -153,9 +153,9 @@ class Router $collector->addRoute(['GET', 'POST'], '[/]', Module\Install::class); $collector->addRoute(['GET'], '/testrewrite', Module\Install::class); }); - $this->routeCollector->addRoute(['GET', 'POST'], '/itemsource[/{guid}]', Module\Itemsource::class); + $this->routeCollector->addRoute(['GET', 'POST'], '/itemsource[/{guid}]', Module\Diagnostic\ItemSource::class); $this->routeCollector->addRoute(['GET'], '/like/{item:\d+}', Module\Like::class); - $this->routeCollector->addRoute(['GET', 'POST'], '/localtime', Module\Localtime::class); + $this->routeCollector->addRoute(['GET', 'POST'], '/localtime', Module\Diagnostic\Localtime::class); $this->routeCollector->addRoute(['GET', 'POST'], '/login', Module\Login::class); $this->routeCollector->addRoute(['GET', 'POST'], '/logout', Module\Logout::class); $this->routeCollector->addRoute(['GET'], '/magic', Module\Magic::class); @@ -185,6 +185,7 @@ class Router $collector->addRoute(['GET'], '/{type}/{customize}/{name}', Module\Photo::class); }); $this->routeCollector->addRoute(['GET'], '/pretheme', Module\ThemeDetails::class); + $this->routeCollector->addRoute(['GET'], '/probe', Module\Diagnostic\Probe::class); $this->routeCollector->addGroup('/profile', function (RouteCollector $collector) { $collector->addRoute(['GET'], '/{nickname}', Module\Profile::class); $collector->addRoute(['GET'], '/{profile:\d+}/view', Module\Profile::class); @@ -213,8 +214,8 @@ class Router $this->routeCollector->addRoute(['GET'], '/toggle_mobile', Module\ToggleMobile::class); $this->routeCollector->addRoute(['GET'], '/tos', Module\Tos::class); $this->routeCollector->addRoute(['GET'], '/view/theme/{theme}/style.pcss', Module\Theme::class); - $this->routeCollector->addRoute(['GET'], '/viewsrc/{item:\d+}', Module\ItemBody::class); - $this->routeCollector->addRoute(['GET'], '/webfinger', Module\WebFinger::class); + $this->routeCollector->addRoute(['GET'], '/viewsrc/{item:\d+}', Module\Diagnostic\ItemBody::class); + $this->routeCollector->addRoute(['GET'], '/webfinger', Module\Diagnostic\WebFinger::class); $this->routeCollector->addRoute(['GET'], '/xrd', Module\Xrd::class); } diff --git a/src/Module/Babel.php b/src/Module/Diagnostic/Babel.php similarity index 99% rename from src/Module/Babel.php rename to src/Module/Diagnostic/Babel.php index 93bb3107f..797584a4f 100644 --- a/src/Module/Babel.php +++ b/src/Module/Diagnostic/Babel.php @@ -1,6 +1,6 @@ */ -class Itemsource extends \Friendica\BaseModule +class ItemSource extends \Friendica\BaseModule { public static function content() { diff --git a/src/Module/Localtime.php b/src/Module/Diagnostic/Localtime.php similarity index 97% rename from src/Module/Localtime.php rename to src/Module/Diagnostic/Localtime.php index d0b540879..a3870ca95 100644 --- a/src/Module/Localtime.php +++ b/src/Module/Diagnostic/Localtime.php @@ -1,6 +1,6 @@ httpdesc = L10n::t("Public access denied."); + throw $e; + } + + $addr = defaults($_GET, 'addr', ''); + $res = ''; + + if (!empty($addr)) { + $res = NetworkProbe::uri($addr, '', 0, false); + $res = print_r($res, true); + } + + $tpl = Renderer::getMarkupTemplate('probe.tpl'); + return Renderer::replaceMacros($tpl, [ + '$addr' => ['addr', + L10n::t('Lookup address'), + $addr, + '', + 'required' + ], + '$res' => $res, + ]); + } +} diff --git a/src/Module/WebFinger.php b/src/Module/Diagnostic/WebFinger.php similarity index 93% rename from src/Module/WebFinger.php rename to src/Module/Diagnostic/WebFinger.php index 0c1a692e1..5d6e05a27 100644 --- a/src/Module/WebFinger.php +++ b/src/Module/Diagnostic/WebFinger.php @@ -1,6 +1,6 @@ +

Probe Diagnostic

+
+
+
+ {{include file="field_input.tpl" field=$addr}} +
+

+
+
+ + {{if $res}} +
+
+
+

Output

+
+
+
{{$res}}
+
+
+
+ {{/if}} + From 492d7abe928c63d62ee9794aa5ff23ec374aece9 Mon Sep 17 00:00:00 2001 From: Philipp Holzer Date: Sun, 19 May 2019 03:02:58 +0200 Subject: [PATCH 2/2] Renamed Diagnostic to Debug and deleted ItemSource (already defined) --- src/App/Router.php | 13 ++--- src/Module/{Diagnostic => Debug}/Babel.php | 2 +- src/Module/{Diagnostic => Debug}/Feed.php | 2 +- src/Module/{Diagnostic => Debug}/ItemBody.php | 2 +- .../{Diagnostic => Debug}/Localtime.php | 2 +- src/Module/{Diagnostic => Debug}/Probe.php | 14 ++--- .../{Diagnostic => Debug}/WebFinger.php | 8 +-- src/Module/Diagnostic/ItemSource.php | 55 ------------------- 8 files changed, 21 insertions(+), 77 deletions(-) rename src/Module/{Diagnostic => Debug}/Babel.php (99%) rename src/Module/{Diagnostic => Debug}/Feed.php (96%) rename src/Module/{Diagnostic => Debug}/ItemBody.php (95%) rename src/Module/{Diagnostic => Debug}/Localtime.php (97%) rename src/Module/{Diagnostic => Debug}/Probe.php (67%) rename src/Module/{Diagnostic => Debug}/WebFinger.php (69%) delete mode 100644 src/Module/Diagnostic/ItemSource.php diff --git a/src/App/Router.php b/src/App/Router.php index ddb3dbdfe..ecc4eed68 100644 --- a/src/App/Router.php +++ b/src/App/Router.php @@ -92,7 +92,7 @@ class Router $this->routeCollector->addRoute(['GET'], '/allfriends/{id:\d+}', Module\AllFriends::class); $this->routeCollector->addRoute(['GET'], '/apps', Module\Apps::class); $this->routeCollector->addRoute(['GET'], '/attach/{item:\d+}', Module\Attach::class); - $this->routeCollector->addRoute(['GET'], '/babel', Module\Diagnostic\Babel::class); + $this->routeCollector->addRoute(['GET'], '/babel', Module\Debug\Babel::class); $this->routeCollector->addRoute(['GET'], '/bookmarklet', Module\Bookmarklet::class); $this->routeCollector->addGroup('/contact', function (RouteCollector $collector) { $collector->addRoute(['GET'], '[/]', Module\Contact::class); @@ -121,7 +121,7 @@ class Router $collector->addRoute(['GET'], '/{nickname}/replies', Module\Feed::class); $collector->addRoute(['GET'], '/{nickname}/activity', Module\Feed::class); }); - $this->routeCollector->addRoute(['GET'], '/feedtest', Module\Feedtest::class); + $this->routeCollector->addRoute(['GET'], '/feedtest', Module\Debug\Feed::class); $this->routeCollector->addGroup('/fetch', function (RouteCollector $collector) { $collector->addRoute(['GET'], '/{guid}/post', Module\Diaspora\Fetch::class); $collector->addRoute(['GET'], '/{guid}/status_message', Module\Diaspora\Fetch::class); @@ -153,9 +153,8 @@ class Router $collector->addRoute(['GET', 'POST'], '[/]', Module\Install::class); $collector->addRoute(['GET'], '/testrewrite', Module\Install::class); }); - $this->routeCollector->addRoute(['GET', 'POST'], '/itemsource[/{guid}]', Module\Diagnostic\ItemSource::class); $this->routeCollector->addRoute(['GET'], '/like/{item:\d+}', Module\Like::class); - $this->routeCollector->addRoute(['GET', 'POST'], '/localtime', Module\Diagnostic\Localtime::class); + $this->routeCollector->addRoute(['GET', 'POST'], '/localtime', Module\Debug\Localtime::class); $this->routeCollector->addRoute(['GET', 'POST'], '/login', Module\Login::class); $this->routeCollector->addRoute(['GET', 'POST'], '/logout', Module\Logout::class); $this->routeCollector->addRoute(['GET'], '/magic', Module\Magic::class); @@ -185,7 +184,7 @@ class Router $collector->addRoute(['GET'], '/{type}/{customize}/{name}', Module\Photo::class); }); $this->routeCollector->addRoute(['GET'], '/pretheme', Module\ThemeDetails::class); - $this->routeCollector->addRoute(['GET'], '/probe', Module\Diagnostic\Probe::class); + $this->routeCollector->addRoute(['GET'], '/probe', Module\Debug\Probe::class); $this->routeCollector->addGroup('/profile', function (RouteCollector $collector) { $collector->addRoute(['GET'], '/{nickname}', Module\Profile::class); $collector->addRoute(['GET'], '/{profile:\d+}/view', Module\Profile::class); @@ -214,8 +213,8 @@ class Router $this->routeCollector->addRoute(['GET'], '/toggle_mobile', Module\ToggleMobile::class); $this->routeCollector->addRoute(['GET'], '/tos', Module\Tos::class); $this->routeCollector->addRoute(['GET'], '/view/theme/{theme}/style.pcss', Module\Theme::class); - $this->routeCollector->addRoute(['GET'], '/viewsrc/{item:\d+}', Module\Diagnostic\ItemBody::class); - $this->routeCollector->addRoute(['GET'], '/webfinger', Module\Diagnostic\WebFinger::class); + $this->routeCollector->addRoute(['GET'], '/viewsrc/{item:\d+}', Module\Debug\ItemBody::class); + $this->routeCollector->addRoute(['GET'], '/webfinger', Module\Debug\WebFinger::class); $this->routeCollector->addRoute(['GET'], '/xrd', Module\Xrd::class); } diff --git a/src/Module/Diagnostic/Babel.php b/src/Module/Debug/Babel.php similarity index 99% rename from src/Module/Diagnostic/Babel.php rename to src/Module/Debug/Babel.php index 797584a4f..899c8033c 100644 --- a/src/Module/Diagnostic/Babel.php +++ b/src/Module/Debug/Babel.php @@ -1,6 +1,6 @@ httpdesc = L10n::t("Public access denied."); + $e = new HTTPException\ForbiddenException(L10n::t('Only logged in users are permitted to perform a probing.')); + $e->httpdesc = L10n::t('Public access denied.'); throw $e; } @@ -32,10 +32,10 @@ class Probe extends BaseModule $tpl = Renderer::getMarkupTemplate('probe.tpl'); return Renderer::replaceMacros($tpl, [ '$addr' => ['addr', - L10n::t('Lookup address'), - $addr, - '', - 'required' + L10n::t('Lookup address'), + $addr, + '', + 'required' ], '$res' => $res, ]); diff --git a/src/Module/Diagnostic/WebFinger.php b/src/Module/Debug/WebFinger.php similarity index 69% rename from src/Module/Diagnostic/WebFinger.php rename to src/Module/Debug/WebFinger.php index 5d6e05a27..2b0b9c53b 100644 --- a/src/Module/Diagnostic/WebFinger.php +++ b/src/Module/Debug/WebFinger.php @@ -1,6 +1,6 @@ httpdesc = L10n::t("Public access denied."); + $e = new \Friendica\Network\HTTPException\ForbiddenException(L10n::t('Only logged in users are permitted to perform a probing.')); + $e->httpdesc = L10n::t('Public access denied.'); throw $e; } $addr = defaults($_GET, 'addr', ''); - $res = ''; + $res = ''; if (!empty($addr)) { $res = Probe::lrdd($addr); diff --git a/src/Module/Diagnostic/ItemSource.php b/src/Module/Diagnostic/ItemSource.php deleted file mode 100644 index bd580cf89..000000000 --- a/src/Module/Diagnostic/ItemSource.php +++ /dev/null @@ -1,55 +0,0 @@ - - */ -class ItemSource extends \Friendica\BaseModule -{ - public static function content() - { - if (!is_site_admin()) { - return; - } - - $a = self::getApp(); - - // @TODO: Replace with parameter from router - if (!empty($a->argv[1])) { - $guid = $a->argv[1]; - } - - $guid = defaults($_REQUEST['guid'], $guid); - - $source = ''; - $item_uri = ''; - $item_id = ''; - $terms = []; - if (!empty($guid)) { - $item = Model\Item::selectFirst(['id', 'guid', 'uri'], ['guid' => $guid]); - - $conversation = Model\Conversation::getByItemUri($item['uri']); - - $item_id = $item['id']; - $item_uri = $item['uri']; - $source = $conversation['source']; - $terms = Model\Term::tagArrayFromItemId($item['id'], [Model\Term::HASHTAG, Model\Term::MENTION, Model\Term::IMPLICIT_MENTION]); - } - - $tpl = Renderer::getMarkupTemplate('debug/itemsource.tpl'); - $o = Renderer::replaceMacros($tpl, [ - '$guid' => ['guid', L10n::t('Item Guid'), $guid, ''], - '$source' => $source, - '$item_uri' => $item_uri, - '$item_id' => $item_id, - '$terms' => $terms, - ]); - - return $o; - } -}