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