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.
 
 
 
 
 
 

1188 lines
39 KiB

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