]> git.mxchange.org Git - friendica.git/blob - mod/admin.php
d5f27a44a01e2823dda4cc1bcbcc2dcf4a7d3bd1
[friendica.git] / mod / admin.php
1 <?php
2  /**
3   * Friendika admin
4   */
5   
6  
7 function admin_init(&$a) {
8         if(!is_site_admin()) {
9                 notice( t('Permission denied.') . EOL);
10                 return;
11         }
12 }
13
14 function admin_post(&$a){
15         if(!is_site_admin()) {
16                 return login(false);
17         }
18         
19         // urls
20         if ($a->argc > 1){
21                 switch ($a->argv[1]){
22                         case 'site':
23                                 admin_page_site_post($a);
24                                 break;
25                         case 'logs':
26                                 admin_page_logs_post($a);
27                                 break;
28                 }
29         }
30
31         goaway($a->get_baseurl() . '/admin' );
32         return; // NOTREACHED   
33 }
34
35 function admin_content(&$a) {
36
37         if(!is_site_admin()) {
38                 return login(false);
39         }
40
41         /**
42          * Side bar links
43          */
44
45         // array( url, name, extra css classes )
46         $aside = Array(
47                 'site'   =>     Array($a->get_baseurl()."/admin/site/", t("Site") , "site"),
48                 'users'  =>     Array($a->get_baseurl()."/admin/users/", t("Users") , "users"),
49                 'plugins'=>     Array($a->get_baseurl()."/admin/plugins/", t("Plugins") , "plugins")
50         );
51         
52         /* get plugins admin page */
53         
54         $r = q("SELECT * FROM `hook` WHERE `hook`='plugin_admin'");
55         $aside['plugins_admin']=Array();
56         foreach ($r as $h){
57                 $plugin = explode("/",$h['file']); $plugin = $plugin[1];
58                 $aside['plugins_admin'][] = Array($a->get_baseurl()."/admin/plugins/".$plugin, $plugin, "plugin");
59         }
60                 
61         $aside['logs'] = Array($a->get_baseurl()."/admin/logs/", t("Logs"), "logs");
62
63         $t = get_markup_template("admin_aside.tpl");
64         $a->page['aside'] = replace_macros( $t, array(
65                         '$admin' => $aside, 
66                         '$h_pending' => t('User registrations waiting for confirm'),
67                         '$admurl'=> $a->get_baseurl()."/admin/"
68         ));
69
70
71
72         /**
73          * Page content
74          */
75         $o = '';
76         
77         // urls
78         if ($a->argc > 1){
79                 switch ($a->argv[1]){
80                         case 'site':
81                                 $o = admin_page_site($a);
82                                 break;
83                         case 'users':
84                                 $o = admin_page_users($a);
85                                 break;
86                         case 'plugins':
87                                 $o = admin_page_plugins($a);
88                                 break;
89                         case 'logs':
90                                 $o = admin_page_logs($a);
91                                 break;                          
92                         default:
93                                 notice( t("Item not found.") );
94                 }
95         } else {
96                 $o = admin_page_summary($a);
97         }
98         return $o;
99
100
101
102 /**
103  * Admin Summary Page
104  */
105 function admin_page_summary(&$a) {
106         $r = q("SELECT `page-flags`, COUNT(uid) as `count` FROM `user` GROUP BY `page-flags`");
107         $accounts = Array(
108                 Array( t('Normal Account'), 0),
109                 Array( t('Soapbox Account'), 0),
110                 Array( t('Community/Celebrity Account'), 0),
111                 Array( t('Automatic Friend Account'), 0)
112         );
113         $users=0;
114         foreach ($r as $u){ $accounts[$u['page-flags']][1] = $u['count']; $users+=$u['count']; }
115
116         
117         $r = q("SELECT COUNT(id) as `count` FROM `register`");
118         $pending = $r[0]['count'];
119         
120         
121         
122         
123         
124         $t = get_markup_template("admin_summary.tpl");
125         return replace_macros($t, array(
126                 '$title' => t('Administration'),
127                 '$page' => t('Summary'),
128                 '$users' => Array( t('Registered users'), $users),
129                 '$accounts' => $accounts,
130                 '$pending' => Array( t('Pending registrations'), $pending),
131                 '$version' => Array( t('Version'), FRIENDIKA_VERSION),
132                 '$build' =>  get_config('system','build'),
133                 '$plugins' => Array( t('Active plugins'), $a->plugins )
134         ));
135 }
136
137
138 /**
139  * Admin Site Page
140  */
141 function admin_page_site_post(&$a){
142         if (!x($_POST,"page_site")){
143                 return;
144         }
145
146         
147         $sitename                       =       ((x($_POST,'sitename'))                 ? notags(trim($_POST['sitename']))                      : '');
148         $banner                         =       ((x($_POST,'banner'))                   ? trim($_POST['banner'])                                        : false);
149         $language                       =       ((x($_POST,'language'))                 ? notags(trim($_POST['language']))                      : '');
150         $theme                          =       ((x($_POST,'theme'))                    ? notags(trim($_POST['theme']))                         : '');
151         $maximagesize           =       ((x($_POST,'maximagesize'))             ? intval(trim($_POST['maximagesize']))          :  0);
152         
153         
154         $register_policy        =       ((x($_POST,'register_policy'))  ? intval(trim($_POST['register_policy']))       :  0);
155         $register_text          =       ((x($_POST,'register_text'))    ? notags(trim($_POST['register_text']))         : '');  
156         
157         $allowed_sites          =       ((x($_POST,'allowed_sites'))    ? notags(trim($_POST['allowed_sites']))         : '');
158         $allowed_email          =       ((x($_POST,'allowed_email'))    ? notags(trim($_POST['allowed_email']))         : '');
159         $block_public           =       ((x($_POST,'block_public'))             ? True  :       False);
160         $force_publish          =       ((x($_POST,'publish_all'))              ? True  :       False);
161         $global_directory       =       ((x($_POST,'directory_submit_url'))     ? notags(trim($_POST['directory_submit_url']))  : '');
162         $global_search_url      =       ((x($_POST,'directory_search_url'))? notags(trim($_POST['directory_search_url']))       : '');
163         $no_multi_reg           =       ((x($_POST,'no_multi_reg'))             ? True  :       False);
164         $no_openid                      =       ((x($_POST,'no_openid'))                ? True  :       False);
165         $no_gravatar            =       ((x($_POST,'no_gravatar'))              ? True  :       False);
166         $no_regfullname         =       ((x($_POST,'no_regfullname'))   ? True  :       False);
167         $no_utf                         =       ((x($_POST,'no_utf'))                   ? True  :       False);
168         $rino_enc                       =       ((x($_POST,'rino_enc'))                 ? True  :       False);
169         $verifyssl                      =       ((x($_POST,'verifyssl'))                ? True  :       False);
170         $proxyuser                      =       ((x($_POST,'proxyuser'))                ? notags(trim($_POST['global_search_url']))     : '');
171         $proxy                          =       ((x($_POST,'proxy'))                    ? notags(trim($_POST['global_search_url']))     : '');
172         $timeout                        =       ((x($_POST,'timeout'))                  ? intval(trim($_POST['timeout']))               : 60);
173
174
175         set_config('config','sitename',$sitename);
176         if ($banner==""){
177                 // don't know why, but del_config doesn't work...
178                 q("DELETE FROM `config` WHERE `cat` = '%s' AND `k` = '%s' LIMIT 1",
179                         dbesc("system"),
180                         dbesc("banner")
181                 );
182         } else {
183                 set_config('system','banner', $banner);
184         }
185         set_config('system','language', $language);
186         set_config('system','theme', $theme);
187         set_config('system','maximagesize', $maximagesize);
188         
189         set_config('config','register_policy', $register_policy);
190         set_config('config','register_text', $register_text);
191         set_config('system','allowed_sites', $allowed_sites);
192         set_config('system','allowed_email', $allowed_email);
193         set_config('system','block_public', $block_public);
194         set_config('system','publish_all', $force_publish);
195         if ($global_directory==""){
196                 // don't know why, but del_config doesn't work...
197                 q("DELETE FROM `config` WHERE `cat` = '%s' AND `k` = '%s' LIMIT 1",
198                         dbesc("system"),
199                         dbesc("directory_submit_url")
200                 );
201         } else {
202                 set_config('system','directory_submit_url', $global_directory);
203         }
204         set_config('system','directory_search_url', $global_search_url);
205         set_config('system','block_extended_register', $no_multi_reg);
206         set_config('system','no_openid', $no_openid);
207         set_config('system','no_gravatar', $no_gravatar);
208         set_config('system','no_regfullname', $no_regfullname);
209         set_config('system','proxy', $no_utf);
210         set_config('system','rino_encrypt', $rino_enc);
211         set_config('system','verifyssl', $verifyssl);
212         set_config('system','proxyuser', $proxyuser);
213         set_config('system','proxy', $proxy);
214         set_config('system','curl_timeout', $timeout);
215
216
217         goaway($a->get_baseurl() . '/admin/site' );
218         return; // NOTREACHED   
219         
220 }
221  
222 function admin_page_site(&$a) {
223         
224         /* Installed langs */
225         $lang_choices = array();
226         $langs = glob('view/*/strings.php');
227         
228         if(is_array($langs) && count($langs)) {
229                 if(! in_array('view/en/strings.php',$langs))
230                         $langs[] = 'view/en/';
231                 asort($langs);
232                 foreach($langs as $l) {
233                         $t = explode("/",$l);
234                         $lang_choices[$t[1]] = $t[1];
235                 }
236         }
237         
238         /* Installed themes */
239         $theme_choices = array();
240         $files = glob('view/theme/*');
241         if($files) {
242                 foreach($files as $file) {
243                         $f = basename($file);
244                         $theme_name = ((file_exists($file . '/experimental')) ?  sprintf("%s - \x28Experimental\x29", $f) : $f);
245                         $theme_choices[$f] = $theme_name;
246                 }
247         }
248         
249         
250         /* Banner */
251         $banner = get_config('system','banner');
252         if($banner == false) 
253                 $banner = htmlspecialchars('<a href="http://project.friendika.com"><img id="logo-img" src="images/friendika-32.png" alt="logo" /></a><span id="logo-text"><a href="http://project.friendika.com">Friendika</a></span>');
254         
255         //echo "<pre>"; var_dump($lang_choices); die("</pre>");
256
257         /* Register policy */
258         $register_choices = Array(
259                 REGISTER_CLOSED => t("Closed"),
260                 REGISTER_APPROVE => t("Need approvation"),
261                 REGISTER_OPEN => t("Open")
262         ); 
263         
264         $t = get_markup_template("admin_site.tpl");
265         return replace_macros($t, array(
266                 '$title' => t('Administration'),
267                 '$page' => t('Site'),
268                 '$submit' => t('Submit'),
269                 '$baseurl' => $a->get_baseurl(),
270                                                 
271                                                                         // name, label, value, help string, extra data...
272                 '$sitename'             => array('sitename', t("Site name"), $a->config['sitename'], ""),
273                 '$banner'                       => array('banner', t("Banner/Logo"), $banner, ""),
274                 '$language'             => array('language', t("System language"), get_config('system','language'), "", $lang_choices),
275                 '$theme'                        => array('theme', t("System theme"), get_config('system','theme'), "Default system theme (which may be over-ridden by user profiles)", $theme_choices),
276
277                 '$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."),
278
279                 '$register_policy'      => array('register_policy', t("Register policy"), $a->config['register_policy'], "", $register_choices),
280                 '$register_text'        => array('register_text', t("Register text"), $a->config['register_text'], "Will be displayed prominently on the registration page."),
281                 '$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"),
282                 '$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"),
283                 '$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."),
284                 '$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."),
285                 '$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."),
286                 '$global_search_url'=> array('directory_search_url', t("Global directory search URL"), get_config('system','directory_search_url'), ""),
287                         
288                         
289                 '$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."),
290                 '$no_openid'            => array('no_openid', t("No OpenID support"), get_config('system','no_openid'), "Disable OpenID support for registration and logins."),
291                 '$no_gravatar'          => array('no_gravatar', t("No Gravatar support"), get_config('system','no_gravatar'), ""),
292                 '$no_regfullname'       => array('no_regfullname', t("No fullname check"), get_config('system','no_regfullname'), "If unchecked, force users to registrate with a space between his firsname and lastname in Full name, as an antispam measure"),
293                 '$no_utf'                       => array('no_utf', t("No UTF-8 Regular expressions"), get_config('system','proxy'), "Default is false (meaning UTF8 regular expressions are supported and working)"),
294                         
295                 '$rino_enc'                     => array('rino_enc', t("Enable Rino encrypt"), get_config('system','rino_encrypt'),""),
296                 '$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."),
297                 '$proxyuser'            => array('proxyuser', t("Proxy user"), get_config('system','proxyuser'), ""),
298                 '$proxy'                        => array('proxy', t("Proxy URL"), get_config('system','proxy'), ""),
299                 '$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)."),
300
301                         
302         ));
303
304 }
305
306
307 /**
308  * Users admin page
309  */
310  
311 function admin_page_users(&$a){
312         /* get pending */
313         $pending = q("SELECT `register`.*, `contact`.`name`, `user`.`email`
314                                  FROM `register`
315                                  LEFT JOIN `contact` ON `register`.`uid` = `contact`.`uid`
316                                  LEFT JOIN `user` ON `register`.`uid` = `user`.`uid`;");
317         
318         /* get users */
319         $users = q("SELECT `user`.*, `contact`.`name` FROM `user` 
320                                         LEFT JOIN `contact` ON `user`.`uid` = `contact`.`uid`
321                                         WHERE `user`.`verified`=1 AND `contact`.`self`=1
322                                         ORDER BY `contact`.`name`");
323                                         
324         
325         $t = get_markup_template("admin_users.tpl");
326         return replace_macros($t, array(
327                 // strings //
328                 '$title' => t('Administration'),
329                 '$page' => t('Users'),
330                 '$submit' => t('Submit'),
331                 '$select_all' => t('select all'),
332                 '$h_pending' => t('User registrations waiting for confirm'),
333                 '$th_pending' => array( t('Request date'), t('Name'), t('Email') ),
334                 '$no_pending' =>  t('No registrations.'),
335                 '$approve' => t('Approve'),
336                 '$deny' => t('Deny'),
337                 '$delete' => t('Delete'),
338                 '$block' => t('Block'),
339                 
340                 '$h_users' => t('Users'),
341                 '$th_users' => array( t('Name'), t('Nickname'), t('Email'), t('Register date'), t('Last login') ),
342
343                 // values //
344                 '$baseurl' => $a->get_baseurl(),
345
346                 '$pending' => $pending,
347                 '$users' => $users,
348         ));
349         
350 }
351
352
353 /*
354  * Plugins admin page
355  */
356
357 function admin_page_plugins(&$a){
358         
359         /**
360          * Single plugin
361          */
362         if ($a->argc == 3){
363                 $plugin = $a->argv[2];
364                 if (!is_file("addon/$plugin/$plugin.php")){
365                         notice( t("Item not found.") );
366                         return;
367                 }
368                 
369                 if (x($_GET,"a") && $_GET['a']=="t"){
370                         // Toggle plugin status
371                         $idx = array_search($plugin, $a->plugins);
372                         if ($idx){
373                                 unset($a->plugins[$idx]);
374                                 uninstall_plugin($plugin);
375                         } else {
376                                 $a->plugins[] = $plugin;
377                                 install_plugin($plugin);
378                         }
379                         set_config("system","addon", implode(", ",$a->plugins));
380                         goaway($a->get_baseurl() . '/admin/plugins' );
381                         return; // NOTREACHED   
382                 }
383                 // display plugin details
384                 require_once('library/markdown.php');
385
386                 if (in_array($plugin, $a->plugins)){
387                         $status="on"; $action= t("Disable");
388                 } else {
389                         $status="off"; $action= t("Enable");
390                 }
391                 
392                 $readme=Null;
393                 if (is_file("addon/$plugin/README.md")){
394                         $readme = file_get_contents("addon/$plugin/README.md");
395                         $readme = Markdown($readme);
396                 } else if (is_file("addon/$plugin/README")){
397                         $readme = "<pre>". file_get_contents("addon/$plugin/README") ."</pre>";
398                 } 
399                 
400                 $t = get_markup_template("admin_plugins_details.tpl");
401                 return replace_macros($t, array(
402                         '$title' => t('Administration'),
403                         '$page' => t('Plugins'),
404                         '$toggle' => t('Toggle'),
405                         '$baseurl' => $a->get_baseurl(),
406                 
407                         '$plugin' => $plugin,
408                         '$status' => $status,
409                         '$action' => $action,
410                         '$info' => get_plugin_info($plugin),
411                         
412                         '$readme' => $readme
413                 ));
414         } 
415          
416          
417         
418         /**
419          * List plugins
420          */
421         
422         $plugins = array();
423         $files = glob("addon/*/");
424         if($files) {
425                 foreach($files as $file) {      
426                         if (is_dir($file)){
427                                 list($tmp, $id)=array_map("trim", explode("/",$file));
428                                 $info = get_plugin_info($id);
429                                 $plugins[] = array( $id, (in_array($id,  $a->plugins)?"on":"off") , $info);
430                         }
431                 }
432         }
433         
434         $t = get_markup_template("admin_plugins.tpl");
435         return replace_macros($t, array(
436                 '$title' => t('Administration'),
437                 '$page' => t('Plugins'),
438                 '$submit' => t('Submit'),
439                 '$baseurl' => $a->get_baseurl(),
440         
441                 '$plugins' => $plugins
442         ));
443 }
444
445
446 /**
447  * Logs admin page
448  */
449  
450 function admin_page_logs_post(&$a) {
451         if (x($_POST,"page_logs")) {
452
453                 $logfile                =       ((x($_POST,'logfile'))          ? notags(trim($_POST['logfile']))       : '');
454                 $debugging              =       ((x($_POST,'debugging'))        ? true                                                          : false);
455                 $loglevel               =       ((x($_POST,'loglevel'))         ? intval(trim($_POST['loglevel']))      : 0);
456
457                 set_config('system','logfile', $logfile);
458                 set_config('system','debugging',  $debugging);
459                 set_config('system','loglevel', $loglevel);
460
461                 
462         }
463
464         goaway($a->get_baseurl() . '/admin/logs' );
465         return; // NOTREACHED   
466 }
467  
468 function admin_page_logs(&$a){
469         
470         $log_choices = Array(
471                 LOGGER_NORMAL => 'Normal',
472                 LOGGER_TRACE => 'Trace',
473                 LOGGER_DEBUG => 'Debug',
474                 LOGGER_DATA => 'Data',
475                 LOGGER_ALL => 'All'
476         );
477         
478         $t = get_markup_template("admin_logs.tpl");
479         return replace_macros($t, array(
480                 '$title' => t('Administration'),
481                 '$page' => t('Logs'),
482                 '$submit' => t('Submit'),
483                 '$clear' => t('Clear'),
484                 '$baseurl' => $a->get_baseurl(),
485                 '$logname' =>  get_config('system','logfile'),
486                 
487                                                                         // name, label, value, help string, extra data...
488                 '$debugging'            => array('debugging', t("Debugging"),get_config('system','debugging'), ""),
489                 '$logfile'                      => array('logfile', t("Log file"), get_config('system','logfile'), "Must be writable by web server. Relative to your Friendika index.php."),
490                 '$loglevel'             => array('loglevel', t("Log level"), get_config('system','loglevel'), "", $log_choices),
491         ));
492 }
493