6 require_once("include/remoteupdate.php");
8 function admin_init(&$a) {
10 notice( t('Permission denied.') . EOL);
15 function admin_post(&$a){
16 if(!is_site_admin()) {
24 admin_page_site_post($a);
27 admin_page_users_post($a);
31 is_file("addon/".$a->argv[2]."/".$a->argv[2].".php")){
32 @include_once("addon/".$a->argv[2]."/".$a->argv[2].".php");
33 if(function_exists($a->argv[2].'_plugin_admin_post')) {
34 $func = $a->argv[2].'_plugin_admin_post';
38 goaway($a->get_baseurl() . '/admin/plugins/' . $a->argv[2] );
42 admin_page_logs_post($a);
45 admin_page_remoteupdate_post($a);
50 goaway($a->get_baseurl() . '/admin' );
54 function admin_content(&$a) {
56 if(!is_site_admin()) {
64 // array( url, name, extra css classes )
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")
72 /* get plugins admin page */
74 $r = q("SELECT * FROM `addon` WHERE `plugin_admin`=1");
75 $aside['plugins_admin']=Array();
78 $aside['plugins_admin'][] = Array($a->get_baseurl()."/admin/plugins/".$plugin, $plugin, "plugin");
79 // temp plugins with admin
80 $a->plugins_admin[] = $plugin;
83 $aside['logs'] = Array($a->get_baseurl()."/admin/logs/", t("Logs"), "logs");
85 $t = get_markup_template("admin_aside.tpl");
86 $a->page['aside'] = replace_macros( $t, array(
88 '$h_pending' => t('User registrations waiting for confirmation'),
89 '$admurl'=> $a->get_baseurl()."/admin/"
101 switch ($a->argv[1]){
103 $o = admin_page_site($a);
106 $o = admin_page_users($a);
109 $o = admin_page_plugins($a);
112 $o = admin_page_logs($a);
115 $o = admin_page_remoteupdate($a);
118 notice( t("Item not found.") );
121 $o = admin_page_summary($a);
130 function admin_page_summary(&$a) {
131 $r = q("SELECT `page-flags`, COUNT(uid) as `count` FROM `user` GROUP BY `page-flags`");
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)
139 foreach ($r as $u){ $accounts[$u['page-flags']][1] = $u['count']; $users+=$u['count']; }
142 $r = q("SELECT COUNT(id) as `count` FROM `register`");
143 $pending = $r[0]['count'];
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'), FRIENDIKA_VERSION),
157 '$build' => get_config('system','build'),
158 '$plugins' => Array( t('Active plugins'), $a->plugins )
166 function admin_page_site_post(&$a){
167 if (!x($_POST,"page_site")){
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);
179 $register_policy = ((x($_POST,'register_policy')) ? intval(trim($_POST['register_policy'])) : 0);
180 $register_text = ((x($_POST,'register_text')) ? notags(trim($_POST['register_text'])) : '');
182 $allowed_sites = ((x($_POST,'allowed_sites')) ? notags(trim($_POST['allowed_sites'])) : '');
183 $allowed_email = ((x($_POST,'allowed_email')) ? notags(trim($_POST['allowed_email'])) : '');
184 $block_public = ((x($_POST,'block_public')) ? True : False);
185 $force_publish = ((x($_POST,'publish_all')) ? True : False);
186 $global_directory = ((x($_POST,'directory_submit_url')) ? notags(trim($_POST['directory_submit_url'])) : '');
187 $no_multi_reg = ((x($_POST,'no_multi_reg')) ? True : False);
188 $no_openid = !((x($_POST,'no_openid')) ? True : False);
189 $no_gravatar = !((x($_POST,'no_gravatar')) ? True : False);
190 $no_regfullname = !((x($_POST,'no_regfullname')) ? True : False);
191 $no_utf = !((x($_POST,'no_utf')) ? True : False);
192 $no_community_page = !((x($_POST,'no_community_page')) ? True : False);
194 $verifyssl = ((x($_POST,'verifyssl')) ? True : False);
195 $proxyuser = ((x($_POST,'proxyuser')) ? notags(trim($_POST['proxyuser'])) : '');
196 $proxy = ((x($_POST,'proxy')) ? notags(trim($_POST['proxy'])) : '');
197 $timeout = ((x($_POST,'timeout')) ? intval(trim($_POST['timeout'])) : 60);
198 $dfrn_only = ((x($_POST,'dfrn_only')) ? True : False);
199 $ostatus_disabled = !((x($_POST,'ostatus_disabled')) ? True : False);
200 $diaspora_enabled = ((x($_POST,'diaspora_enabled')) ? True : False);
203 set_config('config','sitename',$sitename);
205 // don't know why, but del_config doesn't work...
206 q("DELETE FROM `config` WHERE `cat` = '%s' AND `k` = '%s' LIMIT 1",
211 set_config('system','banner', $banner);
213 set_config('system','language', $language);
214 set_config('system','theme', $theme);
215 set_config('system','maximagesize', $maximagesize);
217 set_config('config','register_policy', $register_policy);
218 set_config('config','register_text', $register_text);
219 set_config('system','allowed_sites', $allowed_sites);
220 set_config('system','allowed_email', $allowed_email);
221 set_config('system','block_public', $block_public);
222 set_config('system','publish_all', $force_publish);
223 if ($global_directory==""){
224 // don't know why, but del_config doesn't work...
225 q("DELETE FROM `config` WHERE `cat` = '%s' AND `k` = '%s' LIMIT 1",
227 dbesc("directory_submit_url")
230 set_config('system','directory_submit_url', $global_directory);
232 set_config('system','directory_search_url', $global_search_url);
233 set_config('system','block_extended_register', $no_multi_reg);
234 set_config('system','no_openid', $no_openid);
235 set_config('system','no_gravatar', $no_gravatar);
236 set_config('system','no_regfullname', $no_regfullname);
237 set_config('system','no_community_page', $no_community_page);
238 set_config('system','no_utf', $no_utf);
239 set_config('system','verifyssl', $verifyssl);
240 set_config('system','proxyuser', $proxyuser);
241 set_config('system','proxy', $proxy);
242 set_config('system','curl_timeout', $timeout);
243 set_config('system','dfrn_only', $dfrn_only);
244 set_config('system','ostatus_disabled', $ostatus_disabled);
245 set_config('system','diaspora_enabled', $diaspora_enabled);
247 info( t('Site settings updated.') . EOL);
248 goaway($a->get_baseurl() . '/admin/site' );
249 return; // NOTREACHED
253 function admin_page_site(&$a) {
255 /* Installed langs */
256 $lang_choices = array();
257 $langs = glob('view/*/strings.php');
259 if(is_array($langs) && count($langs)) {
260 if(! in_array('view/en/strings.php',$langs))
261 $langs[] = 'view/en/';
263 foreach($langs as $l) {
264 $t = explode("/",$l);
265 $lang_choices[$t[1]] = $t[1];
269 /* Installed themes */
270 $theme_choices = array();
271 $files = glob('view/theme/*');
273 foreach($files as $file) {
274 $f = basename($file);
275 $theme_name = ((file_exists($file . '/experimental')) ? sprintf("%s - \x28Experimental\x29", $f) : $f);
276 $theme_choices[$f] = $theme_name;
282 $banner = get_config('system','banner');
284 $banner = '<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>';
285 $banner = htmlspecialchars($banner);
287 //echo "<pre>"; var_dump($lang_choices); die("</pre>");
289 /* Register policy */
290 $register_choices = Array(
291 REGISTER_CLOSED => t("Closed"),
292 REGISTER_APPROVE => t("Requires approval"),
293 REGISTER_OPEN => t("Open")
296 $t = get_markup_template("admin_site.tpl");
297 return replace_macros($t, array(
298 '$title' => t('Administration'),
299 '$page' => t('Site'),
300 '$submit' => t('Submit'),
301 '$registration' => t('Registration'),
302 '$upload' => t('File upload'),
303 '$corporate' => t('Policies'),
304 '$advanced' => t('Advanced'),
306 '$baseurl' => $a->get_baseurl(),
307 // name, label, value, help string, extra data...
308 '$sitename' => array('sitename', t("Site name"), htmlentities($a->config['sitename'], ENT_QUOTES), ""),
309 '$banner' => array('banner', t("Banner/Logo"), $banner, ""),
310 '$language' => array('language', t("System language"), get_config('system','language'), "", $lang_choices),
311 '$theme' => array('theme', t("System theme"), get_config('system','theme'), "Default system theme (which may be over-ridden by user profiles)", $theme_choices),
313 '$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."),
315 '$register_policy' => array('register_policy', t("Register policy"), $a->config['register_policy'], "", $register_choices),
316 '$register_text' => array('register_text', t("Register text"), htmlentities($a->config['register_text'], ENT_QUOTES), "Will be displayed prominently on the registration page."),
317 '$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"),
318 '$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"),
319 '$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."),
320 '$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."),
321 '$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."),
323 '$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."),
324 '$no_openid' => array('no_openid', t("OpenID support"), !get_config('system','no_openid'), "OpenID support for registration and logins."),
325 '$no_gravatar' => array('no_gravatar', t("Gravatar support"), !get_config('system','no_gravatar'), "Search new user's photo on Gravatar."),
326 '$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"),
327 '$no_utf' => array('no_utf', t("UTF-8 Regular expressions"), !get_config('system','no_utf'), "Use PHP UTF8 regular expressions"),
328 '$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."),
329 '$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."),
330 '$diaspora_enabled' => array('diaspora_enabled', t("Enable Diaspora support"), get_config('system','diaspora_enabled'), "Provide built-in Diaspora network compatibility."),
331 '$dfrn_only' => array('dfrn_only', t('Only allow Friendika contacts'), get_config('system','dfrn_only'), "All contacts must use Friendika protocols. All other built-in communication protocols disabled."),
332 '$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."),
333 '$proxyuser' => array('proxyuser', t("Proxy user"), get_config('system','proxyuser'), ""),
334 '$proxy' => array('proxy', t("Proxy URL"), get_config('system','proxy'), ""),
335 '$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)."),
346 function admin_page_users_post(&$a){
347 $pending = ( x($_POST, 'pending') ? $_POST['pending'] : Array() );
348 $users = ( x($_POST, 'user') ? $_POST['user'] : Array() );
350 if (x($_POST,'page_users_block')){
351 foreach($users as $uid){
352 q("UPDATE `user` SET `blocked`=1-`blocked` WHERE `uid`=%s",
356 notice( sprintf( tt("%s user blocked", "%s users blocked/unblocked", count($users)), count($users)) );
358 if (x($_POST,'page_users_delete')){
359 require_once("include/Contact.php");
360 foreach($users as $uid){
363 notice( sprintf( tt("%s user deleted", "%s users deleted", count($users)), count($users)) );
366 if (x($_POST,'page_users_approve')){
367 require_once("mod/regmod.php");
368 foreach($pending as $hash){
372 if (x($_POST,'page_users_deny')){
373 require_once("mod/regmod.php");
374 foreach($pending as $hash){
378 goaway($a->get_baseurl() . '/admin/users' );
379 return; // NOTREACHED
382 function admin_page_users(&$a){
385 $user = q("SELECT * FROM `user` WHERE `uid`=%d", intval($uid));
386 if (count($user)==0){
387 notice( 'User not found' . EOL);
388 goaway($a->get_baseurl() . '/admin/users' );
389 return; // NOTREACHED
394 require_once("include/Contact.php");
397 notice( sprintf(t("User '%s' deleted"), $user[0]['username']) . EOL);
400 q("UPDATE `user` SET `blocked`=%d WHERE `uid`=%s",
401 intval( 1-$user[0]['blocked'] ),
404 notice( sprintf( ($user[0]['blocked']?t("User '%s' unblocked"):t("User '%s' blocked")) , $user[0]['username']) . EOL);
407 goaway($a->get_baseurl() . '/admin/users' );
408 return; // NOTREACHED
413 $pending = q("SELECT `register`.*, `contact`.`name`, `user`.`email`
415 LEFT JOIN `contact` ON `register`.`uid` = `contact`.`uid`
416 LEFT JOIN `user` ON `register`.`uid` = `user`.`uid`;");
420 $total = q("SELECT count(*) as total FROM `user` where 1");
422 $a->set_pager_total($total[0]['total']);
423 $a->set_pager_itemspage(100);
426 $users = q("SELECT `user` . * , `contact`.`name` , `contact`.`url` , `contact`.`micro`, `lastitem`.`lastitem_date`
428 (SELECT MAX(`item`.`changed`) as `lastitem_date`, `item`.`uid`
430 WHERE `item`.`type` = 'wall'
431 GROUP BY `item`.`uid`) AS `lastitem`
432 RIGHT OUTER JOIN `user` ON `user`.`uid` = `lastitem`.`uid`,
435 `user`.`uid` = `contact`.`uid`
436 AND `user`.`verified` =1
437 AND `contact`.`self` =1
438 ORDER BY `contact`.`name` LIMIT %d, %d
440 intval($a->pager['start']),
441 intval($a->pager['itemspage'])
444 function _setup_users($e){
447 t('Soapbox Account'),
448 t('Community/Celebrity Account'),
449 t('Automatic Friend Account')
451 $e['page-flags'] = $accounts[$e['page-flags']];
452 $e['register_date'] = relative_date($e['register_date']);
453 $e['login_date'] = relative_date($e['login_date']);
454 $e['lastitem_date'] = relative_date($e['lastitem_date']);
457 $users = array_map("_setup_users", $users);
459 $t = get_markup_template("admin_users.tpl");
460 $o = replace_macros($t, array(
462 '$title' => t('Administration'),
463 '$page' => t('Users'),
464 '$submit' => t('Submit'),
465 '$select_all' => t('select all'),
466 '$h_pending' => t('User registrations waiting for confirm'),
467 '$th_pending' => array( t('Request date'), t('Name'), t('Email') ),
468 '$no_pending' => t('No registrations.'),
469 '$approve' => t('Approve'),
470 '$deny' => t('Deny'),
471 '$delete' => t('Delete'),
472 '$block' => t('Block'),
473 '$unblock' => t('Unblock'),
475 '$h_users' => t('Users'),
476 '$th_users' => array( t('Name'), t('Email'), t('Register date'), t('Last login'), t('Last item'), t('Account') ),
478 '$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?'),
479 '$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?'),
483 '$baseurl' => $a->get_baseurl(),
485 '$pending' => $pending,
497 function admin_page_plugins(&$a){
503 $plugin = $a->argv[2];
504 if (!is_file("addon/$plugin/$plugin.php")){
505 notice( t("Item not found.") );
509 if (x($_GET,"a") && $_GET['a']=="t"){
510 // Toggle plugin status
511 $idx = array_search($plugin, $a->plugins);
513 unset($a->plugins[$idx]);
514 uninstall_plugin($plugin);
515 info( sprintf( t("Plugin %s disabled."), $plugin ) );
517 $a->plugins[] = $plugin;
518 install_plugin($plugin);
519 info( sprintf( t("Plugin %s enabled."), $plugin ) );
521 set_config("system","addon", implode(", ",$a->plugins));
522 goaway($a->get_baseurl() . '/admin/plugins' );
523 return; // NOTREACHED
525 // display plugin details
526 require_once('library/markdown.php');
528 if (in_array($plugin, $a->plugins)){
529 $status="on"; $action= t("Disable");
531 $status="off"; $action= t("Enable");
535 if (is_file("addon/$plugin/README.md")){
536 $readme = file_get_contents("addon/$plugin/README.md");
537 $readme = Markdown($readme);
538 } else if (is_file("addon/$plugin/README")){
539 $readme = "<pre>". file_get_contents("addon/$plugin/README") ."</pre>";
543 if (is_array($a->plugins_admin) && in_array($plugin, $a->plugins_admin)){
544 @require_once("addon/$plugin/$plugin.php");
545 $func = $plugin.'_plugin_admin';
546 $func($a, $admin_form);
549 $t = get_markup_template("admin_plugins_details.tpl");
550 return replace_macros($t, array(
551 '$title' => t('Administration'),
552 '$page' => t('Plugins'),
553 '$toggle' => t('Toggle'),
554 '$settings' => t('Settings'),
555 '$baseurl' => $a->get_baseurl(),
557 '$plugin' => $plugin,
558 '$status' => $status,
559 '$action' => $action,
560 '$info' => get_plugin_info($plugin),
562 '$admin_form' => $admin_form,
575 $files = glob("addon/*/");
577 foreach($files as $file) {
579 list($tmp, $id)=array_map("trim", explode("/",$file));
580 $info = get_plugin_info($id);
581 $plugins[] = array( $id, (in_array($id, $a->plugins)?"on":"off") , $info);
586 $t = get_markup_template("admin_plugins.tpl");
587 return replace_macros($t, array(
588 '$title' => t('Administration'),
589 '$page' => t('Plugins'),
590 '$submit' => t('Submit'),
591 '$baseurl' => $a->get_baseurl(),
593 '$plugins' => $plugins
602 function admin_page_logs_post(&$a) {
603 if (x($_POST,"page_logs")) {
605 $logfile = ((x($_POST,'logfile')) ? notags(trim($_POST['logfile'])) : '');
606 $debugging = ((x($_POST,'debugging')) ? true : false);
607 $loglevel = ((x($_POST,'loglevel')) ? intval(trim($_POST['loglevel'])) : 0);
609 set_config('system','logfile', $logfile);
610 set_config('system','debugging', $debugging);
611 set_config('system','loglevel', $loglevel);
616 info( t("Log settings updated.") );
617 goaway($a->get_baseurl() . '/admin/logs' );
618 return; // NOTREACHED
621 function admin_page_logs(&$a){
623 $log_choices = Array(
624 LOGGER_NORMAL => 'Normal',
625 LOGGER_TRACE => 'Trace',
626 LOGGER_DEBUG => 'Debug',
627 LOGGER_DATA => 'Data',
631 $t = get_markup_template("admin_logs.tpl");
633 $f = get_config('system','logfile');
634 $size = filesize($f);
635 if($size > 5000000 || $size < 0)
641 $seek = fseek($fp,0-$size,SEEK_END);
643 fgets($fp); // throw away the first partial line
644 $data = escape_tags(fread($fp,$size));
646 $data .= escape_tags(fread($fp,4096));
652 return replace_macros($t, array(
653 '$title' => t('Administration'),
654 '$page' => t('Logs'),
655 '$submit' => t('Submit'),
656 '$clear' => t('Clear'),
658 '$baseurl' => $a->get_baseurl(),
659 '$logname' => get_config('system','logfile'),
661 // name, label, value, help string, extra data...
662 '$debugging' => array('debugging', t("Debugging"),get_config('system','debugging'), ""),
663 '$logfile' => array('logfile', t("Log file"), get_config('system','logfile'), t("Must be writable by web server. Relative to your Friendika index.php.")),
664 '$loglevel' => array('loglevel', t("Log level"), get_config('system','loglevel'), "", $log_choices),
668 function admin_page_remoteupdate_post(&$a) {
669 // this function should be called via ajax post
670 if(!is_site_admin()) {
675 if (x($_POST,'remotefile') && $_POST['remotefile']!=""){
676 $remotefile = $_POST['remotefile'];
677 $ftpdata = (x($_POST['ftphost'])?$_POST:false);
678 doUpdate($remotefile, $ftpdata);
680 echo "No remote file to download. Abort!";
686 function admin_page_remoteupdate(&$a) {
687 if(!is_site_admin()) {
691 $canwrite = canWeWrite();
692 $canftp = function_exists('ftp_connect');
698 $u = array('','','');
701 $tpl = get_markup_template("admin_remoteupdate.tpl");
702 return replace_macros($tpl, array(
703 '$baseurl' => $a->get_baseurl(),
704 '$submit' => t("Update now"),
705 '$close' => t("Close"),
706 '$localversion' => FRIENDIKA_VERSION,
707 '$remoteversion' => $u[1],
708 '$needupdate' => $needupdate,
709 '$canwrite' => $canwrite,
710 '$canftp' => $canftp,
711 '$ftphost' => array('ftphost', t("FTP Host"), '',''),
712 '$ftppath' => array('ftppath', t("FTP Path"), '/',''),
713 '$ftpuser' => array('ftpuser', t("FTP User"), '',''),
714 '$ftppwd' => array('ftppwd', t("FTP Password"), '',''),
715 '$remotefile'=>array('remotefile','', $u['2'],'')