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.
 
 
 
 
 
 

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