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.
 
 
 
 
 
 

650 lines
21 KiB

  1. <?php
  2. /**
  3. * Friendika admin
  4. */
  5. function admin_init(&$a) {
  6. if(!is_site_admin()) {
  7. notice( t('Permission denied.') . EOL);
  8. return;
  9. }
  10. }
  11. function admin_post(&$a){
  12. if(!is_site_admin()) {
  13. return login(false);
  14. }
  15. // urls
  16. if ($a->argc > 1){
  17. switch ($a->argv[1]){
  18. case 'site':
  19. admin_page_site_post($a);
  20. break;
  21. case 'users':
  22. admin_page_users_post($a);
  23. break;
  24. case 'plugins':
  25. if ($a->argc > 2 &&
  26. is_file("addon/".$a->argv[2]."/".$a->argv[2].".php")){
  27. @include_once("addon/".$a->argv[2]."/".$a->argv[2].".php");
  28. if(function_exists('plugin_admin_post')) {
  29. plugin_admin_post($a);
  30. }
  31. }
  32. goaway($a->get_baseurl() . '/admin/plugins/' . $a->argv[2] );
  33. return; // NOTREACHED
  34. break;
  35. case 'logs':
  36. admin_page_logs_post($a);
  37. break;
  38. }
  39. }
  40. goaway($a->get_baseurl() . '/admin' );
  41. return; // NOTREACHED
  42. }
  43. function admin_content(&$a) {
  44. if(!is_site_admin()) {
  45. return login(false);
  46. }
  47. /**
  48. * Side bar links
  49. */
  50. // array( url, name, extra css classes )
  51. $aside = Array(
  52. 'site' => Array($a->get_baseurl()."/admin/site/", t("Site") , "site"),
  53. 'users' => Array($a->get_baseurl()."/admin/users/", t("Users") , "users"),
  54. 'plugins'=> Array($a->get_baseurl()."/admin/plugins/", t("Plugins") , "plugins")
  55. );
  56. /* get plugins admin page */
  57. $r = q("SELECT * FROM `hook` WHERE `hook`='plugin_admin'");
  58. $aside['plugins_admin']=Array();
  59. foreach ($r as $h){
  60. $plugin = explode("/",$h['file']); $plugin = $plugin[1];
  61. $aside['plugins_admin'][] = Array($a->get_baseurl()."/admin/plugins/".$plugin, $plugin, "plugin");
  62. // temp plugins with admin
  63. $a->plugins_admin[] = $plugin;
  64. }
  65. $aside['logs'] = Array($a->get_baseurl()."/admin/logs/", t("Logs"), "logs");
  66. $t = get_markup_template("admin_aside.tpl");
  67. $a->page['aside'] = replace_macros( $t, array(
  68. '$admin' => $aside,
  69. '$h_pending' => t('User registrations waiting for confirm'),
  70. '$admurl'=> $a->get_baseurl()."/admin/"
  71. ));
  72. /**
  73. * Page content
  74. */
  75. $o = '';
  76. // urls
  77. if ($a->argc > 1){
  78. switch ($a->argv[1]){
  79. case 'site':
  80. $o = admin_page_site($a);
  81. break;
  82. case 'users':
  83. $o = admin_page_users($a);
  84. break;
  85. case 'plugins':
  86. $o = admin_page_plugins($a);
  87. break;
  88. case 'logs':
  89. $o = admin_page_logs($a);
  90. break;
  91. default:
  92. notice( t("Item not found.") );
  93. }
  94. } else {
  95. $o = admin_page_summary($a);
  96. }
  97. return $o;
  98. }
  99. /**
  100. * Admin Summary Page
  101. */
  102. function admin_page_summary(&$a) {
  103. $r = q("SELECT `page-flags`, COUNT(uid) as `count` FROM `user` GROUP BY `page-flags`");
  104. $accounts = Array(
  105. Array( t('Normal Account'), 0),
  106. Array( t('Soapbox Account'), 0),
  107. Array( t('Community/Celebrity Account'), 0),
  108. Array( t('Automatic Friend Account'), 0)
  109. );
  110. $users=0;
  111. foreach ($r as $u){ $accounts[$u['page-flags']][1] = $u['count']; $users+=$u['count']; }
  112. $r = q("SELECT COUNT(id) as `count` FROM `register`");
  113. $pending = $r[0]['count'];
  114. $t = get_markup_template("admin_summary.tpl");
  115. return replace_macros($t, array(
  116. '$title' => t('Administration'),
  117. '$page' => t('Summary'),
  118. '$users' => Array( t('Registered users'), $users),
  119. '$accounts' => $accounts,
  120. '$pending' => Array( t('Pending registrations'), $pending),
  121. '$version' => Array( t('Version'), FRIENDIKA_VERSION),
  122. '$build' => get_config('system','build'),
  123. '$plugins' => Array( t('Active plugins'), $a->plugins )
  124. ));
  125. }
  126. /**
  127. * Admin Site Page
  128. */
  129. function admin_page_site_post(&$a){
  130. if (!x($_POST,"page_site")){
  131. return;
  132. }
  133. $sitename = ((x($_POST,'sitename')) ? notags(trim($_POST['sitename'])) : '');
  134. $banner = ((x($_POST,'banner')) ? trim($_POST['banner']) : false);
  135. $language = ((x($_POST,'language')) ? notags(trim($_POST['language'])) : '');
  136. $theme = ((x($_POST,'theme')) ? notags(trim($_POST['theme'])) : '');
  137. $maximagesize = ((x($_POST,'maximagesize')) ? intval(trim($_POST['maximagesize'])) : 0);
  138. $register_policy = ((x($_POST,'register_policy')) ? intval(trim($_POST['register_policy'])) : 0);
  139. $register_text = ((x($_POST,'register_text')) ? notags(trim($_POST['register_text'])) : '');
  140. $allowed_sites = ((x($_POST,'allowed_sites')) ? notags(trim($_POST['allowed_sites'])) : '');
  141. $allowed_email = ((x($_POST,'allowed_email')) ? notags(trim($_POST['allowed_email'])) : '');
  142. $block_public = ((x($_POST,'block_public')) ? True : False);
  143. $force_publish = ((x($_POST,'publish_all')) ? True : False);
  144. $global_directory = ((x($_POST,'directory_submit_url')) ? notags(trim($_POST['directory_submit_url'])) : '');
  145. $global_search_url = ((x($_POST,'directory_search_url'))? notags(trim($_POST['directory_search_url'])) : '');
  146. $no_multi_reg = ((x($_POST,'no_multi_reg')) ? True : False);
  147. $no_openid = !((x($_POST,'no_openid')) ? True : False);
  148. $no_gravatar = !((x($_POST,'no_gravatar')) ? True : False);
  149. $no_regfullname = !((x($_POST,'no_regfullname')) ? True : False);
  150. $no_utf = !((x($_POST,'no_utf')) ? True : False);
  151. $verifyssl = ((x($_POST,'verifyssl')) ? True : False);
  152. $proxyuser = ((x($_POST,'proxyuser')) ? notags(trim($_POST['global_search_url'])) : '');
  153. $proxy = ((x($_POST,'proxy')) ? notags(trim($_POST['global_search_url'])) : '');
  154. $timeout = ((x($_POST,'timeout')) ? intval(trim($_POST['timeout'])) : 60);
  155. set_config('config','sitename',$sitename);
  156. if ($banner==""){
  157. // don't know why, but del_config doesn't work...
  158. q("DELETE FROM `config` WHERE `cat` = '%s' AND `k` = '%s' LIMIT 1",
  159. dbesc("system"),
  160. dbesc("banner")
  161. );
  162. } else {
  163. set_config('system','banner', $banner);
  164. }
  165. set_config('system','language', $language);
  166. set_config('system','theme', $theme);
  167. set_config('system','maximagesize', $maximagesize);
  168. set_config('config','register_policy', $register_policy);
  169. set_config('config','register_text', $register_text);
  170. set_config('system','allowed_sites', $allowed_sites);
  171. set_config('system','allowed_email', $allowed_email);
  172. set_config('system','block_public', $block_public);
  173. set_config('system','publish_all', $force_publish);
  174. if ($global_directory==""){
  175. // don't know why, but del_config doesn't work...
  176. q("DELETE FROM `config` WHERE `cat` = '%s' AND `k` = '%s' LIMIT 1",
  177. dbesc("system"),
  178. dbesc("directory_submit_url")
  179. );
  180. } else {
  181. set_config('system','directory_submit_url', $global_directory);
  182. }
  183. set_config('system','directory_search_url', $global_search_url);
  184. set_config('system','block_extended_register', $no_multi_reg);
  185. set_config('system','no_openid', $no_openid);
  186. set_config('system','no_gravatar', $no_gravatar);
  187. set_config('system','no_regfullname', $no_regfullname);
  188. set_config('system','proxy', $no_utf);
  189. set_config('system','verifyssl', $verifyssl);
  190. set_config('system','proxyuser', $proxyuser);
  191. set_config('system','proxy', $proxy);
  192. set_config('system','curl_timeout', $timeout);
  193. info( t('Site settings updated.') . EOL);
  194. goaway($a->get_baseurl() . '/admin/site' );
  195. return; // NOTREACHED
  196. }
  197. function admin_page_site(&$a) {
  198. /* Installed langs */
  199. $lang_choices = array();
  200. $langs = glob('view/*/strings.php');
  201. if(is_array($langs) && count($langs)) {
  202. if(! in_array('view/en/strings.php',$langs))
  203. $langs[] = 'view/en/';
  204. asort($langs);
  205. foreach($langs as $l) {
  206. $t = explode("/",$l);
  207. $lang_choices[$t[1]] = $t[1];
  208. }
  209. }
  210. /* Installed themes */
  211. $theme_choices = array();
  212. $files = glob('view/theme/*');
  213. if($files) {
  214. foreach($files as $file) {
  215. $f = basename($file);
  216. $theme_name = ((file_exists($file . '/experimental')) ? sprintf("%s - \x28Experimental\x29", $f) : $f);
  217. $theme_choices[$f] = $theme_name;
  218. }
  219. }
  220. /* Banner */
  221. $banner = get_config('system','banner');
  222. if($banner == false)
  223. $banner = htmlspecialchars('<a href="http://project.friendika.com"><img id="logo-img" src="images/friendika-32.png" alt="logo" /></a><span id="logo-text"><a href="http://project.friendika.com">Friendika</a></span>');
  224. //echo "<pre>"; var_dump($lang_choices); die("</pre>");
  225. /* Register policy */
  226. $register_choices = Array(
  227. REGISTER_CLOSED => t("Closed"),
  228. REGISTER_APPROVE => t("Need approvation"),
  229. REGISTER_OPEN => t("Open")
  230. );
  231. $t = get_markup_template("admin_site.tpl");
  232. return replace_macros($t, array(
  233. '$title' => t('Administration'),
  234. '$page' => t('Site'),
  235. '$submit' => t('Submit'),
  236. '$registration' => t('Registration'),
  237. '$upload' => t('File upload'),
  238. '$corporate' => t('Corporate/Edu'),
  239. '$advanced' => t('Advanced'),
  240. '$baseurl' => $a->get_baseurl(),
  241. // name, label, value, help string, extra data...
  242. '$sitename' => array('sitename', t("Site name"), $a->config['sitename'], ""),
  243. '$banner' => array('banner', t("Banner/Logo"), $banner, ""),
  244. '$language' => array('language', t("System language"), get_config('system','language'), "", $lang_choices),
  245. '$theme' => array('theme', t("System theme"), get_config('system','theme'), "Default system theme (which may be over-ridden by user profiles)", $theme_choices),
  246. '$maximagesize' => array('maximagesize', t("Maximum image size"), get_config('system','maximagesize'), "Maximum size in bytes of uploaded images. Default is 0, which means no limits."),
  247. '$register_policy' => array('register_policy', t("Register policy"), $a->config['register_policy'], "", $register_choices),
  248. '$register_text' => array('register_text', t("Register text"), $a->config['register_text'], "Will be displayed prominently on the registration page."),
  249. '$allowed_sites' => array('allowed_sites', t("Allowed friend domains"), get_config('system','allowed_sites'), "Comma separated list of domains which are allowed to establish friendships with this site. Wildcards are accepted. Empty to allow any domains"),
  250. '$allowed_email' => array('allowed_email', t("Allowed email domains"), get_config('system','allowed_email'), "Comma separated list of domains which are allowed in email addresses for registrations to this site. Wildcards are accepted. Empty to allow any domains"),
  251. '$block_public' => array('block_public', t("Block public"), get_config('system','block_public'), "Check to block public access to all otherwise public personal pages on this site unless you are currently logged in."),
  252. '$force_publish' => array('publish_all', t("Force publish"), get_config('system','publish_all'), "Check to force all profiles on this site to be listed in the site directory."),
  253. '$global_directory' => array('directory_submit_url', t("Global directory update URL"), get_config('system','directory_submit_url'), "URL to update the global directory. If this is not set, the global directory is completely unavailable to the application."),
  254. '$global_search_url'=> array('directory_search_url', t("Global directory search URL"), get_config('system','directory_search_url'), ""),
  255. '$no_multi_reg' => array('no_multi_reg', t("Block multiple registrations"), get_config('system','block_extended_register'), "Disallow users to register additional accounts for use as pages."),
  256. '$no_openid' => array('no_openid', t("OpenID support"), !get_config('system','no_openid'), "OpenID support for registration and logins."),
  257. '$no_gravatar' => array('no_gravatar', t("Gravatar support"), !get_config('system','no_gravatar'), "Search new user's photo on Gravatar."),
  258. '$no_regfullname' => array('no_regfullname', t("Fullname check"), !get_config('system','no_regfullname'), "Force users to registrate with a space between his firsname and lastname in Full name, as an antispam measure"),
  259. '$no_utf' => array('no_utf', t("UTF-8 Regular expressions"), !get_config('system','proxy'), "Use PHP UTF8 regular expressions"),
  260. '$verifyssl' => array('verifyssl', t("Verify SSL"), get_config('system','verifyssl'), "If you wish, you can turn on strict certificate checking. This will mean you cannot connect (at all) to self-signed SSL sites."),
  261. '$proxyuser' => array('proxyuser', t("Proxy user"), get_config('system','proxyuser'), ""),
  262. '$proxy' => array('proxy', t("Proxy URL"), get_config('system','proxy'), ""),
  263. '$timeout' => array('timeout', t("Network timeout"), (x(get_config('system','curl_timeout'))?get_config('system','curl_timeout'):60), "Value is in seconds. Set to 0 for unlimited (not recommended)."),
  264. ));
  265. }
  266. /**
  267. * Users admin page
  268. */
  269. function admin_page_users_post(&$a){
  270. $users=array(); $pending=array();
  271. foreach($_POST as $k=>$v){
  272. if (substr($k,0,5)=="user_") $users[] = substr($k,5,strlen($k)-5);
  273. if (substr($k,0,8)=="pending_") $users[] = substr($k,8,strlen($k)-8);
  274. }
  275. if (x($_POST,'page_users_block')){
  276. foreach($users as $uid){
  277. q("UPDATE `user` SET `blocked`=1-`blocked` WHERE `uid`=%s",
  278. intval( $uid )
  279. );
  280. }
  281. notice( sprintf( tt("%s user blocked", "%s users blocked/unblocked", count($users)), count($users)) );
  282. }
  283. if (x($_POST,'page_users_delete')){
  284. require_once("include/Contact.php");
  285. foreach($users as $uid){
  286. user_remove($uid);
  287. }
  288. notice( sprintf( tt("%s user deleted", "%s users deleted", count($users)), count($users)) );
  289. }
  290. if (x($_POST,'page_users_approve')){
  291. require_once("include/regmod.php");
  292. foreach($pending as $hash){
  293. user_allow($hash);
  294. }
  295. }
  296. if (x($_POST,'page_users_deny')){
  297. require_once("include/regmod.php");
  298. foreach($pending as $hash){
  299. user_deny($hash);
  300. }
  301. }
  302. goaway($a->get_baseurl() . '/admin/users' );
  303. return; // NOTREACHED
  304. }
  305. function admin_page_users(&$a){
  306. if ($a->argc>2) {
  307. $uid = $a->argv[3];
  308. $user = q("SELECT * FROM `user` WHERE `uid`=%d", intval($uid));
  309. if (count($user)==0){
  310. notice( 'User not found' . EOL);
  311. goaway($a->get_baseurl() . '/admin/users' );
  312. return; // NOTREACHED
  313. }
  314. switch($a->argv[2]){
  315. case "delete":{
  316. // delete user
  317. require_once("include/Contact.php");
  318. user_remove($uid);
  319. notice( sprintf(t("User '%s' deleted"), $user[0]['username']) . EOL);
  320. }; break;
  321. case "block":{
  322. q("UPDATE `user` SET `blocked`=%d WHERE `uid`=%s",
  323. intval( 1-$user[0]['blocked'] ),
  324. intval( $uid )
  325. );
  326. notice( sprintf( ($user[0]['blocked']?t("User '%s' unblocked"):t("User '%s' blocked")) , $user[0]['username']) . EOL);
  327. }; break;
  328. }
  329. goaway($a->get_baseurl() . '/admin/users' );
  330. return; // NOTREACHED
  331. }
  332. /* get pending */
  333. $pending = q("SELECT `register`.*, `contact`.`name`, `user`.`email`
  334. FROM `register`
  335. LEFT JOIN `contact` ON `register`.`uid` = `contact`.`uid`
  336. LEFT JOIN `user` ON `register`.`uid` = `user`.`uid`;");
  337. /* get users */
  338. $total = q("SELECT count(*) as total FROM `user` where 1");
  339. if(count($total)) {
  340. $a->set_pager_total($total[0]['total']);
  341. $a->set_pager_itemspage(100);
  342. }
  343. $users = q("SELECT `user` . * , `contact`.`name` , `contact`.`url` , `contact`.`micro` , `lastitem`.`changed` AS `lastitem_date`
  344. FROM (
  345. SELECT `item`.`changed` , `item`.`uid`
  346. FROM `item`
  347. GROUP BY `uid`
  348. ORDER BY `item`.`changed`
  349. ) AS `lastitem` , `user`
  350. LEFT JOIN `contact` ON `user`.`uid` = `contact`.`uid`
  351. WHERE `user`.`verified` =1
  352. AND `contact`.`self` =1
  353. AND `lastitem`.`uid` = `user`.`uid`
  354. ORDER BY `contact`.`name` LIMIT %d, %d
  355. ",
  356. intval($a->pager['start']),
  357. intval($a->pager['itemspage'])
  358. );
  359. function _setup_users($e){
  360. $accounts = Array(
  361. t('Normal Account'),
  362. t('Soapbox Account'),
  363. t('Community/Celebrity Account'),
  364. t('Automatic Friend Account')
  365. );
  366. $e['page-flags'] = $accounts[$e['page-flags']];
  367. $e['register_date'] = relative_date($e['register_date']);
  368. $e['login_date'] = relative_date($e['login_date']);
  369. $e['lastitem_date'] = relative_date($e['lastitem_date']);
  370. return $e;
  371. }
  372. $users = array_map("_setup_users", $users);
  373. $t = get_markup_template("admin_users.tpl");
  374. $o = replace_macros($t, array(
  375. // strings //
  376. '$title' => t('Administration'),
  377. '$page' => t('Users'),
  378. '$submit' => t('Submit'),
  379. '$select_all' => t('select all'),
  380. '$h_pending' => t('User registrations waiting for confirm'),
  381. '$th_pending' => array( t('Request date'), t('Name'), t('Email') ),
  382. '$no_pending' => t('No registrations.'),
  383. '$approve' => t('Approve'),
  384. '$deny' => t('Deny'),
  385. '$delete' => t('Delete'),
  386. '$block' => t('Block'),
  387. '$unblock' => t('Unblock'),
  388. '$h_users' => t('Users'),
  389. '$th_users' => array( t('Name'), t('Email'), t('Register date'), t('Last login'), t('Last item'), t('Account') ),
  390. '$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?'),
  391. '$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?'),
  392. // values //
  393. '$baseurl' => $a->get_baseurl(),
  394. '$pending' => $pending,
  395. '$users' => $users,
  396. ));
  397. $o .= paginate($a);
  398. return $o;
  399. }
  400. /*
  401. * Plugins admin page
  402. */
  403. function admin_page_plugins(&$a){
  404. /**
  405. * Single plugin
  406. */
  407. if ($a->argc == 3){
  408. $plugin = $a->argv[2];
  409. if (!is_file("addon/$plugin/$plugin.php")){
  410. notice( t("Item not found.") );
  411. return;
  412. }
  413. if (x($_GET,"a") && $_GET['a']=="t"){
  414. // Toggle plugin status
  415. $idx = array_search($plugin, $a->plugins);
  416. if ($idx){
  417. unset($a->plugins[$idx]);
  418. uninstall_plugin($plugin);
  419. info( sprintf( t("Plugin %s disabled."), $plugin ) );
  420. } else {
  421. $a->plugins[] = $plugin;
  422. install_plugin($plugin);
  423. info( sprintf( t("Plugin %s enabled."), $plugin ) );
  424. }
  425. set_config("system","addon", implode(", ",$a->plugins));
  426. goaway($a->get_baseurl() . '/admin/plugins' );
  427. return; // NOTREACHED
  428. }
  429. // display plugin details
  430. require_once('library/markdown.php');
  431. if (in_array($plugin, $a->plugins)){
  432. $status="on"; $action= t("Disable");
  433. } else {
  434. $status="off"; $action= t("Enable");
  435. }
  436. $readme=Null;
  437. if (is_file("addon/$plugin/README.md")){
  438. $readme = file_get_contents("addon/$plugin/README.md");
  439. $readme = Markdown($readme);
  440. } else if (is_file("addon/$plugin/README")){
  441. $readme = "<pre>". file_get_contents("addon/$plugin/README") ."</pre>";
  442. }
  443. $admin_form="";
  444. if (in_array($plugin, $a->plugins_admin)){
  445. call_hooks('plugin_admin', $admin_form);
  446. }
  447. $t = get_markup_template("admin_plugins_details.tpl");
  448. return replace_macros($t, array(
  449. '$title' => t('Administration'),
  450. '$page' => t('Plugins'),
  451. '$toggle' => t('Toggle'),
  452. '$baseurl' => $a->get_baseurl(),
  453. '$plugin' => $plugin,
  454. '$status' => $status,
  455. '$action' => $action,
  456. '$info' => get_plugin_info($plugin),
  457. '$admin_form' => $admin_form,
  458. '$readme' => $readme
  459. ));
  460. }
  461. /**
  462. * List plugins
  463. */
  464. $plugins = array();
  465. $files = glob("addon/*/");
  466. if($files) {
  467. foreach($files as $file) {
  468. if (is_dir($file)){
  469. list($tmp, $id)=array_map("trim", explode("/",$file));
  470. $info = get_plugin_info($id);
  471. $plugins[] = array( $id, (in_array($id, $a->plugins)?"on":"off") , $info);
  472. }
  473. }
  474. }
  475. $t = get_markup_template("admin_plugins.tpl");
  476. return replace_macros($t, array(
  477. '$title' => t('Administration'),
  478. '$page' => t('Plugins'),
  479. '$submit' => t('Submit'),
  480. '$baseurl' => $a->get_baseurl(),
  481. '$plugins' => $plugins
  482. ));
  483. }
  484. /**
  485. * Logs admin page
  486. */
  487. function admin_page_logs_post(&$a) {
  488. if (x($_POST,"page_logs")) {
  489. $logfile = ((x($_POST,'logfile')) ? notags(trim($_POST['logfile'])) : '');
  490. $debugging = ((x($_POST,'debugging')) ? true : false);
  491. $loglevel = ((x($_POST,'loglevel')) ? intval(trim($_POST['loglevel'])) : 0);
  492. set_config('system','logfile', $logfile);
  493. set_config('system','debugging', $debugging);
  494. set_config('system','loglevel', $loglevel);
  495. }
  496. info( t("Log settings updated.") );
  497. goaway($a->get_baseurl() . '/admin/logs' );
  498. return; // NOTREACHED
  499. }
  500. function admin_page_logs(&$a){
  501. $log_choices = Array(
  502. LOGGER_NORMAL => 'Normal',
  503. LOGGER_TRACE => 'Trace',
  504. LOGGER_DEBUG => 'Debug',
  505. LOGGER_DATA => 'Data',
  506. LOGGER_ALL => 'All'
  507. );
  508. $t = get_markup_template("admin_logs.tpl");
  509. $f = get_config('system','logfile');
  510. $size = filesize($f);
  511. if($size > 5000000)
  512. $size = 5000000;
  513. $data = '';
  514. $fp = fopen($f,'r');
  515. if($fp) {
  516. $seek = fseek($fp,0-$size,SEEK_END);
  517. if($seek === 0) {
  518. fgets($fp); // throw away the first partial line
  519. $data = str_replace(array("\n","\t"),array('<br />','&nbsp;&nbsp;&nbsp;&nbsp;'),escape_tags(fread($fp,$size)));
  520. while(! feof($fp))
  521. $data .= str_replace(array("\n","\t"),array('<br />','&nbsp;&nbsp;&nbsp;&nbsp;'),escape_tags(fread($fp,4096)));
  522. }
  523. fclose($fp);
  524. }
  525. return replace_macros($t, array(
  526. '$title' => t('Administration'),
  527. '$page' => t('Logs'),
  528. '$submit' => t('Submit'),
  529. '$clear' => t('Clear'),
  530. '$data' => $data,
  531. '$baseurl' => $a->get_baseurl(),
  532. '$logname' => get_config('system','logfile'),
  533. // name, label, value, help string, extra data...
  534. '$debugging' => array('debugging', t("Debugging"),get_config('system','debugging'), ""),
  535. '$logfile' => array('logfile', t("Log file"), get_config('system','logfile'), "Must be writable by web server. Relative to your Friendika index.php."),
  536. '$loglevel' => array('loglevel', t("Log level"), get_config('system','loglevel'), "", $log_choices),
  537. ));
  538. }