6 require_once("include/remoteupdate.php");
8 function admin_post(&$a){
17 admin_page_site_post($a);
20 admin_page_users_post($a);
24 is_file("addon/".$a->argv[2]."/".$a->argv[2].".php")){
25 @include_once("addon/".$a->argv[2]."/".$a->argv[2].".php");
26 if(function_exists($a->argv[2].'_plugin_admin_post')) {
27 $func = $a->argv[2].'_plugin_admin_post';
31 goaway($a->get_baseurl() . '/admin/plugins/' . $a->argv[2] );
35 admin_page_logs_post($a);
38 admin_page_remoteupdate_post($a);
43 goaway($a->get_baseurl() . '/admin' );
47 function admin_content(&$a) {
49 if(!is_site_admin()) {
57 // array( url, name, extra css classes )
59 'site' => Array($a->get_baseurl()."/admin/site/", t("Site") , "site"),
60 'users' => Array($a->get_baseurl()."/admin/users/", t("Users") , "users"),
61 'plugins'=> Array($a->get_baseurl()."/admin/plugins/", t("Plugins") , "plugins"),
62 'update' => Array($a->get_baseurl()."/admin/update/", t("Update") , "update")
65 /* get plugins admin page */
67 $r = q("SELECT * FROM `addon` WHERE `plugin_admin`=1");
68 $aside['plugins_admin']=Array();
71 $aside['plugins_admin'][] = Array($a->get_baseurl()."/admin/plugins/".$plugin, $plugin, "plugin");
72 // temp plugins with admin
73 $a->plugins_admin[] = $plugin;
76 $aside['logs'] = Array($a->get_baseurl()."/admin/logs/", t("Logs"), "logs");
78 $t = get_markup_template("admin_aside.tpl");
79 $a->page['aside'] = replace_macros( $t, array(
81 '$h_pending' => t('User registrations waiting for confirmation'),
82 '$admurl'=> $a->get_baseurl()."/admin/"
96 $o = admin_page_site($a);
99 $o = admin_page_users($a);
102 $o = admin_page_plugins($a);
105 $o = admin_page_logs($a);
108 $o = admin_page_remoteupdate($a);
111 notice( t("Item not found.") );
114 $o = admin_page_summary($a);
123 function admin_page_summary(&$a) {
124 $r = q("SELECT `page-flags`, COUNT(uid) as `count` FROM `user` GROUP BY `page-flags`");
126 Array( t('Normal Account'), 0),
127 Array( t('Soapbox Account'), 0),
128 Array( t('Community/Celebrity Account'), 0),
129 Array( t('Automatic Friend Account'), 0)
132 foreach ($r as $u){ $accounts[$u['page-flags']][1] = $u['count']; $users+=$u['count']; }
135 $r = q("SELECT COUNT(id) as `count` FROM `register`");
136 $pending = $r[0]['count'];
142 $t = get_markup_template("admin_summary.tpl");
143 return replace_macros($t, array(
144 '$title' => t('Administration'),
145 '$page' => t('Summary'),
146 '$users' => Array( t('Registered users'), $users),
147 '$accounts' => $accounts,
148 '$pending' => Array( t('Pending registrations'), $pending),
149 '$version' => Array( t('Version'), FRIENDICA_VERSION),
150 '$build' => get_config('system','build'),
151 '$plugins' => Array( t('Active plugins'), $a->plugins )
159 function admin_page_site_post(&$a){
160 if (!x($_POST,"page_site")){
165 $sitename = ((x($_POST,'sitename')) ? notags(trim($_POST['sitename'])) : '');
166 $banner = ((x($_POST,'banner')) ? trim($_POST['banner']) : false);
167 $language = ((x($_POST,'language')) ? notags(trim($_POST['language'])) : '');
168 $theme = ((x($_POST,'theme')) ? notags(trim($_POST['theme'])) : '');
169 $maximagesize = ((x($_POST,'maximagesize')) ? intval(trim($_POST['maximagesize'])) : 0);
172 $register_policy = ((x($_POST,'register_policy')) ? intval(trim($_POST['register_policy'])) : 0);
173 $abandon_days = ((x($_POST,'abandon_days')) ? intval(trim($_POST['abandon_days'])) : 0);
175 $register_text = ((x($_POST,'register_text')) ? notags(trim($_POST['register_text'])) : '');
177 $allowed_sites = ((x($_POST,'allowed_sites')) ? notags(trim($_POST['allowed_sites'])) : '');
178 $allowed_email = ((x($_POST,'allowed_email')) ? notags(trim($_POST['allowed_email'])) : '');
179 $block_public = ((x($_POST,'block_public')) ? True : False);
180 $force_publish = ((x($_POST,'publish_all')) ? True : False);
181 $global_directory = ((x($_POST,'directory_submit_url')) ? notags(trim($_POST['directory_submit_url'])) : '');
182 $no_multi_reg = ((x($_POST,'no_multi_reg')) ? True : False);
183 $no_openid = !((x($_POST,'no_openid')) ? True : False);
184 $no_gravatar = !((x($_POST,'no_gravatar')) ? True : False);
185 $no_regfullname = !((x($_POST,'no_regfullname')) ? True : False);
186 $no_utf = !((x($_POST,'no_utf')) ? True : False);
187 $no_community_page = !((x($_POST,'no_community_page')) ? True : False);
189 $verifyssl = ((x($_POST,'verifyssl')) ? True : False);
190 $proxyuser = ((x($_POST,'proxyuser')) ? notags(trim($_POST['proxyuser'])) : '');
191 $proxy = ((x($_POST,'proxy')) ? notags(trim($_POST['proxy'])) : '');
192 $timeout = ((x($_POST,'timeout')) ? intval(trim($_POST['timeout'])) : 60);
193 $dfrn_only = ((x($_POST,'dfrn_only')) ? True : False);
194 $ostatus_disabled = !((x($_POST,'ostatus_disabled')) ? True : False);
195 $diaspora_enabled = ((x($_POST,'diaspora_enabled')) ? True : False);
198 set_config('config','sitename',$sitename);
200 // don't know why, but del_config doesn't work...
201 q("DELETE FROM `config` WHERE `cat` = '%s' AND `k` = '%s' LIMIT 1",
206 set_config('system','banner', $banner);
208 set_config('system','language', $language);
209 set_config('system','theme', $theme);
210 set_config('system','maximagesize', $maximagesize);
212 set_config('config','register_policy', $register_policy);
213 set_config('system','account_abandon_days', $abandon_days);
214 set_config('config','register_text', $register_text);
215 set_config('system','allowed_sites', $allowed_sites);
216 set_config('system','allowed_email', $allowed_email);
217 set_config('system','block_public', $block_public);
218 set_config('system','publish_all', $force_publish);
219 if ($global_directory==""){
220 // don't know why, but del_config doesn't work...
221 q("DELETE FROM `config` WHERE `cat` = '%s' AND `k` = '%s' LIMIT 1",
223 dbesc("directory_submit_url")
226 set_config('system','directory_submit_url', $global_directory);
228 set_config('system','directory_search_url', $global_search_url);
229 set_config('system','block_extended_register', $no_multi_reg);
230 set_config('system','no_openid', $no_openid);
231 set_config('system','no_gravatar', $no_gravatar);
232 set_config('system','no_regfullname', $no_regfullname);
233 set_config('system','no_community_page', $no_community_page);
234 set_config('system','no_utf', $no_utf);
235 set_config('system','verifyssl', $verifyssl);
236 set_config('system','proxyuser', $proxyuser);
237 set_config('system','proxy', $proxy);
238 set_config('system','curl_timeout', $timeout);
239 set_config('system','dfrn_only', $dfrn_only);
240 set_config('system','ostatus_disabled', $ostatus_disabled);
241 set_config('system','diaspora_enabled', $diaspora_enabled);
243 info( t('Site settings updated.') . EOL);
244 goaway($a->get_baseurl() . '/admin/site' );
245 return; // NOTREACHED
249 function admin_page_site(&$a) {
251 /* Installed langs */
252 $lang_choices = array();
253 $langs = glob('view/*/strings.php');
255 if(is_array($langs) && count($langs)) {
256 if(! in_array('view/en/strings.php',$langs))
257 $langs[] = 'view/en/';
259 foreach($langs as $l) {
260 $t = explode("/",$l);
261 $lang_choices[$t[1]] = $t[1];
265 /* Installed themes */
266 $theme_choices = array();
267 $files = glob('view/theme/*');
269 foreach($files as $file) {
270 $f = basename($file);
271 $theme_name = ((file_exists($file . '/experimental')) ? sprintf("%s - \x28Experimental\x29", $f) : $f);
272 $theme_choices[$f] = $theme_name;
278 $banner = get_config('system','banner');
280 $banner = '<a href="http://friendica.com"><img id="logo-img" src="images/friendica-32.png" alt="logo" /></a><span id="logo-text"><a href="http://friendica.com">Friendica</a></span>';
281 $banner = htmlspecialchars($banner);
283 //echo "<pre>"; var_dump($lang_choices); die("</pre>");
285 /* Register policy */
286 $register_choices = Array(
287 REGISTER_CLOSED => t("Closed"),
288 REGISTER_APPROVE => t("Requires approval"),
289 REGISTER_OPEN => t("Open")
292 $t = get_markup_template("admin_site.tpl");
293 return replace_macros($t, array(
294 '$title' => t('Administration'),
295 '$page' => t('Site'),
296 '$submit' => t('Submit'),
297 '$registration' => t('Registration'),
298 '$upload' => t('File upload'),
299 '$corporate' => t('Policies'),
300 '$advanced' => t('Advanced'),
302 '$baseurl' => $a->get_baseurl(),
303 // name, label, value, help string, extra data...
304 '$sitename' => array('sitename', t("Site name"), htmlentities($a->config['sitename'], ENT_QUOTES), ""),
305 '$banner' => array('banner', t("Banner/Logo"), $banner, ""),
306 '$language' => array('language', t("System language"), get_config('system','language'), "", $lang_choices),
307 '$theme' => array('theme', t("System theme"), get_config('system','theme'), "Default system theme (which may be over-ridden by user profiles)", $theme_choices),
309 '$maximagesize' => array('maximagesize', t("Maximum image size"), get_config('system','maximagesize'), "Maximum size in bytes of uploaded images. Default is 0, which means no limits."),
311 '$register_policy' => array('register_policy', t("Register policy"), $a->config['register_policy'], "", $register_choices),
312 '$register_text' => array('register_text', t("Register text"), htmlentities($a->config['register_text'], ENT_QUOTES), "Will be displayed prominently on the registration page."),
313 '$abandon_days' => array('abandon_days', t('Accounts abandoned after x days'), get_config('system','account_abandon_days'), t('Will not waste system resources polling external sites for abandonded accounts. Enter 0 for no time limit.')),
314 '$allowed_sites' => array('allowed_sites', t("Allowed friend domains"), get_config('system','allowed_sites'), "Comma separated list of domains which are allowed to establish friendships with this site. Wildcards are accepted. Empty to allow any domains"),
315 '$allowed_email' => array('allowed_email', t("Allowed email domains"), get_config('system','allowed_email'), "Comma separated list of domains which are allowed in email addresses for registrations to this site. Wildcards are accepted. Empty to allow any domains"),
316 '$block_public' => array('block_public', t("Block public"), get_config('system','block_public'), "Check to block public access to all otherwise public personal pages on this site unless you are currently logged in."),
317 '$force_publish' => array('publish_all', t("Force publish"), get_config('system','publish_all'), "Check to force all profiles on this site to be listed in the site directory."),
318 '$global_directory' => array('directory_submit_url', t("Global directory update URL"), get_config('system','directory_submit_url'), "URL to update the global directory. If this is not set, the global directory is completely unavailable to the application."),
320 '$no_multi_reg' => array('no_multi_reg', t("Block multiple registrations"), get_config('system','block_extended_register'), "Disallow users to register additional accounts for use as pages."),
321 '$no_openid' => array('no_openid', t("OpenID support"), !get_config('system','no_openid'), "OpenID support for registration and logins."),
322 '$no_gravatar' => array('no_gravatar', t("Gravatar support"), !get_config('system','no_gravatar'), "Search new user's photo on Gravatar."),
323 '$no_regfullname' => array('no_regfullname', t("Fullname check"), !get_config('system','no_regfullname'), "Force users to register with a space between firstname and lastname in Full name, as an antispam measure"),
324 '$no_utf' => array('no_utf', t("UTF-8 Regular expressions"), !get_config('system','no_utf'), "Use PHP UTF8 regular expressions"),
325 '$no_community_page' => array('no_community_page', t("Show Community Page"), !get_config('system','no_community_page'), "Display a Community page showing all recent public postings on this site."),
326 '$ostatus_disabled' => array('ostatus_disabled', t("Enable OStatus support"), !get_config('system','ostatus_disable'), "Provide built-in OStatus \x28identi.ca, status.net, etc.\x29 compatibility. All communications in OStatus are public, so privacy warnings will be occasionally displayed."),
327 '$diaspora_enabled' => array('diaspora_enabled', t("Enable Diaspora support"), get_config('system','diaspora_enabled'), "Provide built-in Diaspora network compatibility."),
328 '$dfrn_only' => array('dfrn_only', t('Only allow Friendica contacts'), get_config('system','dfrn_only'), "All contacts must use Friendica protocols. All other built-in communication protocols disabled."),
329 '$verifyssl' => array('verifyssl', t("Verify SSL"), get_config('system','verifyssl'), "If you wish, you can turn on strict certificate checking. This will mean you cannot connect (at all) to self-signed SSL sites."),
330 '$proxyuser' => array('proxyuser', t("Proxy user"), get_config('system','proxyuser'), ""),
331 '$proxy' => array('proxy', t("Proxy URL"), get_config('system','proxy'), ""),
332 '$timeout' => array('timeout', t("Network timeout"), (x(get_config('system','curl_timeout'))?get_config('system','curl_timeout'):60), "Value is in seconds. Set to 0 for unlimited (not recommended)."),
343 function admin_page_users_post(&$a){
344 $pending = ( x($_POST, 'pending') ? $_POST['pending'] : Array() );
345 $users = ( x($_POST, 'user') ? $_POST['user'] : Array() );
347 if (x($_POST,'page_users_block')){
348 foreach($users as $uid){
349 q("UPDATE `user` SET `blocked`=1-`blocked` WHERE `uid`=%s",
353 notice( sprintf( tt("%s user blocked", "%s users blocked/unblocked", count($users)), count($users)) );
355 if (x($_POST,'page_users_delete')){
356 require_once("include/Contact.php");
357 foreach($users as $uid){
360 notice( sprintf( tt("%s user deleted", "%s users deleted", count($users)), count($users)) );
363 if (x($_POST,'page_users_approve')){
364 require_once("mod/regmod.php");
365 foreach($pending as $hash){
369 if (x($_POST,'page_users_deny')){
370 require_once("mod/regmod.php");
371 foreach($pending as $hash){
375 goaway($a->get_baseurl() . '/admin/users' );
376 return; // NOTREACHED
379 function admin_page_users(&$a){
382 $user = q("SELECT * FROM `user` WHERE `uid`=%d", intval($uid));
383 if (count($user)==0){
384 notice( 'User not found' . EOL);
385 goaway($a->get_baseurl() . '/admin/users' );
386 return; // NOTREACHED
391 require_once("include/Contact.php");
394 notice( sprintf(t("User '%s' deleted"), $user[0]['username']) . EOL);
397 q("UPDATE `user` SET `blocked`=%d WHERE `uid`=%s",
398 intval( 1-$user[0]['blocked'] ),
401 notice( sprintf( ($user[0]['blocked']?t("User '%s' unblocked"):t("User '%s' blocked")) , $user[0]['username']) . EOL);
404 goaway($a->get_baseurl() . '/admin/users' );
405 return; // NOTREACHED
410 $pending = q("SELECT `register`.*, `contact`.`name`, `user`.`email`
412 LEFT JOIN `contact` ON `register`.`uid` = `contact`.`uid`
413 LEFT JOIN `user` ON `register`.`uid` = `user`.`uid`;");
417 $total = q("SELECT count(*) as total FROM `user` where 1");
419 $a->set_pager_total($total[0]['total']);
420 $a->set_pager_itemspage(100);
423 $users = q("SELECT `user` . * , `contact`.`name` , `contact`.`url` , `contact`.`micro`, `lastitem`.`lastitem_date`
425 (SELECT MAX(`item`.`changed`) as `lastitem_date`, `item`.`uid`
427 WHERE `item`.`type` = 'wall'
428 GROUP BY `item`.`uid`) AS `lastitem`
429 RIGHT OUTER JOIN `user` ON `user`.`uid` = `lastitem`.`uid`,
432 `user`.`uid` = `contact`.`uid`
433 AND `user`.`verified` =1
434 AND `contact`.`self` =1
435 ORDER BY `contact`.`name` LIMIT %d, %d
437 intval($a->pager['start']),
438 intval($a->pager['itemspage'])
441 function _setup_users($e){
444 t('Soapbox Account'),
445 t('Community/Celebrity Account'),
446 t('Automatic Friend Account')
448 $e['page-flags'] = $accounts[$e['page-flags']];
449 $e['register_date'] = relative_date($e['register_date']);
450 $e['login_date'] = relative_date($e['login_date']);
451 $e['lastitem_date'] = relative_date($e['lastitem_date']);
454 $users = array_map("_setup_users", $users);
456 $t = get_markup_template("admin_users.tpl");
457 $o = replace_macros($t, array(
459 '$title' => t('Administration'),
460 '$page' => t('Users'),
461 '$submit' => t('Submit'),
462 '$select_all' => t('select all'),
463 '$h_pending' => t('User registrations waiting for confirm'),
464 '$th_pending' => array( t('Request date'), t('Name'), t('Email') ),
465 '$no_pending' => t('No registrations.'),
466 '$approve' => t('Approve'),
467 '$deny' => t('Deny'),
468 '$delete' => t('Delete'),
469 '$block' => t('Block'),
470 '$unblock' => t('Unblock'),
472 '$h_users' => t('Users'),
473 '$th_users' => array( t('Name'), t('Email'), t('Register date'), t('Last login'), t('Last item'), t('Account') ),
475 '$confirm_delete_multi' => t('Selected users will be deleted!\n\nEverything these users had posted on this site will be permanently deleted!\n\nAre you sure?'),
476 '$confirm_delete' => t('The user {0} will be deleted!\n\nEverything this user has posted on this site will be permanently deleted!\n\nAre you sure?'),
480 '$baseurl' => $a->get_baseurl(),
482 '$pending' => $pending,
494 function admin_page_plugins(&$a){
500 $plugin = $a->argv[2];
501 if (!is_file("addon/$plugin/$plugin.php")){
502 notice( t("Item not found.") );
506 if (x($_GET,"a") && $_GET['a']=="t"){
507 // Toggle plugin status
508 $idx = array_search($plugin, $a->plugins);
510 unset($a->plugins[$idx]);
511 uninstall_plugin($plugin);
512 info( sprintf( t("Plugin %s disabled."), $plugin ) );
514 $a->plugins[] = $plugin;
515 install_plugin($plugin);
516 info( sprintf( t("Plugin %s enabled."), $plugin ) );
518 set_config("system","addon", implode(", ",$a->plugins));
519 goaway($a->get_baseurl() . '/admin/plugins' );
520 return; // NOTREACHED
522 // display plugin details
523 require_once('library/markdown.php');
525 if (in_array($plugin, $a->plugins)){
526 $status="on"; $action= t("Disable");
528 $status="off"; $action= t("Enable");
532 if (is_file("addon/$plugin/README.md")){
533 $readme = file_get_contents("addon/$plugin/README.md");
534 $readme = Markdown($readme);
535 } else if (is_file("addon/$plugin/README")){
536 $readme = "<pre>". file_get_contents("addon/$plugin/README") ."</pre>";
540 if (is_array($a->plugins_admin) && in_array($plugin, $a->plugins_admin)){
541 @require_once("addon/$plugin/$plugin.php");
542 $func = $plugin.'_plugin_admin';
543 $func($a, $admin_form);
546 $t = get_markup_template("admin_plugins_details.tpl");
547 return replace_macros($t, array(
548 '$title' => t('Administration'),
549 '$page' => t('Plugins'),
550 '$toggle' => t('Toggle'),
551 '$settings' => t('Settings'),
552 '$baseurl' => $a->get_baseurl(),
554 '$plugin' => $plugin,
555 '$status' => $status,
556 '$action' => $action,
557 '$info' => get_plugin_info($plugin),
559 '$admin_form' => $admin_form,
572 $files = glob("addon/*/");
574 foreach($files as $file) {
576 list($tmp, $id)=array_map("trim", explode("/",$file));
577 $info = get_plugin_info($id);
578 $plugins[] = array( $id, (in_array($id, $a->plugins)?"on":"off") , $info);
583 $t = get_markup_template("admin_plugins.tpl");
584 return replace_macros($t, array(
585 '$title' => t('Administration'),
586 '$page' => t('Plugins'),
587 '$submit' => t('Submit'),
588 '$baseurl' => $a->get_baseurl(),
590 '$plugins' => $plugins
599 function admin_page_logs_post(&$a) {
600 if (x($_POST,"page_logs")) {
602 $logfile = ((x($_POST,'logfile')) ? notags(trim($_POST['logfile'])) : '');
603 $debugging = ((x($_POST,'debugging')) ? true : false);
604 $loglevel = ((x($_POST,'loglevel')) ? intval(trim($_POST['loglevel'])) : 0);
606 set_config('system','logfile', $logfile);
607 set_config('system','debugging', $debugging);
608 set_config('system','loglevel', $loglevel);
613 info( t("Log settings updated.") );
614 goaway($a->get_baseurl() . '/admin/logs' );
615 return; // NOTREACHED
618 function admin_page_logs(&$a){
620 $log_choices = Array(
621 LOGGER_NORMAL => 'Normal',
622 LOGGER_TRACE => 'Trace',
623 LOGGER_DEBUG => 'Debug',
624 LOGGER_DATA => 'Data',
628 $t = get_markup_template("admin_logs.tpl");
630 $f = get_config('system','logfile');
631 $size = filesize($f);
632 if($size > 5000000 || $size < 0)
638 $seek = fseek($fp,0-$size,SEEK_END);
640 fgets($fp); // throw away the first partial line
641 $data = escape_tags(fread($fp,$size));
643 $data .= escape_tags(fread($fp,4096));
649 return replace_macros($t, array(
650 '$title' => t('Administration'),
651 '$page' => t('Logs'),
652 '$submit' => t('Submit'),
653 '$clear' => t('Clear'),
655 '$baseurl' => $a->get_baseurl(),
656 '$logname' => get_config('system','logfile'),
658 // name, label, value, help string, extra data...
659 '$debugging' => array('debugging', t("Debugging"),get_config('system','debugging'), ""),
660 '$logfile' => array('logfile', t("Log file"), get_config('system','logfile'), t("Must be writable by web server. Relative to your Friendica top-level directory.")),
661 '$loglevel' => array('loglevel', t("Log level"), get_config('system','loglevel'), "", $log_choices),
665 function admin_page_remoteupdate_post(&$a) {
666 // this function should be called via ajax post
667 if(!is_site_admin()) {
672 if (x($_POST,'remotefile') && $_POST['remotefile']!=""){
673 $remotefile = $_POST['remotefile'];
674 $ftpdata = (x($_POST['ftphost'])?$_POST:false);
675 doUpdate($remotefile, $ftpdata);
677 echo "No remote file to download. Abort!";
683 function admin_page_remoteupdate(&$a) {
684 if(!is_site_admin()) {
688 $canwrite = canWeWrite();
689 $canftp = function_exists('ftp_connect');
695 $u = array('','','');
698 $tpl = get_markup_template("admin_remoteupdate.tpl");
699 return replace_macros($tpl, array(
700 '$baseurl' => $a->get_baseurl(),
701 '$submit' => t("Update now"),
702 '$close' => t("Close"),
703 '$localversion' => FRIENDICA_VERSION,
704 '$remoteversion' => $u[1],
705 '$needupdate' => $needupdate,
706 '$canwrite' => $canwrite,
707 '$canftp' => $canftp,
708 '$ftphost' => array('ftphost', t("FTP Host"), '',''),
709 '$ftppath' => array('ftppath', t("FTP Path"), '/',''),
710 '$ftpuser' => array('ftpuser', t("FTP User"), '',''),
711 '$ftppwd' => array('ftppwd', t("FTP Password"), '',''),
712 '$remotefile'=>array('remotefile','', $u['2'],'')