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