Browse Source

show webmention details and logs

pull/3/head
Aaron Parecki 8 years ago
parent
commit
0d67cd8a24
4 changed files with 128 additions and 4 deletions
  1. +25
    -1
      controllers/Controller.php
  2. +3
    -0
      lib/Telegraph/Webmention.php
  3. +5
    -3
      views/dashboard.php
  4. +95
    -0
      views/webmention-details.php

+ 25
- 1
controllers/Controller.php View File

@ -89,8 +89,32 @@ class Controller {
return $response;
}
public function webmention_details(Request $request, Response $response) {
public function webmention_details(Request $request, Response $response, $args) {
if(!$this->_is_logged_in($request, $response)) {
return $response;
}
// Look up the webmention by its token
$webmention = ORM::for_table('webmentions')->where('token', $args['code'])->find_one();
if(!$webmention) {
$response->setContent(view('not-found'));
return $response;
}
$site = ORM::for_table('sites')->where_id_is($webmention->site_id)->find_one();
$statuses = ORM::for_table('webmention_status')->where('webmention_id', $webmention->id)->order_by_desc('created_at')->find_many();
$response->setContent(view('webmention-details', [
'title' => 'Webmention Details',
'user' => $this->_user(),
'accounts' => $this->_accounts(),
'site' => $site,
'webmention' => $webmention,
'statuses' => $statuses
]));
return $response;
}
private function _user() {

+ 3
- 0
lib/Telegraph/Webmention.php View File

@ -86,6 +86,9 @@ class Webmention {
if(array_key_exists('Location', $response['headers'])) {
$webmention->webmention_status_url = \Mf2\resolveUrl($endpoint, $response['headers']['Location']);
// TODO: queue a job to poll the endpoint for updates and deliver to the callback URL
} else {
// No status URL was returned, so we can't follow up with this later. Mark as complete.
$webmention->complete = 1;
}
} else {

+ 5
- 3
views/dashboard.php View File

@ -3,21 +3,23 @@
<div class="ui main text container" style="margin-top: 80px;">
<table class="ui striped table single line">
<thead>
<th>Status</th>
<th>Date</th>
<th>Source &amp; Target</th>
</thead>
<tbody>
<?php foreach($webmentions as $mention): ?>
<tr<?= $mention['status'] == 'pending' ? ' class="warning"' : '' ?>>
<td><i class="<?= $mention['icon'] ?> icon"></i></td>
<td><a href="/webmention/<?= $mention['webmention']->token ?>/details"><?= date('M j, g:ia', strtotime($mention['webmention']->created_at)) ?></a></td>
<td>
source=<?= $this->e($mention['webmention']->source) ?><br>
target=<?= $this->e($mention['webmention']->target) ?></td>
source=<a href="<?= $this->e($mention['webmention']->source) ?>"><?= $this->e($mention['webmention']->source) ?></a><br>
target=<a href="<?= $this->e($mention['webmention']->source) ?>"><?= $this->e($mention['webmention']->target) ?></a>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>

+ 95
- 0
views/webmention-details.php View File

@ -0,0 +1,95 @@
<?php $this->layout('layout-loggedin', ['title' => $title, 'accounts' => $accounts, 'user' => $user]); ?>
<div class="ui main text container" style="margin-top: 80px;">
<h2>Webmention Request</h2>
<table class="ui table single line"><tbody>
<tr>
<td><b>Date</b></td>
<td><?= date('M j, g:ia', strtotime($webmention->created_at)) ?></td>
</tr>
<tr>
<td><b>Source</b></td>
<td><a href="<?= $this->e($webmention->source) ?>"><?= $this->e($webmention->source) ?></a></td>
</tr>
<tr>
<td><b>Target</b></td>
<td><a href="<?= $this->e($webmention->target) ?>"><?= $this->e($webmention->target) ?></a></td>
</tr>
<? if($webmention->vouch): ?>
<tr>
<td><b>Vouch</b></td>
<td><a href="<?= $this->e($webmention->vouch) ?>"><?= $this->e($webmention->vouch) ?></a></td>
</tr>
<? endif; ?>
<? if($webmention->callback): ?>
<tr>
<td><b>Callback URL</b></td>
<td><?= $this->e($webmention->callback) ?></td>
</tr>
<? endif; ?>
</tbody></table>
<h2>Details</h2>
<? if(count($statuses) == 0): ?>
<p>The request is queued for processing. Check for updates again later.</p>
<? else: ?>
<table class="ui table single line"><tbody>
<? if($webmention->webmention_endpoint): ?>
<tr>
<td><b>Webmention Endpoint</b></td>
<td><?= $this->e($webmention->webmention_endpoint) ?></td>
</tr>
<? endif; ?>
<? if($webmention->pingback_endpoint): ?>
<tr>
<td><b>Pingback Endpoint</b></td>
<td><?= $this->e($webmention->pingback_endpoint) ?></td>
</tr>
<? endif; ?>
<? if($webmention->webmention_endpoint == false && $webmention->pingback_endpoint == false): ?>
<tr>
<td><b>Webmention Endpoint</b></td>
<td>No webmention endpoint was discovered for this target</td>
</tr>
<? endif; ?>
<? if($webmention->webmention_endpoint): ?>
<tr>
<td><b>Status URL</b></td>
<td><?= $webmention->webmention_status_url ? $this->e($webmention->webmention_status_url) : 'The webmention endpoint did not return a status URL' ?></td>
</tr>
<? endif; ?>
</tbody></table>
<h2>Logs</h2>
<table class="ui very compact table single line">
<thead>
<tr>
<th>Date</th>
<th>Status</th>
<th>HTTP Code</th>
</tr>
</thead>
<tbody>
<? foreach($statuses as $status): ?>
<tr>
<td><?= date('M j, g:ia', strtotime($status->created_at)) ?></td>
<td><?= $status->status ?></td>
<td><?= $status->http_code ?></td>
</tr>
<tr>
<td colspan="3">
<pre style="font-size: 10px;"><?= $this->e($status->raw_response) ?></pre>
</td>
</tr>
<? endforeach; ?>
</tbody>
</table>
<? endif; ?>
</div>

Loading…
Cancel
Save