Add admin/contactblock page

- Add page template
This commit is contained in:
Hypolite Petovan 2017-12-01 00:43:39 -05:00
parent 5fd4086fdc
commit dc09319695
3 changed files with 220 additions and 0 deletions

View File

@ -11,6 +11,8 @@ use Friendica\Core\Config;
use Friendica\Core\Worker;
use Friendica\Database\DBM;
use Friendica\Model\User;
use Friendica\Network\Probe;
use Friendica\Object\Contact;
require_once 'include/enotify.php';
require_once 'include/text.php';
@ -117,6 +119,9 @@ function admin_post(App $a)
case 'dbsync':
admin_page_dbsync_post($a);
break;
case 'contactblock':
admin_page_contactblock_post($a);
break;
case 'blocklist':
admin_page_blocklist_post($a);
break;
@ -179,6 +184,7 @@ function admin_content(App $a)
'features' => array("admin/features/" , t("Additional features") , "features"),
'dbsync' => array("admin/dbsync/" , t('DB updates') , "dbsync"),
'queue' => array("admin/queue/" , t('Inspect Queue') , "queue"),
'contactblock' => array("admin/contactblock/", t('Contact Blocklist') , "contactblock"),
'blocklist' => array("admin/blocklist/" , t('Server Blocklist') , "blocklist"),
'federation' => array("admin/federation/" , t('Federation Statistics'), "federation"),
'deleteitem' => array("admin/deleteitem/" , t('Delete Item') , 'deleteitem'),
@ -247,6 +253,9 @@ function admin_content(App $a)
case 'federation':
$o = admin_page_federation($a);
break;
case 'contactblock':
$o = admin_page_contactblock($a);
break;
case 'blocklist':
$o = admin_page_blocklist($a);
break;
@ -359,6 +368,90 @@ function admin_page_blocklist_post(App $a)
return; // NOTREACHED
}
/**
* @brief Process data send by the contact block admin page
*
* @param App $a
*/
function admin_page_contactblock_post(App $a)
{
$contact_url = x($_POST, 'contact_url') ? $_POST['contact_url'] : '';
$contacts = x($_POST, 'contacts') ? $_POST['contacts'] : [];
check_form_security_token_redirectOnErr('/admin/contactblock', 'admin_contactblock');
if (x($_POST, 'page_contactblock_block')) {
$net = Probe::uri($contact_url);
if (in_array($net['network'], array(NETWORK_PHANTOM, NETWORK_MAIL))) {
notice(t('This contact doesn\'t seem to exist.'));
}
$nurl = normalise_link($net['url']);
$r = dba::select('contact', ['id'], ['nurl' => $nurl, 'uid' => 0], ['limit' => 1]);
if (DBM::is_result($r)) {
Contact::block($r['id']);
notice(t('The contact has been blocked from the node'));
} else {
notice(t('Could not find any contact entry for this URL (%s)', $nurl));
}
}
if (x($_POST, 'page_contactblock_unblock')) {
foreach ($contacts as $uid) {
Contact::unblock($uid);
}
notice(tt("%s contact unblocked", "%s contacts unblocked", count($contacts)));
}
goaway('admin/contactblock');
return; // NOTREACHED
}
/**
* @brief Admin panel for server-wide contact block
*
* @param App $a
* @return string
*/
function admin_page_contactblock(App $a)
{
$condition = ['uid' => 0, 'blocked' => true];
$total = dba::count('contact', $condition);
$a->set_pager_total($total);
$a->set_pager_itemspage(30);
$statement = dba::select('contact', [], $condition, ['limit' => [$a->pager['start'], $a->pager['itemspage']]]);
$contacts = dba::inArray($statement);
$t = get_markup_template('admin/contactblock.tpl');
$o = replace_macros($t, array(
// strings //
'$title' => t('Administration'),
'$page' => t('Remote Contact Blocklist'),
'$description' => t('This page allows you to prevent any message from a remote contact to reach your node. However, your node must have knowledge of the contact before you can block it.'),
'$submit' => t('Block Remote Contact'),
'$select_all' => t('select all'),
'$select_none' => t('select none'),
'$block' => t('Block'),
'$unblock' => t('Unblock'),
'$no_data' => t('No remote contact is blocked from this node.'),
'$h_contacts' => t('Blocked Remote Contacts'),
'$h_newblock' => t('Block New Remote Contact'),
'$th_contacts' => [t('Photo'), t('Name'), t('Address'), t('Profile URL')],
'$form_security_token' => get_form_security_token("admin_contactblock"),
// values //
'$baseurl' => System::baseUrl(true),
'$contacts' => $contacts,
'$paginate' => paginate($a),
'$contacturl' => ['contact_url', t("Profile URL"), '', t("URL of the remote contact to block.")],
));
return $o;
}
/**
* @brief Subpage where the admin can delete an item from their node given the GUID
*

View File

@ -0,0 +1,64 @@
<script>
function selectall(cls) {
$('.' + cls).prop('checked', true);
return false;
}
function selectnone(cls) {
$('.' + cls).prop('checked', false);
return false;
}
</script>
<div id="adminpage">
<h1>{{$title}} - {{$page}}</h1>
<p>{{$description}}</p>
<form action="{{$baseurl}}/admin/contactblock" method="post">
<input type="hidden" name="form_security_token" value="{{$form_security_token}}">
<h3>{{$h_contacts}}</h3>
{{if $contacts}}
<table id="contactblock">
<thead>
<tr>
<th></th>
{{foreach $th_contacts as $th}}
<th>
{{$th}}
</th>
{{/foreach}}
<th></th>
</tr>
</thead>
<tbody>
{{foreach $contacts as $contact}}
<tr>
<td class="checkbox"><input type="checkbox" class="contacts_ckbx" id="id_contact_{{$contact.id}}" name="contacts[]" value="{{$contact.id}}"/></td>
<td><img class="icon" src="{{$contact.micro}}" alt="{{$contact.nickname}}" title="{{$contact.nickname}}"></td>
<td class="name">{{$contact.name}}</td>
<td class="addr">{{$contact.addr}}</td>
<td class="addr"><a href="{{$contact.url}}" title="{{$contact.nickname}}" >{{$contact.url}}</a></td>
</tr>
{{/foreach}}
</tbody>
</table>
<p><a href="#" onclick="return selectall('contacts_ckbx');">{{$select_all}}</a> | <a href="#" onclick="return selectnone('contacts_ckbx');">{{$select_none}}</a></p>
{{$paginate}}
<div class="submit"><input type="submit" name="page_contactblock_unblock" value="{{$unblock|escape:'html'}}" /></div>
{{else}}
<p>{{$no_data|escape:'html'}}</p>
{{/if}}
</form>
<h3>{{$h_newblock}}</h3>
<form action="{{$baseurl}}/admin/contactblock" method="post">
<input type="hidden" name="form_security_token" value="{{$form_security_token}}">
<table id="contactblock">
<tbody>
<tr>
<td>{{include file="field_input.tpl" field=$contacturl}}</td>
</tr>
</tbody>
</table>
<div class="submit"><input type="submit" name="page_contactblock_block" value="{{$submit|escape:'html'}}" /></div>
</form>
</div>

View File

@ -0,0 +1,63 @@
<script>
function selectall(cls) {
$('.' + cls).prop('checked', true);
return false;
}
function selectnone(cls) {
$('.' + cls).prop('checked', false);
return false;
}
</script>
<div id="adminpage">
<h1>{{$title}} - {{$page}}</h1>
<p>{{$description}}</p>
<form action="{{$baseurl}}/admin/contactblock" method="post">
<input type="hidden" name="form_security_token" value="{{$form_security_token}}">
<h3>{{$h_contacts}}</h3>
{{if $contacts}}
<table id="contactblock" class="table table-condensed table-striped">
<thead>
<tr>
<th></th>
{{foreach $th_contacts as $th}}
<th>
{{$th}}
</th>
{{/foreach}}
<th></th>
</tr>
</thead>
<tbody>
{{foreach $contacts as $contact}}
<tr>
<td><input type="checkbox" class="contacts_ckbx" id="id_contact_{{$contact.id}}" name="contacts[]" value="{{$contact.id}}"/></td>
<td><img class="icon" src="{{$contact.micro}}" alt="{{$contact.nickname}}" title="{{$contact.addr}}"></td>
<td class="name">{{$contact.name}}</td>
<td class="addr" colspan="2"><a href="{{$contact.url}}" title="{{$contact.addr}}" >{{$contact.url}}</a></td>
</tr>
{{/foreach}}
</tbody>
</table>
<p><a href="#" onclick="return selectall('contacts_ckbx');">{{$select_all}}</a> | <a href="#" onclick="return selectnone('contacts_ckbx');">{{$select_none}}</a></p>
{{$paginate}}
<div class="submit"><input type="submit" name="page_contactblock_unblock" value="{{$unblock|escape:'html'}}" /></div>
{{else}}
<p>{{$no_data|escape:'html'}}</p>
{{/if}}
</form>
<h3>{{$h_newblock}}</h3>
<form action="{{$baseurl}}/admin/contactblock" method="post">
<input type="hidden" name="form_security_token" value="{{$form_security_token}}">
<table id="contactblock">
<tbody>
<tr>
<td>{{include file="field_input.tpl" field=$contacturl}}</td>
</tr>
</tbody>
</table>
<div class="submit"><input type="submit" name="page_contactblock_block" value="{{$submit|escape:'html'}}" /></div>
</form>
</div>