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.
 
 
 
 
 
 

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