Friendica Communications Platform (please note that this is a clone of the repository at github, issues are handled there) https://friendi.ca
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2175 lines
85 KiB

9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
3 years ago
3 years ago
3 years ago
3 years ago
5 years ago
5 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
6 years ago
6 years ago
9 years ago
6 years ago
6 years ago
3 years ago
9 years ago
9 years ago
9 years ago
9 years ago
6 years ago
6 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
8 years ago
9 years ago
6 years ago
9 years ago
9 years ago
5 years ago
9 years ago
9 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
5 years ago
6 years ago
5 years ago
6 years ago
6 years ago
6 years ago
  1. <?php
  2. /**
  3. * @file mod/admin.php
  4. *
  5. * @brief Friendica admin
  6. */
  7. use Friendica\Core\Config;
  8. require_once("include/enotify.php");
  9. require_once("include/text.php");
  10. /**
  11. * @brief Process send data from the admin panels subpages
  12. *
  13. * This function acts as relais for processing the data send from the subpages
  14. * of the admin panel. Depending on the 1st parameter of the url (argv[1])
  15. * specialized functions are called to process the data from the subpages.
  16. *
  17. * The function itself does not return anything, but the subsequencely function
  18. * return the HTML for the pages of the admin panel.
  19. *
  20. * @param App $a
  21. *
  22. */
  23. function admin_post(App $a) {
  24. if (!is_site_admin()) {
  25. return;
  26. }
  27. // do not allow a page manager to access the admin panel at all.
  28. if (x($_SESSION,'submanage') && intval($_SESSION['submanage'])) {
  29. return;
  30. }
  31. // urls
  32. if ($a->argc > 1) {
  33. switch ($a->argv[1]) {
  34. case 'site':
  35. admin_page_site_post($a);
  36. break;
  37. case 'users':
  38. admin_page_users_post($a);
  39. break;
  40. case 'plugins':
  41. if ($a->argc > 2 &&
  42. is_file("addon/".$a->argv[2]."/".$a->argv[2].".php")) {
  43. @include_once("addon/".$a->argv[2]."/".$a->argv[2].".php");
  44. if (function_exists($a->argv[2].'_plugin_admin_post')) {
  45. $func = $a->argv[2].'_plugin_admin_post';
  46. $func($a);
  47. }
  48. }
  49. goaway('admin/plugins/'.$a->argv[2]);
  50. return; // NOTREACHED
  51. break;
  52. case 'themes':
  53. if ($a->argc < 2) {
  54. if (is_ajax()) {
  55. return;
  56. }
  57. goaway('admin/');
  58. return;
  59. }
  60. $theme = $a->argv[2];
  61. if (is_file("view/theme/$theme/config.php")) {
  62. function __call_theme_admin_post(App $a, $theme) {
  63. $orig_theme = $a->theme;
  64. $orig_page = $a->page;
  65. $orig_session_theme = $_SESSION['theme'];
  66. require_once("view/theme/$theme/theme.php");
  67. require_once("view/theme/$theme/config.php");
  68. $_SESSION['theme'] = $theme;
  69. $init = $theme."_init";
  70. if (function_exists($init)) {
  71. $init($a);
  72. }
  73. if (function_exists("theme_admin_post")) {
  74. $admin_form = theme_admin_post($a);
  75. }
  76. $_SESSION['theme'] = $orig_session_theme;
  77. $a->theme = $orig_theme;
  78. $a->page = $orig_page;
  79. return $admin_form;
  80. }
  81. __call_theme_admin_post($a, $theme);
  82. }
  83. info(t('Theme settings updated.'));
  84. if (is_ajax()) {
  85. return;
  86. }
  87. goaway('admin/themes/'.$theme);
  88. return;
  89. break;
  90. case 'features':
  91. admin_page_features_post($a);
  92. break;
  93. case 'logs':
  94. admin_page_logs_post($a);
  95. break;
  96. case 'dbsync':
  97. admin_page_dbsync_post($a);
  98. break;
  99. case 'blocklist':
  100. admin_page_blocklist_post($a);
  101. break;
  102. }
  103. }
  104. goaway('admin');
  105. return; // NOTREACHED
  106. }
  107. /**
  108. * @brief Generates content of the admin panel pages
  109. *
  110. * This function generates the content for the admin panel. It consists of the
  111. * aside menu (same for the entire admin panel) and the code for the soecified
  112. * subpage of the panel.
  113. *
  114. * The structure of the adress is: /admin/subpage/details though "details" is
  115. * only necessary for some subpages, like themes or addons where it is the name
  116. * of one theme resp. addon from which the details should be shown. Content for
  117. * the subpages is generated in separate functions for each of the subpages.
  118. *
  119. * The returned string hold the generated HTML code of the page.
  120. *
  121. * @param App $a
  122. * @return string
  123. */
  124. function admin_content(App $a) {
  125. if (!is_site_admin()) {
  126. return login(false);
  127. }
  128. if (x($_SESSION,'submanage') && intval($_SESSION['submanage'])) {
  129. return "";
  130. }
  131. // APC deactivated, since there are problems with PHP 5.5
  132. //if (function_exists("apc_delete")) {
  133. // $toDelete = new APCIterator('user', APC_ITER_VALUE);
  134. // apc_delete($toDelete);
  135. //}
  136. // Header stuff
  137. $a->page['htmlhead'] .= replace_macros(get_markup_template('admin_settings_head.tpl'), array());
  138. /*
  139. * Side bar links
  140. */
  141. $aside_tools = array();
  142. // array(url, name, extra css classes)
  143. // not part of $aside to make the template more adjustable
  144. $aside_sub = array(
  145. 'site' => array("admin/site/", t("Site") , "site"),
  146. 'users' => array("admin/users/", t("Users") , "users"),
  147. 'plugins'=> array("admin/plugins/", t("Plugins") , "plugins"),
  148. 'themes' => array("admin/themes/", t("Themes") , "themes"),
  149. 'features' => array("admin/features/", t("Additional features") , "features"),
  150. 'dbsync' => array("admin/dbsync/", t('DB updates'), "dbsync"),
  151. 'queue' => array("admin/queue/", t('Inspect Queue'), "queue"),
  152. 'blocklist' => array("admin/blocklist/", t('Server Blocklist'), "blocklist"),
  153. 'federation' => array("admin/federation/", t('Federation Statistics'), "federation"),
  154. );
  155. /* get plugins admin page */
  156. $r = q("SELECT `name` FROM `addon` WHERE `plugin_admin` = 1 ORDER BY `name`");
  157. $aside_tools['plugins_admin']=array();
  158. foreach ($r as $h) {
  159. $plugin =$h['name'];
  160. $aside_tools['plugins_admin'][] = array("admin/plugins/".$plugin, $plugin, "plugin");
  161. // temp plugins with admin
  162. $a->plugins_admin[] = $plugin;
  163. }
  164. $aside_tools['logs'] = array("admin/logs/", t("Logs"), "logs");
  165. $aside_tools['viewlogs'] = array("admin/viewlogs/", t("View Logs"), 'viewlogs');
  166. $aside_tools['diagnostics_probe'] = array('probe/', t('probe address'), 'probe');
  167. $aside_tools['diagnostics_webfinger'] = array('webfinger/', t('check webfinger'), 'webfinger');
  168. $t = get_markup_template("admin_aside.tpl");
  169. $a->page['aside'] .= replace_macros($t, array(
  170. '$admin' => $aside_tools,
  171. '$subpages' => $aside_sub,
  172. '$admtxt' => t('Admin'),
  173. '$plugadmtxt' => t('Plugin Features'),
  174. '$logtxt' => t('Logs'),
  175. '$diagnosticstxt' => t('diagnostics'),
  176. '$h_pending' => t('User registrations waiting for confirmation'),
  177. '$admurl'=> "admin/"
  178. ));
  179. /*
  180. * Page content
  181. */
  182. $o = '';
  183. // urls
  184. if ($a->argc > 1) {
  185. switch ($a->argv[1]) {
  186. case 'site':
  187. $o = admin_page_site($a);
  188. break;
  189. case 'users':
  190. $o = admin_page_users($a);
  191. break;
  192. case 'plugins':
  193. $o = admin_page_plugins($a);
  194. break;
  195. case 'themes':
  196. $o = admin_page_themes($a);
  197. break;
  198. case 'features':
  199. $o = admin_page_features($a);
  200. break;
  201. case 'logs':
  202. $o = admin_page_logs($a);
  203. break;
  204. case 'viewlogs':
  205. $o = admin_page_viewlogs($a);
  206. break;
  207. case 'dbsync':
  208. $o = admin_page_dbsync($a);
  209. break;
  210. case 'queue':
  211. $o = admin_page_queue($a);
  212. break;
  213. case 'federation':
  214. $o = admin_page_federation($a);
  215. break;
  216. case 'blocklist':
  217. $o = admin_page_blocklist($a);
  218. break;
  219. default:
  220. notice(t("Item not found."));
  221. }
  222. } else {
  223. $o = admin_page_summary($a);
  224. }
  225. if (is_ajax()) {
  226. echo $o;
  227. killme();
  228. return '';
  229. } else {
  230. return $o;
  231. }
  232. }
  233. /**
  234. * @brief Subpage to modify the server wide block list via the admin panel.
  235. *
  236. * This function generates the subpage of the admin panel to allow the
  237. * modification of the node wide block/black list to block entire
  238. * remote servers from communication with this node. The page allows
  239. * adding, removing and editing of entries from the blocklist.
  240. *
  241. * @param App $a
  242. * @return string
  243. */
  244. function admin_page_blocklist(App $a) {
  245. $blocklist = Config::get('system', 'blocklist');
  246. $blocklistform = array();
  247. if (is_array($blocklist)) {
  248. foreach($blocklist as $id => $b) {
  249. $blocklistform[] = array(
  250. 'domain' => array("domain[$id]", t('Blocked domain'), $b['domain'], '', t('The blocked domain'), 'required', '', ''),
  251. 'reason' => array("reason[$id]", t("Reason for the block"), $b['reason'], t('The reason why you blocked this domain.').'('.$b['domain'].')', 'required', '', ''),
  252. 'delete' => array("delete[$id]", t("Delete domain").' ('.$b['domain'].')', False , "Check to delete this entry from the blocklist")
  253. );
  254. }
  255. }
  256. $t = get_markup_template("admin_blocklist.tpl");
  257. return replace_macros($t, array(
  258. '$title' => t('Administration'),
  259. '$page' => t('Server Blocklist'),
  260. '$intro' => t('This page can be used to define a black list of servers from the federated network that are not allowed to interact with your node. For all entered domains you should also give a reason why you have blocked the remote server.'),
  261. '$public' => t('The list of blocked servers will be made publically available on the /friendica page so that your users and people investigating communication problems can find the reason easily.'),
  262. '$addtitle' => t('Add new entry to block list'),
  263. '$newdomain' => array('newentry_domain', t('Server Domain'), '', t('The domain of the new server to add to the block list. Do not include the protocol.'), 'required', '', ''),
  264. '$newreason' => array('newentry_reason', t('Block reason'), '', t('The reason why you blocked this domain.'), 'required', '', ''),
  265. '$submit' => t('Add Entry'),
  266. '$savechanges' => t('Save changes to the blocklist'),
  267. '$currenttitle' => t('Current Entries in the Blocklist'),
  268. '$thurl' => t('Blocked domain'),
  269. '$threason' => t('Reason for the block'),
  270. '$delentry' => t('Delete entry from blocklist'),
  271. '$entries' => $blocklistform,
  272. '$baseurl' => App::get_baseurl(true),
  273. '$confirm_delete' => t('Delete entry from blocklist?'),
  274. '$form_security_token' => get_form_security_token("admin_blocklist")
  275. ));
  276. }
  277. /**
  278. * @brief Process send data from Admin Blocklist Page
  279. *
  280. * @param App $a
  281. */
  282. function admin_page_blocklist_post(App $a) {
  283. if (!x($_POST,"page_blocklist_save") && (!x($_POST['page_blocklist_edit']))) {
  284. return;
  285. }
  286. check_form_security_token_redirectOnErr('/admin/blocklist', 'admin_blocklist');
  287. if (x($_POST['page_blocklist_save'])) {
  288. // Add new item to blocklist
  289. $blocklist = get_config('system', 'blocklist');
  290. $blocklist[] = array(
  291. 'domain' => notags(trim($_POST['newentry_domain'])),
  292. 'reason' => notags(trim($_POST['newentry_reason']))
  293. );
  294. Config::set('system', 'blocklist', $blocklist);
  295. info(t('Server added to blocklist.').EOL);
  296. } else {
  297. // Edit the entries from blocklist
  298. $blocklist = array();
  299. foreach ($_POST['domain'] as $id => $domain) {
  300. // Trimming whitespaces as well as any lingering slashes
  301. $domain = notags(trim($domain, "\x00..\x1F/"));
  302. $reason = notags(trim($_POST['reason'][$id]));
  303. if (!x($_POST['delete'][$id])) {
  304. $blocklist[] = array(
  305. 'domain' => $domain,
  306. 'reason' => $reason
  307. );
  308. }
  309. }
  310. Config::set('system', 'blocklist', $blocklist);
  311. info(t('Site blocklist updated.').EOL);
  312. }
  313. goaway('admin/blocklist');
  314. return; // NOTREACHED
  315. }
  316. /**
  317. * @brief Subpage with some stats about "the federation" network
  318. *
  319. * This function generates the "Federation Statistics" subpage for the admin
  320. * panel. The page lists some numbers to the part of "The Federation" known to
  321. * the node. This data includes the different connected networks (e.g.
  322. * Diaspora, Hubzilla, GNU Social) and the used versions in the different
  323. * networks.
  324. *
  325. * The returned string contains the HTML code of the subpage for display.
  326. *
  327. * @param App $a
  328. * @return string
  329. */
  330. function admin_page_federation(App $a) {
  331. // get counts on active friendica, diaspora, redmatrix, hubzilla, gnu
  332. // social and statusnet nodes this node is knowing
  333. //
  334. // We are looking for the following platforms in the DB, "Red" should find
  335. // all variants of that platform ID string as the q() function is stripping
  336. // off one % two of them are needed in the query
  337. // Add more platforms if you like, when one returns 0 known nodes it is not
  338. // displayed on the stats page.
  339. $platforms = array('Friendi%%a', 'Diaspora', '%%red%%', 'Hubzilla', 'BlaBlaNet', 'GNU Social', 'StatusNet', 'Mastodon');
  340. $colors = array('Friendi%%a' => '#ffc018', // orange from the logo
  341. 'Diaspora' => '#a1a1a1', // logo is black and white, makes a gray
  342. '%%red%%' => '#c50001', // fire red from the logo
  343. 'Hubzilla' => '#43488a', // blue from the logo
  344. 'BlaBlaNet' => '#3B5998', // blue from the navbar at blablanet-dot-com
  345. 'GNU Social'=> '#a22430', // dark red from the logo
  346. 'StatusNet' => '#789240', // the green from the logo (red and blue have already others
  347. 'Mastodon' => '#1a9df9'); // blue from the Mastodon logo
  348. $counts = array();
  349. $total = 0;
  350. foreach ($platforms as $p) {
  351. // get a total count for the platform, the name and version of the
  352. // highest version and the protocol tpe
  353. $c = qu('SELECT COUNT(*) AS `total`, ANY_VALUE(`platform`) AS `platform`,
  354. ANY_VALUE(`network`) AS `network`, MAX(`version`) AS `version` FROM `gserver`
  355. WHERE `platform` LIKE "%s" AND `last_contact` >= `last_failure`
  356. ORDER BY `version` ASC;', $p);
  357. $total = $total + $c[0]['total'];
  358. // what versions for that platform do we know at all?
  359. // again only the active nodes
  360. $v = qu('SELECT COUNT(*) AS `total`, `version` FROM `gserver`
  361. WHERE `last_contact` >= `last_failure` AND `platform` LIKE "%s"
  362. GROUP BY `version`
  363. ORDER BY `version`;', $p);
  364. //
  365. // clean up version numbers
  366. //
  367. // some platforms do not provide version information, add a unkown there
  368. // to the version string for the displayed list.
  369. foreach ($v as $key => $value) {
  370. if ($v[$key]['version'] == '') {
  371. $v[$key] = array('total'=>$v[$key]['total'], 'version'=>t('unknown'));
  372. }
  373. }
  374. // in the DB the Diaspora versions have the format x.x.x.x-xx the last
  375. // part (-xx) should be removed to clean up the versions from the "head
  376. // commit" information and combined into a single entry for x.x.x.x
  377. if ($p == 'Diaspora') {
  378. $newV = array();
  379. $newVv = array();
  380. foreach ($v as $vv) {
  381. $newVC = $vv['total'];
  382. $newVV = $vv['version'];
  383. $posDash = strpos($newVV, '-');
  384. if ($posDash) {
  385. $newVV = substr($newVV, 0, $posDash);
  386. }
  387. if (isset($newV[$newVV])) {
  388. $newV[$newVV] += $newVC;
  389. } else {
  390. $newV[$newVV] = $newVC;
  391. }
  392. }
  393. foreach ($newV as $key => $value) {
  394. array_push($newVv, array('total'=>$value, 'version'=>$key));
  395. }
  396. $v = $newVv;
  397. }
  398. // early friendica versions have the format x.x.xxxx where xxxx is the
  399. // DB version stamp; those should be operated out and versions be
  400. // conbined
  401. if ($p == 'Friendi%%a') {
  402. $newV = array();
  403. $newVv = array();
  404. foreach ($v as $vv) {
  405. $newVC = $vv['total'];
  406. $newVV = $vv['version'];
  407. $lastDot = strrpos($newVV,'.');
  408. $len = strlen($newVV)-1;
  409. if (($lastDot == $len-4) && (!strrpos($newVV,'-rc') == $len-3)) {
  410. $newVV = substr($newVV, 0, $lastDot);
  411. }
  412. if (isset($newV[$newVV])) {
  413. $newV[$newVV] += $newVC;
  414. } else {
  415. $newV[$newVV] = $newVC;
  416. }
  417. }
  418. foreach ($newV as $key => $value) {
  419. array_push($newVv, array('total'=>$value, 'version'=>$key));
  420. }
  421. $v = $newVv;
  422. }
  423. foreach ($v as $key => $vv)
  424. $v[$key]["version"] = trim(strip_tags($vv["version"]));
  425. // the 3rd array item is needed for the JavaScript graphs as JS does
  426. // not like some characters in the names of variables...
  427. $counts[$p]=array($c[0], $v, str_replace(array(' ','%'),'',$p), $colors[$p]);
  428. }
  429. // some helpful text
  430. $intro = t('This page offers you some numbers to the known part of the federated social network your Friendica node is part of. These numbers are not complete but only reflect the part of the network your node is aware of.');
  431. $hint = t('The <em>Auto Discovered Contact Directory</em> feature is not enabled, it will improve the data displayed here.');
  432. // load the template, replace the macros and return the page content
  433. $t = get_markup_template("admin_federation.tpl");
  434. return replace_macros($t, array(
  435. '$title' => t('Administration'),
  436. '$page' => t('Federation Statistics'),
  437. '$intro' => $intro,
  438. '$hint' => $hint,
  439. '$autoactive' => get_config('system', 'poco_completion'),
  440. '$counts' => $counts,
  441. '$version' => FRIENDICA_VERSION,
  442. '$legendtext' => sprintf(t('Currently this node is aware of %d nodes from the following platforms:'), $total),
  443. '$baseurl' => App::get_baseurl(),
  444. ));
  445. }
  446. /**
  447. * @brief Admin Inspect Queue Page
  448. *
  449. * Generates a page for the admin to have a look into the current queue of
  450. * postings that are not deliverabke. Shown are the name and url of the
  451. * recipient, the delivery network and the dates when the posting was generated
  452. * and the last time tried to deliver the posting.
  453. *
  454. * The returned string holds the content of the page.
  455. *
  456. * @param App $a
  457. * @return string
  458. */
  459. function admin_page_queue(App $a) {
  460. // get content from the queue table
  461. $r = q("SELECT `c`.`name`, `c`.`nurl`, `q`.`id`, `q`.`network`, `q`.`created`, `q`.`last`
  462. FROM `queue` AS `q`, `contact` AS `c`
  463. WHERE `c`.`id` = `q`.`cid`
  464. ORDER BY `q`.`cid`, `q`.`created`;");
  465. $t = get_markup_template("admin_queue.tpl");
  466. return replace_macros($t, array(
  467. '$title' => t('Administration'),
  468. '$page' => t('Inspect Queue'),
  469. '$count' => sizeof($r),
  470. 'id_header' => t('ID'),
  471. '$to_header' => t('Recipient Name'),
  472. '$url_header' => t('Recipient Profile'),
  473. '$network_header' => t('Network'),
  474. '$created_header' => t('Created'),
  475. '$last_header' => t('Last Tried'),
  476. '$info' => t('This page lists the content of the queue for outgoing postings. These are postings the initial delivery failed for. They will be resend later and eventually deleted if the delivery fails permanently.'),
  477. '$entries' => $r,
  478. ));
  479. }
  480. /**
  481. * @brief Admin Summary Page
  482. *
  483. * The summary page is the "start page" of the admin panel. It gives the admin
  484. * a first overview of the open adminastrative tasks.
  485. *
  486. * The returned string contains the HTML content of the generated page.
  487. *
  488. * @param App $a
  489. * @return string
  490. */
  491. function admin_page_summary(App $a) {
  492. global $db;
  493. // are there MyISAM tables in the DB? If so, trigger a warning message
  494. $r = q("SELECT `engine` FROM `information_schema`.`tables` WHERE `engine` = 'myisam' AND `table_schema` = '%s' LIMIT 1",
  495. dbesc($db->database_name()));
  496. $showwarning = false;
  497. $warningtext = array();
  498. if (dbm::is_result($r)) {
  499. $showwarning = true;
  500. $warningtext[] = sprintf(t('Your DB still runs with MyISAM tables. You should change the engine type to InnoDB. As Friendica will use InnoDB only features in the future, you should change this! See <a href="%s">here</a> for a guide that may be helpful converting the table engines. You may also use the command <tt>php include/dbstructure.php toinnodb</tt> of your Friendica installation for an automatic conversion.<br />'), 'https://dev.mysql.com/doc/refman/5.7/en/converting-tables-to-innodb.html');
  501. }
  502. // MySQL >= 5.7.4 doesn't support the IGNORE keyword in ALTER TABLE statements
  503. if ((version_compare($db->server_info(), '5.7.4') >= 0) AND
  504. !(strpos($db->server_info(), 'MariaDB') !== false)) {
  505. $warningtext[] = t('You are using a MySQL version which does not support all features that Friendica uses. You should consider switching to MariaDB.');
  506. }
  507. $r = q("SELECT `page-flags`, COUNT(`uid`) AS `count` FROM `user` GROUP BY `page-flags`");
  508. $accounts = array(
  509. array(t('Normal Account'), 0),
  510. array(t('Soapbox Account'), 0),
  511. array(t('Community/Celebrity Account'), 0),
  512. array(t('Automatic Friend Account'), 0),
  513. array(t('Blog Account'), 0),
  514. array(t('Private Forum'), 0)
  515. );
  516. $users=0;
  517. foreach ($r as $u) {
  518. $accounts[$u['page-flags']][1] = $u['count'];
  519. $users+= $u['count'];
  520. }
  521. logger('accounts: '.print_r($accounts,true),LOGGER_DATA);
  522. $r = qu("SELECT COUNT(`id`) AS `count` FROM `register`");
  523. $pending = $r[0]['count'];
  524. $r = qu("SELECT COUNT(*) AS `total` FROM `queue` WHERE 1");
  525. $queue = (($r) ? $r[0]['total'] : 0);
  526. $r = qu("SELECT COUNT(*) AS `total` FROM `workerqueue` WHERE 1");
  527. $workerqueue = (($r) ? $r[0]['total'] : 0);
  528. // We can do better, but this is a quick queue status
  529. $queues = array('label' => t('Message queues'), 'queue' => $queue, 'workerq' => $workerqueue);
  530. $t = get_markup_template("admin_summary.tpl");
  531. return replace_macros($t, array(
  532. '$title' => t('Administration'),
  533. '$page' => t('Summary'),
  534. '$queues' => $queues,
  535. '$users' => array(t('Registered users'), $users),
  536. '$accounts' => $accounts,
  537. '$pending' => array(t('Pending registrations'), $pending),
  538. '$version' => array(t('Version'), FRIENDICA_VERSION),
  539. '$baseurl' => App::get_baseurl(),
  540. '$platform' => FRIENDICA_PLATFORM,
  541. '$codename' => FRIENDICA_CODENAME,
  542. '$build' => get_config('system','build'),
  543. '$plugins' => array(t('Active plugins'), $a->plugins),
  544. '$showwarning' => $showwarning,
  545. '$warningtext' => $warningtext
  546. ));
  547. }
  548. /**
  549. * @brief Process send data from Admin Site Page
  550. *
  551. * @param App $a
  552. */
  553. function admin_page_site_post(App $a) {
  554. if (!x($_POST,"page_site")) {
  555. return;
  556. }
  557. check_form_security_token_redirectOnErr('/admin/site', 'admin_site');
  558. // relocate
  559. if (x($_POST,'relocate') && x($_POST,'relocate_url') && $_POST['relocate_url'] != "") {
  560. $new_url = $_POST['relocate_url'];
  561. $new_url = rtrim($new_url,"/");
  562. $parsed = @parse_url($new_url);
  563. if (!$parsed || (!x($parsed,'host') || !x($parsed,'scheme'))) {
  564. notice(t("Can not parse base url. Must have at least <scheme>://<domain>"));
  565. goaway('admin/site');
  566. }
  567. /* steps:
  568. * replace all "baseurl" to "new_url" in config, profile, term, items and contacts
  569. * send relocate for every local user
  570. * */
  571. $old_url = App::get_baseurl(true);
  572. // Generate host names for relocation the addresses in the format user@address.tld
  573. $new_host = str_replace("http://", "@", normalise_link($new_url));
  574. $old_host = str_replace("http://", "@", normalise_link($old_url));
  575. function update_table($table_name, $fields, $old_url, $new_url) {
  576. global $db, $a;
  577. $dbold = dbesc($old_url);
  578. $dbnew = dbesc($new_url);
  579. $upd = array();
  580. foreach ($fields as $f) {
  581. $upd[] = "`$f` = REPLACE(`$f`, '$dbold', '$dbnew')";
  582. }
  583. $upds = implode(", ", $upd);
  584. $q = sprintf("UPDATE %s SET %s;", $table_name, $upds);
  585. $r = q($q);
  586. if (!$r) {
  587. notice("Failed updating '$table_name': ".$db->error);
  588. goaway('admin/site');
  589. }
  590. }
  591. // update tables
  592. // update profile links in the format "http://server.tld"
  593. update_table("profile", array('photo', 'thumb'), $old_url, $new_url);
  594. update_table("term", array('url'), $old_url, $new_url);
  595. update_table("contact", array('photo','thumb','micro','url','nurl','alias','request','notify','poll','confirm','poco', 'avatar'), $old_url, $new_url);
  596. update_table("gcontact", array('url','nurl','photo','server_url','notify','alias'), $old_url, $new_url);
  597. update_table("item", array('owner-link','owner-avatar','author-link','author-avatar','body','plink','tag'), $old_url, $new_url);
  598. // update profile addresses in the format "user@server.tld"
  599. update_table("contact", array('addr'), $old_host, $new_host);
  600. update_table("gcontact", array('connect','addr'), $old_host, $new_host);
  601. // update config
  602. $a->set_baseurl($new_url);
  603. set_config('system','url',$new_url);
  604. // send relocate
  605. $users = q("SELECT `uid` FROM `user` WHERE `account_removed` = 0 AND `account_expired` = 0");
  606. foreach ($users as $user) {
  607. proc_run(PRIORITY_HIGH, 'include/notifier.php', 'relocate', $user['uid']);
  608. }
  609. info("Relocation started. Could take a while to complete.");
  610. goaway('admin/site');
  611. }
  612. // end relocate
  613. $sitename = ((x($_POST,'sitename')) ? notags(trim($_POST['sitename'])) : '');
  614. $hostname = ((x($_POST,'hostname')) ? notags(trim($_POST['hostname'])) : '');
  615. $sender_email = ((x($_POST,'sender_email')) ? notags(trim($_POST['sender_email'])) : '');
  616. $banner = ((x($_POST,'banner')) ? trim($_POST['banner']) : false);
  617. $shortcut_icon = ((x($_POST,'shortcut_icon')) ? notags(trim($_POST['shortcut_icon'])) : '');
  618. $touch_icon = ((x($_POST,'touch_icon')) ? notags(trim($_POST['touch_icon'])) : '');
  619. $info = ((x($_POST,'info')) ? trim($_POST['info']) : false);
  620. $language = ((x($_POST,'language')) ? notags(trim($_POST['language'])) : '');
  621. $theme = ((x($_POST,'theme')) ? notags(trim($_POST['theme'])) : '');
  622. $theme_mobile = ((x($_POST,'theme_mobile')) ? notags(trim($_POST['theme_mobile'])) : '');
  623. $maximagesize = ((x($_POST,'maximagesize')) ? intval(trim($_POST['maximagesize'])) : 0);
  624. $maximagelength = ((x($_POST,'maximagelength')) ? intval(trim($_POST['maximagelength'])) : MAX_IMAGE_LENGTH);
  625. $jpegimagequality = ((x($_POST,'jpegimagequality')) ? intval(trim($_POST['jpegimagequality'])) : JPEG_QUALITY);
  626. $register_policy = ((x($_POST,'register_policy')) ? intval(trim($_POST['register_policy'])) : 0);
  627. $daily_registrations = ((x($_POST,'max_daily_registrations')) ? intval(trim($_POST['max_daily_registrations'])) :0);
  628. $abandon_days = ((x($_POST,'abandon_days')) ? intval(trim($_POST['abandon_days'])) : 0);
  629. $register_text = ((x($_POST,'register_text')) ? notags(trim($_POST['register_text'])) : '');
  630. $allowed_sites = ((x($_POST,'allowed_sites')) ? notags(trim($_POST['allowed_sites'])) : '');
  631. $allowed_email = ((x($_POST,'allowed_email')) ? notags(trim($_POST['allowed_email'])) : '');
  632. $block_public = ((x($_POST,'block_public')) ? True : False);
  633. $force_publish = ((x($_POST,'publish_all')) ? True : False);
  634. $global_directory = ((x($_POST,'directory')) ? notags(trim($_POST['directory'])) : '');
  635. $thread_allow = ((x($_POST,'thread_allow')) ? True : False);
  636. $newuser_private = ((x($_POST,'newuser_private')) ? True : False);
  637. $enotify_no_content = ((x($_POST,'enotify_no_content')) ? True : False);
  638. $private_addons = ((x($_POST,'private_addons')) ? True : False);
  639. $disable_embedded = ((x($_POST,'disable_embedded')) ? True : False);
  640. $allow_users_remote_self = ((x($_POST,'allow_users_remote_self')) ? True : False);
  641. $no_multi_reg = ((x($_POST,'no_multi_reg')) ? True : False);
  642. $no_openid = !((x($_POST,'no_openid')) ? True : False);
  643. $no_regfullname = !((x($_POST,'no_regfullname')) ? True : False);
  644. $community_page_style = ((x($_POST,'community_page_style')) ? intval(trim($_POST['community_page_style'])) : 0);
  645. $max_author_posts_community_page = ((x($_POST,'max_author_posts_community_page')) ? intval(trim($_POST['max_author_posts_community_page'])) : 0);
  646. $verifyssl = ((x($_POST,'verifyssl')) ? True : False);
  647. $proxyuser = ((x($_POST,'proxyuser')) ? notags(trim($_POST['proxyuser'])) : '');
  648. $proxy = ((x($_POST,'proxy')) ? notags(trim($_POST['proxy'])) : '');
  649. $timeout = ((x($_POST,'timeout')) ? intval(trim($_POST['timeout'])) : 60);
  650. $maxloadavg = ((x($_POST,'maxloadavg')) ? intval(trim($_POST['maxloadavg'])) : 50);
  651. $maxloadavg_frontend = ((x($_POST,'maxloadavg_frontend')) ? intval(trim($_POST['maxloadavg_frontend'])) : 50);
  652. $min_memory = ((x($_POST,'min_memory')) ? intval(trim($_POST['min_memory'])) : 0);
  653. $optimize_max_tablesize = ((x($_POST,'optimize_max_tablesize')) ? intval(trim($_POST['optimize_max_tablesize'])): 100);
  654. $optimize_fragmentation = ((x($_POST,'optimize_fragmentation')) ? intval(trim($_POST['optimize_fragmentation'])): 30);
  655. $poco_completion = ((x($_POST,'poco_completion')) ? intval(trim($_POST['poco_completion'])) : false);
  656. $poco_requery_days = ((x($_POST,'poco_requery_days')) ? intval(trim($_POST['poco_requery_days'])) : 7);
  657. $poco_discovery = ((x($_POST,'poco_discovery')) ? intval(trim($_POST['poco_discovery'])) : 0);
  658. $poco_discovery_since = ((x($_POST,'poco_discovery_since')) ? intval(trim($_POST['poco_discovery_since'])) : 30);
  659. $poco_local_search = ((x($_POST,'poco_local_search')) ? intval(trim($_POST['poco_local_search'])) : false);
  660. $nodeinfo = ((x($_POST,'nodeinfo')) ? intval(trim($_POST['nodeinfo'])) : false);
  661. $dfrn_only = ((x($_POST,'dfrn_only')) ? True : False);
  662. $ostatus_disabled = !((x($_POST,'ostatus_disabled')) ? True : False);
  663. $ostatus_poll_interval = ((x($_POST,'ostatus_poll_interval')) ? intval(trim($_POST['ostatus_poll_interval'])) : 0);
  664. $ostatus_full_threads = ((x($_POST,'ostatus_full_threads')) ? True : False);
  665. $diaspora_enabled = ((x($_POST,'diaspora_enabled')) ? True : False);
  666. $ssl_policy = ((x($_POST,'ssl_policy')) ? intval($_POST['ssl_policy']) : 0);
  667. $force_ssl = ((x($_POST,'force_ssl')) ? True : False);
  668. $hide_help = ((x($_POST,'hide_help')) ? True : False);
  669. $suppress_tags = ((x($_POST,'suppress_tags')) ? True : False);
  670. $itemcache = ((x($_POST,'itemcache')) ? notags(trim($_POST['itemcache'])) : '');
  671. $itemcache_duration = ((x($_POST,'itemcache_duration')) ? intval($_POST['itemcache_duration']) : 0);
  672. $max_comments = ((x($_POST,'max_comments')) ? intval($_POST['max_comments']) : 0);
  673. $temppath = ((x($_POST,'temppath')) ? notags(trim($_POST['temppath'])) : '');
  674. $basepath = ((x($_POST,'basepath')) ? notags(trim($_POST['basepath'])) : '');
  675. $singleuser = ((x($_POST,'singleuser')) ? notags(trim($_POST['singleuser'])) : '');
  676. $proxy_disabled = ((x($_POST,'proxy_disabled')) ? True : False);
  677. $only_tag_search