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.
 
 
 
 
 
 

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