7 function admin_init(&$a) {
9 notice( t('Permission denied.') . EOL);
14 function admin_post(&$a){
15 if(!is_site_admin()) {
23 admin_page_site_post($a);
26 admin_page_users_post($a);
29 admin_page_logs_post($a);
34 goaway($a->get_baseurl() . '/admin' );
38 function admin_content(&$a) {
40 if(!is_site_admin()) {
48 // array( url, name, extra css classes )
50 'site' => Array($a->get_baseurl()."/admin/site/", t("Site") , "site"),
51 'users' => Array($a->get_baseurl()."/admin/users/", t("Users") , "users"),
52 'plugins'=> Array($a->get_baseurl()."/admin/plugins/", t("Plugins") , "plugins")
55 /* get plugins admin page */
57 $r = q("SELECT * FROM `hook` WHERE `hook`='plugin_admin'");
58 $aside['plugins_admin']=Array();
60 $plugin = explode("/",$h['file']); $plugin = $plugin[1];
61 $aside['plugins_admin'][] = Array($a->get_baseurl()."/admin/plugins/".$plugin, $plugin, "plugin");
64 $aside['logs'] = Array($a->get_baseurl()."/admin/logs/", t("Logs"), "logs");
66 $t = get_markup_template("admin_aside.tpl");
67 $a->page['aside'] = replace_macros( $t, array(
69 '$h_pending' => t('User registrations waiting for confirm'),
70 '$admurl'=> $a->get_baseurl()."/admin/"
84 $o = admin_page_site($a);
87 $o = admin_page_users($a);
90 $o = admin_page_plugins($a);
93 $o = admin_page_logs($a);
96 notice( t("Item not found.") );
99 $o = admin_page_summary($a);
108 function admin_page_summary(&$a) {
109 $r = q("SELECT `page-flags`, COUNT(uid) as `count` FROM `user` GROUP BY `page-flags`");
111 Array( t('Normal Account'), 0),
112 Array( t('Soapbox Account'), 0),
113 Array( t('Community/Celebrity Account'), 0),
114 Array( t('Automatic Friend Account'), 0)
117 foreach ($r as $u){ $accounts[$u['page-flags']][1] = $u['count']; $users+=$u['count']; }
120 $r = q("SELECT COUNT(id) as `count` FROM `register`");
121 $pending = $r[0]['count'];
127 $t = get_markup_template("admin_summary.tpl");
128 return replace_macros($t, array(
129 '$title' => t('Administration'),
130 '$page' => t('Summary'),
131 '$users' => Array( t('Registered users'), $users),
132 '$accounts' => $accounts,
133 '$pending' => Array( t('Pending registrations'), $pending),
134 '$version' => Array( t('Version'), FRIENDIKA_VERSION),
135 '$build' => get_config('system','build'),
136 '$plugins' => Array( t('Active plugins'), $a->plugins )
144 function admin_page_site_post(&$a){
145 if (!x($_POST,"page_site")){
150 $sitename = ((x($_POST,'sitename')) ? notags(trim($_POST['sitename'])) : '');
151 $banner = ((x($_POST,'banner')) ? trim($_POST['banner']) : false);
152 $language = ((x($_POST,'language')) ? notags(trim($_POST['language'])) : '');
153 $theme = ((x($_POST,'theme')) ? notags(trim($_POST['theme'])) : '');
154 $maximagesize = ((x($_POST,'maximagesize')) ? intval(trim($_POST['maximagesize'])) : 0);
157 $register_policy = ((x($_POST,'register_policy')) ? intval(trim($_POST['register_policy'])) : 0);
158 $register_text = ((x($_POST,'register_text')) ? notags(trim($_POST['register_text'])) : '');
160 $allowed_sites = ((x($_POST,'allowed_sites')) ? notags(trim($_POST['allowed_sites'])) : '');
161 $allowed_email = ((x($_POST,'allowed_email')) ? notags(trim($_POST['allowed_email'])) : '');
162 $block_public = ((x($_POST,'block_public')) ? True : False);
163 $force_publish = ((x($_POST,'publish_all')) ? True : False);
164 $global_directory = ((x($_POST,'directory_submit_url')) ? notags(trim($_POST['directory_submit_url'])) : '');
165 $global_search_url = ((x($_POST,'directory_search_url'))? notags(trim($_POST['directory_search_url'])) : '');
166 $no_multi_reg = ((x($_POST,'no_multi_reg')) ? True : False);
167 $no_openid = ((x($_POST,'no_openid')) ? True : False);
168 $no_gravatar = ((x($_POST,'no_gravatar')) ? True : False);
169 $no_regfullname = ((x($_POST,'no_regfullname')) ? True : False);
170 $no_utf = ((x($_POST,'no_utf')) ? True : False);
171 $rino_enc = ((x($_POST,'rino_enc')) ? True : False);
172 $verifyssl = ((x($_POST,'verifyssl')) ? True : False);
173 $proxyuser = ((x($_POST,'proxyuser')) ? notags(trim($_POST['global_search_url'])) : '');
174 $proxy = ((x($_POST,'proxy')) ? notags(trim($_POST['global_search_url'])) : '');
175 $timeout = ((x($_POST,'timeout')) ? intval(trim($_POST['timeout'])) : 60);
178 set_config('config','sitename',$sitename);
180 // don't know why, but del_config doesn't work...
181 q("DELETE FROM `config` WHERE `cat` = '%s' AND `k` = '%s' LIMIT 1",
186 set_config('system','banner', $banner);
188 set_config('system','language', $language);
189 set_config('system','theme', $theme);
190 set_config('system','maximagesize', $maximagesize);
192 set_config('config','register_policy', $register_policy);
193 set_config('config','register_text', $register_text);
194 set_config('system','allowed_sites', $allowed_sites);
195 set_config('system','allowed_email', $allowed_email);
196 set_config('system','block_public', $block_public);
197 set_config('system','publish_all', $force_publish);
198 if ($global_directory==""){
199 // don't know why, but del_config doesn't work...
200 q("DELETE FROM `config` WHERE `cat` = '%s' AND `k` = '%s' LIMIT 1",
202 dbesc("directory_submit_url")
205 set_config('system','directory_submit_url', $global_directory);
207 set_config('system','directory_search_url', $global_search_url);
208 set_config('system','block_extended_register', $no_multi_reg);
209 set_config('system','no_openid', $no_openid);
210 set_config('system','no_gravatar', $no_gravatar);
211 set_config('system','no_regfullname', $no_regfullname);
212 set_config('system','proxy', $no_utf);
213 set_config('system','rino_encrypt', $rino_enc);
214 set_config('system','verifyssl', $verifyssl);
215 set_config('system','proxyuser', $proxyuser);
216 set_config('system','proxy', $proxy);
217 set_config('system','curl_timeout', $timeout);
220 goaway($a->get_baseurl() . '/admin/site' );
221 return; // NOTREACHED
225 function admin_page_site(&$a) {
227 /* Installed langs */
228 $lang_choices = array();
229 $langs = glob('view/*/strings.php');
231 if(is_array($langs) && count($langs)) {
232 if(! in_array('view/en/strings.php',$langs))
233 $langs[] = 'view/en/';
235 foreach($langs as $l) {
236 $t = explode("/",$l);
237 $lang_choices[$t[1]] = $t[1];
241 /* Installed themes */
242 $theme_choices = array();
243 $files = glob('view/theme/*');
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;
254 $banner = get_config('system','banner');
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>');
258 //echo "<pre>"; var_dump($lang_choices); die("</pre>");
260 /* Register policy */
261 $register_choices = Array(
262 REGISTER_CLOSED => t("Closed"),
263 REGISTER_APPROVE => t("Need approvation"),
264 REGISTER_OPEN => t("Open")
267 $t = get_markup_template("admin_site.tpl");
268 return replace_macros($t, array(
269 '$title' => t('Administration'),
270 '$page' => t('Site'),
271 '$submit' => t('Submit'),
272 '$baseurl' => $a->get_baseurl(),
274 // name, label, value, help string, extra data...
275 '$sitename' => array('sitename', t("Site name"), $a->config['sitename'], ""),
276 '$banner' => array('banner', t("Banner/Logo"), $banner, ""),
277 '$language' => array('language', t("System language"), get_config('system','language'), "", $lang_choices),
278 '$theme' => array('theme', t("System theme"), get_config('system','theme'), "Default system theme (which may be over-ridden by user profiles)", $theme_choices),
280 '$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."),
282 '$register_policy' => array('register_policy', t("Register policy"), $a->config['register_policy'], "", $register_choices),
283 '$register_text' => array('register_text', t("Register text"), $a->config['register_text'], "Will be displayed prominently on the registration page."),
284 '$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"),
285 '$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"),
286 '$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."),
287 '$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."),
288 '$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."),
289 '$global_search_url'=> array('directory_search_url', t("Global directory search URL"), get_config('system','directory_search_url'), ""),
292 '$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."),
293 '$no_openid' => array('no_openid', t("No OpenID support"), get_config('system','no_openid'), "Disable OpenID support for registration and logins."),
294 '$no_gravatar' => array('no_gravatar', t("No Gravatar support"), get_config('system','no_gravatar'), ""),
295 '$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"),
296 '$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)"),
298 '$rino_enc' => array('rino_enc', t("Enable Rino encrypt"), get_config('system','rino_encrypt'),""),
299 '$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."),
300 '$proxyuser' => array('proxyuser', t("Proxy user"), get_config('system','proxyuser'), ""),
301 '$proxy' => array('proxy', t("Proxy URL"), get_config('system','proxy'), ""),
302 '$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)."),
313 function admin_page_users_post(&$a){
314 $users=array(); $pending=array();
315 foreach($_POST as $k=>$v){
316 if (substr($k,0,5)=="user_") $users[] = substr($k,5,strlen($k)-5);
317 if (substr($k,0,8)=="pending_") $users[] = substr($k,8,strlen($k)-8);
320 if (x($_POST,'page_users_block')){
321 foreach($users as $uid){
322 q("UPDATE `user` SET `blocked`=1-`blocked` WHERE `uid`=%s",
326 notice( sprintf( tt("%s user blocked", "%s users blocked", count($users)), count($users)) );
328 if (x($_POST,'page_users_delete')){
329 require_once("include/Contact.php");
330 foreach($users as $uid){
333 notice( sprintf( tt("%s user deleted", "%s users deleted", count($users)), count($users)) );
336 if (x($_POST,'page_users_approve')){
337 require_once("include/regmod.php");
338 foreach($pending as $hash){
342 if (x($_POST,'page_users_deny')){
343 require_once("include/regmod.php");
344 foreach($pending as $hash){
348 goaway($a->get_baseurl() . '/admin/users' );
349 return; // NOTREACHED
352 function admin_page_users(&$a){
355 $user = q("SELECT * FROM `user` WHERE `uid`=%d", intval($uid));
356 if (count($user)==0){
357 notice( 'User not found' . EOL);
358 goaway($a->get_baseurl() . '/admin/users' );
359 return; // NOTREACHED
364 require_once("include/Contact.php");
367 notice( sprintf(t("User '%s' deleted"), $user[0]['username']) . EOL);
370 q("UPDATE `user` SET `blocked`=%d WHERE `uid`=%s",
371 intval( 1-$user[0]['blocked'] ),
376 goaway($a->get_baseurl() . '/admin/users' );
377 return; // NOTREACHED
382 $pending = q("SELECT `register`.*, `contact`.`name`, `user`.`email`
384 LEFT JOIN `contact` ON `register`.`uid` = `contact`.`uid`
385 LEFT JOIN `user` ON `register`.`uid` = `user`.`uid`;");
389 $total = q("SELECT count(*) as total FROM `user` where 1");
391 $a->set_pager_total($total[0]['total']);
392 $a->set_pager_itemspage(100);
395 $users = q("SELECT `user` . * , `contact`.`name` , `contact`.`url` , `contact`.`micro` , `lastitem`.`changed` AS `lastitem_date`
397 SELECT `item`.`changed` , `item`.`uid`
400 ORDER BY `item`.`changed`
401 ) AS `lastitem` , `user`
402 LEFT JOIN `contact` ON `user`.`uid` = `contact`.`uid`
403 WHERE `user`.`verified` =1
404 AND `contact`.`self` =1
405 AND `lastitem`.`uid` = `user`.`uid`
406 ORDER BY `contact`.`name` LIMIT %d, %d
408 intval($a->pager['start']),
409 intval($a->pager['itemspage'])
413 function _setup_users($e){
416 t('Soapbox Account'),
417 t('Community/Celebrity Account'),
418 t('Automatic Friend Account')
420 $e['page-flags'] = $accounts[$e['page-flags']];
421 $e['register_date'] = relative_date($e['register_date']);
422 $e['login_date'] = relative_date($e['login_date']);
423 $e['lastitem_date'] = relative_date($e['lastitem_date']);
426 $users = array_map("_setup_users", $users);
428 $t = get_markup_template("admin_users.tpl");
429 $o = replace_macros($t, array(
431 '$title' => t('Administration'),
432 '$page' => t('Users'),
433 '$submit' => t('Submit'),
434 '$select_all' => t('select all'),
435 '$h_pending' => t('User registrations waiting for confirm'),
436 '$th_pending' => array( t('Request date'), t('Name'), t('Email') ),
437 '$no_pending' => t('No registrations.'),
438 '$approve' => t('Approve'),
439 '$deny' => t('Deny'),
440 '$delete' => t('Delete'),
441 '$block' => t('Block'),
442 '$unblock' => t('Unblock'),
444 '$h_users' => t('Users'),
445 '$th_users' => array( t('Name'), t('Email'), t('Register date'), t('Last login'), t('Last item'), t('Account') ),
447 '$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?'),
448 '$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?'),
452 '$baseurl' => $a->get_baseurl(),
454 '$pending' => $pending,
466 function admin_page_plugins(&$a){
472 $plugin = $a->argv[2];
473 if (!is_file("addon/$plugin/$plugin.php")){
474 notice( t("Item not found.") );
478 if (x($_GET,"a") && $_GET['a']=="t"){
479 // Toggle plugin status
480 $idx = array_search($plugin, $a->plugins);
482 unset($a->plugins[$idx]);
483 uninstall_plugin($plugin);
485 $a->plugins[] = $plugin;
486 install_plugin($plugin);
488 set_config("system","addon", implode(", ",$a->plugins));
489 goaway($a->get_baseurl() . '/admin/plugins' );
490 return; // NOTREACHED
492 // display plugin details
493 require_once('library/markdown.php');
495 if (in_array($plugin, $a->plugins)){
496 $status="on"; $action= t("Disable");
498 $status="off"; $action= t("Enable");
502 if (is_file("addon/$plugin/README.md")){
503 $readme = file_get_contents("addon/$plugin/README.md");
504 $readme = Markdown($readme);
505 } else if (is_file("addon/$plugin/README")){
506 $readme = "<pre>". file_get_contents("addon/$plugin/README") ."</pre>";
509 $t = get_markup_template("admin_plugins_details.tpl");
510 return replace_macros($t, array(
511 '$title' => t('Administration'),
512 '$page' => t('Plugins'),
513 '$toggle' => t('Toggle'),
514 '$baseurl' => $a->get_baseurl(),
516 '$plugin' => $plugin,
517 '$status' => $status,
518 '$action' => $action,
519 '$info' => get_plugin_info($plugin),
532 $files = glob("addon/*/");
534 foreach($files as $file) {
536 list($tmp, $id)=array_map("trim", explode("/",$file));
537 $info = get_plugin_info($id);
538 $plugins[] = array( $id, (in_array($id, $a->plugins)?"on":"off") , $info);
543 $t = get_markup_template("admin_plugins.tpl");
544 return replace_macros($t, array(
545 '$title' => t('Administration'),
546 '$page' => t('Plugins'),
547 '$submit' => t('Submit'),
548 '$baseurl' => $a->get_baseurl(),
550 '$plugins' => $plugins
559 function admin_page_logs_post(&$a) {
560 if (x($_POST,"page_logs")) {
562 $logfile = ((x($_POST,'logfile')) ? notags(trim($_POST['logfile'])) : '');
563 $debugging = ((x($_POST,'debugging')) ? true : false);
564 $loglevel = ((x($_POST,'loglevel')) ? intval(trim($_POST['loglevel'])) : 0);
566 set_config('system','logfile', $logfile);
567 set_config('system','debugging', $debugging);
568 set_config('system','loglevel', $loglevel);
573 goaway($a->get_baseurl() . '/admin/logs' );
574 return; // NOTREACHED
577 function admin_page_logs(&$a){
579 $log_choices = Array(
580 LOGGER_NORMAL => 'Normal',
581 LOGGER_TRACE => 'Trace',
582 LOGGER_DEBUG => 'Debug',
583 LOGGER_DATA => 'Data',
587 $t = get_markup_template("admin_logs.tpl");
589 $f = get_config('system','logfile');
590 $size = filesize($f);
597 $seek = fseek($fp,0-$size,SEEK_END);
599 fgets($fp); // throw away the first partial line
600 $data = str_replace(array("\n","\t"),array('<br />',' '),escape_tags(fread($fp,$size)));
602 $data .= str_replace(array("\n","\t"),array('<br />',' '),escape_tags(fread($fp,4096)));
608 return replace_macros($t, array(
609 '$title' => t('Administration'),
610 '$page' => t('Logs'),
611 '$submit' => t('Submit'),
612 '$clear' => t('Clear'),
614 '$baseurl' => $a->get_baseurl(),
615 '$logname' => get_config('system','logfile'),
617 // name, label, value, help string, extra data...
618 '$debugging' => array('debugging', t("Debugging"),get_config('system','debugging'), ""),
619 '$logfile' => array('logfile', t("Log file"), get_config('system','logfile'), "Must be writable by web server. Relative to your Friendika index.php."),
620 '$loglevel' => array('loglevel', t("Log level"), get_config('system','loglevel'), "", $log_choices),