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.
 
 
 
 
 
 

2033 lines
81 KiB

  1. <?php
  2. /**
  3. * @file mod/admin.php
  4. *
  5. * @brief Friendica admin
  6. */
  7. require_once("include/enotify.php");
  8. require_once("include/text.php");
  9. /**
  10. * @brief Process send data from the admin panels subpages
  11. *
  12. * This function acts as relais for processing the data send from the subpages
  13. * of the admin panel. Depending on the 1st parameter of the url (argv[1])
  14. * specialized functions are called to process the data from the subpages.
  15. *
  16. * The function itself does not return anything, but the subsequencely function
  17. * return the HTML for the pages of the admin panel.
  18. *
  19. * @param App $a
  20. *
  21. */
  22. function admin_post(&$a){
  23. if(!is_site_admin()) {
  24. return;
  25. }
  26. // do not allow a page manager to access the admin panel at all.
  27. if(x($_SESSION,'submanage') && intval($_SESSION['submanage']))
  28. return;
  29. // urls
  30. if($a->argc > 1) {
  31. switch ($a->argv[1]){
  32. case 'site':
  33. admin_page_site_post($a);
  34. break;
  35. case 'users':
  36. admin_page_users_post($a);
  37. break;
  38. case 'plugins':
  39. if($a->argc > 2 &&
  40. is_file("addon/".$a->argv[2]."/".$a->argv[2].".php")) {
  41. @include_once("addon/".$a->argv[2]."/".$a->argv[2].".php");
  42. if(function_exists($a->argv[2].'_plugin_admin_post')) {
  43. $func = $a->argv[2].'_plugin_admin_post';
  44. $func($a);
  45. }
  46. }
  47. goaway('admin/plugins/'.$a->argv[2]);
  48. return; // NOTREACHED
  49. break;
  50. case 'themes':
  51. if($a->argc < 2) {
  52. if(is_ajax()) return;
  53. goaway('admin/');
  54. return;
  55. }
  56. $theme = $a->argv[2];
  57. if(is_file("view/theme/$theme/config.php")){
  58. function __call_theme_admin_post(&$a, $theme) {
  59. $orig_theme = $a->theme;
  60. $orig_page = $a->page;
  61. $orig_session_theme = $_SESSION['theme'];
  62. require_once("view/theme/$theme/theme.php");
  63. require_once("view/theme/$theme/config.php");
  64. $_SESSION['theme'] = $theme;
  65. $init = $theme."_init";
  66. if(function_exists($init)) $init($a);
  67. if(function_exists("theme_admin_post")) {
  68. $admin_form = theme_admin_post($a);
  69. }
  70. $_SESSION['theme'] = $orig_session_theme;
  71. $a->theme = $orig_theme;
  72. $a->page = $orig_page;
  73. return $admin_form;
  74. }
  75. __call_theme_admin_post($a, $theme);
  76. }
  77. info(t('Theme settings updated.'));
  78. if(is_ajax()) return;
  79. goaway('admin/themes/'.$theme);
  80. return;
  81. break;
  82. case 'features':
  83. admin_page_features_post($a);
  84. break;
  85. case 'logs':
  86. admin_page_logs_post($a);
  87. break;
  88. case 'dbsync':
  89. admin_page_dbsync_post($a);
  90. break;
  91. }
  92. }
  93. goaway('admin');
  94. return; // NOTREACHED
  95. }
  96. /**
  97. * @brief Generates content of the admin panel pages
  98. *
  99. * This function generates the content for the admin panel. It consists of the
  100. * aside menu (same for the entire admin panel) and the code for the soecified
  101. * subpage of the panel.
  102. *
  103. * The structure of the adress is: /admin/subpage/details though "details" is
  104. * only necessary for some subpages, like themes or addons where it is the name
  105. * of one theme resp. addon from which the details should be shown. Content for
  106. * the subpages is generated in separate functions for each of the subpages.
  107. *
  108. * The returned string hold the generated HTML code of the page.
  109. *
  110. * @param App $a
  111. * @return string
  112. */
  113. function admin_content(&$a) {
  114. if(!is_site_admin()) {
  115. return login(false);
  116. }
  117. if(x($_SESSION,'submanage') && intval($_SESSION['submanage']))
  118. return "";
  119. // APC deactivated, since there are problems with PHP 5.5
  120. //if (function_exists("apc_delete")) {
  121. // $toDelete = new APCIterator('user', APC_ITER_VALUE);
  122. // apc_delete($toDelete);
  123. //}
  124. // Header stuff
  125. $a->page['htmlhead'] .= replace_macros(get_markup_template('admin_settings_head.tpl'), array());
  126. /*
  127. * Side bar links
  128. */
  129. $aside_tools = array();
  130. // array(url, name, extra css classes)
  131. // not part of $aside to make the template more adjustable
  132. $aside_sub = array(
  133. 'site' => array("admin/site/", t("Site") , "site"),
  134. 'users' => array("admin/users/", t("Users") , "users"),
  135. 'plugins'=> array("admin/plugins/", t("Plugins") , "plugins"),
  136. 'themes' => array("admin/themes/", t("Themes") , "themes"),
  137. 'features' => array("admin/features/", t("Additional features") , "features"),
  138. 'dbsync' => array("admin/dbsync/", t('DB updates'), "dbsync"),
  139. 'queue' => array("admin/queue/", t('Inspect Queue'), "queue"),
  140. 'federation' => array("admin/federation/", t('Federation Statistics'), "federation"),
  141. );
  142. /* get plugins admin page */
  143. $r = q("SELECT `name` FROM `addon` WHERE `plugin_admin` = 1 ORDER BY `name`");
  144. $aside_tools['plugins_admin']=array();
  145. foreach ($r as $h){
  146. $plugin =$h['name'];
  147. $aside_tools['plugins_admin'][] = array("admin/plugins/".$plugin, $plugin, "plugin");
  148. // temp plugins with admin
  149. $a->plugins_admin[] = $plugin;
  150. }
  151. $aside_tools['logs'] = array("admin/logs/", t("Logs"), "logs");
  152. $aside_tools['viewlogs'] = array("admin/viewlogs/", t("View Logs"), 'viewlogs');
  153. $aside_tools['diagnostics_probe'] = array('probe/', t('probe address'), 'probe');
  154. $aside_tools['diagnostics_webfinger'] = array('webfinger/', t('check webfinger'), 'webfinger');
  155. $t = get_markup_template("admin_aside.tpl");
  156. $a->page['aside'] .= replace_macros($t, array(
  157. '$admin' => $aside_tools,
  158. '$subpages' => $aside_sub,
  159. '$admtxt' => t('Admin'),
  160. '$plugadmtxt' => t('Plugin Features'),
  161. '$logtxt' => t('Logs'),
  162. '$diagnosticstxt' => t('diagnostics'),
  163. '$h_pending' => t('User registrations waiting for confirmation'),
  164. '$admurl'=> "admin/"
  165. ));
  166. /*
  167. * Page content
  168. */
  169. $o = '';
  170. // urls
  171. if($a->argc > 1) {
  172. switch ($a->argv[1]){
  173. case 'site':
  174. $o = admin_page_site($a);
  175. break;
  176. case 'users':
  177. $o = admin_page_users($a);
  178. break;
  179. case 'plugins':
  180. $o = admin_page_plugins($a);
  181. break;
  182. case 'themes':
  183. $o = admin_page_themes($a);
  184. break;
  185. case 'features':
  186. $o = admin_page_features($a);
  187. break;
  188. case 'logs':
  189. $o = admin_page_logs($a);
  190. break;
  191. case 'viewlogs':
  192. $o = admin_page_viewlogs($a);
  193. break;
  194. case 'dbsync':
  195. $o = admin_page_dbsync($a);
  196. break;
  197. case 'queue':
  198. $o = admin_page_queue($a);
  199. break;
  200. case 'federation':
  201. $o = admin_page_federation($a);
  202. break;
  203. default:
  204. notice(t("Item not found."));
  205. }
  206. } else {
  207. $o = admin_page_summary($a);
  208. }
  209. if(is_ajax()) {
  210. echo $o;
  211. killme();
  212. return '';
  213. } else {
  214. return $o;
  215. }
  216. }
  217. /**
  218. * @brief Subpage with some stats about "the federation" network
  219. *
  220. * This function generates the "Federation Statistics" subpage for the admin
  221. * panel. The page lists some numbers to the part of "The Federation" known to
  222. * the node. This data includes the different connected networks (e.g.
  223. * Diaspora, Hubzilla, GNU Social) and the used versions in the different
  224. * networks.
  225. *
  226. * The returned string contains the HTML code of the subpage for display.
  227. *
  228. * @param App $a
  229. * @return string
  230. */
  231. function admin_page_federation(&$a) {
  232. // get counts on active friendica, diaspora, redmatrix, hubzilla, gnu
  233. // social and statusnet nodes this node is knowing
  234. //
  235. // We are looking for the following platforms in the DB, "Red" should find
  236. // all variants of that platform ID string as the q() function is stripping
  237. // off one % two of them are needed in the query
  238. // Add more platforms if you like, when one returns 0 known nodes it is not
  239. // displayed on the stats page.
  240. $platforms = array('Friendica', 'Diaspora', '%%red%%', 'Hubzilla', 'BlaBlaNet', 'GNU Social', 'StatusNet', 'Mastodon');
  241. $colors = array('Friendica' => '#ffc018', // orange from the logo
  242. 'Diaspora' => '#a1a1a1', // logo is black and white, makes a gray
  243. '%%red%%' => '#c50001', // fire red from the logo
  244. 'Hubzilla' => '#43488a', // blue from the logo
  245. 'BlaBlaNet' => '#3B5998', // blue from the navbar at blablanet-dot-com
  246. 'GNU Social'=> '#a22430', // dark red from the logo
  247. 'StatusNet' => '#789240', // the green from the logo (red and blue have already others
  248. 'Mastodon' => '#1a9df9'); // blue from the Mastodon logo
  249. $counts = array();
  250. $total = 0;
  251. foreach ($platforms as $p) {
  252. // get a total count for the platform, the name and version of the
  253. // highest version and the protocol tpe
  254. $c = qu('SELECT COUNT(*) AS `total`, `platform`, `network`, `version` FROM `gserver`
  255. WHERE `platform` LIKE "%s" AND `last_contact` > `last_failure` AND `version` != ""
  256. ORDER BY `version` ASC;', $p);
  257. $total = $total + $c[0]['total'];
  258. // what versions for that platform do we know at all?
  259. // again only the active nodes
  260. $v = qu('SELECT COUNT(*) AS `total`, `version` FROM `gserver`
  261. WHERE `last_contact` > `last_failure` AND `platform` LIKE "%s" AND `version` != ""
  262. GROUP BY `version`
  263. ORDER BY `version`;', $p);
  264. //
  265. // clean up version numbers
  266. //
  267. // in the DB the Diaspora versions have the format x.x.x.x-xx the last
  268. // part (-xx) should be removed to clean up the versions from the "head
  269. // commit" information and combined into a single entry for x.x.x.x
  270. if($p=='Diaspora') {
  271. $newV = array();
  272. $newVv = array();
  273. foreach($v as $vv) {
  274. $newVC = $vv['total'];
  275. $newVV = $vv['version'];
  276. $posDash = strpos($newVV, '-');
  277. if($posDash)
  278. $newVV = substr($newVV, 0, $posDash);
  279. if(isset($newV[$newVV]))
  280. $newV[$newVV] += $newVC;
  281. else
  282. $newV[$newVV] = $newVC;
  283. }
  284. foreach ($newV as $key => $value) {
  285. array_push($newVv, array('total'=>$value, 'version'=>$key));
  286. }
  287. $v = $newVv;
  288. }
  289. // early friendica versions have the format x.x.xxxx where xxxx is the
  290. // DB version stamp; those should be operated out and versions be
  291. // conbined
  292. if($p=='Friendica') {
  293. $newV = array();
  294. $newVv = array();
  295. foreach ($v as $vv) {
  296. $newVC = $vv['total'];
  297. $newVV = $vv['version'];
  298. $lastDot = strrpos($newVV,'.');
  299. $len = strlen($newVV)-1;
  300. if(($lastDot == $len-4) && (!strrpos($newVV,'-rc')==$len-3))
  301. $newVV = substr($newVV, 0, $lastDot);
  302. if(isset($newV[$newVV]))
  303. $newV[$newVV] += $newVC;
  304. else
  305. $newV[$newVV] = $newVC;
  306. }
  307. foreach ($newV as $key => $value) {
  308. array_push($newVv, array('total'=>$value, 'version'=>$key));
  309. }
  310. $v = $newVv;
  311. }
  312. foreach ($v as $key => $vv)
  313. $v[$key]["version"] = trim(strip_tags($vv["version"]));
  314. // the 3rd array item is needed for the JavaScript graphs as JS does
  315. // not like some characters in the names of variables...
  316. $counts[$p]=array($c[0], $v, str_replace(array(' ','%'),'',$p), $colors[$p]);
  317. }
  318. // some helpful text
  319. $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.');
  320. $hint = t('The <em>Auto Discovered Contact Directory</em> feature is not enabled, it will improve the data displayed here.');
  321. // load the template, replace the macros and return the page content
  322. $t = get_markup_template("admin_federation.tpl");
  323. return replace_macros($t, array(
  324. '$title' => t('Administration'),
  325. '$page' => t('Federation Statistics'),
  326. '$intro' => $intro,
  327. '$hint' => $hint,
  328. '$autoactive' => get_config('system', 'poco_completion'),
  329. '$counts' => $counts,
  330. '$version' => FRIENDICA_VERSION,
  331. '$legendtext' => sprintf(t('Currently this node is aware of %d nodes from the following platforms:'), $total),
  332. '$baseurl' => $a->get_baseurl(),
  333. ));
  334. }
  335. /**
  336. * @brief Admin Inspect Queue Page
  337. *
  338. * Generates a page for the admin to have a look into the current queue of
  339. * postings that are not deliverabke. Shown are the name and url of the
  340. * recipient, the delivery network and the dates when the posting was generated
  341. * and the last time tried to deliver the posting.
  342. *
  343. * The returned string holds the content of the page.
  344. *
  345. * @param App $a
  346. * @return string
  347. */
  348. function admin_page_queue(&$a) {
  349. // get content from the queue table
  350. $r = q("SELECT `c`.`name`, `c`.`nurl`, `q`.`id`, `q`.`network`, `q`.`created`, `q`.`last`
  351. FROM `queue` AS `q`, `contact` AS `c`
  352. WHERE `c`.`id` = `q`.`cid`
  353. ORDER BY `q`.`cid`, `q`.`created`;");
  354. $t = get_markup_template("admin_queue.tpl");
  355. return replace_macros($t, array(
  356. '$title' => t('Administration'),
  357. '$page' => t('Inspect Queue'),
  358. '$count' => sizeof($r),
  359. 'id_header' => t('ID'),
  360. '$to_header' => t('Recipient Name'),
  361. '$url_header' => t('Recipient Profile'),
  362. '$network_header' => t('Network'),
  363. '$created_header' => t('Created'),
  364. '$last_header' => t('Last Tried'),
  365. '$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.'),
  366. '$entries' => $r,
  367. ));
  368. }
  369. /**
  370. * @brief Admin Summary Page
  371. *
  372. * The summary page is the "start page" of the admin panel. It gives the admin
  373. * a first overview of the open adminastrative tasks.
  374. *
  375. * The returned string contains the HTML content of the generated page.
  376. *
  377. * @param App $a
  378. * @return string
  379. */
  380. function admin_page_summary(&$a) {
  381. $r = q("SELECT `page-flags`, COUNT(`uid`) AS `count` FROM `user` GROUP BY `page-flags`");
  382. $accounts = array(
  383. array(t('Normal Account'), 0),
  384. array(t('Soapbox Account'), 0),
  385. array(t('Community/Celebrity Account'), 0),
  386. array(t('Automatic Friend Account'), 0),
  387. array(t('Blog Account'), 0),
  388. array(t('Private Forum'), 0)
  389. );
  390. $users=0;
  391. foreach ($r as $u){ $accounts[$u['page-flags']][1] = $u['count']; $users+= $u['count']; }
  392. logger('accounts: '.print_r($accounts,true),LOGGER_DATA);
  393. $r = qu("SELECT COUNT(`id`) AS `count` FROM `register`");
  394. $pending = $r[0]['count'];
  395. $r = qu("SELECT COUNT(*) AS `total` FROM `deliverq` WHERE 1");
  396. $deliverq = (($r) ? $r[0]['total'] : 0);
  397. $r = qu("SELECT COUNT(*) AS `total` FROM `queue` WHERE 1");
  398. $queue = (($r) ? $r[0]['total'] : 0);
  399. if (get_config('system','worker')) {
  400. $r = qu("SELECT COUNT(*) AS `total` FROM `workerqueue` WHERE 1");
  401. $workerqueue = (($r) ? $r[0]['total'] : 0);
  402. } else {
  403. $workerqueue = 0;
  404. }
  405. // We can do better, but this is a quick queue status
  406. $queues = array('label' => t('Message queues'), 'deliverq' => $deliverq, 'queue' => $queue, 'workerq' => $workerqueue);
  407. $t = get_markup_template("admin_summary.tpl");
  408. return replace_macros($t, array(
  409. '$title' => t('Administration'),
  410. '$page' => t('Summary'),
  411. '$queues' => $queues,
  412. '$workeractive' => get_config('system','worker'),
  413. '$users' => array(t('Registered users'), $users),
  414. '$accounts' => $accounts,
  415. '$pending' => array(t('Pending registrations'), $pending),
  416. '$version' => array(t('Version'), FRIENDICA_VERSION),
  417. '$baseurl' => $a->get_baseurl(),
  418. '$platform' => FRIENDICA_PLATFORM,
  419. '$codename' => FRIENDICA_CODENAME,
  420. '$build' => get_config('system','build'),
  421. '$plugins' => array(t('Active plugins'), $a->plugins)
  422. ));
  423. }
  424. /**
  425. * @brief Process send data from Admin Site Page
  426. *
  427. * @param App $a
  428. */
  429. function admin_page_site_post(&$a) {
  430. if(!x($_POST,"page_site")) {
  431. return;
  432. }
  433. check_form_security_token_redirectOnErr('/admin/site', 'admin_site');
  434. // relocate
  435. if(x($_POST,'relocate') && x($_POST,'relocate_url') && $_POST['relocate_url']!="") {
  436. $new_url = $_POST['relocate_url'];
  437. $new_url = rtrim($new_url,"/");
  438. $parsed = @parse_url($new_url);
  439. if(!$parsed || (!x($parsed,'host') || !x($parsed,'scheme'))) {
  440. notice(t("Can not parse base url. Must have at least <scheme>://<domain>"));
  441. goaway('admin/site');
  442. }
  443. /* steps:
  444. * replace all "baseurl" to "new_url" in config, profile, term, items and contacts
  445. * send relocate for every local user
  446. * */
  447. $old_url = $a->get_baseurl(true);
  448. // Generate host names for relocation the addresses in the format user@address.tld
  449. $new_host = str_replace("http://", "@", normalise_link($new_url));
  450. $old_host = str_replace("http://", "@", normalise_link($old_url));
  451. function update_table($table_name, $fields, $old_url, $new_url) {
  452. global $db, $a;
  453. $dbold = dbesc($old_url);
  454. $dbnew = dbesc($new_url);
  455. $upd = array();
  456. foreach ($fields as $f) {
  457. $upd[] = "`$f` = REPLACE(`$f`, '$dbold', '$dbnew')";
  458. }
  459. $upds = implode(", ", $upd);
  460. $q = sprintf("UPDATE %s SET %s;", $table_name, $upds);
  461. $r = q($q);
  462. if(!$r) {
  463. notice("Failed updating '$table_name': ".$db->error);
  464. goaway('admin/site');
  465. }
  466. }
  467. // update tables
  468. // update profile links in the format "http://server.tld"
  469. update_table("profile", array('photo', 'thumb'), $old_url, $new_url);
  470. update_table("term", array('url'), $old_url, $new_url);
  471. update_table("contact", array('photo','thumb','micro','url','nurl','alias','request','notify','poll','confirm','poco', 'avatar'), $old_url, $new_url);
  472. update_table("gcontact", array('url','nurl','photo','server_url','notify','alias'), $old_url, $new_url);
  473. update_table("item", array('owner-link','owner-avatar','author-link','author-avatar','body','plink','tag'), $old_url, $new_url);
  474. // update profile addresses in the format "user@server.tld"
  475. update_table("contact", array('addr'), $old_host, $new_host);
  476. update_table("gcontact", array('connect','addr'), $old_host, $new_host);
  477. // update config
  478. $a->set_baseurl($new_url);
  479. set_config('system','url',$new_url);
  480. // send relocate
  481. $users = q("SELECT `uid` FROM `user` WHERE `account_removed` = 0 AND `account_expired` = 0");
  482. foreach ($users as $user) {
  483. proc_run(PRIORITY_HIGH, 'include/notifier.php', 'relocate', $user['uid']);
  484. }
  485. info("Relocation started. Could take a while to complete.");
  486. goaway('admin/site');
  487. }
  488. // end relocate
  489. $sitename = ((x($_POST,'sitename')) ? notags(trim($_POST['sitename'])) : '');
  490. $hostname = ((x($_POST,'hostname')) ? notags(trim($_POST['hostname'])) : '');
  491. $sender_email = ((x($_POST,'sender_email')) ? notags(trim($_POST['sender_email'])) : '');
  492. $banner = ((x($_POST,'banner')) ? trim($_POST['banner']) : false);
  493. $shortcut_icon = ((x($_POST,'shortcut_icon')) ? notags(trim($_POST['shortcut_icon'])) : '');
  494. $touch_icon = ((x($_POST,'touch_icon')) ? notags(trim($_POST['touch_icon'])) : '');
  495. $info = ((x($_POST,'info')) ? trim($_POST['info']) : false);
  496. $language = ((x($_POST,'language')) ? notags(trim($_POST['language'])) : '');
  497. $theme = ((x($_POST,'theme')) ? notags(trim($_POST['theme'])) : '');
  498. $theme_mobile = ((x($_POST,'theme_mobile')) ? notags(trim($_POST['theme_mobile'])) : '');
  499. $maximagesize = ((x($_POST,'maximagesize')) ? intval(trim($_POST['maximagesize'])) : 0);
  500. $maximagelength = ((x($_POST,'maximagelength')) ? intval(trim($_POST['maximagelength'])) : MAX_IMAGE_LENGTH);
  501. $jpegimagequality = ((x($_POST,'jpegimagequality')) ? intval(trim($_POST['jpegimagequality'])) : JPEG_QUALITY);
  502. $register_policy = ((x($_POST,'register_policy')) ? intval(trim($_POST['register_policy'])) : 0);
  503. $daily_registrations = ((x($_POST,'max_daily_registrations')) ? intval(trim($_POST['max_daily_registrations'])) :0);
  504. $abandon_days = ((x($_POST,'abandon_days')) ? intval(trim($_POST['abandon_days'])) : 0);
  505. $register_text = ((x($_POST,'register_text')) ? notags(trim($_POST['register_text'])) : '');
  506. $allowed_sites = ((x($_POST,'allowed_sites')) ? notags(trim($_POST['allowed_sites'])) : '');
  507. $allowed_email = ((x($_POST,'allowed_email')) ? notags(trim($_POST['allowed_email'])) : '');
  508. $block_public = ((x($_POST,'block_public')) ? True : False);
  509. $force_publish = ((x($_POST,'publish_all')) ? True : False);
  510. $global_directory = ((x($_POST,'directory')) ? notags(trim($_POST['directory'])) : '');
  511. $thread_allow = ((x($_POST,'thread_allow')) ? True : False);
  512. $newuser_private = ((x($_POST,'newuser_private')) ? True : False);
  513. $enotify_no_content = ((x($_POST,'enotify_no_content')) ? True : False);
  514. $private_addons = ((x($_POST,'private_addons')) ? True : False);
  515. $disable_embedded = ((x($_POST,'disable_embedded')) ? True : False);
  516. $allow_users_remote_self = ((x($_POST,'allow_users_remote_self')) ? True : False);
  517. $no_multi_reg = ((x($_POST,'no_multi_reg')) ? True : False);
  518. $no_openid = !((x($_POST,'no_openid')) ? True : False);
  519. $no_regfullname = !((x($_POST,'no_regfullname')) ? True : False);
  520. $no_utf = !((x($_POST,'no_utf')) ? True : False);
  521. $community_page_style = ((x($_POST,'community_page_style')) ? intval(trim($_POST['community_page_style'])) : 0);
  522. $max_author_posts_community_page = ((x($_POST,'max_author_posts_community_page')) ? intval(trim($_POST['max_author_posts_community_page'])) : 0);
  523. $verifyssl = ((x($_POST,'verifyssl')) ? True : False);
  524. $proxyuser = ((x($_POST,'proxyuser')) ? notags(trim($_POST['proxyuser'])) : '');
  525. $proxy = ((x($_POST,'proxy')) ? notags(trim($_POST['proxy'])) : '');
  526. $timeout = ((x($_POST,'timeout')) ? intval(trim($_POST['timeout'])) : 60);
  527. $delivery_interval = ((x($_POST,'delivery_interval')) ? intval(trim($_POST['delivery_interval'])) : 0);
  528. $poll_interval = ((x($_POST,'poll_interval')) ? intval(trim($_POST['poll_interval'])) : 0);
  529. $maxloadavg = ((x($_POST,'maxloadavg')) ? intval(trim($_POST['maxloadavg'])) : 50);
  530. $maxloadavg_frontend = ((x($_POST,'maxloadavg_frontend')) ? intval(trim($_POST['maxloadavg_frontend'])) : 50);
  531. $optimize_max_tablesize = ((x($_POST,'optimize_max_tablesize')) ? intval(trim($_POST['optimize_max_tablesize'])): 100);
  532. $optimize_fragmentation = ((x($_POST,'optimize_fragmentation')) ? intval(trim($_POST['optimize_fragmentation'])): 30);
  533. $poco_completion = ((x($_POST,'poco_completion')) ? intval(trim($_POST['poco_completion'])) : false);
  534. $poco_requery_days = ((x($_POST,'poco_requery_days')) ? intval(trim($_POST['poco_requery_days'])) : 7);
  535. $poco_discovery = ((x($_POST,'poco_discovery')) ? intval(trim($_POST['poco_discovery'])) : 0);
  536. $poco_discovery_since = ((x($_POST,'poco_discovery_since')) ? intval(trim($_POST['poco_discovery_since'])) : 30);
  537. $poco_local_search = ((x($_POST,'poco_local_search')) ? intval(trim($_POST['poco_local_search'])) : false);
  538. $nodeinfo = ((x($_POST,'nodeinfo')) ? intval(trim($_POST['nodeinfo'])) : false);
  539. $dfrn_only = ((x($_POST,'dfrn_only')) ? True : False);
  540. $ostatus_disabled = !((x($_POST,'ostatus_disabled')) ? True : False);
  541. $ostatus_poll_interval = ((x($_POST,'ostatus_poll_interval')) ? intval(trim($_POST['ostatus_poll_interval'])) : 0);
  542. $ostatus_full_threads = ((x($_POST,'ostatus_full_threads')) ? True : False);
  543. $diaspora_enabled = ((x($_POST,'diaspora_enabled')) ? True : False);
  544. $ssl_policy = ((x($_POST,'ssl_policy')) ? intval($_POST['ssl_policy']) : 0);
  545. $force_ssl = ((x($_POST,'force_ssl')) ? True : False);
  546. $old_share = ((x($_POST,'old_share')) ? True : False);
  547. $hide_help = ((x($_POST,'hide_help')) ? True : False);
  548. $suppress_language = ((x($_POST,'suppress_language')) ? True : False);
  549. $suppress_tags = ((x($_POST,'suppress_tags')) ? True : False);
  550. $use_fulltext_engine = ((x($_POST,'use_fulltext_engine')) ? True : False);
  551. $itemcache = ((x($_POST,'itemcache')) ? notags(trim($_POST['itemcache'])) : '');
  552. $itemcache_duration = ((x($_POST,'itemcache_duration')) ? intval($_POST['itemcache_duration']) : 0);
  553. $max_comments = ((x($_POST,'max_comments')) ? intval($_POST['max_comments']) : 0);
  554. $lockpath = ((x($_POST,'lockpath')) ? notags(trim($_POST['lockpath'])) : '');
  555. $temppath = ((x($_POST,'temppath')) ? notags(trim($_POST['temppath'])) : '');
  556. $basepath = ((x($_POST,'basepath')) ? notags(trim($_POST['basepath'])) : '');
  557. $singleuser = ((x($_POST,'singleuser')) ? notags(trim($_POST['singleuser'])) : '');
  558. $proxy_disabled = ((x($_POST,'proxy_disabled')) ? True : False);
  559. $old_pager = ((x($_POST,'old_pager')) ? True : False);
  560. $only_tag_search = ((x($_POST,'only_tag_search')) ? True : False);
  561. $rino = ((x($_POST,'rino')) ? intval($_POST['rino']) : 0);
  562. $embedly = ((x($_POST,'embedly')) ? notags(trim($_POST['embedly'])) : '');
  563. $worker = ((x($_POST,'worker')) ? True : False);
  564. $worker_queues = ((x($_POST,'worker_queues')) ? intval($_POST['worker_queues']) : 4);
  565. $worker_dont_fork = ((x($_POST,'worker_dont_fork')) ? True : False);
  566. $worker_fastlane = ((x($_POST,'worker_fastlane')) ? True : False);
  567. if($a->get_path() != "")
  568. $diaspora_enabled = false;
  569. if(!$thread_allow)
  570. $ostatus_disabled = true;
  571. if($ssl_policy != intval(get_config('system','ssl_policy'))) {
  572. if($ssl_policy == SSL_POLICY_FULL) {
  573. q("UPDATE `contact` SET
  574. `url` = REPLACE(`url` , 'http:' , 'https:'),
  575. `photo` = REPLACE(`photo` , 'http:' , 'https:'),
  576. `thumb` = REPLACE(`thumb` , 'http:' , 'https:'),
  577. `micro` = REPLACE(`micro` , 'http:' , 'https:'),
  578. `request` = REPLACE(`request`, 'http:' , 'https:'),
  579. `notify` = REPLACE(`notify` , 'http:' , 'https:'),
  580. `poll` = REPLACE(`poll` , 'http:' , 'https:'),
  581. `confirm` = REPLACE(`confirm`, 'http:' , 'https:'),
  582. `poco` = REPLACE(`poco` , 'http:' , 'https:')
  583. WHERE `self` = 1"
  584. );
  585. q("UPDATE `profile` SET
  586. `photo` = REPLACE(`photo` , 'http:' , 'https:'),
  587. `thumb` = REPLACE(`thumb` , 'http:' , 'https:')
  588. WHERE 1 "
  589. );
  590. }
  591. elseif($ssl_policy == SSL_POLICY_SELFSIGN) {
  592. q("UPDATE `contact` SET
  593. `url` = REPLACE(`url` , 'https:' , 'http:'),
  594. `photo` = REPLACE(`photo` , 'https:' , 'http:'),
  595. `thumb` = REPLACE(`thumb` , 'https:' , 'http:'),
  596. `micro` = REPLACE(`micro` , 'https:' , 'http:'),
  597. `request` = REPLACE(`request`, 'https:' , 'http:'),
  598. `notify` = REPLACE(`notify` , 'https:' , 'http:'),
  599. `poll` = REPLACE(`poll` , 'https:' , 'http:'),
  600. `confirm` = REPLACE(`confirm`, 'https:' , 'http:'),
  601. `poco` = REPLACE(`poco` , 'https:' , 'http:')
  602. WHERE `self` = 1"
  603. );
  604. q("UPDATE `profile` SET
  605. `photo` = REPLACE(`photo` , 'https:' , 'http:'),
  606. `thumb` = REPLACE(`thumb` , 'https:' , 'http:')
  607. WHERE 1 "
  608. );
  609. }
  610. }
  611. set_config('system','ssl_policy',$ssl_policy);
  612. set_config('system','delivery_interval',$delivery_interval);
  613. set_config('system','poll_interval',$poll_interval);
  614. set_config('system','maxloadavg',$maxloadavg);
  615. set_config('system','maxloadavg_frontend',$maxloadavg_frontend);
  616. set_config('system','optimize_max_tablesize',$optimize_max_tablesize);
  617. set_config('system','optimize_fragmentation',$optimize_fragmentation);
  618. set_config('system','poco_completion',$poco_completion);
  619. set_config('system','poco_requery_days',$poco_requery_days);
  620. set_config('system','poco_discovery',$poco_discovery);
  621. set_config('system','poco_discovery_since',$poco_discovery_since);
  622. set_config('system','poco_local_search',$poco_local_search);
  623. set_config('system','nodeinfo',$nodeinfo);
  624. set_config('config','sitename',$sitename);
  625. set_config('config','hostname',$hostname);
  626. set_config('config','sender_email', $sender_email);
  627. set_config('system','suppress_language',$suppress_language);
  628. set_config('system','suppress_tags',$suppress_tags);
  629. set_config('system','shortcut_icon',$shortcut_icon);
  630. set_config('system','touch_icon',$touch_icon);
  631. if($banner=="") {
  632. // don't know why, but del_config doesn't work...
  633. q("DELETE FROM `config` WHERE `cat` = '%s' AND `k` = '%s' LIMIT 1",
  634. dbesc("system"),
  635. dbesc("banner")
  636. );
  637. } else {
  638. set_config('system','banner', $banner);
  639. }
  640. if($info=="") {
  641. del_config('config','info');
  642. } else {
  643. set_config('config','info',$info);
  644. }
  645. set_config('system','language', $language);
  646. set_config('system','theme', $theme);
  647. if($theme_mobile === '---') {
  648. del_config('system','mobile-theme');
  649. } else {
  650. set_config('system','mobile-theme', $theme_mobile);
  651. }
  652. if($singleuser === '---') {
  653. del_config('system','singleuser');
  654. } else {
  655. set_config('system','singleuser', $singleuser);
  656. }
  657. set_config('system','maximagesize', $maximagesize);
  658. set_config('system','max_image_length', $maximagelength);
  659. set_config('system','jpeg_quality', $jpegimagequality);
  660. set_config('config','register_policy', $register_policy);
  661. set_config('system','max_daily_registrations', $daily_registrations);
  662. set_config('system','account_abandon_days', $abandon_days);
  663. set_config('config','register_text', $register_text);
  664. set_config('system','allowed_sites', $allowed_sites);
  665. set_config('system','allowed_email', $allowed_email);
  666. set_config('system','block_public', $block_public);
  667. set_config('system','publish_all', $force_publish);
  668. set_config('system','directory', $global_directory);
  669. set_config('system','thread_allow', $thread_allow);
  670. set_config('system','newuser_private', $newuser_private);
  671. set_config('system','enotify_no_content', $enotify_no_content);
  672. set_config('system','disable_embedded', $disable_embedded);
  673. set_config('system','allow_users_remote_self', $allow_users_remote_self);
  674. set_config('system','block_extended_register', $no_multi_reg);
  675. set_config('system','no_openid', $no_openid);
  676. set_config('system','no_regfullname', $no_regfullname);
  677. set_config('system','community_page_style', $community_page_style);
  678. set_config('system','max_author_posts_community_page', $max_author_posts_community_page);
  679. set_config('system','no_utf', $no_utf);
  680. set_config('system','verifyssl', $verifyssl);
  681. set_config('system','proxyuser', $proxyuser);
  682. set_config('system','proxy', $proxy);
  683. set_config('system','curl_timeout', $timeout);
  684. set_config('system','dfrn_only', $dfrn_only);
  685. set_config('system','ostatus_disabled', $ostatus_disabled);
  686. set_config('system','ostatus_poll_interval', $ostatus_poll_interval);
  687. set_config('system','ostatus_full_threads', $ostatus_full_threads);
  688. set_config('system','diaspora_enabled', $diaspora_enabled);
  689. set_config('config','private_addons', $private_addons);
  690. set_config('system','force_ssl', $force_ssl);
  691. set_config('system','old_share', $old_share);
  692. set_config('system','hide_help', $hide_help);
  693. set_config('system','use_fulltext_engine', $use_fulltext_engine);
  694. set_config('system','itemcache', $itemcache);
  695. set_config('system','itemcache_duration', $itemcache_duration);
  696. set_config('system','max_comments', $max_comments);
  697. set_config('system','lockpath', $lockpath);
  698. set_config('system','temppath', $temppath);
  699. set_config('system','basepath', $basepath);
  700. set_config('system','proxy_disabled', $proxy_disabled);
  701. set_config('system','old_pager', $old_pager);
  702. set_config('system','only_tag_search', $only_tag_search);
  703. set_config('system','worker', $worker);
  704. set_config('system','worker_queues', $worker_queues);
  705. set_config('system','worker_dont_fork', $worker_dont_fork);
  706. set_config('system','worker_fastlane', $worker_fastlane);
  707. if($rino==2 and !function_exists('mcrypt_create_iv')) {
  708. notice(t("RINO2 needs mcrypt php extension to work."));
  709. } else {
  710. set_config('system','rino_encrypt', $rino);
  711. }
  712. set_config('system','embedly', $embedly);
  713. info(t('Site settings updated.').EOL);
  714. goaway('admin/site');
  715. return; // NOTREACHED
  716. }
  717. /**
  718. * @brief Generate Admin Site subpage
  719. *
  720. * This function generates the main configuration page of the admin panel.
  721. *
  722. * @param App $a
  723. * @return string
  724. */
  725. function admin_page_site(&$a) {
  726. /* Installed langs */
  727. $lang_choices = get_available_languages();
  728. if(strlen(get_config('system','directory_submit_url')) AND
  729. !strlen(get_config('system','directory'))) {
  730. set_config('system','directory', dirname(get_config('system','directory_submit_url')));
  731. del_config('system','directory_submit_url');
  732. }
  733. /* Installed themes */
  734. $theme_choices = array();
  735. $theme_choices_mobile = array();
  736. $theme_choices_mobile["---"] = t("No special theme for mobile devices");
  737. $files = glob('view/theme/*');
  738. if($files) {
  739. foreach($files as $file) {
  740. if(intval(file_exists($file.'/unsupported')))
  741. continue;
  742. $f = basename($file);
  743. $theme_name = ((file_exists($file.'/experimental')) ? sprintf("%s - \x28Experimental\x29", $f) : $f);
  744. if(file_exists($file.'/mobile')) {
  745. $theme_choices_mobile[$f] = $theme_name;
  746. } else {
  747. $theme_choices[$f] = $theme_name;
  748. }
  749. }
  750. }
  751. /* Community page style */
  752. $community_page_style_choices = array(
  753. CP_NO_COMMUNITY_PAGE => t("No community page"),
  754. CP_USERS_ON_SERVER => t("Public postings from users of this site"),
  755. CP_GLOBAL_COMMUNITY => t("Global community page")
  756. );
  757. /* OStatus conversation poll choices */
  758. $ostatus_poll_choices = array(
  759. "-2" => t("Never"),
  760. "-1" => t("At post arrival"),
  761. "0" => t("Frequently"),
  762. "60" => t("Hourly"),
  763. "720" => t("Twice daily"),
  764. "1440" => t("Daily")
  765. );
  766. $poco_discovery_choices = array(
  767. "0" => t("Disabled"),
  768. "1" => t("Users"),
  769. "2" => t("Users, Global Contacts"),
  770. "3" => t("Users, Global Contacts/fallback"),
  771. );
  772. $poco_discovery_since_choices = array(
  773. "30" => t("One month"),
  774. "91" => t("Three months"),
  775. "182" => t("Half a year"),
  776. "365" => t("One year"),
  777. );
  778. /* get user names to make the install a personal install of X */
  779. $user_names = array();
  780. $user_names['---'] = t('Multi user instance');
  781. $users = q("SELECT `username`, `nickname` FROM `user`");
  782. foreach ($users as $user) {
  783. $user_names[$user['nickname']] = $user['username'];
  784. }
  785. /* Banner */
  786. $banner = get_config('system','banner');
  787. if($banner == false)
  788. $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>';
  789. $banner = htmlspecialchars($banner);
  790. $info = get_config('config','info');
  791. $info = htmlspecialchars($info);
  792. // Automatically create temporary paths
  793. get_temppath();
  794. get_lockpath();
  795. get_itemcachepath();
  796. //echo "<pre>"; var_dump($lang_choices); die("</pre>");
  797. /* Register policy */
  798. $register_choices = array(
  799. REGISTER_CLOSED => t("Closed"),
  800. REGISTER_APPROVE => t("Requires approval"),
  801. REGISTER_OPEN => t("Open")
  802. );
  803. $ssl_choices = array(
  804. SSL_POLICY_NONE => t("No SSL policy, links will track page SSL state"),
  805. SSL_POLICY_FULL => t("Force all links to use SSL"),
  806. SSL_POLICY_SELFSIGN => t("Self-signed certificate, use SSL for local links only (discouraged)")
  807. );
  808. if($a->config['hostname'] == "")
  809. $a->config['hostname'] = $a->get_hostname();
  810. $diaspora_able = ($a->get_path() == "");
  811. $t = get_markup_template("admin_site.tpl");
  812. return replace_macros($t, array(
  813. '$title' => t('Administration'),
  814. '$page' => t('Site'),
  815. '$submit' => t('Save Settings'),
  816. '$registration' => t('Registration'),
  817. '$upload' => t('File upload'),
  818. '$corporate' => t('Policies'),
  819. '$advanced' => t('Advanced'),
  820. '$portable_contacts' => t('Auto Discovered Contact Directory'),
  821. '$performance' => t('Performance'),
  822. '$worker_title' => t('Worker'),
  823. '$relocate'=> t('Relocate - WARNING: advanced function. Could make this server unreachable.'),
  824. '$baseurl' => $a->get_baseurl(true),
  825. // name, label, value, help string, extra data...
  826. '$sitename' => array('sitename', t("Site name"), $a->config['sitename'],''),
  827. '$hostname' => array('hostname', t("Host name"), $a->config['hostname'], ""),
  828. '$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"),
  829. '$banner' => array('banner', t("Banner/Logo"), $banner, ""),
  830. '$shortcut_icon' => array('shortcut_icon', t("Shortcut icon"), get_config('system','shortcut_icon'), t("Link to an icon that will be used for browsers.")),
  831. '$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.")),
  832. '$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())),
  833. '$language' => array('language', t("System language"), get_config('system','language'), "", $lang_choices),
  834. '$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),
  835. '$theme_mobile' => array('theme_mobile', t("Mobile system theme"), get_config('system','mobile-theme'), t("Theme for mobile devices"), $theme_choices_mobile),
  836. '$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),
  837. '$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.")),
  838. '$old_share' => array('old_share', t("Old style 'Share'"), get_config('system','old_share'), t("Deactivates the bbcode element 'share' for repeating items.")),
  839. '$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.")),
  840. '$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),
  841. '$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.")),
  842. '$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.")),
  843. '$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.")),
  844. '$register_policy' => array('register_policy', t("Register policy"), $a->config['register_policy'], "", $register_choices),
  845. '$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.")),
  846. '$register_text' => array('register_text', t("Register text"), $a->config['register_text'], t("Will be displayed prominently on the registration page.")),
  847. '$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.')),
  848. '$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")),
  849. '$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")),
  850. '$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.")),
  851. '$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.")),
  852. '$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.")),
  853. '$thread_allow' => array('thread_allow', t("Allow threaded items"), get_config('system','thread_allow'), t("Allow infinite level threading for items on this site.")),
  854. '$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.")),
  855. '$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.")),
  856. '$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.")),
  857. '$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.")),
  858. '$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.')),
  859. '$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.")),
  860. '$no_openid' => array('no_openid', t("OpenID support"), !get_config('system','no_openid'), t("OpenID support for registration and logins.")),
  861. '$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")),
  862. '$no_utf' => array('no_utf', t("UTF-8 Regular expressions"), !get_config('system','no_utf'), t("Use PHP UTF8 regular expressions")),
  863. '$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),
  864. '$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')")),
  865. '$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.")),
  866. '$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),
  867. '$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.")),
  868. '$ostatus_not_able' => t("OStatus support can only be enabled if threading is enabled."),
  869. '$diaspora_able' => $diaspora_able,
  870. '$diaspora_not_able' => t("Diaspora support can't be enabled because Friendica was installed into a sub directory."),
  871. '$diaspora_enabled' => array('diaspora_enabled', t("Enable Diaspora support"), get_config('system','diaspora_enabled'), t("Provide built-in Diaspora network compatibility.")),
  872. '$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.")),
  873. '$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.")),
  874. '$proxyuser' => array('proxyuser', t("Proxy user"), get_config('system','proxyuser'), ""),
  875. '$proxy' => array('proxy', t("Proxy URL"), get_config('system','proxy'), ""),
  876. '$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).")),
  877. '$delivery_interval' => array('delivery_interval', t("Delivery interval"), (x(get_config('system','delivery_interval'))?get_config('system','delivery_interval'):2), t("Delay background delivery processes by this many seconds to reduce system load. Recommend: 4-5 for shared hosts, 2-3 for virtual private servers. 0-1 for large dedicated servers.")),
  878. '$poll_interval' => array('poll_interval', t("Poll interval"), (x(get_config('system','poll_interval'))?get_config('system','poll_interval'):2), t("Delay background polling processes by this many seconds to reduce system load. If 0, use delivery interval.")),
  879. '$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.")),
  880. '$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.")),
  881. '$optimize_max_tablesize'=> array('optimize_max_tablesize', t("Maximum table size for optimization"), ((intval(get_config('system','optimize_max_tablesize')) > 0)?get_config('system','optimize_max_tablesize'):100), t("Maximum table size (in MB) for the automatic optimization - default 100 MB. Enter -1 to disable it.")),
  882. '$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%.")),
  883. '$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.")),
  884. '$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.")),
  885. '$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),
  886. '$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),
  887. '$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.")),
  888. '$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.")),
  889. '$use_fulltext_engine' => array('use_fulltext_engine', t("Use MySQL full text engine"), get_config('system','use_fulltext_engine'), t("Activates the full text engine. Speeds up search - but can only search for four and more characters.")),
  890. '$suppress_language' => array('suppress_language', t("Suppress Language"), get_config('system','suppress_language'), t("Suppress language information in meta information about a posting.")),
  891. '$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.")),
  892. '$itemcache' => array('itemcache', t("Path to item cache"), get_config('system','itemcache'), t("The item caches buffers generated bbcode and external images.")),
  893. '$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.")),
  894. '$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.")),
  895. '$lockpath' => array('lockpath', t("Path for lock file"), get_config('system','lockpath'), t("The lock file is used to avoid multiple pollers at one time. Only define a folder here.")),
  896. '$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.")),
  897. '$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.")),
  898. '$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.")),
  899. '$old_pager' => array('old_pager', t("Enable old style pager"), get_config('system','old_pager'), t("The old style pager has page numbers but slows down massively the page speed.")),
  900. '$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.")),
  901. '$relocate_url' => array('relocate_url', t("New base url"), $a->get_baseurl(), t("Change base url for this server. Sends relocate message to all DFRN contacts of all users.")),
  902. '$rino' => array('rino', t("RINO Encryption"), intval(get_config('system','rino_encrypt')), t("Encryption layer between nodes."), array("Disabled", "RINO1 (deprecated)", "RINO2")),
  903. '$embedly' => array('embedly', t("Embedly API key"), get_config('system','embedly'), t("<a href='http://embed.ly'>Embedly</a> is used to fetch additional data for web pages. This is an optional parameter.")),
  904. '$worker' => array('worker', t("Enable 'worker' background processing"), get_config('system','worker'), t("The worker background processing limits the number of parallel background jobs to a maximum number and respects the system load.")),
  905. '$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.")),
  906. '$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.")),
  907. '$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.")),
  908. '$form_security_token' => get_form_security_token("admin_site")
  909. ));
  910. }
  911. /**
  912. * @brief Generates admin panel subpage for DB syncronization
  913. *
  914. * This page checks if the database of friendica is in sync with the specs.
  915. * Should this not be the case, it attemps to sync the structure and notifies
  916. * the admin if the automatic process was failing.
  917. *
  918. * The returned string holds the HTML code of the page.
  919. *
  920. * @param App $a
  921. * @return string
  922. **/
  923. function admin_page_dbsync(&$a) {
  924. $o = '';
  925. if($a->argc > 3 && intval($a->argv[3]) && $a->argv[2] === 'mark') {
  926. set_config('database', 'update_'.intval($a->argv[3]), 'success');
  927. $curr = get_config('system','build');
  928. if(intval($curr) == intval($a->argv[3]))
  929. set_config('system','build',intval($curr) + 1);
  930. info(t('Update has been marked successful').EOL);
  931. goaway('admin/dbsync');
  932. }
  933. if(($a->argc > 2) AND (intval($a->argv[2]) OR ($a->argv[2] === 'check'))) {
  934. require_once("include/dbstructure.php");
  935. $retval = update_structure(false, true);
  936. if(!$retval) {
  937. $o .= sprintf(t("Database structure update %s was successfully applied."), DB_UPDATE_VERSION)."<br />";
  938. set_config('database', 'dbupdate_'.DB_UPDATE_VERSION, 'success');
  939. } else
  940. $o .= sprintf(t("Executing of database structure update %s failed with error: %s"),
  941. DB_UPDATE_VERSION, $retval)."<br />";
  942. if($a->argv[2] === 'check')
  943. return $o;
  944. }
  945. if($a->argc > 2 && intval($a->argv[2])) {
  946. require_once('update.php');
  947. $func = 'update_'.intval($a->argv[2]);
  948. if(function_exists($func)) {
  949. $retval = $func();
  950. if($retval === UPDATE_FAILED) {
  951. $o .= sprintf(t("Executing %s failed with error: %s"), $func, $retval);
  952. }
  953. elseif($retval === UPDATE_SUCCESS) {
  954. $o .= sprintf(t('Update %s was successfully applied.', $func));
  955. set_config('database',$func, 'success');
  956. }
  957. else
  958. $o .= sprintf(t('Update %s did not return a status. Unknown if it succeeded.'), $func);
  959. } else {
  960. $o .= sprintf(t('There was no additional update function %s that needed to be called.'), $func)."<br />";
  961. set_config('database',$func, 'success');
  962. }
  963. return $o;
  964. }
  965. $failed = array();
  966. $r = q("SELECT `k`, `v` FROM `config` WHERE `cat` = 'database' ");
  967. if(count($r)) {
  968. foreach($r as $rr) {
  969. $upd = intval(substr($rr['k'],7));
  970. if($upd < 1139 || $rr['v'] === 'success')
  971. continue;
  972. $failed[] = $upd;
  973. }
  974. }
  975. if(! count($failed)) {
  976. $o = replace_macros(get_markup_template('structure_check.tpl'),array(
  977. '$base' => $a->get_baseurl(true),
  978. '$banner' => t('No failed updates.'),
  979. '$check' => t('Check database structure'),
  980. ));
  981. } else {
  982. $o = replace_macros(get_markup_template('failed_updates.tpl'),array(
  983. '$base' => $a->get_baseurl(true),
  984. '$banner' => t('Failed Updates'),
  985. '$desc' => t('This does not include updates prior to 1139, which did not return a status.'),
  986. '$mark' => t('Mark success (if update was manually applied)'),
  987. '$apply' => t('Attempt to execute this update step automatically'),
  988. '$failed' => $failed
  989. ));
  990. }
  991. return $o;
  992. }
  993. /**
  994. * @brief Process data send by Users admin page
  995. *
  996. * @param App $a
  997. */
  998. function admin_page_users_post(&$a){
  999. $pending = (x($_POST, 'pending') ? $_POST['pending'] : array());
  1000. $users = (x($_POST, 'user') ? $_POST['user'] : array());
  1001. $nu_name = (x($_POST, 'new_user_name') ? $_POST['new_user_name'] : '');
  1002. $nu_nickname = (x($_POST, 'new_user_nickname') ? $_POST['new_user_nickname'] : '');
  1003. $nu_email = (x($_POST, 'new_user_email') ? $_POST['new_user_email'] : '');
  1004. $nu_language = get_config('system', 'language');
  1005. check_form_security_token_redirectOnErr('/admin/users', 'admin_users');
  1006. if(!($nu_name==="") && !($nu_email==="") && !($nu_nickname==="")) {
  1007. require_once('include/user.php');
  1008. $result = create_user(array('username'=>$nu_name, 'email'=>$nu_email,
  1009. 'nickname'=>$nu_nickname, 'verified'=>1, 'language'=>$nu_language));
  1010. if(! $result['success']) {
  1011. notice($result['message']);
  1012. return;
  1013. }
  1014. $nu = $result['user'];
  1015. $preamble = deindent(t('
  1016. Dear %1$s,
  1017. the administrator of %2$s has set up an account for you.'));
  1018. $body = deindent(t('
  1019. The login details are as follows:
  1020. Site Location: %1$s
  1021. Login Name: %2$s
  1022. Password: %3$s
  1023. You may change your password from your account "Settings" page after logging
  1024. in.
  1025. Please take a few moments to review the other account settings on that page.
  1026. You may also wish to add some basic information to your default profile
  1027. (on the "Profiles" page) so that other people can easily find you.
  1028. We recommend setting your full name, adding a profile photo,
  1029. adding some profile "keywords" (very useful in making new friends) - and
  1030. perhaps what country you live in; if you do not wish to be more specific
  1031. than that.
  1032. We fully respect your right to privacy, and none of these items are necessary.
  1033. If you are new and do not know anybody here, they may help
  1034. you to make some new and interesting friends.
  1035. Thank you and welcome to %4$s.'));
  1036. $preamble = sprintf($preamble, $nu['username'], $a->config['sitename']);
  1037. $body = sprintf($body, $a->get_baseurl(), $nu['email'], $result['password'], $a->config['sitename']);
  1038. notification(array(
  1039. 'type' => "SYSTEM_EMAIL",
  1040. 'to_email' => $nu['email'],
  1041. 'subject'=> sprintf(t('Registration details for %s'), $a->config['sitename']),
  1042. 'preamble'=> $preamble,
  1043. 'body' => $body));
  1044. }
  1045. if(x($_POST,'page_users_block')) {
  1046. foreach($users as $uid){
  1047. q("UPDATE `user` SET `blocked` = 1-`blocked` WHERE `uid` = %s",
  1048. intval($uid)
  1049. );
  1050. }
  1051. notice(sprintf(tt("%s user blocked/unblocked", "%s users blocked/unblocked", count($users)), count($users)));
  1052. }
  1053. if(x($_POST,'page_users_delete')) {
  1054. require_once("include/Contact.php");
  1055. foreach($users as $uid){
  1056. user_remove($uid);
  1057. }
  1058. notice(sprintf(tt("%s user deleted", "%s users deleted", count($users)), count($users)));
  1059. }
  1060. if(x($_POST,'page_users_approve')) {
  1061. require_once("mod/regmod.php");
  1062. foreach($pending as $hash){
  1063. user_allow($hash);
  1064. }
  1065. }
  1066. if(x($_POST,'page_users_deny')) {
  1067. require_once("mod/regmod.php");
  1068. foreach($pending as $hash){
  1069. user_deny($hash);
  1070. }
  1071. }
  1072. goaway('admin/users');
  1073. return; // NOTREACHED
  1074. }
  1075. /**
  1076. * @brief Admin panel subpage for User management
  1077. *
  1078. * This function generates the admin panel page for user management of the
  1079. * node. It offers functionality to add/block/delete users and offers some
  1080. * statistics about the userbase.
  1081. *
  1082. * The returned string holds the HTML code of the page.
  1083. *
  1084. * @param App $a
  1085. * @return string
  1086. */
  1087. function admin_page_users(&$a){
  1088. if($a->argc>2) {
  1089. $uid = $a->argv[3];
  1090. $user = q("SELECT `username`, `blocked` FROM `user` WHERE `uid` = %d", intval($uid));
  1091. if(count($user)==0) {
  1092. notice('User not found'.EOL);
  1093. goaway('admin/users');
  1094. return ''; // NOTREACHED
  1095. }
  1096. switch($a->argv[2]){
  1097. case "delete":{
  1098. check_form_security_token_redirectOnErr('/admin/users', 'admin_users', 't');
  1099. // delete user
  1100. require_once("include/Contact.php");
  1101. user_remove($uid);
  1102. notice(sprintf(t("User '%s' deleted"), $user[0]['username']).EOL);
  1103. }; break;
  1104. case "block":{
  1105. check_form_security_token_redirectOnErr('/admin/users', 'admin_users', 't');
  1106. q("UPDATE `user` SET `blocked` = %d WHERE `uid` = %s",
  1107. intval(1-$user[0]['blocked']),
  1108. intval($uid)
  1109. );
  1110. notice(sprintf(($user[0]['blocked']?t("User '%s' unblocked"):t("User '%s' blocked")) , $user[0]['username']).EOL);
  1111. }; break;
  1112. }
  1113. goaway('admin/users');
  1114. return ''; // NOTREACHED
  1115. }
  1116. /* get pending */
  1117. $pending = q("SELECT `register`.*, `contact`.`name`, `user`.`email`
  1118. FROM `register`
  1119. LEFT JOIN `contact` ON `register`.`uid` = `contact`.`uid`
  1120. LEFT JOIN `user` ON `register`.`uid` = `user`.`uid`;");
  1121. /* get users */
  1122. $total = qu("SELECT COUNT(*) AS `total` FROM `user` WHERE 1");
  1123. if(count($total)) {
  1124. $a->set_pager_total($total[0]['total']);
  1125. $a->set_pager_itemspage(100);
  1126. }
  1127. /* ordering */
  1128. $valid_orders = array(
  1129. 'contact.name',
  1130. 'user.email',
  1131. 'user.register_date',
  1132. 'user.login_date',
  1133. 'lastitem_date',
  1134. 'user.page-flags'
  1135. );
  1136. $order = "contact.name";
  1137. $order_direction = "+";
  1138. if (x($_GET,'o')){
  1139. $new_order = $_GET['o'];
  1140. if ($new_order[0]==="-") {
  1141. $order_direction = "-";
  1142. $new_order = substr($new_order,1);
  1143. }
  1144. if (in_array($new_order, $valid_orders)){
  1145. $order = $new_order;
  1146. }
  1147. if (x($_GET,'d')){
  1148. $new_direction = $_GET['d'];
  1149. }
  1150. }
  1151. $sql_order = "`".str_replace('.','`.`',$order)."`";
  1152. $sql_order_direction = ($order_direction==="+")?"ASC":"DESC";
  1153. $users = qu("SELECT `user`.*, `contact`.`name`, `contact`.`url`, `contact`.`micro`, `user`.`account_expired`, `contact`.`last-item` AS `lastitem_date`
  1154. FROM `user`
  1155. INNER JOIN `contact` ON `contact`.`uid` = `user`.`uid` AND `contact`.`self`
  1156. WHERE `user`.`verified`
  1157. ORDER BY $sql_order $sql_order_direction LIMIT %d, %d",
  1158. intval($a->pager['start']),
  1159. intval($a->pager['itemspage'])
  1160. );
  1161. //echo "<pre>$users"; killme();
  1162. $adminlist = explode(",", str_replace(" ", "", $a->config['admin_email']));
  1163. $_setup_users = function ($e) use ($adminlist){
  1164. $accounts = array(
  1165. t('Normal Account'),
  1166. t('Soapbox Account'),
  1167. t('Community/Celebrity Account'),
  1168. t('Automatic Friend Account')
  1169. );
  1170. $e['page-flags'] = $accounts[$e['page-flags']];
  1171. $e['register_date'] = relative_date($e['register_date']);
  1172. $e['login_date'] = relative_date($e['login_date']);
  1173. $e['lastitem_date'] = relative_date($e['lastitem_date']);
  1174. //$e['is_admin'] = ($e['email'] === $a->config['admin_email']);
  1175. $e['is_admin'] = in_array($e['email'], $adminlist);
  1176. $e['is_deletable'] = (intval($e['uid']) != local_user());
  1177. $e['deleted'] = ($e['account_removed']?relative_date($e['account_expires_on']):False);
  1178. return $e;
  1179. };
  1180. $users = array_map($_setup_users, $users);
  1181. // Get rid of dashes in key names, Smarty3 can't handle them
  1182. // and extracting deleted users
  1183. $tmp_users = array();
  1184. $deleted = array();
  1185. while(count($users)) {
  1186. $new_user = array();
  1187. foreach(array_pop($users) as $k => $v) {
  1188. $k = str_replace('-','_',$k);
  1189. $new_user[$k] = $v;
  1190. }
  1191. if($new_user['deleted']) {
  1192. array_push($deleted, $new_user);
  1193. }
  1194. else {
  1195. array_push($tmp_users, $new_user);
  1196. }
  1197. }
  1198. //Reversing the two array, and moving $tmp_users to $users
  1199. array_reverse($deleted);
  1200. while(count($tmp_users)) {
  1201. array_push($users, array_pop($tmp_users));
  1202. }
  1203. $th_users = array_map(null,
  1204. array(t('Name'), t('Email'), t('Register date'), t('Last login'), t('Last item'), t('Account')),
  1205. $valid_orders
  1206. );
  1207. $t = get_markup_template("admin_users.tpl");
  1208. $o = replace_macros($t, array(
  1209. // strings //
  1210. '$title' => t('Administration'),
  1211. '$page' => t('Users'),
  1212. '$submit' => t('Add User'),
  1213. '$select_all' => t('select all'),
  1214. '$h_pending' => t('User registrations waiting for confirm'),
  1215. '$h_deleted' => t('User waiting for permanent deletion'),
  1216. '$th_pending' => array(t('Request date'), t('Name'), t('Email')),
  1217. '$no_pending' => t('No registrations.'),
  1218. '$approve' => t('Approve'),
  1219. '$deny' => t('Deny'),
  1220. '$delete' => t('Delete'),
  1221. '$block' => t('Block'),
  1222. '$unblock' => t('Unblock'),
  1223. '$siteadmin' => t('Site admin'),
  1224. '$accountexpired' => t('Account expired'),
  1225. '$h_users' => t('Users'),
  1226. '$h_newuser' => t('New User'),
  1227. '$th_deleted' => array(t('Name'), t('Email'), t('Register date'), t('Last login'), t('Last item'), t('Deleted since')),
  1228. '$th_users' => $th_users,
  1229. '$order_users' => $order,
  1230. '$order_direction_users' => $order_direction,
  1231. '$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?'),
  1232. '$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?'),
  1233. '$form_security_token' => get_form_security_token("admin_users"),
  1234. // values //
  1235. '$baseurl' => $a->get_baseurl(true),
  1236. '$pending' => $pending,
  1237. 'deleted' => $deleted,
  1238. '$users' => $users,
  1239. '$newusername' => array('new_user_name', t("Name"), '', t("Name of the new user.")),
  1240. '$newusernickname' => array('new_user_nickname', t("Nickname"), '', t("Nickname of the new user.")),
  1241. '$newuseremail' => array('new_user_email', t("Email"), '', t("Email address of the new user."), '', '', 'email'),
  1242. ));
  1243. $o .= paginate($a);
  1244. return $o;
  1245. }
  1246. /**
  1247. * @brief Plugins admin page
  1248. *
  1249. * This function generates the admin panel page for managing plugins on the
  1250. * friendica node. If a plugin name is given a single page showing the details
  1251. * for this addon is generated. If no name is given, a list of available
  1252. * plugins is shown.
  1253. *
  1254. * The template used for displaying the list of plugins and the details of the
  1255. * plugin are the same as used for the templates.
  1256. *
  1257. * The returned string returned hulds the HTML code of the page.
  1258. *
  1259. * @param App $a
  1260. * @return string
  1261. */
  1262. function admin_page_plugins(&$a){
  1263. /*
  1264. * Single plugin
  1265. */
  1266. if($a->argc == 3) {
  1267. $plugin = $a->argv[2];
  1268. if(!is_file("addon/$plugin/$plugin.php")) {
  1269. notice(t("Item not found."));
  1270. return '';
  1271. }
  1272. if(x($_GET,"a") && $_GET['a']=="t") {
  1273. check_form_security_token_redirectOnErr('/admin/plugins', 'admin_themes', 't');
  1274. // Toggle plugin status
  1275. $idx = array_search($plugin, $a->plugins);
  1276. if($idx !== false) {
  1277. unset($a->plugins[$idx]);
  1278. uninstall_plugin($plugin);
  1279. info(sprintf(t("Plugin %s disabled."), $plugin));
  1280. } else {
  1281. $a->plugins[] = $plugin;
  1282. install_plugin($plugin);
  1283. info(sprintf(t("Plugin %s enabled."), $plugin));
  1284. }
  1285. set_config("system","addon", implode(", ",$a->plugins));
  1286. goaway('admin/plugins');
  1287. return ''; // NOTREACHED
  1288. }
  1289. // display plugin details
  1290. require_once('library/markdown.php');
  1291. if(in_array($plugin, $a->plugins)) {
  1292. $status="on"; $action= t("Disable");
  1293. } else {
  1294. $status="off"; $action= t("Enable");
  1295. }
  1296. $readme=Null;
  1297. if(is_file("addon/$plugin/README.md")) {
  1298. $readme = file_get_contents("addon/$plugin/README.md");
  1299. $readme = Markdown($readme);
  1300. } elseif(is_file("addon/$plugin/README")) {
  1301. $readme = "<pre>". file_get_contents("addon/$plugin/README") ."</pre>";
  1302. }
  1303. $admin_form="";
  1304. if(is_array($a->plugins_admin) && in_array($plugin, $a->plugins_admin)) {
  1305. @require_once("addon/$plugin/$plugin.php");
  1306. $func = $plugin.'_plugin_admin';
  1307. $func($a, $admin_form);
  1308. }
  1309. $t = get_markup_template("admin_plugins_details.tpl");
  1310. return replace_macros($t, array(
  1311. '$title' => t('Administration'),
  1312. '$page' => t('Plugins'),
  1313. '$toggle' => t('Toggle'),
  1314. '$settings' => t('Settings'),
  1315. '$baseurl' => $a->get_baseurl(true),
  1316. '$plugin' => $plugin,
  1317. '$status' => $status,
  1318. '$action' => $action,
  1319. '$info' => get_plugin_info($plugin),
  1320. '$str_author' => t('Author: '),
  1321. '$str_maintainer' => t('Maintainer: '),
  1322. '$admin_form' => $admin_form,
  1323. '$function' => 'plugins',
  1324. '$screenshot' => '',
  1325. '$readme' => $readme,
  1326. '$form_security_token' => get_form_security_token("admin_themes"),
  1327. ));
  1328. }
  1329. /*
  1330. * List plugins
  1331. */
  1332. if(x($_GET,"a") && $_GET['a']=="r") {
  1333. check_form_security_token_redirectOnErr($a->get_baseurl().'/admin/plugins', 'admin_themes', 't');
  1334. reload_plugins();
  1335. info("Plugins reloaded");
  1336. goaway($a->get_baseurl().'/admin/plugins');
  1337. }
  1338. $plugins = array();
  1339. $files = glob("addon/*/");
  1340. if($files) {
  1341. foreach($files as $file) {
  1342. if(is_dir($file)) {
  1343. list($tmp, $id)=array_map("trim", explode("/",$file));
  1344. $info = get_plugin_info($id);
  1345. $show_plugin = true;
  1346. // If the addon is unsupported, then only show it, when it is enabled
  1347. if((strtolower($info["status"]) == "unsupported") AND !in_array($id, $a->plugins))
  1348. $show_plugin = false;
  1349. // Override the above szenario, when the admin really wants to see outdated stuff
  1350. if(get_config("system", "show_unsupported_addons"))
  1351. $show_plugin = true;
  1352. if($show_plugin)
  1353. $plugins[] = array($id, (in_array($id, $a->plugins)?"on":"off") , $info);
  1354. }
  1355. }
  1356. }
  1357. $t = get_markup_template("admin_plugins.tpl");
  1358. return replace_macros($t, array(
  1359. '$title' => t('Administration'),
  1360. '$page' => t('Plugins'),
  1361. '$submit' => t('Save Settings'),
  1362. '$reload' => t('Reload active plugins'),
  1363. '$baseurl' => $a->get_baseurl(true),
  1364. '$function' => 'plugins',
  1365. '$plugins' => $plugins,
  1366. '$pcount' => count($plugins),
  1367. '$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'),
  1368. '$form_security_token' => get_form_security_token("admin_themes"),
  1369. ));
  1370. }
  1371. /**
  1372. * @param array $themes
  1373. * @param string $th
  1374. * @param int $result
  1375. */
  1376. function toggle_theme(&$themes,$th,&$result) {
  1377. for($x = 0; $x < count($themes); $x ++) {
  1378. if($themes[$x]['name'] === $th) {
  1379. if($themes[$x]['allowed']) {
  1380. $themes[$x]['allowed'] = 0;
  1381. $result = 0;
  1382. }
  1383. else {
  1384. $themes[$x]['allowed'] = 1;
  1385. $result = 1;
  1386. }
  1387. }
  1388. }
  1389. }
  1390. /**
  1391. * @param array $themes
  1392. * @param string $th
  1393. * @return int
  1394. */
  1395. function theme_status($themes,$th) {
  1396. for($x = 0; $x < count($themes); $x ++) {
  1397. if($themes[$x]['name'] === $th) {
  1398. if($themes[$x]['allowed']) {
  1399. return 1;
  1400. }
  1401. else {
  1402. return 0;
  1403. }
  1404. }
  1405. }
  1406. return 0;
  1407. }
  1408. /**
  1409. * @param array $themes
  1410. * @return string
  1411. */
  1412. function rebuild_theme_table($themes) {
  1413. $o = '';
  1414. if(count($themes)) {
  1415. foreach($themes as $th) {
  1416. if($th['allowed']) {
  1417. if(strlen($o))
  1418. $o .= ',';
  1419. $o .= $th['name'];
  1420. }
  1421. }
  1422. }
  1423. return $o;
  1424. }
  1425. /**
  1426. * @brief Themes admin page
  1427. *
  1428. * This function generates the admin panel page to control the themes available
  1429. * on the friendica node. If the name of a theme is given as parameter a page
  1430. * with the details for the theme is shown. Otherwise a list of available
  1431. * themes is generated.
  1432. *
  1433. * The template used for displaying the list of themes and the details of the
  1434. * themes are the same as used for the plugins.
  1435. *
  1436. * The returned string contains the HTML code of the admin panel page.
  1437. *
  1438. * @param App $a
  1439. * @return string
  1440. */
  1441. function admin_page_themes(&$a){
  1442. $allowed_themes_str = get_config('system','allowed_themes');
  1443. $allowed_themes_raw = explode(',',$allowed_themes_str);
  1444. $allowed_themes = array();
  1445. if(count($allowed_themes_raw))
  1446. foreach($allowed_themes_raw as $x)
  1447. if(strlen(trim($x)))
  1448. $allowed_themes[] = trim($x);
  1449. $themes = array();
  1450. $files = glob('view/theme/*');
  1451. if($files) {
  1452. foreach($files as $file) {
  1453. $f = basename($file);
  1454. $is_experimental = intval(file_exists($file.'/experimental'));
  1455. $is_supported = 1-(intval(file_exists($file.'/unsupported')));
  1456. $is_allowed = intval(in_array($f,$allowed_themes));
  1457. if($is_allowed OR $is_supported OR get_config("system", "show_unsupported_themes"))
  1458. $themes[] = array('name' => $f, 'experimental' => $is_experimental, 'supported' => $is_supported, 'allowed' => $is_allowed);
  1459. }
  1460. }
  1461. if(! count($themes)) {
  1462. notice(t('No themes found.'));
  1463. return '';
  1464. }
  1465. /*
  1466. * Single theme
  1467. */
  1468. if($a->argc == 3) {
  1469. $theme = $a->argv[2];
  1470. if(! is_dir("view/theme/$theme")) {
  1471. notice(t("Item not found."));
  1472. return '';
  1473. }
  1474. if(x($_GET,"a") && $_GET['a']=="t") {
  1475. check_form_security_token_redirectOnErr('/admin/themes', 'admin_themes', 't');
  1476. // Toggle theme status
  1477. toggle_theme($themes,$theme,$result);
  1478. $s = rebuild_theme_table($themes);
  1479. if($result) {
  1480. install_theme($theme);
  1481. info(sprintf('Theme %s enabled.',$theme));
  1482. }
  1483. else {
  1484. uninstall_theme($theme);
  1485. info(sprintf('Theme %s disabled.',$theme));
  1486. }
  1487. set_config('system','allowed_themes',$s);
  1488. goaway('admin/themes');
  1489. return ''; // NOTREACHED
  1490. }
  1491. // display theme details
  1492. require_once('library/markdown.php');
  1493. if(theme_status($themes,$theme)) {
  1494. $status="on"; $action= t("Disable");
  1495. } else {
  1496. $status="off"; $action= t("Enable");
  1497. }
  1498. $readme=Null;
  1499. if(is_file("view/theme/$theme/README.md")) {
  1500. $readme = file_get_contents("view/theme/$theme/README.md");
  1501. $readme = Markdown($readme);
  1502. } elseif(is_file("view/theme/$theme/README")) {
  1503. $readme = "<pre>". file_get_contents("view/theme/$theme/README") ."</pre>";
  1504. }
  1505. $admin_form="";
  1506. if(is_file("view/theme/$theme/config.php")) {
  1507. function __get_theme_admin_form(&$a, $theme) {
  1508. $orig_theme = $a->theme;
  1509. $orig_page = $a->page;
  1510. $orig_session_theme = $_SESSION['theme'];
  1511. require_once("view/theme/$theme/theme.php");
  1512. require_once("view/theme/$theme/config.php");
  1513. $_SESSION['theme'] = $theme;
  1514. $init = $theme."_init";
  1515. if(function_exists($init)) $init($a);
  1516. if(function_exists("theme_admin")) {
  1517. $admin_form = theme_admin($a);
  1518. }
  1519. $_SESSION['theme'] = $orig_session_theme;
  1520. $a->theme = $orig_theme;
  1521. $a->page = $orig_page;
  1522. return $admin_form;
  1523. }
  1524. $admin_form = __get_theme_admin_form($a, $theme);
  1525. }
  1526. $screenshot = array(get_theme_screenshot($theme), t('Screenshot'));
  1527. if(! stristr($screenshot[0],$theme))
  1528. $screenshot = null;
  1529. $t = get_markup_template("admin_plugins_details.tpl");
  1530. return replace_macros($t, array(
  1531. '$title' => t('Administration'),
  1532. '$page' => t('Themes'),
  1533. '$toggle' => t('Toggle'),
  1534. '$settings' => t('Settings'),
  1535. '$baseurl' => $a->get_baseurl(true),
  1536. '$plugin' => $theme,
  1537. '$status' => $status,
  1538. '$action' => $action,
  1539. '$info' => get_theme_info($theme),
  1540. '$function' => 'themes',
  1541. '$admin_form' => $admin_form,
  1542. '$str_author' => t('Author: '),
  1543. '$str_maintainer' => t('Maintainer: '),
  1544. '$screenshot' => $screenshot,
  1545. '$readme' => $readme,
  1546. '$form_security_token' => get_form_security_token("admin_themes"),
  1547. ));
  1548. }
  1549. // reload active themes
  1550. if(x($_GET,"a") && $_GET['a']=="r") {
  1551. check_form_security_token_redirectOnErr($a->get_baseurl().'/admin/themes', 'admin_themes', 't');
  1552. if($themes) {
  1553. foreach($themes as $th) {
  1554. if($th['allowed']) {
  1555. uninstall_theme($th['name']);
  1556. install_theme($th['name']);
  1557. }
  1558. }
  1559. }
  1560. info("Themes reloaded");
  1561. goaway($a->get_baseurl().'/admin/themes');
  1562. }
  1563. /*
  1564. * List themes
  1565. */
  1566. $xthemes = array();
  1567. if($themes) {
  1568. foreach($themes as $th) {
  1569. $xthemes[] = array($th['name'],(($th['allowed']) ? "on" : "off"), get_theme_info($th['name']));
  1570. }
  1571. }
  1572. $t = get_markup_template("admin_plugins.tpl");
  1573. return replace_macros($t, array(
  1574. '$title' => t('Administration'),
  1575. '$page' => t('Themes'),
  1576. '$submit' => t('Save Settings'),
  1577. '$reload' => t('Reload active themes'),
  1578. '$baseurl' => $a->get_baseurl(true),
  1579. '$function' => 'themes',
  1580. '$plugins' => $xthemes,
  1581. '$pcount' => count($themes),
  1582. '$noplugshint' => sprintf(t('No themes found on the system. They should be paced in %1$s'),'<code>/view/themes</code>'),
  1583. '$experimental' => t('[Experimental]'),
  1584. '$unsupported' => t('[Unsupported]'),
  1585. '$form_security_token' => get_form_security_token("admin_themes"),
  1586. ));
  1587. }
  1588. /**
  1589. * @brief Prosesses data send by Logs admin page
  1590. *
  1591. * @param App $a
  1592. */
  1593. function admin_page_logs_post(&$a) {
  1594. if(x($_POST,"page_logs")) {
  1595. check_form_security_token_redirectOnErr('/admin/logs', 'admin_logs');
  1596. $logfile = ((x($_POST,'logfile')) ? notags(trim($_POST['logfile'])) : '');
  1597. $debugging = ((x($_POST,'debugging')) ? true : false);
  1598. $loglevel = ((x($_POST,'loglevel')) ? intval(trim($_POST['loglevel'])) : 0);
  1599. set_config('system','logfile', $logfile);
  1600. set_config('system','debugging', $debugging);
  1601. set_config('system','loglevel', $loglevel);
  1602. }
  1603. info(t("Log settings updated."));
  1604. goaway('admin/logs');
  1605. return; // NOTREACHED
  1606. }
  1607. /**
  1608. * @brief Generates admin panel subpage for configuration of the logs
  1609. *
  1610. * This function take the view/templates/admin_logs.tpl file and generates a
  1611. * page where admin can configure the logging of friendica.
  1612. *
  1613. * Displaying the log is separated from the log config as the logfile can get
  1614. * big depending on the settings and changing settings regarding the logs can
  1615. * thus waste bandwidth.
  1616. *
  1617. * The string returned contains the content of the template file with replaced
  1618. * macros.
  1619. *
  1620. * @param App $a
  1621. * @return string
  1622. */
  1623. function admin_page_logs(&$a){
  1624. $log_choices = array(
  1625. LOGGER_NORMAL => 'Normal',
  1626. LOGGER_TRACE => 'Trace',
  1627. LOGGER_DEBUG => 'Debug',
  1628. LOGGER_DATA => 'Data',
  1629. LOGGER_ALL => 'All'
  1630. );
  1631. if (ini_get('log_errors')) {
  1632. $phplogenabled = t('PHP log currently enabled.');
  1633. } else {
  1634. $phplogenabled = t('PHP log currently disabled.');
  1635. }
  1636. $t = get_markup_template("admin_logs.tpl");
  1637. return replace_macros($t, array(
  1638. '$title' => t('Administration'),
  1639. '$page' => t('Logs'),
  1640. '$submit' => t('Save Settings'),
  1641. '$clear' => t('Clear'),
  1642. '$baseurl' => $a->get_baseurl(true),
  1643. '$logname' => get_config('system','logfile'),
  1644. // name, label, value, help string, extra data...
  1645. '$debugging' => array('debugging', t("Enable Debugging"),get_config('system','debugging'), ""),
  1646. '$logfile' => array('logfile', t("Log file"), get_config('system','logfile'), t("Must be writable by web server. Relative to your Friendica top-level directory.")),
  1647. '$loglevel' => array('loglevel', t("Log level"), get_config('system','loglevel'), "", $log_choices),
  1648. '$form_security_token' => get_form_security_token("admin_logs"),
  1649. '$phpheader' => t("PHP logging"),
  1650. '$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."),
  1651. '$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');",
  1652. '$phplogenabled' => $phplogenabled,
  1653. ));
  1654. }
  1655. /**
  1656. * @brief Generates admin panel subpage to view the Friendica log
  1657. *
  1658. * This function loads the template view/templates/admin_viewlogs.tpl to
  1659. * display the systemlog content. The filename for the systemlog of friendica
  1660. * is relative to the base directory and taken from the config entry 'logfile'
  1661. * in the 'system' category.
  1662. *
  1663. * Displaying the log is separated from the log config as the logfile can get
  1664. * big depending on the settings and changing settings regarding the logs can
  1665. * thus waste bandwidth.
  1666. *
  1667. * The string returned contains the content of the template file with replaced
  1668. * macros.
  1669. *
  1670. * @param App $a
  1671. * @return string
  1672. */
  1673. function admin_page_viewlogs(&$a){
  1674. $t = get_markup_template("admin_viewlogs.tpl");
  1675. $f = get_config('system','logfile');
  1676. $data = '';
  1677. if(!file_exists($f)) {
  1678. $data = t("Error trying to open <strong>$f</strong> log file.\r\n<br/>Check to see if file $f exist and is readable.");
  1679. }
  1680. else {
  1681. $fp = fopen($f, 'r');
  1682. if(!$fp) {
  1683. $data = t("Couldn't open <strong>$f</strong> log file.\r\n<br/>Check to see if file $f is readable.");
  1684. }
  1685. else {
  1686. $fstat = fstat($fp);
  1687. $size = $fstat['size'];
  1688. if($size != 0) {
  1689. if($size > 5000000 || $size < 0)
  1690. $size = 5000000;
  1691. $seek = fseek($fp,0-$size,SEEK_END);
  1692. if($seek === 0) {
  1693. $data = escape_tags(fread($fp,$size));
  1694. while(! feof($fp))
  1695. $data .= escape_tags(fread($fp,4096));
  1696. }
  1697. }
  1698. fclose($fp);
  1699. }
  1700. }
  1701. return replace_macros($t, array(
  1702. '$title' => t('Administration'),
  1703. '$page' => t('View Logs'),
  1704. '$data' => $data,
  1705. '$logname' => get_config('system','logfile')
  1706. ));
  1707. }
  1708. /**
  1709. * @brief Prosesses data send by the features admin page
  1710. *
  1711. * @param App $a
  1712. */
  1713. function admin_page_features_post(&$a) {
  1714. check_form_security_token_redirectOnErr('/admin/features', 'admin_manage_features');
  1715. logger('postvars: '.print_r($_POST,true),LOGGER_DATA);
  1716. $arr = array();
  1717. $features = get_features(false);
  1718. foreach($features as $fname => $fdata) {
  1719. foreach(array_slice($fdata,1) as $f) {
  1720. $feature = $f[0];
  1721. $feature_state = 'feature_'.$feature;
  1722. $featurelock = 'featurelock_'.$feature;
  1723. if(x($_POST[$feature_state]))
  1724. $val = intval($_POST['feature_'.$feature]);
  1725. else
  1726. $val = 0;
  1727. set_config('feature',$feature,$val);
  1728. if(x($_POST[$featurelock]))
  1729. set_config('feature_lock',$feature,$val);
  1730. else
  1731. del_config('feature_lock',$feature);
  1732. }
  1733. }
  1734. goaway('admin/features');
  1735. return; // NOTREACHED
  1736. }
  1737. /**
  1738. * @brief Subpage for global additional feature management
  1739. *
  1740. * This functin generates the subpage 'Manage Additional Features'
  1741. * for the admin panel. At this page the admin can set preferences
  1742. * for the user settings of the 'additional features'. If needed this
  1743. * preferences can be locked through the admin.
  1744. *
  1745. * The returned string contains the HTML code of the subpage 'Manage
  1746. * Additional Features'
  1747. *
  1748. * @param App $a
  1749. * @return string
  1750. */
  1751. function admin_page_features(&$a) {
  1752. if((argc() > 1) && (argv(1) === 'features')) {
  1753. $arr = array();
  1754. $features = get_features(false);
  1755. foreach($features as $fname => $fdata) {
  1756. $arr[$fname] = array();
  1757. $arr[$fname][0] = $fdata[0];
  1758. foreach(array_slice($fdata,1) as $f) {
  1759. $set = get_config('feature',$f[0]);
  1760. if($set === false)
  1761. $set = $f[3];
  1762. $arr[$fname][1][] = array(
  1763. array('feature_' .$f[0],$f[1],$set,$f[2],array(t('Off'),t('On'))),
  1764. array('featurelock_' .$f[0],sprintf(t('Lock feature %s'),$f[1]),(($f[4] !== false) ? "1" : ''),'',array(t('Off'),t('On')))
  1765. );
  1766. }
  1767. }
  1768. $tpl = get_markup_template("admin_settings_features.tpl");
  1769. $o .= replace_macros($tpl, array(
  1770. '$form_security_token' => get_form_security_token("admin_manage_features"),
  1771. '$title' => t('Manage Additional Features'),
  1772. '$features' => $arr,
  1773. '$submit' => t('Save Settings'),
  1774. ));
  1775. return $o;
  1776. }
  1777. }