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.
 
 
 
 
 
 

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