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.
 
 
 
 
 
 

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