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