Merge pull request #3986 from MrPetovan/task/admin-block-list

Admin remote contact block list
This commit is contained in:
Michael Vogel 2017-12-02 22:09:04 +01:00 committed by GitHub
commit 2ca03acb45
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
30 changed files with 736 additions and 387 deletions

View File

@ -1104,7 +1104,8 @@ class dba {
*
* $data = dba::select($table, $fields, $condition, $params);
*/
public static function select($table, $fields = array(), $condition = array(), $params = array()) {
public static function select($table, array $fields = [], array $condition = [], array $params = [])
{
if ($table == '') {
return false;
}
@ -1115,17 +1116,7 @@ class dba {
$select_fields = "*";
}
if (count($condition) > 0) {
$array_element = each($condition);
$array_key = $array_element['key'];
if (is_int($array_key)) {
$condition_string = " WHERE ".array_shift($condition);
} else {
$condition_string = " WHERE `".implode("` = ? AND `", array_keys($condition))."` = ?";
}
} else {
$condition_string = "";
}
$condition_string = self::buildCondition($condition);
$param_string = '';
$single_row = false;
@ -1147,6 +1138,11 @@ class dba {
$single_row = ($params['limit'] == 1);
}
if (isset($params['limit']) && is_array($params['limit'])) {
$param_string .= " LIMIT ".intval($params['limit'][0]).", ".intval($params['limit'][1]);
$single_row = ($params['limit'][1] == 1);
}
if (isset($params['only_query']) && $params['only_query']) {
$single_row = !$params['only_query'];
}
@ -1164,6 +1160,71 @@ class dba {
}
}
/**
* @brief Counts the rows from a table satisfying the provided condition
*
* @param string $table Table name
* @param array $condition array of fields for condition
*
* @return int
*
* Example:
* $table = "item";
*
* $condition = ["uid" => 1, "network" => 'dspr'];
* or:
* $condition = ["`uid` = ? AND `network` IN (?, ?)", 1, 'dfrn', 'dspr'];
*
* $count = dba::count($table, $condition);
*/
public static function count($table, array $condition = [])
{
if ($table == '') {
return false;
}
$condition_string = self::buildCondition($condition);
$sql = "SELECT COUNT(*) AS `count` FROM `".$table."`".$condition_string;
$row = self::fetch_first($sql, $condition);
return $row['count'];
}
/**
* @brief Returns the SQL condition string built from the provided condition array
*
* This function operates with two modes.
* - Supplied with a filed/value associative array, it builds simple strict
* equality conditions linked by AND.
* - Supplied with a flat list, the first element is the condition string and
* the following arguments are the values to be interpolated
*
* $condition = ["uid" => 1, "network" => 'dspr'];
* or:
* $condition = ["`uid` = ? AND `network` IN (?, ?)", 1, 'dfrn', 'dspr'];
*
* In either case, the provided array is left with the parameters only
*
* @param array $condition
* @return string
*/
private static function buildCondition(array &$condition = [])
{
$condition_string = '';
if (count($condition) > 0) {
$array_element = each($condition);
$array_key = $array_element['key'];
if (is_int($array_key)) {
$condition_string = " WHERE ".array_shift($condition);
} else {
$condition_string = " WHERE `".implode("` = ? AND `", array_keys($condition))."` = ?";
}
}
return $condition_string;
}
/**
* @brief Fills an array with data from a query

View File

@ -120,48 +120,90 @@ function load_translation_table($lang) {
}}
// translate string if translation exists
if (! function_exists('t')) {
function t($s) {
/**
* @brief Return the localized version of the provided string with optional string interpolation
*
* This function takes a english string as parameter, and if a localized version
* exists for the current language, substitutes it before performing an eventual
* string interpolation (sprintf) with additional optional arguments.
*
* Usages:
* - t('This is an example')
* - t('URL %s returned no result', $url)
* - t('Current version: %s, new version: %s', $current_version, $new_version)
*
* @param string $s
* @return string
*/
function t($s)
{
$a = get_app();
if (x($a->strings, $s)) {
$t = $a->strings[$s];
return is_array($t)?$t[0]:$t;
$s = is_array($t) ? $t[0] : $t;
}
if (func_num_args() > 1) {
$args = array_slice(func_get_args(), 1);
$s = @vsprintf($s, $args);
}
return $s;
}}
if (! function_exists('tt')){
function tt($singular, $plural, $count){
return $s;
}
/**
* @brief Return the localized version of a singular/plural string with optional string interpolation
*
* This function takes two english strings as parameters, singular and plural, as
* well as a count. If a localized version exists for the current language, they
* are used instead. Discrimination between singular and plural is done using the
* localized function if any or the default one. Finally, a string interpolation
* is performed using the count as parameter.
*
* Usages:
* - tt('Like', 'Likes', $count)
* - tt("%s user deleted", "%s users deleted", count($users))
*
* @global type $lang
* @param string $singular
* @param string $plural
* @param int $count
* @return string
*/
function tt($singular, $plural, $count)
{
global $lang;
$a = get_app();
if (x($a->strings, $singular)) {
$t = $a->strings[$singular];
$f = 'string_plural_select_' . str_replace('-','_',$lang);
if (! function_exists($f))
$f = 'string_plural_select_default';
$k = $f($count);
return is_array($t)?$t[$k]:$t;
if (is_array($t)) {
$plural_function = 'string_plural_select_' . str_replace('-', '_', $lang);
if (function_exists($plural_function)) {
$plural_function = 'string_plural_select_default';
}
$i = $plural_function($count);
$s = $t[$i];
} else {
$s = $t;
}
} elseif (string_plural_select_default($count)) {
$s = $plural;
} else {
$s = $singular;
}
if ($count!=1){
return $plural;
} else {
return $singular;
$s = @sprintf($s, $count);
return $s;
}
}}
// provide a fallback which will not collide with
// a function defined in any language file
if (! function_exists('string_plural_select_default')) {
function string_plural_select_default($n) {
return ($n != 1);
}}
function string_plural_select_default($n)
{
return $n != 1;
}

View File

@ -5,13 +5,13 @@
*
* @brief Friendica admin
*/
use Friendica\App;
use Friendica\Core\System;
use Friendica\Core\Config;
use Friendica\Core\Worker;
use Friendica\Database\DBM;
use Friendica\Model\User;
use Friendica\Object\Contact;
require_once 'include/enotify.php';
require_once 'include/text.php';
@ -30,9 +30,8 @@ require_once 'include/items.php';
* @param App $a
*
*/
function admin_post(App $a) {
function admin_post(App $a)
{
if (!is_site_admin()) {
return;
}
@ -75,7 +74,9 @@ function admin_post(App $a) {
$theme = $a->argv[2];
if (is_file("view/theme/$theme/config.php")) {
function __call_theme_admin_post(App $a, $theme) {
function __call_theme_admin_post(App $a, $theme)
{
$orig_theme = $a->theme;
$orig_page = $a->page;
$orig_session_theme = $_SESSION['theme'];
@ -115,6 +116,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;
@ -145,8 +149,8 @@ function admin_post(App $a) {
* @param App $a
* @return string
*/
function admin_content(App $a) {
function admin_content(App $a)
{
if (!is_site_admin()) {
return login(false);
}
@ -160,9 +164,8 @@ function admin_content(App $a) {
// $toDelete = new APCIterator('user', APC_ITER_VALUE);
// apc_delete($toDelete);
//}
// Header stuff
$a->page['htmlhead'] .= replace_macros(get_markup_template('admin_settings_head.tpl'), array());
$a->page['htmlhead'] .= replace_macros(get_markup_template('admin/settings_head.tpl'), array());
/*
* Side bar links
@ -178,6 +181,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'),
@ -199,7 +203,7 @@ function admin_content(App $a) {
$aside_tools['diagnostics_probe'] = array('probe/', t('probe address'), 'probe');
$aside_tools['diagnostics_webfinger'] = array('webfinger/', t('check webfinger'), 'webfinger');
$t = get_markup_template("admin_aside.tpl");
$t = get_markup_template('admin/aside.tpl');
$a->page['aside'] .= replace_macros($t, array(
'$admin' => $aside_tools,
'$subpages' => $aside_sub,
@ -211,11 +215,7 @@ function admin_content(App $a) {
'$admurl' => "admin/"
));
/*
* Page content
*/
// Page content
$o = '';
// urls
if ($a->argc > 1) {
@ -250,6 +250,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;
@ -283,7 +286,8 @@ function admin_content(App $a) {
* @param App $a
* @return string
*/
function admin_page_blocklist(App $a) {
function admin_page_blocklist(App $a)
{
$blocklist = Config::get('system', 'blocklist');
$blocklistform = array();
if (is_array($blocklist)) {
@ -295,7 +299,7 @@ function admin_page_blocklist(App $a) {
);
}
}
$t = get_markup_template("admin_blocklist.tpl");
$t = get_markup_template('admin/blocklist.tpl');
return replace_macros($t, array(
'$title' => t('Administration'),
'$page' => t('Server Blocklist'),
@ -322,7 +326,8 @@ function admin_page_blocklist(App $a) {
*
* @param App $a
*/
function admin_page_blocklist_post(App $a) {
function admin_page_blocklist_post(App $a)
{
if (!x($_POST, "page_blocklist_save") && (!x($_POST['page_blocklist_edit']))) {
return;
}
@ -360,6 +365,86 @@ 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')) {
$contact_id = Contact::getIdForURL($contact_url, 0);
if ($contact_id) {
Contact::block($contact_id);
notice(t('The contact has been blocked from the node'));
} else {
notice(t('Could not find any contact entry for this URL (%s)', $contact_url));
}
}
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.'),
'$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,
'$total_contacts' => tt('%s total blocked contact', '%s total blocked contacts', $total),
'$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
*
@ -370,8 +455,9 @@ function admin_page_blocklist_post(App $a) {
* @param App $a
* @return string
*/
function admin_page_deleteitem(App $a) {
$t = get_markup_template("admin_deleteitem.tpl");
function admin_page_deleteitem(App $a)
{
$t = get_markup_template('admin/deleteitem.tpl');
return replace_macros($t, array(
'$title' => t('Administration'),
@ -384,6 +470,7 @@ function admin_page_deleteitem(App $a) {
'$form_security_token' => get_form_security_token("admin_deleteitem")
));
}
/**
* @brief Process send data from Admin Delete Item Page
*
@ -392,7 +479,8 @@ function admin_page_deleteitem(App $a) {
*
* @param App $a
*/
function admin_page_deleteitem_post(App $a) {
function admin_page_deleteitem_post(App $a)
{
if (!x($_POST['page_deleteitem_submit'])) {
return;
}
@ -435,7 +523,8 @@ function admin_page_deleteitem_post(App $a) {
* @param App $a
* @return string
*/
function admin_page_federation(App $a) {
function admin_page_federation(App $a)
{
// get counts on active friendica, diaspora, redmatrix, hubzilla, gnu
// social and statusnet nodes this node is knowing
//
@ -445,7 +534,8 @@ function admin_page_federation(App $a) {
// Add more platforms if you like, when one returns 0 known nodes it is not
// displayed on the stats page.
$platforms = array('Friendi%%a', 'Diaspora', '%%red%%', 'Hubzilla', 'BlaBlaNet', 'GNU Social', 'StatusNet', 'Mastodon', 'Pleroma');
$colors = array('Friendi%%a' => '#ffc018', // orange from the logo
$colors = array(
'Friendi%%a' => '#ffc018', // orange from the logo
'Diaspora' => '#a1a1a1', // logo is black and white, makes a gray
'%%red%%' => '#c50001', // fire red from the logo
'Hubzilla' => '#43488a', // blue from the logo
@ -453,7 +543,8 @@ function admin_page_federation(App $a) {
'GNU Social' => '#a22430', // dark red from the logo
'StatusNet' => '#789240', // the green from the logo (red and blue have already others
'Mastodon' => '#1a9df9', // blue from the Mastodon logo
'Pleroma' => '#E46F0F'); // Orange from the text that is used on Pleroma instances
'Pleroma' => '#E46F0F' // Orange from the text that is used on Pleroma instances
);
$counts = array();
$total = 0;
@ -547,7 +638,7 @@ function admin_page_federation(App $a) {
$hint = t('The <em>Auto Discovered Contact Directory</em> feature is not enabled, it will improve the data displayed here.');
// load the template, replace the macros and return the page content
$t = get_markup_template("admin_federation.tpl");
$t = get_markup_template('admin/federation.tpl');
return replace_macros($t, array(
'$title' => t('Administration'),
'$page' => t('Federation Statistics'),
@ -574,14 +665,15 @@ function admin_page_federation(App $a) {
* @param App $a
* @return string
*/
function admin_page_queue(App $a) {
function admin_page_queue(App $a)
{
// get content from the queue table
$r = q("SELECT `c`.`name`, `c`.`nurl`, `q`.`id`, `q`.`network`, `q`.`created`, `q`.`last`
FROM `queue` AS `q`, `contact` AS `c`
WHERE `c`.`id` = `q`.`cid`
ORDER BY `q`.`cid`, `q`.`created`;");
$t = get_markup_template("admin_queue.tpl");
$t = get_markup_template('admin/queue.tpl');
return replace_macros($t, array(
'$title' => t('Administration'),
'$page' => t('Inspect Queue'),
@ -608,10 +700,10 @@ function admin_page_queue(App $a) {
* @param App $a
* @return string
*/
function admin_page_summary(App $a) {
function admin_page_summary(App $a)
{
// are there MyISAM tables in the DB? If so, trigger a warning message
$r = q("SELECT `engine` FROM `information_schema`.`tables` WHERE `engine` = 'myisam' AND `table_schema` = '%s' LIMIT 1",
dbesc(dba::database_name()));
$r = q("SELECT `engine` FROM `information_schema`.`tables` WHERE `engine` = 'myisam' AND `table_schema` = '%s' LIMIT 1", dbesc(dba::database_name()));
$showwarning = false;
$warningtext = array();
if (DBM::is_result($r)) {
@ -678,7 +770,7 @@ function admin_page_summary(App $a) {
$queues = array('label' => t('Message queues'), 'queue' => $queue, 'workerq' => $workerqueue);
$t = get_markup_template("admin_summary.tpl");
$t = get_markup_template('admin/summary.tpl');
return replace_macros($t, array(
'$title' => t('Administration'),
'$page' => t('Summary'),
@ -702,7 +794,8 @@ function admin_page_summary(App $a) {
*
* @param App $a
*/
function admin_page_site_post(App $a) {
function admin_page_site_post(App $a)
{
check_form_security_token_redirectOnErr('/admin/site', 'admin_site');
if (!empty($_POST['republish_directory'])) {
@ -736,7 +829,8 @@ function admin_page_site_post(App $a) {
$new_host = str_replace("http://", "@", normalise_link($new_url));
$old_host = str_replace("http://", "@", normalise_link($old_url));
function update_table($table_name, $fields, $old_url, $new_url) {
function update_table($table_name, $fields, $old_url, $new_url)
{
global $a;
$dbold = dbesc($old_url);
@ -758,7 +852,6 @@ function admin_page_site_post(App $a) {
goaway('admin/site');
}
}
// update tables
// update profile links in the format "http://server.tld"
update_table("profile", array('photo', 'thumb'), $old_url, $new_url);
@ -933,9 +1026,7 @@ function admin_page_site_post(App $a) {
if ($banner == "") {
// don't know why, but del_config doesn't work...
q("DELETE FROM `config` WHERE `cat` = '%s' AND `k` = '%s' LIMIT 1",
dbesc("system"),
dbesc("banner")
q("DELETE FROM `config` WHERE `cat` = '%s' AND `k` = '%s' LIMIT 1", dbesc("system"), dbesc("banner")
);
} else {
Config::set('system', 'banner', $banner);
@ -1026,7 +1117,6 @@ function admin_page_site_post(App $a) {
info(t('Site settings updated.') . EOL);
goaway('admin/site');
return; // NOTREACHED
}
/**
@ -1037,8 +1127,8 @@ function admin_page_site_post(App $a) {
* @param App $a
* @return string
*/
function admin_page_site(App $a) {
function admin_page_site(App $a)
{
/* Installed langs */
$lang_choices = get_available_languages();
@ -1058,8 +1148,9 @@ function admin_page_site(App $a) {
$allowed_theme_list = Config::get('system', 'allowed_themes');
foreach ($files as $file) {
if (intval(file_exists($file.'/unsupported')))
if (intval(file_exists($file . '/unsupported'))) {
continue;
}
$f = basename($file);
@ -1166,7 +1257,7 @@ function admin_page_site(App $a) {
$optimize_max_tablesize = 100;
}
$t = get_markup_template("admin_site.tpl");
$t = get_markup_template('admin/site.tpl');
return replace_macros($t, array(
'$title' => t('Administration'),
'$page' => t('Site'),
@ -1264,9 +1355,7 @@ function admin_page_site(App $a) {
'$worker_frontend' => array('worker_frontend', t('Enable frontend worker'), Config::get('system','frontend_worker'), sprintf(t('When enabled the Worker process is triggered when backend access is performed (e.g. messages being delivered). On smaller sites you might want to call %s/worker on a regular basis via an external cron job. You should only enable this option if you cannot utilize cron/scheduled jobs on your server.'), System::baseUrl())),
'$form_security_token' => get_form_security_token("admin_site")
));
}
/**
@ -1281,8 +1370,8 @@ function admin_page_site(App $a) {
* @param App $a
* @return string
* */
function admin_page_dbsync(App $a) {
function admin_page_dbsync(App $a)
{
$o = '';
if ($a->argc > 3 && intval($a->argv[3]) && $a->argv[2] === 'mark') {
@ -1302,8 +1391,7 @@ function admin_page_dbsync(App $a) {
$o .= sprintf(t("Database structure update %s was successfully applied."), DB_UPDATE_VERSION) . "<br />";
Config::set('database', 'dbupdate_' . DB_UPDATE_VERSION, 'success');
} else {
$o .= sprintf(t("Executing of database structure update %s failed with error: %s"),
DB_UPDATE_VERSION, $retval)."<br />";
$o .= sprintf(t("Executing of database structure update %s failed with error: %s"), DB_UPDATE_VERSION, $retval) . "<br />";
}
if ($a->argv[2] === 'check') {
return $o;
@ -1311,14 +1399,13 @@ function admin_page_dbsync(App $a) {
}
if ($a->argc > 2 && intval($a->argv[2])) {
require_once('update.php');
require_once 'update.php';
$func = 'update_' . intval($a->argv[2]);
if (function_exists($func)) {
$retval = $func();
if ($retval === UPDATE_FAILED) {
$o .= sprintf(t("Executing %s failed with error: %s"), $func, $retval);
}
elseif ($retval === UPDATE_SUCCESS) {
} elseif ($retval === UPDATE_SUCCESS) {
$o .= sprintf(t('Update %s was successfully applied.', $func));
Config::set('database', $func, 'success');
} else {
@ -1360,7 +1447,6 @@ function admin_page_dbsync(App $a) {
}
return $o;
}
/**
@ -1368,7 +1454,8 @@ function admin_page_dbsync(App $a) {
*
* @param App $a
*/
function admin_page_users_post(App $a) {
function admin_page_users_post(App $a)
{
$pending = (x($_POST, 'pending') ? $_POST['pending'] : array());
$users = (x($_POST, 'user') ? $_POST['user'] : array());
$nu_name = (x($_POST, 'new_user_name') ? $_POST['new_user_name'] : '');
@ -1379,7 +1466,7 @@ function admin_page_users_post(App $a) {
check_form_security_token_redirectOnErr('/admin/users', 'admin_users');
if (!($nu_name === "") && !($nu_email === "") && !($nu_nickname === "")) {
require_once('include/user.php');
require_once 'include/user.php';
$result = create_user(array('username' => $nu_name, 'email' => $nu_email,
'nickname' => $nu_nickname, 'verified' => 1, 'language' => $nu_language));
@ -1426,13 +1513,11 @@ function admin_page_users_post(App $a) {
'subject' => sprintf(t('Registration details for %s'), $a->config['sitename']),
'preamble' => $preamble,
'body' => $body));
}
if (x($_POST, 'page_users_block')) {
foreach ($users as $uid) {
q("UPDATE `user` SET `blocked` = 1-`blocked` WHERE `uid` = %s",
intval($uid)
q("UPDATE `user` SET `blocked` = 1-`blocked` WHERE `uid` = %s", intval($uid)
);
}
notice(sprintf(tt("%s user blocked/unblocked", "%s users blocked/unblocked", count($users)), count($users)));
@ -1472,7 +1557,8 @@ function admin_page_users_post(App $a) {
* @param App $a
* @return string
*/
function admin_page_users(App $a) {
function admin_page_users(App $a)
{
if ($a->argc > 2) {
$uid = $a->argv[3];
$user = q("SELECT `username`, `blocked` FROM `user` WHERE `uid` = %d", intval($uid));
@ -1491,16 +1577,13 @@ function admin_page_users(App $a) {
break;
case "block":
check_form_security_token_redirectOnErr('/admin/users', 'admin_users', 't');
q("UPDATE `user` SET `blocked` = %d WHERE `uid` = %s",
intval(1-$user[0]['blocked']),
intval($uid)
q("UPDATE `user` SET `blocked` = %d WHERE `uid` = %s", intval(1 - $user[0]['blocked']), intval($uid)
);
notice(sprintf(($user[0]['blocked'] ? t("User '%s' unblocked") : t("User '%s' blocked")), $user[0]['username']) . EOL);
break;
}
goaway('admin/users');
return ''; // NOTREACHED
}
/* get pending */
@ -1550,9 +1633,7 @@ function admin_page_users(App $a) {
FROM `user`
INNER JOIN `contact` ON `contact`.`uid` = `user`.`uid` AND `contact`.`self`
WHERE `user`.`verified`
ORDER BY $sql_order $sql_order_direction LIMIT %d, %d",
intval($a->pager['start']),
intval($a->pager['itemspage'])
ORDER BY $sql_order $sql_order_direction LIMIT %d, %d", intval($a->pager['start']), intval($a->pager['itemspage'])
);
//echo "<pre>$users"; killme();
@ -1602,12 +1683,10 @@ function admin_page_users(App $a) {
array_push($users, array_pop($tmp_users));
}
$th_users = array_map(null,
array(t('Name'), t('Email'), t('Register date'), t('Last login'), t('Last item'), t('Account')),
$valid_orders
$th_users = array_map(null, array(t('Name'), t('Email'), t('Register date'), t('Last login'), t('Last item'), t('Account')), $valid_orders
);
$t = get_markup_template("admin_users.tpl");
$t = get_markup_template('admin/users.tpl');
$o = replace_macros($t, array(
// strings //
'$title' => t('Administration'),
@ -1653,7 +1732,6 @@ function admin_page_users(App $a) {
return $o;
}
/**
* @brief Plugins admin page
*
@ -1670,8 +1748,8 @@ function admin_page_users(App $a) {
* @param App $a
* @return string
*/
function admin_page_plugins(App $a) {
function admin_page_plugins(App $a)
{
/*
* Single plugin
*/
@ -1705,9 +1783,11 @@ function admin_page_plugins(App $a) {
require_once('library/markdown.php');
if (in_array($plugin, $a->plugins)) {
$status="on"; $action= t("Disable");
$status = "on";
$action = t("Disable");
} else {
$status="off"; $action= t("Enable");
$status = "off";
$action = t("Enable");
}
$readme = Null;
@ -1725,7 +1805,7 @@ function admin_page_plugins(App $a) {
$func($a, $admin_form);
}
$t = get_markup_template("admin_plugins_details.tpl");
$t = get_markup_template('admin/plugins_details.tpl');
return replace_macros($t, array(
'$title' => t('Administration'),
@ -1750,12 +1830,9 @@ function admin_page_plugins(App $a) {
));
}
/*
* List plugins
*/
if (x($_GET, "a") && $_GET['a'] == "r") {
check_form_security_token_redirectOnErr(System::baseUrl() . '/admin/plugins', 'admin_themes', 't');
reload_plugins();
@ -1789,7 +1866,7 @@ function admin_page_plugins(App $a) {
}
}
$t = get_markup_template("admin_plugins.tpl");
$t = get_markup_template('admin/plugins.tpl');
return replace_macros($t, array(
'$title' => t('Administration'),
'$page' => t('Plugins'),
@ -1809,14 +1886,14 @@ function admin_page_plugins(App $a) {
* @param string $th
* @param int $result
*/
function toggle_theme(&$themes,$th,&$result) {
function toggle_theme(&$themes, $th, &$result)
{
for ($x = 0; $x < count($themes); $x ++) {
if ($themes[$x]['name'] === $th) {
if ($themes[$x]['allowed']) {
$themes[$x]['allowed'] = 0;
$result = 0;
}
else {
} else {
$themes[$x]['allowed'] = 1;
$result = 1;
}
@ -1829,13 +1906,13 @@ function toggle_theme(&$themes,$th,&$result) {
* @param string $th
* @return int
*/
function theme_status($themes,$th) {
function theme_status($themes, $th)
{
for ($x = 0; $x < count($themes); $x ++) {
if ($themes[$x]['name'] === $th) {
if ($themes[$x]['allowed']) {
return 1;
}
else {
} else {
return 0;
}
}
@ -1843,12 +1920,12 @@ function theme_status($themes,$th) {
return 0;
}
/**
* @param array $themes
* @return string
*/
function rebuild_theme_table($themes) {
function rebuild_theme_table($themes)
{
$o = '';
if (count($themes)) {
foreach ($themes as $th) {
@ -1863,7 +1940,6 @@ function rebuild_theme_table($themes) {
return $o;
}
/**
* @brief Themes admin page
*
@ -1880,8 +1956,8 @@ function rebuild_theme_table($themes) {
* @param App $a
* @return string
*/
function admin_page_themes(App $a) {
function admin_page_themes(App $a)
{
$allowed_themes_str = Config::get('system', 'allowed_themes');
$allowed_themes_raw = explode(',', $allowed_themes_str);
$allowed_themes = array();
@ -1954,12 +2030,14 @@ function admin_page_themes(App $a) {
}
// display theme details
require_once('library/markdown.php');
require_once 'library/markdown.php';
if (theme_status($themes, $theme)) {
$status="on"; $action= t("Disable");
$status = "on";
$action = t("Disable");
} else {
$status="off"; $action= t("Enable");
$status = "off";
$action = t("Enable");
}
$readme = Null;
@ -1972,7 +2050,9 @@ function admin_page_themes(App $a) {
$admin_form = "";
if (is_file("view/theme/$theme/config.php")) {
function __get_theme_admin_form(App $a, $theme) {
function __get_theme_admin_form(App $a, $theme)
{
$orig_theme = $a->theme;
$orig_page = $a->page;
$orig_session_theme = $_SESSION['theme'];
@ -2002,7 +2082,7 @@ function admin_page_themes(App $a) {
$screenshot = null;
}
$t = get_markup_template("admin_plugins_details.tpl");
$t = get_markup_template('admin/plugins_details.tpl');
return replace_macros($t, array(
'$title' => t('Administration'),
'$page' => t('Themes'),
@ -2051,8 +2131,7 @@ function admin_page_themes(App $a) {
}
}
$t = get_markup_template("admin_plugins.tpl");
$t = get_markup_template('admin/plugins.tpl');
return replace_macros($t, array(
'$title' => t('Administration'),
'$page' => t('Themes'),
@ -2069,13 +2148,13 @@ function admin_page_themes(App $a) {
));
}
/**
* @brief Prosesses data send by Logs admin page
*
* @param App $a
*/
function admin_page_logs_post(App $a) {
function admin_page_logs_post(App $a)
{
if (x($_POST, "page_logs")) {
check_form_security_token_redirectOnErr('/admin/logs', 'admin_logs');
@ -2109,8 +2188,8 @@ function admin_page_logs_post(App $a) {
* @param App $a
* @return string
*/
function admin_page_logs(App $a) {
function admin_page_logs(App $a)
{
$log_choices = array(
LOGGER_NORMAL => 'Normal',
LOGGER_TRACE => 'Trace',
@ -2125,7 +2204,7 @@ function admin_page_logs(App $a) {
$phplogenabled = t('PHP log currently disabled.');
}
$t = get_markup_template("admin_logs.tpl");
$t = get_markup_template('admin/logs.tpl');
return replace_macros($t, array(
'$title' => t('Administration'),
@ -2134,12 +2213,10 @@ function admin_page_logs(App $a) {
'$clear' => t('Clear'),
'$baseurl' => System::baseUrl(true),
'$logname' => Config::get('system', 'logfile'),
// name, label, value, help string, extra data...
'$debugging' => array('debugging', t("Enable Debugging"), Config::get('system', 'debugging'), ""),
'$logfile' => array('logfile', t("Log file"), Config::get('system', 'logfile'), t("Must be writable by web server. Relative to your Friendica top-level directory.")),
'$loglevel' => array('loglevel', t("Log level"), Config::get('system', 'loglevel'), "", $log_choices),
'$form_security_token' => get_form_security_token("admin_logs"),
'$phpheader' => t("PHP logging"),
'$phphint' => t("To enable logging of PHP errors and warnings you can add the following to the .htconfig.php file of your installation. The filename set in the 'error_log' line is relative to the friendica top-level directory and must be writeable by the web server. The option '1' for 'log_errors' and 'display_errors' is to enable these options, set to '0' to disable them."),
@ -2166,8 +2243,9 @@ function admin_page_logs(App $a) {
* @param App $a
* @return string
*/
function admin_page_viewlogs(App $a) {
$t = get_markup_template("admin_viewlogs.tpl");
function admin_page_viewlogs(App $a)
{
$t = get_markup_template('admin/viewlogs.tpl');
$f = Config::get('system', 'logfile');
$data = '';
@ -2208,8 +2286,8 @@ function admin_page_viewlogs(App $a) {
*
* @param App $a
*/
function admin_page_features_post(App $a) {
function admin_page_features_post(App $a)
{
check_form_security_token_redirectOnErr('/admin/features', 'admin_manage_features');
logger('postvars: ' . print_r($_POST, true), LOGGER_DATA);
@ -2256,8 +2334,8 @@ function admin_page_features_post(App $a) {
* @param App $a
* @return string
*/
function admin_page_features(App $a) {
function admin_page_features(App $a)
{
if ((argc() > 1) && (argv(1) === 'features')) {
$arr = array();
$features = get_features(false);
@ -2266,7 +2344,6 @@ function admin_page_features(App $a) {
$arr[$fname] = array();
$arr[$fname][0] = $fdata[0];
foreach (array_slice($fdata, 1) as $f) {
$set = Config::get('feature', $f[0], $f[3]);
$arr[$fname][1][] = array(
array('feature_' . $f[0], $f[1], $set, $f[2], array(t('Off'), t('On'))),
@ -2275,7 +2352,7 @@ function admin_page_features(App $a) {
}
}
$tpl = get_markup_template("admin_settings_features.tpl");
$tpl = get_markup_template('admin/settings_features.tpl');
$o .= replace_macros($tpl, array(
'$form_security_token' => get_form_security_token("admin_manage_features"),
'$title' => t('Manage Additional Features'),

View File

@ -821,6 +821,32 @@ class Contact extends BaseObject
return $account_type;
}
/**
* @brief Blocks a contact
*
* @param int $uid
* @return bool
*/
public static function block($uid)
{
$return = dba::update('contact', ['blocked' => true], ['id' => $uid]);
return $return;
}
/**
* @brief Unblocks a contact
*
* @param int $uid
* @return bool
*/
public static function unblock($uid)
{
$return = dba::update('contact', ['blocked' => false], ['id' => $uid]);
return $return;
}
/**
* @brief Updates the avatar links in a contact only if needed
*

View File

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

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">
<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,31 @@
/**
* @brief Javascript for the admin module
*/
$(function() {
$('body').on('click', '.selectall', function() {
selectall($(this).data('selectAll'));
});
$('body').on('click', '.selectnone', function() {
selectnone($(this).data('selectNone'));
});
$('body').on('change', 'input[type=checkbox].select', function() {
$this = $(this);
if ($this.prop('checked')) {
selectall($this.data('selectClass'));
$this.attr('title', $this.data('selectNone'));
} else {
selectnone($this.data('selectClass'));
$this.attr('title', $this.data('selectAll'));
}
});
function selectall(cls) {
$('.' + cls).prop('checked', true);
return false;
}
function selectnone(cls) {
$('.' + cls).prop('checked', false);
return false;
}
});

View File

@ -0,0 +1,60 @@
<script type="text/javascript" src="view/theme/frio/js/mod_admin.js"></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><input type="checkbox" class="select contacts_ckbx" data-select-class="contacts_ckbx" data-select-all="{{$select_all}}" data-select-none="{{$select_none}}" title="{{$select_all}}"/></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>
<tfoot>
<tr>
<td><input type="checkbox" class="select contacts_ckbx" data-select-class="contacts_ckbx" data-select-all="{{$select_all}}" data-select-none="{{$select_none}}" title="{{$select_all}}"/></td>
<td colspan="3">
{{$total_contacts}}
</td>
</tr>
</tfoot>
</table>
<div class="submit"><button type="submit" class="btn btn-small btn-default" name="page_contactblock_unblock" value="1">{{$unblock|escape:'html'}}</button></div>
{{$paginate}}
{{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"><button type="submit" class="btn btn-primary" name="page_contactblock_block" value="1">{{$submit|escape:'html'}}</button></div>
</form>
</div>