Friendica Communications Platform (please note that this is a clone of the repository at github, issues are handled there) https://friendi.ca
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

338 lines
12 KiB

  1. <?php
  2. /**
  3. * Friendika admin
  4. */
  5. function admin_init(&$a) {
  6. if(!is_site_admin()) {
  7. notice( t('Permission denied.') . EOL);
  8. return;
  9. }
  10. }
  11. function admin_post(&$a){
  12. if(!is_site_admin()) {
  13. return login(false);
  14. }
  15. // urls
  16. if ($a->argc > 1){
  17. switch ($a->argv[1]){
  18. case 'site': {
  19. admin_page_site_post($a);
  20. break;
  21. }
  22. }
  23. }
  24. goaway($a->get_baseurl() . '/admin' );
  25. return; // NOTREACHED
  26. }
  27. function admin_content(&$a) {
  28. if(!is_site_admin()) {
  29. return login(false);
  30. }
  31. /**
  32. * Side bar links
  33. */
  34. // array( url, name, extra css classes )
  35. $aside = Array(
  36. 'site' => Array($a->get_baseurl()."/admin/site/", t("Site") , "site"),
  37. 'users' => Array($a->get_baseurl()."/admin/users/", t("Users") , "users"),
  38. 'plugins'=> Array($a->get_baseurl()."/admin/plugins/", t("Plugins") , "plugins")
  39. );
  40. /* get plugins admin page */
  41. $r = q("SELECT * FROM `hook` WHERE `hook`='plugin_admin'");
  42. $aside['plugins_admin']=Array();
  43. foreach ($r as $h){
  44. $plugin = explode("/",$h['file']); $plugin = $plugin[1];
  45. $aside['plugins_admin'][] = Array($a->get_baseurl()."/admin/plugins/".$plugin, $plugin, "plugin");
  46. }
  47. $aside['logs'] = Array($a->get_baseurl()."/admin/logs/", t("Logs"), "logs");
  48. $t = get_markup_template("admin_aside.tpl");
  49. $a->page['aside'] = replace_macros( $t, array(
  50. '$admin' => $aside,
  51. '$admurl'=> $a->get_baseurl()."/admin/"
  52. ));
  53. /**
  54. * Page content
  55. */
  56. $o = '';
  57. // urls
  58. if ($a->argc > 1){
  59. switch ($a->argv[1]){
  60. case 'site':
  61. $o = admin_page_site($a);
  62. break;
  63. case 'users':
  64. $o = admin_page_users($a);
  65. break;
  66. case 'plugins':
  67. $o = admin_page_plugins($a);
  68. break;
  69. default:
  70. notice( t("Item not found.") );
  71. }
  72. } else {
  73. $o = admin_page_summary($a);
  74. }
  75. return $o;
  76. }
  77. /**
  78. * Admin Summary Page
  79. */
  80. function admin_page_summary(&$a) {
  81. $r = q("SELECT `page-flags`, COUNT(uid) as `count` FROM `user` GROUP BY `page-flags`");
  82. $accounts = Array(
  83. Array( t('Normal Account'), 0),
  84. Array( t('Soapbox Account'), 0),
  85. Array( t('Community/Celebrity Account'), 0),
  86. Array( t('Automatic Friend Account'), 0)
  87. );
  88. $users=0;
  89. foreach ($r as $u){ $accounts[$u['page-flags']][1] = $u['count']; $users+=$u['count']; }
  90. $r = q("SELECT COUNT(id) as `count` FROM `register`");
  91. $pending = $r[0]['count'];
  92. $t = get_markup_template("admin_summary.tpl");
  93. return replace_macros($t, array(
  94. '$title' => t('Administration'),
  95. '$page' => t('Summary'),
  96. '$users' => Array( t('Registered users'), $users),
  97. '$accounts' => $accounts,
  98. '$pending' => Array( t('Pending registrations'), $pending),
  99. '$version' => Array( t('Version'), FRIENDIKA_VERSION),
  100. '$build' => get_config('system','build'),
  101. '$plugins' => Array( t('Active plugins'), $a->plugins )
  102. ));
  103. }
  104. /**
  105. * Admin Site Page
  106. */
  107. function admin_page_site_post(&$a){
  108. if (!x($_POST,"page_site")){
  109. return;
  110. }
  111. $sitename = ((x($_POST,'sitename')) ? notags(trim($_POST['sitename'])) : '');
  112. $banner = ((x($_POST,'banner')) ? trim($_POST['banner']) : false);
  113. $language = ((x($_POST,'language')) ? notags(trim($_POST['language'])) : '');
  114. $theme = ((x($_POST,'theme')) ? notags(trim($_POST['theme'])) : '');
  115. $maximagesize = ((x($_POST,'maximagesize')) ? intval(trim($_POST['maximagesize'])) : 0);
  116. $allowed_sites = ((x($_POST,'allowed_sites')) ? notags(trim($_POST['allowed_sites'])) : '');
  117. $allowed_email = ((x($_POST,'allowed_email')) ? notags(trim($_POST['allowed_email'])) : '');
  118. $block_public = ((x($_POST,'block_public')) ? True : False);
  119. $force_publish = ((x($_POST,'publish_all')) ? True : False);
  120. $global_directory = ((x($_POST,'directory_submit_url')) ? notags(trim($_POST['directory_submit_url'])) : '');
  121. $global_search_url = ((x($_POST,'directory_search_url'))? notags(trim($_POST['directory_search_url'])) : '');
  122. $no_multi_reg = ((x($_POST,'no_multi_reg')) ? True : False);
  123. $no_openid = ((x($_POST,'no_openid')) ? True : False);
  124. $no_gravatar = ((x($_POST,'no_gravatar')) ? True : False);
  125. $no_regfullname = ((x($_POST,'no_regfullname')) ? True : False);
  126. $no_utf = ((x($_POST,'no_utf')) ? True : False);
  127. $rino_enc = ((x($_POST,'rino_enc')) ? True : False);
  128. $verifyssl = ((x($_POST,'verifyssl')) ? True : False);
  129. $proxyuser = ((x($_POST,'proxyuser')) ? notags(trim($_POST['global_search_url'])) : '');
  130. $proxy = ((x($_POST,'proxy')) ? notags(trim($_POST['global_search_url'])) : '');
  131. $timeout = ((x($_POST,'timeout')) ? intval(trim($_POST['timeout'])) : 60);
  132. $a->config['sitename'] = $sitename;
  133. if ($banner==""){
  134. // don't know why, but del_config doesn't work...
  135. q("DELETE FROM `config` WHERE `cat` = '%s' AND `k` = '%s' LIMIT 1",
  136. dbesc("system"),
  137. dbesc("banner")
  138. );
  139. } else {
  140. set_config('system','banner', $banner);
  141. }
  142. set_config('system','language', $language);
  143. set_config('system','theme', $theme);
  144. set_config('system','maximagesize', $maximagesize);
  145. set_config('system','allowed_sites', $allowed_sites);
  146. set_config('system','allowed_email', $allowed_email);
  147. set_config('system','block_public', $block_public);
  148. set_config('system','publish_all', $force_publish);
  149. if ($global_directory==""){
  150. // don't know why, but del_config doesn't work...
  151. q("DELETE FROM `config` WHERE `cat` = '%s' AND `k` = '%s' LIMIT 1",
  152. dbesc("system"),
  153. dbesc("directory_submit_url")
  154. );
  155. } else {
  156. set_config('system','directory_submit_url', $global_directory);
  157. }
  158. set_config('system','directory_search_url', $global_search_url);
  159. set_config('system','block_extended_register', $no_multi_reg);
  160. set_config('system','no_openid', $no_openid);
  161. set_config('system','no_gravatar', $no_gravatar);
  162. set_config('system','no_regfullname', $no_regfullname);
  163. set_config('system','proxy', $no_utf);
  164. set_config('system','rino_encrypt', $rino_enc);
  165. set_config('system','verifyssl', $verifyssl);
  166. set_config('system','proxyuser', $proxyuser);
  167. set_config('system','proxy', $proxy);
  168. set_config('system','curl_timeout', $timeout);
  169. $r = q("SELECT * FROM `config` WHERE `cat`='config' AND `k`='sitename'");
  170. if (count($r)>0){
  171. q("UPDATE `config` SET `v`='%s' WHERE `cat`='config' AND `k`='sitename'",
  172. dbesc($a->config['sitename'])
  173. );
  174. } else {
  175. q("INSERT INTO `config` ( `cat`, `k`, `v` ) VALUES ( 'config', 'sitename', '%s' )",
  176. dbesc($a->config['sitename'])
  177. );
  178. }
  179. goaway($a->get_baseurl() . '/admin/site' );
  180. return; // NOTREACHED
  181. }
  182. function admin_page_site(&$a) {
  183. /* Installed langs */
  184. $lang_choices = array();
  185. $langs = glob('view/*/strings.php');
  186. if(is_array($langs) && count($langs)) {
  187. if(! in_array('view/en/strings.php',$langs))
  188. $langs[] = 'view/en/';
  189. asort($langs);
  190. foreach($langs as $l) {
  191. $t = explode("/",$l);
  192. $lang_choices[$t[1]] = $t[1];
  193. }
  194. }
  195. /* Installed themes */
  196. $theme_choices = array();
  197. $files = glob('view/theme/*');
  198. if($files) {
  199. foreach($files as $file) {
  200. $f = basename($file);
  201. $theme_name = ((file_exists($file . '/experimental')) ? sprintf("%s - \x28Experimental\x29", $f) : $f);
  202. $theme_choices[$f] = $theme_name;
  203. }
  204. }
  205. /* Banner */
  206. $banner = get_config('system','banner');
  207. if($banner == false)
  208. $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>');
  209. //echo "<pre>"; var_dump($lang_choices); die("</pre>");
  210. $t = get_markup_template("admin_site.tpl");
  211. return replace_macros($t, array(
  212. '$title' => t('Administration'),
  213. '$page' => t('Site'),
  214. '$submit' => t('Submit'),
  215. '$baseurl' => $a->get_baseurl(),
  216. // name, label, value, help string, extra data...
  217. '$sitename' => array('sitename', t("Site name"), $a->config['sitename'], ""),
  218. '$banner' => array('banner', t("Banner/Logo"), $banner, ""),
  219. '$language' => array('language', t("System language"), get_config('system','language'), "", $lang_choices),
  220. '$theme' => array('theme', t("System theme"), get_config('system','theme'), "Default system theme (which may be over-ridden by user profiles)", $theme_choices),
  221. '$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."),
  222. '$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"),
  223. '$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"),
  224. '$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."),
  225. '$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."),
  226. '$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."),
  227. '$global_search_url'=> array('directory_search_url', t("Global directory search URL"), get_config('system','directory_search_url'), ""),
  228. '$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."),
  229. '$no_openid' => array('no_openid', t("No OpenID support"), get_config('system','no_openid'), "Disable OpenID support for registration and logins."),
  230. '$no_gravatar' => array('no_gravatar', t("No Gravatar support"), get_config('system','no_gravatar'), ""),
  231. '$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"),
  232. '$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)"),
  233. '$rino_enc' => array('rino_enc', t("Enable Rino encrypt"), get_config('system','rino_encrypt'),""),
  234. '$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."),
  235. '$proxyuser' => array('proxyuser', t("Proxy user"), get_config('system','proxyuser'), ""),
  236. '$proxy' => array('proxy', t("Proxy URL"), get_config('system','proxy'), ""),
  237. '$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)."),
  238. ));
  239. }
  240. /**
  241. * Users admin page
  242. */
  243. function admin_page_users(&$a){
  244. return ":)";
  245. }
  246. /*
  247. * Plugins admin page
  248. */
  249. function admin_page_plugins(&$a){
  250. /* all plugins */
  251. $plugins = array();
  252. $files = glob("addon/*/");
  253. if($files) {
  254. foreach($files as $file) {
  255. if (is_dir($file)){
  256. list($tmp, $id)=array_map("trim", explode("/",$file));
  257. // TODO: plugins info
  258. $name=$author=$description=$homepage="";
  259. $plugins[] = array( $id, (in_array($id, $a->plugins)?"on":"off") , $name, $author, $description, $homepage);
  260. }
  261. }
  262. }
  263. $t = get_markup_template("admin_plugins.tpl");
  264. return replace_macros($t, array(
  265. '$title' => t('Administration'),
  266. '$page' => t('Plugins'),
  267. '$submit' => t('Submit'),
  268. '$baseurl' => $a->get_baseurl(),
  269. '$plugins' => $plugins
  270. ));
  271. }