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.
 
 
 
 
 
 

1246 lines
43 KiB

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