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.
 
 
 
 
 
 

1247 lines
44 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. $enotify_no_content = ((x($_POST,'enotify_no_content')) ? True : False);
  215. $private_addons = ((x($_POST,'private_addons')) ? True : False);
  216. $no_multi_reg = ((x($_POST,'no_multi_reg')) ? True : False);
  217. $no_openid = !((x($_POST,'no_openid')) ? True : False);
  218. $no_regfullname = !((x($_POST,'no_regfullname')) ? True : False);
  219. $no_utf = !((x($_POST,'no_utf')) ? True : False);
  220. $no_community_page = !((x($_POST,'no_community_page')) ? True : False);
  221. $verifyssl = ((x($_POST,'verifyssl')) ? True : False);
  222. $proxyuser = ((x($_POST,'proxyuser')) ? notags(trim($_POST['proxyuser'])) : '');
  223. $proxy = ((x($_POST,'proxy')) ? notags(trim($_POST['proxy'])) : '');
  224. $timeout = ((x($_POST,'timeout')) ? intval(trim($_POST['timeout'])) : 60);
  225. $delivery_interval = ((x($_POST,'delivery_interval')) ? intval(trim($_POST['delivery_interval'])) : 0);
  226. $poll_interval = ((x($_POST,'poll_interval')) ? intval(trim($_POST['poll_interval'])) : 0);
  227. $maxloadavg = ((x($_POST,'maxloadavg')) ? intval(trim($_POST['maxloadavg'])) : 50);
  228. $dfrn_only = ((x($_POST,'dfrn_only')) ? True : False);
  229. $ostatus_disabled = !((x($_POST,'ostatus_disabled')) ? True : False);
  230. $diaspora_enabled = ((x($_POST,'diaspora_enabled')) ? True : False);
  231. $ssl_policy = ((x($_POST,'ssl_policy')) ? intval($_POST['ssl_policy']) : 0);
  232. $new_share = ((x($_POST,'new_share')) ? True : False);
  233. $hide_help = ((x($_POST,'hide_help')) ? True : False);
  234. $use_fulltext_engine = ((x($_POST,'use_fulltext_engine')) ? True : False);
  235. $itemcache = ((x($_POST,'itemcache')) ? notags(trim($_POST['itemcache'])) : '');
  236. $itemcache_duration = ((x($_POST,'itemcache_duration')) ? intval($_POST['itemcache_duration']) : 0);
  237. $lockpath = ((x($_POST,'lockpath')) ? notags(trim($_POST['lockpath'])) : '');
  238. $temppath = ((x($_POST,'temppath')) ? notags(trim($_POST['temppath'])) : '');
  239. $basepath = ((x($_POST,'basepath')) ? notags(trim($_POST['basepath'])) : '');
  240. $singleuser = ((x($_POST,'singleuser')) ? notags(trim($_POST['singleuser'])) : '');
  241. if($ssl_policy != intval(get_config('system','ssl_policy'))) {
  242. if($ssl_policy == SSL_POLICY_FULL) {
  243. q("update `contact` set
  244. `url` = replace(`url` , 'http:' , 'https:'),
  245. `photo` = replace(`photo` , 'http:' , 'https:'),
  246. `thumb` = replace(`thumb` , 'http:' , 'https:'),
  247. `micro` = replace(`micro` , 'http:' , 'https:'),
  248. `request` = replace(`request`, 'http:' , 'https:'),
  249. `notify` = replace(`notify` , 'http:' , 'https:'),
  250. `poll` = replace(`poll` , 'http:' , 'https:'),
  251. `confirm` = replace(`confirm`, 'http:' , 'https:'),
  252. `poco` = replace(`poco` , 'http:' , 'https:')
  253. where `self` = 1"
  254. );
  255. q("update `profile` set
  256. `photo` = replace(`photo` , 'http:' , 'https:'),
  257. `thumb` = replace(`thumb` , 'http:' , 'https:')
  258. where 1 "
  259. );
  260. }
  261. elseif($ssl_policy == SSL_POLICY_SELFSIGN) {
  262. q("update `contact` set
  263. `url` = replace(`url` , 'https:' , 'http:'),
  264. `photo` = replace(`photo` , 'https:' , 'http:'),
  265. `thumb` = replace(`thumb` , 'https:' , 'http:'),
  266. `micro` = replace(`micro` , 'https:' , 'http:'),
  267. `request` = replace(`request`, 'https:' , 'http:'),
  268. `notify` = replace(`notify` , 'https:' , 'http:'),
  269. `poll` = replace(`poll` , 'https:' , 'http:'),
  270. `confirm` = replace(`confirm`, 'https:' , 'http:'),
  271. `poco` = replace(`poco` , 'https:' , 'http:')
  272. where `self` = 1"
  273. );
  274. q("update `profile` set
  275. `photo` = replace(`photo` , 'https:' , 'http:'),
  276. `thumb` = replace(`thumb` , 'https:' , 'http:')
  277. where 1 "
  278. );
  279. }
  280. }
  281. set_config('system','ssl_policy',$ssl_policy);
  282. set_config('system','delivery_interval',$delivery_interval);
  283. set_config('system','poll_interval',$poll_interval);
  284. set_config('system','maxloadavg',$maxloadavg);
  285. set_config('config','sitename',$sitename);
  286. if ($banner==""){
  287. // don't know why, but del_config doesn't work...
  288. q("DELETE FROM `config` WHERE `cat` = '%s' AND `k` = '%s' LIMIT 1",
  289. dbesc("system"),
  290. dbesc("banner")
  291. );
  292. } else {
  293. set_config('system','banner', $banner);
  294. }
  295. set_config('system','language', $language);
  296. set_config('system','theme', $theme);
  297. if ( $theme_mobile === '---' ) {
  298. del_config('system','mobile-theme');
  299. } else {
  300. set_config('system','mobile-theme', $theme_mobile);
  301. }
  302. if ( $singleuser === '---' ) {
  303. del_config('system','singleuser');
  304. } else {
  305. set_config('system','singleuser', $singleuser);
  306. }
  307. set_config('system','maximagesize', $maximagesize);
  308. set_config('system','max_image_length', $maximagelength);
  309. set_config('system','jpeg_quality', $jpegimagequality);
  310. set_config('config','register_policy', $register_policy);
  311. set_config('system','max_daily_registrations', $daily_registrations);
  312. set_config('system','account_abandon_days', $abandon_days);
  313. set_config('config','register_text', $register_text);
  314. set_config('system','allowed_sites', $allowed_sites);
  315. set_config('system','allowed_email', $allowed_email);
  316. set_config('system','block_public', $block_public);
  317. set_config('system','publish_all', $force_publish);
  318. if ($global_directory==""){
  319. // don't know why, but del_config doesn't work...
  320. q("DELETE FROM `config` WHERE `cat` = '%s' AND `k` = '%s' LIMIT 1",
  321. dbesc("system"),
  322. dbesc("directory_submit_url")
  323. );
  324. } else {
  325. set_config('system','directory_submit_url', $global_directory);
  326. }
  327. set_config('system','thread_allow', $thread_allow);
  328. set_config('system','newuser_private', $newuser_private);
  329. set_config('system','enotify_no_content', $enotify_no_content);
  330. set_config('system','block_extended_register', $no_multi_reg);
  331. set_config('system','no_openid', $no_openid);
  332. set_config('system','no_regfullname', $no_regfullname);
  333. set_config('system','no_community_page', $no_community_page);
  334. set_config('system','no_utf', $no_utf);
  335. set_config('system','verifyssl', $verifyssl);
  336. set_config('system','proxyuser', $proxyuser);
  337. set_config('system','proxy', $proxy);
  338. set_config('system','curl_timeout', $timeout);
  339. set_config('system','dfrn_only', $dfrn_only);
  340. set_config('system','ostatus_disabled', $ostatus_disabled);
  341. set_config('system','diaspora_enabled', $diaspora_enabled);
  342. set_config('config','private_addons', $private_addons);
  343. set_config('system','new_share', $new_share);
  344. set_config('system','hide_help', $hide_help);
  345. set_config('system','use_fulltext_engine', $use_fulltext_engine);
  346. set_config('system','itemcache', $itemcache);
  347. set_config('system','itemcache_duration', $itemcache_duration);
  348. set_config('system','lockpath', $lockpath);
  349. set_config('system','temppath', $temppath);
  350. set_config('system','basepath', $basepath);
  351. info( t('Site settings updated.') . EOL);
  352. goaway($a->get_baseurl(true) . '/admin/site' );
  353. return; // NOTREACHED
  354. }
  355. /**
  356. * @param App $a
  357. * @return string
  358. */
  359. function admin_page_site(&$a) {
  360. /* Installed langs */
  361. $lang_choices = array();
  362. $langs = glob('view/*/strings.php');
  363. if(is_array($langs) && count($langs)) {
  364. if(! in_array('view/en/strings.php',$langs))
  365. $langs[] = 'view/en/';
  366. asort($langs);
  367. foreach($langs as $l) {
  368. $t = explode("/",$l);
  369. $lang_choices[$t[1]] = $t[1];
  370. }
  371. }
  372. /* Installed themes */
  373. $theme_choices = array();
  374. $theme_choices_mobile = array();
  375. $theme_choices_mobile["---"] = t("No special theme for mobile devices");
  376. $files = glob('view/theme/*');
  377. if($files) {
  378. foreach($files as $file) {
  379. $f = basename($file);
  380. $theme_name = ((file_exists($file . '/experimental')) ? sprintf("%s - \x28Experimental\x29", $f) : $f);
  381. if (file_exists($file . '/mobile')) {
  382. $theme_choices_mobile[$f] = $theme_name;
  383. }
  384. else {
  385. $theme_choices[$f] = $theme_name;
  386. }
  387. }
  388. }
  389. /* get user names to make the install a personal install of X */
  390. $user_names = array();
  391. $user_names['---'] = t('Multi user instance');
  392. $users = q("SELECT username, nickname FROM `user`");
  393. foreach ($users as $user) {
  394. $user_names[$user['nickname']] = $user['username'];
  395. }
  396. /* Banner */
  397. $banner = get_config('system','banner');
  398. if($banner == false)
  399. $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>';
  400. $banner = htmlspecialchars($banner);
  401. //echo "<pre>"; var_dump($lang_choices); die("</pre>");
  402. /* Register policy */
  403. $register_choices = Array(
  404. REGISTER_CLOSED => t("Closed"),
  405. REGISTER_APPROVE => t("Requires approval"),
  406. REGISTER_OPEN => t("Open")
  407. );
  408. $ssl_choices = array(
  409. SSL_POLICY_NONE => t("No SSL policy, links will track page SSL state"),
  410. SSL_POLICY_FULL => t("Force all links to use SSL"),
  411. SSL_POLICY_SELFSIGN => t("Self-signed certificate, use SSL for local links only (discouraged)")
  412. );
  413. $t = get_markup_template("admin_site.tpl");
  414. return replace_macros($t, array(
  415. '$title' => t('Administration'),
  416. '$page' => t('Site'),
  417. '$submit' => t('Submit'),
  418. '$registration' => t('Registration'),
  419. '$upload' => t('File upload'),
  420. '$corporate' => t('Policies'),
  421. '$advanced' => t('Advanced'),
  422. '$performance' => t('Performance'),
  423. '$baseurl' => $a->get_baseurl(true),
  424. // name, label, value, help string, extra data...
  425. '$sitename' => array('sitename', t("Site name"), htmlentities($a->config['sitename'], ENT_QUOTES), 'UTF-8'),
  426. '$banner' => array('banner', t("Banner/Logo"), $banner, ""),
  427. '$language' => array('language', t("System language"), get_config('system','language'), "", $lang_choices),
  428. '$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),
  429. '$theme_mobile' => array('theme_mobile', t("Mobile system theme"), get_config('system','mobile-theme'), t("Theme for mobile devices"), $theme_choices_mobile),
  430. '$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),
  431. '$new_share' => array('new_share', t("'Share' element"), get_config('system','new_share'), t("Activates the bbcode element 'share' for repeating items.")),
  432. '$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.")),
  433. '$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),
  434. '$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.")),
  435. '$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.")),
  436. '$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.")),
  437. '$register_policy' => array('register_policy', t("Register policy"), $a->config['register_policy'], "", $register_choices),
  438. '$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.")),
  439. '$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.")),
  440. '$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.')),
  441. '$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")),
  442. '$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")),
  443. '$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.")),
  444. '$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.")),
  445. '$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.")),
  446. '$thread_allow' => array('thread_allow', t("Allow threaded items"), get_config('system','thread_allow'), t("Allow infinite level threading for items on this site.")),
  447. '$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.")),
  448. '$enotify_no_content' => array('enotify_no_content', t("Don't include post content in email notifications"), get_config('system','enotify_no_content'), t("Don't include the content of a post/comment/private message/etc. in the email notifications that are sent out from this site, as a privacy measure.")),
  449. '$private_addons' => array('private_addons', t("Disallow public access to addons listed in the apps menu."), get_config('config','private_addons'), t("Checking this box will restrict addons listed in the apps menu to members only.")),
  450. '$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.")),
  451. '$no_openid' => array('no_openid', t("OpenID support"), !get_config('system','no_openid'), t("OpenID support for registration and logins.")),
  452. '$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")),
  453. '$no_utf' => array('no_utf', t("UTF-8 Regular expressions"), !get_config('system','no_utf'), t("Use PHP UTF8 regular expressions")),
  454. '$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.")),
  455. '$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.")),
  456. '$diaspora_enabled' => array('diaspora_enabled', t("Enable Diaspora support"), get_config('system','diaspora_enabled'), t("Provide built-in Diaspora network compatibility.")),
  457. '$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.")),
  458. '$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.")),
  459. '$proxyuser' => array('proxyuser', t("Proxy user"), get_config('system','proxyuser'), ""),
  460. '$proxy' => array('proxy', t("Proxy URL"), get_config('system','proxy'), ""),
  461. '$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).")),
  462. '$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.")),
  463. '$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.")),
  464. '$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.")),
  465. '$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.")),
  466. '$itemcache' => array('itemcache', t("Path to item cache"), get_config('system','itemcache'), "The item caches buffers generated bbcode and external images."),
  467. '$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).")),
  468. '$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."),
  469. '$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."),
  470. '$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."),
  471. '$form_security_token' => get_form_security_token("admin_site"),
  472. ));
  473. }
  474. function admin_page_dbsync(&$a) {
  475. $o = '';
  476. if($a->argc > 3 && intval($a->argv[3]) && $a->argv[2] === 'mark') {
  477. set_config('database', 'update_' . intval($a->argv[3]), 'success');
  478. $curr = get_config('system','build');
  479. if(intval($curr) == intval($a->argv[3]))
  480. set_config('system','build',intval($curr) + 1);
  481. info( t('Update has been marked successful') . EOL);
  482. goaway($a->get_baseurl(true) . '/admin/dbsync');
  483. }
  484. if($a->argc > 2 && intval($a->argv[2])) {
  485. require_once('update.php');
  486. $func = 'update_' . intval($a->argv[2]);
  487. if(function_exists($func)) {
  488. $retval = $func();
  489. if($retval === UPDATE_FAILED) {
  490. $o .= sprintf( t('Executing %s failed. Check system logs.'), $func);
  491. }
  492. elseif($retval === UPDATE_SUCCESS) {
  493. $o .= sprintf( t('Update %s was successfully applied.', $func));
  494. set_config('database',$func, 'success');
  495. }
  496. else
  497. $o .= sprintf( t('Update %s did not return a status. Unknown if it succeeded.'), $func);
  498. }
  499. else
  500. $o .= sprintf( t('Update function %s could not be found.'), $func);
  501. return $o;
  502. }
  503. $failed = array();
  504. $r = q("select * from config where `cat` = 'database' ");
  505. if(count($r)) {
  506. foreach($r as $rr) {
  507. $upd = intval(substr($rr['k'],7));
  508. if($upd < 1139 || $rr['v'] === 'success')
  509. continue;
  510. $failed[] = $upd;
  511. }
  512. }
  513. if(! count($failed))
  514. return '<h3>' . t('No failed updates.') . '</h3>';
  515. $o = replace_macros(get_markup_template('failed_updates.tpl'),array(
  516. '$base' => $a->get_baseurl(true),
  517. '$banner' => t('Failed Updates'),
  518. '$desc' => t('This does not include updates prior to 1139, which did not return a status.'),
  519. '$mark' => t('Mark success (if update was manually applied)'),
  520. '$apply' => t('Attempt to execute this update step automatically'),
  521. '$failed' => $failed
  522. ));
  523. return $o;
  524. }
  525. /**
  526. * Users admin page
  527. *
  528. * @param App $a
  529. */
  530. function admin_page_users_post(&$a){
  531. $pending = ( x($_POST, 'pending') ? $_POST['pending'] : Array() );
  532. $users = ( x($_POST, 'user') ? $_POST['user'] : Array() );
  533. check_form_security_token_redirectOnErr('/admin/users', 'admin_users');
  534. if (x($_POST,'page_users_block')){
  535. foreach($users as $uid){
  536. q("UPDATE `user` SET `blocked`=1-`blocked` WHERE `uid`=%s",
  537. intval( $uid )
  538. );
  539. }
  540. notice( sprintf( tt("%s user blocked/unblocked", "%s users blocked/unblocked", count($users)), count($users)) );
  541. }
  542. if (x($_POST,'page_users_delete')){
  543. require_once("include/Contact.php");
  544. foreach($users as $uid){
  545. user_remove($uid);
  546. }
  547. notice( sprintf( tt("%s user deleted", "%s users deleted", count($users)), count($users)) );
  548. }
  549. if (x($_POST,'page_users_approve')){
  550. require_once("mod/regmod.php");
  551. foreach($pending as $hash){
  552. user_allow($hash);
  553. }
  554. }
  555. if (x($_POST,'page_users_deny')){
  556. require_once("mod/regmod.php");
  557. foreach($pending as $hash){
  558. user_deny($hash);
  559. }
  560. }
  561. goaway($a->get_baseurl(true) . '/admin/users' );
  562. return; // NOTREACHED
  563. }
  564. /**
  565. * @param App $a
  566. * @return string
  567. */
  568. function admin_page_users(&$a){
  569. if ($a->argc>2) {
  570. $uid = $a->argv[3];
  571. $user = q("SELECT * FROM `user` WHERE `uid`=%d", intval($uid));
  572. if (count($user)==0){
  573. notice( 'User not found' . EOL);
  574. goaway($a->get_baseurl(true) . '/admin/users' );
  575. return ''; // NOTREACHED
  576. }
  577. switch($a->argv[2]){
  578. case "delete":{
  579. check_form_security_token_redirectOnErr('/admin/users', 'admin_users', 't');
  580. // delete user
  581. require_once("include/Contact.php");
  582. user_remove($uid);
  583. notice( sprintf(t("User '%s' deleted"), $user[0]['username']) . EOL);
  584. }; break;
  585. case "block":{
  586. check_form_security_token_redirectOnErr('/admin/users', 'admin_users', 't');
  587. q("UPDATE `user` SET `blocked`=%d WHERE `uid`=%s",
  588. intval( 1-$user[0]['blocked'] ),
  589. intval( $uid )
  590. );
  591. notice( sprintf( ($user[0]['blocked']?t("User '%s' unblocked"):t("User '%s' blocked")) , $user[0]['username']) . EOL);
  592. }; break;
  593. }
  594. goaway($a->get_baseurl(true) . '/admin/users' );
  595. return ''; // NOTREACHED
  596. }
  597. /* get pending */
  598. $pending = q("SELECT `register`.*, `contact`.`name`, `user`.`email`
  599. FROM `register`
  600. LEFT JOIN `contact` ON `register`.`uid` = `contact`.`uid`
  601. LEFT JOIN `user` ON `register`.`uid` = `user`.`uid`;");
  602. /* get users */
  603. $total = q("SELECT count(*) as total FROM `user` where 1");
  604. if(count($total)) {
  605. $a->set_pager_total($total[0]['total']);
  606. $a->set_pager_itemspage(100);
  607. }
  608. $users = q("SELECT `user` . * , `contact`.`name` , `contact`.`url` , `contact`.`micro`, `lastitem`.`lastitem_date`, `user`.`account_expired`
  609. FROM
  610. (SELECT MAX(`item`.`changed`) as `lastitem_date`, `item`.`uid`
  611. FROM `item`
  612. WHERE `item`.`type` = 'wall'
  613. GROUP BY `item`.`uid`) AS `lastitem`
  614. RIGHT OUTER JOIN `user` ON `user`.`uid` = `lastitem`.`uid`,
  615. `contact`
  616. WHERE
  617. `user`.`uid` = `contact`.`uid`
  618. AND `user`.`verified` =1
  619. AND `contact`.`self` =1
  620. ORDER BY `contact`.`name` LIMIT %d, %d
  621. ",
  622. intval($a->pager['start']),
  623. intval($a->pager['itemspage'])
  624. );
  625. function _setup_users($e){
  626. $a = get_app();
  627. $accounts = Array(
  628. t('Normal Account'),
  629. t('Soapbox Account'),
  630. t('Community/Celebrity Account'),
  631. t('Automatic Friend Account')
  632. );
  633. $e['page-flags'] = $accounts[$e['page-flags']];
  634. $e['register_date'] = relative_date($e['register_date']);
  635. $e['login_date'] = relative_date($e['login_date']);
  636. $e['lastitem_date'] = relative_date($e['lastitem_date']);
  637. $e['is_admin'] = ($e['email'] === $a->config['admin_email']);
  638. return $e;
  639. }
  640. $users = array_map("_setup_users", $users);
  641. // Get rid of dashes in key names, Smarty3 can't handle them
  642. foreach($users as $key => $user) {
  643. $new_user = array();
  644. foreach($user as $k => $v) {
  645. $k = str_replace('-','_',$k);
  646. $new_user[$k] = $v;
  647. }
  648. $users[$key] = $new_user;
  649. }
  650. $t = get_markup_template("admin_users.tpl");
  651. $o = replace_macros($t, array(
  652. // strings //
  653. '$title' => t('Administration'),
  654. '$page' => t('Users'),
  655. '$submit' => t('Submit'),
  656. '$select_all' => t('select all'),
  657. '$h_pending' => t('User registrations waiting for confirm'),
  658. '$th_pending' => array( t('Request date'), t('Name'), t('Email') ),
  659. '$no_pending' => t('No registrations.'),
  660. '$approve' => t('Approve'),
  661. '$deny' => t('Deny'),
  662. '$delete' => t('Delete'),
  663. '$block' => t('Block'),
  664. '$unblock' => t('Unblock'),
  665. '$siteadmin' => t('Site admin'),
  666. '$accountexpired' => t('Account expired'),
  667. '$h_users' => t('Users'),
  668. '$th_users' => array( t('Name'), t('Email'), t('Register date'), t('Last login'), t('Last item'), t('Account') ),
  669. '$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?'),
  670. '$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?'),
  671. '$form_security_token' => get_form_security_token("admin_users"),
  672. // values //
  673. '$baseurl' => $a->get_baseurl(true),
  674. '$pending' => $pending,
  675. '$users' => $users,
  676. ));
  677. $o .= paginate($a);
  678. return $o;
  679. }
  680. /**
  681. * Plugins admin page
  682. *
  683. * @param App $a
  684. * @return string
  685. */
  686. function admin_page_plugins(&$a){
  687. /**
  688. * Single plugin
  689. */
  690. if ($a->argc == 3){
  691. $plugin = $a->argv[2];
  692. if (!is_file("addon/$plugin/$plugin.php")){
  693. notice( t("Item not found.") );
  694. return '';
  695. }
  696. if (x($_GET,"a") && $_GET['a']=="t"){
  697. check_form_security_token_redirectOnErr('/admin/plugins', 'admin_themes', 't');
  698. // Toggle plugin status
  699. $idx = array_search($plugin, $a->plugins);
  700. if ($idx !== false){
  701. unset($a->plugins[$idx]);
  702. uninstall_plugin($plugin);
  703. info( sprintf( t("Plugin %s disabled."), $plugin ) );
  704. } else {
  705. $a->plugins[] = $plugin;
  706. install_plugin($plugin);
  707. info( sprintf( t("Plugin %s enabled."), $plugin ) );
  708. }
  709. set_config("system","addon", implode(", ",$a->plugins));
  710. goaway($a->get_baseurl(true) . '/admin/plugins' );
  711. return ''; // NOTREACHED
  712. }
  713. // display plugin details
  714. require_once('library/markdown.php');
  715. if (in_array($plugin, $a->plugins)){
  716. $status="on"; $action= t("Disable");
  717. } else {
  718. $status="off"; $action= t("Enable");
  719. }
  720. $readme=Null;
  721. if (is_file("addon/$plugin/README.md")){
  722. $readme = file_get_contents("addon/$plugin/README.md");
  723. $readme = Markdown($readme);
  724. } else if (is_file("addon/$plugin/README")){
  725. $readme = "<pre>". file_get_contents("addon/$plugin/README") ."</pre>";
  726. }
  727. $admin_form="";
  728. if (is_array($a->plugins_admin) && in_array($plugin, $a->plugins_admin)){
  729. @require_once("addon/$plugin/$plugin.php");
  730. $func = $plugin.'_plugin_admin';
  731. $func($a, $admin_form);
  732. }
  733. $t = get_markup_template("admin_plugins_details.tpl");
  734. return replace_macros($t, array(
  735. '$title' => t('Administration'),
  736. '$page' => t('Plugins'),
  737. '$toggle' => t('Toggle'),
  738. '$settings' => t('Settings'),
  739. '$baseurl' => $a->get_baseurl(true),
  740. '$plugin' => $plugin,
  741. '$status' => $status,
  742. '$action' => $action,
  743. '$info' => get_plugin_info($plugin),
  744. '$str_author' => t('Author: '),
  745. '$str_maintainer' => t('Maintainer: '),
  746. '$admin_form' => $admin_form,
  747. '$function' => 'plugins',
  748. '$screenshot' => '',
  749. '$readme' => $readme,
  750. '$form_security_token' => get_form_security_token("admin_themes"),
  751. ));
  752. }
  753. /**
  754. * List plugins
  755. */
  756. $plugins = array();
  757. $files = glob("addon/*/");
  758. if($files) {
  759. foreach($files as $file) {
  760. if (is_dir($file)){
  761. list($tmp, $id)=array_map("trim", explode("/",$file));
  762. $info = get_plugin_info($id);
  763. $plugins[] = array( $id, (in_array($id, $a->plugins)?"on":"off") , $info);
  764. }
  765. }
  766. }
  767. $t = get_markup_template("admin_plugins.tpl");
  768. return replace_macros($t, array(
  769. '$title' => t('Administration'),
  770. '$page' => t('Plugins'),
  771. '$submit' => t('Submit'),
  772. '$baseurl' => $a->get_baseurl(true),
  773. '$function' => 'plugins',
  774. '$plugins' => $plugins,
  775. '$form_security_token' => get_form_security_token("admin_themes"),
  776. ));
  777. }
  778. /**
  779. * @param array $themes
  780. * @param string $th
  781. * @param int $result
  782. */
  783. function toggle_theme(&$themes,$th,&$result) {
  784. for($x = 0; $x < count($themes); $x ++) {
  785. if($themes[$x]['name'] === $th) {
  786. if($themes[$x]['allowed']) {
  787. $themes[$x]['allowed'] = 0;
  788. $result = 0;
  789. }
  790. else {
  791. $themes[$x]['allowed'] = 1;
  792. $result = 1;
  793. }
  794. }
  795. }
  796. }
  797. /**
  798. * @param array $themes
  799. * @param string $th
  800. * @return int
  801. */
  802. function theme_status($themes,$th) {
  803. for($x = 0; $x < count($themes); $x ++) {
  804. if($themes[$x]['name'] === $th) {
  805. if($themes[$x]['allowed']) {
  806. return 1;
  807. }
  808. else {
  809. return 0;
  810. }
  811. }
  812. }
  813. return 0;
  814. }
  815. /**
  816. * @param array $themes
  817. * @return string
  818. */
  819. function rebuild_theme_table($themes) {
  820. $o = '';
  821. if(count($themes)) {
  822. foreach($themes as $th) {
  823. if($th['allowed']) {
  824. if(strlen($o))
  825. $o .= ',';
  826. $o .= $th['name'];
  827. }
  828. }
  829. }
  830. return $o;
  831. }
  832. /**
  833. * Themes admin page
  834. *
  835. * @param App $a
  836. * @return string
  837. */
  838. function admin_page_themes(&$a){
  839. $allowed_themes_str = get_config('system','allowed_themes');
  840. $allowed_themes_raw = explode(',',$allowed_themes_str);
  841. $allowed_themes = array();
  842. if(count($allowed_themes_raw))
  843. foreach($allowed_themes_raw as $x)
  844. if(strlen(trim($x)))
  845. $allowed_themes[] = trim($x);
  846. $themes = array();
  847. $files = glob('view/theme/*');
  848. if($files) {
  849. foreach($files as $file) {
  850. $f = basename($file);
  851. $is_experimental = intval(file_exists($file . '/experimental'));
  852. $is_supported = 1-(intval(file_exists($file . '/unsupported'))); // Is not used yet
  853. $is_allowed = intval(in_array($f,$allowed_themes));
  854. $themes[] = array('name' => $f, 'experimental' => $is_experimental, 'supported' => $is_supported, 'allowed' => $is_allowed);
  855. }
  856. }
  857. if(! count($themes)) {
  858. notice( t('No themes found.'));
  859. return '';
  860. }
  861. /**
  862. * Single theme
  863. */
  864. if ($a->argc == 3){
  865. $theme = $a->argv[2];
  866. if(! is_dir("view/theme/$theme")){
  867. notice( t("Item not found.") );
  868. return '';
  869. }
  870. if (x($_GET,"a") && $_GET['a']=="t"){
  871. check_form_security_token_redirectOnErr('/admin/themes', 'admin_themes', 't');
  872. // Toggle theme status
  873. toggle_theme($themes,$theme,$result);
  874. $s = rebuild_theme_table($themes);
  875. if($result) {
  876. install_theme($theme);
  877. info( sprintf('Theme %s enabled.',$theme));
  878. }
  879. else {
  880. uninstall_theme($theme);
  881. info( sprintf('Theme %s disabled.',$theme));
  882. }
  883. set_config('system','allowed_themes',$s);
  884. goaway($a->get_baseurl(true) . '/admin/themes' );
  885. return ''; // NOTREACHED
  886. }
  887. // display theme details
  888. require_once('library/markdown.php');
  889. if (theme_status($themes,$theme)) {
  890. $status="on"; $action= t("Disable");
  891. } else {
  892. $status="off"; $action= t("Enable");
  893. }
  894. $readme=Null;
  895. if (is_file("view/theme/$theme/README.md")){
  896. $readme = file_get_contents("view/theme/$theme/README.md");
  897. $readme = Markdown($readme);
  898. } else if (is_file("view/theme/$theme/README")){
  899. $readme = "<pre>". file_get_contents("view/theme/$theme/README") ."</pre>";
  900. }
  901. $admin_form="";
  902. if (is_file("view/theme/$theme/config.php")){
  903. require_once("view/theme/$theme/config.php");
  904. if(function_exists("theme_admin")){
  905. $admin_form = theme_admin($a);
  906. }
  907. }
  908. $screenshot = array( get_theme_screenshot($theme), t('Screenshot'));
  909. if(! stristr($screenshot[0],$theme))
  910. $screenshot = null;
  911. $t = get_markup_template("admin_plugins_details.tpl");
  912. return replace_macros($t, array(
  913. '$title' => t('Administration'),
  914. '$page' => t('Themes'),
  915. '$toggle' => t('Toggle'),
  916. '$settings' => t('Settings'),
  917. '$baseurl' => $a->get_baseurl(true),
  918. '$plugin' => $theme,
  919. '$status' => $status,
  920. '$action' => $action,
  921. '$info' => get_theme_info($theme),
  922. '$function' => 'themes',
  923. '$admin_form' => $admin_form,
  924. '$str_author' => t('Author: '),
  925. '$str_maintainer' => t('Maintainer: '),
  926. '$screenshot' => $screenshot,
  927. '$readme' => $readme,
  928. '$form_security_token' => get_form_security_token("admin_themes"),
  929. ));
  930. }
  931. /**
  932. * List themes
  933. */
  934. $xthemes = array();
  935. if($themes) {
  936. foreach($themes as $th) {
  937. $xthemes[] = array($th['name'],(($th['allowed']) ? "on" : "off"), get_theme_info($th['name']));
  938. }
  939. }
  940. $t = get_markup_template("admin_plugins.tpl");
  941. return replace_macros($t, array(
  942. '$title' => t('Administration'),
  943. '$page' => t('Themes'),
  944. '$submit' => t('Submit'),
  945. '$baseurl' => $a->get_baseurl(true),
  946. '$function' => 'themes',
  947. '$plugins' => $xthemes,
  948. '$experimental' => t('[Experimental]'),
  949. '$unsupported' => t('[Unsupported]'),
  950. '$form_security_token' => get_form_security_token("admin_themes"),
  951. ));
  952. }
  953. /**
  954. * Logs admin page
  955. *
  956. * @param App $a
  957. */
  958. function admin_page_logs_post(&$a) {
  959. if (x($_POST,"page_logs")) {
  960. check_form_security_token_redirectOnErr('/admin/logs', 'admin_logs');
  961. $logfile = ((x($_POST,'logfile')) ? notags(trim($_POST['logfile'])) : '');
  962. $debugging = ((x($_POST,'debugging')) ? true : false);
  963. $loglevel = ((x($_POST,'loglevel')) ? intval(trim($_POST['loglevel'])) : 0);
  964. set_config('system','logfile', $logfile);
  965. set_config('system','debugging', $debugging);
  966. set_config('system','loglevel', $loglevel);
  967. }
  968. info( t("Log settings updated.") );
  969. goaway($a->get_baseurl(true) . '/admin/logs' );
  970. return; // NOTREACHED
  971. }
  972. /**
  973. * @param App $a
  974. * @return string
  975. */
  976. function admin_page_logs(&$a){
  977. $log_choices = Array(
  978. LOGGER_NORMAL => 'Normal',
  979. LOGGER_TRACE => 'Trace',
  980. LOGGER_DEBUG => 'Debug',
  981. LOGGER_DATA => 'Data',
  982. LOGGER_ALL => 'All'
  983. );
  984. $t = get_markup_template("admin_logs.tpl");
  985. $f = get_config('system','logfile');
  986. $data = '';
  987. if(!file_exists($f)) {
  988. $data = t("Error trying to open <strong>$f</strong> log file.\r\n<br/>Check to see if file $f exist and is
  989. readable.");
  990. }
  991. else {
  992. $fp = fopen($f, 'r');
  993. if(!$fp) {
  994. $data = t("Couldn't open <strong>$f</strong> log file.\r\n<br/>Check to see if file $f is readable.");
  995. }
  996. else {
  997. $fstat = fstat($fp);
  998. $size = $fstat['size'];
  999. if($size != 0)
  1000. {
  1001. if($size > 5000000 || $size < 0)
  1002. $size = 5000000;
  1003. $seek = fseek($fp,0-$size,SEEK_END);
  1004. if($seek === 0) {
  1005. $data = escape_tags(fread($fp,$size));
  1006. while(! feof($fp))
  1007. $data .= escape_tags(fread($fp,4096));
  1008. }
  1009. }
  1010. fclose($fp);
  1011. }
  1012. }
  1013. return replace_macros($t, array(
  1014. '$title' => t('Administration'),
  1015. '$page' => t('Logs'),
  1016. '$submit' => t('Submit'),
  1017. '$clear' => t('Clear'),
  1018. '$data' => $data,
  1019. '$baseurl' => $a->get_baseurl(true),
  1020. '$logname' => get_config('system','logfile'),
  1021. // name, label, value, help string, extra data...
  1022. '$debugging' => array('debugging', t("Debugging"),get_config('system','debugging'), ""),
  1023. '$logfile' => array('logfile', t("Log file"), get_config('system','logfile'), t("Must be writable by web server. Relative to your Friendica top-level directory.")),
  1024. '$loglevel' => array('loglevel', t("Log level"), get_config('system','loglevel'), "", $log_choices),
  1025. '$form_security_token' => get_form_security_token("admin_logs"),
  1026. ));
  1027. }
  1028. /**
  1029. * @param App $a
  1030. */
  1031. function admin_page_remoteupdate_post(&$a) {
  1032. // this function should be called via ajax post
  1033. if(!is_site_admin()) {
  1034. return;
  1035. }
  1036. if (x($_POST,'remotefile') && $_POST['remotefile']!=""){
  1037. $remotefile = $_POST['remotefile'];
  1038. $ftpdata = (x($_POST['ftphost'])?$_POST:false);
  1039. doUpdate($remotefile, $ftpdata);
  1040. } else {
  1041. echo "No remote file to download. Abort!";
  1042. }
  1043. killme();
  1044. }
  1045. /**
  1046. * @param App $a
  1047. * @return string
  1048. */
  1049. function admin_page_remoteupdate(&$a) {
  1050. if(!is_site_admin()) {
  1051. return login(false);
  1052. }
  1053. $canwrite = canWeWrite();
  1054. $canftp = function_exists('ftp_connect');
  1055. $needupdate = true;
  1056. $u = checkUpdate();
  1057. if (!is_array($u)){
  1058. $needupdate = false;
  1059. $u = array('','','');
  1060. }
  1061. $tpl = get_markup_template("admin_remoteupdate.tpl");
  1062. return replace_macros($tpl, array(
  1063. '$baseurl' => $a->get_baseurl(true),
  1064. '$submit' => t("Update now"),
  1065. '$close' => t("Close"),
  1066. '$localversion' => FRIENDICA_VERSION,
  1067. '$remoteversion' => $u[1],
  1068. '$needupdate' => $needupdate,
  1069. '$canwrite' => $canwrite,
  1070. '$canftp' => $canftp,
  1071. '$ftphost' => array('ftphost', t("FTP Host"), '',''),
  1072. '$ftppath' => array('ftppath', t("FTP Path"), '/',''),
  1073. '$ftpuser' => array('ftpuser', t("FTP User"), '',''),
  1074. '$ftppwd' => array('ftppwd', t("FTP Password"), '',''),
  1075. '$remotefile'=>array('remotefile','', $u['2'],''),
  1076. ));
  1077. }