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.
 
 
 
 
 
 

494 lines
16 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. '$h_pending' => t('User registrations waiting for confirm'),
  54. '$admurl'=> $a->get_baseurl()."/admin/"
  55. ));
  56. /**
  57. * Page content
  58. */
  59. $o = '';
  60. // urls
  61. if ($a->argc > 1){
  62. switch ($a->argv[1]){
  63. case 'site':
  64. $o = admin_page_site($a);
  65. break;
  66. case 'users':
  67. $o = admin_page_users($a);
  68. break;
  69. case 'plugins':
  70. $o = admin_page_plugins($a);
  71. break;
  72. case 'logs':
  73. $o = admin_page_logs($a);
  74. break;
  75. default:
  76. notice( t("Item not found.") );
  77. }
  78. } else {
  79. $o = admin_page_summary($a);
  80. }
  81. return $o;
  82. }
  83. /**
  84. * Admin Summary Page
  85. */
  86. function admin_page_summary(&$a) {
  87. $r = q("SELECT `page-flags`, COUNT(uid) as `count` FROM `user` GROUP BY `page-flags`");
  88. $accounts = Array(
  89. Array( t('Normal Account'), 0),
  90. Array( t('Soapbox Account'), 0),
  91. Array( t('Community/Celebrity Account'), 0),
  92. Array( t('Automatic Friend Account'), 0)
  93. );
  94. $users=0;
  95. foreach ($r as $u){ $accounts[$u['page-flags']][1] = $u['count']; $users+=$u['count']; }
  96. $r = q("SELECT COUNT(id) as `count` FROM `register`");
  97. $pending = $r[0]['count'];
  98. $t = get_markup_template("admin_summary.tpl");
  99. return replace_macros($t, array(
  100. '$title' => t('Administration'),
  101. '$page' => t('Summary'),
  102. '$users' => Array( t('Registered users'), $users),
  103. '$accounts' => $accounts,
  104. '$pending' => Array( t('Pending registrations'), $pending),
  105. '$version' => Array( t('Version'), FRIENDIKA_VERSION),
  106. '$build' => get_config('system','build'),
  107. '$plugins' => Array( t('Active plugins'), $a->plugins )
  108. ));
  109. }
  110. /**
  111. * Admin Site Page
  112. */
  113. function admin_page_site_post(&$a){
  114. if (!x($_POST,"page_site")){
  115. return;
  116. }
  117. $sitename = ((x($_POST,'sitename')) ? notags(trim($_POST['sitename'])) : '');
  118. $banner = ((x($_POST,'banner')) ? trim($_POST['banner']) : false);
  119. $language = ((x($_POST,'language')) ? notags(trim($_POST['language'])) : '');
  120. $theme = ((x($_POST,'theme')) ? notags(trim($_POST['theme'])) : '');
  121. $maximagesize = ((x($_POST,'maximagesize')) ? intval(trim($_POST['maximagesize'])) : 0);
  122. $register_policy = ((x($_POST,'register_policy')) ? intval(trim($_POST['register_policy'])) : 0);
  123. $register_text = ((x($_POST,'register_text')) ? notags(trim($_POST['register_text'])) : '');
  124. $allowed_sites = ((x($_POST,'allowed_sites')) ? notags(trim($_POST['allowed_sites'])) : '');
  125. $allowed_email = ((x($_POST,'allowed_email')) ? notags(trim($_POST['allowed_email'])) : '');
  126. $block_public = ((x($_POST,'block_public')) ? True : False);
  127. $force_publish = ((x($_POST,'publish_all')) ? True : False);
  128. $global_directory = ((x($_POST,'directory_submit_url')) ? notags(trim($_POST['directory_submit_url'])) : '');
  129. $global_search_url = ((x($_POST,'directory_search_url'))? notags(trim($_POST['directory_search_url'])) : '');
  130. $no_multi_reg = ((x($_POST,'no_multi_reg')) ? True : False);
  131. $no_openid = ((x($_POST,'no_openid')) ? True : False);
  132. $no_gravatar = ((x($_POST,'no_gravatar')) ? True : False);
  133. $no_regfullname = ((x($_POST,'no_regfullname')) ? True : False);
  134. $no_utf = ((x($_POST,'no_utf')) ? True : False);
  135. $rino_enc = ((x($_POST,'rino_enc')) ? True : False);
  136. $verifyssl = ((x($_POST,'verifyssl')) ? True : False);
  137. $proxyuser = ((x($_POST,'proxyuser')) ? notags(trim($_POST['global_search_url'])) : '');
  138. $proxy = ((x($_POST,'proxy')) ? notags(trim($_POST['global_search_url'])) : '');
  139. $timeout = ((x($_POST,'timeout')) ? intval(trim($_POST['timeout'])) : 60);
  140. set_config('config','sitename',$sitename);
  141. if ($banner==""){
  142. // don't know why, but del_config doesn't work...
  143. q("DELETE FROM `config` WHERE `cat` = '%s' AND `k` = '%s' LIMIT 1",
  144. dbesc("system"),
  145. dbesc("banner")
  146. );
  147. } else {
  148. set_config('system','banner', $banner);
  149. }
  150. set_config('system','language', $language);
  151. set_config('system','theme', $theme);
  152. set_config('system','maximagesize', $maximagesize);
  153. set_config('config','register_policy', $register_policy);
  154. set_config('config','register_text', $register_text);
  155. set_config('system','allowed_sites', $allowed_sites);
  156. set_config('system','allowed_email', $allowed_email);
  157. set_config('system','block_public', $block_public);
  158. set_config('system','publish_all', $force_publish);
  159. if ($global_directory==""){
  160. // don't know why, but del_config doesn't work...
  161. q("DELETE FROM `config` WHERE `cat` = '%s' AND `k` = '%s' LIMIT 1",
  162. dbesc("system"),
  163. dbesc("directory_submit_url")
  164. );
  165. } else {
  166. set_config('system','directory_submit_url', $global_directory);
  167. }
  168. set_config('system','directory_search_url', $global_search_url);
  169. set_config('system','block_extended_register', $no_multi_reg);
  170. set_config('system','no_openid', $no_openid);
  171. set_config('system','no_gravatar', $no_gravatar);
  172. set_config('system','no_regfullname', $no_regfullname);
  173. set_config('system','proxy', $no_utf);
  174. set_config('system','rino_encrypt', $rino_enc);
  175. set_config('system','verifyssl', $verifyssl);
  176. set_config('system','proxyuser', $proxyuser);
  177. set_config('system','proxy', $proxy);
  178. set_config('system','curl_timeout', $timeout);
  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. /* Register policy */
  211. $register_choices = Array(
  212. REGISTER_CLOSED => t("Closed"),
  213. REGISTER_APPROVE => t("Need approvation"),
  214. REGISTER_OPEN => t("Open")
  215. );
  216. $t = get_markup_template("admin_site.tpl");
  217. return replace_macros($t, array(
  218. '$title' => t('Administration'),
  219. '$page' => t('Site'),
  220. '$submit' => t('Submit'),
  221. '$baseurl' => $a->get_baseurl(),
  222. // name, label, value, help string, extra data...
  223. '$sitename' => array('sitename', t("Site name"), $a->config['sitename'], ""),
  224. '$banner' => array('banner', t("Banner/Logo"), $banner, ""),
  225. '$language' => array('language', t("System language"), get_config('system','language'), "", $lang_choices),
  226. '$theme' => array('theme', t("System theme"), get_config('system','theme'), "Default system theme (which may be over-ridden by user profiles)", $theme_choices),
  227. '$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."),
  228. '$register_policy' => array('register_policy', t("Register policy"), $a->config['register_policy'], "", $register_choices),
  229. '$register_text' => array('register_text', t("Register text"), $a->config['register_text'], "Will be displayed prominently on the registration page."),
  230. '$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"),
  231. '$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"),
  232. '$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."),
  233. '$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."),
  234. '$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."),
  235. '$global_search_url'=> array('directory_search_url', t("Global directory search URL"), get_config('system','directory_search_url'), ""),
  236. '$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."),
  237. '$no_openid' => array('no_openid', t("No OpenID support"), get_config('system','no_openid'), "Disable OpenID support for registration and logins."),
  238. '$no_gravatar' => array('no_gravatar', t("No Gravatar support"), get_config('system','no_gravatar'), ""),
  239. '$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"),
  240. '$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)"),
  241. '$rino_enc' => array('rino_enc', t("Enable Rino encrypt"), get_config('system','rino_encrypt'),""),
  242. '$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."),
  243. '$proxyuser' => array('proxyuser', t("Proxy user"), get_config('system','proxyuser'), ""),
  244. '$proxy' => array('proxy', t("Proxy URL"), get_config('system','proxy'), ""),
  245. '$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)."),
  246. ));
  247. }
  248. /**
  249. * Users admin page
  250. */
  251. function admin_page_users(&$a){
  252. /* get pending */
  253. $pending = q("SELECT `register`.*, `contact`.`name`, `user`.`email`
  254. FROM `register`
  255. LEFT JOIN `contact` ON `register`.`uid` = `contact`.`uid`
  256. LEFT JOIN `user` ON `register`.`uid` = `user`.`uid`;");
  257. /* get users */
  258. $users = q("SELECT `user`.*, `contact`.`name` FROM `user`
  259. LEFT JOIN `contact` ON `user`.`uid` = `contact`.`uid`
  260. WHERE `user`.`verified`=1 AND `contact`.`self`=1
  261. ORDER BY `contact`.`name`");
  262. $t = get_markup_template("admin_users.tpl");
  263. return replace_macros($t, array(
  264. // strings //
  265. '$title' => t('Administration'),
  266. '$page' => t('Users'),
  267. '$submit' => t('Submit'),
  268. '$select_all' => t('select all'),
  269. '$h_pending' => t('User registrations waiting for confirm'),
  270. '$th_pending' => array( t('Request date'), t('Name'), t('Email') ),
  271. '$no_pending' => t('No registrations.'),
  272. '$approve' => t('Approve'),
  273. '$deny' => t('Deny'),
  274. '$delete' => t('Delete'),
  275. '$block' => t('Block'),
  276. '$h_users' => t('Users'),
  277. '$th_users' => array( t('Name'), t('Nickname'), t('Email'), t('Register date'), t('Last login') ),
  278. // values //
  279. '$baseurl' => $a->get_baseurl(),
  280. '$pending' => $pending,
  281. '$users' => $users,
  282. ));
  283. }
  284. /*
  285. * Plugins admin page
  286. */
  287. function admin_page_plugins(&$a){
  288. /**
  289. * Single plugin
  290. */
  291. if ($a->argc == 3){
  292. $plugin = $a->argv[2];
  293. if (!is_file("addon/$plugin/$plugin.php")){
  294. notice( t("Item not found.") );
  295. return;
  296. }
  297. if (x($_GET,"a") && $_GET['a']=="t"){
  298. // Toggle plugin status
  299. $idx = array_search($plugin, $a->plugins);
  300. if ($idx){
  301. unset($a->plugins[$idx]);
  302. uninstall_plugin($plugin);
  303. } else {
  304. $a->plugins[] = $plugin;
  305. install_plugin($plugin);
  306. }
  307. set_config("system","addon", implode(", ",$a->plugins));
  308. goaway($a->get_baseurl() . '/admin/plugins' );
  309. return; // NOTREACHED
  310. }
  311. // display plugin details
  312. require_once('library/markdown.php');
  313. if (in_array($plugin, $a->plugins)){
  314. $status="on"; $action= t("Disable");
  315. } else {
  316. $status="off"; $action= t("Enable");
  317. }
  318. $readme=Null;
  319. if (is_file("addon/$plugin/README.md")){
  320. $readme = file_get_contents("addon/$plugin/README.md");
  321. $readme = Markdown($readme);
  322. } else if (is_file("addon/$plugin/README")){
  323. $readme = "<pre>". file_get_contents("addon/$plugin/README") ."</pre>";
  324. }
  325. $t = get_markup_template("admin_plugins_details.tpl");
  326. return replace_macros($t, array(
  327. '$title' => t('Administration'),
  328. '$page' => t('Plugins'),
  329. '$toggle' => t('Toggle'),
  330. '$baseurl' => $a->get_baseurl(),
  331. '$plugin' => $plugin,
  332. '$status' => $status,
  333. '$action' => $action,
  334. '$info' => get_plugin_info($plugin),
  335. '$readme' => $readme
  336. ));
  337. }
  338. /**
  339. * List plugins
  340. */
  341. $plugins = array();
  342. $files = glob("addon/*/");
  343. if($files) {
  344. foreach($files as $file) {
  345. if (is_dir($file)){
  346. list($tmp, $id)=array_map("trim", explode("/",$file));
  347. $info = get_plugin_info($id);
  348. $plugins[] = array( $id, (in_array($id, $a->plugins)?"on":"off") , $info);
  349. }
  350. }
  351. }
  352. $t = get_markup_template("admin_plugins.tpl");
  353. return replace_macros($t, array(
  354. '$title' => t('Administration'),
  355. '$page' => t('Plugins'),
  356. '$submit' => t('Submit'),
  357. '$baseurl' => $a->get_baseurl(),
  358. '$plugins' => $plugins
  359. ));
  360. }
  361. /**
  362. * Logs admin page
  363. */
  364. function admin_page_logs_post(&$a) {
  365. if (x($_POST,"page_logs")) {
  366. $logfile = ((x($_POST,'logfile')) ? notags(trim($_POST['logfile'])) : '');
  367. $debugging = ((x($_POST,'debugging')) ? true : false);
  368. $loglevel = ((x($_POST,'loglevel')) ? intval(trim($_POST['loglevel'])) : 0);
  369. set_config('system','logfile', $logfile);
  370. set_config('system','debugging', $debugging);
  371. set_config('system','loglevel', $loglevel);
  372. }
  373. goaway($a->get_baseurl() . '/admin/logs' );
  374. return; // NOTREACHED
  375. }
  376. function admin_page_logs(&$a){
  377. $log_choices = Array(
  378. LOGGER_NORMAL => 'Normal',
  379. LOGGER_TRACE => 'Trace',
  380. LOGGER_DEBUG => 'Debug',
  381. LOGGER_DATA => 'Data',
  382. LOGGER_ALL => 'All'
  383. );
  384. $t = get_markup_template("admin_logs.tpl");
  385. return replace_macros($t, array(
  386. '$title' => t('Administration'),
  387. '$page' => t('Logs'),
  388. '$submit' => t('Submit'),
  389. '$clear' => t('Clear'),
  390. '$baseurl' => $a->get_baseurl(),
  391. '$logname' => get_config('system','logfile'),
  392. // name, label, value, help string, extra data...
  393. '$debugging' => array('debugging', t("Debugging"),get_config('system','debugging'), ""),
  394. '$logfile' => array('logfile', t("Log file"), get_config('system','logfile'), "Must be writable by web server. Relative to your Friendika index.php."),
  395. '$loglevel' => array('loglevel', t("Log level"), get_config('system','loglevel'), "", $log_choices),
  396. ));
  397. }