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.

2278 lines
88 KiB

10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
6 years ago
6 years ago
4 years ago
4 years ago
4 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
7 years ago
7 years ago
10 years ago
4 years ago
4 years ago
4 years ago
4 years ago
10 years ago
10 years ago
10 years ago
10 years ago
7 years ago
7 years ago
10 years ago
10 years ago
4 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
9 years ago
10 years ago
9 years ago
8 years ago
9 years ago
7 years ago
9 years ago
10 years ago
6 years ago
10 years ago
10 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
4 years ago
4 years ago
7 years ago
6 years ago
7 years ago
6 years ago
7 years ago
7 years ago
7 years ago
  1. <?php
  2. /**
  3. * @file mod/admin.php
  4. *
  5. * @brief Friendica admin
  6. */
  7. use Friendica\App;
  8. use Friendica\Core\System;
  9. use Friendica\Core\Config;
  10. require_once("include/enotify.php");
  11. require_once("include/text.php");
  12. require_once('include/items.php');
  13. /**
  14. * @brief Process send data from the admin panels subpages
  15. *
  16. * This function acts as relais for processing the data send from the subpages
  17. * of the admin panel. Depending on the 1st parameter of the url (argv[1])
  18. * specialized functions are called to process the data from the subpages.
  19. *
  20. * The function itself does not return anything, but the subsequencely function
  21. * return the HTML for the pages of the admin panel.
  22. *
  23. * @param App $a
  24. *
  25. */
  26. function admin_post(App $a) {
  27. if (!is_site_admin()) {
  28. return;
  29. }
  30. // do not allow a page manager to access the admin panel at all.
  31. if (x($_SESSION,'submanage') && intval($_SESSION['submanage'])) {
  32. return;
  33. }
  34. // urls
  35. if ($a->argc > 1) {
  36. switch ($a->argv[1]) {
  37. case 'site':
  38. admin_page_site_post($a);
  39. break;
  40. case 'users':
  41. admin_page_users_post($a);
  42. break;
  43. case 'plugins':
  44. if ($a->argc > 2 &&
  45. is_file("addon/".$a->argv[2]."/".$a->argv[2].".php")) {
  46. @include_once("addon/".$a->argv[2]."/".$a->argv[2].".php");
  47. if (function_exists($a->argv[2].'_plugin_admin_post')) {
  48. $func = $a->argv[2].'_plugin_admin_post';
  49. $func($a);
  50. }
  51. }
  52. goaway('admin/plugins/'.$a->argv[2]);
  53. return; // NOTREACHED
  54. break;
  55. case 'themes':
  56. if ($a->argc < 2) {
  57. if (is_ajax()) {
  58. return;
  59. }
  60. goaway('admin/');
  61. return;
  62. }
  63. $theme = $a->argv[2];
  64. if (is_file("view/theme/$theme/config.php")) {
  65. function __call_theme_admin_post(App $a, $theme) {
  66. $orig_theme = $a->theme;
  67. $orig_page = $a->page;
  68. $orig_session_theme = $_SESSION['theme'];
  69. require_once("view/theme/$theme/theme.php");
  70. require_once("view/theme/$theme/config.php");
  71. $_SESSION['theme'] = $theme;
  72. $init = $theme."_init";
  73. if (function_exists($init)) {
  74. $init($a);
  75. }
  76. if (function_exists("theme_admin_post")) {
  77. $admin_form = theme_admin_post($a);
  78. }
  79. $_SESSION['theme'] = $orig_session_theme;
  80. $a->theme = $orig_theme;
  81. $a->page = $orig_page;
  82. return $admin_form;
  83. }
  84. __call_theme_admin_post($a, $theme);
  85. }
  86. info(t('Theme settings updated.'));
  87. if (is_ajax()) {
  88. return;
  89. }
  90. goaway('admin/themes/'.$theme);
  91. return;
  92. break;
  93. case 'features':
  94. admin_page_features_post($a);
  95. break;
  96. case 'logs':
  97. admin_page_logs_post($a);
  98. break;
  99. case 'dbsync':
  100. admin_page_dbsync_post($a);
  101. break;
  102. case 'blocklist':
  103. admin_page_blocklist_post($a);
  104. break;
  105. case 'deleteitem':
  106. admin_page_deleteitem_post($a);
  107. break;
  108. }
  109. }
  110. goaway('admin');
  111. return; // NOTREACHED
  112. }
  113. /**
  114. * @brief Generates content of the admin panel pages
  115. *
  116. * This function generates the content for the admin panel. It consists of the
  117. * aside menu (same for the entire admin panel) and the code for the soecified
  118. * subpage of the panel.
  119. *
  120. * The structure of the adress is: /admin/subpage/details though "details" is
  121. * only necessary for some subpages, like themes or addons where it is the name
  122. * of one theme resp. addon from which the details should be shown. Content for
  123. * the subpages is generated in separate functions for each of the subpages.
  124. *
  125. * The returned string hold the generated HTML code of the page.
  126. *
  127. * @param App $a
  128. * @return string
  129. */
  130. function admin_content(App $a) {
  131. if (!is_site_admin()) {
  132. return login(false);
  133. }
  134. if (x($_SESSION,'submanage') && intval($_SESSION['submanage'])) {
  135. return "";
  136. }
  137. // APC deactivated, since there are problems with PHP 5.5
  138. //if (function_exists("apc_delete")) {
  139. // $toDelete = new APCIterator('user', APC_ITER_VALUE);
  140. // apc_delete($toDelete);
  141. //}
  142. // Header stuff
  143. $a->page['htmlhead'] .= replace_macros(get_markup_template('admin_settings_head.tpl'), array());
  144. /*
  145. * Side bar links
  146. */
  147. $aside_tools = array();
  148. // array(url, name, extra css classes)
  149. // not part of $aside to make the template more adjustable
  150. $aside_sub = array(
  151. 'site' => array("admin/site/", t("Site") , "site"),
  152. 'users' => array("admin/users/", t("Users") , "users"),
  153. 'plugins'=> array("admin/plugins/", t("Plugins") , "plugins"),
  154. 'themes' => array("admin/themes/", t("Themes") , "themes"),
  155. 'features' => array("admin/features/", t("Additional features") , "features"),
  156. 'dbsync' => array("admin/dbsync/", t('DB updates'), "dbsync"),
  157. 'queue' => array("admin/queue/", t('Inspect Queue'), "queue"),
  158. 'blocklist' => array("admin/blocklist/", t('Server Blocklist'), "blocklist"),
  159. 'federation' => array("admin/federation/", t('Federation Statistics'), "federation"),
  160. 'deleteitem' => array("admin/deleteitem/", t('Delete Item'), 'deleteitem'),
  161. );
  162. /* get plugins admin page */
  163. $r = q("SELECT `name` FROM `addon` WHERE `plugin_admin` = 1 ORDER BY `name`");
  164. $aside_tools['plugins_admin']=array();
  165. foreach ($r as $h) {
  166. $plugin =$h['name'];
  167. $aside_tools['plugins_admin'][] = array("admin/plugins/".$plugin, $plugin, "plugin");
  168. // temp plugins with admin
  169. $a->plugins_admin[] = $plugin;
  170. }
  171. $aside_tools['logs'] = array("admin/logs/", t("Logs"), "logs");
  172. $aside_tools['viewlogs'] = array("admin/viewlogs/", t("View Logs"), 'viewlogs');
  173. $aside_tools['diagnostics_probe'] = array('probe/', t('probe address'), 'probe');
  174. $aside_tools['diagnostics_webfinger'] = array('webfinger/', t('check webfinger'), 'webfinger');
  175. $t = get_markup_template("admin_aside.tpl");
  176. $a->page['aside'] .= replace_macros($t, array(
  177. '$admin' => $aside_tools,
  178. '$subpages' => $aside_sub,
  179. '$admtxt' => t('Admin'),
  180. '$plugadmtxt' => t('Plugin Features'),
  181. '$logtxt' => t('Logs'),
  182. '$diagnosticstxt' => t('diagnostics'),
  183. '$h_pending' => t('User registrations waiting for confirmation'),
  184. '$admurl'=> "admin/"
  185. ));
  186. /*
  187. * Page content
  188. */
  189. $o = '';
  190. // urls
  191. if ($a->argc > 1) {
  192. switch ($a->argv[1]) {
  193. case 'site':
  194. $o = admin_page_site($a);
  195. break;
  196. case 'users':
  197. $o = admin_page_users($a);
  198. break;
  199. case 'plugins':
  200. $o = admin_page_plugins($a);
  201. break;
  202. case 'themes':
  203. $o = admin_page_themes($a);
  204. break;
  205. case 'features':
  206. $o = admin_page_features($a);
  207. break;
  208. case 'logs':
  209. $o = admin_page_logs($a);
  210. break;
  211. case 'viewlogs':
  212. $o = admin_page_viewlogs($a);
  213. break;
  214. case 'dbsync':
  215. $o = admin_page_dbsync($a);
  216. break;
  217. case 'queue':
  218. $o = admin_page_queue($a);
  219. break;
  220. case 'federation':
  221. $o = admin_page_federation($a);
  222. break;
  223. case 'blocklist':
  224. $o = admin_page_blocklist($a);
  225. break;
  226. case 'deleteitem':
  227. $o = admin_page_deleteitem($a);
  228. break;
  229. default:
  230. notice(t("Item not found."));
  231. }
  232. } else {
  233. $o = admin_page_summary($a);
  234. }
  235. if (is_ajax()) {
  236. echo $o;
  237. killme();
  238. return '';
  239. } else {
  240. return $o;
  241. }
  242. }
  243. /**
  244. * @brief Subpage to modify the server wide block list via the admin panel.
  245. *
  246. * This function generates the subpage of the admin panel to allow the
  247. * modification of the node wide block/black list to block entire
  248. * remote servers from communication with this node. The page allows
  249. * adding, removing and editing of entries from the blocklist.
  250. *
  251. * @param App $a
  252. * @return string
  253. */
  254. function admin_page_blocklist(App $a) {
  255. $blocklist = Config::get('system', 'blocklist');
  256. $blocklistform = array();
  257. if (is_array($blocklist)) {
  258. foreach($blocklist as $id => $b) {
  259. $blocklistform[] = array(
  260. 'domain' => array("domain[$id]", t('Blocked domain'), $b['domain'], '', t('The blocked domain'), 'required', '', ''),
  261. 'reason' => array("reason[$id]", t("Reason for the block"), $b['reason'], t('The reason why you blocked this domain.').'('.$b['domain'].')', 'required', '', ''),
  262. 'delete' => array("delete[$id]", t("Delete domain").' ('.$b['domain'].')', False , t("Check to delete this entry from the blocklist"))
  263. );
  264. }
  265. }
  266. $t = get_markup_template("admin_blocklist.tpl");
  267. return replace_macros($t, array(
  268. '$title' => t('Administration'),
  269. '$page' => t('Server Blocklist'),
  270. '$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.'),
  271. '$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.'),
  272. '$addtitle' => t('Add new entry to block list'),
  273. '$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', '', ''),
  274. '$newreason' => array('newentry_reason', t('Block reason'), '', t('The reason why you blocked this domain.'), 'required', '', ''),
  275. '$submit' => t('Add Entry'),
  276. '$savechanges' => t('Save changes to the blocklist'),
  277. '$currenttitle' => t('Current Entries in the Blocklist'),
  278. '$thurl' => t('Blocked domain'),
  279. '$threason' => t('Reason for the block'),
  280. '$delentry' => t('Delete entry from blocklist'),
  281. '$entries' => $blocklistform,
  282. '$baseurl' => System::baseUrl(true),
  283. '$confirm_delete' => t('Delete entry from blocklist?'),
  284. '$form_security_token' => get_form_security_token("admin_blocklist")
  285. ));
  286. }
  287. /**
  288. * @brief Process send data from Admin Blocklist Page
  289. *
  290. * @param App $a
  291. */
  292. function admin_page_blocklist_post(App $a) {
  293. if (!x($_POST,"page_blocklist_save") && (!x($_POST['page_blocklist_edit']))) {
  294. return;
  295. }
  296. check_form_security_token_redirectOnErr('/admin/blocklist', 'admin_blocklist');
  297. if (x($_POST['page_blocklist_save'])) {
  298. // Add new item to blocklist
  299. $blocklist = get_config('system', 'blocklist');
  300. $blocklist[] = array(
  301. 'domain' => notags(trim($_POST['newentry_domain'])),
  302. 'reason' => notags(trim($_POST['newentry_reason']))
  303. );
  304. Config::set('system', 'blocklist', $blocklist);
  305. info(t('Server added to blocklist.').EOL);
  306. } else {
  307. // Edit the entries from blocklist
  308. $blocklist = array();
  309. foreach ($_POST['domain'] as $id => $domain) {
  310. // Trimming whitespaces as well as any lingering slashes
  311. $domain = notags(trim($domain, "\x00..\x1F/"));
  312. $reason = notags(trim($_POST['reason'][$id]));
  313. if (!x($_POST['delete'][$id])) {
  314. $blocklist[] = array(
  315. 'domain' => $domain,
  316. 'reason' => $reason
  317. );
  318. }
  319. }
  320. Config::set('system', 'blocklist', $blocklist);
  321. info(t('Site blocklist updated.').EOL);
  322. }
  323. goaway('admin/blocklist');
  324. return; // NOTREACHED
  325. }
  326. /**
  327. * @brief Subpage where the admin can delete an item from their node given the GUID
  328. *
  329. * This subpage of the admin panel offers the nodes admin to delete an item from
  330. * the node, given the GUID or the display URL such as http://example.com/display/123456.
  331. * The item will then be marked as deleted in the database and processed accordingly.
  332. *
  333. * @param App $a
  334. * @return string
  335. */
  336. function admin_page_deleteitem(App $a) {
  337. $t = get_markup_template("admin_deleteitem.tpl");
  338. return replace_macros($t, array(
  339. '$title' => t('Administration'),
  340. '$page' => t('Delete Item'),
  341. '$submit' => t('Delete this Item'),
  342. '$intro1' => t('On this page you can delete an item from your node. If the item is a top level posting, the entire thread will be deleted.'),
  343. '$intro2' => t('You need to know the GUID of the item. You can find it e.g. by looking at the display URL. The last part of http://example.com/display/123456 is the GUID, here 123456.'),
  344. '$deleteitemguid' => array('deleteitemguid', t("GUID"), '', t("The GUID of the item you want to delete."), 'required', 'autofocus'),
  345. '$baseurl' => System::baseUrl(),
  346. '$form_security_token' => get_form_security_token("admin_deleteitem")
  347. ));
  348. }
  349. /**
  350. * @brief Process send data from Admin Delete Item Page
  351. *
  352. * The GUID passed through the form should be only the GUID. But we also parse
  353. * URLs like the full /display URL to make the process more easy for the admin.
  354. *
  355. * @param App $a
  356. */
  357. function admin_page_deleteitem_post(App $a) {
  358. if (!x($_POST['page_deleteitem_submit'])) {
  359. return;
  360. }
  361. check_form_security_token_redirectOnErr('/admin/deleteitem/', 'admin_deleteitem');
  362. if (x($_POST['page_deleteitem_submit'])) {
  363. $guid = trim(notags($_POST['deleteitemguid']));
  364. // The GUID should not include a "/", so if there is one, we got an URL
  365. // and the last part of it is most likely the GUID.
  366. if (strpos($guid, '/')) {
  367. $guid = substr($guid, strrpos($guid, '/')+1);
  368. }
  369. // Now that we have the GUID get all IDs of the associated entries in the
  370. // item table of the DB and drop those items, which will also delete the
  371. // associated threads.
  372. $r = dba::select('item', array('id'), array('guid'=>$guid));
  373. while ($row = dba::fetch($r)) {
  374. drop_item($row['id'], false);
  375. }
  376. dba::close($r);
  377. }
  378. info(t('Item marked for deletion.').EOL);
  379. goaway('admin/deleteitem');
  380. return; // NOTREACHED
  381. }
  382. /**
  383. * @brief Subpage with some stats about "the federation" network
  384. *
  385. * This function generates the "Federation Statistics" subpage for the admin
  386. * panel. The page lists some numbers to the part of "The Federation" known to
  387. * the node. This data includes the different connected networks (e.g.
  388. * Diaspora, Hubzilla, GNU Social) and the used versions in the different
  389. * networks.
  390. *
  391. * The returned string contains the HTML code of the subpage for display.
  392. *
  393. * @param App $a
  394. * @return string
  395. */
  396. function admin_page_federation(App $a) {
  397. // get counts on active friendica, diaspora, redmatrix, hubzilla, gnu
  398. // social and statusnet nodes this node is knowing
  399. //
  400. // We are looking for the following platforms in the DB, "Red" should find
  401. // all variants of that platform ID string as the q() function is stripping
  402. // off one % two of them are needed in the query
  403. // Add more platforms if you like, when one returns 0 known nodes it is not
  404. // displayed on the stats page.
  405. $platforms = array('Friendi%%a', 'Diaspora', '%%red%%', 'Hubzilla', 'BlaBlaNet', 'GNU Social', 'StatusNet', 'Mastodon', 'Pleroma');
  406. $colors = array('Friendi%%a' => '#ffc018', // orange from the logo
  407. 'Diaspora' => '#a1a1a1', // logo is black and white, makes a gray
  408. '%%red%%' => '#c50001', // fire red from the logo
  409. 'Hubzilla' => '#43488a', // blue from the logo
  410. 'BlaBlaNet' => '#3B5998', // blue from the navbar at blablanet-dot-com
  411. 'GNU Social'=> '#a22430', // dark red from the logo
  412. 'StatusNet' => '#789240', // the green from the logo (red and blue have already others
  413. 'Mastodon' => '#1a9df9', // blue from the Mastodon logo
  414. 'Pleroma' => '#E46F0F'); // Orange from the text that is used on Pleroma instances
  415. $counts = array();
  416. $total = 0;
  417. foreach ($platforms as $p) {
  418. // get a total count for the platform, the name and version of the
  419. // highest version and the protocol tpe
  420. $c = q('SELECT COUNT(*) AS `total`, ANY_VALUE(`platform`) AS `platform`,
  421. ANY_VALUE(`network`) AS `network`, MAX(`version`) AS `version` FROM `gserver`
  422. WHERE `platform` LIKE "%s" AND `last_contact` >= `last_failure`
  423. ORDER BY `version` ASC;', $p);
  424. $total = $total + $c[0]['total'];
  425. // what versions for that platform do we know at all?
  426. // again only the active nodes
  427. $v = q('SELECT COUNT(*) AS `total`, `version` FROM `gserver`
  428. WHERE `last_contact` >= `last_failure` AND `platform` LIKE "%s"
  429. GROUP BY `version`
  430. ORDER BY `version`;', $p);
  431. //
  432. // clean up version numbers
  433. //
  434. // some platforms do not provide version information, add a unkown there
  435. // to the version string for the displayed list.
  436. foreach ($v as $key => $value) {
  437. if ($v[$key]['version'] == '') {
  438. $v[$key] = array('total'=>$v[$key]['total'], 'version'=>t('unknown'));
  439. }
  440. }
  441. // in the DB the Diaspora versions have the format x.x.x.x-xx the last
  442. // part (-xx) should be removed to clean up the versions from the "head
  443. // commit" information and combined into a single entry for x.x.x.x
  444. if ($p == 'Diaspora') {
  445. $newV = array();
  446. $newVv = array();
  447. foreach ($v as $vv) {
  448. $newVC = $vv['total'];
  449. $newVV = $vv['version'];
  450. $posDash = strpos($newVV, '-');
  451. if ($posDash) {
  452. $newVV = substr($newVV, 0, $posDash);
  453. }
  454. if (isset($newV[$newVV])) {
  455. $newV[$newVV] += $newVC;
  456. } else {
  457. $newV[$newVV] = $newVC;
  458. }
  459. }
  460. foreach ($newV as $key => $value) {
  461. array_push($newVv, array('total'=>$value, 'version'=>$key));
  462. }
  463. $v = $newVv;
  464. }
  465. // early friendica versions have the format x.x.xxxx where xxxx is the
  466. // DB version stamp; those should be operated out and versions be
  467. // conbined
  468. if ($p == 'Friendi%%a') {
  469. $newV = array();
  470. $newVv = array();
  471. foreach ($v as $vv) {
  472. $newVC = $vv['total'];
  473. $newVV = $vv['version'];
  474. $lastDot = strrpos($newVV,'.');
  475. $len = strlen($newVV)-1;
  476. if (($lastDot == $len-4) && (!strrpos($newVV,'-rc') == $len-3)) {
  477. $newVV = substr($newVV, 0, $lastDot);
  478. }
  479. if (isset($newV[$newVV])) {
  480. $newV[$newVV] += $newVC;
  481. } else {
  482. $newV[$newVV] = $newVC;
  483. }
  484. }
  485. foreach ($newV as $key => $value) {
  486. array_push($newVv, array('total'=>$value, 'version'=>$key));
  487. }
  488. $v = $newVv;
  489. }
  490. foreach ($v as $key => $vv)
  491. $v[$key]["version"] = trim(strip_tags($vv["version"]));
  492. // the 3rd array item is needed for the JavaScript graphs as JS does
  493. // not like some characters in the names of variables...
  494. $counts[$p]=array($c[0], $v, str_replace(array(' ','%'),'',$p), $colors[$p]);
  495. }
  496. // some helpful text
  497. $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.');
  498. $hint = t('The <em>Auto Discovered Contact Directory</em> feature is not enabled, it will improve the data displayed here.');
  499. // load the template, replace the macros and return the page content
  500. $t = get_markup_template("admin_federation.tpl");
  501. return replace_macros($t, array(
  502. '$title' => t('Administration'),
  503. '$page' => t('Federation Statistics'),
  504. '$intro' => $intro,
  505. '$hint' => $hint,
  506. '$autoactive' => get_config('system', 'poco_completion'),
  507. '$counts' => $counts,
  508. '$version' => FRIENDICA_VERSION,
  509. '$legendtext' => sprintf(t('Currently this node is aware of %d nodes from the following platforms:'), $total),
  510. '$baseurl' => System::baseUrl(),
  511. ));
  512. }
  513. /**
  514. * @brief Admin Inspect Queue Page
  515. *
  516. * Generates a page for the admin to have a look into the current queue of
  517. * postings that are not deliverabke. Shown are the name and url of the
  518. * recipient, the delivery network and the dates when the posting was generated
  519. * and the last time tried to deliver the posting.
  520. *
  521. * The returned string holds the content of the page.
  522. *
  523. * @param App $a
  524. * @return string
  525. */
  526. function admin_page_queue(App $a) {
  527. // get content from the queue table
  528. $r = q("SELECT `c`.`name`, `c`.`nurl`, `q`.`id`, `q`.`network`, `q`.`created`, `q`.`last`
  529. FROM `queue` AS `q`, `contact` AS `c`
  530. WHERE `c`.`id` = `q`.`cid`
  531. ORDER BY `q`.`cid`, `q`.`created`;");
  532. $t = get_markup_template("admin_queue.tpl");
  533. return replace_macros($t, array(
  534. '$title' => t('Administration'),
  535. '$page' => t('Inspect Queue'),
  536. '$count' => sizeof($r),
  537. 'id_header' => t('ID'),
  538. '$to_header' => t('Recipient Name'),
  539. '$url_header' => t('Recipient Profile'),
  540. '$network_header' => t('Network'),
  541. '$created_header' => t('Created'),
  542. '$last_header' => t('Last Tried'),
  543. '$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.'),
  544. '$entries' => $r,
  545. ));
  546. }
  547. /**
  548. * @brief Admin Summary Page
  549. *
  550. * The summary page is the "start page" of the admin panel. It gives the admin
  551. * a first overview of the open adminastrative tasks.
  552. *
  553. * The returned string contains the HTML content of the generated page.
  554. *
  555. * @param App $a
  556. * @return string
  557. */
  558. function admin_page_summary(App $a) {
  559. // are there MyISAM tables in the DB? If so, trigger a warning message
  560. $r = q("SELECT `engine` FROM `information_schema`.`tables` WHERE `engine` = 'myisam' AND `table_schema` = '%s' LIMIT 1",
  561. dbesc(dba::database_name()));
  562. $showwarning = false;
  563. $warningtext = array();
  564. if (dbm::is_result($r)) {
  565. $showwarning = true;
  566. $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');
  567. }
  568. if (Config::get('system', 'dbupdate', DB_UPDATE_NOT_CHECKED) == DB_UPDATE_NOT_CHECKED) {
  569. require_once("include/dbstructure.php");
  570. update_structure(false, true);
  571. }
  572. if (Config::get('system', 'dbupdate') == DB_UPDATE_FAILED) {
  573. $showwarning = true;
  574. $warningtext[] = t('The database update failed. Please run "php include/dbstructure.php update" from the command line and have a look at the errors that might appear.');
  575. }
  576. $last_worker_call = Config::get('system', 'last_poller_execution', false);
  577. if (!$last_worker_call) {
  578. $showwarning = true;
  579. $warningtext[] = t('The worker was never executed. Please check your database structure!');
  580. } elseif ((strtotime(datetime_convert()) - strtotime($last_worker_call)) > 60 * 60) {
  581. $showwarning = true;
  582. $warningtext[] = sprintf(t('The last worker execution was on %s UTC. This is older than one hour. Please check your crontab settings.'), $last_worker_call);
  583. }
  584. $r = q("SELECT `page-flags`, COUNT(`uid`) AS `count` FROM `user` GROUP BY `page-flags`");
  585. $accounts = array(
  586. array(t('Normal Account'), 0),
  587. array(t('Automatic Follower Account'), 0),
  588. array(t('Public Forum Account'), 0),
  589. array(t('Automatic Friend Account'), 0),
  590. array(t('Blog Account'), 0),
  591. array(t('Private Forum Account'), 0)
  592. );
  593. $users=0;
  594. foreach ($r as $u) {
  595. $accounts[$u['page-flags']][1] = $u['count'];
  596. $users+= $u['count'];
  597. }
  598. logger('accounts: '.print_r($accounts,true),LOGGER_DATA);
  599. $r = q("SELECT COUNT(`id`) AS `count` FROM `register`");
  600. $pending = $r[0]['count'];
  601. $r = q("SELECT COUNT(*) AS `total` FROM `queue` WHERE 1");
  602. $queue = (($r) ? $r[0]['total'] : 0);
  603. $r = q("SELECT COUNT(*) AS `total` FROM `workerqueue` WHERE NOT `done`");
  604. $workerqueue = (($r) ? $r[0]['total'] : 0);
  605. // We can do better, but this is a quick queue status
  606. $queues = array('label' => t('Message queues'), 'queue' => $queue, 'workerq' => $workerqueue);
  607. $t = get_markup_template("admin_summary.tpl");
  608. return replace_macros($t, array(
  609. '$title' => t('Administration'),
  610. '$page' => t('Summary'),
  611. '$queues' => $queues,
  612. '$users' => array(t('Registered users'), $users),
  613. '$accounts' => $accounts,
  614. '$pending' => array(t('Pending registrations'), $pending),
  615. '$version' => array(t('Version'), FRIENDICA_VERSION),
  616. '$baseurl' => System::baseUrl(),
  617. '$platform' => FRIENDICA_PLATFORM,
  618. '$codename' => FRIENDICA_CODENAME,
  619. '$build' => get_config('system','build'),
  620. '$plugins' => array(t('Active plugins'), $a->plugins),
  621. '$showwarning' => $showwarning,
  622. '$warningtext' => $warningtext
  623. ));
  624. }
  625. /**
  626. * @brief Process send data from Admin Site Page
  627. *
  628. * @param App $a
  629. */
  630. function admin_page_site_post(App $a) {
  631. check_form_security_token_redirectOnErr('/admin/site', 'admin_site');
  632. if (!empty($_POST['republish_directory'])) {
  633. proc_run(PRIORITY_LOW, 'include/directory.php');
  634. return;
  635. }
  636. if (!x($_POST,"page_site")) {
  637. return;
  638. }
  639. // relocate
  640. if (x($_POST,'relocate') && x($_POST,'relocate_url') && $_POST['relocate_url'] != "") {
  641. $new_url = $_POST['relocate_url'];
  642. $new_url = rtrim($new_url,"/