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.

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