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.
 
 
 
 
 
 

1245 lines
43 KiB

  1. <?php
  2. /**
  3. * Friendica admin
  4. */
  5. require_once("include/remoteupdate.php");
  6. /**
  7. * @param App $a
  8. */
  9. function admin_post(&$a){
  10. if(!is_site_admin()) {
  11. return;
  12. }
  13. // do not allow a page manager to access the admin panel at all.
  14. if(x($_SESSION,'submanage') && intval($_SESSION['submanage']))
  15. return;
  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(true) . '/admin/plugins/' . $a->argv[2] );
  35. return; // NOTREACHED
  36. break;
  37. case 'themes':
  38. $theme = $a->argv[2];
  39. if (is_file("view/theme/$theme/config.php")){
  40. require_once("view/theme/$theme/config.php");
  41. if (function_exists("theme_admin_post")){
  42. theme_admin_post($a);
  43. }
  44. }
  45. info(t('Theme settings updated.'));
  46. if(is_ajax()) return;
  47. goaway($a->get_baseurl(true) . '/admin/themes/' . $theme );
  48. return;
  49. break;
  50. case 'logs':
  51. admin_page_logs_post($a);
  52. break;
  53. case 'dbsync':
  54. admin_page_dbsync_post($a);
  55. break;
  56. case 'update':
  57. admin_page_remoteupdate_post($a);
  58. break;
  59. }
  60. }
  61. goaway($a->get_baseurl(true) . '/admin' );
  62. return; // NOTREACHED
  63. }
  64. /**
  65. * @param App $a
  66. * @return string
  67. */
  68. function admin_content(&$a) {
  69. if(!is_site_admin()) {
  70. return login(false);
  71. }
  72. if(x($_SESSION,'submanage') && intval($_SESSION['submanage']))
  73. return "";
  74. /**
  75. * Side bar links
  76. */
  77. // array( url, name, extra css classes )
  78. $aside = Array(
  79. 'site' => Array($a->get_baseurl(true)."/admin/site/", t("Site") , "site"),
  80. 'users' => Array($a->get_baseurl(true)."/admin/users/", t("Users") , "users"),
  81. 'plugins'=> Array($a->get_baseurl(true)."/admin/plugins/", t("Plugins") , "plugins"),
  82. 'themes' => Array($a->get_baseurl(true)."/admin/themes/", t("Themes") , "themes"),
  83. 'dbsync' => Array($a->get_baseurl(true)."/admin/dbsync/", t('DB updates'), "dbsync"),
  84. //'update' => Array($a->get_baseurl(true)."/admin/update/", t("Software Update") , "update")
  85. );
  86. /* get plugins admin page */
  87. $r = q("SELECT * FROM `addon` WHERE `plugin_admin`=1");
  88. $aside['plugins_admin']=Array();
  89. foreach ($r as $h){
  90. $plugin =$h['name'];
  91. $aside['plugins_admin'][] = Array($a->get_baseurl(true)."/admin/plugins/".$plugin, $plugin, "plugin");
  92. // temp plugins with admin
  93. $a->plugins_admin[] = $plugin;
  94. }
  95. $aside['logs'] = Array($a->get_baseurl(true)."/admin/logs/", t("Logs"), "logs");
  96. $t = get_markup_template("admin_aside.tpl");
  97. $a->page['aside'] .= replace_macros( $t, array(
  98. '$admin' => $aside,
  99. '$admtxt' => t('Admin'),
  100. '$plugadmtxt' => t('Plugin Features'),
  101. '$logtxt' => t('Logs'),
  102. '$h_pending' => t('User registrations waiting for confirmation'),
  103. '$admurl'=> $a->get_baseurl(true)."/admin/"
  104. ));
  105. /**
  106. * Page content
  107. */
  108. $o = '';
  109. // urls
  110. if ($a->argc > 1){
  111. switch ($a->argv[1]){
  112. case 'site':
  113. $o = admin_page_site($a);
  114. break;
  115. case 'users':
  116. $o = admin_page_users($a);
  117. break;
  118. case 'plugins':
  119. $o = admin_page_plugins($a);
  120. break;
  121. case 'themes':
  122. $o = admin_page_themes($a);
  123. break;
  124. case 'logs':
  125. $o = admin_page_logs($a);
  126. break;
  127. case 'dbsync':
  128. $o = admin_page_dbsync($a);
  129. break;
  130. case 'update':
  131. $o = admin_page_remoteupdate($a);
  132. break;
  133. default:
  134. notice( t("Item not found.") );
  135. }
  136. } else {
  137. $o = admin_page_summary($a);
  138. }
  139. if(is_ajax()) {
  140. echo $o;
  141. killme();
  142. return '';
  143. } else {
  144. return $o;
  145. }
  146. }
  147. /**
  148. * Admin Summary Page
  149. * @param App $a
  150. * @return string
  151. */
  152. function admin_page_summary(&$a) {
  153. $r = q("SELECT `page-flags`, COUNT(uid) as `count` FROM `user` GROUP BY `page-flags`");
  154. $accounts = Array(
  155. Array( t('Normal Account'), 0),
  156. Array( t('Soapbox Account'), 0),
  157. Array( t('Community/Celebrity Account'), 0),
  158. Array( t('Automatic Friend Account'), 0),
  159. Array( t('Blog Account'), 0),
  160. Array( t('Private Forum'), 0)
  161. );
  162. $users=0;
  163. foreach ($r as $u){ $accounts[$u['page-flags']][1] = $u['count']; $users+= $u['count']; }
  164. logger('accounts: ' . print_r($accounts,true),LOGGER_DATA);
  165. $r = q("SELECT COUNT(id) as `count` FROM `register`");
  166. $pending = $r[0]['count'];
  167. $r = q("select count(*) as total from deliverq where 1");
  168. $deliverq = (($r) ? $r[0]['total'] : 0);
  169. $r = q("select count(*) as total from queue where 1");
  170. $queue = (($r) ? $r[0]['total'] : 0);
  171. // We can do better, but this is a quick queue status
  172. $queues = array( 'label' => t('Message queues'), 'deliverq' => $deliverq, 'queue' => $queue );
  173. $t = get_markup_template("admin_summary.tpl");
  174. return replace_macros($t, array(
  175. '$title' => t('Administration'),
  176. '$page' => t('Summary'),
  177. '$queues' => $queues,
  178. '$users' => Array( t('Registered users'), $users),
  179. '$accounts' => $accounts,
  180. '$pending' => Array( t('Pending registrations'), $pending),
  181. '$version' => Array( t('Version'), FRIENDICA_VERSION),
  182. '$build' => get_config('system','build'),
  183. '$plugins' => Array( t('Active plugins'), $a->plugins )
  184. ));
  185. }
  186. /**
  187. * Admin Site Page
  188. * @param App $a
  189. */
  190. function admin_page_site_post(&$a){
  191. if (!x($_POST,"page_site")){
  192. return;
  193. }
  194. check_form_security_token_redirectOnErr('/admin/site', 'admin_site');
  195. $sitename = ((x($_POST,'sitename')) ? notags(trim($_POST['sitename'])) : '');
  196. $banner = ((x($_POST,'banner')) ? trim($_POST['banner']) : false);
  197. $language = ((x($_POST,'language')) ? notags(trim($_POST['language'])) : '');
  198. $theme = ((x($_POST,'theme')) ? notags(trim($_POST['theme'])) : '');
  199. $theme_mobile = ((x($_POST,'theme_mobile')) ? notags(trim($_POST['theme_mobile'])) : '');
  200. $maximagesize = ((x($_POST,'maximagesize')) ? intval(trim($_POST['maximagesize'])) : 0);
  201. $maximagelength = ((x($_POST,'maximagelength')) ? intval(trim($_POST['maximagelength'])) : MAX_IMAGE_LENGTH);
  202. $jpegimagequality = ((x($_POST,'jpegimagequality')) ? intval(trim($_POST['jpegimagequality'])) : JPEG_QUALITY);
  203. $register_policy = ((x($_POST,'register_policy')) ? intval(trim($_POST['register_policy'])) : 0);
  204. $daily_registrations = ((x($_POST,'max_daily_registrations')) ? intval(trim($_POST['max_daily_registrations'])) :0);
  205. $abandon_days = ((x($_POST,'abandon_days')) ? intval(trim($_POST['abandon_days'])) : 0);
  206. $register_text = ((x($_POST,'register_text')) ? notags(trim($_POST['register_text'])) : '');
  207. $allowed_sites = ((x($_POST,'allowed_sites')) ? notags(trim($_POST['allowed_sites'])) : '');
  208. $allowed_email = ((x($_POST,'allowed_email')) ? notags(trim($_POST['allowed_email'])) : '');
  209. $block_public = ((x($_POST,'block_public')) ? True : False);
  210. $force_publish = ((x($_POST,'publish_all')) ? True : False);
  211. $global_directory = ((x($_POST,'directory_submit_url')) ? notags(trim($_POST['directory_submit_url'])) : '');
  212. $thread_allow = ((x($_POST,'thread_allow')) ? True : False);
  213. $newuser_private = ((x($_POST,'newuser_private')) ? True : False);
  214. $no_multi_reg = ((x($_POST,'no_multi_reg')) ? True : False);
  215. $no_openid = !((x($_POST,'no_openid')) ? True : False);
  216. $no_regfullname = !((x($_POST,'no_regfullname')) ? True : False);
  217. $no_utf = !((x($_POST,'no_utf')) ? True : False);
  218. $no_community_page = !((x($_POST,'no_community_page')) ? True : False);
  219. $verifyssl = ((x($_POST,'verifyssl')) ? True : False);
  220. $proxyuser = ((x($_POST,'proxyuser')) ? notags(trim($_POST['proxyuser'])) : '');
  221. $proxy = ((x($_POST,'proxy')) ? notags(trim($_POST['proxy'])) : '');
  222. $timeout = ((x($_POST,'timeout')) ? intval(trim($_POST['timeout'])) : 60);
  223. $delivery_interval = ((x($_POST,'delivery_interval')) ? intval(trim($_POST['delivery_interval'])) : 0);
  224. $poll_interval = ((x($_POST,'poll_interval')) ? intval(trim($_POST['poll_interval'])) : 0);
  225. $maxloadavg = ((x($_POST,'maxloadavg')) ? intval(trim($_POST['maxloadavg'])) : 50);
  226. $dfrn_only = ((x($_POST,'dfrn_only')) ? True : False);
  227. $ostatus_disabled = !((x($_POST,'ostatus_disabled')) ? True : False);
  228. $diaspora_enabled = ((x($_POST,'diaspora_enabled')) ? True : False);
  229. $ssl_policy = ((x($_POST,'ssl_policy')) ? intval($_POST['ssl_policy']) : 0);
  230. $new_share = ((x($_POST,'new_share')) ? True : False);
  231. $hide_help = ((x($_POST,'hide_help')) ? True : False);
  232. $use_fulltext_engine = ((x($_POST,'use_fulltext_engine')) ? True : False);
  233. $itemcache = ((x($_POST,'itemcache')) ? notags(trim($_POST['itemcache'])) : '');
  234. $itemcache_duration = ((x($_POST,'itemcache_duration')) ? intval($_POST['itemcache_duration']) : 0);
  235. $lockpath = ((x($_POST,'lockpath')) ? notags(trim($_POST['lockpath'])) : '');
  236. $temppath = ((x($_POST,'temppath')) ? notags(trim($_POST['temppath'])) : '');
  237. $basepath = ((x($_POST,'basepath')) ? notags(trim($_POST['basepath'])) : '');
  238. $singleuser = ((x($_POST,'singleuser')) ? notags(trim($_POST['singleuser'])) : '');
  239. if($ssl_policy != intval(get_config('system','ssl_policy'))) {
  240. if($ssl_policy == SSL_POLICY_FULL) {
  241. q("update `contact` set
  242. `url` = replace(`url` , 'http:' , 'https:'),
  243. `photo` = replace(`photo` , 'http:' , 'https:'),
  244. `thumb` = replace(`thumb` , 'http:' , 'https:'),
  245. `micro` = replace(`micro` , 'http:' , 'https:'),
  246. `request` = replace(`request`, 'http:' , 'https:'),
  247. `notify` = replace(`notify` , 'http:' , 'https:'),
  248. `poll` = replace(`poll` , 'http:' , 'https:'),
  249. `confirm` = replace(`confirm`, 'http:' , 'https:'),
  250. `poco` = replace(`poco` , 'http:' , 'https:')
  251. where `self` = 1"
  252. );
  253. q("update `profile` set
  254. `photo` = replace(`photo` , 'http:' , 'https:'),
  255. `thumb` = replace(`thumb` , 'http:' , 'https:')
  256. where 1 "
  257. );
  258. }
  259. elseif($ssl_policy == SSL_POLICY_SELFSIGN) {
  260. q("update `contact` set
  261. `url` = replace(`url` , 'https:' , 'http:'),
  262. `photo` = replace(`photo` , 'https:' , 'http:'),
  263. `thumb` = replace(`thumb` , 'https:' , 'http:'),
  264. `micro` = replace(`micro` , 'https:' , 'http:'),
  265. `request` = replace(`request`, 'https:' , 'http:'),
  266. `notify` = replace(`notify` , 'https:' , 'http:'),
  267. `poll` = replace(`poll` , 'https:' , 'http:'),
  268. `confirm` = replace(`confirm`, 'https:' , 'http:'),
  269. `poco` = replace(`poco` , 'https:' , 'http:')
  270. where `self` = 1"
  271. );
  272. q("update `profile` set
  273. `photo` = replace(`photo` , 'https:' , 'http:'),
  274. `thumb` = replace(`thumb` , 'https:' , 'http:')
  275. where 1 "
  276. );
  277. }
  278. }
  279. set_config('system','ssl_policy',$ssl_policy);
  280. set_config('system','delivery_interval',$delivery_interval);
  281. set_config('system','poll_interval',$poll_interval);
  282. set_config('system','maxloadavg',$maxloadavg);
  283. set_config('config','sitename',$sitename);
  284. if ($banner==""){
  285. // don't know why, but del_config doesn't work...
  286. q("DELETE FROM `config` WHERE `cat` = '%s' AND `k` = '%s' LIMIT 1",
  287. dbesc("system"),
  288. dbesc("banner")
  289. );
  290. } else {
  291. set_config('system','banner', $banner);
  292. }
  293. set_config('system','language', $language);
  294. set_config('system','theme', $theme);
  295. if ( $theme_mobile === '---' ) {
  296. del_config('system','mobile-theme');
  297. } else {
  298. set_config('system','mobile-theme', $theme_mobile);
  299. }
  300. if ( $singleuser === '---' ) {
  301. del_config('system','singleuser');
  302. } else {
  303. set_config('system','singleuser', $singleuser);
  304. }
  305. set_config('system','maximagesize', $maximagesize);
  306. set_config('system','max_image_length', $maximagelength);
  307. set_config('system','jpeg_quality', $jpegimagequality);
  308. set_config('config','register_policy', $register_policy);
  309. set_config('system','max_daily_registrations', $daily_registrations);
  310. set_config('system','account_abandon_days', $abandon_days);
  311. set_config('config','register_text', $register_text);
  312. set_config('system','allowed_sites', $allowed_sites);
  313. set_config('system','allowed_email', $allowed_email);
  314. set_config('system','block_public', $block_public);
  315. set_config('system','publish_all', $force_publish);
  316. if ($global_directory==""){
  317. // don't know why, but del_config doesn't work...
  318. q("DELETE FROM `config` WHERE `cat` = '%s' AND `k` = '%s' LIMIT 1",
  319. dbesc("system"),
  320. dbesc("directory_submit_url")
  321. );
  322. } else {
  323. set_config('system','directory_submit_url', $global_directory);
  324. }
  325. set_config('system','thread_allow', $thread_allow);
  326. set_config('system','newuser_private', $newuser_private);
  327. set_config('system','block_extended_register', $no_multi_reg);
  328. set_config('system','no_openid', $no_openid);
  329. set_config('system','no_regfullname', $no_regfullname);
  330. set_config('system','no_community_page', $no_community_page);
  331. set_config('system','no_utf', $no_utf);
  332. set_config('system','verifyssl', $verifyssl);
  333. set_config('system','proxyuser', $proxyuser);
  334. set_config('system','proxy', $proxy);
  335. set_config('system','curl_timeout', $timeout);
  336. set_config('system','dfrn_only', $dfrn_only);
  337. set_config('system','ostatus_disabled', $ostatus_disabled);
  338. set_config('system','diaspora_enabled', $diaspora_enabled);
  339. set_config('system','new_share', $new_share);
  340. set_config('system','hide_help', $hide_help);
  341. set_config('system','use_fulltext_engine', $use_fulltext_engine);
  342. set_config('system','itemcache', $itemcache);
  343. set_config('system','itemcache_duration', $itemcache_duration);
  344. set_config('system','lockpath', $lockpath);
  345. set_config('system','temppath', $temppath);
  346. set_config('system','basepath', $basepath);
  347. info( t('Site settings updated.') . EOL);
  348. goaway($a->get_baseurl(true) . '/admin/site' );
  349. return; // NOTREACHED
  350. }
  351. /**
  352. * @param App $a
  353. * @return string
  354. */
  355. function admin_page_site(&$a) {
  356. /* Installed langs */
  357. $lang_choices = array();
  358. $langs = glob('view/*/strings.php');
  359. if(is_array($langs) && count($langs)) {
  360. if(! in_array('view/en/strings.php',$langs))
  361. $langs[] = 'view/en/';
  362. asort($langs);
  363. foreach($langs as $l) {
  364. $t = explode("/",$l);
  365. $lang_choices[$t[1]] = $t[1];
  366. }
  367. }
  368. /* Installed themes */
  369. $theme_choices = array();
  370. $theme_choices_mobile = array();
  371. $theme_choices_mobile["---"] = t("No special theme for mobile devices");
  372. $files = glob('view/theme/*');
  373. if($files) {
  374. foreach($files as $file) {
  375. $f = basename($file);
  376. $theme_name = ((file_exists($file . '/experimental')) ? sprintf("%s - \x28Experimental\x29", $f) : $f);
  377. if (file_exists($file . '/mobile')) {
  378. $theme_choices_mobile[$f] = $theme_name;
  379. }
  380. else {
  381. $theme_choices[$f] = $theme_name;
  382. }
  383. }
  384. }
  385. /* get user names to make the install a personal install of X */
  386. $user_names = array();
  387. $user_names['---'] = t('Multi user instance');
  388. $users = q("SELECT username, nickname FROM `user`");
  389. foreach ($users as $user) {
  390. $user_names[$user['nickname']] = $user['username'];
  391. }
  392. /* Banner */
  393. $banner = get_config('system','banner');
  394. if($banner == false)
  395. $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>';
  396. $banner = htmlspecialchars($banner);
  397. //echo "<pre>"; var_dump($lang_choices); die("</pre>");
  398. /* Register policy */
  399. $register_choices = Array(
  400. REGISTER_CLOSED => t("Closed"),
  401. REGISTER_APPROVE => t("Requires approval"),
  402. REGISTER_OPEN => t("Open")
  403. );
  404. $ssl_choices = array(
  405. SSL_POLICY_NONE => t("No SSL policy, links will track page SSL state"),
  406. SSL_POLICY_FULL => t("Force all links to use SSL"),
  407. SSL_POLICY_SELFSIGN => t("Self-signed certificate, use SSL for local links only (discouraged)")
  408. );
  409. $t = get_markup_template("admin_site.tpl");
  410. return replace_macros($t, array(
  411. '$title' => t('Administration'),
  412. '$page' => t('Site'),
  413. '$submit' => t('Submit'),
  414. '$registration' => t('Registration'),
  415. '$upload' => t('File upload'),
  416. '$corporate' => t('Policies'),
  417. '$advanced' => t('Advanced'),
  418. '$performance' => t('Performance'),
  419. '$baseurl' => $a->get_baseurl(true),
  420. // name, label, value, help string, extra data...
  421. '$sitename' => array('sitename', t("Site name"), htmlentities($a->config['sitename'], ENT_QUOTES), 'UTF-8'),
  422. '$banner' => array('banner', t("Banner/Logo"), $banner, ""),
  423. '$language' => array('language', t("System language"), get_config('system','language'), "", $lang_choices),
  424. '$theme' => array('theme', t("System theme"), get_config('system','theme'), t("Default system theme - may be over-ridden by user profiles - <a href='#' id='cnftheme'>change theme settings</a>"), $theme_choices),
  425. '$theme_mobile' => array('theme_mobile', t("Mobile system theme"), get_config('system','mobile-theme'), t("Theme for mobile devices"), $theme_choices_mobile),
  426. '$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),
  427. '$new_share' => array('new_share', t("'Share' element"), get_config('system','new_share'), t("Activates the bbcode element 'share' for repeating items.")),
  428. '$hide_help' => array('hide_help', t("Hide help entry from navigation menu"), get_config('system','hide_help'), t("Hides the menu entry for the Help pages from the navigation menu. You can still access it calling /help directly.")),
  429. '$singleuser' => array('singleuser', t("Single user instance"), get_config('system','singleuser'), t("Make this instance multi-user or single-user for the named user"), $user_names),
  430. '$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.")),
  431. '$maximagelength' => array('maximagelength', t("Maximum image length"), get_config('system','max_image_length'), t("Maximum length in pixels of the longest side of uploaded images. Default is -1, which means no limits.")),
  432. '$jpegimagequality' => array('jpegimagequality', t("JPEG image quality"), get_config('system','jpeg_quality'), t("Uploaded JPEGS will be saved at this quality setting [0-100]. Default is 100, which is full quality.")),
  433. '$register_policy' => array('register_policy', t("Register policy"), $a->config['register_policy'], "", $register_choices),
  434. '$daily_registrations' => array('max_daily_registrations', t("Maximum Daily Registrations"), get_config('system', 'max_daily_registrations'), t("If registration is permitted above, this sets the maximum number of new user registrations to accept per day. If register is set to closed, this setting has no effect.")),
  435. '$register_text' => array('register_text', t("Register text"), htmlentities($a->config['register_text'], ENT_QUOTES, 'UTF-8'), t("Will be displayed prominently on the registration page.")),
  436. '$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.')),
  437. '$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")),
  438. '$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")),
  439. '$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.")),
  440. '$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.")),
  441. '$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.")),
  442. '$thread_allow' => array('thread_allow', t("Allow threaded items"), get_config('system','thread_allow'), t("Allow infinite level threading for items on this site.")),
  443. '$newuser_private' => array('newuser_private', t("Private posts by default for new users"), get_config('system','newuser_private'), t("Set default post permissions for all new members to the default privacy group rather than public.")),
  444. '$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.")),
  445. '$no_openid' => array('no_openid', t("OpenID support"), !get_config('system','no_openid'), t("OpenID support for registration and logins.")),
  446. '$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")),
  447. '$no_utf' => array('no_utf', t("UTF-8 Regular expressions"), !get_config('system','no_utf'), t("Use PHP UTF8 regular expressions")),
  448. '$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.")),
  449. '$ostatus_disabled' => array('ostatus_disabled', t("Enable OStatus support"), !get_config('system','ostatus_disabled'), 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.")),
  450. '$diaspora_enabled' => array('diaspora_enabled', t("Enable Diaspora support"), get_config('system','diaspora_enabled'), t("Provide built-in Diaspora network compatibility.")),
  451. '$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.")),
  452. '$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.")),
  453. '$proxyuser' => array('proxyuser', t("Proxy user"), get_config('system','proxyuser'), ""),
  454. '$proxy' => array('proxy', t("Proxy URL"), get_config('system','proxy'), ""),
  455. '$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).")),
  456. '$delivery_interval' => array('delivery_interval', t("Delivery interval"), (x(get_config('system','delivery_interval'))?get_config('system','delivery_interval'):2), t("Delay background delivery processes by this many seconds to reduce system load. Recommend: 4-5 for shared hosts, 2-3 for virtual private servers. 0-1 for large dedicated servers.")),
  457. '$poll_interval' => array('poll_interval', t("Poll interval"), (x(get_config('system','poll_interval'))?get_config('system','poll_interval'):2), t("Delay background polling processes by this many seconds to reduce system load. If 0, use delivery interval.")),
  458. '$maxloadavg' => array('maxloadavg', t("Maximum Load Average"), ((intval(get_config('system','maxloadavg')) > 0)?get_config('system','maxloadavg'):50), t("Maximum system load before delivery and poll processes are deferred - default 50.")),
  459. '$use_fulltext_engine' => array('use_fulltext_engine', t("Use MySQL full text engine"), get_config('system','use_fulltext_engine'), t("Activates the full text engine. Speeds up search - but can only search for four and more characters.")),
  460. '$itemcache' => array('itemcache', t("Path to item cache"), get_config('system','itemcache'), "The item caches buffers generated bbcode and external images."),
  461. '$itemcache_duration' => array('itemcache_duration', t("Cache duration in seconds"), get_config('system','itemcache_duration'), t("How long should the cache files be hold? Default value is 86400 seconds (One day).")),
  462. '$lockpath' => array('lockpath', t("Path for lock file"), get_config('system','lockpath'), "The lock file is used to avoid multiple pollers at one time. Only define a folder here."),
  463. '$temppath' => array('temppath', t("Temp path"), get_config('system','temppath'), "If you have a restricted system where the webserver can't access the system temp path, enter another path here."),
  464. '$basepath' => array('basepath', t("Base path to installation"), get_config('system','basepath'), "If the system cannot detect the correct path to your installation, enter the correct path here. This setting should only be set if you are using a restricted system and symbolic links to your webroot."),
  465. '$form_security_token' => get_form_security_token("admin_site"),
  466. ));
  467. }
  468. function admin_page_dbsync(&$a) {
  469. $o = '';
  470. if($a->argc > 3 && intval($a->argv[3]) && $a->argv[2] === 'mark') {
  471. set_config('database', 'update_' . intval($a->argv[3]), 'success');
  472. $curr = get_config('system','build');
  473. if(intval($curr) == intval($a->argv[3]))
  474. set_config('system','build',intval($curr) + 1);
  475. info( t('Update has been marked successful') . EOL);
  476. goaway($a->get_baseurl(true) . '/admin/dbsync');
  477. }
  478. if($a->argc > 2 && intval($a->argv[2])) {
  479. require_once('update.php');
  480. $func = 'update_' . intval($a->argv[2]);
  481. if(function_exists($func)) {
  482. $retval = $func();
  483. if($retval === UPDATE_FAILED) {
  484. $o .= sprintf( t('Executing %s failed. Check system logs.'), $func);
  485. }
  486. elseif($retval === UPDATE_SUCCESS) {
  487. $o .= sprintf( t('Update %s was successfully applied.', $func));
  488. set_config('database',$func, 'success');
  489. }
  490. else
  491. $o .= sprintf( t('Update %s did not return a status. Unknown if it succeeded.'), $func);
  492. }
  493. else
  494. $o .= sprintf( t('Update function %s could not be found.'), $func);
  495. return $o;
  496. }
  497. $failed = array();
  498. $r = q("select * from config where `cat` = 'database' ");
  499. if(count($r)) {
  500. foreach($r as $rr) {
  501. $upd = intval(substr($rr['k'],7));
  502. if($upd < 1139 || $rr['v'] === 'success')
  503. continue;
  504. $failed[] = $upd;
  505. }
  506. }
  507. if(! count($failed))
  508. return '<h3>' . t('No failed updates.') . '</h3>';
  509. $o = replace_macros(get_markup_template('failed_updates.tpl'),array(
  510. '$base' => $a->get_baseurl(true),
  511. '$banner' => t('Failed Updates'),
  512. '$desc' => t('This does not include updates prior to 1139, which did not return a status.'),
  513. '$mark' => t('Mark success (if update was manually applied)'),
  514. '$apply' => t('Attempt to execute this update step automatically'),
  515. '$failed' => $failed
  516. ));
  517. return $o;
  518. }
  519. /**
  520. * Users admin page
  521. *
  522. * @param App $a
  523. */
  524. function admin_page_users_post(&$a){
  525. $pending = ( x($_POST, 'pending') ? $_POST['pending'] : Array() );
  526. $users = ( x($_POST, 'user') ? $_POST['user'] : Array() );
  527. check_form_security_token_redirectOnErr('/admin/users', 'admin_users');
  528. if (x($_POST,'page_users_block')){
  529. foreach($users as $uid){
  530. q("UPDATE `user` SET `blocked`=1-`blocked` WHERE `uid`=%s",
  531. intval( $uid )
  532. );
  533. }
  534. notice( sprintf( tt("%s user blocked/unblocked", "%s users blocked/unblocked", count($users)), count($users)) );
  535. }
  536. if (x($_POST,'page_users_delete')){
  537. require_once("include/Contact.php");
  538. foreach($users as $uid){
  539. user_remove($uid);
  540. }
  541. notice( sprintf( tt("%s user deleted", "%s users deleted", count($users)), count($users)) );
  542. }
  543. if (x($_POST,'page_users_approve')){
  544. require_once("mod/regmod.php");
  545. foreach($pending as $hash){
  546. user_allow($hash);
  547. }
  548. }
  549. if (x($_POST,'page_users_deny')){
  550. require_once("mod/regmod.php");
  551. foreach($pending as $hash){
  552. user_deny($hash);
  553. }
  554. }
  555. goaway($a->get_baseurl(true) . '/admin/users' );
  556. return; // NOTREACHED
  557. }
  558. /**
  559. * @param App $a
  560. * @return string
  561. */
  562. function admin_page_users(&$a){
  563. if ($a->argc>2) {
  564. $uid = $a->argv[3];
  565. $user = q("SELECT * FROM `user` WHERE `uid`=%d", intval($uid));
  566. if (count($user)==0){
  567. notice( 'User not found' . EOL);
  568. goaway($a->get_baseurl(true) . '/admin/users' );
  569. return ''; // NOTREACHED
  570. }
  571. switch($a->argv[2]){
  572. case "delete":{
  573. check_form_security_token_redirectOnErr('/admin/users', 'admin_users', 't');
  574. // delete user
  575. require_once("include/Contact.php");
  576. user_remove($uid);
  577. notice( sprintf(t("User '%s' deleted"), $user[0]['username']) . EOL);
  578. }; break;
  579. case "block":{
  580. check_form_security_token_redirectOnErr('/admin/users', 'admin_users', 't');
  581. q("UPDATE `user` SET `blocked`=%d WHERE `uid`=%s",
  582. intval( 1-$user[0]['blocked'] ),
  583. intval( $uid )
  584. );
  585. notice( sprintf( ($user[0]['blocked']?t("User '%s' unblocked"):t("User '%s' blocked")) , $user[0]['username']) . EOL);
  586. }; break;
  587. }
  588. goaway($a->get_baseurl(true) . '/admin/users' );
  589. return ''; // NOTREACHED
  590. }
  591. /* get pending */
  592. $pending = q("SELECT `register`.*, `contact`.`name`, `user`.`email`
  593. FROM `register`
  594. LEFT JOIN `contact` ON `register`.`uid` = `contact`.`uid`
  595. LEFT JOIN `user` ON `register`.`uid` = `user`.`uid`;");
  596. /* get users */
  597. $total = q("SELECT count(*) as total FROM `user` where 1");
  598. if(count($total)) {
  599. $a->set_pager_total($total[0]['total']);
  600. $a->set_pager_itemspage(100);
  601. }
  602. $users = q("SELECT `user` . * , `contact`.`name` , `contact`.`url` , `contact`.`micro`, `lastitem`.`lastitem_date`
  603. FROM
  604. (SELECT MAX(`item`.`changed`) as `lastitem_date`, `item`.`uid`
  605. FROM `item`
  606. WHERE `item`.`type` = 'wall'
  607. GROUP BY `item`.`uid`) AS `lastitem`
  608. RIGHT OUTER JOIN `user` ON `user`.`uid` = `lastitem`.`uid`,
  609. `contact`
  610. WHERE
  611. `user`.`uid` = `contact`.`uid`
  612. AND `user`.`verified` =1
  613. AND `contact`.`self` =1
  614. ORDER BY `contact`.`name` LIMIT %d, %d
  615. ",
  616. intval($a->pager['start']),
  617. intval($a->pager['itemspage'])
  618. );
  619. function _setup_users($e){
  620. $a = get_app();
  621. $accounts = Array(
  622. t('Normal Account'),
  623. t('Soapbox Account'),
  624. t('Community/Celebrity Account'),
  625. t('Automatic Friend Account')
  626. );
  627. $e['page-flags'] = $accounts[$e['page-flags']];
  628. $e['register_date'] = relative_date($e['register_date']);
  629. $e['login_date'] = relative_date($e['login_date']);
  630. $e['lastitem_date'] = relative_date($e['lastitem_date']);
  631. $e['is_admin'] = ($e['email'] === $a->config['admin_email']);
  632. return $e;
  633. }
  634. $users = array_map("_setup_users", $users);
  635. // Get rid of dashes in key names, Smarty3 can't handle them
  636. foreach($users as $key => $user) {
  637. $new_user = array();
  638. foreach($user as $k => $v) {
  639. $k = str_replace('-','_',$k);
  640. $new_user[$k] = $v;
  641. }
  642. $users[$key] = $new_user;
  643. }
  644. $t = get_markup_template("admin_users.tpl");
  645. $o = replace_macros($t, array(
  646. // strings //
  647. '$title' => t('Administration'),
  648. '$page' => t('Users'),
  649. '$submit' => t('Submit'),
  650. '$select_all' => t('select all'),
  651. '$h_pending' => t('User registrations waiting for confirm'),
  652. '$th_pending' => array( t('Request date'), t('Name'), t('Email') ),
  653. '$no_pending' => t('No registrations.'),
  654. '$approve' => t('Approve'),
  655. '$deny' => t('Deny'),
  656. '$delete' => t('Delete'),
  657. '$block' => t('Block'),
  658. '$unblock' => t('Unblock'),
  659. '$siteadmin' => t('Site admin'),
  660. '$h_users' => t('Users'),
  661. '$th_users' => array( t('Name'), t('Email'), t('Register date'), t('Last login'), t('Last item'), t('Account') ),
  662. '$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?'),
  663. '$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?'),
  664. '$form_security_token' => get_form_security_token("admin_users"),
  665. // values //
  666. '$baseurl' => $a->get_baseurl(true),
  667. '$pending' => $pending,
  668. '$users' => $users,
  669. ));
  670. $o .= paginate($a);
  671. return $o;
  672. }
  673. /**
  674. * Plugins admin page
  675. *
  676. * @param App $a
  677. * @return string
  678. */
  679. function admin_page_plugins(&$a){
  680. /**
  681. * Single plugin
  682. */
  683. if ($a->argc == 3){
  684. $plugin = $a->argv[2];
  685. if (!is_file("addon/$plugin/$plugin.php")){
  686. notice( t("Item not found.") );
  687. return '';
  688. }
  689. if (x($_GET,"a") && $_GET['a']=="t"){
  690. check_form_security_token_redirectOnErr('/admin/plugins', 'admin_themes', 't');
  691. // Toggle plugin status
  692. $idx = array_search($plugin, $a->plugins);
  693. if ($idx !== false){
  694. unset($a->plugins[$idx]);
  695. uninstall_plugin($plugin);
  696. info( sprintf( t("Plugin %s disabled."), $plugin ) );
  697. } else {
  698. $a->plugins[] = $plugin;
  699. install_plugin($plugin);
  700. info( sprintf( t("Plugin %s enabled."), $plugin ) );
  701. }
  702. set_config("system","addon", implode(", ",$a->plugins));
  703. goaway($a->get_baseurl(true) . '/admin/plugins' );
  704. return ''; // NOTREACHED
  705. }
  706. // display plugin details
  707. require_once('library/markdown.php');
  708. if (in_array($plugin, $a->plugins)){
  709. $status="on"; $action= t("Disable");
  710. } else {
  711. $status="off"; $action= t("Enable");
  712. }
  713. $readme=Null;
  714. if (is_file("addon/$plugin/README.md")){
  715. $readme = file_get_contents("addon/$plugin/README.md");
  716. $readme = Markdown($readme);
  717. } else if (is_file("addon/$plugin/README")){
  718. $readme = "<pre>". file_get_contents("addon/$plugin/README") ."</pre>";
  719. }
  720. $admin_form="";
  721. if (is_array($a->plugins_admin) && in_array($plugin, $a->plugins_admin)){
  722. @require_once("addon/$plugin/$plugin.php");
  723. $func = $plugin.'_plugin_admin';
  724. $func($a, $admin_form);
  725. }
  726. $t = get_markup_template("admin_plugins_details.tpl");
  727. return replace_macros($t, array(
  728. '$title' => t('Administration'),
  729. '$page' => t('Plugins'),
  730. '$toggle' => t('Toggle'),
  731. '$settings' => t('Settings'),
  732. '$baseurl' => $a->get_baseurl(true),
  733. '$plugin' => $plugin,
  734. '$status' => $status,
  735. '$action' => $action,
  736. '$info' => get_plugin_info($plugin),
  737. '$str_author' => t('Author: '),
  738. '$str_maintainer' => t('Maintainer: '),
  739. '$admin_form' => $admin_form,
  740. '$function' => 'plugins',
  741. '$screenshot' => '',
  742. '$readme' => $readme,
  743. '$form_security_token' => get_form_security_token("admin_themes"),
  744. ));
  745. }
  746. /**
  747. * List plugins
  748. */
  749. $plugins = array();
  750. $files = glob("addon/*/");
  751. if($files) {
  752. foreach($files as $file) {
  753. if (is_dir($file)){
  754. list($tmp, $id)=array_map("trim", explode("/",$file));
  755. $info = get_plugin_info($id);
  756. $plugins[] = array( $id, (in_array($id, $a->plugins)?"on":"off") , $info);
  757. }
  758. }
  759. }
  760. $t = get_markup_template("admin_plugins.tpl");
  761. return replace_macros($t, array(
  762. '$title' => t('Administration'),
  763. '$page' => t('Plugins'),
  764. '$submit' => t('Submit'),
  765. '$baseurl' => $a->get_baseurl(true),
  766. '$function' => 'plugins',
  767. '$plugins' => $plugins,
  768. '$form_security_token' => get_form_security_token("admin_themes"),
  769. ));
  770. }
  771. /**
  772. * @param array $themes
  773. * @param string $th
  774. * @param int $result
  775. */
  776. function toggle_theme(&$themes,$th,&$result) {
  777. for($x = 0; $x < count($themes); $x ++) {
  778. if($themes[$x]['name'] === $th) {
  779. if($themes[$x]['allowed']) {
  780. $themes[$x]['allowed'] = 0;
  781. $result = 0;
  782. }
  783. else {
  784. $themes[$x]['allowed'] = 1;
  785. $result = 1;
  786. }
  787. }
  788. }
  789. }
  790. /**
  791. * @param array $themes
  792. * @param string $th
  793. * @return int
  794. */
  795. function theme_status($themes,$th) {
  796. for($x = 0; $x < count($themes); $x ++) {
  797. if($themes[$x]['name'] === $th) {
  798. if($themes[$x]['allowed']) {
  799. return 1;
  800. }
  801. else {
  802. return 0;
  803. }
  804. }
  805. }
  806. return 0;
  807. }
  808. /**
  809. * @param array $themes
  810. * @return string
  811. */
  812. function rebuild_theme_table($themes) {
  813. $o = '';
  814. if(count($themes)) {
  815. foreach($themes as $th) {
  816. if($th['allowed']) {
  817. if(strlen($o))
  818. $o .= ',';
  819. $o .= $th['name'];
  820. }
  821. }
  822. }
  823. return $o;
  824. }
  825. /**
  826. * Themes admin page
  827. *
  828. * @param App $a
  829. * @return string
  830. */
  831. function admin_page_themes(&$a){
  832. $allowed_themes_str = get_config('system','allowed_themes');
  833. $allowed_themes_raw = explode(',',$allowed_themes_str);
  834. $allowed_themes = array();
  835. if(count($allowed_themes_raw))
  836. foreach($allowed_themes_raw as $x)
  837. if(strlen(trim($x)))
  838. $allowed_themes[] = trim($x);
  839. $themes = array();
  840. $files = glob('view/theme/*');
  841. if($files) {
  842. foreach($files as $file) {
  843. $f = basename($file);
  844. $is_experimental = intval(file_exists($file . '/experimental'));
  845. $is_supported = 1-(intval(file_exists($file . '/unsupported'))); // Is not used yet
  846. $is_allowed = intval(in_array($f,$allowed_themes));
  847. $themes[] = array('name' => $f, 'experimental' => $is_experimental, 'supported' => $is_supported, 'allowed' => $is_allowed);
  848. }
  849. }
  850. if(! count($themes)) {
  851. notice( t('No themes found.'));
  852. return '';
  853. }
  854. /**
  855. * Single theme
  856. */
  857. if ($a->argc == 3){
  858. $theme = $a->argv[2];
  859. if(! is_dir("view/theme/$theme")){
  860. notice( t("Item not found.") );
  861. return '';
  862. }
  863. if (x($_GET,"a") && $_GET['a']=="t"){
  864. check_form_security_token_redirectOnErr('/admin/themes', 'admin_themes', 't');
  865. // Toggle theme status
  866. toggle_theme($themes,$theme,$result);
  867. $s = rebuild_theme_table($themes);
  868. if($result) {
  869. install_theme($theme);
  870. info( sprintf('Theme %s enabled.',$theme));
  871. }
  872. else {
  873. uninstall_theme($theme);
  874. info( sprintf('Theme %s disabled.',$theme));
  875. }
  876. set_config('system','allowed_themes',$s);
  877. goaway($a->get_baseurl(true) . '/admin/themes' );
  878. return ''; // NOTREACHED
  879. }
  880. // display theme details
  881. require_once('library/markdown.php');
  882. if (theme_status($themes,$theme)) {
  883. $status="on"; $action= t("Disable");
  884. } else {
  885. $status="off"; $action= t("Enable");
  886. }
  887. $readme=Null;
  888. if (is_file("view/theme/$theme/README.md")){
  889. $readme = file_get_contents("view/theme/$theme/README.md");
  890. $readme = Markdown($readme);
  891. } else if (is_file("view/theme/$theme/README")){
  892. $readme = "<pre>". file_get_contents("view/theme/$theme/README") ."</pre>";
  893. }
  894. $admin_form="";
  895. if (is_file("view/theme/$theme/config.php")){
  896. require_once("view/theme/$theme/config.php");
  897. if(function_exists("theme_admin")){
  898. $admin_form = theme_admin($a);
  899. }
  900. }
  901. $screenshot = array( get_theme_screenshot($theme), t('Screenshot'));
  902. if(! stristr($screenshot[0],$theme))
  903. $screenshot = null;
  904. $t = get_markup_template("admin_plugins_details.tpl");
  905. return replace_macros($t, array(
  906. '$title' => t('Administration'),
  907. '$page' => t('Themes'),
  908. '$toggle' => t('Toggle'),
  909. '$settings' => t('Settings'),
  910. '$baseurl' => $a->get_baseurl(true),
  911. '$plugin' => $theme,
  912. '$status' => $status,
  913. '$action' => $action,
  914. '$info' => get_theme_info($theme),
  915. '$function' => 'themes',
  916. '$admin_form' => $admin_form,
  917. '$str_author' => t('Author: '),
  918. '$str_maintainer' => t('Maintainer: '),
  919. '$screenshot' => $screenshot,
  920. '$readme' => $readme,
  921. '$form_security_token' => get_form_security_token("admin_themes"),
  922. ));
  923. }
  924. /**
  925. * List themes
  926. */
  927. $xthemes = array();
  928. if($themes) {
  929. foreach($themes as $th) {
  930. $xthemes[] = array($th['name'],(($th['allowed']) ? "on" : "off"), get_theme_info($th['name']));
  931. }
  932. }
  933. $t = get_markup_template("admin_plugins.tpl");
  934. return replace_macros($t, array(
  935. '$title' => t('Administration'),
  936. '$page' => t('Themes'),
  937. '$submit' => t('Submit'),
  938. '$baseurl' => $a->get_baseurl(true),
  939. '$function' => 'themes',
  940. '$plugins' => $xthemes,
  941. '$experimental' => t('[Experimental]'),
  942. '$unsupported' => t('[Unsupported]'),
  943. '$form_security_token' => get_form_security_token("admin_themes"),
  944. ));
  945. }
  946. /**
  947. * Logs admin page
  948. *
  949. * @param App $a
  950. */
  951. function admin_page_logs_post(&$a) {
  952. if (x($_POST,"page_logs")) {
  953. check_form_security_token_redirectOnErr('/admin/logs', 'admin_logs');
  954. $logfile = ((x($_POST,'logfile')) ? notags(trim($_POST['logfile'])) : '');
  955. $debugging = ((x($_POST,'debugging')) ? true : false);
  956. $loglevel = ((x($_POST,'loglevel')) ? intval(trim($_POST['loglevel'])) : 0);
  957. set_config('system','logfile', $logfile);
  958. set_config('system','debugging', $debugging);
  959. set_config('system','loglevel', $loglevel);
  960. }
  961. info( t("Log settings updated.") );
  962. goaway($a->get_baseurl(true) . '/admin/logs' );
  963. return; // NOTREACHED
  964. }
  965. /**
  966. * @param App $a
  967. * @return string
  968. */
  969. function admin_page_logs(&$a){
  970. $log_choices = Array(
  971. LOGGER_NORMAL => 'Normal',
  972. LOGGER_TRACE => 'Trace',
  973. LOGGER_DEBUG => 'Debug',
  974. LOGGER_DATA => 'Data',
  975. LOGGER_ALL => 'All'
  976. );
  977. $t = get_markup_template("admin_logs.tpl");
  978. $f = get_config('system','logfile');
  979. $data = '';
  980. if(!file_exists($f)) {
  981. $data = t("Error trying to open <strong>$f</strong> log file.\r\n<br/>Check to see if file $f exist and is
  982. readable.");
  983. }
  984. else {
  985. $fp = fopen($f, 'r');
  986. if(!$fp) {
  987. $data = t("Couldn't open <strong>$f</strong> log file.\r\n<br/>Check to see if file $f is readable.");
  988. }
  989. else {
  990. $fstat = fstat($fp);
  991. $size = $fstat['size'];
  992. if($size != 0)
  993. {
  994. if($size > 5000000 || $size < 0)
  995. $size = 5000000;
  996. $seek = fseek($fp,0-$size,SEEK_END);
  997. if($seek === 0) {
  998. $data = escape_tags(fread($fp,$size));
  999. while(! feof($fp))
  1000. $data .= escape_tags(fread($fp,4096));
  1001. }
  1002. }
  1003. fclose($fp);
  1004. }
  1005. }
  1006. return replace_macros($t, array(
  1007. '$title' => t('Administration'),
  1008. '$page' => t('Logs'),
  1009. '$submit' => t('Submit'),
  1010. '$clear' => t('Clear'),
  1011. '$data' => $data,
  1012. '$baseurl' => $a->get_baseurl(true),
  1013. '$logname' => get_config('system','logfile'),
  1014. // name, label, value, help string, extra data...
  1015. '$debugging' => array('debugging', t("Debugging"),get_config('system','debugging'), ""),
  1016. '$logfile' => array('logfile', t("Log file"), get_config('system','logfile'), t("Must be writable by web server. Relative to your Friendica top-level directory.")),
  1017. '$loglevel' => array('loglevel', t("Log level"), get_config('system','loglevel'), "", $log_choices),
  1018. '$form_security_token' => get_form_security_token("admin_logs"),
  1019. ));
  1020. }
  1021. /**
  1022. * @param App $a
  1023. */
  1024. function admin_page_remoteupdate_post(&$a) {
  1025. // this function should be called via ajax post
  1026. if(!is_site_admin()) {
  1027. return;
  1028. }
  1029. if (x($_POST,'remotefile') && $_POST['remotefile']!=""){
  1030. $remotefile = $_POST['remotefile'];
  1031. $ftpdata = (x($_POST['ftphost'])?$_POST:false);
  1032. doUpdate($remotefile, $ftpdata);
  1033. } else {
  1034. echo "No remote file to download. Abort!";
  1035. }
  1036. killme();
  1037. }
  1038. /**
  1039. * @param App $a
  1040. * @return string
  1041. */
  1042. function admin_page_remoteupdate(&$a) {
  1043. if(!is_site_admin()) {
  1044. return login(false);
  1045. }
  1046. $canwrite = canWeWrite();
  1047. $canftp = function_exists('ftp_connect');
  1048. $needupdate = true;
  1049. $u = checkUpdate();
  1050. if (!is_array($u)){
  1051. $needupdate = false;
  1052. $u = array('','','');
  1053. }
  1054. $tpl = get_markup_template("admin_remoteupdate.tpl");
  1055. return replace_macros($tpl, array(
  1056. '$baseurl' => $a->get_baseurl(true),
  1057. '$submit' => t("Update now"),
  1058. '$close' => t("Close"),
  1059. '$localversion' => FRIENDICA_VERSION,
  1060. '$remoteversion' => $u[1],
  1061. '$needupdate' => $needupdate,
  1062. '$canwrite' => $canwrite,
  1063. '$canftp' => $canftp,
  1064. '$ftphost' => array('ftphost', t("FTP Host"), '',''),
  1065. '$ftppath' => array('ftppath', t("FTP Path"), '/',''),
  1066. '$ftpuser' => array('ftpuser', t("FTP User"), '',''),
  1067. '$ftppwd' => array('ftppwd', t("FTP Password"), '',''),
  1068. '$remotefile'=>array('remotefile','', $u['2'],''),
  1069. ));
  1070. }