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