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.
 
 
 
 
 
 

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