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.
 
 
 
 
 
 

443 lines
14 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. case 'logs':
  22. admin_page_logs_post($a);
  23. break;
  24. }
  25. }
  26. goaway($a->get_baseurl() . '/admin' );
  27. return; // NOTREACHED
  28. }
  29. function admin_content(&$a) {
  30. if(!is_site_admin()) {
  31. return login(false);
  32. }
  33. /**
  34. * Side bar links
  35. */
  36. // array( url, name, extra css classes )
  37. $aside = Array(
  38. 'site' => Array($a->get_baseurl()."/admin/site/", t("Site") , "site"),
  39. 'users' => Array($a->get_baseurl()."/admin/users/", t("Users") , "users"),
  40. 'plugins'=> Array($a->get_baseurl()."/admin/plugins/", t("Plugins") , "plugins")
  41. );
  42. /* get plugins admin page */
  43. $r = q("SELECT * FROM `hook` WHERE `hook`='plugin_admin'");
  44. $aside['plugins_admin']=Array();
  45. foreach ($r as $h){
  46. $plugin = explode("/",$h['file']); $plugin = $plugin[1];
  47. $aside['plugins_admin'][] = Array($a->get_baseurl()."/admin/plugins/".$plugin, $plugin, "plugin");
  48. }
  49. $aside['logs'] = Array($a->get_baseurl()."/admin/logs/", t("Logs"), "logs");
  50. $t = get_markup_template("admin_aside.tpl");
  51. $a->page['aside'] = replace_macros( $t, array(
  52. '$admin' => $aside,
  53. '$admurl'=> $a->get_baseurl()."/admin/"
  54. ));
  55. /**
  56. * Page content
  57. */
  58. $o = '';
  59. // urls
  60. if ($a->argc > 1){
  61. switch ($a->argv[1]){
  62. case 'site':
  63. $o = admin_page_site($a);
  64. break;
  65. case 'users':
  66. $o = admin_page_users($a);
  67. break;
  68. case 'plugins':
  69. $o = admin_page_plugins($a);
  70. break;
  71. case 'logs':
  72. $o = admin_page_logs($a);
  73. break;
  74. default:
  75. notice( t("Item not found.") );
  76. }
  77. } else {
  78. $o = admin_page_summary($a);
  79. }
  80. return $o;
  81. }
  82. /**
  83. * Admin Summary Page
  84. */
  85. function admin_page_summary(&$a) {
  86. $r = q("SELECT `page-flags`, COUNT(uid) as `count` FROM `user` GROUP BY `page-flags`");
  87. $accounts = Array(
  88. Array( t('Normal Account'), 0),
  89. Array( t('Soapbox Account'), 0),
  90. Array( t('Community/Celebrity Account'), 0),
  91. Array( t('Automatic Friend Account'), 0)
  92. );
  93. $users=0;
  94. foreach ($r as $u){ $accounts[$u['page-flags']][1] = $u['count']; $users+=$u['count']; }
  95. $r = q("SELECT COUNT(id) as `count` FROM `register`");
  96. $pending = $r[0]['count'];
  97. $t = get_markup_template("admin_summary.tpl");
  98. return replace_macros($t, array(
  99. '$title' => t('Administration'),
  100. '$page' => t('Summary'),
  101. '$users' => Array( t('Registered users'), $users),
  102. '$accounts' => $accounts,
  103. '$pending' => Array( t('Pending registrations'), $pending),
  104. '$version' => Array( t('Version'), FRIENDIKA_VERSION),
  105. '$build' => get_config('system','build'),
  106. '$plugins' => Array( t('Active plugins'), $a->plugins )
  107. ));
  108. }
  109. /**
  110. * Admin Site Page
  111. */
  112. function admin_page_site_post(&$a){
  113. if (!x($_POST,"page_site")){
  114. return;
  115. }
  116. $sitename = ((x($_POST,'sitename')) ? notags(trim($_POST['sitename'])) : '');
  117. $banner = ((x($_POST,'banner')) ? trim($_POST['banner']) : false);
  118. $language = ((x($_POST,'language')) ? notags(trim($_POST['language'])) : '');
  119. $theme = ((x($_POST,'theme')) ? notags(trim($_POST['theme'])) : '');
  120. $maximagesize = ((x($_POST,'maximagesize')) ? intval(trim($_POST['maximagesize'])) : 0);
  121. $allowed_sites = ((x($_POST,'allowed_sites')) ? notags(trim($_POST['allowed_sites'])) : '');
  122. $allowed_email = ((x($_POST,'allowed_email')) ? notags(trim($_POST['allowed_email'])) : '');
  123. $block_public = ((x($_POST,'block_public')) ? True : False);
  124. $force_publish = ((x($_POST,'publish_all')) ? True : False);
  125. $global_directory = ((x($_POST,'directory_submit_url')) ? notags(trim($_POST['directory_submit_url'])) : '');
  126. $global_search_url = ((x($_POST,'directory_search_url'))? notags(trim($_POST['directory_search_url'])) : '');
  127. $no_multi_reg = ((x($_POST,'no_multi_reg')) ? True : False);
  128. $no_openid = ((x($_POST,'no_openid')) ? True : False);
  129. $no_gravatar = ((x($_POST,'no_gravatar')) ? True : False);
  130. $no_regfullname = ((x($_POST,'no_regfullname')) ? True : False);
  131. $no_utf = ((x($_POST,'no_utf')) ? True : False);
  132. $rino_enc = ((x($_POST,'rino_enc')) ? True : False);
  133. $verifyssl = ((x($_POST,'verifyssl')) ? True : False);
  134. $proxyuser = ((x($_POST,'proxyuser')) ? notags(trim($_POST['global_search_url'])) : '');
  135. $proxy = ((x($_POST,'proxy')) ? notags(trim($_POST['global_search_url'])) : '');
  136. $timeout = ((x($_POST,'timeout')) ? intval(trim($_POST['timeout'])) : 60);
  137. $a->config['sitename'] = $sitename;
  138. if ($banner==""){
  139. // don't know why, but del_config doesn't work...
  140. q("DELETE FROM `config` WHERE `cat` = '%s' AND `k` = '%s' LIMIT 1",
  141. dbesc("system"),
  142. dbesc("banner")
  143. );
  144. } else {
  145. set_config('system','banner', $banner);
  146. }
  147. set_config('system','language', $language);
  148. set_config('system','theme', $theme);
  149. set_config('system','maximagesize', $maximagesize);
  150. set_config('system','allowed_sites', $allowed_sites);
  151. set_config('system','allowed_email', $allowed_email);
  152. set_config('system','block_public', $block_public);
  153. set_config('system','publish_all', $force_publish);
  154. if ($global_directory==""){
  155. // don't know why, but del_config doesn't work...
  156. q("DELETE FROM `config` WHERE `cat` = '%s' AND `k` = '%s' LIMIT 1",
  157. dbesc("system"),
  158. dbesc("directory_submit_url")
  159. );
  160. } else {
  161. set_config('system','directory_submit_url', $global_directory);
  162. }
  163. set_config('system','directory_search_url', $global_search_url);
  164. set_config('system','block_extended_register', $no_multi_reg);
  165. set_config('system','no_openid', $no_openid);
  166. set_config('system','no_gravatar', $no_gravatar);
  167. set_config('system','no_regfullname', $no_regfullname);
  168. set_config('system','proxy', $no_utf);
  169. set_config('system','rino_encrypt', $rino_enc);
  170. set_config('system','verifyssl', $verifyssl);
  171. set_config('system','proxyuser', $proxyuser);
  172. set_config('system','proxy', $proxy);
  173. set_config('system','curl_timeout', $timeout);
  174. $r = q("SELECT * FROM `config` WHERE `cat`='config' AND `k`='sitename'");
  175. if (count($r)>0){
  176. q("UPDATE `config` SET `v`='%s' WHERE `cat`='config' AND `k`='sitename'",
  177. dbesc($a->config['sitename'])
  178. );
  179. } else {
  180. q("INSERT INTO `config` ( `cat`, `k`, `v` ) VALUES ( 'config', 'sitename', '%s' )",
  181. dbesc($a->config['sitename'])
  182. );
  183. }
  184. goaway($a->get_baseurl() . '/admin/site' );
  185. return; // NOTREACHED
  186. }
  187. function admin_page_site(&$a) {
  188. /* Installed langs */
  189. $lang_choices = array();
  190. $langs = glob('view/*/strings.php');
  191. if(is_array($langs) && count($langs)) {
  192. if(! in_array('view/en/strings.php',$langs))
  193. $langs[] = 'view/en/';
  194. asort($langs);
  195. foreach($langs as $l) {
  196. $t = explode("/",$l);
  197. $lang_choices[$t[1]] = $t[1];
  198. }
  199. }
  200. /* Installed themes */
  201. $theme_choices = array();
  202. $files = glob('view/theme/*');
  203. if($files) {
  204. foreach($files as $file) {
  205. $f = basename($file);
  206. $theme_name = ((file_exists($file . '/experimental')) ? sprintf("%s - \x28Experimental\x29", $f) : $f);
  207. $theme_choices[$f] = $theme_name;
  208. }
  209. }
  210. /* Banner */
  211. $banner = get_config('system','banner');
  212. if($banner == false)
  213. $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>');
  214. //echo "<pre>"; var_dump($lang_choices); die("</pre>");
  215. $t = get_markup_template("admin_site.tpl");
  216. return replace_macros($t, array(
  217. '$title' => t('Administration'),
  218. '$page' => t('Site'),
  219. '$submit' => t('Submit'),
  220. '$baseurl' => $a->get_baseurl(),
  221. // name, label, value, help string, extra data...
  222. '$sitename' => array('sitename', t("Site name"), $a->config['sitename'], ""),
  223. '$banner' => array('banner', t("Banner/Logo"), $banner, ""),
  224. '$language' => array('language', t("System language"), get_config('system','language'), "", $lang_choices),
  225. '$theme' => array('theme', t("System theme"), get_config('system','theme'), "Default system theme (which may be over-ridden by user profiles)", $theme_choices),
  226. '$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."),
  227. '$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"),
  228. '$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"),
  229. '$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."),
  230. '$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."),
  231. '$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."),
  232. '$global_search_url'=> array('directory_search_url', t("Global directory search URL"), get_config('system','directory_search_url'), ""),
  233. '$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."),
  234. '$no_openid' => array('no_openid', t("No OpenID support"), get_config('system','no_openid'), "Disable OpenID support for registration and logins."),
  235. '$no_gravatar' => array('no_gravatar', t("No Gravatar support"), get_config('system','no_gravatar'), ""),
  236. '$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"),
  237. '$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)"),
  238. '$rino_enc' => array('rino_enc', t("Enable Rino encrypt"), get_config('system','rino_encrypt'),""),
  239. '$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."),
  240. '$proxyuser' => array('proxyuser', t("Proxy user"), get_config('system','proxyuser'), ""),
  241. '$proxy' => array('proxy', t("Proxy URL"), get_config('system','proxy'), ""),
  242. '$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)."),
  243. ));
  244. }
  245. /**
  246. * Users admin page
  247. */
  248. function admin_page_users(&$a){
  249. return ":)";
  250. }
  251. /*
  252. * Plugins admin page
  253. */
  254. function admin_page_plugins(&$a){
  255. /**
  256. * Single plugin
  257. */
  258. if ($a->argc == 3){
  259. $plugin = $a->argv[2];
  260. if (!is_file("addon/$plugin/$plugin.php")){
  261. notice( t("Item not found.") );
  262. return;
  263. }
  264. if (x($_GET,"a") && $_GET['a']=="t"){
  265. // Toggle plugin status
  266. $idx = array_search($plugin, $a->plugins);
  267. if ($idx){
  268. unset($a->plugins[$idx]);
  269. uninstall_plugin($plugin);
  270. } else {
  271. $a->plugins[] = $plugin;
  272. install_plugin($plugin);
  273. }
  274. set_config("system","addon", implode(", ",$a->plugins));
  275. goaway($a->get_baseurl() . '/admin/plugins' );
  276. return; // NOTREACHED
  277. }
  278. // display plugin details
  279. if (in_array($plugin, $a->plugins)){
  280. $status="on"; $action= t("Disable");
  281. } else {
  282. $status="off"; $action= t("Enable");
  283. }
  284. $t = get_markup_template("admin_plugins_details.tpl");
  285. return replace_macros($t, array(
  286. '$title' => t('Administration'),
  287. '$page' => t('Plugins'),
  288. '$toggle' => t('Toggle'),
  289. '$baseurl' => $a->get_baseurl(),
  290. '$plugin' => $plugin,
  291. '$status' => $status,
  292. '$action' => $action
  293. ));
  294. }
  295. /**
  296. * List plugins
  297. */
  298. $plugins = array();
  299. $files = glob("addon/*/");
  300. if($files) {
  301. foreach($files as $file) {
  302. if (is_dir($file)){
  303. list($tmp, $id)=array_map("trim", explode("/",$file));
  304. // TODO: plugins info
  305. $name=$author=$description=$homepage="";
  306. $plugins[] = array( $id, (in_array($id, $a->plugins)?"on":"off") , $name, $author, $description, $homepage);
  307. }
  308. }
  309. }
  310. $t = get_markup_template("admin_plugins.tpl");
  311. return replace_macros($t, array(
  312. '$title' => t('Administration'),
  313. '$page' => t('Plugins'),
  314. '$submit' => t('Submit'),
  315. '$baseurl' => $a->get_baseurl(),
  316. '$plugins' => $plugins
  317. ));
  318. }
  319. /**
  320. * Logs admin page
  321. */
  322. function admin_page_logs_post(&$a) {
  323. if (x($_POST,"page_logs")) {
  324. $logfile = ((x($_POST,'logfile')) ? notags(trim($_POST['logfile'])) : '');
  325. $debugging = ((x($_POST,'debugging')) ? true : false);
  326. $loglevel = ((x($_POST,'loglevel')) ? intval(trim($_POST['loglevel'])) : 0);
  327. set_config('system','logfile', $logfile);
  328. set_config('system','debugging', $debugging);
  329. set_config('system','loglevel', $loglevel);
  330. }
  331. goaway($a->get_baseurl() . '/admin/logs' );
  332. return; // NOTREACHED
  333. }
  334. function admin_page_logs(&$a){
  335. $log_choices = Array(
  336. LOGGER_NORMAL => 'Normal',
  337. LOGGER_TRACE => 'Trace',
  338. LOGGER_DEBUG => 'Debug',
  339. LOGGER_DATA => 'Data',
  340. LOGGER_ALL => 'All'
  341. );
  342. $t = get_markup_template("admin_logs.tpl");
  343. return replace_macros($t, array(
  344. '$title' => t('Administration'),
  345. '$page' => t('Logs'),
  346. '$submit' => t('Submit'),
  347. '$clear' => t('Clear'),
  348. '$baseurl' => $a->get_baseurl(),
  349. '$logname' => get_config('system','logfile'),
  350. // name, label, value, help string, extra data...
  351. '$debugging' => array('debugging', t("Debugging"),get_config('system','debugging'), ""),
  352. '$logfile' => array('logfile', t("Log file"), get_config('system','logfile'), "Must be writable by web server. Relative to your Friendika index.php."),
  353. '$loglevel' => array('loglevel', t("Log level"), get_config('system','loglevel'), "", $log_choices),
  354. ));
  355. }