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.
 
 
 
 
 
 

2172 lines
85 KiB

  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. 'url' => Array("url[$id]", t('Blocked URL'), $b['URL'], '', t('The blocked URL'), 'required', '', ''),
  251. 'reason' => Array("reason[$id]", t("Reason for the block"), $b['reason'], t('The reason why you blocked this URL.').'('.$b['URL'].')', 'required', '', ''),
  252. 'delete' => Array("delete[$id]", t("Delete UFL").' ('.$b['URL'].')', 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 URLs 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. '$newurl' => Array('newentry_url', t('Server URL'), '', t('The URL of the new server to add to the block list. Do not include the protocol to the URL.'), 'required', '', ''),
  264. '$newreason' => Array('newentry_reason', t('Block reason'), '', t('The reason why you blocked this URL.'), '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 URL'),
  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 entriy 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. 'URL' => notags(trim($_POST['newentry_url'])),
  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['url'] as $id => $URL) {
  300. $URL = notags(trim($URL));
  301. $reason = notags(trim($_POST['reason'][$id]));
  302. if (!x($_POST['delete'][$id])) {
  303. $blocklist[] = Array(
  304. 'URL' => $URL,
  305. 'reason' => $reason
  306. );
  307. }
  308. }
  309. Config::set('system', 'blocklist', $blocklist);
  310. info(t('Site blocklist updated.').EOL);
  311. }
  312. goaway('admin/blocklist');
  313. return; // NOTREACHED
  314. }
  315. /**
  316. * @brief Subpage with some stats about "the federation" network
  317. *
  318. * This function generates the "Federation Statistics" subpage for the admin
  319. * panel. The page lists some numbers to the part of "The Federation" known to
  320. * the node. This data includes the different connected networks (e.g.
  321. * Diaspora, Hubzilla, GNU Social) and the used versions in the different
  322. * networks.
  323. *
  324. * The returned string contains the HTML code of the subpage for display.
  325. *
  326. * @param App $a
  327. * @return string
  328. */
  329. function admin_page_federation(App $a) {
  330. // get counts on active friendica, diaspora, redmatrix, hubzilla, gnu
  331. // social and statusnet nodes this node is knowing
  332. //
  333. // We are looking for the following platforms in the DB, "Red" should find
  334. // all variants of that platform ID string as the q() function is stripping
  335. // off one % two of them are needed in the query
  336. // Add more platforms if you like, when one returns 0 known nodes it is not
  337. // displayed on the stats page.
  338. $platforms = array('Friendi%%a', 'Diaspora', '%%red%%', 'Hubzilla', 'BlaBlaNet', 'GNU Social', 'StatusNet', 'Mastodon');
  339. $colors = array('Friendi%%a' => '#ffc018', // orange from the logo
  340. 'Diaspora' => '#a1a1a1', // logo is black and white, makes a gray
  341. '%%red%%' => '#c50001', // fire red from the logo
  342. 'Hubzilla' => '#43488a', // blue from the logo
  343. 'BlaBlaNet' => '#3B5998', // blue from the navbar at blablanet-dot-com
  344. 'GNU Social'=> '#a22430', // dark red from the logo
  345. 'StatusNet' => '#789240', // the green from the logo (red and blue have already others
  346. 'Mastodon' => '#1a9df9'); // blue from the Mastodon logo
  347. $counts = array();
  348. $total = 0;
  349. foreach ($platforms as $p) {
  350. // get a total count for the platform, the name and version of the
  351. // highest version and the protocol tpe
  352. $c = qu('SELECT COUNT(*) AS `total`, ANY_VALUE(`platform`) AS `platform`,
  353. ANY_VALUE(`network`) AS `network`, MAX(`version`) AS `version` FROM `gserver`
  354. WHERE `platform` LIKE "%s" AND `last_contact` >= `last_failure`
  355. ORDER BY `version` ASC;', $p);
  356. $total = $total + $c[0]['total'];
  357. // what versions for that platform do we know at all?
  358. // again only the active nodes
  359. $v = qu('SELECT COUNT(*) AS `total`, `version` FROM `gserver`
  360. WHERE `last_contact` >= `last_failure` AND `platform` LIKE "%s"
  361. GROUP BY `version`
  362. ORDER BY `version`;', $p);
  363. //
  364. // clean up version numbers
  365. //
  366. // some platforms do not provide version information, add a unkown there
  367. // to the version string for the displayed list.
  368. foreach ($v as $key => $value) {
  369. if ($v[$key]['version'] == '') {
  370. $v[$key] = array('total'=>$v[$key]['total'], 'version'=>t('unknown'));
  371. }
  372. }
  373. // in the DB the Diaspora versions have the format x.x.x.x-xx the last
  374. // part (-xx) should be removed to clean up the versions from the "head
  375. // commit" information and combined into a single entry for x.x.x.x
  376. if ($p == 'Diaspora') {
  377. $newV = array();
  378. $newVv = array();
  379. foreach ($v as $vv) {
  380. $newVC = $vv['total'];
  381. $newVV = $vv['version'];
  382. $posDash = strpos($newVV, '-');
  383. if ($posDash) {
  384. $newVV = substr($newVV, 0, $posDash);
  385. }
  386. if (isset($newV[$newVV])) {
  387. $newV[$newVV] += $newVC;
  388. } else {
  389. $newV[$newVV] = $newVC;
  390. }
  391. }
  392. foreach ($newV as $key => $value) {
  393. array_push($newVv, array('total'=>$value, 'version'=>$key));
  394. }
  395. $v = $newVv;
  396. }
  397. // early friendica versions have the format x.x.xxxx where xxxx is the
  398. // DB version stamp; those should be operated out and versions be
  399. // conbined
  400. if ($p == 'Friendi%%a') {
  401. $newV = array();
  402. $newVv = array();
  403. foreach ($v as $vv) {
  404. $newVC = $vv['total'];
  405. $newVV = $vv['version'];
  406. $lastDot = strrpos($newVV,'.');
  407. $len = strlen($newVV)-1;
  408. if (($lastDot == $len-4) && (!strrpos($newVV,'-rc') == $len-3)) {
  409. $newVV = substr($newVV, 0, $lastDot);
  410. }
  411. if (isset($newV[$newVV])) {
  412. $newV[$newVV] += $newVC;
  413. } else {
  414. $newV[$newVV] = $newVC;
  415. }
  416. }
  417. foreach ($newV as $key => $value) {
  418. array_push($newVv, array('total'=>$value, 'version'=>$key));
  419. }
  420. $v = $newVv;
  421. }
  422. foreach ($v as $key => $vv)
  423. $v[$key]["version"] = trim(strip_tags($vv["version"]));
  424. // the 3rd array item is needed for the JavaScript graphs as JS does
  425. // not like some characters in the names of variables...
  426. $counts[$p]=array($c[0], $v, str_replace(array(' ','%'),'',$p), $colors[$p]);
  427. }
  428. // some helpful text
  429. $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.');
  430. $hint = t('The <em>Auto Discovered Contact Directory</em> feature is not enabled, it will improve the data displayed here.');
  431. // load the template, replace the macros and return the page content
  432. $t = get_markup_template("admin_federation.tpl");
  433. return replace_macros($t, array(
  434. '$title' => t('Administration'),
  435. '$page' => t('Federation Statistics'),
  436. '$intro' => $intro,
  437. '$hint' => $hint,
  438. '$autoactive' => get_config('system', 'poco_completion'),
  439. '$counts' => $counts,
  440. '$version' => FRIENDICA_VERSION,
  441. '$legendtext' => sprintf(t('Currently this node is aware of %d nodes from the following platforms:'), $total),
  442. '$baseurl' => App::get_baseurl(),
  443. ));
  444. }
  445. /**
  446. * @brief Admin Inspect Queue Page
  447. *
  448. * Generates a page for the admin to have a look into the current queue of
  449. * postings that are not deliverabke. Shown are the name and url of the
  450. * recipient, the delivery network and the dates when the posting was generated
  451. * and the last time tried to deliver the posting.
  452. *
  453. * The returned string holds the content of the page.
  454. *
  455. * @param App $a
  456. * @return string
  457. */
  458. function admin_page_queue(App $a) {
  459. // get content from the queue table
  460. $r = q("SELECT `c`.`name`, `c`.`nurl`, `q`.`id`, `q`.`network`, `q`.`created`, `q`.`last`
  461. FROM `queue` AS `q`, `contact` AS `c`
  462. WHERE `c`.`id` = `q`.`cid`
  463. ORDER BY `q`.`cid`, `q`.`created`;");
  464. $t = get_markup_template("admin_queue.tpl");
  465. return replace_macros($t, array(
  466. '$title' => t('Administration'),
  467. '$page' => t('Inspect Queue'),
  468. '$count' => sizeof($r),
  469. 'id_header' => t('ID'),
  470. '$to_header' => t('Recipient Name'),
  471. '$url_header' => t('Recipient Profile'),
  472. '$network_header' => t('Network'),
  473. '$created_header' => t('Created'),
  474. '$last_header' => t('Last Tried'),
  475. '$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.'),
  476. '$entries' => $r,
  477. ));
  478. }
  479. /**
  480. * @brief Admin Summary Page
  481. *
  482. * The summary page is the "start page" of the admin panel. It gives the admin
  483. * a first overview of the open adminastrative tasks.
  484. *
  485. * The returned string contains the HTML content of the generated page.
  486. *
  487. * @param App $a
  488. * @return string
  489. */
  490. function admin_page_summary(App $a) {
  491. global $db;
  492. // are there MyISAM tables in the DB? If so, trigger a warning message
  493. $r = q("SELECT `engine` FROM `information_schema`.`tables` WHERE `engine` = 'myisam' AND `table_schema` = '%s' LIMIT 1",
  494. dbesc($db->database_name()));
  495. $showwarning = false;
  496. $warningtext = array();
  497. if (dbm::is_result($r)) {
  498. $showwarning = true;
  499. $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');
  500. }
  501. // MySQL >= 5.7.4 doesn't support the IGNORE keyword in ALTER TABLE statements
  502. if ((version_compare($db->server_info(), '5.7.4') >= 0) AND
  503. !(strpos($db->server_info(), 'MariaDB') !== false)) {
  504. $warningtext[] = t('You are using a MySQL version which does not support all features that Friendica uses. You should consider switching to MariaDB.');
  505. }
  506. $r = q("SELECT `page-flags`, COUNT(`uid`) AS `count` FROM `user` GROUP BY `page-flags`");
  507. $accounts = array(
  508. array(t('Normal Account'), 0),
  509. array(t('Soapbox Account'), 0),
  510. array(t('Community/Celebrity Account'), 0),
  511. array(t('Automatic Friend Account'), 0),
  512. array(t('Blog Account'), 0),
  513. array(t('Private Forum'), 0)
  514. );
  515. $users=0;
  516. foreach ($r as $u) {
  517. $accounts[$u['page-flags']][1] = $u['count'];
  518. $users+= $u['count'];
  519. }
  520. logger('accounts: '.print_r($accounts,true),LOGGER_DATA);
  521. $r = qu("SELECT COUNT(`id`) AS `count` FROM `register`");
  522. $pending = $r[0]['count'];
  523. $r = qu("SELECT COUNT(*) AS `total` FROM `queue` WHERE 1");
  524. $queue = (($r) ? $r[0]['total'] : 0);
  525. $r = qu("SELECT COUNT(*) AS `total` FROM `workerqueue` WHERE 1");
  526. $workerqueue = (($r) ? $r[0]['total'] : 0);
  527. // We can do better, but this is a quick queue status
  528. $queues = array('label' => t('Message queues'), 'queue' => $queue, 'workerq' => $workerqueue);
  529. $t = get_markup_template("admin_summary.tpl");
  530. return replace_macros($t, array(
  531. '$title' => t('Administration'),
  532. '$page' => t('Summary'),
  533. '$queues' => $queues,
  534. '$users' => array(t('Registered users'), $users),
  535. '$accounts' => $accounts,
  536. '$pending' => array(t('Pending registrations'), $pending),
  537. '$version' => array(t('Version'), FRIENDICA_VERSION),
  538. '$baseurl' => App::get_baseurl(),
  539. '$platform' => FRIENDICA_PLATFORM,
  540. '$codename' => FRIENDICA_CODENAME,
  541. '$build' => get_config('system','build'),
  542. '$plugins' => array(t('Active plugins'), $a->plugins),
  543. '$showwarning' => $showwarning,
  544. '$warningtext' => $warningtext
  545. ));
  546. }
  547. /**
  548. * @brief Process send data from Admin Site Page
  549. *
  550. * @param App $a
  551. */
  552. function admin_page_site_post(App $a) {
  553. if (!x($_POST,"page_site")) {
  554. return;
  555. }
  556. check_form_security_token_redirectOnErr('/admin/site', 'admin_site');
  557. // relocate
  558. if (x($_POST,'relocate') && x($_POST,'relocate_url') && $_POST['relocate_url'] != "") {
  559. $new_url = $_POST['relocate_url'];
  560. $new_url = rtrim($new_url,"/");
  561. $parsed = @parse_url($new_url);
  562. if (!$parsed || (!x($parsed,'host') || !x($parsed,'scheme'))) {
  563. notice(t("Can not parse base url. Must have at least <scheme>://<domain>"));
  564. goaway('admin/site');
  565. }
  566. /* steps:
  567. * replace all "baseurl" to "new_url" in config, profile, term, items and contacts
  568. * send relocate for every local user
  569. * */
  570. $old_url = App::get_baseurl(true);
  571. // Generate host names for relocation the addresses in the format user@address.tld
  572. $new_host = str_replace("http://", "@", normalise_link($new_url));
  573. $old_host = str_replace("http://", "@", normalise_link($old_url));
  574. function update_table($table_name, $fields, $old_url, $new_url) {
  575. global $db, $a;
  576. $dbold = dbesc($old_url);
  577. $dbnew = dbesc($new_url);
  578. $upd = array();
  579. foreach ($fields as $f) {
  580. $upd[] = "`$f` = REPLACE(`$f`, '$dbold', '$dbnew')";
  581. }
  582. $upds = implode(", ", $upd);
  583. $q = sprintf("UPDATE %s SET %s;", $table_name, $upds);
  584. $r = q($q);
  585. if (!$r) {
  586. notice("Failed updating '$table_name': ".$db->error);
  587. goaway('admin/site');
  588. }
  589. }
  590. // update tables
  591. // update profile links in the format "http://server.tld"
  592. update_table("profile", array('photo', 'thumb'), $old_url, $new_url);
  593. update_table("term", array('url'), $old_url, $new_url);
  594. update_table("contact", array('photo','thumb','micro','url','nurl','alias','request','notify','poll','confirm','poco', 'avatar'), $old_url, $new_url);
  595. update_table("gcontact", array('url','nurl','photo','server_url','notify','alias'), $old_url, $new_url);
  596. update_table("item", array('owner-link','owner-avatar','author-link','author-avatar','body','plink','tag'), $old_url, $new_url);
  597. // update profile addresses in the format "user@server.tld"
  598. update_table("contact", array('addr'), $old_host, $new_host);
  599. update_table("gcontact", array('connect','addr'), $old_host, $new_host);
  600. // update config
  601. $a->set_baseurl($new_url);
  602. set_config('system','url',$new_url);
  603. // send relocate
  604. $users = q("SELECT `uid` FROM `user` WHERE `account_removed` = 0 AND `account_expired` = 0");
  605. foreach ($users as $user) {
  606. proc_run(PRIORITY_HIGH, 'include/notifier.php', 'relocate', $user['uid']);
  607. }
  608. info("Relocation started. Could take a while to complete.");
  609. goaway('admin/site');
  610. }
  611. // end relocate
  612. $sitename = ((x($_POST,'sitename')) ? notags(trim($_POST['sitename'])) : '');
  613. $hostname = ((x($_POST,'hostname')) ? notags(trim($_POST['hostname'])) : '');
  614. $sender_email = ((x($_POST,'sender_email')) ? notags(trim($_POST['sender_email'])) : '');
  615. $banner = ((x($_POST,'banner')) ? trim($_POST['banner']) : false);
  616. $shortcut_icon = ((x($_POST,'shortcut_icon')) ? notags(trim($_POST['shortcut_icon'])) : '');
  617. $touch_icon = ((x($_POST,'touch_icon')) ? notags(trim($_POST['touch_icon'])) : '');
  618. $info = ((x($_POST,'info')) ? trim($_POST['info']) : false);
  619. $language = ((x($_POST,'language')) ? notags(trim($_POST['language'])) : '');
  620. $theme = ((x($_POST,'theme')) ? notags(trim($_POST['theme'])) : '');
  621. $theme_mobile = ((x($_POST,'theme_mobile')) ? notags(trim($_POST['theme_mobile'])) : '');
  622. $maximagesize = ((x($_POST,'maximagesize')) ? intval(trim($_POST['maximagesize'])) : 0);
  623. $maximagelength = ((x($_POST,'maximagelength')) ? intval(trim($_POST['maximagelength'])) : MAX_IMAGE_LENGTH);
  624. $jpegimagequality = ((x($_POST,'jpegimagequality')) ? intval(trim($_POST['jpegimagequality'])) : JPEG_QUALITY);
  625. $register_policy = ((x($_POST,'register_policy')) ? intval(trim($_POST['register_policy'])) : 0);
  626. $daily_registrations = ((x($_POST,'max_daily_registrations')) ? intval(trim($_POST['max_daily_registrations'])) :0);
  627. $abandon_days = ((x($_POST,'abandon_days')) ? intval(trim($_POST['abandon_days'])) : 0);
  628. $register_text = ((x($_POST,'register_text')) ? notags(trim($_POST['register_text'])) : '');
  629. $allowed_sites = ((x($_POST,'allowed_sites')) ? notags(trim($_POST['allowed_sites'])) : '');
  630. $allowed_email = ((x($_POST,'allowed_email')) ? notags(trim($_POST['allowed_email'])) : '');
  631. $block_public = ((x($_POST,'block_public')) ? True : False);
  632. $force_publish = ((x($_POST,'publish_all')) ? True : False);
  633. $global_directory = ((x($_POST,'directory')) ? notags(trim($_POST['directory'])) : '');
  634. $thread_allow = ((x($_POST,'thread_allow')) ? True : False);
  635. $newuser_private = ((x($_POST,'newuser_private')) ? True : False);
  636. $enotify_no_content = ((x($_POST,'enotify_no_content')) ? True : False);
  637. $private_addons = ((x($_POST,'private_addons')) ? True : False);
  638. $disable_embedded = ((x($_POST,'disable_embedded')) ? True : False);
  639. $allow_users_remote_self = ((x($_POST,'allow_users_remote_self')) ? True : False);
  640. $no_multi_reg = ((x($_POST,'no_multi_reg')) ? True : False);
  641. $no_openid = !((x($_POST,'no_openid')) ? True : False);
  642. $no_regfullname = !((x($_POST,'no_regfullname')) ? True : False);
  643. $community_page_style = ((x($_POST,'community_page_style')) ? intval(trim($_POST['community_page_style'])) : 0);
  644. $max_author_posts_community_page = ((x($_POST,'max_author_posts_community_page')) ? intval(trim($_POST['max_author_posts_community_page'])) : 0);
  645. $verifyssl = ((x($_POST,'verifyssl')) ? True : False);
  646. $proxyuser = ((x($_POST,'proxyuser')) ? notags(trim($_POST['proxyuser'])) : '');
  647. $proxy = ((x($_POST,'proxy')) ? notags(trim($_POST['proxy'])) : '');
  648. $timeout = ((x($_POST,'timeout')) ? intval(trim($_POST['timeout'])) : 60);
  649. $maxloadavg = ((x($_POST,'maxloadavg')) ? intval(trim($_POST['maxloadavg'])) : 50);
  650. $maxloadavg_frontend = ((x($_POST,'maxloadavg_frontend')) ? intval(trim($_POST['maxloadavg_frontend'])) : 50);
  651. $optimize_max_tablesize = ((x($_POST,'optimize_max_tablesize')) ? intval(trim($_POST['optimize_max_tablesize'])): 100);
  652. $optimize_fragmentation = ((x($_POST,'optimize_fragmentation')) ? intval(trim($_POST['optimize_fragmentation'])): 30);
  653. $poco_completion = ((x($_POST,'poco_completion')) ? intval(trim($_POST['poco_completion'])) : false);
  654. $poco_requery_days = ((x($_POST,'poco_requery_days')) ? intval(trim($_POST['poco_requery_days'])) : 7);
  655. $poco_discovery = ((x($_POST,'poco_discovery')) ? intval(trim($_POST['poco_discovery'])) : 0);
  656. $poco_discovery_since = ((x($_POST,'poco_discovery_since')) ? intval(trim($_POST['poco_discovery_since'])) : 30);
  657. $poco_local_search = ((x($_POST,'poco_local_search')) ? intval(trim($_POST['poco_local_search'])) : false);
  658. $nodeinfo = ((x($_POST,'nodeinfo')) ? intval(trim($_POST['nodeinfo'])) : false);
  659. $dfrn_only = ((x($_POST,'dfrn_only')) ? True : False);
  660. $ostatus_disabled = !((x($_POST,'ostatus_disabled')) ? True : False);
  661. $ostatus_poll_interval = ((x($_POST,'ostatus_poll_interval')) ? intval(trim($_POST['ostatus_poll_interval'])) : 0);
  662. $ostatus_full_threads = ((x($_POST,'ostatus_full_threads')) ? True : False);
  663. $diaspora_enabled = ((x($_POST,'diaspora_enabled')) ? True : False);
  664. $ssl_policy = ((x($_POST,'ssl_policy')) ? intval($_POST['ssl_policy']) : 0);
  665. $force_ssl = ((x($_POST,'force_ssl')) ? True : False);
  666. $hide_help = ((x($_POST,'hide_help')) ? True : False);
  667. $suppress_tags = ((x($_POST,'suppress_tags')) ? True : False);
  668. $itemcache = ((x($_POST,'itemcache')) ? notags(trim($_POST['itemcache'])) : '');
  669. $itemcache_duration = ((x($_POST,'itemcache_duration')) ? intval($_POST['itemcache_duration']) : 0);
  670. $max_comments = ((x($_POST,'max_comments')) ? intval($_POST['max_comments']) : 0);
  671. $temppath = ((x($_POST,'temppath')) ? notags(trim($_POST['temppath'])) : '');
  672. $basepath = ((x($_POST,'basepath')) ? notags(trim($_POST['basepath'])) : '');
  673. $singleuser = ((x($_POST,'singleuser')) ? notags(trim($_POST['singleuser'])) : '');
  674. $proxy_disabled = ((x($_POST,'proxy_disabled')) ? True : False);
  675. $only_tag_search = ((x($_POST,'only_tag_search')) ? True : False);
  676. $rino = ((x($_POST,'rino')) ? intval($_POST['rino']) : 0);
  677. $worker_queues = ((x($_POST,'worker_queues')) ? intval($_POST['worker_queues']) : 4);
  678. $worker_dont_fork = ((x($_POST,'worker_dont_fork')) ? True : False);
  679. $worker_fastlane = ((x($_POST,'worker_fastlane')) ? True : False);
  680. $worker_frontend = ((x($_POST,'worker_frontend')) ? True : False);
  681. // Has the directory url changed? If yes, then resubmit the existing profiles there
  682. if ($global_directory != Config::get('system', 'directory') AND ($global_directory != '')) {
  683. Config::set('system', 'directory', $global_directory);
  684. proc_run(PRIORITY_LOW, 'include/directory.php');
  685. }
  686. if ($a->get_path() != "") {
  687. $diaspora_enabled = false;
  688. }
  689. if (!$thread_allow) {
  690. $ostatus_disabled = true;
  691. }
  692. if ($ssl_policy != intval(get_config('system','ssl_policy'))) {
  693. if ($ssl_policy == SSL_POLICY_FULL) {
  694. q("UPDATE `contact` SET
  695. `url` = REPLACE(`url` , 'http:' , 'https:'),
  696. `photo` = REPLACE(`photo` , 'http:' , 'https:'),
  697. `thumb` = REPLACE(`thumb` , 'http:' , 'https:'),
  698. `micro` = REPLACE(`micro` , 'http:' , 'https:'),
  699. `request` = REPLACE(`request`, 'http:' , 'https:'),
  700. `notify` = REPLACE(`notify` , 'http:' , 'https:'),
  701. `poll` = REPLACE(`poll` , 'http:' , 'https:'),
  702. `confirm` = REPLACE(`confirm`, 'http:' , 'https:'),
  703. `poco` = REPLACE(`poco` , 'http:' , 'https:')
  704. WHERE `self` = 1"
  705. );
  706. q("UPDATE `profile` SET
  707. `photo` = REPLACE(`photo` , 'http:' , 'https:'),
  708. `thumb` = REPLACE(`thumb` , 'http:' , 'https:')
  709. WHERE 1 "
  710. );
  711. } elseif ($ssl_policy == SSL_POLICY_SELFSIGN) {
  712. q("UPDATE `contact` SET
  713. `url` = REPLACE(`url` , 'https:' , 'http:'),
  714. `photo` = REPLACE(`photo` , 'https:' , 'http:'),
  715. `thumb` = REPLACE(`thumb` , 'https:' , 'http:'),
  716. `micro` = REPLACE(`micro` , 'https:' , 'http:'),
  717. `request` = REPLACE(`request`, 'https:' , 'http:'),
  718. `notify` = REPLACE(`notify` , 'https:' , 'http:'),
  719. `poll` = REPLACE(`poll` , 'https:' , 'http:'),
  720. `confirm` = REPLACE(`confirm`, 'https:' , 'http:'),
  721. `poco` = REPLACE(`poco` , 'https:' , 'http:')
  722. WHERE `self` = 1"
  723. );
  724. q("UPDATE `profile` SET
  725. `photo` = REPLACE(`photo` , 'https:' , 'http:'),
  726. `thumb` = REPLACE(`thumb` , 'https:' , 'http:')
  727. WHERE 1 "
  728. );
  729. }
  730. }
  731. set_config('system','ssl_policy',$ssl_policy);
  732. set_config('system','maxloadavg',$maxloadavg);
  733. set_config('system','maxloadavg_frontend',$maxloadavg_frontend);
  734. set_config('system','optimize_max_tablesize',$optimize_max_tablesize);
  735. set_config('system','optimize_fragmentation',$optimize_fragmentation);
  736. set_config('system','poco_completion',$poco_completion);
  737. set_config('system','poco_requery_days',$poco_requery_days);
  738. set_config('system','poco_discovery',$poco_discovery);
  739. set_config('system','poco_discovery_since',$poco_discovery_since);
  740. set_config('system','poco_local_search',$poco_local_search);
  741. set_config('system','nodeinfo',$nodeinfo);
  742. set_config('config','sitename',$sitename);
  743. set_config('config','hostname',$hostname);
  744. set_config('config','sender_email', $sender_email);
  745. set_config('system','suppress_tags',$suppress_tags);
  746. set_config('system','shortcut_icon',$shortcut_icon);
  747. set_config('system','touch_icon',$touch_icon);
  748. if ($banner == "") {
  749. // don't know why, but del_config doesn't work...
  750. q("DELETE FROM `config` WHERE `cat` = '%s' AND `k` = '%s' LIMIT 1",
  751. dbesc("system"),
  752. dbesc("banner")
  753. );
  754. } else {
  755. set_config('system','banner', $banner);
  756. }
  757. if ($info == "") {
  758. del_config('config','info');
  759. } else {
  760. set_config('config','info',$info);
  761. }
  762. set_config('system','language', $language);
  763. set_config('system','theme', $theme);
  764. if ($theme_mobile === '---') {
  765. del_config('system','mobile-theme');
  766. } else {
  767. set_config('system','mobile-theme', $theme_mobile);
  768. }
  769. if ($singleuser === '---') {
  770. del_config('system','singleuser');
  771. } else {
  772. set_config('system','singleuser', $singleuser);
  773. }
  774. set_config('system', 'maximagesize', $maximagesize);
  775. set_config('system', 'max_image_length', $maximagelength);
  776. set_config('system', 'jpeg_quality', $jpegimagequality);
  777. set_config('config', 'register_policy', $register_policy);
  778. set_config('system', 'max_daily_registrations', $daily_registrations);
  779. set_config('system', 'account_abandon_days', $abandon_days);
  780. set_config('config', 'register_text', $register_text);
  781. set_config('system', 'allowed_sites', $allowed_sites);
  782. set_config('system', 'allowed_email', $allowed_email);
  783. set_config('system', 'block_public', $block_public);
  784. set_config('system', 'publish_all', $force_publish);
  785. set_config('system', 'thread_allow', $thread_allow);
  786. set_config('system', 'newuser_private', $newuser_private);
  787. set_config('system', 'enotify_no_content', $enotify_no_content);
  788. set_config('system', 'disable_embedded', $disable_embedded);
  789. set_config('system', 'allow_users_remote_self', $allow_users_remote_self);
  790. set_config('system', 'block_extended_register', $no_multi_reg);
  791. set_config('system', 'no_openid', $no_openid);
  792. set_config('system', 'no_regfullname', $no_regfullname);
  793. set_config('system', 'community_page_style', $community_page_style);
  794. set_config('system', 'max_author_posts_community_page', $max_author_posts_community_page);
  795. set_config('system', 'verifyssl', $verifyssl);
  796. set_config('system', 'proxyuser', $proxyuser);
  797. set_config('system', 'proxy', $proxy);
  798. set_config('system', 'curl_timeout', $timeout);
  799. set_config('system', 'dfrn_only', $dfrn_only);
  800. set_config('system', 'ostatus_disabled', $ostatus_disabled);
  801. set_config('system', 'ostatus_poll_interval', $ostatus_poll_interval);
  802. set_config('system', 'ostatus_full_threads', $ostatus_full_threads);
  803. set_config('system', 'diaspora_enabled', $diaspora_enabled);
  804. set_config('config', 'private_addons', $private_addons);
  805. set_config('system', 'force_ssl', $force_ssl);
  806. set_config('system', 'hide_help', $hide_help);
  807. set_config('system', 'itemcache', $itemcache);
  808. set_config('system', 'itemcache_duration', $itemcache_duration);
  809. set_config('system', 'max_comments', $max_comments);
  810. set_config('system', 'temppath', $temppath);
  811. set_config('system', 'basepath', $basepath);
  812. set_config('system', 'proxy_disabled', $proxy_disabled);
  813. set_config('system', 'only_tag_search', $only_tag_search);
  814. set_config('system', 'worker_queues', $worker_queues);
  815. set_config('system', 'worker_dont_fork', $worker_dont_fork);
  816. set_config('system', 'worker_fastlane', $worker_fastlane);
  817. set_config('system', 'frontend_worker', $worker_frontend);
  818. set_config('system', 'rino_encrypt', $rino);
  819. info(t('Site settings updated.').EOL);
  820. goaway('admin/site');
  821. return; // NOTREACHED
  822. }
  823. /**
  824. * @brief Generate Admin Site subpage
  825. *
  826. * This function generates the main configuration page of the admin panel.
  827. *
  828. * @param App $a
  829. * @return string
  830. */
  831. function admin_page_site(App $a) {
  832. /* Installed langs */
  833. $lang_choices = get_available_languages();
  834. if (strlen(get_config('system','directory_submit_url')) AND
  835. !strlen(get_config('system','directory'))) {
  836. set_config('system','directory', dirname(get_config('system','directory_submit_url')));
  837. del_config('system','directory_submit_url');
  838. }
  839. /* Installed themes */
  840. $theme_choices = array();
  841. $theme_choices_mobile = array();
  842. $theme_choices_mobile["---"] = t("No special theme for mobile devices");
  843. $files = glob('view/theme/*');
  844. if ($files) {
  845. $allowed_theme_list = Config::get('system', 'allowed_themes');
  846. foreach ($files as $file) {
  847. if (intval(file_exists($file.'/unsupported')))
  848. continue;
  849. $f = basename($file);
  850. // Only show allowed themes here
  851. if (($allowed_theme_list != '') AND !strstr($allowed_theme_list, $f)) {
  852. continue;
  853. }
  854. $theme_name = ((file_exists($file.'/experimental')) ? sprintf("%s - \x28Experimental\x29", $f) : $f);
  855. if (file_exists($file.'/mobile')) {
  856. $theme_choices_mobile[$f] = $theme_name;
  857. } else {
  858. $theme_choices[$f] = $theme_name;
  859. }
  860. }
  861. }
  862. /* Community page style */
  863. $community_page_style_choices = array(
  864. CP_NO_COMMUNITY_PAGE => t("No community page"),
  865. CP_USERS_ON_SERVER => t("Public postings from users of this site"),
  866. CP_GLOBAL_COMMUNITY => t("Global community page")
  867. );
  868. /* OStatus conversation poll choices */
  869. $ostatus_poll_choices = array(
  870. "-2" => t("Never"),
  871. "-1" => t("At post arrival"),
  872. "0" => t("Frequently"),
  873. "60" => t("Hourly"),
  874. "720" => t("Twice daily"),
  875. "1440" => t("Daily")
  876. );
  877. $poco_discovery_choices = array(
  878. "0" => t("Disabled"),
  879. "1" => t("Users"),
  880. "2" => t("Users, Global Contacts"),
  881. "3" => t("Users, Global Contacts/fallback"),
  882. );
  883. $poco_discovery_since_choices = array(
  884. "30" => t("One month"),
  885. "91" => t("Three months"),
  886. "182" => t("Half a year"),
  887. "365" => t("One year"),
  888. );
  889. /* get user names to make the install a personal install of X */
  890. $user_names = array();
  891. $user_names['---'] = t('Multi user instance');
  892. $users = q("SELECT `username`, `nickname` FROM `user`");
  893. foreach ($users as $user) {
  894. $user_names[$user['nickname']] = $user['username'];
  895. }
  896. /* Banner */
  897. $banner = get_config('system','banner');
  898. if ($banner == false) {
  899. $banner = '<a href="http://friendica.com"><img id="logo-img" src="images/friendica-32.png" alt="logo" /></a><span id="logo-text"><a href="http://friendica.com">Friendica</a></span>';
  900. }
  901. $banner = htmlspecialchars($banner);
  902. $info = get_config('config','info');
  903. $info = htmlspecialchars($info);
  904. // Automatically create temporary paths
  905. get_temppath();
  906. get_itemcachepath();
  907. //echo "<pre>"; var_dump($lang_choices); die("</pre>");
  908. /* Register policy */
  909. $register_choices = array(
  910. REGISTER_CLOSED => t("Closed"),
  911. REGISTER_APPROVE => t("Requires approval"),
  912. REGISTER_OPEN => t("Open")
  913. );
  914. $ssl_choices = array(
  915. SSL_POLICY_NONE => t("No SSL policy, links will track page SSL state"),
  916. SSL_POLICY_FULL => t("Force all links to use SSL"),
  917. SSL_POLICY_SELFSIGN => t("Self-signed certificate, use SSL for local links only (discouraged)")
  918. );
  919. if ($a->config['hostname'] == "") {
  920. $a->config['hostname'] = $a->get_hostname();
  921. }
  922. $diaspora_able = ($a->get_path() == "");
  923. $optimize_max_tablesize = Config::get('system','optimize_max_tablesize', 100);
  924. if ($optimize_max_tablesize < -1) {
  925. $optimize_max_tablesize = -1;
  926. }
  927. if ($optimize_max_tablesize == 0) {
  928. $optimize_max_tablesize = 100;
  929. }
  930. $t = get_markup_template("admin_site.tpl");
  931. return replace_macros($t, array(
  932. '$title' => t('Administration'),
  933. '$page' => t('Site'),
  934. '$submit' => t('Save Settings'),
  935. '$registration' => t('Registration'),
  936. '$upload' => t('File upload'),
  937. '$corporate' => t('Policies'),
  938. '$advanced' => t('Advanced'),
  939. '$portable_contacts' => t('Auto Discovered Contact Directory'),
  940. '$performance' => t('Performance'),
  941. '$worker_title' => t('Worker'),
  942. '$relocate'=> t('Relocate - WARNING: advanced function. Could make this server unreachable.'),
  943. '$baseurl' => App::get_baseurl(true),
  944. // name, label, value, help string, extra data...
  945. '$sitename' => array('sitename', t("Site name"), $a->config['sitename'],''),
  946. '$hostname' => array('hostname', t("Host name"), $a->config['hostname'], ""),
  947. '$sender_email' => array('sender_email', t("Sender Email"), $a->config['sender_email'], t("The email address your server shall use to send notification emails from."), "", "", "email"),
  948. '$banner' => array('banner', t("Banner/Logo"), $banner, ""),
  949. '$shortcut_icon' => array('shortcut_icon', t("Shortcut icon"), get_config('system','shortcut_icon'), t("Link to an icon that will be used for browsers.")),
  950. '$touch_icon' => array('touch_icon', t("Touch icon"), get_config('system','touch_icon'), t("Link to an icon that will be used for tablets and mobiles.")),
  951. '$info' => array('info', t('Additional Info'), $info, sprintf(t('For public servers: you can add additional information here that will be listed at %s/siteinfo.'), get_server())),
  952. '$language' => array('language', t("System language"), get_config('system','language'), "", $lang_choices),
  953. '$theme' => array('theme', t("System theme"), get_config('system','theme'), t("Default system theme - may be over-ridden by user profiles - <a href='#' id='cnftheme'>change theme settings</a>"), $theme_choices),
  954. '$theme_mobile' => array('theme_mobile', t("Mobile system theme"), get_config('system','mobile-theme'), t("Theme for mobile devices"), $theme_choices_mobile),
  955. '$ssl_policy' => array('ssl_policy', t("SSL link policy"), (string) intval(get_config('system','ssl_policy')), t("Determines whether generated links should be forced to use SSL"), $ssl_choices),
  956. '$force_ssl' => array('force_ssl', t("Force SSL"), get_config('system','force_ssl'), t("Force all Non-SSL requests to SSL - Attention: on some systems it could lead to endless loops.")),
  957. '$hide_help' => array('hide_help', t("Hide help entry from navigation menu"), get_config('system','hide_help'), t("Hides the menu entry for the Help pages from the navigation menu. You can still access it calling /help directly.")),
  958. '$singleuser' => array('singleuser', t("Single user instance"), get_config('system','singleuser'), t("Make this instance multi-user or single-user for the named user"), $user_names),
  959. '$maximagesize' => array('maximagesize', t("Maximum image size"), get_config('system','maximagesize'), t("Maximum size in bytes of uploaded images. Default is 0, which means no limits.")),
  960. '$maximagelength' => array('maximagelength', t("Maximum image length"), get_config('system','max_image_length'), t("Maximum length in pixels of the longest side of uploaded images. Default is -1, which means no limits.")),
  961. '$jpegimagequality' => array('jpegimagequality', t("JPEG image quality"), get_config('system','jpeg_quality'), t("Uploaded JPEGS will be saved at this quality setting [0-100]. Default is 100, which is full quality.")),
  962. '$register_policy' => array('register_policy', t("Register policy"), $a->config['register_policy'], "", $register_choices),
  963. '$daily_registrations' => array('max_daily_registrations', t("Maximum Daily Registrations"), get_config('system', 'max_daily_registrations'), t("If registration is permitted above, this sets the maximum number of new user registrations to accept per day. If register is set to closed, this setting has no effect.")),
  964. '$register_text' => array('register_text', t("Register text"), $a->config['register_text'], t("Will be displayed prominently on the registration page.")),
  965. '$abandon_days' => array('abandon_days', t('Accounts abandoned after x days'), get_config('system','account_abandon_days'), t('Will not waste system resources polling external sites for abandonded accounts. Enter 0 for no time limit.')),
  966. '$allowed_sites' => array('allowed_sites', t("Allowed friend domains"), get_config('system','allowed_sites'), t("Comma separated list of domains which are allowed to establish friendships with this site. Wildcards are accepted. Empty to allow any domains")),
  967. '$allowed_email' => array('allowed_email', t("Allowed email domains"), get_config('system','allowed_email'), t("Comma separated list of domains which are allowed in email addresses for registrations to this site. Wildcards are accepted. Empty to allow any domains")),
  968. '$block_public' => array('block_public', t("Block public"), get_config('system','block_public'), t("Check to block public access to all otherwise public personal pages on this site unless you are currently logged in.")),
  969. '$force_publish' => array('publish_all', t("Force publish"), get_config('system','publish_all'), t("Check to force all profiles on this site to be listed in the site directory.")),
  970. '$global_directory' => array('directory', t("Global directory URL"), get_config('system','directory'), t("URL to the global directory. If this is not set, the global directory is completely unavailable to the application.")),
  971. '$thread_allow' => array('thread_allow', t("Allow threaded items"), get_config('system','thread_allow'), t("Allow infinite level threading for items on this site.")),
  972. '$newuser_private' => array('newuser_private', t("Private posts by default for new users"), get_config('system','newuser_private'), t("Set default post permissions for all new members to the default privacy group rather than public.")),
  973. '$enotify_no_content' => array('enotify_no_content', t("Don't include post content in email notifications"), get_config('system','enotify_no_content'), t("Don't include the content of a post/comment/private message/etc. in the email notifications that are sent out from this site, as a privacy measure.")),
  974. '$private_addons' => array('private_addons', t("Disallow public access to addons listed in the apps menu."), get_config('config','private_addons'), t("Checking this box will restrict addons listed in the apps menu to members only.")),
  975. '$disable_embedded' => array('disable_embedded', t("Don't embed private images in posts"), get_config('system','disable_embedded'), t("Don't replace locally-hosted private photos in posts with an embedded copy of the image. This means that contacts who receive posts containing private photos will have to authenticate and load each image, which may take a while.")),
  976. '$allow_users_remote_self' => array('allow_users_remote_self', t('Allow Users to set remote_self'), get_config('system','allow_users_remote_self'), t('With checking this, every user is allowed to mark every contact as a remote_self in the repair contact dialog. Setting this flag on a contact causes mirroring every posting of that contact in the users stream.')),
  977. '$no_multi_reg' => array('no_multi_reg', t("Block multiple registrations"), get_config('system','block_extended_register'), t("Disallow users to register additional accounts for use as pages.")),
  978. '$no_openid' => array('no_openid', t("OpenID support"), !get_config('system','no_openid'), t("OpenID support for registration and logins.")),
  979. '$no_regfullname' => array('no_regfullname', t("Fullname check"), !get_config('system','no_regfullname'), t("Force users to register with a space between firstname and lastname in Full name, as an antispam measure")),
  980. '$community_page_style' => array('community_page_style', t("Community Page Style"), get_config('system','community_page_style'), t("Type of community page to show. 'Global community' shows every public posting from an open distributed network that arrived on this server."), $community_page_style_choices),
  981. '$max_author_posts_community_page' => array('max_author_posts_community_page', t("Posts per user on community page"), get_config('system','max_author_posts_community_page'), t("The maximum number of posts per user on the community page. (Not valid for 'Global Community')")),
  982. '$ostatus_disabled' => array('ostatus_disabled', t("Enable OStatus support"), !get_config('system','ostatus_disabled'), t("Provide built-in OStatus \x28StatusNet, GNU Social etc.\x29 compatibility. All communications in OStatus are public, so privacy warnings will be occasionally displayed.")),
  983. '$ostatus_poll_interval' => array('ostatus_poll_interval', t("OStatus conversation completion interval"), (string) intval(get_config('system','ostatus_poll_interval')), t("How often shall the poller check for new entries in OStatus conversations? This can be a very ressource task."), $ostatus_poll_choices),
  984. '$ostatus_full_threads' => array('ostatus_full_threads', t("Only import OStatus threads from our contacts"), get_config('system','ostatus_full_threads'), t("Normally we import every content from our OStatus contacts. With this option we only store threads that are started by a contact that is known on our system.")),
  985. '$ostatus_not_able' => t("OStatus support can only be enabled if threading is enabled."),
  986. '$diaspora_able' => $diaspora_able,
  987. '$diaspora_not_able' => t("Diaspora support can't be enabled because Friendica was installed into a sub directory."),
  988. '$diaspora_enabled' => array('diaspora_enabled', t("Enable Diaspora support"), get_config('system','diaspora_enabled'), t("Provide built-in Diaspora network compatibility.")),
  989. '$dfrn_only' => array('dfrn_only', t('Only allow Friendica contacts'), get_config('system','dfrn_only'), t("All contacts must use Friendica protocols. All other built-in communication protocols disabled.")),
  990. '$verifyssl' => array('verifyssl', t("Verify SSL"), get_config('system','verifyssl'), t("If you wish, you can turn on strict certificate checking. This will mean you cannot connect (at all) to self-signed SSL sites.")),
  991. '$proxyuser' => array('proxyuser', t("Proxy user"), get_config('system','proxyuser'), ""),
  992. '$proxy' => array('proxy', t("Proxy URL"), get_config('system','proxy'), ""),
  993. '$timeout' => array('timeout', t("Network timeout"), (x(get_config('system','curl_timeout'))?get_config('system','curl_timeout'):60), t("Value is in seconds. Set to 0 for unlimited (not recommended).")),
  994. '$maxloadavg' => array('maxloadavg', t("Maximum Load Average"), ((intval(get_config('system','maxloadavg')) > 0)?get_config('system','maxloadavg'):50), t("Maximum system load before delivery and poll processes are deferred - default 50.")),
  995. '$maxloadavg_frontend' => array('maxloadavg_frontend', t("Maximum Load Average (Frontend)"), ((intval(get_config('system','maxloadavg_frontend')) > 0)?get_config('system','maxloadavg_frontend'):50), t("Maximum system load before the frontend quits service - default 50.")),
  996. '$optimize_max_tablesize'=> array('optimize_max_tablesize', t("Maximum table size for optimization"), $optimize_max_tablesize, t("Maximum table size (in MB) for the automatic optimization - default 100 MB. Enter -1 to disable it.")),
  997. '$optimize_fragmentation'=> array('optimize_fragmentation', t("Minimum level of fragmentation"), ((intval(get_config('system','optimize_fragmentation')) > 0)?get_config('system','optimize_fragmentation'):30), t("Minimum fragmenation level to start the automatic optimization - default value is 30%.")),
  998. '$poco_completion' => array('poco_completion', t("Periodical check of global contacts"), get_config('system','poco_completion'), t("If enabled, the global contacts are checked periodically for missing or outdated data and the vitality of the contacts and servers.")),
  999. '$poco_requery_days' => array('poco_requery_days', t("Days between requery"), get_config('system','poco_requery_days'), t("Number of days after which a server is requeried for his contacts.")),
  1000. '$poco_discovery' => array('poco_discovery', t("Discover contacts from other servers"), (string) intval(get_config('system','poco_discovery')), t("Periodically query other servers for contacts. You can choose between 'users': the users on the remote system, 'Global Contacts': active contacts that are known on the system. The fallback is meant for Redmatrix servers and older friendica servers, where global contacts weren't available. The fallback increases the server load, so the recommened setting is 'Users, Global Contacts'."), $poco_discovery_choices),
  1001. '$poco_discovery_since' => array('poco_discovery_since', t("Timeframe for fetching global contacts"), (string) intval(get_config('system','poco_discovery_since')), t("When the discovery is activated, this value defines the timeframe for the activity of the global contacts that are fetched from other servers."), $poco_discovery_since_choices),
  1002. '$poco_local_search' => array('poco_local_search', t("Search the local directory"), get_config('system','poco_local_search'), t("Search the local directory instead of the global directory. When searching locally, every search will be executed on the global directory in the background. This improves the search results when the search is repeated.")),
  1003. '$nodeinfo' => array('nodeinfo', t("Publish server information"), get_config('system','nodeinfo'), t("If enabled, general server and usage data will be published. The data contains the name and version of the server, number of users with public profiles, number of posts and the activated protocols and connectors. See <a href='http://the-federation.info/'>the-federation.info</a> for details.")),
  1004. '$suppress_tags' => array('suppress_tags', t("Suppress Tags"), get_config('system','suppress_tags'), t("Suppress showing a list of hashtags at the end of the posting.")),
  1005. '$itemcache' => array('itemcache', t("Path to item cache"), get_config('system','itemcache'), t("The item caches buffers generated bbcode and external images.")),
  1006. '$itemcache_duration' => array('itemcache_duration', t("Cache duration in seconds"), get_config('system','itemcache_duration'), t("How long should the cache files be hold? Default value is 86400 seconds (One day). To disable the item cache, set the value to -1.")),
  1007. '$max_comments' => array('max_comments', t("Maximum numbers of comments per post"), get_config('system','max_comments'), t("How much comments should be shown for each post? Default value is 100.")),
  1008. '$temppath' => array('temppath', t("Temp path"), get_config('system','temppath'), t("If you have a restricted system where the webserver can't access the system temp path, enter another path here.")),
  1009. '$basepath' => array('basepath', t("Base path to installation"), get_config('system','basepath'), t("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.")),
  1010. '$proxy_disabled' => array('proxy_disabled', t("Disable picture proxy"), get_config('system','proxy_disabled'), t("The picture proxy increases performance and privacy. It shouldn't be used on systems with very low bandwith.")),
  1011. '$only_tag_search' => array('only_tag_search', t("Only search in tags"), get_config('system','only_tag_search'), t("On large systems the text search can slow down the system extremely.")),
  1012. '$relocate_url' => array('relocate_url', t("New base url"), App::get_baseurl(), t("Change base url for this server. Sends relocate message to all DFRN contacts of all users.")),
  1013. '$rino' => array('rino', t("RINO Encryption"), intval(get_config('system','rino_encrypt')), t("Encryption layer between nodes."), array("Disabled", "RINO1 (deprecated)", "RINO2")),
  1014. '$worker_queues' => array('worker_queues', t("Maximum number of parallel workers"), get_config('system','worker_queues'), t("On shared hosters set this to 2. On larger systems, values of 10 are great. Default value is 4.")),
  1015. '$worker_dont_fork' => array('worker_dont_fork', t("Don't use 'proc_open' with the worker"), get_config('system','worker_dont_fork'), t("Enable this if your system doesn't allow the use of 'proc_open'. This can happen on shared hosters. If this is enabled you should increase the frequency of poller calls in your crontab.")),
  1016. '$worker_fastlane' => array('worker_fastlane', t("Enable fastlane"), get_config('system','worker_fastlane'), t("When enabed, the fastlane mechanism starts an additional worker if processes with higher priority are blocked by processes of lower priority.")),
  1017. '$worker_frontend' => array('worker_frontend', t('Enable frontend worker'), get_config('system','frontend_worker'), 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 yourdomain.tld/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. The worker background process needs to be activated for this.')),
  1018. '$form_security_token' => get_form_security_token("admin_site")
  1019. ));
  1020. }
  1021. /**
  1022. * @brief Generates admin panel subpage for DB syncronization
  1023. *
  1024. * This page checks if the database of friendica is in sync with the specs.
  1025. * Should this not be the case, it attemps to sync the structure and notifies
  1026. * the admin if the automatic process was failing.
  1027. *
  1028. * The returned string holds the HTML code of the page.
  1029. *
  1030. * @param App $a
  1031. * @return string
  1032. **/
  1033. function admin_page_dbsync(App $a) {
  1034. $o = '';
  1035. if ($a->argc > 3 && intval($a->argv[3]) && $a->argv[2] === 'mark') {
  1036. set_config('database', 'update_'.intval($a->argv[3]), 'success');
  1037. $curr = get_config('system','build');
  1038. if (intval($curr) == intval($a->argv[3])) {
  1039. set_config('system','build',intval($curr) + 1);
  1040. }
  1041. info(t('Update has been marked successful').EOL);
  1042. goaway('admin/dbsync');
  1043. }
  1044. if (($a->argc > 2) AND (intval($a->argv[2]) OR ($a->argv[2] === 'check'))) {
  1045. require_once("include/dbstructure.php");
  1046. $retval = update_structure(false, true);
  1047. if (!$retval) {
  1048. $o .= sprintf(t("Database structure update %s was successfully applied."), DB_UPDATE_VERSION)."<br />";
  1049. set_config('database', 'dbupdate_'.DB_UPDATE_VERSION, 'success');
  1050. } else {
  1051. $o .= sprintf(t("Executing of database structure update %s failed with error: %s"),
  1052. DB_UPDATE_VERSION, $retval)."<br />";
  1053. }
  1054. if ($a->argv[2] === 'check') {
  1055. return $o;
  1056. }
  1057. }
  1058. if ($a->argc > 2 && intval($a->argv[2])) {
  1059. require_once('update.php');
  1060. $func = 'update_'.intval($a->argv[2]);
  1061. if (function_exists($func)) {
  1062. $retval = $func();
  1063. if ($retval === UPDATE_FAILED) {
  1064. $o .= sprintf(t("Executing %s failed with error: %s"), $func, $retval);
  1065. }
  1066. elseif ($retval === UPDATE_SUCCESS) {
  1067. $o .= sprintf(t('Update %s was successfully applied.', $func));
  1068. set_config('database',$func, 'success');
  1069. } else {
  1070. $o .= sprintf(t('Update %s did not return a status. Unknown if it succeeded.'), $func);
  1071. }
  1072. } else {
  1073. $o .= sprintf(t('There was no additional update function %s that needed to be called.'), $func)."<br />";
  1074. set_config('database',$func, 'success');
  1075. }
  1076. return $o;
  1077. }
  1078. $failed = array();
  1079. $r = q("SELECT `k`, `v` FROM `config` WHERE `cat` = 'database' ");
  1080. if (dbm::is_result($r)) {
  1081. foreach ($r as $rr) {
  1082. $upd = intval(substr($rr['k'],7));
  1083. if ($upd < 1139 || $rr['v'] === 'success') {
  1084. continue;
  1085. }
  1086. $failed[] = $upd;
  1087. }
  1088. }
  1089. if (! count($failed)) {
  1090. $o = replace_macros(get_markup_template('structure_check.tpl'),array(
  1091. '$base' => App::get_baseurl(true),
  1092. '$banner' => t('No failed updates.'),
  1093. '$check' => t('Check database structure'),
  1094. ));
  1095. } else {
  1096. $o = replace_macros(get_markup_template('failed_updates.tpl'),array(
  1097. '$base' => App::get_baseurl(true),
  1098. '$banner' => t('Failed Updates'),
  1099. '$desc' => t('This does not include updates prior to 1139, which did not return a status.'),
  1100. '$mark' => t('Mark success (if update was manually applied)'),
  1101. '$apply' => t('Attempt to execute this update step automatically'),
  1102. '$failed' => $failed
  1103. ));
  1104. }
  1105. return $o;
  1106. }
  1107. /**
  1108. * @brief Process data send by Users admin page
  1109. *
  1110. * @param App $a
  1111. */
  1112. function admin_page_users_post(App $a) {
  1113. $pending = (x($_POST, 'pending') ? $_POST['pending'] : array());
  1114. $users = (x($_POST, 'user') ? $_POST['user'] : array());
  1115. $nu_name = (x($_POST, 'new_user_name') ? $_POST['new_user_name'] : '');
  1116. $nu_nickname = (x($_POST, 'new_user_nickname') ? $_POST['new_user_nickname'] : '');
  1117. $nu_email = (x($_POST, 'new_user_email') ? $_POST['new_user_email'] : '');
  1118. $nu_language = get_config('system', 'language');
  1119. check_form_security_token_redirectOnErr('/admin/users', 'admin_users');
  1120. if (!($nu_name === "") && !($nu_email === "") && !($nu_nickname === "")) {
  1121. require_once('include/user.php');
  1122. $result = create_user(array('username'=>$nu_name, 'email'=>$nu_email,
  1123. 'nickname'=>$nu_nickname, 'verified'=>1, 'language'=>$nu_language));
  1124. if (! $result['success']) {
  1125. notice($result['message']);
  1126. return;
  1127. }
  1128. $nu = $result['user'];
  1129. $preamble = deindent(t('
  1130. Dear %1$s,
  1131. the administrator of %2$s has set up an account for you.'));
  1132. $body = deindent(t('
  1133. The login details are as follows:
  1134. Site Location: %1$s
  1135. Login Name: %2$s
  1136. Password: %3$s
  1137. You may change your password from your account "Settings" page after logging
  1138. in.
  1139. Please take a few moments to review the other account settings on that page.
  1140. You may also wish to add some basic information to your default profile
  1141. (on the "Profiles" page) so that other people can easily find you.
  1142. We recommend setting your full name, adding a profile photo,
  1143. adding some profile "keywords" (very useful in making new friends) - and
  1144. perhaps what country you live in; if you do not wish to be more specific
  1145. than that.
  1146. We fully respect your right to privacy, and none of these items are necessary.
  1147. If you are new and do not know anybody here, they may help
  1148. you to make some new and interesting friends.
  1149. Thank you and welcome to %4$s.'));
  1150. $preamble = sprintf($preamble, $nu['username'], $a->config['sitename']);
  1151. $body = sprintf($body, App::get_baseurl(), $nu['email'], $result['password'], $a->config['sitename']);
  1152. notification(array(
  1153. 'type' => "SYSTEM_EMAIL",
  1154. 'to_email' => $nu['email'],
  1155. 'subject'=> sprintf(t('Registration details for %s'), $a->config['sitename']),
  1156. 'preamble'=> $preamble,
  1157. 'body' => $body));
  1158. }
  1159. if (x($_POST,'page_users_block')) {
  1160. foreach ($users as $uid) {
  1161. q("UPDATE `user` SET `blocked` = 1-`blocked` WHERE `uid` = %s",
  1162. intval($uid)
  1163. );
  1164. }
  1165. notice(sprintf(tt("%s user blocked/unblocked", "%s users blocked/unblocked", count($users)), count($users)));
  1166. }
  1167. if (x($_POST,'page_users_delete')) {
  1168. require_once("include/Contact.php");
  1169. foreach ($users as $uid) {
  1170. user_remove($uid);
  1171. }
  1172. notice(sprintf(tt("%s user deleted", "%s users deleted", count($users)), count($users)));
  1173. }
  1174. if (x($_POST,'page_users_approve')) {
  1175. require_once("mod/regmod.php");
  1176. foreach ($pending as $hash) {
  1177. user_allow($hash);
  1178. }
  1179. }
  1180. if (x($_POST,'page_users_deny')) {
  1181. require_once("mod/regmod.php");
  1182. foreach ($pending as $hash) {
  1183. user_deny($hash);
  1184. }
  1185. }
  1186. goaway('admin/users');
  1187. return; // NOTREACHED
  1188. }
  1189. /**
  1190. * @brief Admin panel subpage for User management
  1191. *
  1192. * This function generates the admin panel page for user management of the
  1193. * node. It offers functionality to add/block/delete users and offers some
  1194. * statistics about the userbase.
  1195. *
  1196. * The returned string holds the HTML code of the page.
  1197. *
  1198. * @param App $a
  1199. * @return string
  1200. */
  1201. function admin_page_users(App $a) {
  1202. if ($a->argc>2) {
  1203. $uid = $a->argv[3];
  1204. $user = q("SELECT `username`, `blocked` FROM `user` WHERE `uid` = %d", intval($uid));
  1205. if (count($user) == 0) {
  1206. notice('User not found'.EOL);
  1207. goaway('admin/users');
  1208. return ''; // NOTREACHED
  1209. }
  1210. switch($a->argv[2]) {
  1211. case "delete":
  1212. check_form_security_token_redirectOnErr('/admin/users', 'admin_users', 't');
  1213. // delete user
  1214. require_once("include/Contact.php");
  1215. user_remove($uid);
  1216. notice(sprintf(t("User '%s' deleted"), $user[0]['username']).EOL);
  1217. break;
  1218. case "block":
  1219. check_form_security_token_redirectOnErr('/admin/users', 'admin_users', 't');
  1220. q("UPDATE `user` SET `blocked` = %d WHERE `uid` = %s",
  1221. intval(1-$user[0]['blocked']),
  1222. intval($uid)
  1223. );
  1224. notice(sprintf(($user[0]['blocked']?t("User '%s' unblocked"):t("User '%s' blocked")) , $user[0]['username']).EOL);
  1225. break;
  1226. }
  1227. goaway('admin/users');
  1228. return ''; // NOTREACHED
  1229. }
  1230. /* get pending */
  1231. $pending = q("SELECT `register`.*, `contact`.`name`, `user`.`email`
  1232. FROM `register`
  1233. LEFT JOIN `contact` ON `register`.`uid` = `contact`.`uid`
  1234. LEFT JOIN `user` ON `register`.`uid` = `user`.`uid`;");
  1235. /* get users */
  1236. $total = qu("SELECT COUNT(*) AS `total` FROM `user` WHERE 1");
  1237. if (count($total)) {
  1238. $a->set_pager_total($total[0]['total']);
  1239. $a->set_pager_itemspage(100);
  1240. }
  1241. /* ordering */
  1242. $valid_orders = array(
  1243. 'contact.name',
  1244. 'user.email',
  1245. 'user.register_date',
  1246. 'user.login_date',
  1247. 'lastitem_date',
  1248. 'user.page-flags'
  1249. );
  1250. $order = "contact.name";
  1251. $order_direction = "+";
  1252. if (x($_GET,'o')) {
  1253. $new_order = $_GET['o'];
  1254. if ($new_order[0] === "-") {
  1255. $order_direction = "-";
  1256. $new_order = substr($new_order,1);
  1257. }
  1258. if (in_array($new_order, $valid_orders)) {
  1259. $order = $new_order;
  1260. }
  1261. if (x($_GET,'d')) {
  1262. $new_direction = $_GET['d'];
  1263. }
  1264. }
  1265. $sql_order = "`".str_replace('.','`.`',$order)."`";
  1266. $sql_order_direction = ($order_direction === "+")?"ASC":"DESC";
  1267. $users = qu("SELECT `user`.*, `contact`.`name`, `contact`.`url`, `contact`.`micro`, `user`.`account_expired`, `contact`.`last-item` AS `lastitem_date`
  1268. FROM `user`
  1269. INNER JOIN `contact` ON `contact`.`uid` = `user`.`uid` AND `contact`.`self`
  1270. WHERE `user`.`verified`
  1271. ORDER BY $sql_order $sql_order_direction LIMIT %d, %d",
  1272. intval($a->pager['start']),
  1273. intval($a->pager['itemspage'])
  1274. );
  1275. //echo "<pre>$users"; killme();
  1276. $adminlist = explode(",", str_replace(" ", "", $a->config['admin_email']));
  1277. $_setup_users = function ($e) use ($adminlist) {
  1278. $accounts = array(
  1279. t('Normal Account'),
  1280. t('Soapbox Account'),
  1281. t('Community/Celebrity Account'),
  1282. t('Automatic Friend Account')
  1283. );
  1284. $e['page-flags'] = $accounts[$e['page-flags']];
  1285. $e['register_date'] = relative_date($e['register_date']);
  1286. $e['login_date'] = relative_date($e['login_date']);
  1287. $e['lastitem_date'] = relative_date($e['lastitem_date']);
  1288. //$e['is_admin'] = ($e['email'] === $a->config['admin_email']);
  1289. $e['is_admin'] = in_array($e['email'], $adminlist);
  1290. $e['is_deletable'] = (intval($e['uid']) != local_user());
  1291. $e['deleted'] = ($e['account_removed']?relative_date($e['account_expires_on']):False);
  1292. return $e;
  1293. };
  1294. $users = array_map($_setup_users, $users);
  1295. // Get rid of dashes in key names, Smarty3 can't handle them
  1296. // and extracting deleted users
  1297. $tmp_users = array();
  1298. $deleted = array();
  1299. while (count($users)) {
  1300. $new_user = array();
  1301. foreach (array_pop($users) as $k => $v) {
  1302. $k = str_replace('-','_',$k);
  1303. $new_user[$k] = $v;
  1304. }
  1305. if ($new_user['deleted']) {
  1306. array_push($deleted, $new_user);
  1307. } else {
  1308. array_push($tmp_users, $new_user);
  1309. }
  1310. }
  1311. //Reversing the two array, and moving $tmp_users to $users
  1312. array_reverse($deleted);
  1313. while (count($tmp_users)) {
  1314. array_push($users, array_pop($tmp_users));
  1315. }
  1316. $th_users = array_map(null,
  1317. array(t('Name'), t('Email'), t('Register date'), t('Last login'), t('Last item'), t('Account')),
  1318. $valid_orders
  1319. );
  1320. $t = get_markup_template("admin_users.tpl");
  1321. $o = replace_macros($t, array(
  1322. // strings //
  1323. '$title' => t('Administration'),
  1324. '$page' => t('Users'),
  1325. '$submit' => t('Add User'),
  1326. '$select_all' => t('select all'),
  1327. '$h_pending' => t('User registrations waiting for confirm'),
  1328. '$h_deleted' => t('User waiting for permanent deletion'),
  1329. '$th_pending' => array(t('Request date'), t('Name'), t('Email')),
  1330. '$no_pending' => t('No registrations.'),
  1331. '$pendingnotetext' => t('Note from the user'),
  1332. '$approve' => t('Approve'),
  1333. '$deny' => t('Deny'),
  1334. '$delete' => t('Delete'),
  1335. '$block' => t('Block'),
  1336. '$unblock' => t('Unblock'),
  1337. '$siteadmin' => t('Site admin'),
  1338. '$accountexpired' => t('Account expired'),
  1339. '$h_users' => t('Users'),
  1340. '$h_newuser' => t('New User'),
  1341. '$th_deleted' => array(t('Name'), t('Email'), t('Register date'), t('Last login'), t('Last item'), t('Deleted since')),
  1342. '$th_users' => $th_users,
  1343. '$order_users' => $order,
  1344. '$order_direction_users' => $order_direction,
  1345. '$confirm_delete_multi' => t('Selected users will be deleted!\n\nEverything these users had posted on this site will be permanently deleted!\n\nAre you sure?'),
  1346. '$confirm_delete' => t('The user {0} will be deleted!\n\nEverything this user has posted on this site will be permanently deleted!\n\nAre you sure?'),
  1347. '$form_security_token' => get_form_security_token("admin_users"),
  1348. // values //
  1349. '$baseurl' => App::get_baseurl(true),
  1350. '$pending' => $pending,
  1351. 'deleted' => $deleted,
  1352. '$users' => $users,
  1353. '$newusername' => array('new_user_name', t("Name"), '', t("Name of the new user.")),
  1354. '$newusernickname' => array('new_user_nickname', t("Nickname"), '', t("Nickname of the new user.")),
  1355. '$newuseremail' => array('new_user_email', t("Email"), '', t("Email address of the new user."), '', '', 'email'),
  1356. ));
  1357. $o .= paginate($a);
  1358. return $o;
  1359. }
  1360. /**
  1361. * @brief Plugins admin page
  1362. *
  1363. * This function generates the admin panel page for managing plugins on the
  1364. * friendica node. If a plugin name is given a single page showing the details
  1365. * for this addon is generated. If no name is given, a list of available
  1366. * plugins is shown.
  1367. *
  1368. * The template used for displaying the list of plugins and the details of the
  1369. * plugin are the same as used for the templates.
  1370. *
  1371. * The returned string returned hulds the HTML code of the page.
  1372. *
  1373. * @param App $a
  1374. * @return string
  1375. */
  1376. function admin_page_plugins(App $a) {
  1377. /*
  1378. * Single plugin
  1379. */
  1380. if ($a->argc == 3) {
  1381. $plugin = $a->argv[2];
  1382. if (!is_file("addon/$plugin/$plugin.php")) {
  1383. notice(t("Item not found."));
  1384. return '';
  1385. }
  1386. if (x($_GET,"a") && $_GET['a']=="t") {
  1387. check_form_security_token_redirectOnErr('/admin/plugins', 'admin_themes', 't');
  1388. // Toggle plugin status
  1389. $idx = array_search($plugin, $a->plugins);
  1390. if ($idx !== false) {
  1391. unset($a->plugins[$idx]);
  1392. uninstall_plugin($plugin);
  1393. info(sprintf(t("Plugin %s disabled."), $plugin));
  1394. } else {
  1395. $a->plugins[] = $plugin;
  1396. install_plugin($plugin);
  1397. info(sprintf(t("Plugin %s enabled."), $plugin));
  1398. }
  1399. set_config("system","addon", implode(", ",$a->plugins));
  1400. goaway('admin/plugins');
  1401. return ''; // NOTREACHED
  1402. }
  1403. // display plugin details
  1404. require_once('library/markdown.php');
  1405. if (in_array($plugin, $a->plugins)) {
  1406. $status="on"; $action= t("Disable");
  1407. } else {
  1408. $status="off"; $action= t("Enable");
  1409. }
  1410. $readme=Null;
  1411. if (is_file("addon/$plugin/README.md")) {
  1412. $readme = file_get_contents("addon/$plugin/README.md");
  1413. $readme = Markdown($readme);
  1414. } elseif (is_file("addon/$plugin/README")) {
  1415. $readme = "<pre>". file_get_contents("addon/$plugin/README") ."</pre>";
  1416. }
  1417. $admin_form="";
  1418. if (is_array($a->plugins_admin) && in_array($plugin, $a->plugins_admin)) {
  1419. @require_once("addon/$plugin/$plugin.php");
  1420. $func = $plugin.'_plugin_admin';
  1421. $func($a, $admin_form);
  1422. }
  1423. $t = get_markup_template("admin_plugins_details.tpl");
  1424. return replace_macros($t, array(
  1425. '$title' => t('Administration'),
  1426. '$page' => t('Plugins'),
  1427. '$toggle' => t('Toggle'),
  1428. '$settings' => t('Settings'),
  1429. '$baseurl' => App::get_baseurl(true),
  1430. '$plugin' => $plugin,
  1431. '$status' => $status,
  1432. '$action' => $action,
  1433. '$info' => get_plugin_info($plugin),
  1434. '$str_author' => t('Author: '),
  1435. '$str_maintainer' => t('Maintainer: '),
  1436. '$admin_form' => $admin_form,
  1437. '$function' => 'plugins',
  1438. '$screenshot' => '',
  1439. '$readme' => $readme,
  1440. '$form_security_token' => get_form_security_token("admin_themes"),
  1441. ));
  1442. }
  1443. /*
  1444. * List plugins
  1445. */
  1446. if (x($_GET,"a") && $_GET['a']=="r") {
  1447. check_form_security_token_redirectOnErr(App::get_baseurl().'/admin/plugins', 'admin_themes', 't');
  1448. reload_plugins();
  1449. info("Plugins reloaded");
  1450. goaway(App::get_baseurl().'/admin/plugins');
  1451. }
  1452. $plugins = array();
  1453. $files = glob("addon/*/");
  1454. if ($files) {
  1455. foreach ($files as $file) {
  1456. if (is_dir($file)) {
  1457. list($tmp, $id)=array_map("trim", explode("/",$file));
  1458. $info = get_plugin_info($id);
  1459. $show_plugin = true;
  1460. // If the addon is unsupported, then only show it, when it is enabled
  1461. if ((strtolower($info["status"]) == "unsupported") AND !in_array($id, $a->plugins)) {
  1462. $show_plugin = false;
  1463. }
  1464. // Override the above szenario, when the admin really wants to see outdated stuff
  1465. if (get_config("system", "show_unsupported_addons")) {
  1466. $show_plugin = true;
  1467. }
  1468. if ($show_plugin) {
  1469. $plugins[] = array($id, (in_array($id, $a->plugins)?"on":"off") , $info);
  1470. }
  1471. }
  1472. }
  1473. }
  1474. $t = get_markup_template("admin_plugins.tpl");
  1475. return replace_macros($t, array(
  1476. '$title' => t('Administration'),
  1477. '$page' => t('Plugins'),
  1478. '$submit' => t('Save Settings'),
  1479. '$reload' => t('Reload active plugins'),
  1480. '$baseurl' => App::get_baseurl(true),
  1481. '$function' => 'plugins',
  1482. '$plugins' => $plugins,
  1483. '$pcount' => count($plugins),
  1484. '$noplugshint' => sprintf(t('There are currently no plugins available on your node. You can find the official plugin repository at %1$s and might find other interesting plugins in the open plugin registry at %2$s'), 'https://github.com/friendica/friendica-addons', 'http://addons.friendi.ca'),
  1485. '$form_security_token' => get_form_security_token("admin_themes"),
  1486. ));
  1487. }
  1488. /**
  1489. * @param array $themes
  1490. * @param string $th
  1491. * @param int $result
  1492. */
  1493. function toggle_theme(&$themes,$th,&$result) {
  1494. for($x = 0; $x < count($themes); $x ++) {
  1495. if ($themes[$x]['name'] === $th) {
  1496. if ($themes[$x]['allowed']) {
  1497. $themes[$x]['allowed'] = 0;
  1498. $result = 0;
  1499. }
  1500. else {
  1501. $themes[$x]['allowed'] = 1;
  1502. $result = 1;
  1503. }
  1504. }
  1505. }
  1506. }
  1507. /**
  1508. * @param array $themes
  1509. * @param string $th
  1510. * @return int
  1511. */
  1512. function theme_status($themes,$th) {
  1513. for($x = 0; $x < count($themes); $x ++) {
  1514. if ($themes[$x]['name'] === $th) {
  1515. if ($themes[$x]['allowed']) {
  1516. return 1;
  1517. }
  1518. else {
  1519. return 0;
  1520. }
  1521. }
  1522. }
  1523. return 0;
  1524. }
  1525. /**
  1526. * @param array $themes
  1527. * @return string
  1528. */
  1529. function rebuild_theme_table($themes) {
  1530. $o = '';
  1531. if (count($themes)) {
  1532. foreach ($themes as $th) {
  1533. if ($th['allowed']) {
  1534. if (strlen($o)) {
  1535. $o .= ',';
  1536. }
  1537. $o .= $th['name'];
  1538. }
  1539. }
  1540. }
  1541. return $o;
  1542. }
  1543. /**
  1544. * @brief Themes admin page
  1545. *
  1546. * This function generates the admin panel page to control the themes available
  1547. * on the friendica node. If the name of a theme is given as parameter a page
  1548. * with the details for the theme is shown. Otherwise a list of available
  1549. * themes is generated.
  1550. *
  1551. * The template used for displaying the list of themes and the details of the
  1552. * themes are the same as used for the plugins.
  1553. *
  1554. * The returned string contains the HTML code of the admin panel page.
  1555. *
  1556. * @param App $a
  1557. * @return string
  1558. */
  1559. function admin_page_themes(App $a) {
  1560. $allowed_themes_str = get_config('system','allowed_themes');
  1561. $allowed_themes_raw = explode(',',$allowed_themes_str);
  1562. $allowed_themes = array();
  1563. if (count($allowed_themes_raw)) {
  1564. foreach ($allowed_themes_raw as $x) {
  1565. if (strlen(trim($x))) {
  1566. $allowed_themes[] = trim($x);
  1567. }
  1568. }
  1569. }
  1570. $themes = array();
  1571. $files = glob('view/theme/*');
  1572. if ($files) {
  1573. foreach ($files as $file) {
  1574. $f = basename($file);
  1575. // Is there a style file?
  1576. $theme_files = glob('view/theme/'.$f.'/style.*');
  1577. // If not then quit
  1578. if (count($theme_files) == 0) {
  1579. continue;
  1580. }
  1581. $is_experimental = intval(file_exists($file.'/experimental'));
  1582. $is_supported = 1-(intval(file_exists($file.'/unsupported')));
  1583. $is_allowed = intval(in_array($f,$allowed_themes));
  1584. if ($is_allowed OR $is_supported OR get_config("system", "show_unsupported_themes")) {
  1585. $themes[] = array('name' => $f, 'experimental' => $is_experimental, 'supported' => $is_supported, 'allowed' => $is_allowed);
  1586. }
  1587. }
  1588. }
  1589. if (! count($themes)) {
  1590. notice(t('No themes found.'));
  1591. return '';
  1592. }
  1593. /*
  1594. * Single theme
  1595. */
  1596. if ($a->argc == 3) {
  1597. $theme = $a->argv[2];
  1598. if (! is_dir("view/theme/$theme")) {
  1599. notice(t("Item not found."));
  1600. return '';
  1601. }
  1602. if (x($_GET,"a") && $_GET['a']=="t") {
  1603. check_form_security_token_redirectOnErr('/admin/themes', 'admin_themes', 't');
  1604. // Toggle theme status
  1605. toggle_theme($themes,$theme,$result);
  1606. $s = rebuild_theme_table($themes);
  1607. if ($result) {
  1608. install_theme($theme);
  1609. info(sprintf('Theme %s enabled.',$theme));
  1610. } else {
  1611. uninstall_theme($theme);
  1612. info(sprintf('Theme %s disabled.',$theme));
  1613. }
  1614. set_config('system','allowed_themes',$s);
  1615. goaway('admin/themes');
  1616. return ''; // NOTREACHED
  1617. }
  1618. // display theme details
  1619. require_once('library/markdown.php');
  1620. if (theme_status($themes,$theme)) {
  1621. $status="on"; $action= t("Disable");
  1622. } else {
  1623. $status="off"; $action= t("Enable");
  1624. }
  1625. $readme = Null;
  1626. if (is_file("view/theme/$theme/README.md")) {
  1627. $readme = file_get_contents("view/theme/$theme/README.md");
  1628. $readme = Markdown($readme);
  1629. } elseif (is_file("view/theme/$theme/README")) {
  1630. $readme = "<pre>". file_get_contents("view/theme/$theme/README") ."</pre>";
  1631. }
  1632. $admin_form = "";
  1633. if (is_file("view/theme/$theme/config.php")) {
  1634. function __get_theme_admin_form(App $a, $theme) {
  1635. $orig_theme = $a->theme;
  1636. $orig_page = $a->page;
  1637. $orig_session_theme = $_SESSION['theme'];
  1638. require_once("view/theme/$theme/theme.php");
  1639. require_once("view/theme/$theme/config.php");
  1640. $_SESSION['theme'] = $theme;
  1641. $init = $theme."_init";
  1642. if (function_exists($init)) {
  1643. $init($a);
  1644. }
  1645. if (function_exists("theme_admin")) {
  1646. $admin_form = theme_admin($a);
  1647. }
  1648. $_SESSION['theme'] = $orig_session_theme;
  1649. $a->theme = $orig_theme;
  1650. $a->page = $orig_page;
  1651. return $admin_form;
  1652. }
  1653. $admin_form = __get_theme_admin_form($a, $theme);
  1654. }
  1655. $screenshot = array(get_theme_screenshot($theme), t('Screenshot'));
  1656. if (! stristr($screenshot[0],$theme)) {
  1657. $screenshot = null;
  1658. }
  1659. $t = get_markup_template("admin_plugins_details.tpl");
  1660. return replace_macros($t, array(
  1661. '$title' => t('Administration'),
  1662. '$page' => t('Themes'),
  1663. '$toggle' => t('Toggle'),
  1664. '$settings' => t('Settings'),
  1665. '$baseurl' => App::get_baseurl(true),
  1666. '$plugin' => $theme,
  1667. '$status' => $status,
  1668. '$action' => $action,
  1669. '$info' => get_theme_info($theme),
  1670. '$function' => 'themes',
  1671. '$admin_form' => $admin_form,
  1672. '$str_author' => t('Author: '),
  1673. '$str_maintainer' => t('Maintainer: '),
  1674. '$screenshot' => $screenshot,
  1675. '$readme' => $readme,
  1676. '$form_security_token' => get_form_security_token("admin_themes"),
  1677. ));
  1678. }
  1679. // reload active themes
  1680. if (x($_GET,"a") && $_GET['a']=="r") {
  1681. check_form_security_token_redirectOnErr(App::get_baseurl().'/admin/themes', 'admin_themes', 't');
  1682. if ($themes) {
  1683. foreach ($themes as $th) {
  1684. if ($th['allowed']) {
  1685. uninstall_theme($th['name']);
  1686. install_theme($th['name']);
  1687. }
  1688. }
  1689. }
  1690. info("Themes reloaded");
  1691. goaway(App::get_baseurl().'/admin/themes');
  1692. }
  1693. /*
  1694. * List themes
  1695. */
  1696. $xthemes = array();
  1697. if ($themes) {
  1698. foreach ($themes as $th) {
  1699. $xthemes[] = array($th['name'],(($th['allowed']) ? "on" : "off"), get_theme_info($th['name']));
  1700. }
  1701. }
  1702. $t = get_markup_template("admin_plugins.tpl");
  1703. return replace_macros($t, array(
  1704. '$title' => t('Administration'),
  1705. '$page' => t('Themes'),
  1706. '$submit' => t('Save Settings'),
  1707. '$reload' => t('Reload active themes'),
  1708. '$baseurl' => App::get_baseurl(true),
  1709. '$function' => 'themes',
  1710. '$plugins' => $xthemes,
  1711. '$pcount' => count($themes),
  1712. '$noplugshint' => sprintf(t('No themes found on the system. They should be paced in %1$s'),'<code>/view/themes</code>'),
  1713. '$experimental' => t('[Experimental]'),
  1714. '$unsupported' => t('[Unsupported]'),
  1715. '$form_security_token' => get_form_security_token("admin_themes"),
  1716. ));
  1717. }
  1718. /**
  1719. * @brief Prosesses data send by Logs admin page
  1720. *
  1721. * @param App $a
  1722. */
  1723. function admin_page_logs_post(App $a) {
  1724. if (x($_POST,"page_logs")) {
  1725. check_form_security_token_redirectOnErr('/admin/logs', 'admin_logs');
  1726. $logfile = ((x($_POST,'logfile')) ? notags(trim($_POST['logfile'])) : '');
  1727. $debugging = ((x($_POST,'debugging')) ? true : false);
  1728. $loglevel = ((x($_POST,'loglevel')) ? intval(trim($_POST['loglevel'])) : 0);
  1729. set_config('system','logfile', $logfile);
  1730. set_config('system','debugging', $debugging);
  1731. set_config('system','loglevel', $loglevel);
  1732. }
  1733. info(t("Log settings updated."));
  1734. goaway('admin/logs');
  1735. return; // NOTREACHED
  1736. }
  1737. /**
  1738. * @brief Generates admin panel subpage for configuration of the logs
  1739. *
  1740. * This function take the view/templates/admin_logs.tpl file and generates a
  1741. * page where admin can configure the logging of friendica.
  1742. *
  1743. * Displaying the log is separated from the log config as the logfile can get
  1744. * big depending on the settings and changing settings regarding the logs can
  1745. * thus waste bandwidth.
  1746. *
  1747. * The string returned contains the content of the template file with replaced
  1748. * macros.
  1749. *
  1750. * @param App $a
  1751. * @return string
  1752. */
  1753. function admin_page_logs(App $a) {
  1754. $log_choices = array(
  1755. LOGGER_NORMAL => 'Normal',
  1756. LOGGER_TRACE => 'Trace',
  1757. LOGGER_DEBUG => 'Debug',
  1758. LOGGER_DATA => 'Data',
  1759. LOGGER_ALL => 'All'
  1760. );
  1761. if (ini_get('log_errors')) {
  1762. $phplogenabled = t('PHP log currently enabled.');
  1763. } else {
  1764. $phplogenabled = t('PHP log currently disabled.');
  1765. }
  1766. $t = get_markup_template("admin_logs.tpl");
  1767. return replace_macros($t, array(
  1768. '$title' => t('Administration'),
  1769. '$page' => t('Logs'),
  1770. '$submit' => t('Save Settings'),
  1771. '$clear' => t('Clear'),
  1772. '$baseurl' => App::get_baseurl(true),
  1773. '$logname' => get_config('system','logfile'),
  1774. // name, label, value, help string, extra data...
  1775. '$debugging' => array('debugging', t("Enable Debugging"),get_config('system','debugging'), ""),
  1776. '$logfile' => array('logfile', t("Log file"), get_config('system','logfile'), t("Must be writable by web server. Relative to your Friendica top-level directory.")),
  1777. '$loglevel' => array('loglevel', t("Log level"), get_config('system','loglevel'), "", $log_choices),
  1778. '$form_security_token' => get_form_security_token("admin_logs"),
  1779. '$phpheader' => t("PHP logging"),
  1780. '$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."),
  1781. '$phplogcode' => "error_reporting(E_ERROR | E_WARNING | E_PARSE);\nini_set('error_log','php.out');\nini_set('log_errors','1');\nini_set('display_errors', '1');",
  1782. '$phplogenabled' => $phplogenabled,
  1783. ));
  1784. }
  1785. /**
  1786. * @brief Generates admin panel subpage to view the Friendica log
  1787. *
  1788. * This function loads the template view/templates/admin_viewlogs.tpl to
  1789. * display the systemlog content. The filename for the systemlog of friendica
  1790. * is relative to the base directory and taken from the config entry 'logfile'
  1791. * in the 'system' category.
  1792. *
  1793. * Displaying the log is separated from the log config as the logfile can get
  1794. * big depending on the settings and changing settings regarding the logs can
  1795. * thus waste bandwidth.
  1796. *
  1797. * The string returned contains the content of the template file with replaced
  1798. * macros.
  1799. *
  1800. * @param App $a
  1801. * @return string
  1802. */
  1803. function admin_page_viewlogs(App $a) {
  1804. $t = get_markup_template("admin_viewlogs.tpl");
  1805. $f = get_config('system','logfile');
  1806. $data = '';
  1807. if (!file_exists($f)) {
  1808. $data = t("Error trying to open <strong>$f</strong> log file.\r\n<br/>Check to see if file $f exist and is readable.");
  1809. } else {
  1810. $fp = fopen($f, 'r');
  1811. if (!$fp) {
  1812. $data = t("Couldn't open <strong>$f</strong> log file.\r\n<br/>Check to see if file $f is readable.");
  1813. } else {
  1814. $fstat = fstat($fp);
  1815. $size = $fstat['size'];
  1816. if ($size != 0) {
  1817. if ($size > 5000000 || $size < 0) {
  1818. $size = 5000000;
  1819. }
  1820. $seek = fseek($fp,0-$size,SEEK_END);
  1821. if ($seek === 0) {
  1822. $data = escape_tags(fread($fp,$size));
  1823. while (! feof($fp)) {
  1824. $data .= escape_tags(fread($fp,4096));
  1825. }
  1826. }
  1827. }
  1828. fclose($fp);
  1829. }
  1830. }
  1831. return replace_macros($t, array(
  1832. '$title' => t('Administration'),
  1833. '$page' => t('View Logs'),
  1834. '$data' => $data,
  1835. '$logname' => get_config('system','logfile')
  1836. ));
  1837. }
  1838. /**
  1839. * @brief Prosesses data send by the features admin page
  1840. *
  1841. * @param App $a
  1842. */
  1843. function admin_page_features_post(App $a) {
  1844. check_form_security_token_redirectOnErr('/admin/features', 'admin_manage_features');
  1845. logger('postvars: '.print_r($_POST,true),LOGGER_DATA);
  1846. $arr = array();
  1847. $features = get_features(false);
  1848. foreach ($features as $fname => $fdata) {
  1849. foreach (array_slice($fdata, 1) as $f) {
  1850. $feature = $f[0];
  1851. $feature_state = 'feature_' . $feature;
  1852. $featurelock = 'featurelock_' . $feature;
  1853. if (x($_POST, $feature_state)) {
  1854. $val = intval($_POST[$feature_state]);
  1855. } else {
  1856. $val = 0;
  1857. }
  1858. set_config('feature',$feature,$val);
  1859. if (x($_POST, $featurelock)) {
  1860. set_config('feature_lock', $feature, $val);
  1861. } else {
  1862. del_config('feature_lock', $feature);
  1863. }
  1864. }
  1865. }
  1866. goaway('admin/features');
  1867. return; // NOTREACHED
  1868. }
  1869. /**
  1870. * @brief Subpage for global additional feature management
  1871. *
  1872. * This functin generates the subpage 'Manage Additional Features'
  1873. * for the admin panel. At this page the admin can set preferences
  1874. * for the user settings of the 'additional features'. If needed this
  1875. * preferences can be locked through the admin.
  1876. *
  1877. * The returned string contains the HTML code of the subpage 'Manage
  1878. * Additional Features'
  1879. *
  1880. * @param App $a
  1881. * @return string
  1882. */
  1883. function admin_page_features(App $a) {
  1884. if ((argc() > 1) && (argv(1) === 'features')) {
  1885. $arr = array();
  1886. $features = get_features(false);
  1887. foreach ($features as $fname => $fdata) {
  1888. $arr[$fname] = array();
  1889. $arr[$fname][0] = $fdata[0];
  1890. foreach (array_slice($fdata,1) as $f) {
  1891. $set = get_config('feature',$f[0]);
  1892. if ($set === false) {
  1893. $set = $f[3];
  1894. }
  1895. $arr[$fname][1][] = array(
  1896. array('feature_' .$f[0],$f[1],$set,$f[2],array(t('Off'), t('On'))),
  1897. array('featurelock_' .$f[0],sprintf(t('Lock feature %s'),$f[1]),(($f[4] !== false) ? "1" : ''),'',array(t('Off'), t('On')))
  1898. );
  1899. }
  1900. }
  1901. $tpl = get_markup_template("admin_settings_features.tpl");
  1902. $o .= replace_macros($tpl, array(
  1903. '$form_security_token' => get_form_security_token("admin_manage_features"),
  1904. '$title' => t('Manage Additional Features'),
  1905. '$features' => $arr,
  1906. '$submit' => t('Save Settings'),
  1907. ));
  1908. return $o;
  1909. }
  1910. }