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.
 
 
 
 
 
 

911 lines
28 KiB

  1. <?php
  2. /**
  3. * Friendica admin
  4. */
  5. require_once("include/remoteupdate.php");
  6. function admin_post(&$a){
  7. if(!is_site_admin()) {
  8. return;
  9. }
  10. // do not allow a page manager to access the admin panel at all.
  11. if(x($_SESSION,'submanage') && intval($_SESSION['submanage']))
  12. return;
  13. // urls
  14. if ($a->argc > 1){
  15. switch ($a->argv[1]){
  16. case 'site':
  17. admin_page_site_post($a);
  18. break;
  19. case 'users':
  20. admin_page_users_post($a);
  21. break;
  22. case 'plugins':
  23. if ($a->argc > 2 &&
  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';
  28. $func($a);
  29. }
  30. }
  31. goaway($a->get_baseurl() . '/admin/plugins/' . $a->argv[2] );
  32. return; // NOTREACHED
  33. break;
  34. case 'logs':
  35. admin_page_logs_post($a);
  36. break;
  37. case 'update':
  38. admin_page_remoteupdate_post($a);
  39. break;
  40. }
  41. }
  42. goaway($a->get_baseurl() . '/admin' );
  43. return; // NOTREACHED
  44. }
  45. function admin_content(&$a) {
  46. if(!is_site_admin()) {
  47. return login(false);
  48. }
  49. if(x($_SESSION,'submanage') && intval($_SESSION['submanage']))
  50. return;
  51. /**
  52. * Side bar links
  53. */
  54. // array( url, name, extra css classes )
  55. $aside = Array(
  56. 'site' => Array($a->get_baseurl()."/admin/site/", t("Site") , "site"),
  57. 'users' => Array($a->get_baseurl()."/admin/users/", t("Users") , "users"),
  58. 'plugins'=> Array($a->get_baseurl()."/admin/plugins/", t("Plugins") , "plugins"),
  59. 'themes' => Array($a->get_baseurl()."/admin/themes/", t("Themes") , "themes"),
  60. 'update' => Array($a->get_baseurl()."/admin/update/", t("Update") , "update")
  61. );
  62. /* get plugins admin page */
  63. $r = q("SELECT * FROM `addon` WHERE `plugin_admin`=1");
  64. $aside['plugins_admin']=Array();
  65. foreach ($r as $h){
  66. $plugin =$h['name'];
  67. $aside['plugins_admin'][] = Array($a->get_baseurl()."/admin/plugins/".$plugin, $plugin, "plugin");
  68. // temp plugins with admin
  69. $a->plugins_admin[] = $plugin;
  70. }
  71. $aside['logs'] = Array($a->get_baseurl()."/admin/logs/", t("Logs"), "logs");
  72. $t = get_markup_template("admin_aside.tpl");
  73. $a->page['aside'] = replace_macros( $t, array(
  74. '$admin' => $aside,
  75. '$h_pending' => t('User registrations waiting for confirmation'),
  76. '$admurl'=> $a->get_baseurl()."/admin/"
  77. ));
  78. /**
  79. * Page content
  80. */
  81. $o = '';
  82. // urls
  83. if ($a->argc > 1){
  84. switch ($a->argv[1]){
  85. case 'site':
  86. $o = admin_page_site($a);
  87. break;
  88. case 'users':
  89. $o = admin_page_users($a);
  90. break;
  91. case 'plugins':
  92. $o = admin_page_plugins($a);
  93. break;
  94. case 'themes':
  95. $o = admin_page_themes($a);
  96. break;
  97. case 'logs':
  98. $o = admin_page_logs($a);
  99. break;
  100. case 'update':
  101. $o = admin_page_remoteupdate($a);
  102. break;
  103. default:
  104. notice( t("Item not found.") );
  105. }
  106. } else {
  107. $o = admin_page_summary($a);
  108. }
  109. return $o;
  110. }
  111. /**
  112. * Admin Summary Page
  113. */
  114. function admin_page_summary(&$a) {
  115. $r = q("SELECT `page-flags`, COUNT(uid) as `count` FROM `user` GROUP BY `page-flags`");
  116. $accounts = Array(
  117. Array( t('Normal Account'), 0),
  118. Array( t('Soapbox Account'), 0),
  119. Array( t('Community/Celebrity Account'), 0),
  120. Array( t('Automatic Friend Account'), 0)
  121. );
  122. $users=0;
  123. foreach ($r as $u){ $accounts[$u['page-flags']][1] = $u['count']; $users+=$u['count']; }
  124. $r = q("SELECT COUNT(id) as `count` FROM `register`");
  125. $pending = $r[0]['count'];
  126. $t = get_markup_template("admin_summary.tpl");
  127. return replace_macros($t, array(
  128. '$title' => t('Administration'),
  129. '$page' => t('Summary'),
  130. '$users' => Array( t('Registered users'), $users),
  131. '$accounts' => $accounts,
  132. '$pending' => Array( t('Pending registrations'), $pending),
  133. '$version' => Array( t('Version'), FRIENDICA_VERSION),
  134. '$build' => get_config('system','build'),
  135. '$plugins' => Array( t('Active plugins'), $a->plugins )
  136. ));
  137. }
  138. /**
  139. * Admin Site Page
  140. */
  141. function admin_page_site_post(&$a){
  142. if (!x($_POST,"page_site")){
  143. return;
  144. }
  145. $sitename = ((x($_POST,'sitename')) ? notags(trim($_POST['sitename'])) : '');
  146. $banner = ((x($_POST,'banner')) ? trim($_POST['banner']) : false);
  147. $language = ((x($_POST,'language')) ? notags(trim($_POST['language'])) : '');
  148. $theme = ((x($_POST,'theme')) ? notags(trim($_POST['theme'])) : '');
  149. $maximagesize = ((x($_POST,'maximagesize')) ? intval(trim($_POST['maximagesize'])) : 0);
  150. $register_policy = ((x($_POST,'register_policy')) ? intval(trim($_POST['register_policy'])) : 0);
  151. $abandon_days = ((x($_POST,'abandon_days')) ? intval(trim($_POST['abandon_days'])) : 0);
  152. $register_text = ((x($_POST,'register_text')) ? notags(trim($_POST['register_text'])) : '');
  153. $allowed_sites = ((x($_POST,'allowed_sites')) ? notags(trim($_POST['allowed_sites'])) : '');
  154. $allowed_email = ((x($_POST,'allowed_email')) ? notags(trim($_POST['allowed_email'])) : '');
  155. $block_public = ((x($_POST,'block_public')) ? True : False);
  156. $force_publish = ((x($_POST,'publish_all')) ? True : False);
  157. $global_directory = ((x($_POST,'directory_submit_url')) ? notags(trim($_POST['directory_submit_url'])) : '');
  158. $no_multi_reg = ((x($_POST,'no_multi_reg')) ? True : False);
  159. $no_openid = !((x($_POST,'no_openid')) ? True : False);
  160. $no_gravatar = !((x($_POST,'no_gravatar')) ? True : False);
  161. $no_regfullname = !((x($_POST,'no_regfullname')) ? True : False);
  162. $no_utf = !((x($_POST,'no_utf')) ? True : False);
  163. $no_community_page = !((x($_POST,'no_community_page')) ? True : False);
  164. $verifyssl = ((x($_POST,'verifyssl')) ? True : False);
  165. $proxyuser = ((x($_POST,'proxyuser')) ? notags(trim($_POST['proxyuser'])) : '');
  166. $proxy = ((x($_POST,'proxy')) ? notags(trim($_POST['proxy'])) : '');
  167. $timeout = ((x($_POST,'timeout')) ? intval(trim($_POST['timeout'])) : 60);
  168. $dfrn_only = ((x($_POST,'dfrn_only')) ? True : False);
  169. $ostatus_disabled = !((x($_POST,'ostatus_disabled')) ? True : False);
  170. $diaspora_enabled = ((x($_POST,'diaspora_enabled')) ? True : False);
  171. set_config('config','sitename',$sitename);
  172. if ($banner==""){
  173. // don't know why, but del_config doesn't work...
  174. q("DELETE FROM `config` WHERE `cat` = '%s' AND `k` = '%s' LIMIT 1",
  175. dbesc("system"),
  176. dbesc("banner")
  177. );
  178. } else {
  179. set_config('system','banner', $banner);
  180. }
  181. set_config('system','language', $language);
  182. set_config('system','theme', $theme);
  183. set_config('system','maximagesize', $maximagesize);
  184. set_config('config','register_policy', $register_policy);
  185. set_config('system','account_abandon_days', $abandon_days);
  186. set_config('config','register_text', $register_text);
  187. set_config('system','allowed_sites', $allowed_sites);
  188. set_config('system','allowed_email', $allowed_email);
  189. set_config('system','block_public', $block_public);
  190. set_config('system','publish_all', $force_publish);
  191. if ($global_directory==""){
  192. // don't know why, but del_config doesn't work...
  193. q("DELETE FROM `config` WHERE `cat` = '%s' AND `k` = '%s' LIMIT 1",
  194. dbesc("system"),
  195. dbesc("directory_submit_url")
  196. );
  197. } else {
  198. set_config('system','directory_submit_url', $global_directory);
  199. }
  200. set_config('system','directory_search_url', $global_search_url);
  201. set_config('system','block_extended_register', $no_multi_reg);
  202. set_config('system','no_openid', $no_openid);
  203. set_config('system','no_gravatar', $no_gravatar);
  204. set_config('system','no_regfullname', $no_regfullname);
  205. set_config('system','no_community_page', $no_community_page);
  206. set_config('system','no_utf', $no_utf);
  207. set_config('system','verifyssl', $verifyssl);
  208. set_config('system','proxyuser', $proxyuser);
  209. set_config('system','proxy', $proxy);
  210. set_config('system','curl_timeout', $timeout);
  211. set_config('system','dfrn_only', $dfrn_only);
  212. set_config('system','ostatus_disabled', $ostatus_disabled);
  213. set_config('system','diaspora_enabled', $diaspora_enabled);
  214. info( t('Site settings updated.') . EOL);
  215. goaway($a->get_baseurl() . '/admin/site' );
  216. return; // NOTREACHED
  217. }
  218. function admin_page_site(&$a) {
  219. /* Installed langs */
  220. $lang_choices = array();
  221. $langs = glob('view/*/strings.php');
  222. if(is_array($langs) && count($langs)) {
  223. if(! in_array('view/en/strings.php',$langs))
  224. $langs[] = 'view/en/';
  225. asort($langs);
  226. foreach($langs as $l) {
  227. $t = explode("/",$l);
  228. $lang_choices[$t[1]] = $t[1];
  229. }
  230. }
  231. /* Installed themes */
  232. $theme_choices = array();
  233. $files = glob('view/theme/*');
  234. if($files) {
  235. foreach($files as $file) {
  236. $f = basename($file);
  237. $theme_name = ((file_exists($file . '/experimental')) ? sprintf("%s - \x28Experimental\x29", $f) : $f);
  238. $theme_choices[$f] = $theme_name;
  239. }
  240. }
  241. /* Banner */
  242. $banner = get_config('system','banner');
  243. if($banner == false)
  244. $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>';
  245. $banner = htmlspecialchars($banner);
  246. //echo "<pre>"; var_dump($lang_choices); die("</pre>");
  247. /* Register policy */
  248. $register_choices = Array(
  249. REGISTER_CLOSED => t("Closed"),
  250. REGISTER_APPROVE => t("Requires approval"),
  251. REGISTER_OPEN => t("Open")
  252. );
  253. $t = get_markup_template("admin_site.tpl");
  254. return replace_macros($t, array(
  255. '$title' => t('Administration'),
  256. '$page' => t('Site'),
  257. '$submit' => t('Submit'),
  258. '$registration' => t('Registration'),
  259. '$upload' => t('File upload'),
  260. '$corporate' => t('Policies'),
  261. '$advanced' => t('Advanced'),
  262. '$baseurl' => $a->get_baseurl(),
  263. // name, label, value, help string, extra data...
  264. '$sitename' => array('sitename', t("Site name"), htmlentities($a->config['sitename'], ENT_QUOTES), ""),
  265. '$banner' => array('banner', t("Banner/Logo"), $banner, ""),
  266. '$language' => array('language', t("System language"), get_config('system','language'), "", $lang_choices),
  267. '$theme' => array('theme', t("System theme"), get_config('system','theme'), "Default system theme (which may be over-ridden by user profiles)", $theme_choices),
  268. '$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."),
  269. '$register_policy' => array('register_policy', t("Register policy"), $a->config['register_policy'], "", $register_choices),
  270. '$register_text' => array('register_text', t("Register text"), htmlentities($a->config['register_text'], ENT_QUOTES), "Will be displayed prominently on the registration page."),
  271. '$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.')),
  272. '$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"),
  273. '$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"),
  274. '$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."),
  275. '$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."),
  276. '$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."),
  277. '$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."),
  278. '$no_openid' => array('no_openid', t("OpenID support"), !get_config('system','no_openid'), "OpenID support for registration and logins."),
  279. '$no_gravatar' => array('no_gravatar', t("Gravatar support"), !get_config('system','no_gravatar'), "Search new user's photo on Gravatar."),
  280. '$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"),
  281. '$no_utf' => array('no_utf', t("UTF-8 Regular expressions"), !get_config('system','no_utf'), "Use PHP UTF8 regular expressions"),
  282. '$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."),
  283. '$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."),
  284. '$diaspora_enabled' => array('diaspora_enabled', t("Enable Diaspora support"), get_config('system','diaspora_enabled'), "Provide built-in Diaspora network compatibility."),
  285. '$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."),
  286. '$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."),
  287. '$proxyuser' => array('proxyuser', t("Proxy user"), get_config('system','proxyuser'), ""),
  288. '$proxy' => array('proxy', t("Proxy URL"), get_config('system','proxy'), ""),
  289. '$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)."),
  290. ));
  291. }
  292. /**
  293. * Users admin page
  294. */
  295. function admin_page_users_post(&$a){
  296. $pending = ( x($_POST, 'pending') ? $_POST['pending'] : Array() );
  297. $users = ( x($_POST, 'user') ? $_POST['user'] : Array() );
  298. if (x($_POST,'page_users_block')){
  299. foreach($users as $uid){
  300. q("UPDATE `user` SET `blocked`=1-`blocked` WHERE `uid`=%s",
  301. intval( $uid )
  302. );
  303. }
  304. notice( sprintf( tt("%s user blocked", "%s users blocked/unblocked", count($users)), count($users)) );
  305. }
  306. if (x($_POST,'page_users_delete')){
  307. require_once("include/Contact.php");
  308. foreach($users as $uid){
  309. user_remove($uid);
  310. }
  311. notice( sprintf( tt("%s user deleted", "%s users deleted", count($users)), count($users)) );
  312. }
  313. if (x($_POST,'page_users_approve')){
  314. require_once("mod/regmod.php");
  315. foreach($pending as $hash){
  316. user_allow($hash);
  317. }
  318. }
  319. if (x($_POST,'page_users_deny')){
  320. require_once("mod/regmod.php");
  321. foreach($pending as $hash){
  322. user_deny($hash);
  323. }
  324. }
  325. goaway($a->get_baseurl() . '/admin/users' );
  326. return; // NOTREACHED
  327. }
  328. function admin_page_users(&$a){
  329. if ($a->argc>2) {
  330. $uid = $a->argv[3];
  331. $user = q("SELECT * FROM `user` WHERE `uid`=%d", intval($uid));
  332. if (count($user)==0){
  333. notice( 'User not found' . EOL);
  334. goaway($a->get_baseurl() . '/admin/users' );
  335. return; // NOTREACHED
  336. }
  337. switch($a->argv[2]){
  338. case "delete":{
  339. // delete user
  340. require_once("include/Contact.php");
  341. user_remove($uid);
  342. notice( sprintf(t("User '%s' deleted"), $user[0]['username']) . EOL);
  343. }; break;
  344. case "block":{
  345. q("UPDATE `user` SET `blocked`=%d WHERE `uid`=%s",
  346. intval( 1-$user[0]['blocked'] ),
  347. intval( $uid )
  348. );
  349. notice( sprintf( ($user[0]['blocked']?t("User '%s' unblocked"):t("User '%s' blocked")) , $user[0]['username']) . EOL);
  350. }; break;
  351. }
  352. goaway($a->get_baseurl() . '/admin/users' );
  353. return; // NOTREACHED
  354. }
  355. /* get pending */
  356. $pending = q("SELECT `register`.*, `contact`.`name`, `user`.`email`
  357. FROM `register`
  358. LEFT JOIN `contact` ON `register`.`uid` = `contact`.`uid`
  359. LEFT JOIN `user` ON `register`.`uid` = `user`.`uid`;");
  360. /* get users */
  361. $total = q("SELECT count(*) as total FROM `user` where 1");
  362. if(count($total)) {
  363. $a->set_pager_total($total[0]['total']);
  364. $a->set_pager_itemspage(100);
  365. }
  366. $users = q("SELECT `user` . * , `contact`.`name` , `contact`.`url` , `contact`.`micro`, `lastitem`.`lastitem_date`
  367. FROM
  368. (SELECT MAX(`item`.`changed`) as `lastitem_date`, `item`.`uid`
  369. FROM `item`
  370. WHERE `item`.`type` = 'wall'
  371. GROUP BY `item`.`uid`) AS `lastitem`
  372. RIGHT OUTER JOIN `user` ON `user`.`uid` = `lastitem`.`uid`,
  373. `contact`
  374. WHERE
  375. `user`.`uid` = `contact`.`uid`
  376. AND `user`.`verified` =1
  377. AND `contact`.`self` =1
  378. ORDER BY `contact`.`name` LIMIT %d, %d
  379. ",
  380. intval($a->pager['start']),
  381. intval($a->pager['itemspage'])
  382. );
  383. function _setup_users($e){
  384. $accounts = Array(
  385. t('Normal Account'),
  386. t('Soapbox Account'),
  387. t('Community/Celebrity Account'),
  388. t('Automatic Friend Account')
  389. );
  390. $e['page-flags'] = $accounts[$e['page-flags']];
  391. $e['register_date'] = relative_date($e['register_date']);
  392. $e['login_date'] = relative_date($e['login_date']);
  393. $e['lastitem_date'] = relative_date($e['lastitem_date']);
  394. return $e;
  395. }
  396. $users = array_map("_setup_users", $users);
  397. $t = get_markup_template("admin_users.tpl");
  398. $o = replace_macros($t, array(
  399. // strings //
  400. '$title' => t('Administration'),
  401. '$page' => t('Users'),
  402. '$submit' => t('Submit'),
  403. '$select_all' => t('select all'),
  404. '$h_pending' => t('User registrations waiting for confirm'),
  405. '$th_pending' => array( t('Request date'), t('Name'), t('Email') ),
  406. '$no_pending' => t('No registrations.'),
  407. '$approve' => t('Approve'),
  408. '$deny' => t('Deny'),
  409. '$delete' => t('Delete'),
  410. '$block' => t('Block'),
  411. '$unblock' => t('Unblock'),
  412. '$h_users' => t('Users'),
  413. '$th_users' => array( t('Name'), t('Email'), t('Register date'), t('Last login'), t('Last item'), t('Account') ),
  414. '$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?'),
  415. '$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?'),
  416. // values //
  417. '$baseurl' => $a->get_baseurl(),
  418. '$pending' => $pending,
  419. '$users' => $users,
  420. ));
  421. $o .= paginate($a);
  422. return $o;
  423. }
  424. /*
  425. * Plugins admin page
  426. */
  427. function admin_page_plugins(&$a){
  428. /**
  429. * Single plugin
  430. */
  431. if ($a->argc == 3){
  432. $plugin = $a->argv[2];
  433. if (!is_file("addon/$plugin/$plugin.php")){
  434. notice( t("Item not found.") );
  435. return;
  436. }
  437. if (x($_GET,"a") && $_GET['a']=="t"){
  438. // Toggle plugin status
  439. $idx = array_search($plugin, $a->plugins);
  440. if ($idx !== false){
  441. unset($a->plugins[$idx]);
  442. uninstall_plugin($plugin);
  443. info( sprintf( t("Plugin %s disabled."), $plugin ) );
  444. } else {
  445. $a->plugins[] = $plugin;
  446. install_plugin($plugin);
  447. info( sprintf( t("Plugin %s enabled."), $plugin ) );
  448. }
  449. set_config("system","addon", implode(", ",$a->plugins));
  450. goaway($a->get_baseurl() . '/admin/plugins' );
  451. return; // NOTREACHED
  452. }
  453. // display plugin details
  454. require_once('library/markdown.php');
  455. if (in_array($plugin, $a->plugins)){
  456. $status="on"; $action= t("Disable");
  457. } else {
  458. $status="off"; $action= t("Enable");
  459. }
  460. $readme=Null;
  461. if (is_file("addon/$plugin/README.md")){
  462. $readme = file_get_contents("addon/$plugin/README.md");
  463. $readme = Markdown($readme);
  464. } else if (is_file("addon/$plugin/README")){
  465. $readme = "<pre>". file_get_contents("addon/$plugin/README") ."</pre>";
  466. }
  467. $admin_form="";
  468. if (is_array($a->plugins_admin) && in_array($plugin, $a->plugins_admin)){
  469. @require_once("addon/$plugin/$plugin.php");
  470. $func = $plugin.'_plugin_admin';
  471. $func($a, $admin_form);
  472. }
  473. $t = get_markup_template("admin_plugins_details.tpl");
  474. return replace_macros($t, array(
  475. '$title' => t('Administration'),
  476. '$page' => t('Plugins'),
  477. '$toggle' => t('Toggle'),
  478. '$settings' => t('Settings'),
  479. '$baseurl' => $a->get_baseurl(),
  480. '$plugin' => $plugin,
  481. '$status' => $status,
  482. '$action' => $action,
  483. '$info' => get_plugin_info($plugin),
  484. '$admin_form' => $admin_form,
  485. '$function' => 'plugins',
  486. '$readme' => $readme
  487. ));
  488. }
  489. /**
  490. * List plugins
  491. */
  492. $plugins = array();
  493. $files = glob("addon/*/");
  494. if($files) {
  495. foreach($files as $file) {
  496. if (is_dir($file)){
  497. list($tmp, $id)=array_map("trim", explode("/",$file));
  498. $info = get_plugin_info($id);
  499. $plugins[] = array( $id, (in_array($id, $a->plugins)?"on":"off") , $info);
  500. }
  501. }
  502. }
  503. $t = get_markup_template("admin_plugins.tpl");
  504. return replace_macros($t, array(
  505. '$title' => t('Administration'),
  506. '$page' => t('Plugins'),
  507. '$submit' => t('Submit'),
  508. '$baseurl' => $a->get_baseurl(),
  509. '$function' => 'plugins',
  510. '$plugins' => $plugins
  511. ));
  512. }
  513. function toggle_theme(&$themes,$th,&$result) {
  514. for($x = 0; $x < count($themes); $x ++) {
  515. if($themes[$x]['name'] === $th) {
  516. if($themes[$x]['allowed']) {
  517. $themes[$x]['allowed'] = 0;
  518. $result = 0;
  519. }
  520. else {
  521. $themes[$x]['allowed'] = 1;
  522. $result = 1;
  523. }
  524. }
  525. }
  526. }
  527. function theme_status($themes,$th) {
  528. for($x = 0; $x < count($themes); $x ++) {
  529. if($themes[$x]['name'] === $th) {
  530. if($themes[$x]['allowed']) {
  531. return 1;
  532. }
  533. else {
  534. return 0;
  535. }
  536. }
  537. }
  538. return 0;
  539. }
  540. function rebuild_theme_table($themes) {
  541. $o = '';
  542. if(count($themes)) {
  543. foreach($themes as $th) {
  544. if($th['allowed']) {
  545. if(strlen($o))
  546. $o .= ',';
  547. $o .= $th['name'];
  548. }
  549. }
  550. }
  551. return $o;
  552. }
  553. /*
  554. * Themes admin page
  555. */
  556. function admin_page_themes(&$a){
  557. $allowed_themes_str = get_config('system','allowed_themes');
  558. $allowed_themes_raw = explode(',',$allowed_themes_str);
  559. $allowed_themes = array();
  560. if(count($allowed_themes_raw))
  561. foreach($allowed_themes_raw as $x)
  562. if(strlen(trim($x)))
  563. $allowed_themes[] = trim($x);
  564. $themes = array();
  565. $files = glob('view/theme/*');
  566. if($files) {
  567. foreach($files as $file) {
  568. $f = basename($file);
  569. $is_experimental = intval(file_exists($file . '/experimental'));
  570. $is_unsupported = 1-(intval(file_exists($file . '/unsupported')));
  571. $is_allowed = intval(in_array($f,$allowed_themes));
  572. $themes[] = array('name' => $f, 'experimental' => $is_experimental, 'supported' => $is_supported, 'allowed' => $is_allowed);
  573. }
  574. }
  575. if(! count($themes)) {
  576. notice( t('No themes found.'));
  577. return;
  578. }
  579. /**
  580. * Single theme
  581. */
  582. if ($a->argc == 3){
  583. $theme = $a->argv[2];
  584. if(! is_dir("view/theme/$theme")){
  585. notice( t("Item not found.") );
  586. return;
  587. }
  588. if (x($_GET,"a") && $_GET['a']=="t"){
  589. // Toggle theme status
  590. toggle_theme($themes,$theme,$result);
  591. $s = rebuild_theme_table($themes);
  592. if($result)
  593. info( sprintf('Theme %s enabled.',$theme));
  594. else
  595. info( sprintf('Theme %s disabled.',$theme));
  596. set_config('system','allowed_themes',$s);
  597. goaway($a->get_baseurl() . '/admin/themes' );
  598. return; // NOTREACHED
  599. }
  600. // display plugin details
  601. require_once('library/markdown.php');
  602. if (theme_status($themes,$theme)) {
  603. $status="on"; $action= t("Disable");
  604. } else {
  605. $status="off"; $action= t("Enable");
  606. }
  607. $readme=Null;
  608. if (is_file("view/$theme/README.md")){
  609. $readme = file_get_contents("view/$theme/README.md");
  610. $readme = Markdown($readme);
  611. } else if (is_file("view/$theme/README")){
  612. $readme = "<pre>". file_get_contents("view/$theme/README") ."</pre>";
  613. }
  614. $admin_form="";
  615. $t = get_markup_template("admin_plugins_details.tpl");
  616. return replace_macros($t, array(
  617. '$title' => t('Administration'),
  618. '$page' => t('Themes'),
  619. '$toggle' => t('Toggle'),
  620. '$settings' => t('Settings'),
  621. '$baseurl' => $a->get_baseurl(),
  622. '$plugin' => $theme,
  623. '$status' => $status,
  624. '$action' => $action,
  625. '$info' => get_theme_info($theme),
  626. '$function' => 'themes',
  627. '$admin_form' => $admin_form,
  628. '$readme' => $readme
  629. ));
  630. }
  631. /**
  632. * List plugins
  633. */
  634. $xthemes = array();
  635. if($themes) {
  636. foreach($themes as $th) {
  637. $xthemes[] = array($th['name'],(($th['allowed']) ? "on" : "off"), get_theme_info($th['name']));
  638. }
  639. }
  640. $t = get_markup_template("admin_plugins.tpl");
  641. return replace_macros($t, array(
  642. '$title' => t('Administration'),
  643. '$page' => t('Themes'),
  644. '$submit' => t('Submit'),
  645. '$baseurl' => $a->get_baseurl(),
  646. '$function' => 'themes',
  647. '$plugins' => $xthemes
  648. ));
  649. }
  650. /**
  651. * Logs admin page
  652. */
  653. function admin_page_logs_post(&$a) {
  654. if (x($_POST,"page_logs")) {
  655. $logfile = ((x($_POST,'logfile')) ? notags(trim($_POST['logfile'])) : '');
  656. $debugging = ((x($_POST,'debugging')) ? true : false);
  657. $loglevel = ((x($_POST,'loglevel')) ? intval(trim($_POST['loglevel'])) : 0);
  658. set_config('system','logfile', $logfile);
  659. set_config('system','debugging', $debugging);
  660. set_config('system','loglevel', $loglevel);
  661. }
  662. info( t("Log settings updated.") );
  663. goaway($a->get_baseurl() . '/admin/logs' );
  664. return; // NOTREACHED
  665. }
  666. function admin_page_logs(&$a){
  667. $log_choices = Array(
  668. LOGGER_NORMAL => 'Normal',
  669. LOGGER_TRACE => 'Trace',
  670. LOGGER_DEBUG => 'Debug',
  671. LOGGER_DATA => 'Data',
  672. LOGGER_ALL => 'All'
  673. );
  674. $t = get_markup_template("admin_logs.tpl");
  675. $f = get_config('system','logfile');
  676. $data = '';
  677. if(!file_exists($f)) {
  678. $data = t("Error trying to open <strong>$f</strong> log file.\r\n<br/>Check to see if file $f exist and is
  679. readable.");
  680. }
  681. else {
  682. $fp = fopen($f, 'r');
  683. if(!$fp) {
  684. $data = t("Couldn't open <strong>$f</strong> log file.\r\n<br/>Check to see if file $f is readable.");
  685. }
  686. else {
  687. $fstat = fstat($fp);
  688. $size = $fstat['size'];
  689. if($size != 0)
  690. {
  691. if($size > 5000000 || $size < 0)
  692. $size = 5000000;
  693. $seek = fseek($fp,0-$size,SEEK_END);
  694. if($seek === 0) {
  695. fgets($fp); // throw away the first partial line
  696. $data = escape_tags(fread($fp,$size));
  697. while(! feof($fp))
  698. $data .= escape_tags(fread($fp,4096));
  699. }
  700. }
  701. fclose($fp);
  702. }
  703. }
  704. return replace_macros($t, array(
  705. '$title' => t('Administration'),
  706. '$page' => t('Logs'),
  707. '$submit' => t('Submit'),
  708. '$clear' => t('Clear'),
  709. '$data' => $data,
  710. '$baseurl' => $a->get_baseurl(),
  711. '$logname' => get_config('system','logfile'),
  712. // name, label, value, help string, extra data...
  713. '$debugging' => array('debugging', t("Debugging"),get_config('system','debugging'), ""),
  714. '$logfile' => array('logfile', t("Log file"), get_config('system','logfile'), t("Must be writable by web server. Relative to your Friendica top-level directory.")),
  715. '$loglevel' => array('loglevel', t("Log level"), get_config('system','loglevel'), "", $log_choices),
  716. ));
  717. }
  718. function admin_page_remoteupdate_post(&$a) {
  719. // this function should be called via ajax post
  720. if(!is_site_admin()) {
  721. return;
  722. }
  723. if (x($_POST,'remotefile') && $_POST['remotefile']!=""){
  724. $remotefile = $_POST['remotefile'];
  725. $ftpdata = (x($_POST['ftphost'])?$_POST:false);
  726. doUpdate($remotefile, $ftpdata);
  727. } else {
  728. echo "No remote file to download. Abort!";
  729. }
  730. killme();
  731. }
  732. function admin_page_remoteupdate(&$a) {
  733. if(!is_site_admin()) {
  734. return login(false);
  735. }
  736. $canwrite = canWeWrite();
  737. $canftp = function_exists('ftp_connect');
  738. $needupdate = true;
  739. $u = checkUpdate();
  740. if (!is_array($u)){
  741. $needupdate = false;
  742. $u = array('','','');
  743. }
  744. $tpl = get_markup_template("admin_remoteupdate.tpl");
  745. return replace_macros($tpl, array(
  746. '$baseurl' => $a->get_baseurl(),
  747. '$submit' => t("Update now"),
  748. '$close' => t("Close"),
  749. '$localversion' => FRIENDICA_VERSION,
  750. '$remoteversion' => $u[1],
  751. '$needupdate' => $needupdate,
  752. '$canwrite' => $canwrite,
  753. '$canftp' => $canftp,
  754. '$ftphost' => array('ftphost', t("FTP Host"), '',''),
  755. '$ftppath' => array('ftppath', t("FTP Path"), '/',''),
  756. '$ftpuser' => array('ftpuser', t("FTP User"), '',''),
  757. '$ftppwd' => array('ftppwd', t("FTP Password"), '',''),
  758. '$remotefile'=>array('remotefile','', $u['2'],'')
  759. ));
  760. }