1
1
Fork 0

Merge pull request #7160 from nupplaphil/task/mod_probe

Move mod/probe to src/Module/Probe
This commit is contained in:
Hypolite Petovan 2019-05-19 15:06:13 -04:00 committed by GitHub
commit 6f0c6e8926
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 82 additions and 109 deletions

View file

@ -1,37 +0,0 @@
<?php
/**
* @file mod/probe.php
*/
use Friendica\App;
use Friendica\Core\L10n;
use Friendica\Core\System;
use Friendica\Network\Probe;
function probe_content(App $a)
{
if (!local_user()) {
$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;
}
$o = '<div class="generic-page-wrapper">';
$o .= '<h3>Probe Diagnostic</h3>';
$o .= '<form action="probe" method="get">';
$o .= 'Lookup address: <input type="text" style="width: 250px;" name="addr" value="' . defaults($_GET, 'addr', '') . '" />';
$o .= '<input type="submit" name="submit" value="Submit" /></form>';
$o .= '<br /><br />';
if (!empty($_GET['addr'])) {
$addr = trim($_GET['addr']);
$res = Probe::uri($addr, "", 0, false);
$o .= '<pre>';
$o .= str_replace("\n", '<br />', print_r($res, true));
$o .= '</pre>';
}
$o .= '</div>';
return $o;
}

View file

@ -92,7 +92,7 @@ class Router
$this->routeCollector->addRoute(['GET'], '/allfriends/{id:\d+}', Module\AllFriends::class); $this->routeCollector->addRoute(['GET'], '/allfriends/{id:\d+}', Module\AllFriends::class);
$this->routeCollector->addRoute(['GET'], '/apps', Module\Apps::class); $this->routeCollector->addRoute(['GET'], '/apps', Module\Apps::class);
$this->routeCollector->addRoute(['GET'], '/attach/{item:\d+}', Module\Attach::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\Debug\Babel::class);
$this->routeCollector->addRoute(['GET'], '/bookmarklet', Module\Bookmarklet::class); $this->routeCollector->addRoute(['GET'], '/bookmarklet', Module\Bookmarklet::class);
$this->routeCollector->addGroup('/contact', function (RouteCollector $collector) { $this->routeCollector->addGroup('/contact', function (RouteCollector $collector) {
$collector->addRoute(['GET'], '[/]', Module\Contact::class); $collector->addRoute(['GET'], '[/]', Module\Contact::class);
@ -120,7 +120,7 @@ class Router
$collector->addRoute(['GET'], '/{nickname}/replies', Module\Feed::class); $collector->addRoute(['GET'], '/{nickname}/replies', Module\Feed::class);
$collector->addRoute(['GET'], '/{nickname}/activity', 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) { $this->routeCollector->addGroup('/fetch', function (RouteCollector $collector) {
$collector->addRoute(['GET'], '/{guid}/post', Module\Diaspora\Fetch::class); $collector->addRoute(['GET'], '/{guid}/post', Module\Diaspora\Fetch::class);
$collector->addRoute(['GET'], '/{guid}/status_message', Module\Diaspora\Fetch::class); $collector->addRoute(['GET'], '/{guid}/status_message', Module\Diaspora\Fetch::class);
@ -152,9 +152,8 @@ class Router
$collector->addRoute(['GET', 'POST'], '[/]', Module\Install::class); $collector->addRoute(['GET', 'POST'], '[/]', Module\Install::class);
$collector->addRoute(['GET'], '/testrewrite', Module\Install::class); $collector->addRoute(['GET'], '/testrewrite', Module\Install::class);
}); });
$this->routeCollector->addRoute(['GET', 'POST'], '/itemsource[/{guid}]', Module\Itemsource::class);
$this->routeCollector->addRoute(['GET'], '/like/{item:\d+}', Module\Like::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\Debug\Localtime::class);
$this->routeCollector->addRoute(['GET', 'POST'], '/login', Module\Login::class); $this->routeCollector->addRoute(['GET', 'POST'], '/login', Module\Login::class);
$this->routeCollector->addRoute(['GET', 'POST'], '/logout', Module\Logout::class); $this->routeCollector->addRoute(['GET', 'POST'], '/logout', Module\Logout::class);
$this->routeCollector->addRoute(['GET'], '/magic', Module\Magic::class); $this->routeCollector->addRoute(['GET'], '/magic', Module\Magic::class);
@ -184,6 +183,7 @@ class Router
$collector->addRoute(['GET'], '/{type}/{customize}/{name}', Module\Photo::class); $collector->addRoute(['GET'], '/{type}/{customize}/{name}', Module\Photo::class);
}); });
$this->routeCollector->addRoute(['GET'], '/pretheme', Module\ThemeDetails::class); $this->routeCollector->addRoute(['GET'], '/pretheme', Module\ThemeDetails::class);
$this->routeCollector->addRoute(['GET'], '/probe', Module\Debug\Probe::class);
$this->routeCollector->addGroup('/profile', function (RouteCollector $collector) { $this->routeCollector->addGroup('/profile', function (RouteCollector $collector) {
$collector->addRoute(['GET'], '/{nickname}', Module\Profile::class); $collector->addRoute(['GET'], '/{nickname}', Module\Profile::class);
$collector->addRoute(['GET'], '/{profile:\d+}/view', Module\Profile::class); $collector->addRoute(['GET'], '/{profile:\d+}/view', Module\Profile::class);
@ -212,8 +212,8 @@ class Router
$this->routeCollector->addRoute(['GET'], '/toggle_mobile', Module\ToggleMobile::class); $this->routeCollector->addRoute(['GET'], '/toggle_mobile', Module\ToggleMobile::class);
$this->routeCollector->addRoute(['GET'], '/tos', Module\Tos::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'], '/view/theme/{theme}/style.pcss', Module\Theme::class);
$this->routeCollector->addRoute(['GET'], '/viewsrc/{item:\d+}', Module\ItemBody::class); $this->routeCollector->addRoute(['GET'], '/viewsrc/{item:\d+}', Module\Debug\ItemBody::class);
$this->routeCollector->addRoute(['GET'], '/webfinger', Module\WebFinger::class); $this->routeCollector->addRoute(['GET'], '/webfinger', Module\Debug\WebFinger::class);
$this->routeCollector->addRoute(['GET'], '/xrd', Module\Xrd::class); $this->routeCollector->addRoute(['GET'], '/xrd', Module\Xrd::class);
} }

View file

@ -1,6 +1,6 @@
<?php <?php
namespace Friendica\Module; namespace Friendica\Module\Debug;
use Friendica\BaseModule; use Friendica\BaseModule;
use Friendica\Content\Text; use Friendica\Content\Text;

View file

@ -1,6 +1,6 @@
<?php <?php
namespace Friendica\Module; namespace Friendica\Module\Debug;
use Friendica\BaseModule; use Friendica\BaseModule;
use Friendica\Core\L10n; use Friendica\Core\L10n;
@ -12,7 +12,7 @@ use Friendica\Util\Network;
/** /**
* Tests a given feed of a contact * Tests a given feed of a contact
*/ */
class Feedtest extends BaseModule class Feed extends BaseModule
{ {
public static function init() public static function init()
{ {

View file

@ -1,6 +1,6 @@
<?php <?php
namespace Friendica\Module; namespace Friendica\Module\Debug;
use Friendica\BaseModule; use Friendica\BaseModule;
use Friendica\Core\L10n; use Friendica\Core\L10n;

View file

@ -1,6 +1,6 @@
<?php <?php
namespace Friendica\Module; namespace Friendica\Module\Debug;
use Friendica\BaseModule; use Friendica\BaseModule;
use Friendica\Core\Installer; use Friendica\Core\Installer;

View file

@ -0,0 +1,43 @@
<?php
namespace Friendica\Module\Debug;
use Friendica\BaseModule;
use Friendica\Core\L10n;
use Friendica\Core\Renderer;
use Friendica\Network\HTTPException;
use Friendica\Network\Probe as NetworkProbe;
/**
* Fetch information (protocol endpoints and user information) about a given uri
*/
class Probe extends BaseModule
{
public static function content()
{
if (!local_user()) {
$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;
}
$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,
]);
}
}

View file

@ -1,6 +1,6 @@
<?php <?php
namespace Friendica\Module; namespace Friendica\Module\Debug;
use Friendica\BaseModule; use Friendica\BaseModule;
use Friendica\Core\L10n; use Friendica\Core\L10n;
@ -15,15 +15,13 @@ class WebFinger extends BaseModule
public static function content() public static function content()
{ {
if (!local_user()) { if (!local_user()) {
$e = new \Friendica\Network\HTTPException\ForbiddenException(L10n::t("Only logged in users are permitted to perform a probing.")); $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."); $e->httpdesc = L10n::t('Public access denied.');
throw $e; throw $e;
} }
$app = self::getApp();
$addr = defaults($_GET, 'addr', ''); $addr = defaults($_GET, 'addr', '');
$res = ''; $res = '';
if (!empty($addr)) { if (!empty($addr)) {
$res = Probe::lrdd($addr); $res = Probe::lrdd($addr);

View file

@ -1,55 +0,0 @@
<?php
namespace Friendica\Module;
use Friendica\Core\L10n;
use Friendica\Core\Renderer;
use Friendica\Model;
/**
* @author Hypolite Petovan <mrpetovan@gmail.com>
*/
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;
}
}

24
view/templates/probe.tpl Normal file
View file

@ -0,0 +1,24 @@
<div id="probe" class="generic-page-wrapper">
<h2>Probe Diagnostic</h2>
<form action="probe" method="get" class="panel panel-default">
<div class="panel-body">
<div class="form-group">
{{include file="field_input.tpl" field=$addr}}
</div>
<p><button type="submit" class="btn btn-primary">Submit</button></p>
</div>
</form>
{{if $res}}
<div class="probe-result">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">Output</h3>
</div>
<div class="panel-body">
<pre>{{$res}}</pre>
</div>
</div>
</div>
{{/if}}
</div>