Use Contact::getIdForURL instead of probing

- Add change to mod/admin
- Add change to util/global_community_block
This commit is contained in:
Hypolite Petovan 2017-12-01 22:32:24 -05:00
parent 843ec842c3
commit 8826ece55e
2 changed files with 22 additions and 37 deletions

View file

@ -381,17 +381,12 @@ function admin_page_contactblock_post(App $a)
check_form_security_token_redirectOnErr('/admin/contactblock', 'admin_contactblock'); check_form_security_token_redirectOnErr('/admin/contactblock', 'admin_contactblock');
if (x($_POST, 'page_contactblock_block')) { if (x($_POST, 'page_contactblock_block')) {
$net = Probe::uri($contact_url); $contact_id = Contact::getIdForURL($contact_url, 0);
if (in_array($net['network'], array(NETWORK_PHANTOM, NETWORK_MAIL))) { if ($contact_id) {
notice(t('This contact doesn\'t seem to exist.')); Contact::block($contact_id);
}
$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')); notice(t('The contact has been blocked from the node'));
} else { } else {
notice(t('Could not find any contact entry for this URL (%s)', $nurl)); notice(t('Could not find any contact entry for this URL (%s)', $contact_url));
} }
} }
if (x($_POST, 'page_contactblock_unblock')) { if (x($_POST, 'page_contactblock_unblock')) {
@ -428,7 +423,7 @@ function admin_page_contactblock(App $a)
// strings // // strings //
'$title' => t('Administration'), '$title' => t('Administration'),
'$page' => t('Remote Contact Blocklist'), '$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.'), '$description' => t('This page allows you to prevent any message from a remote contact to reach your node.'),
'$submit' => t('Block Remote Contact'), '$submit' => t('Block Remote Contact'),
'$select_all' => t('select all'), '$select_all' => t('select all'),
'$select_none' => t('select none'), '$select_none' => t('select none'),

View file

@ -1,6 +1,5 @@
#!/usr/bin/env php #!/usr/bin/env php
<?php <?php
/** /**
* @brief tool to block an account from the node * @brief tool to block an account from the node
* *
@ -17,8 +16,7 @@
* Author: Tobias Diekershoff * Author: Tobias Diekershoff
* *
* License: AGPLv3 or later, same as Friendica * License: AGPLv3 or later, same as Friendica
**/ */
if ($argc != 2 || $argv[1] == "-h" || $argv[1] == "--help" || $argv[1] == "-?") { if ($argc != 2 || $argv[1] == "-h" || $argv[1] == "--help" || $argv[1] == "-?") {
echo "Usage: " . $argv[0] . " [-h|profile_url]\r\n"; echo "Usage: " . $argv[0] . " [-h|profile_url]\r\n";
echo " -h, -?, --help ... show this help\r\n"; echo " -h, -?, --help ... show this help\r\n";
@ -30,36 +28,28 @@ if ($argc != 2 || $argv[1] == "-h" || $argv[1] == "--help" || $argv[1] == "-?")
exit(0); exit(0);
} }
use Friendica\Database\DBM; use Friendica\BaseObject;
use Friendica\Network\Probe; use Friendica\Object\Contact;
require_once 'boot.php'; require_once 'boot.php';
$a = get_app();;
BaseObject::setApp($a);
require_once '.htconfig.php';
require_once 'include/dba.php'; require_once 'include/dba.php';
require_once 'include/text.php'; require_once 'include/text.php';
$a = get_app();
require_once '.htconfig.php';
dba::connect($db_host, $db_user, $db_pass, $db_data); dba::connect($db_host, $db_user, $db_pass, $db_data);
unset($db_host, $db_user, $db_pass, $db_data); unset($db_host, $db_user, $db_pass, $db_data);
/** $contact_id = Contact::getIdForURL($argv[1], 0);
* 1. make nurl from last parameter if (!$contact_id) {
* 2. check DB (contact) if there is a contact with uid=0 and that nurl, get the ID echo t('Could not find any contact entry for this URL (%s)', $nurl);
* 3. set the flag hidden=1 for the contact entry with the found ID
**/
$net = Probe::uri($argv[1]);
if (in_array($net['network'], array(NETWORK_PHANTOM, NETWORK_MAIL))) {
echo 'This account seems not to exist.';
echo "\r\n"; echo "\r\n";
exit(1); exit(1);
} }
$nurl = normalise_link($net['url']); Contact::block($contact_id);
$r = dba::select('contact', array('id'), array('nurl' => $nurl, 'uid' => 0), array('limit' => 1)); echo t('The contact has been blocked from the node');
if (DBM::is_result($r)) { echo "\r\n";
dba::update('contact', array('blocked' => true), array('id' => $r['id'])); exit(0);
echo "NOTICE: The account should be blocked from the node now\r\n";
} else {
echo "NOTICE: Could not find any entry for this URL (".$nurl.")\r\n";
}
?>