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.
 
 
 
 
 
 

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