]> git.mxchange.org Git - friendica.git/blob - mod/admin.php
e40c5039624b44702adcdadc1fd5a11b6ea048f0
[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                         '$admurl'=> $a->get_baseurl()."/admin/"
67         ));
68
69
70
71         /**
72          * Page content
73          */
74         $o = '';
75         
76         // urls
77         if ($a->argc > 1){
78                 switch ($a->argv[1]){
79                         case 'site':
80                                 $o = admin_page_site($a);
81                                 break;
82                         case 'users':
83                                 $o = admin_page_users($a);
84                                 break;
85                         case 'plugins':
86                                 $o = admin_page_plugins($a);
87                                 break;
88                         case 'logs':
89                                 $o = admin_page_logs($a);
90                                 break;                          
91                         default:
92                                 notice( t("Item not found.") );
93                 }
94         } else {
95                 $o = admin_page_summary($a);
96         }
97         return $o;
98
99
100
101 /**
102  * Admin Summary Page
103  */
104 function admin_page_summary(&$a) {
105         $r = q("SELECT `page-flags`, COUNT(uid) as `count` FROM `user` GROUP BY `page-flags`");
106         $accounts = Array(
107                 Array( t('Normal Account'), 0),
108                 Array( t('Soapbox Account'), 0),
109                 Array( t('Community/Celebrity Account'), 0),
110                 Array( t('Automatic Friend Account'), 0)
111         );
112         $users=0;
113         foreach ($r as $u){ $accounts[$u['page-flags']][1] = $u['count']; $users+=$u['count']; }
114
115         
116         $r = q("SELECT COUNT(id) as `count` FROM `register`");
117         $pending = $r[0]['count'];
118         
119         
120         
121         
122         
123         $t = get_markup_template("admin_summary.tpl");
124         return replace_macros($t, array(
125                 '$title' => t('Administration'),
126                 '$page' => t('Summary'),
127                 '$users' => Array( t('Registered users'), $users),
128                 '$accounts' => $accounts,
129                 '$pending' => Array( t('Pending registrations'), $pending),
130                 '$version' => Array( t('Version'), FRIENDIKA_VERSION),
131                 '$build' =>  get_config('system','build'),
132                 '$plugins' => Array( t('Active plugins'), $a->plugins )
133         ));
134 }
135
136
137 /**
138  * Admin Site Page
139  */
140 function admin_page_site_post(&$a){
141         if (!x($_POST,"page_site")){
142                 return;
143         }
144
145         
146         $sitename                       =       ((x($_POST,'sitename'))                 ? notags(trim($_POST['sitename']))                      : '');
147         $banner                         =       ((x($_POST,'banner'))                   ? trim($_POST['banner'])                                        : false);
148         $language                       =       ((x($_POST,'language'))                 ? notags(trim($_POST['language']))                      : '');
149         $theme                          =       ((x($_POST,'theme'))                    ? notags(trim($_POST['theme']))                         : '');
150         $maximagesize           =       ((x($_POST,'maximagesize'))             ? intval(trim($_POST['maximagesize']))          :  0);
151         $allowed_sites          =       ((x($_POST,'allowed_sites'))    ? notags(trim($_POST['allowed_sites']))         : '');
152         $allowed_email          =       ((x($_POST,'allowed_email'))    ? notags(trim($_POST['allowed_email']))         : '');
153         $block_public           =       ((x($_POST,'block_public'))             ? True  :       False);
154         $force_publish          =       ((x($_POST,'publish_all'))              ? True  :       False);
155         $global_directory       =       ((x($_POST,'directory_submit_url'))     ? notags(trim($_POST['directory_submit_url']))  : '');
156         $global_search_url      =       ((x($_POST,'directory_search_url'))? notags(trim($_POST['directory_search_url']))       : '');
157         $no_multi_reg           =       ((x($_POST,'no_multi_reg'))             ? True  :       False);
158         $no_openid                      =       ((x($_POST,'no_openid'))                ? True  :       False);
159         $no_gravatar            =       ((x($_POST,'no_gravatar'))              ? True  :       False);
160         $no_regfullname         =       ((x($_POST,'no_regfullname'))   ? True  :       False);
161         $no_utf                         =       ((x($_POST,'no_utf'))                   ? True  :       False);
162         $rino_enc                       =       ((x($_POST,'rino_enc'))                 ? True  :       False);
163         $verifyssl                      =       ((x($_POST,'verifyssl'))                ? True  :       False);
164         $proxyuser                      =       ((x($_POST,'proxyuser'))                ? notags(trim($_POST['global_search_url']))     : '');
165         $proxy                          =       ((x($_POST,'proxy'))                    ? notags(trim($_POST['global_search_url']))     : '');
166         $timeout                        =       ((x($_POST,'timeout'))                  ? intval(trim($_POST['timeout']))               : 60);
167
168
169         $a->config['sitename'] = $sitename;
170         if ($banner==""){
171                 // don't know why, but del_config doesn't work...
172                 q("DELETE FROM `config` WHERE `cat` = '%s' AND `k` = '%s' LIMIT 1",
173                         dbesc("system"),
174                         dbesc("banner")
175                 );
176         } else {
177                 set_config('system','banner', $banner);
178         }
179         set_config('system','language', $language);
180         set_config('system','theme', $theme);
181         set_config('system','maximagesize', $maximagesize);
182         set_config('system','allowed_sites', $allowed_sites);
183         set_config('system','allowed_email', $allowed_email);
184         set_config('system','block_public', $block_public);
185         set_config('system','publish_all', $force_publish);
186         if ($global_directory==""){
187                 // don't know why, but del_config doesn't work...
188                 q("DELETE FROM `config` WHERE `cat` = '%s' AND `k` = '%s' LIMIT 1",
189                         dbesc("system"),
190                         dbesc("directory_submit_url")
191                 );
192         } else {
193                 set_config('system','directory_submit_url', $global_directory);
194         }
195         set_config('system','directory_search_url', $global_search_url);
196         set_config('system','block_extended_register', $no_multi_reg);
197         set_config('system','no_openid', $no_openid);
198         set_config('system','no_gravatar', $no_gravatar);
199         set_config('system','no_regfullname', $no_regfullname);
200         set_config('system','proxy', $no_utf);
201         set_config('system','rino_encrypt', $rino_enc);
202         set_config('system','verifyssl', $verifyssl);
203         set_config('system','proxyuser', $proxyuser);
204         set_config('system','proxy', $proxy);
205         set_config('system','curl_timeout', $timeout);
206
207         $r = q("SELECT * FROM `config` WHERE `cat`='config' AND `k`='sitename'");
208         if (count($r)>0){
209                 q("UPDATE `config` SET `v`='%s' WHERE `cat`='config' AND `k`='sitename'",
210                         dbesc($a->config['sitename'])
211                 );
212         } else {
213                 q("INSERT INTO `config`  ( `cat`, `k`, `v` ) VALUES ( 'config', 'sitename', '%s' )",
214                         dbesc($a->config['sitename'])
215                 );
216         }
217         
218
219
220         goaway($a->get_baseurl() . '/admin/site' );
221         return; // NOTREACHED   
222         
223 }
224  
225 function admin_page_site(&$a) {
226         
227         /* Installed langs */
228         $lang_choices = array();
229         $langs = glob('view/*/strings.php');
230         
231         if(is_array($langs) && count($langs)) {
232                 if(! in_array('view/en/strings.php',$langs))
233                         $langs[] = 'view/en/';
234                 asort($langs);
235                 foreach($langs as $l) {
236                         $t = explode("/",$l);
237                         $lang_choices[$t[1]] = $t[1];
238                 }
239         }
240         
241         /* Installed themes */
242         $theme_choices = array();
243         $files = glob('view/theme/*');
244         if($files) {
245                 foreach($files as $file) {
246                         $f = basename($file);
247                         $theme_name = ((file_exists($file . '/experimental')) ?  sprintf("%s - \x28Experimental\x29", $f) : $f);
248                         $theme_choices[$f] = $theme_name;
249                 }
250         }
251         
252         
253         /* Banner */
254         $banner = get_config('system','banner');
255         if($banner == false) 
256                 $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>');
257         
258         //echo "<pre>"; var_dump($lang_choices); die("</pre>");
259
260
261         
262         $t = get_markup_template("admin_site.tpl");
263         return replace_macros($t, array(
264                 '$title' => t('Administration'),
265                 '$page' => t('Site'),
266                 '$submit' => t('Submit'),
267                 '$baseurl' => $a->get_baseurl(),
268                                                 
269                                                                         // name, label, value, help string, extra data...
270                 '$sitename'             => array('sitename', t("Site name"), $a->config['sitename'], ""),
271                 '$banner'                       => array('banner', t("Banner/Logo"), $banner, ""),
272                 '$language'             => array('language', t("System language"), get_config('system','language'), "", $lang_choices),
273                 '$theme'                        => array('theme', t("System theme"), get_config('system','theme'), "Default system theme (which may be over-ridden by user profiles)", $theme_choices),
274
275                 '$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."),
276
277                 '$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"),
278                 '$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"),
279                 '$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."),
280                 '$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."),
281                 '$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."),
282                 '$global_search_url'=> array('directory_search_url', t("Global directory search URL"), get_config('system','directory_search_url'), ""),
283                         
284                         
285                 '$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."),
286                 '$no_openid'            => array('no_openid', t("No OpenID support"), get_config('system','no_openid'), "Disable OpenID support for registration and logins."),
287                 '$no_gravatar'          => array('no_gravatar', t("No Gravatar support"), get_config('system','no_gravatar'), ""),
288                 '$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"),
289                 '$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)"),
290                         
291                 '$rino_enc'                     => array('rino_enc', t("Enable Rino encrypt"), get_config('system','rino_encrypt'),""),
292                 '$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."),
293                 '$proxyuser'            => array('proxyuser', t("Proxy user"), get_config('system','proxyuser'), ""),
294                 '$proxy'                        => array('proxy', t("Proxy URL"), get_config('system','proxy'), ""),
295                 '$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)."),
296
297                         
298         ));
299
300 }
301
302
303 /**
304  * Users admin page
305  */
306  
307 function admin_page_users(&$a){
308         return ":)";
309 }
310
311
312 /*
313  * Plugins admin page
314  */
315
316 function admin_page_plugins(&$a){
317         
318         /**
319          * Single plugin
320          */
321         if ($a->argc == 3){
322                 $plugin = $a->argv[2];
323                 if (!is_file("addon/$plugin/$plugin.php")){
324                         notice( t("Item not found.") );
325                         return;
326                 }
327                 
328                 if (x($_GET,"a") && $_GET['a']=="t"){
329                         // Toggle plugin status
330                         $idx = array_search($plugin, $a->plugins);
331                         if ($idx){
332                                 unset($a->plugins[$idx]);
333                                 uninstall_plugin($plugin);
334                         } else {
335                                 $a->plugins[] = $plugin;
336                                 install_plugin($plugin);
337                         }
338                         set_config("system","addon", implode(", ",$a->plugins));
339                         goaway($a->get_baseurl() . '/admin/plugins' );
340                         return; // NOTREACHED   
341                 }
342                 // display plugin details
343                 
344
345                 if (in_array($plugin, $a->plugins)){
346                         $status="on"; $action= t("Disable");
347                 } else {
348                         $status="off"; $action= t("Enable");
349                 }
350                 
351                 $t = get_markup_template("admin_plugins_details.tpl");
352                 return replace_macros($t, array(
353                         '$title' => t('Administration'),
354                         '$page' => t('Plugins'),
355                         '$toggle' => t('Toggle'),
356                         '$baseurl' => $a->get_baseurl(),
357                 
358                         '$plugin' => $plugin,
359                         '$status' => $status,
360                         '$action' => $action
361                 ));
362         } 
363          
364          
365         
366         /**
367          * List plugins
368          */
369         
370         $plugins = array();
371         $files = glob("addon/*/");
372         if($files) {
373                 foreach($files as $file) {      
374                         if (is_dir($file)){
375                                 list($tmp, $id)=array_map("trim", explode("/",$file));
376                                 // TODO: plugins info
377                                 $name=$author=$description=$homepage="";
378                                 $plugins[] = array( $id, (in_array($id,  $a->plugins)?"on":"off") , $name, $author, $description, $homepage);
379                         }
380                 }
381         }
382         
383         $t = get_markup_template("admin_plugins.tpl");
384         return replace_macros($t, array(
385                 '$title' => t('Administration'),
386                 '$page' => t('Plugins'),
387                 '$submit' => t('Submit'),
388                 '$baseurl' => $a->get_baseurl(),
389         
390                 '$plugins' => $plugins
391         ));
392 }
393
394
395 /**
396  * Logs admin page
397  */
398  
399 function admin_page_logs_post(&$a) {
400         if (x($_POST,"page_logs")) {
401
402                 $logfile                =       ((x($_POST,'logfile'))          ? notags(trim($_POST['logfile']))       : '');
403                 $debugging              =       ((x($_POST,'debugging'))        ? true                                                          : false);
404                 $loglevel               =       ((x($_POST,'loglevel'))         ? intval(trim($_POST['loglevel']))      : 0);
405
406                 set_config('system','logfile', $logfile);
407                 set_config('system','debugging',  $debugging);
408                 set_config('system','loglevel', $loglevel);
409
410                 
411         }
412
413         goaway($a->get_baseurl() . '/admin/logs' );
414         return; // NOTREACHED   
415 }
416  
417 function admin_page_logs(&$a){
418         
419         $log_choices = Array(
420                 LOGGER_NORMAL => 'Normal',
421                 LOGGER_TRACE => 'Trace',
422                 LOGGER_DEBUG => 'Debug',
423                 LOGGER_DATA => 'Data',
424                 LOGGER_ALL => 'All'
425         );
426         
427         $t = get_markup_template("admin_logs.tpl");
428         return replace_macros($t, array(
429                 '$title' => t('Administration'),
430                 '$page' => t('Logs'),
431                 '$submit' => t('Submit'),
432                 '$clear' => t('Clear'),
433                 '$baseurl' => $a->get_baseurl(),
434                 '$logname' =>  get_config('system','logfile'),
435                 
436                                                                         // name, label, value, help string, extra data...
437                 '$debugging'            => array('debugging', t("Debugging"),get_config('system','debugging'), ""),
438                 '$logfile'                      => array('logfile', t("Log file"), get_config('system','logfile'), "Must be writable by web server. Relative to your Friendika index.php."),
439                 '$loglevel'             => array('loglevel', t("Log level"), get_config('system','loglevel'), "", $log_choices),
440         ));
441 }
442