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