Merge remote-tracking branch 'upstream/master'

Conflicts:
	mod/admin.php
	mod/settings.php
This commit is contained in:
Michael Vogel 2013-12-02 00:33:46 +01:00
commit e0cf2c5167
26 changed files with 29884 additions and 28549 deletions

View file

@ -108,7 +108,7 @@ function admin_content(&$a) {
/* get plugins admin page */
$r = q("SELECT * FROM `addon` WHERE `plugin_admin`=1");
$r = q("SELECT name FROM `addon` WHERE `plugin_admin`=1");
$aside['plugins_admin']=Array();
foreach ($r as $h){
$plugin =$h['name'];
@ -237,6 +237,70 @@ function admin_page_site_post(&$a){
check_form_security_token_redirectOnErr('/admin/site', 'admin_site');
// relocate
if (x($_POST,'relocate') && x($_POST,'relocate_url') && $_POST['relocate_url']!=""){
$new_url = $_POST['relocate_url'];
$new_url = rtrim($new_url,"/");
$parsed = @parse_url($new_url);
if (!$parsed || (!x($parsed,'host') || !x($parsed,'scheme'))) {
notice(t("Can not parse base url. Must have at least <scheme>://<domain>"));
goaway($a->get_baseurl(true) . '/admin/site' );
}
/* steps:
* replace all "baseurl" to "new_url" in config, profile, term, items and contacts
* send relocate for every local user
* */
$old_url = $a->get_baseurl(true);
function update_table($table_name, $fields, $old_url, $new_url) {
global $db, $a;
$dbold = dbesc($old_url);
$dbnew = dbesc($new_url);
$upd = array();
foreach ($fields as $f) {
$upd[] = "`$f` = REPLACE(`$f`, '$dbold', '$dbnew')";
}
$upds = implode(", ", $upd);
$q = sprintf("UPDATE %s SET %s;", $table_name, $upds);
$r = q($q);
if (!$r) {
notice( "Falied updating '$table_name': " . $db->error );
goaway($a->get_baseurl(true) . '/admin/site' );
}
}
// update tables
update_table("profile", array('photo', 'thumb'), $old_url, $new_url);
update_table("term", array('url'), $old_url, $new_url);
update_table("contact", array('photo','thumb','micro','url','nurl','request','notify','poll','confirm','poco'), $old_url, $new_url);
update_table("item", array('owner-link','owner-avatar','author-name','author-link','author-avatar','body','plink','tag'), $old_url, $new_url);
// update config
$a->set_baseurl($new_url);
set_config('system','url',$new_url);
// send relocate
$users = q("SELECT uid FROM user WHERE account_removed = 0 AND account_expired = 0");
foreach ($users as $user) {
proc_run('php', 'include/notifier.php', 'relocate', $user['uid']);
}
info("Relocation started. Could take a while to complete.");
goaway($a->get_baseurl(true) . '/admin/site' );
}
// end relocate
$sitename = ((x($_POST,'sitename')) ? notags(trim($_POST['sitename'])) : '');
$banner = ((x($_POST,'banner')) ? trim($_POST['banner']) : false);
$info = ((x($_POST,'info')) ? trim($_POST['info']) : false);
@ -502,13 +566,13 @@ function admin_page_site(&$a) {
return replace_macros($t, array(
'$title' => t('Administration'),
'$page' => t('Site'),
'$submit' => t('Submit'),
'$submit' => t('Save Settings'),
'$registration' => t('Registration'),
'$upload' => t('File upload'),
'$corporate' => t('Policies'),
'$advanced' => t('Advanced'),
'$performance' => t('Performance'),
'$relocate'=> t('Relocate - WARNING: advanced function. Could make this server unreachable.'),
'$baseurl' => $a->get_baseurl(true),
// name, label, value, help string, extra data...
'$sitename' => array('sitename', t("Site name"), htmlentities($a->config['sitename'], ENT_QUOTES), 'UTF-8'),
@ -564,6 +628,9 @@ function admin_page_site(&$a) {
'$lockpath' => array('lockpath', t("Path for lock file"), get_config('system','lockpath'), "The lock file is used to avoid multiple pollers at one time. Only define a folder here."),
'$temppath' => array('temppath', t("Temp path"), get_config('system','temppath'), "If you have a restricted system where the webserver can't access the system temp path, enter another path here."),
'$basepath' => array('basepath', t("Base path to installation"), get_config('system','basepath'), "If the system cannot detect the correct path to your installation, enter the correct path here. This setting should only be set if you are using a restricted system and symbolic links to your webroot."),
'$relocate_url' => array('relocate_url', t("New base url"), $a->get_baseurl(), "Change base url for this server. Sends relocate message to all DFRN contacts of all users."),
'$form_security_token' => get_form_security_token("admin_site"),
));
@ -605,7 +672,7 @@ function admin_page_dbsync(&$a) {
}
$failed = array();
$r = q("select * from config where `cat` = 'database' ");
$r = q("select k, v from config where `cat` = 'database' ");
if(count($r)) {
foreach($r as $rr) {
$upd = intval(substr($rr['k'],7));
@ -711,7 +778,7 @@ function admin_page_users_post(&$a){
function admin_page_users(&$a){
if ($a->argc>2) {
$uid = $a->argv[3];
$user = q("SELECT * FROM `user` WHERE `uid`=%d", intval($uid));
$user = q("SELECT username, blocked FROM `user` WHERE `uid`=%d", intval($uid));
if (count($user)==0){
notice( 'User not found' . EOL);
goaway($a->get_baseurl(true) . '/admin/users' );
@ -827,7 +894,7 @@ function admin_page_users(&$a){
// strings //
'$title' => t('Administration'),
'$page' => t('Users'),
'$submit' => t('Submit'),
'$submit' => t('Add User'),
'$select_all' => t('select all'),
'$h_pending' => t('User registrations waiting for confirm'),
'$h_deleted' => t('User waiting for permanent deletion'),
@ -973,7 +1040,7 @@ function admin_page_plugins(&$a){
return replace_macros($t, array(
'$title' => t('Administration'),
'$page' => t('Plugins'),
'$submit' => t('Submit'),
'$submit' => t('Save Settings'),
'$baseurl' => $a->get_baseurl(true),
'$function' => 'plugins',
'$plugins' => $plugins,
@ -1173,7 +1240,7 @@ function admin_page_themes(&$a){
return replace_macros($t, array(
'$title' => t('Administration'),
'$page' => t('Themes'),
'$submit' => t('Submit'),
'$submit' => t('Save Settings'),
'$baseurl' => $a->get_baseurl(true),
'$function' => 'themes',
'$plugins' => $xthemes,
@ -1260,7 +1327,7 @@ readable.");
return replace_macros($t, array(
'$title' => t('Administration'),
'$page' => t('Logs'),
'$submit' => t('Submit'),
'$submit' => t('Save Settings'),
'$clear' => t('Clear'),
'$data' => $data,
'$baseurl' => $a->get_baseurl(true),

View file

@ -84,7 +84,7 @@ function group_content(&$a) {
$tpl = get_markup_template('group_edit.tpl');
$context = array(
'$submit' => t('Submit'),
'$submit' => t('Save Group'),
);
if(($a->argc == 2) && ($a->argv[1] === 'new')) {

162
mod/pubsubhubbub.php Normal file
View file

@ -0,0 +1,162 @@
<?php
function post_var($name) {
return (x($_POST, $name)) ? notags(trim($_POST[$name])) : '';
}
function pubsubhubbub_init(&$a) {
// PuSH subscription must be considered "public" so just block it
// if public access isn't enabled.
if (get_config('system', 'block_public')) {
http_status_exit(403);
}
// Subscription request from subscriber
// https://pubsubhubbub.googlecode.com/git/pubsubhubbub-core-0.4.html#anchor4
// Example from GNU Social:
// [hub_mode] => subscribe
// [hub_callback] => http://status.local/main/push/callback/1
// [hub_verify] => sync
// [hub_verify_token] => af11...
// [hub_secret] => af11...
// [hub_topic] => http://friendica.local/dfrn_poll/sazius
if($_SERVER['REQUEST_METHOD'] === 'POST') {
$hub_mode = post_var('hub_mode');
$hub_callback = post_var('hub_callback');
$hub_verify = post_var('hub_verify');
$hub_verify_token = post_var('hub_verify_token');
$hub_secret = post_var('hub_secret');
$hub_topic = post_var('hub_topic');
// check for valid hub_mode
if ($hub_mode === 'subscribe') {
$subscribe = 1;
} else if ($hub_mode === 'unsubscribe') {
$subscribe = 0;
} else {
logger("pubsubhubbub: invalid hub_mode=$hub_mode, ignoring.");
http_status_exit(404);
}
logger("pubsubhubbub: $hub_mode request from " .
$_SERVER['REMOTE_ADDR']);
// get the nick name from the topic, a bit hacky but needed
$nick = substr(strrchr($hub_topic, "/"), 1);
if (!$nick) {
logger('pubsubhubbub: bad hub_topic=$hub_topic, ignoring.');
http_status_exit(404);
}
// fetch user from database given the nickname
$r = q("SELECT * FROM `user` WHERE `nickname` = '%s'" .
" AND `account_expired` = 0 AND `account_removed` = 0 LIMIT 1",
dbesc($nick));
if(!count($r)) {
logger('pubsubhubbub: local account not found: ' . $nick);
http_status_exit(404);
}
$owner = $r[0];
// abort if user's wall is supposed to be private
if ($r[0]['hidewall']) {
logger('pubsubhubbub: local user ' . $nick .
'has chosen to hide wall, ignoring.');
http_status_exit(403);
}
// get corresponding row from contact table
$r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `blocked` = 0" .
" AND `pending` = 0 LIMIT 1",
intval($owner['uid']));
if(!count($r)) {
logger('pubsubhubbub: contact not found.');
http_status_exit(404);
}
$contact = $r[0];
// sanity check that topic URLs are the same
if(!link_compare($hub_topic, $contact['poll'])) {
logger('pubsubhubbub: hub topic ' . $hub_topic . ' != ' .
$contact['poll']);
http_status_exit(404);
}
// do subscriber verification according to the PuSH protocol
$hub_challenge = random_string(40);
$params = 'hub.mode=' .
($subscribe == 1 ? 'subscribe' : 'unsubscribe') .
'&hub.topic=' . urlencode($hub_topic) .
'&hub.challenge=' . $hub_challenge .
'&hub.lease_seconds=604800' .
'&hub.verify_token=' . $hub_verify_token;
// lease time is hard coded to one week (in seconds)
// we don't actually enforce the lease time because GNU
// Social/StatusNet doesn't honour it (yet)
$body = fetch_url($hub_callback . "?" . $params);
$ret = $a->get_curl_code();
// give up if the HTTP return code wasn't a success (2xx)
if ($ret < 200 || $ret > 299) {
logger("pubsubhubbub: subscriber verification at $hub_callback ".
"returned $ret, ignoring.");
http_status_exit(404);
}
// check that the correct hub_challenge code was echoed back
if (trim($body) !== $hub_challenge) {
logger("pubsubhubbub: subscriber did not echo back ".
"hub.challenge, ignoring.");
logger("\"$hub_challenge\" != \"".trim($body)."\"");
http_status_exit(404);
}
// fetch the old subscription if it exists
$r = q("SELECT * FROM `push_subscriber` WHERE `callback_url` = '%s'",
dbesc($hub_callback));
// delete old subscription if it exists
q("DELETE FROM `push_subscriber` WHERE `callback_url` = '%s'",
dbesc($hub_callback));
if ($subscribe) {
$last_update = datetime_convert('UTC','UTC','now','Y-m-d H:i:s');
$push_flag = 0;
// if we are just updating an old subscription, keep the
// old values for push and last_update
if (count($r)) {
$last_update = $r[0]['last_update'];
$push_flag = $r[0]['push'];
}
// subscribe means adding the row to the table
q("INSERT INTO `push_subscriber` (`uid`, `callback_url`, " .
"`topic`, `nickname`, `push`, `last_update`, `secret`) values " .
"(%d, '%s', '%s', '%s', %d, '%s', '%s')",
intval($owner['uid']),
dbesc($hub_callback),
dbesc($hub_topic),
dbesc($nick),
intval($push_flag),
dbesc($last_update),
dbesc($hub_secret));
logger("pubsubhubbub: successfully subscribed [$hub_callback].");
} else {
logger("pubsubhubbub: successfully unsubscribed [$hub_callback].");
// we do nothing here, since the row was already deleted
}
http_status_exit(202);
}
killme();
}
?>

View file

@ -306,11 +306,17 @@ function settings_post(&$a) {
check_form_security_token_redirectOnErr('/settings', 'settings');
if (x($_POST,'resend_relocate')) {
proc_run('php', 'include/notifier.php', 'relocate', local_user());
info(t("Relocate message has been send to your contacts"));
goaway($a->get_baseurl(true) . '/settings');
}
call_hooks('settings_post', $_POST);
if((x($_POST,'npassword')) || (x($_POST,'confirm'))) {
if((x($_POST,'password')) || (x($_POST,'confirm'))) {
$newpass = $_POST['npassword'];
$newpass = $_POST['password'];
$confirm = $_POST['confirm'];
$oldpass = hash('whirlpool', $_POST['opassword']);
@ -416,7 +422,7 @@ function settings_post(&$a) {
$email_changed = true;
// check for the correct password
$r = q("SELECT `password` FROM `user`WHERE `uid` = %d LIMIT 1", intval(local_user()));
$password = hash('whirlpool', $_POST['password']);
$password = hash('whirlpool', $_POST['mpassword']);
if ($password != $r[0]['password']) {
$err .= t('Wrong Password') . EOL;
$email = $a->user['email'];
@ -592,7 +598,7 @@ function settings_content(&$a) {
$o .= replace_macros($tpl, array(
'$form_security_token' => get_form_security_token("settings_oauth"),
'$title' => t('Add application'),
'$submit' => t('Submit'),
'$submit' => t('Save Settings'),
'$cancel' => t('Cancel'),
'$name' => array('name', t('Name'), '', ''),
'$key' => array('key', t('Consumer Key'), '', ''),
@ -702,7 +708,7 @@ function settings_content(&$a) {
'$form_security_token' => get_form_security_token("settings_features"),
'$title' => t('Additional Features'),
'$features' => $arr,
'$submit' => t('Submit'),
'$submit' => t('Save Settings'),
));
return $o;
}
@ -771,7 +777,7 @@ function settings_content(&$a) {
'$mail_pubmail' => array('mail_pubmail', t('Send public posts to all email contacts:'), $mail_pubmail, ''),
'$mail_action' => array('mail_action', t('Action after import:'), $mail_action, '', array(0=>t('None'), /*1=>t('Delete'),*/ 2=>t('Mark as seen'), 3=>t('Move to folder'))),
'$mail_movetofolder' => array('mail_movetofolder', t('Move to folder:'), $mail_movetofolder, ''),
'$submit' => t('Submit'),
'$submit' => t('Save Settings'),
'$settings_connectors' => $settings_connectors
));
@ -847,7 +853,7 @@ function settings_content(&$a) {
$o = replace_macros($tpl, array(
'$ptitle' => t('Display Settings'),
'$form_security_token' => get_form_security_token("settings_display"),
'$submit' => t('Submit'),
'$submit' => t('Save Settings'),
'$baseurl' => $a->get_baseurl(true),
'$uid' => local_user(),
@ -1075,27 +1081,27 @@ function settings_content(&$a) {
$o .= replace_macros($stpl, array(
'$ptitle' => t('Account Settings'),
'$submit' => t('Submit'),
'$submit' => t('Save Settings'),
'$baseurl' => $a->get_baseurl(true),
'$uid' => local_user(),
'$form_security_token' => get_form_security_token("settings"),
'$nickname_block' => $prof_addr,
'$h_pass' => t('Password Settings'),
'$password1'=> array('npassword', t('New Password:'), '', ''),
'$password1'=> array('password', t('New Password:'), '', ''),
'$password2'=> array('confirm', t('Confirm:'), '', t('Leave password fields blank unless changing')),
'$password3'=> array('opassword', t('Current Password:'), '', t('Your current password to confirm the changes')),
'$password4'=> array('password', t('Password:'), '', t('Your current password to confirm the changes')),
'$password4'=> array('mpassword', t('Password:'), '', t('Your current password to confirm the changes')),
'$oid_enable' => (! get_config('system','no_openid')),
'$openid' => $openid_field,
'$h_basic' => t('Basic Settings'),
'$username' => array('username', t('Full Name:'), $username,''),
'$email' => array('email', t('Email Address:'), $email, ''),
'$timezone' => array('timezone_select' , t('Your Timezone:'), select_timezone($timezone), ''),
'$defloc' => array('defloc', t('Default Post Location:'), $defloc, ''),
'$allowloc' => array('allow_location', t('Use Browser Location:'), ($a->user['allow_location'] == 1), ''),
'$h_prv' => t('Security and Privacy Settings'),
@ -1152,6 +1158,10 @@ function settings_content(&$a) {
'$h_descadvn' => t('Change the behaviour of this account for special situations'),
'$pagetype' => $pagetype,
'$relocate' => t('Relocate'),
'$relocate_text' => t("If you have moved this profile from another server, and some of your contacts don't receive your updates, try pushing this button."),
'$relocate_button' => t("Resend relocate message to contacts"),
));
call_hooks('settings_form',$o);