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.

2077 lines
81 KiB

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