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.
 
 
 
 
 
 

1883 lines
74 KiB

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