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.

2074 lines
84 KiB

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