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.

722 lines
24 KiB

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