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.
 
 
 
 
 
 

1400 lines
51 KiB

  1. <?php
  2. /**
  3. * Friendica admin
  4. */
  5. require_once("include/remoteupdate.php");
  6. /**
  7. * @param App $a
  8. */
  9. function admin_post(&$a){
  10. if(!is_site_admin()) {
  11. return;
  12. }
  13. // do not allow a page manager to access the admin panel at all.
  14. if(x($_SESSION,'submanage') && intval($_SESSION['submanage']))
  15. return;
  16. // urls
  17. if ($a->argc > 1){
  18. switch ($a->argv[1]){
  19. case 'site':
  20. admin_page_site_post($a);
  21. break;
  22. case 'users':
  23. admin_page_users_post($a);
  24. break;
  25. case 'plugins':
  26. if ($a->argc > 2 &&
  27. is_file("addon/".$a->argv[2]."/".$a->argv[2].".php")){
  28. @include_once("addon/".$a->argv[2]."/".$a->argv[2].".php");
  29. if(function_exists($a->argv[2].'_plugin_admin_post')) {
  30. $func = $a->argv[2].'_plugin_admin_post';
  31. $func($a);
  32. }
  33. }
  34. goaway($a->get_baseurl(true) . '/admin/plugins/' . $a->argv[2] );
  35. return; // NOTREACHED
  36. break;
  37. case 'themes':
  38. $theme = $a->argv[2];
  39. if (is_file("view/theme/$theme/config.php")){
  40. require_once("view/theme/$theme/config.php");
  41. if (function_exists("theme_admin_post")){
  42. theme_admin_post($a);
  43. }
  44. }
  45. info(t('Theme settings updated.'));
  46. if(is_ajax()) return;
  47. goaway($a->get_baseurl(true) . '/admin/themes/' . $theme );
  48. return;
  49. break;
  50. case 'logs':
  51. admin_page_logs_post($a);
  52. break;
  53. case 'dbsync':
  54. admin_page_dbsync_post($a);
  55. break;
  56. case 'update':
  57. admin_page_remoteupdate_post($a);
  58. break;
  59. }
  60. }
  61. goaway($a->get_baseurl(true) . '/admin' );
  62. return; // NOTREACHED
  63. }
  64. /**
  65. * @param App $a
  66. * @return string
  67. */
  68. function admin_content(&$a) {
  69. if(!is_site_admin()) {
  70. return login(false);
  71. }
  72. if(x($_SESSION,'submanage') && intval($_SESSION['submanage']))
  73. return "";
  74. if (function_exists("apc_delete")) {
  75. $toDelete = new APCIterator('user', APC_ITER_VALUE);
  76. apc_delete($toDelete);
  77. }
  78. /**
  79. * Side bar links
  80. */
  81. // array( url, name, extra css classes )
  82. $aside = Array(
  83. 'site' => Array($a->get_baseurl(true)."/admin/site/", t("Site") , "site"),
  84. 'users' => Array($a->get_baseurl(true)."/admin/users/", t("Users") , "users"),
  85. 'plugins'=> Array($a->get_baseurl(true)."/admin/plugins/", t("Plugins") , "plugins"),
  86. 'themes' => Array($a->get_baseurl(true)."/admin/themes/", t("Themes") , "themes"),
  87. 'dbsync' => Array($a->get_baseurl(true)."/admin/dbsync/", t('DB updates'), "dbsync"),
  88. //'update' => Array($a->get_baseurl(true)."/admin/update/", t("Software Update") , "update")
  89. );
  90. /* get plugins admin page */
  91. $r = q("SELECT name FROM `addon` WHERE `plugin_admin`=1");
  92. $aside['plugins_admin']=Array();
  93. foreach ($r as $h){
  94. $plugin =$h['name'];
  95. $aside['plugins_admin'][] = Array($a->get_baseurl(true)."/admin/plugins/".$plugin, $plugin, "plugin");
  96. // temp plugins with admin
  97. $a->plugins_admin[] = $plugin;
  98. }
  99. $aside['logs'] = Array($a->get_baseurl(true)."/admin/logs/", t("Logs"), "logs");
  100. $t = get_markup_template("admin_aside.tpl");
  101. $a->page['aside'] .= replace_macros( $t, array(
  102. '$admin' => $aside,
  103. '$admtxt' => t('Admin'),
  104. '$plugadmtxt' => t('Plugin Features'),
  105. '$logtxt' => t('Logs'),
  106. '$h_pending' => t('User registrations waiting for confirmation'),
  107. '$admurl'=> $a->get_baseurl(true)."/admin/"
  108. ));
  109. /**
  110. * Page content
  111. */
  112. $o = '';
  113. // urls
  114. if ($a->argc > 1){
  115. switch ($a->argv[1]){
  116. case 'site':
  117. $o = admin_page_site($a);
  118. break;
  119. case 'users':
  120. $o = admin_page_users($a);
  121. break;
  122. case 'plugins':
  123. $o = admin_page_plugins($a);
  124. break;
  125. case 'themes':
  126. $o = admin_page_themes($a);
  127. break;
  128. case 'logs':
  129. $o = admin_page_logs($a);
  130. break;
  131. case 'dbsync':
  132. $o = admin_page_dbsync($a);
  133. break;
  134. case 'update':
  135. $o = admin_page_remoteupdate($a);
  136. break;
  137. default:
  138. notice( t("Item not found.") );
  139. }
  140. } else {
  141. $o = admin_page_summary($a);
  142. }
  143. if(is_ajax()) {
  144. echo $o;
  145. killme();
  146. return '';
  147. } else {
  148. return $o;
  149. }
  150. }
  151. /**
  152. * Admin Summary Page
  153. * @param App $a
  154. * @return string
  155. */
  156. function admin_page_summary(&$a) {
  157. $r = q("SELECT `page-flags`, COUNT(uid) as `count` FROM `user` GROUP BY `page-flags`");
  158. $accounts = Array(
  159. Array( t('Normal Account'), 0),
  160. Array( t('Soapbox Account'), 0),
  161. Array( t('Community/Celebrity Account'), 0),
  162. Array( t('Automatic Friend Account'), 0),
  163. Array( t('Blog Account'), 0),
  164. Array( t('Private Forum'), 0)
  165. );
  166. $users=0;
  167. foreach ($r as $u){ $accounts[$u['page-flags']][1] = $u['count']; $users+= $u['count']; }
  168. logger('accounts: ' . print_r($accounts,true),LOGGER_DATA);
  169. $r = q("SELECT COUNT(id) as `count` FROM `register`");
  170. $pending = $r[0]['count'];
  171. $r = q("select count(*) as total from deliverq where 1");
  172. $deliverq = (($r) ? $r[0]['total'] : 0);
  173. $r = q("select count(*) as total from queue where 1");
  174. $queue = (($r) ? $r[0]['total'] : 0);
  175. // We can do better, but this is a quick queue status
  176. $queues = array( 'label' => t('Message queues'), 'deliverq' => $deliverq, 'queue' => $queue );
  177. $t = get_markup_template("admin_summary.tpl");
  178. return replace_macros($t, array(
  179. '$title' => t('Administration'),
  180. '$page' => t('Summary'),
  181. '$queues' => $queues,
  182. '$users' => Array( t('Registered users'), $users),
  183. '$accounts' => $accounts,
  184. '$pending' => Array( t('Pending registrations'), $pending),
  185. '$version' => Array( t('Version'), FRIENDICA_VERSION),
  186. '$build' => get_config('system','build'),
  187. '$plugins' => Array( t('Active plugins'), $a->plugins )
  188. ));
  189. }
  190. /**
  191. * Admin Site Page
  192. * @param App $a
  193. */
  194. function admin_page_site_post(&$a){
  195. if (!x($_POST,"page_site")){
  196. return;
  197. }
  198. check_form_security_token_redirectOnErr('/admin/site', 'admin_site');
  199. // relocate
  200. if (x($_POST,'relocate') && x($_POST,'relocate_url') && $_POST['relocate_url']!=""){
  201. $new_url = $_POST['relocate_url'];
  202. $new_url = rtrim($new_url,"/");
  203. $parsed = @parse_url($new_url);
  204. if (!$parsed || (!x($parsed,'host') || !x($parsed,'scheme'))) {
  205. notice(t("Can not parse base url. Must have at least <scheme>://<domain>"));
  206. goaway($a->get_baseurl(true) . '/admin/site' );
  207. }
  208. /* steps:
  209. * replace all "baseurl" to "new_url" in config, profile, term, items and contacts
  210. * send relocate for every local user
  211. * */
  212. $old_url = $a->get_baseurl(true);
  213. function update_table($table_name, $fields, $old_url, $new_url) {
  214. global $db, $a;
  215. $dbold = dbesc($old_url);
  216. $dbnew = dbesc($new_url);
  217. $upd = array();
  218. foreach ($fields as $f) {
  219. $upd[] = "`$f` = REPLACE(`$f`, '$dbold', '$dbnew')";
  220. }
  221. $upds = implode(", ", $upd);
  222. $q = sprintf("UPDATE %s SET %s;", $table_name, $upds);
  223. $r = q($q);
  224. if (!$r) {
  225. notice( "Falied updating '$table_name': " . $db->error );
  226. goaway($a->get_baseurl(true) . '/admin/site' );
  227. }
  228. }
  229. // update tables
  230. update_table("profile", array('photo', 'thumb'), $old_url, $new_url);
  231. update_table("term", array('url'), $old_url, $new_url);
  232. update_table("contact", array('photo','thumb','micro','url','nurl','request','notify','poll','confirm','poco'), $old_url, $new_url);
  233. update_table("item", array('owner-link','owner-avatar','author-name','author-link','author-avatar','body','plink','tag'), $old_url, $new_url);
  234. // update config
  235. $a->set_baseurl($new_url);
  236. set_config('system','url',$new_url);
  237. // send relocate
  238. $users = q("SELECT uid FROM user WHERE account_removed = 0 AND account_expired = 0");
  239. foreach ($users as $user) {
  240. proc_run('php', 'include/notifier.php', 'relocate', $user['uid']);
  241. }
  242. info("Relocation started. Could take a while to complete.");
  243. goaway($a->get_baseurl(true) . '/admin/site' );
  244. }
  245. // end relocate
  246. $sitename = ((x($_POST,'sitename')) ? notags(trim($_POST['sitename'])) : '');
  247. $banner = ((x($_POST,'banner')) ? trim($_POST['banner']) : false);
  248. $info = ((x($_POST,'info')) ? trim($_POST['info']) : false);
  249. $language = ((x($_POST,'language')) ? notags(trim($_POST['language'])) : '');
  250. $theme = ((x($_POST,'theme')) ? notags(trim($_POST['theme'])) : '');
  251. $theme_mobile = ((x($_POST,'theme_mobile')) ? notags(trim($_POST['theme_mobile'])) : '');
  252. $maximagesize = ((x($_POST,'maximagesize')) ? intval(trim($_POST['maximagesize'])) : 0);
  253. $maximagelength = ((x($_POST,'maximagelength')) ? intval(trim($_POST['maximagelength'])) : MAX_IMAGE_LENGTH);
  254. $jpegimagequality = ((x($_POST,'jpegimagequality')) ? intval(trim($_POST['jpegimagequality'])) : JPEG_QUALITY);
  255. $register_policy = ((x($_POST,'register_policy')) ? intval(trim($_POST['register_policy'])) : 0);
  256. $daily_registrations = ((x($_POST,'max_daily_registrations')) ? intval(trim($_POST['max_daily_registrations'])) :0);
  257. $abandon_days = ((x($_POST,'abandon_days')) ? intval(trim($_POST['abandon_days'])) : 0);
  258. $register_text = ((x($_POST,'register_text')) ? notags(trim($_POST['register_text'])) : '');
  259. $allowed_sites = ((x($_POST,'allowed_sites')) ? notags(trim($_POST['allowed_sites'])) : '');
  260. $allowed_email = ((x($_POST,'allowed_email')) ? notags(trim($_POST['allowed_email'])) : '');
  261. $block_public = ((x($_POST,'block_public')) ? True : False);
  262. $force_publish = ((x($_POST,'publish_all')) ? True : False);
  263. $global_directory = ((x($_POST,'directory_submit_url')) ? notags(trim($_POST['directory_submit_url'])) : '');
  264. $thread_allow = ((x($_POST,'thread_allow')) ? True : False);
  265. $newuser_private = ((x($_POST,'newuser_private')) ? True : False);
  266. $enotify_no_content = ((x($_POST,'enotify_no_content')) ? True : False);
  267. $private_addons = ((x($_POST,'private_addons')) ? True : False);
  268. $disable_embedded = ((x($_POST,'disable_embedded')) ? True : False);
  269. $no_multi_reg = ((x($_POST,'no_multi_reg')) ? True : False);
  270. $no_openid = !((x($_POST,'no_openid')) ? True : False);
  271. $no_regfullname = !((x($_POST,'no_regfullname')) ? True : False);
  272. $no_utf = !((x($_POST,'no_utf')) ? True : False);
  273. $no_community_page = !((x($_POST,'no_community_page')) ? True : False);
  274. $verifyssl = ((x($_POST,'verifyssl')) ? True : False);
  275. $proxyuser = ((x($_POST,'proxyuser')) ? notags(trim($_POST['proxyuser'])) : '');
  276. $proxy = ((x($_POST,'proxy')) ? notags(trim($_POST['proxy'])) : '');
  277. $timeout = ((x($_POST,'timeout')) ? intval(trim($_POST['timeout'])) : 60);
  278. $delivery_interval = ((x($_POST,'delivery_interval')) ? intval(trim($_POST['delivery_interval'])) : 0);
  279. $poll_interval = ((x($_POST,'poll_interval')) ? intval(trim($_POST['poll_interval'])) : 0);
  280. $maxloadavg = ((x($_POST,'maxloadavg')) ? intval(trim($_POST['maxloadavg'])) : 50);
  281. $dfrn_only = ((x($_POST,'dfrn_only')) ? True : False);
  282. $ostatus_disabled = !((x($_POST,'ostatus_disabled')) ? True : False);
  283. $ostatus_poll_interval = ((x($_POST,'ostatus_poll_interval')) ? intval(trim($_POST['ostatus_poll_interval'])) : 0);
  284. $diaspora_enabled = ((x($_POST,'diaspora_enabled')) ? True : False);
  285. $ssl_policy = ((x($_POST,'ssl_policy')) ? intval($_POST['ssl_policy']) : 0);
  286. $old_share = ((x($_POST,'old_share')) ? True : False);
  287. $hide_help = ((x($_POST,'hide_help')) ? True : False);
  288. $suppress_language = ((x($_POST,'suppress_language')) ? True : False);
  289. $use_fulltext_engine = ((x($_POST,'use_fulltext_engine')) ? True : False);
  290. $itemcache = ((x($_POST,'itemcache')) ? notags(trim($_POST['itemcache'])) : '');
  291. $itemcache_duration = ((x($_POST,'itemcache_duration')) ? intval($_POST['itemcache_duration']) : 0);
  292. $lockpath = ((x($_POST,'lockpath')) ? notags(trim($_POST['lockpath'])) : '');
  293. $temppath = ((x($_POST,'temppath')) ? notags(trim($_POST['temppath'])) : '');
  294. $basepath = ((x($_POST,'basepath')) ? notags(trim($_POST['basepath'])) : '');
  295. $singleuser = ((x($_POST,'singleuser')) ? notags(trim($_POST['singleuser'])) : '');
  296. if($ssl_policy != intval(get_config('system','ssl_policy'))) {
  297. if($ssl_policy == SSL_POLICY_FULL) {
  298. q("update `contact` set
  299. `url` = replace(`url` , 'http:' , 'https:'),
  300. `photo` = replace(`photo` , 'http:' , 'https:'),
  301. `thumb` = replace(`thumb` , 'http:' , 'https:'),
  302. `micro` = replace(`micro` , 'http:' , 'https:'),
  303. `request` = replace(`request`, 'http:' , 'https:'),
  304. `notify` = replace(`notify` , 'http:' , 'https:'),
  305. `poll` = replace(`poll` , 'http:' , 'https:'),
  306. `confirm` = replace(`confirm`, 'http:' , 'https:'),
  307. `poco` = replace(`poco` , 'http:' , 'https:')
  308. where `self` = 1"
  309. );
  310. q("update `profile` set
  311. `photo` = replace(`photo` , 'http:' , 'https:'),
  312. `thumb` = replace(`thumb` , 'http:' , 'https:')
  313. where 1 "
  314. );
  315. }
  316. elseif($ssl_policy == SSL_POLICY_SELFSIGN) {
  317. q("update `contact` set
  318. `url` = replace(`url` , 'https:' , 'http:'),
  319. `photo` = replace(`photo` , 'https:' , 'http:'),
  320. `thumb` = replace(`thumb` , 'https:' , 'http:'),
  321. `micro` = replace(`micro` , 'https:' , 'http:'),
  322. `request` = replace(`request`, 'https:' , 'http:'),
  323. `notify` = replace(`notify` , 'https:' , 'http:'),
  324. `poll` = replace(`poll` , 'https:' , 'http:'),
  325. `confirm` = replace(`confirm`, 'https:' , 'http:'),
  326. `poco` = replace(`poco` , 'https:' , 'http:')
  327. where `self` = 1"
  328. );
  329. q("update `profile` set
  330. `photo` = replace(`photo` , 'https:' , 'http:'),
  331. `thumb` = replace(`thumb` , 'https:' , 'http:')
  332. where 1 "
  333. );
  334. }
  335. }
  336. set_config('system','ssl_policy',$ssl_policy);
  337. set_config('system','delivery_interval',$delivery_interval);
  338. set_config('system','poll_interval',$poll_interval);
  339. set_config('system','maxloadavg',$maxloadavg);
  340. set_config('config','sitename',$sitename);
  341. if ($banner==""){
  342. // don't know why, but del_config doesn't work...
  343. q("DELETE FROM `config` WHERE `cat` = '%s' AND `k` = '%s' LIMIT 1",
  344. dbesc("system"),
  345. dbesc("banner")
  346. );
  347. } else {
  348. set_config('system','banner', $banner);
  349. }
  350. if ($info=="") {
  351. del_config('config','info');
  352. } else {
  353. set_config('config','info',$info);
  354. }
  355. set_config('system','language', $language);
  356. set_config('system','theme', $theme);
  357. if ( $theme_mobile === '---' ) {
  358. del_config('system','mobile-theme');
  359. } else {
  360. set_config('system','mobile-theme', $theme_mobile);
  361. }
  362. if ( $singleuser === '---' ) {
  363. del_config('system','singleuser');
  364. } else {
  365. set_config('system','singleuser', $singleuser);
  366. }
  367. set_config('system','maximagesize', $maximagesize);
  368. set_config('system','max_image_length', $maximagelength);
  369. set_config('system','jpeg_quality', $jpegimagequality);
  370. set_config('config','register_policy', $register_policy);
  371. set_config('system','max_daily_registrations', $daily_registrations);
  372. set_config('system','account_abandon_days', $abandon_days);
  373. set_config('config','register_text', $register_text);
  374. set_config('system','allowed_sites', $allowed_sites);
  375. set_config('system','allowed_email', $allowed_email);
  376. set_config('system','block_public', $block_public);
  377. set_config('system','publish_all', $force_publish);
  378. if ($global_directory==""){
  379. // don't know why, but del_config doesn't work...
  380. q("DELETE FROM `config` WHERE `cat` = '%s' AND `k` = '%s' LIMIT 1",
  381. dbesc("system"),
  382. dbesc("directory_submit_url")
  383. );
  384. } else {
  385. set_config('system','directory_submit_url', $global_directory);
  386. }
  387. set_config('system','thread_allow', $thread_allow);
  388. set_config('system','newuser_private', $newuser_private);
  389. set_config('system','enotify_no_content', $enotify_no_content);
  390. set_config('system','disable_embedded', $disable_embedded);
  391. set_config('system','block_extended_register', $no_multi_reg);
  392. set_config('system','no_openid', $no_openid);
  393. set_config('system','no_regfullname', $no_regfullname);
  394. set_config('system','no_community_page', $no_community_page);
  395. set_config('system','no_utf', $no_utf);
  396. set_config('system','verifyssl', $verifyssl);
  397. set_config('system','proxyuser', $proxyuser);
  398. set_config('system','proxy', $proxy);
  399. set_config('system','curl_timeout', $timeout);
  400. set_config('system','dfrn_only', $dfrn_only);
  401. set_config('system','ostatus_disabled', $ostatus_disabled);
  402. set_config('system','ostatus_poll_interval', $ostatus_poll_interval);
  403. set_config('system','diaspora_enabled', $diaspora_enabled);
  404. set_config('config','private_addons', $private_addons);
  405. set_config('system','old_share', $old_share);
  406. set_config('system','hide_help', $hide_help);
  407. set_config('system','use_fulltext_engine', $use_fulltext_engine);
  408. set_config('system','itemcache', $itemcache);
  409. set_config('system','itemcache_duration', $itemcache_duration);
  410. set_config('system','lockpath', $lockpath);
  411. set_config('system','temppath', $temppath);
  412. set_config('system','basepath', $basepath);
  413. info( t('Site settings updated.') . EOL);
  414. goaway($a->get_baseurl(true) . '/admin/site' );
  415. return; // NOTREACHED
  416. }
  417. /**
  418. * @param App $a
  419. * @return string
  420. */
  421. function admin_page_site(&$a) {
  422. /* Installed langs */
  423. $lang_choices = array();
  424. $langs = glob('view/*/strings.php');
  425. if(is_array($langs) && count($langs)) {
  426. if(! in_array('view/en/strings.php',$langs))
  427. $langs[] = 'view/en/';
  428. asort($langs);
  429. foreach($langs as $l) {
  430. $t = explode("/",$l);
  431. $lang_choices[$t[1]] = $t[1];
  432. }
  433. }
  434. /* Installed themes */
  435. $theme_choices = array();
  436. $theme_choices_mobile = array();
  437. $theme_choices_mobile["---"] = t("No special theme for mobile devices");
  438. $files = glob('view/theme/*');
  439. if($files) {
  440. foreach($files as $file) {
  441. $f = basename($file);
  442. $theme_name = ((file_exists($file . '/experimental')) ? sprintf("%s - \x28Experimental\x29", $f) : $f);
  443. if (file_exists($file . '/mobile')) {
  444. $theme_choices_mobile[$f] = $theme_name;
  445. }
  446. else {
  447. $theme_choices[$f] = $theme_name;
  448. }
  449. }
  450. }
  451. /* OStatus conversation poll choices */
  452. $ostatus_poll_choices = array(
  453. "-1" => t("Never"),
  454. "0" => t("Frequently"),
  455. "60" => t("Hourly"),
  456. "720" => t("Twice daily"),
  457. "1440" => t("Daily")
  458. );
  459. /* get user names to make the install a personal install of X */
  460. $user_names = array();
  461. $user_names['---'] = t('Multi user instance');
  462. $users = q("SELECT username, nickname FROM `user`");
  463. foreach ($users as $user) {
  464. $user_names[$user['nickname']] = $user['username'];
  465. }
  466. /* Banner */
  467. $banner = get_config('system','banner');
  468. if($banner == false)
  469. $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>';
  470. $banner = htmlspecialchars($banner);
  471. $info = get_config('config','info');
  472. $info = htmlspecialchars($info);
  473. //echo "<pre>"; var_dump($lang_choices); die("</pre>");
  474. /* Register policy */
  475. $register_choices = Array(
  476. REGISTER_CLOSED => t("Closed"),
  477. REGISTER_APPROVE => t("Requires approval"),
  478. REGISTER_OPEN => t("Open")
  479. );
  480. $ssl_choices = array(
  481. SSL_POLICY_NONE => t("No SSL policy, links will track page SSL state"),
  482. SSL_POLICY_FULL => t("Force all links to use SSL"),
  483. SSL_POLICY_SELFSIGN => t("Self-signed certificate, use SSL for local links only (discouraged)")
  484. );
  485. $t = get_markup_template("admin_site.tpl");
  486. return replace_macros($t, array(
  487. '$title' => t('Administration'),
  488. '$page' => t('Site'),
  489. '$submit' => t('Save Settings'),
  490. '$registration' => t('Registration'),
  491. '$upload' => t('File upload'),
  492. '$corporate' => t('Policies'),
  493. '$advanced' => t('Advanced'),
  494. '$performance' => t('Performance'),
  495. '$relocate'=> t('Relocate - WARNING: advanced function. Could make this server unreachable.'),
  496. '$baseurl' => $a->get_baseurl(true),
  497. // name, label, value, help string, extra data...
  498. '$sitename' => array('sitename', t("Site name"), htmlentities($a->config['sitename'], ENT_QUOTES), 'UTF-8'),
  499. '$banner' => array('banner', t("Banner/Logo"), $banner, ""),
  500. '$info' => array('info',t('Additional Info'), $info, t('For public servers: you can add additional information here that will be listed at dir.friendica.com/siteinfo.')),
  501. '$language' => array('language', t("System language"), get_config('system','language'), "", $lang_choices),
  502. '$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),
  503. '$theme_mobile' => array('theme_mobile', t("Mobile system theme"), get_config('system','mobile-theme'), t("Theme for mobile devices"), $theme_choices_mobile),
  504. '$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),
  505. '$old_share' => array('old_share', t("Old style 'Share'"), get_config('system','old_share'), t("Deactivates the bbcode element 'share' for repeating items.")),
  506. '$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.")),
  507. '$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),
  508. '$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.")),
  509. '$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.")),
  510. '$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.")),
  511. '$register_policy' => array('register_policy', t("Register policy"), $a->config['register_policy'], "", $register_choices),
  512. '$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.")),
  513. '$register_text' => array('register_text', t("Register text"), htmlentities($a->config['register_text'], ENT_QUOTES, 'UTF-8'), t("Will be displayed prominently on the registration page.")),
  514. '$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.')),
  515. '$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")),
  516. '$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")),
  517. '$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.")),
  518. '$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.")),
  519. '$global_directory' => array('directory_submit_url', t("Global directory update URL"), get_config('system','directory_submit_url'), t("URL to update the global directory. If this is not set, the global directory is completely unavailable to the application.")),
  520. '$thread_allow' => array('thread_allow', t("Allow threaded items"), get_config('system','thread_allow'), t("Allow infinite level threading for items on this site.")),
  521. '$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.")),
  522. '$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.")),
  523. '$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.")),
  524. '$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.")),
  525. '$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.")),
  526. '$no_openid' => array('no_openid', t("OpenID support"), !get_config('system','no_openid'), t("OpenID support for registration and logins.")),
  527. '$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")),
  528. '$no_utf' => array('no_utf', t("UTF-8 Regular expressions"), !get_config('system','no_utf'), t("Use PHP UTF8 regular expressions")),
  529. '$no_community_page' => array('no_community_page', t("Show Community Page"), !get_config('system','no_community_page'), t("Display a Community page showing all recent public postings on this site.")),
  530. '$ostatus_disabled' => array('ostatus_disabled', t("Enable OStatus support"), !get_config('system','ostatus_disabled'), t("Provide built-in OStatus \x28identi.ca, status.net, etc.\x29 compatibility. All communications in OStatus are public, so privacy warnings will be occasionally displayed.")),
  531. '$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),
  532. '$diaspora_enabled' => array('diaspora_enabled', t("Enable Diaspora support"), get_config('system','diaspora_enabled'), t("Provide built-in Diaspora network compatibility.")),
  533. '$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.")),
  534. '$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.")),
  535. '$proxyuser' => array('proxyuser', t("Proxy user"), get_config('system','proxyuser'), ""),
  536. '$proxy' => array('proxy', t("Proxy URL"), get_config('system','proxy'), ""),
  537. '$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).")),
  538. '$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.")),
  539. '$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.")),
  540. '$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.")),
  541. '$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.")),
  542. '$suppress_language' => array('suppress_language', t("Suppress Language"), get_config('system','suppress_language'), t("Suppress language information in meta information about a posting.")),
  543. '$itemcache' => array('itemcache', t("Path to item cache"), get_config('system','itemcache'), "The item caches buffers generated bbcode and external images."),
  544. '$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).")),
  545. '$lockpath' => array('lockpath', t("Path for lock file"), get_config('system','lockpath'), "The lock file is used to avoid multiple pollers at one time. Only define a folder here."),
  546. '$temppath' => array('temppath', t("Temp path"), get_config('system','temppath'), "If you have a restricted system where the webserver can't access the system temp path, enter another path here."),
  547. '$basepath' => array('basepath', t("Base path to installation"), get_config('system','basepath'), "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."),
  548. '$relocate_url' => array('relocate_url', t("New base url"), $a->get_baseurl(), "Change base url for this server. Sends relocate message to all DFRN contacts of all users."),
  549. '$form_security_token' => get_form_security_token("admin_site"),
  550. ));
  551. }
  552. function admin_page_dbsync(&$a) {
  553. $o = '';
  554. if($a->argc > 3 && intval($a->argv[3]) && $a->argv[2] === 'mark') {
  555. set_config('database', 'update_' . intval($a->argv[3]), 'success');
  556. $curr = get_config('system','build');
  557. if(intval($curr) == intval($a->argv[3]))
  558. set_config('system','build',intval($curr) + 1);
  559. info( t('Update has been marked successful') . EOL);
  560. goaway($a->get_baseurl(true) . '/admin/dbsync');
  561. }
  562. if($a->argc > 2 && intval($a->argv[2])) {
  563. require_once('update.php');
  564. $func = 'update_' . intval($a->argv[2]);
  565. if(function_exists($func)) {
  566. $retval = $func();
  567. if($retval === UPDATE_FAILED) {
  568. $o .= sprintf( t('Executing %s failed. Check system logs.'), $func);
  569. }
  570. elseif($retval === UPDATE_SUCCESS) {
  571. $o .= sprintf( t('Update %s was successfully applied.', $func));
  572. set_config('database',$func, 'success');
  573. }
  574. else
  575. $o .= sprintf( t('Update %s did not return a status. Unknown if it succeeded.'), $func);
  576. }
  577. else
  578. $o .= sprintf( t('Update function %s could not be found.'), $func);
  579. return $o;
  580. }
  581. $failed = array();
  582. $r = q("select k, v from config where `cat` = 'database' ");
  583. if(count($r)) {
  584. foreach($r as $rr) {
  585. $upd = intval(substr($rr['k'],7));
  586. if($upd < 1139 || $rr['v'] === 'success')
  587. continue;
  588. $failed[] = $upd;
  589. }
  590. }
  591. if(! count($failed))
  592. return '<h3>' . t('No failed updates.') . '</h3>';
  593. $o = replace_macros(get_markup_template('failed_updates.tpl'),array(
  594. '$base' => $a->get_baseurl(true),
  595. '$banner' => t('Failed Updates'),
  596. '$desc' => t('This does not include updates prior to 1139, which did not return a status.'),
  597. '$mark' => t('Mark success (if update was manually applied)'),
  598. '$apply' => t('Attempt to execute this update step automatically'),
  599. '$failed' => $failed
  600. ));
  601. return $o;
  602. }
  603. /**
  604. * Users admin page
  605. *
  606. * @param App $a
  607. */
  608. function admin_page_users_post(&$a){
  609. $pending = ( x($_POST, 'pending') ? $_POST['pending'] : Array() );
  610. $users = ( x($_POST, 'user') ? $_POST['user'] : Array() );
  611. $nu_name = ( x($_POST, 'new_user_name') ? $_POST['new_user_name'] : '');
  612. $nu_nickname = ( x($_POST, 'new_user_nickname') ? $_POST['new_user_nickname'] : '');
  613. $nu_email = ( x($_POST, 'new_user_email') ? $_POST['new_user_email'] : '');
  614. check_form_security_token_redirectOnErr('/admin/users', 'admin_users');
  615. if (!($nu_name==="") && !($nu_email==="") && !($nu_nickname==="")) {
  616. require_once('include/user.php');
  617. require_once('include/email.php');
  618. $result = create_user( array('username'=>$nu_name, 'email'=>$nu_email, 'nickname'=>$nu_nickname, 'verified'=>1) );
  619. if(! $result['success']) {
  620. notice($result['message']);
  621. return;
  622. }
  623. $nu = $result['user'];
  624. $email_tpl = get_intltext_template("register_adminadd_eml.tpl");
  625. $email_tpl = replace_macros($email_tpl, array(
  626. '$sitename' => $a->config['sitename'],
  627. '$siteurl' => $a->get_baseurl(),
  628. '$username' => $nu['username'],
  629. '$email' => $nu['email'],
  630. '$password' => $result['password'],
  631. '$uid' => $nu['uid'] ));
  632. $res = mail($nu['email'], email_header_encode( sprintf( t('Registration details for %s'), $a->config['sitename']),'UTF-8'),
  633. $email_tpl,
  634. 'From: ' . 'Administrator' . '@' . $_SERVER['SERVER_NAME'] . "\n"
  635. . 'Content-type: text/plain; charset=UTF-8' . "\n"
  636. . 'Content-transfer-encoding: 8bit' );
  637. if ($res) {
  638. info( t('Registration successful. Email send to user').EOL );
  639. }
  640. }
  641. if (x($_POST,'page_users_block')){
  642. foreach($users as $uid){
  643. q("UPDATE `user` SET `blocked`=1-`blocked` WHERE `uid`=%s",
  644. intval( $uid )
  645. );
  646. }
  647. notice( sprintf( tt("%s user blocked/unblocked", "%s users blocked/unblocked", count($users)), count($users)) );
  648. }
  649. if (x($_POST,'page_users_delete')){
  650. require_once("include/Contact.php");
  651. foreach($users as $uid){
  652. user_remove($uid);
  653. }
  654. notice( sprintf( tt("%s user deleted", "%s users deleted", count($users)), count($users)) );
  655. }
  656. if (x($_POST,'page_users_approve')){
  657. require_once("mod/regmod.php");
  658. foreach($pending as $hash){
  659. user_allow($hash);
  660. }
  661. }
  662. if (x($_POST,'page_users_deny')){
  663. require_once("mod/regmod.php");
  664. foreach($pending as $hash){
  665. user_deny($hash);
  666. }
  667. }
  668. goaway($a->get_baseurl(true) . '/admin/users' );
  669. return; // NOTREACHED
  670. }
  671. /**
  672. * @param App $a
  673. * @return string
  674. */
  675. function admin_page_users(&$a){
  676. if ($a->argc>2) {
  677. $uid = $a->argv[3];
  678. $user = q("SELECT username, blocked FROM `user` WHERE `uid`=%d", intval($uid));
  679. if (count($user)==0){
  680. notice( 'User not found' . EOL);
  681. goaway($a->get_baseurl(true) . '/admin/users' );
  682. return ''; // NOTREACHED
  683. }
  684. switch($a->argv[2]){
  685. case "delete":{
  686. check_form_security_token_redirectOnErr('/admin/users', 'admin_users', 't');
  687. // delete user
  688. require_once("include/Contact.php");
  689. user_remove($uid);
  690. notice( sprintf(t("User '%s' deleted"), $user[0]['username']) . EOL);
  691. }; break;
  692. case "block":{
  693. check_form_security_token_redirectOnErr('/admin/users', 'admin_users', 't');
  694. q("UPDATE `user` SET `blocked`=%d WHERE `uid`=%s",
  695. intval( 1-$user[0]['blocked'] ),
  696. intval( $uid )
  697. );
  698. notice( sprintf( ($user[0]['blocked']?t("User '%s' unblocked"):t("User '%s' blocked")) , $user[0]['username']) . EOL);
  699. }; break;
  700. }
  701. goaway($a->get_baseurl(true) . '/admin/users' );
  702. return ''; // NOTREACHED
  703. }
  704. /* get pending */
  705. $pending = q("SELECT `register`.*, `contact`.`name`, `user`.`email`
  706. FROM `register`
  707. LEFT JOIN `contact` ON `register`.`uid` = `contact`.`uid`
  708. LEFT JOIN `user` ON `register`.`uid` = `user`.`uid`;");
  709. /* get users */
  710. $total = q("SELECT count(*) as total FROM `user` where 1");
  711. if(count($total)) {
  712. $a->set_pager_total($total[0]['total']);
  713. $a->set_pager_itemspage(100);
  714. }
  715. $users = q("SELECT `user` . * , `contact`.`name` , `contact`.`url` , `contact`.`micro`, `lastitem`.`lastitem_date`, `user`.`account_expired`
  716. FROM
  717. (SELECT MAX(`item`.`changed`) as `lastitem_date`, `item`.`uid`
  718. FROM `item`
  719. WHERE `item`.`type` = 'wall'
  720. GROUP BY `item`.`uid`) AS `lastitem`
  721. RIGHT OUTER JOIN `user` ON `user`.`uid` = `lastitem`.`uid`,
  722. `contact`
  723. WHERE
  724. `user`.`uid` = `contact`.`uid`
  725. AND `user`.`verified` =1
  726. AND `contact`.`self` =1
  727. ORDER BY `contact`.`name` LIMIT %d, %d
  728. ",
  729. intval($a->pager['start']),
  730. intval($a->pager['itemspage'])
  731. );
  732. function _setup_users($e){
  733. $a = get_app();
  734. $accounts = Array(
  735. t('Normal Account'),
  736. t('Soapbox Account'),
  737. t('Community/Celebrity Account'),
  738. t('Automatic Friend Account')
  739. );
  740. $e['page-flags'] = $accounts[$e['page-flags']];
  741. $e['register_date'] = relative_date($e['register_date']);
  742. $e['login_date'] = relative_date($e['login_date']);
  743. $e['lastitem_date'] = relative_date($e['lastitem_date']);
  744. $e['is_admin'] = ($e['email'] === $a->config['admin_email']);
  745. $e['deleted'] = ($e['account_removed']?relative_date($e['account_expires_on']):False);
  746. return $e;
  747. }
  748. $users = array_map("_setup_users", $users);
  749. // Get rid of dashes in key names, Smarty3 can't handle them
  750. // and extracting deleted users
  751. $tmp_users = Array();
  752. $deleted = Array();
  753. while(count($users)) {
  754. $new_user = Array();
  755. foreach( array_pop($users) as $k => $v) {
  756. $k = str_replace('-','_',$k);
  757. $new_user[$k] = $v;
  758. }
  759. if($new_user['deleted']) {
  760. array_push($deleted, $new_user);
  761. }
  762. else {
  763. array_push($tmp_users, $new_user);
  764. }
  765. }
  766. //Reversing the two array, and moving $tmp_users to $users
  767. array_reverse($deleted);
  768. while(count($tmp_users)) {
  769. array_push($users, array_pop($tmp_users));
  770. }
  771. $t = get_markup_template("admin_users.tpl");
  772. $o = replace_macros($t, array(
  773. // strings //
  774. '$title' => t('Administration'),
  775. '$page' => t('Users'),
  776. '$submit' => t('Add User'),
  777. '$select_all' => t('select all'),
  778. '$h_pending' => t('User registrations waiting for confirm'),
  779. '$h_deleted' => t('User waiting for permanent deletion'),
  780. '$th_pending' => array( t('Request date'), t('Name'), t('Email') ),
  781. '$no_pending' => t('No registrations.'),
  782. '$approve' => t('Approve'),
  783. '$deny' => t('Deny'),
  784. '$delete' => t('Delete'),
  785. '$block' => t('Block'),
  786. '$unblock' => t('Unblock'),
  787. '$siteadmin' => t('Site admin'),
  788. '$accountexpired' => t('Account expired'),
  789. '$h_users' => t('Users'),
  790. '$h_newuser' => t('New User'),
  791. '$th_deleted' => array( t('Name'), t('Email'), t('Register date'), t('Last login'), t('Last item'), t('Deleted since') ),
  792. '$th_users' => array( t('Name'), t('Email'), t('Register date'), t('Last login'), t('Last item'), t('Account') ),
  793. '$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?'),
  794. '$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?'),
  795. '$form_security_token' => get_form_security_token("admin_users"),
  796. // values //
  797. '$baseurl' => $a->get_baseurl(true),
  798. '$pending' => $pending,
  799. 'deleted' => $deleted,
  800. '$users' => $users,
  801. '$newusername' => array('new_user_name', t("Name"), '', t("Name of the new user.")),
  802. '$newusernickname' => array('new_user_nickname', t("Nickname"), '', t("Nickname of the new user.")),
  803. '$newuseremail' => array('new_user_email', t("Email"), '', t("Email address of the new user.")),
  804. ));
  805. $o .= paginate($a);
  806. return $o;
  807. }
  808. /**
  809. * Plugins admin page
  810. *
  811. * @param App $a
  812. * @return string
  813. */
  814. function admin_page_plugins(&$a){
  815. /**
  816. * Single plugin
  817. */
  818. if ($a->argc == 3){
  819. $plugin = $a->argv[2];
  820. if (!is_file("addon/$plugin/$plugin.php")){
  821. notice( t("Item not found.") );
  822. return '';
  823. }
  824. if (x($_GET,"a") && $_GET['a']=="t"){
  825. check_form_security_token_redirectOnErr('/admin/plugins', 'admin_themes', 't');
  826. // Toggle plugin status
  827. $idx = array_search($plugin, $a->plugins);
  828. if ($idx !== false){
  829. unset($a->plugins[$idx]);
  830. uninstall_plugin($plugin);
  831. info( sprintf( t("Plugin %s disabled."), $plugin ) );
  832. } else {
  833. $a->plugins[] = $plugin;
  834. install_plugin($plugin);
  835. info( sprintf( t("Plugin %s enabled."), $plugin ) );
  836. }
  837. set_config("system","addon", implode(", ",$a->plugins));
  838. goaway($a->get_baseurl(true) . '/admin/plugins' );
  839. return ''; // NOTREACHED
  840. }
  841. // display plugin details
  842. require_once('library/markdown.php');
  843. if (in_array($plugin, $a->plugins)){
  844. $status="on"; $action= t("Disable");
  845. } else {
  846. $status="off"; $action= t("Enable");
  847. }
  848. $readme=Null;
  849. if (is_file("addon/$plugin/README.md")){
  850. $readme = file_get_contents("addon/$plugin/README.md");
  851. $readme = Markdown($readme);
  852. } else if (is_file("addon/$plugin/README")){
  853. $readme = "<pre>". file_get_contents("addon/$plugin/README") ."</pre>";
  854. }
  855. $admin_form="";
  856. if (is_array($a->plugins_admin) && in_array($plugin, $a->plugins_admin)){
  857. @require_once("addon/$plugin/$plugin.php");
  858. $func = $plugin.'_plugin_admin';
  859. $func($a, $admin_form);
  860. }
  861. $t = get_markup_template("admin_plugins_details.tpl");
  862. return replace_macros($t, array(
  863. '$title' => t('Administration'),
  864. '$page' => t('Plugins'),
  865. '$toggle' => t('Toggle'),
  866. '$settings' => t('Settings'),
  867. '$baseurl' => $a->get_baseurl(true),
  868. '$plugin' => $plugin,
  869. '$status' => $status,
  870. '$action' => $action,
  871. '$info' => get_plugin_info($plugin),
  872. '$str_author' => t('Author: '),
  873. '$str_maintainer' => t('Maintainer: '),
  874. '$admin_form' => $admin_form,
  875. '$function' => 'plugins',
  876. '$screenshot' => '',
  877. '$readme' => $readme,
  878. '$form_security_token' => get_form_security_token("admin_themes"),
  879. ));
  880. }
  881. /**
  882. * List plugins
  883. */
  884. $plugins = array();
  885. $files = glob("addon/*/");
  886. if($files) {
  887. foreach($files as $file) {
  888. if (is_dir($file)){
  889. list($tmp, $id)=array_map("trim", explode("/",$file));
  890. $info = get_plugin_info($id);
  891. $plugins[] = array( $id, (in_array($id, $a->plugins)?"on":"off") , $info);
  892. }
  893. }
  894. }
  895. $t = get_markup_template("admin_plugins.tpl");
  896. return replace_macros($t, array(
  897. '$title' => t('Administration'),
  898. '$page' => t('Plugins'),
  899. '$submit' => t('Save Settings'),
  900. '$baseurl' => $a->get_baseurl(true),
  901. '$function' => 'plugins',
  902. '$plugins' => $plugins,
  903. '$form_security_token' => get_form_security_token("admin_themes"),
  904. ));
  905. }
  906. /**
  907. * @param array $themes
  908. * @param string $th
  909. * @param int $result
  910. */
  911. function toggle_theme(&$themes,$th,&$result) {
  912. for($x = 0; $x < count($themes); $x ++) {
  913. if($themes[$x]['name'] === $th) {
  914. if($themes[$x]['allowed']) {
  915. $themes[$x]['allowed'] = 0;
  916. $result = 0;
  917. }
  918. else {
  919. $themes[$x]['allowed'] = 1;
  920. $result = 1;
  921. }
  922. }
  923. }
  924. }
  925. /**
  926. * @param array $themes
  927. * @param string $th
  928. * @return int
  929. */
  930. function theme_status($themes,$th) {
  931. for($x = 0; $x < count($themes); $x ++) {
  932. if($themes[$x]['name'] === $th) {
  933. if($themes[$x]['allowed']) {
  934. return 1;
  935. }
  936. else {
  937. return 0;
  938. }
  939. }
  940. }
  941. return 0;
  942. }
  943. /**
  944. * @param array $themes
  945. * @return string
  946. */
  947. function rebuild_theme_table($themes) {
  948. $o = '';
  949. if(count($themes)) {
  950. foreach($themes as $th) {
  951. if($th['allowed']) {
  952. if(strlen($o))
  953. $o .= ',';
  954. $o .= $th['name'];
  955. }
  956. }
  957. }
  958. return $o;
  959. }
  960. /**
  961. * Themes admin page
  962. *
  963. * @param App $a
  964. * @return string
  965. */
  966. function admin_page_themes(&$a){
  967. $allowed_themes_str = get_config('system','allowed_themes');
  968. $allowed_themes_raw = explode(',',$allowed_themes_str);
  969. $allowed_themes = array();
  970. if(count($allowed_themes_raw))
  971. foreach($allowed_themes_raw as $x)
  972. if(strlen(trim($x)))
  973. $allowed_themes[] = trim($x);
  974. $themes = array();
  975. $files = glob('view/theme/*');
  976. if($files) {
  977. foreach($files as $file) {
  978. $f = basename($file);
  979. $is_experimental = intval(file_exists($file . '/experimental'));
  980. $is_supported = 1-(intval(file_exists($file . '/unsupported'))); // Is not used yet
  981. $is_allowed = intval(in_array($f,$allowed_themes));
  982. $themes[] = array('name' => $f, 'experimental' => $is_experimental, 'supported' => $is_supported, 'allowed' => $is_allowed);
  983. }
  984. }
  985. if(! count($themes)) {
  986. notice( t('No themes found.'));
  987. return '';
  988. }
  989. /**
  990. * Single theme
  991. */
  992. if ($a->argc == 3){
  993. $theme = $a->argv[2];
  994. if(! is_dir("view/theme/$theme")){
  995. notice( t("Item not found.") );
  996. return '';
  997. }
  998. if (x($_GET,"a") && $_GET['a']=="t"){
  999. check_form_security_token_redirectOnErr('/admin/themes', 'admin_themes', 't');
  1000. // Toggle theme status
  1001. toggle_theme($themes,$theme,$result);
  1002. $s = rebuild_theme_table($themes);
  1003. if($result) {
  1004. install_theme($theme);
  1005. info( sprintf('Theme %s enabled.',$theme));
  1006. }
  1007. else {
  1008. uninstall_theme($theme);
  1009. info( sprintf('Theme %s disabled.',$theme));
  1010. }
  1011. set_config('system','allowed_themes',$s);
  1012. goaway($a->get_baseurl(true) . '/admin/themes' );
  1013. return ''; // NOTREACHED
  1014. }
  1015. // display theme details
  1016. require_once('library/markdown.php');
  1017. if (theme_status($themes,$theme)) {
  1018. $status="on"; $action= t("Disable");
  1019. } else {
  1020. $status="off"; $action= t("Enable");
  1021. }
  1022. $readme=Null;
  1023. if (is_file("view/theme/$theme/README.md")){
  1024. $readme = file_get_contents("view/theme/$theme/README.md");
  1025. $readme = Markdown($readme);
  1026. } else if (is_file("view/theme/$theme/README")){
  1027. $readme = "<pre>". file_get_contents("view/theme/$theme/README") ."</pre>";
  1028. }
  1029. $admin_form="";
  1030. if (is_file("view/theme/$theme/config.php")){
  1031. require_once("view/theme/$theme/config.php");
  1032. if(function_exists("theme_admin")){
  1033. $admin_form = theme_admin($a);
  1034. }
  1035. }
  1036. $screenshot = array( get_theme_screenshot($theme), t('Screenshot'));
  1037. if(! stristr($screenshot[0],$theme))
  1038. $screenshot = null;
  1039. $t = get_markup_template("admin_plugins_details.tpl");
  1040. return replace_macros($t, array(
  1041. '$title' => t('Administration'),
  1042. '$page' => t('Themes'),
  1043. '$toggle' => t('Toggle'),
  1044. '$settings' => t('Settings'),
  1045. '$baseurl' => $a->get_baseurl(true),
  1046. '$plugin' => $theme,
  1047. '$status' => $status,
  1048. '$action' => $action,
  1049. '$info' => get_theme_info($theme),
  1050. '$function' => 'themes',
  1051. '$admin_form' => $admin_form,
  1052. '$str_author' => t('Author: '),
  1053. '$str_maintainer' => t('Maintainer: '),
  1054. '$screenshot' => $screenshot,
  1055. '$readme' => $readme,
  1056. '$form_security_token' => get_form_security_token("admin_themes"),
  1057. ));
  1058. }
  1059. /**
  1060. * List themes
  1061. */
  1062. $xthemes = array();
  1063. if($themes) {
  1064. foreach($themes as $th) {
  1065. $xthemes[] = array($th['name'],(($th['allowed']) ? "on" : "off"), get_theme_info($th['name']));
  1066. }
  1067. }
  1068. $t = get_markup_template("admin_plugins.tpl");
  1069. return replace_macros($t, array(
  1070. '$title' => t('Administration'),
  1071. '$page' => t('Themes'),
  1072. '$submit' => t('Save Settings'),
  1073. '$baseurl' => $a->get_baseurl(true),
  1074. '$function' => 'themes',
  1075. '$plugins' => $xthemes,
  1076. '$experimental' => t('[Experimental]'),
  1077. '$unsupported' => t('[Unsupported]'),
  1078. '$form_security_token' => get_form_security_token("admin_themes"),
  1079. ));
  1080. }
  1081. /**
  1082. * Logs admin page
  1083. *
  1084. * @param App $a
  1085. */
  1086. function admin_page_logs_post(&$a) {
  1087. if (x($_POST,"page_logs")) {
  1088. check_form_security_token_redirectOnErr('/admin/logs', 'admin_logs');
  1089. $logfile = ((x($_POST,'logfile')) ? notags(trim($_POST['logfile'])) : '');
  1090. $debugging = ((x($_POST,'debugging')) ? true : false);
  1091. $loglevel = ((x($_POST,'loglevel')) ? intval(trim($_POST['loglevel'])) : 0);
  1092. set_config('system','logfile', $logfile);
  1093. set_config('system','debugging', $debugging);
  1094. set_config('system','loglevel', $loglevel);
  1095. }
  1096. info( t("Log settings updated.") );
  1097. goaway($a->get_baseurl(true) . '/admin/logs' );
  1098. return; // NOTREACHED
  1099. }
  1100. /**
  1101. * @param App $a
  1102. * @return string
  1103. */
  1104. function admin_page_logs(&$a){
  1105. $log_choices = Array(
  1106. LOGGER_NORMAL => 'Normal',
  1107. LOGGER_TRACE => 'Trace',
  1108. LOGGER_DEBUG => 'Debug',
  1109. LOGGER_DATA => 'Data',
  1110. LOGGER_ALL => 'All'
  1111. );
  1112. $t = get_markup_template("admin_logs.tpl");
  1113. $f = get_config('system','logfile');
  1114. $data = '';
  1115. if(!file_exists($f)) {
  1116. $data = t("Error trying to open <strong>$f</strong> log file.\r\n<br/>Check to see if file $f exist and is
  1117. readable.");
  1118. }
  1119. else {
  1120. $fp = fopen($f, 'r');
  1121. if(!$fp) {
  1122. $data = t("Couldn't open <strong>$f</strong> log file.\r\n<br/>Check to see if file $f is readable.");
  1123. }
  1124. else {
  1125. $fstat = fstat($fp);
  1126. $size = $fstat['size'];
  1127. if($size != 0)
  1128. {
  1129. if($size > 5000000 || $size < 0)
  1130. $size = 5000000;
  1131. $seek = fseek($fp,0-$size,SEEK_END);
  1132. if($seek === 0) {
  1133. $data = escape_tags(fread($fp,$size));
  1134. while(! feof($fp))
  1135. $data .= escape_tags(fread($fp,4096));
  1136. }
  1137. }
  1138. fclose($fp);
  1139. }
  1140. }
  1141. return replace_macros($t, array(
  1142. '$title' => t('Administration'),
  1143. '$page' => t('Logs'),
  1144. '$submit' => t('Save Settings'),
  1145. '$clear' => t('Clear'),
  1146. '$data' => $data,
  1147. '$baseurl' => $a->get_baseurl(true),
  1148. '$logname' => get_config('system','logfile'),
  1149. // name, label, value, help string, extra data...
  1150. '$debugging' => array('debugging', t("Enable Debugging"),get_config('system','debugging'), ""),
  1151. '$logfile' => array('logfile', t("Log file"), get_config('system','logfile'), t("Must be writable by web server. Relative to your Friendica top-level directory.")),
  1152. '$loglevel' => array('loglevel', t("Log level"), get_config('system','loglevel'), "", $log_choices),
  1153. '$form_security_token' => get_form_security_token("admin_logs"),
  1154. ));
  1155. }
  1156. /**
  1157. * @param App $a
  1158. */
  1159. function admin_page_remoteupdate_post(&$a) {
  1160. // this function should be called via ajax post
  1161. if(!is_site_admin()) {
  1162. return;
  1163. }
  1164. if (x($_POST,'remotefile') && $_POST['remotefile']!=""){
  1165. $remotefile = $_POST['remotefile'];
  1166. $ftpdata = (x($_POST['ftphost'])?$_POST:false);
  1167. doUpdate($remotefile, $ftpdata);
  1168. } else {
  1169. echo "No remote file to download. Abort!";
  1170. }
  1171. killme();
  1172. }
  1173. /**
  1174. * @param App $a
  1175. * @return string
  1176. */
  1177. function admin_page_remoteupdate(&$a) {
  1178. if(!is_site_admin()) {
  1179. return login(false);
  1180. }
  1181. $canwrite = canWeWrite();
  1182. $canftp = function_exists('ftp_connect');
  1183. $needupdate = true;
  1184. $u = checkUpdate();
  1185. if (!is_array($u)){
  1186. $needupdate = false;
  1187. $u = array('','','');
  1188. }
  1189. $tpl = get_markup_template("admin_remoteupdate.tpl");
  1190. return replace_macros($tpl, array(
  1191. '$baseurl' => $a->get_baseurl(true),
  1192. '$submit' => t("Update now"),
  1193. '$close' => t("Close"),
  1194. '$localversion' => FRIENDICA_VERSION,
  1195. '$remoteversion' => $u[1],
  1196. '$needupdate' => $needupdate,
  1197. '$canwrite' => $canwrite,
  1198. '$canftp' => $canftp,
  1199. '$ftphost' => array('ftphost', t("FTP Host"), '',''),
  1200. '$ftppath' => array('ftppath', t("FTP Path"), '/',''),
  1201. '$ftpuser' => array('ftpuser', t("FTP User"), '',''),
  1202. '$ftppwd' => array('ftppwd', t("FTP Password"), '',''),
  1203. '$remotefile'=>array('remotefile','', $u['2'],''),
  1204. ));
  1205. }