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.

admin.php 90KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294
  1. <?php
  2. /**
  3. * @file mod/admin.php
  4. *
  5. * @brief Friendica admin
  6. */
  7. use Friendica\App;
  8. use Friendica\Core\System;
  9. use Friendica\Core\Config;
  10. use Friendica\Core\Worker;
  11. require_once("include/enotify.php");
  12. require_once("include/text.php");
  13. require_once('include/items.php');
  14. /**
  15. * @brief Process send data from the admin panels subpages
  16. *
  17. * This function acts as relais for processing the data send from the subpages
  18. * of the admin panel. Depending on the 1st parameter of the url (argv[1])
  19. * specialized functions are called to process the data from the subpages.
  20. *
  21. * The function itself does not return anything, but the subsequencely function
  22. * return the HTML for the pages of the admin panel.
  23. *
  24. * @param App $a
  25. *
  26. */
  27. function admin_post(App $a) {
  28. if (!is_site_admin()) {
  29. return;
  30. }
  31. // do not allow a page manager to access the admin panel at all.
  32. if (x($_SESSION,'submanage') && intval($_SESSION['submanage'])) {
  33. return;
  34. }
  35. // urls
  36. if ($a->argc > 1) {
  37. switch ($a->argv[1]) {
  38. case 'site':
  39. admin_page_site_post($a);
  40. break;
  41. case 'users':
  42. admin_page_users_post($a);
  43. break;
  44. case 'plugins':
  45. if ($a->argc > 2 &&
  46. is_file("addon/".$a->argv[2]."/".$a->argv[2].".php")) {
  47. @include_once("addon/".$a->argv[2]."/".$a->argv[2].".php");
  48. if (function_exists($a->argv[2].'_plugin_admin_post')) {
  49. $func = $a->argv[2].'_plugin_admin_post';
  50. $func($a);
  51. }
  52. }
  53. goaway('admin/plugins/'.$a->argv[2]);
  54. return; // NOTREACHED
  55. break;
  56. case 'themes':
  57. if ($a->argc < 2) {
  58. if (is_ajax()) {
  59. return;
  60. }
  61. goaway('admin/');
  62. return;
  63. }
  64. $theme = $a->argv[2];
  65. if (is_file("view/theme/$theme/config.php")) {
  66. function __call_theme_admin_post(App $a, $theme) {
  67. $orig_theme = $a->theme;
  68. $orig_page = $a->page;
  69. $orig_session_theme = $_SESSION['theme'];
  70. require_once("view/theme/$theme/theme.php");
  71. require_once("view/theme/$theme/config.php");
  72. $_SESSION['theme'] = $theme;
  73. $init = $theme."_init";
  74. if (function_exists($init)) {
  75. $init($a);
  76. }
  77. if (function_exists("theme_admin_post")) {
  78. $admin_form = theme_admin_post($a);
  79. }
  80. $_SESSION['theme'] = $orig_session_theme;
  81. $a->theme = $orig_theme;
  82. $a->page = $orig_page;
  83. return $admin_form;
  84. }
  85. __call_theme_admin_post($a, $theme);
  86. }
  87. info(t('Theme settings updated.'));
  88. if (is_ajax()) {
  89. return;
  90. }
  91. goaway('admin/themes/'.$theme);
  92. return;
  93. break;
  94. case 'features':
  95. admin_page_features_post($a);
  96. break;
  97. case 'logs':
  98. admin_page_logs_post($a);
  99. break;
  100. case 'dbsync':
  101. admin_page_dbsync_post($a);
  102. break;
  103. case 'blocklist':
  104. admin_page_blocklist_post($a);
  105. break;
  106. case 'deleteitem':
  107. admin_page_deleteitem_post($a);
  108. break;
  109. }
  110. }
  111. goaway('admin');
  112. return; // NOTREACHED
  113. }
  114. /**
  115. * @brief Generates content of the admin panel pages
  116. *
  117. * This function generates the content for the admin panel. It consists of the
  118. * aside menu (same for the entire admin panel) and the code for the soecified
  119. * subpage of the panel.
  120. *
  121. * The structure of the adress is: /admin/subpage/details though "details" is
  122. * only necessary for some subpages, like themes or addons where it is the name
  123. * of one theme resp. addon from which the details should be shown. Content for
  124. * the subpages is generated in separate functions for each of the subpages.
  125. *
  126. * The returned string hold the generated HTML code of the page.
  127. *
  128. * @param App $a
  129. * @return string
  130. */
  131. function admin_content(App $a) {
  132. if (!is_site_admin()) {
  133. return login(false);
  134. }
  135. if (x($_SESSION,'submanage') && intval($_SESSION['submanage'])) {
  136. return "";
  137. }
  138. // APC deactivated, since there are problems with PHP 5.5
  139. //if (function_exists("apc_delete")) {
  140. // $toDelete = new APCIterator('user', APC_ITER_VALUE);
  141. // apc_delete($toDelete);
  142. //}
  143. // Header stuff
  144. $a->page['htmlhead'] .= replace_macros(get_markup_template('admin_settings_head.tpl'), array());
  145. /*
  146. * Side bar links
  147. */
  148. $aside_tools = array();
  149. // array(url, name, extra css classes)
  150. // not part of $aside to make the template more adjustable
  151. $aside_sub = array(
  152. 'site' => array("admin/site/", t("Site") , "site"),
  153. 'users' => array("admin/users/", t("Users") , "users"),
  154. 'plugins'=> array("admin/plugins/", t("Plugins") , "plugins"),
  155. 'themes' => array("admin/themes/", t("Themes") , "themes"),
  156. 'features' => array("admin/features/", t("Additional features") , "features"),
  157. 'dbsync' => array("admin/dbsync/", t('DB updates'), "dbsync"),
  158. 'queue' => array("admin/queue/", t('Inspect Queue'), "queue"),
  159. 'blocklist' => array("admin/blocklist/", t('Server Blocklist'), "blocklist"),
  160. 'federation' => array("admin/federation/", t('Federation Statistics'), "federation"),
  161. 'deleteitem' => array("admin/deleteitem/", t('Delete Item'), 'deleteitem'),
  162. );
  163. /* get plugins admin page */
  164. $r = q("SELECT `name` FROM `addon` WHERE `plugin_admin` = 1 ORDER BY `name`");
  165. $aside_tools['plugins_admin']=array();
  166. foreach ($r as $h) {
  167. $plugin =$h['name'];
  168. $aside_tools['plugins_admin'][] = array("admin/plugins/".$plugin, $plugin, "plugin");
  169. // temp plugins with admin
  170. $a->plugins_admin[] = $plugin;
  171. }
  172. $aside_tools['logs'] = array("admin/logs/", t("Logs"), "logs");
  173. $aside_tools['viewlogs'] = array("admin/viewlogs/", t("View Logs"), 'viewlogs');
  174. $aside_tools['diagnostics_probe'] = array('probe/', t('probe address'), 'probe');
  175. $aside_tools['diagnostics_webfinger'] = array('webfinger/', t('check webfinger'), 'webfinger');
  176. $t = get_markup_template("admin_aside.tpl");
  177. $a->page['aside'] .= replace_macros($t, array(
  178. '$admin' => $aside_tools,
  179. '$subpages' => $aside_sub,
  180. '$admtxt' => t('Admin'),
  181. '$plugadmtxt' => t('Plugin Features'),
  182. '$logtxt' => t('Logs'),
  183. '$diagnosticstxt' => t('diagnostics'),
  184. '$h_pending' => t('User registrations waiting for confirmation'),
  185. '$admurl'=> "admin/"
  186. ));
  187. /*
  188. * Page content
  189. */
  190. $o = '';
  191. // urls
  192. if ($a->argc > 1) {
  193. switch ($a->argv[1]) {
  194. case 'site':
  195. $o = admin_page_site($a);
  196. break;
  197. case 'users':
  198. $o = admin_page_users($a);
  199. break;
  200. case 'plugins':
  201. $o = admin_page_plugins($a);
  202. break;
  203. case 'themes':
  204. $o = admin_page_themes($a);
  205. break;
  206. case 'features':
  207. $o = admin_page_features($a);
  208. break;
  209. case 'logs':
  210. $o = admin_page_logs($a);
  211. break;
  212. case 'viewlogs':
  213. $o = admin_page_viewlogs($a);
  214. break;
  215. case 'dbsync':
  216. $o = admin_page_dbsync($a);
  217. break;
  218. case 'queue':
  219. $o = admin_page_queue($a);
  220. break;
  221. case 'federation':
  222. $o = admin_page_federation($a);
  223. break;
  224. case 'blocklist':
  225. $o = admin_page_blocklist($a);
  226. break;
  227. case 'deleteitem':
  228. $o = admin_page_deleteitem($a);
  229. break;
  230. default:
  231. notice(t("Item not found."));
  232. }
  233. } else {
  234. $o = admin_page_summary($a);
  235. }
  236. if (is_ajax()) {
  237. echo $o;
  238. killme();
  239. return '';
  240. } else {
  241. return $o;
  242. }
  243. }
  244. /**
  245. * @brief Subpage to modify the server wide block list via the admin panel.
  246. *
  247. * This function generates the subpage of the admin panel to allow the
  248. * modification of the node wide block/black list to block entire
  249. * remote servers from communication with this node. The page allows
  250. * adding, removing and editing of entries from the blocklist.
  251. *
  252. * @param App $a
  253. * @return string
  254. */
  255. function admin_page_blocklist(App $a) {
  256. $blocklist = Config::get('system', 'blocklist');
  257. $blocklistform = array();
  258. if (is_array($blocklist)) {
  259. foreach($blocklist as $id => $b) {
  260. $blocklistform[] = array(
  261. 'domain' => array("domain[$id]", t('Blocked domain'), $b['domain'], '', t('The blocked domain'), 'required', '', ''),
  262. 'reason' => array("reason[$id]", t("Reason for the block"), $b['reason'], t('The reason why you blocked this domain.').'('.$b['domain'].')', 'required', '', ''),
  263. 'delete' => array("delete[$id]", t("Delete domain").' ('.$b['domain'].')', False , t("Check to delete this entry from the blocklist"))
  264. );
  265. }
  266. }
  267. $t = get_markup_template("admin_blocklist.tpl");
  268. return replace_macros($t, array(
  269. '$title' => t('Administration'),
  270. '$page' => t('Server Blocklist'),
  271. '$intro' => t('This page can be used to define a black list of servers from the federated network that are not allowed to interact with your node. For all entered domains you should also give a reason why you have blocked the remote server.'),
  272. '$public' => t('The list of blocked servers will be made publically available on the /friendica page so that your users and people investigating communication problems can find the reason easily.'),
  273. '$addtitle' => t('Add new entry to block list'),
  274. '$newdomain' => array('newentry_domain', t('Server Domain'), '', t('The domain of the new server to add to the block list. Do not include the protocol.'), 'required', '', ''),
  275. '$newreason' => array('newentry_reason', t('Block reason'), '', t('The reason why you blocked this domain.'), 'required', '', ''),
  276. '$submit' => t('Add Entry'),
  277. '$savechanges' => t('Save changes to the blocklist'),
  278. '$currenttitle' => t('Current Entries in the Blocklist'),
  279. '$thurl' => t('Blocked domain'),
  280. '$threason' => t('Reason for the block'),
  281. '$delentry' => t('Delete entry from blocklist'),
  282. '$entries' => $blocklistform,
  283. '$baseurl' => System::baseUrl(true),
  284. '$confirm_delete' => t('Delete entry from blocklist?'),
  285. '$form_security_token' => get_form_security_token("admin_blocklist")
  286. ));
  287. }
  288. /**
  289. * @brief Process send data from Admin Blocklist Page
  290. *
  291. * @param App $a
  292. */
  293. function admin_page_blocklist_post(App $a) {
  294. if (!x($_POST,"page_blocklist_save") && (!x($_POST['page_blocklist_edit']))) {
  295. return;
  296. }
  297. check_form_security_token_redirectOnErr('/admin/blocklist', 'admin_blocklist');
  298. if (x($_POST['page_blocklist_save'])) {
  299. // Add new item to blocklist
  300. $blocklist = Config::get('system', 'blocklist');
  301. $blocklist[] = array(
  302. 'domain' => notags(trim($_POST['newentry_domain'])),
  303. 'reason' => notags(trim($_POST['newentry_reason']))
  304. );
  305. Config::set('system', 'blocklist', $blocklist);
  306. info(t('Server added to blocklist.').EOL);
  307. } else {
  308. // Edit the entries from blocklist
  309. $blocklist = array();
  310. foreach ($_POST['domain'] as $id => $domain) {
  311. // Trimming whitespaces as well as any lingering slashes
  312. $domain = notags(trim($domain, "\x00..\x1F/"));
  313. $reason = notags(trim($_POST['reason'][$id]));
  314. if (!x($_POST['delete'][$id])) {
  315. $blocklist[] = array(
  316. 'domain' => $domain,
  317. 'reason' => $reason
  318. );
  319. }
  320. }
  321. Config::set('system', 'blocklist', $blocklist);
  322. info(t('Site blocklist updated.').EOL);
  323. }
  324. goaway('admin/blocklist');
  325. return; // NOTREACHED
  326. }
  327. /**
  328. * @brief Subpage where the admin can delete an item from their node given the GUID
  329. *
  330. * This subpage of the admin panel offers the nodes admin to delete an item from
  331. * the node, given the GUID or the display URL such as http://example.com/display/123456.
  332. * The item will then be marked as deleted in the database and processed accordingly.
  333. *
  334. * @param App $a
  335. * @return string
  336. */
  337. function admin_page_deleteitem(App $a) {
  338. $t = get_markup_template("admin_deleteitem.tpl");
  339. return replace_macros($t, array(
  340. '$title' => t('Administration'),
  341. '$page' => t('Delete Item'),
  342. '$submit' => t('Delete this Item'),
  343. '$intro1' => t('On this page you can delete an item from your node. If the item is a top level posting, the entire thread will be deleted.'),
  344. '$intro2' => t('You need to know the GUID of the item. You can find it e.g. by looking at the display URL. The last part of http://example.com/display/123456 is the GUID, here 123456.'),
  345. '$deleteitemguid' => array('deleteitemguid', t("GUID"), '', t("The GUID of the item you want to delete."), 'required', 'autofocus'),
  346. '$baseurl' => System::baseUrl(),
  347. '$form_security_token' => get_form_security_token("admin_deleteitem")
  348. ));
  349. }
  350. /**
  351. * @brief Process send data from Admin Delete Item Page
  352. *
  353. * The GUID passed through the form should be only the GUID. But we also parse
  354. * URLs like the full /display URL to make the process more easy for the admin.
  355. *
  356. * @param App $a
  357. */
  358. function admin_page_deleteitem_post(App $a) {
  359. if (!x($_POST['page_deleteitem_submit'])) {
  360. return;
  361. }
  362. check_form_security_token_redirectOnErr('/admin/deleteitem/', 'admin_deleteitem');
  363. if (x($_POST['page_deleteitem_submit'])) {
  364. $guid = trim(notags($_POST['deleteitemguid']));
  365. // The GUID should not include a "/", so if there is one, we got an URL
  366. // and the last part of it is most likely the GUID.
  367. if (strpos($guid, '/')) {
  368. $guid = substr($guid, strrpos($guid, '/')+1);
  369. }
  370. // Now that we have the GUID get all IDs of the associated entries in the
  371. // item table of the DB and drop those items, which will also delete the
  372. // associated threads.
  373. $r = dba::select('item', array('id'), array('guid'=>$guid));
  374. while ($row = dba::fetch($r)) {
  375. drop_item($row['id'], false);
  376. }
  377. dba::close($r);
  378. }
  379. info(t('Item marked for deletion.').EOL);
  380. goaway('admin/deleteitem');
  381. return; // NOTREACHED
  382. }
  383. /**
  384. * @brief Subpage with some stats about "the federation" network
  385. *
  386. * This function generates the "Federation Statistics" subpage for the admin
  387. * panel. The page lists some numbers to the part of "The Federation" known to
  388. * the node. This data includes the different connected networks (e.g.
  389. * Diaspora, Hubzilla, GNU Social) and the used versions in the different
  390. * networks.
  391. *
  392. * The returned string contains the HTML code of the subpage for display.
  393. *
  394. * @param App $a
  395. * @return string
  396. */
  397. function admin_page_federation(App $a) {
  398. // get counts on active friendica, diaspora, redmatrix, hubzilla, gnu
  399. // social and statusnet nodes this node is knowing
  400. //
  401. // We are looking for the following platforms in the DB, "Red" should find
  402. // all variants of that platform ID string as the q() function is stripping
  403. // off one % two of them are needed in the query
  404. // Add more platforms if you like, when one returns 0 known nodes it is not
  405. // displayed on the stats page.
  406. $platforms = array('Friendi%%a', 'Diaspora', '%%red%%', 'Hubzilla', 'BlaBlaNet', 'GNU Social', 'StatusNet', 'Mastodon', 'Pleroma');
  407. $colors = array('Friendi%%a' => '#ffc018', // orange from the logo
  408. 'Diaspora' => '#a1a1a1', // logo is black and white, makes a gray
  409. '%%red%%' => '#c50001', // fire red from the logo
  410. 'Hubzilla' => '#43488a', // blue from the logo
  411. 'BlaBlaNet' => '#3B5998', // blue from the navbar at blablanet-dot-com
  412. 'GNU Social'=> '#a22430', // dark red from the logo
  413. 'StatusNet' => '#789240', // the green from the logo (red and blue have already others
  414. 'Mastodon' => '#1a9df9', // blue from the Mastodon logo
  415. 'Pleroma' => '#E46F0F'); // Orange from the text that is used on Pleroma instances
  416. $counts = array();
  417. $total = 0;
  418. foreach ($platforms as $p) {
  419. // get a total count for the platform, the name and version of the
  420. // highest version and the protocol tpe
  421. $c = q('SELECT COUNT(*) AS `total`, ANY_VALUE(`platform`) AS `platform`,
  422. ANY_VALUE(`network`) AS `network`, MAX(`version`) AS `version` FROM `gserver`
  423. WHERE `platform` LIKE "%s" AND `last_contact` >= `last_failure`
  424. ORDER BY `version` ASC;', $p);
  425. $total = $total + $c[0]['total'];
  426. // what versions for that platform do we know at all?
  427. // again only the active nodes
  428. $v = q('SELECT COUNT(*) AS `total`, `version` FROM `gserver`
  429. WHERE `last_contact` >= `last_failure` AND `platform` LIKE "%s"
  430. GROUP BY `version`
  431. ORDER BY `version`;', $p);
  432. //
  433. // clean up version numbers
  434. //
  435. // some platforms do not provide version information, add a unkown there
  436. // to the version string for the displayed list.
  437. foreach ($v as $key => $value) {
  438. if ($v[$key]['version'] == '') {
  439. $v[$key] = array('total'=>$v[$key]['total'], 'version'=>t('unknown'));
  440. }
  441. }
  442. // in the DB the Diaspora versions have the format x.x.x.x-xx the last
  443. // part (-xx) should be removed to clean up the versions from the "head
  444. // commit" information and combined into a single entry for x.x.x.x
  445. if ($p == 'Diaspora') {
  446. $newV = array();
  447. $newVv = array();
  448. foreach ($v as $vv) {
  449. $newVC = $vv['total'];
  450. $newVV = $vv['version'];
  451. $posDash = strpos($newVV, '-');
  452. if ($posDash) {
  453. $newVV = substr($newVV, 0, $posDash);
  454. }
  455. if (isset($newV[$newVV])) {
  456. $newV[$newVV] += $newVC;
  457. } else {
  458. $newV[$newVV] = $newVC;
  459. }
  460. }
  461. foreach ($newV as $key => $value) {
  462. array_push($newVv, array('total'=>$value, 'version'=>$key));
  463. }
  464. $v = $newVv;
  465. }
  466. // early friendica versions have the format x.x.xxxx where xxxx is the
  467. // DB version stamp; those should be operated out and versions be
  468. // conbined
  469. if ($p == 'Friendi%%a') {
  470. $newV = array();
  471. $newVv = array();
  472. foreach ($v as $vv) {
  473. $newVC = $vv['total'];
  474. $newVV = $vv['version'];
  475. $lastDot = strrpos($newVV,'.');
  476. $len = strlen($newVV)-1;
  477. if (($lastDot == $len-4) && (!strrpos($newVV,'-rc') == $len-3)) {
  478. $newVV = substr($newVV, 0, $lastDot);
  479. }
  480. if (isset($newV[$newVV])) {
  481. $newV[$newVV] += $newVC;
  482. } else {
  483. $newV[$newVV] = $newVC;
  484. }
  485. }
  486. foreach ($newV as $key => $value) {
  487. array_push($newVv, array('total'=>$value, 'version'=>$key));
  488. }
  489. $v = $newVv;
  490. }
  491. foreach ($v as $key => $vv)
  492. $v[$key]["version"] = trim(strip_tags($vv["version"]));
  493. // the 3rd array item is needed for the JavaScript graphs as JS does
  494. // not like some characters in the names of variables...
  495. $counts[$p]=array($c[0], $v, str_replace(array(' ','%'),'',$p), $colors[$p]);
  496. }
  497. // some helpful text
  498. $intro = t('This page offers you some numbers to the known part of the federated social network your Friendica node is part of. These numbers are not complete but only reflect the part of the network your node is aware of.');
  499. $hint = t('The <em>Auto Discovered Contact Directory</em> feature is not enabled, it will improve the data displayed here.');
  500. // load the template, replace the macros and return the page content
  501. $t = get_markup_template("admin_federation.tpl");
  502. return replace_macros($t, array(
  503. '$title' => t('Administration'),
  504. '$page' => t('Federation Statistics'),
  505. '$intro' => $intro,
  506. '$hint' => $hint,
  507. '$autoactive' => Config::get('system', 'poco_completion'),
  508. '$counts' => $counts,
  509. '$version' => FRIENDICA_VERSION,
  510. '$legendtext' => sprintf(t('Currently this node is aware of %d nodes from the following platforms:'), $total),
  511. '$baseurl' => System::baseUrl(),
  512. ));
  513. }
  514. /**
  515. * @brief Admin Inspect Queue Page
  516. *
  517. * Generates a page for the admin to have a look into the current queue of
  518. * postings that are not deliverabke. Shown are the name and url of the
  519. * recipient, the delivery network and the dates when the posting was generated
  520. * and the last time tried to deliver the posting.
  521. *
  522. * The returned string holds the content of the page.
  523. *
  524. * @param App $a
  525. * @return string
  526. */
  527. function admin_page_queue(App $a) {
  528. // get content from the queue table
  529. $r = q("SELECT `c`.`name`, `c`.`nurl`, `q`.`id`, `q`.`network`, `q`.`created`, `q`.`last`
  530. FROM `queue` AS `q`, `contact` AS `c`
  531. WHERE `c`.`id` = `q`.`cid`
  532. ORDER BY `q`.`cid`, `q`.`created`;");
  533. $t = get_markup_template("admin_queue.tpl");
  534. return replace_macros($t, array(
  535. '$title' => t('Administration'),
  536. '$page' => t('Inspect Queue'),
  537. '$count' => sizeof($r),
  538. 'id_header' => t('ID'),
  539. '$to_header' => t('Recipient Name'),
  540. '$url_header' => t('Recipient Profile'),
  541. '$network_header' => t('Network'),
  542. '$created_header' => t('Created'),
  543. '$last_header' => t('Last Tried'),
  544. '$info' => t('This page lists the content of the queue for outgoing postings. These are postings the initial delivery failed for. They will be resend later and eventually deleted if the delivery fails permanently.'),
  545. '$entries' => $r,
  546. ));
  547. }
  548. /**
  549. * @brief Admin Summary Page
  550. *
  551. * The summary page is the "start page" of the admin panel. It gives the admin
  552. * a first overview of the open adminastrative tasks.
  553. *
  554. * The returned string contains the HTML content of the generated page.
  555. *
  556. * @param App $a
  557. * @return string
  558. */
  559. function admin_page_summary(App $a) {
  560. // are there MyISAM tables in the DB? If so, trigger a warning message
  561. $r = q("SELECT `engine` FROM `information_schema`.`tables` WHERE `engine` = 'myisam' AND `table_schema` = '%s' LIMIT 1",
  562. dbesc(dba::database_name()));
  563. $showwarning = false;
  564. $warningtext = array();
  565. if (dbm::is_result($r)) {
  566. $showwarning = true;
  567. $warningtext[] = sprintf(t('Your DB still runs with MyISAM tables. You should change the engine type to InnoDB. As Friendica will use InnoDB only features in the future, you should change this! See <a href="%s">here</a> for a guide that may be helpful converting the table engines. You may also use the command <tt>php include/dbstructure.php toinnodb</tt> of your Friendica installation for an automatic conversion.<br />'), 'https://dev.mysql.com/doc/refman/5.7/en/converting-tables-to-innodb.html');
  568. }
  569. // Check if github.com/friendica/master/VERSION is higher then
  570. // the local version of Friendica. Check is opt-in, source may be master or devel branch
  571. if (Config::get('system', 'check_new_version_url', 'none') != 'none' ) {
  572. $gitversion = Config::get('system','git_friendica_version');
  573. if (version_compare(FRIENDICA_VERSION, $gitversion) < 0) {
  574. $warningtext[] = sprintf(t('There is a new version of Friendica available for download. Your current version is %1$s, upstream version is %2$s'), $FRIENDICA_VERSION, $gitversion);
  575. $showwarning = true;
  576. }
  577. }
  578. if (Config::get('system', 'dbupdate', DB_UPDATE_NOT_CHECKED) == DB_UPDATE_NOT_CHECKED) {
  579. require_once("include/dbstructure.php");
  580. update_structure(false, true);
  581. }
  582. if (Config::get('system', 'dbupdate') == DB_UPDATE_FAILED) {
  583. $showwarning = true;
  584. $warningtext[] = t('The database update failed. Please run "php include/dbstructure.php update" from the command line and have a look at the errors that might appear.');
  585. }
  586. $last_worker_call = Config::get('system', 'last_poller_execution', false);
  587. if (!$last_worker_call) {
  588. $showwarning = true;
  589. $warningtext[] = t('The worker was never executed. Please check your database structure!');
  590. } elseif ((strtotime(datetime_convert()) - strtotime($last_worker_call)) > 60 * 60) {
  591. $showwarning = true;
  592. $warningtext[] = sprintf(t('The last worker execution was on %s UTC. This is older than one hour. Please check your crontab settings.'), $last_worker_call);
  593. }
  594. $r = q("SELECT `page-flags`, COUNT(`uid`) AS `count` FROM `user` GROUP BY `page-flags`");
  595. $accounts = array(
  596. array(t('Normal Account'), 0),
  597. array(t('Automatic Follower Account'), 0),
  598. array(t('Public Forum Account'), 0),
  599. array(t('Automatic Friend Account'), 0),
  600. array(t('Blog Account'), 0),
  601. array(t('Private Forum Account'), 0)
  602. );
  603. $users=0;
  604. foreach ($r as $u) {
  605. $accounts[$u['page-flags']][1] = $u['count'];
  606. $users+= $u['count'];
  607. }
  608. logger('accounts: '.print_r($accounts,true),LOGGER_DATA);
  609. $r = q("SELECT COUNT(`id`) AS `count` FROM `register`");
  610. $pending = $r[0]['count'];
  611. $r = q("SELECT COUNT(*) AS `total` FROM `queue` WHERE 1");
  612. $queue = (($r) ? $r[0]['total'] : 0);
  613. $r = q("SELECT COUNT(*) AS `total` FROM `workerqueue` WHERE NOT `done`");
  614. $workerqueue = (($r) ? $r[0]['total'] : 0);
  615. // We can do better, but this is a quick queue status
  616. $queues = array('label' => t('Message queues'), 'queue' => $queue, 'workerq' => $workerqueue);
  617. $t = get_markup_template("admin_summary.tpl");
  618. return replace_macros($t, array(
  619. '$title' => t('Administration'),
  620. '$page' => t('Summary'),
  621. '$queues' => $queues,
  622. '$users' => array(t('Registered users'), $users),
  623. '$accounts' => $accounts,
  624. '$pending' => array(t('Pending registrations'), $pending),
  625. '$version' => array(t('Version'), FRIENDICA_VERSION),
  626. '$baseurl' => System::baseUrl(),
  627. '$platform' => FRIENDICA_PLATFORM,
  628. '$codename' => FRIENDICA_CODENAME,
  629. '$build' => Config::get('system','build'),
  630. '$plugins' => array(t('Active plugins'), $a->plugins),
  631. '$showwarning' => $showwarning,
  632. '$warningtext' => $warningtext
  633. ));
  634. }
  635. /**
  636. * @brief Process send data from Admin Site Page
  637. *
  638. * @param App $a
  639. */
  640. function admin_page_site_post(App $a) {
  641. check_form_security_token_redirectOnErr('/admin/site', 'admin_site');
  642. if (!empty($_POST['republish_directory'])) {
  643. Worker::add(PRIORITY_LOW, 'directory');
  644. return;
  645. }
  646. if (!x($_POST,"page_site")) {
  647. return;
  648. }
  649. // relocate
  650. if (x($_POST,'relocate') && x($_POST,'relocate_url') && $_POST['relocate_url'] != "") {
  651. $new_url = $_POST['relocate_url'];
  652. $new_url = rtrim($new_url,"/");
  653. $parsed = @parse_url($new_url);
  654. if (!$parsed || (!x($parsed,'host') || !x($parsed,'scheme'))) {
  655. notice(t("Can not parse base url. Must have at least <scheme>://<domain>"));
  656. goaway('admin/site');
  657. }
  658. /* steps:
  659. * replace all "baseurl" to "new_url" in config, profile, term, items and contacts
  660. * send relocate for every local user
  661. * */
  662. $old_url = System::baseUrl(true);
  663. // Generate host names for relocation the addresses in the format user@address.tld
  664. $new_host = str_replace("http://", "@", normalise_link($new_url));
  665. $old_host = str_replace("http://", "@", normalise_link($old_url));
  666. function update_table($table_name, $fields, $old_url, $new_url) {
  667. global $a;
  668. $dbold = dbesc($old_url);
  669. $dbnew = dbesc($new_url);
  670. $upd = array();
  671. foreach ($fields as $f) {
  672. $upd[] = "`$f` = REPLACE(`$f`, '$dbold', '$dbnew')";
  673. }
  674. $upds = implode(", ", $upd);
  675. $q = sprintf("UPDATE %s SET %s;", $table_name, $upds);
  676. $r = q($q);
  677. if (!$r) {
  678. notice("Failed updating '$table_name': ".dba::errorMessage());
  679. goaway('admin/site');
  680. }
  681. }
  682. // update tables
  683. // update profile links in the format "http://server.tld"
  684. update_table("profile", array('photo', 'thumb'), $old_url, $new_url);
  685. update_table("term", array('url'), $old_url, $new_url);
  686. update_table("contact", array('photo','thumb','micro','url','nurl','alias','request','notify','poll','confirm','poco', 'avatar'), $old_url, $new_url);
  687. update_table("gcontact", array('url','nurl','photo','server_url','notify','alias'), $old_url, $new_url);
  688. update_table("item", array('owner-link','owner-avatar','author-link','author-avatar','body','plink','tag'), $old_url, $new_url);
  689. // update profile addresses in the format "user@server.tld"
  690. update_table("contact", array('addr'), $old_host, $new_host);
  691. update_table("gcontact", array('connect','addr'), $old_host, $new_host);
  692. // update config
  693. $a->set_baseurl($new_url);
  694. Config::set('system','url',$new_url);
  695. // send relocate
  696. $users = q("SELECT `uid` FROM `user` WHERE `account_removed` = 0 AND `account_expired` = 0");
  697. foreach ($users as $user) {
  698. Worker::add(PRIORITY_HIGH, 'notifier', 'relocate', $user['uid']);
  699. }
  700. info("Relocation started. Could take a while to complete.");
  701. goaway('admin/site');
  702. }
  703. // end relocate
  704. $sitename = ((x($_POST,'sitename')) ? notags(trim($_POST['sitename'])) : '');
  705. $hostname = ((x($_POST,'hostname')) ? notags(trim($_POST['hostname'])) : '');
  706. $sender_email = ((x($_POST,'sender_email')) ? notags(trim($_POST['sender_email'])) : '');
  707. $banner = ((x($_POST,'banner')) ? trim($_POST['banner']) : false);
  708. $shortcut_icon = ((x($_POST,'shortcut_icon')) ? notags(trim($_POST['shortcut_icon'])) : '');
  709. $touch_icon = ((x($_POST,'touch_icon')) ? notags(trim($_POST['touch_icon'])) : '');
  710. $info = ((x($_POST,'info')) ? trim($_POST['info']) : false);
  711. $language = ((x($_POST,'language')) ? notags(trim($_POST['language'])) : '');
  712. $theme = ((x($_POST,'theme')) ? notags(trim($_POST['theme'])) : '');
  713. $theme_mobile = ((x($_POST,'theme_mobile')) ? notags(trim($_POST['theme_mobile'])) : '');
  714. $maximagesize = ((x($_POST,'maximagesize')) ? intval(trim($_POST['maximagesize'])) : 0);
  715. $maximagelength = ((x($_POST,'maximagelength')) ? intval(trim($_POST['maximagelength'])) : MAX_IMAGE_LENGTH);
  716. $jpegimagequality = ((x($_POST,'jpegimagequality')) ? intval(trim($_POST['jpegimagequality'])) : JPEG_QUALITY);
  717. $register_policy = ((x($_POST,'register_policy')) ? intval(trim($_POST['register_policy'])) : 0);
  718. $daily_registrations = ((x($_POST,'max_daily_registrations')) ? intval(trim($_POST['max_daily_registrations'])) :0);
  719. $abandon_days = ((x($_POST,'abandon_days')) ? intval(trim($_POST['abandon_days'])) : 0);
  720. $register_text = ((x($_POST,'register_text')) ? notags(trim($_POST['register_text'])) : '');
  721. $allowed_sites = ((x($_POST,'allowed_sites')) ? notags(trim($_POST['allowed_sites'])) : '');
  722. $allowed_email = ((x($_POST,'allowed_email')) ? notags(trim($_POST['allowed_email'])) : '');
  723. $block_public = ((x($_POST,'block_public')) ? True : False);
  724. $force_publish = ((x($_POST,'publish_all')) ? True : False);
  725. $global_directory = ((x($_POST,'directory')) ? notags(trim($_POST['directory'])) : '');
  726. $thread_allow = ((x($_POST,'thread_allow')) ? True : False);
  727. $newuser_private = ((x($_POST,'newuser_private')) ? True : False);
  728. $enotify_no_content = ((x($_POST,'enotify_no_content')) ? True : False);
  729. $private_addons = ((x($_POST,'private_addons')) ? True : False);
  730. $disable_embedded = ((x($_POST,'disable_embedded')) ? True : False);
  731. $allow_users_remote_self = ((x($_POST,'allow_users_remote_self')) ? True : False);
  732. $no_multi_reg = ((x($_POST,'no_multi_reg')) ? True : False);
  733. $no_openid = !((x($_POST,'no_openid')) ? True : False);
  734. $no_regfullname = !((x($_POST,'no_regfullname')) ? True : False);
  735. $community_page_style = ((x($_POST,'community_page_style')) ? intval(trim($_POST['community_page_style'])) : 0);
  736. $max_author_posts_community_page = ((x($_POST,'max_author_posts_community_page')) ? intval(trim($_POST['max_author_posts_community_page'])) : 0);
  737. $verifyssl = ((x($_POST,'verifyssl')) ? True : False);
  738. $proxyuser = ((x($_POST,'proxyuser')) ? notags(trim($_POST['proxyuser'])) : '');
  739. $proxy = ((x($_POST,'proxy')) ? notags(trim($_POST['proxy'])) : '');
  740. $timeout = ((x($_POST,'timeout')) ? intval(trim($_POST['timeout'])) : 60);
  741. $maxloadavg = ((x($_POST,'maxloadavg')) ? intval(trim($_POST['maxloadavg'])) : 50);
  742. $maxloadavg_frontend = ((x($_POST,'maxloadavg_frontend')) ? intval(trim($_POST['maxloadavg_frontend'])) : 50);
  743. $min_memory = ((x($_POST,'min_memory')) ? intval(trim($_POST['min_memory'])) : 0);
  744. $optimize_max_tablesize = ((x($_POST,'optimize_max_tablesize')) ? intval(trim($_POST['optimize_max_tablesize'])): 100);
  745. $optimize_fragmentation = ((x($_POST,'optimize_fragmentation')) ? intval(trim($_POST['optimize_fragmentation'])): 30);
  746. $poco_completion = ((x($_POST,'poco_completion')) ? intval(trim($_POST['poco_completion'])) : false);
  747. $poco_requery_days = ((x($_POST,'poco_requery_days')) ? intval(trim($_POST['poco_requery_days'])) : 7);
  748. $poco_discovery = ((x($_POST,'poco_discovery')) ? intval(trim($_POST['poco_discovery'])) : 0);
  749. $poco_discovery_since = ((x($_POST,'poco_discovery_since')) ? intval(trim($_POST['poco_discovery_since'])) : 30);
  750. $poco_local_search = ((x($_POST,'poco_local_search')) ? intval(trim($_POST['poco_local_search'])) : false);
  751. $nodeinfo = ((x($_POST,'nodeinfo')) ? intval(trim($_POST['nodeinfo'])) : false);
  752. $dfrn_only = ((x($_POST,'dfrn_only')) ? True : False);
  753. $ostatus_disabled = !((x($_POST,'ostatus_disabled')) ? True : False);
  754. $ostatus_full_threads = ((x($_POST,'ostatus_full_threads')) ? True : False);
  755. $diaspora_enabled = ((x($_POST,'diaspora_enabled')) ? True : False);
  756. $ssl_policy = ((x($_POST,'ssl_policy')) ? intval($_POST['ssl_policy']) : 0);
  757. $force_ssl = ((x($_POST,'force_ssl')) ? True : False);
  758. $hide_help = ((x($_POST,'hide_help')) ? True : False);
  759. $suppress_tags = ((x($_POST,'suppress_tags')) ? True : False);
  760. $itemcache = ((x($_POST,'itemcache')) ? notags(trim($_POST['itemcache'])) : '');
  761. $itemcache_duration = ((x($_POST,'itemcache_duration')) ? intval($_POST['itemcache_duration']) : 0);
  762. $max_comments = ((x($_POST,'max_comments')) ? intval($_POST['max_comments']) : 0);
  763. $temppath = ((x($_POST,'temppath')) ? notags(trim($_POST['temppath'])) : '');
  764. $basepath = ((x($_POST,'basepath')) ? notags(trim($_POST['basepath'])) : '');
  765. $singleuser = ((x($_POST,'singleuser')) ? notags(trim($_POST['singleuser'])) : '');
  766. $proxy_disabled = ((x($_POST,'proxy_disabled')) ? True : False);
  767. $only_tag_search = ((x($_POST,'only_tag_search')) ? True : False);
  768. $rino = ((x($_POST,'rino')) ? intval($_POST['rino']) : 0);
  769. $check_new_version_url = ((x($_POST, 'check_new_version_url')) ? notags(trim($_POST['check_new_version_url'])) : 'none');
  770. $worker_queues = ((x($_POST,'worker_queues')) ? intval($_POST['worker_queues']) : 4);
  771. $worker_dont_fork = ((x($_POST,'worker_dont_fork')) ? True : False);
  772. $worker_fastlane = ((x($_POST,'worker_fastlane')) ? True : False);
  773. $worker_frontend = ((x($_POST,'worker_frontend')) ? True : False);
  774. // Has the directory url changed? If yes, then resubmit the existing profiles there
  775. if ($global_directory != Config::get('system', 'directory') && ($global_directory != '')) {
  776. Config::set('system', 'directory', $global_directory);
  777. Worker::add(PRIORITY_LOW, 'directory');
  778. }
  779. if ($a->get_path() != "") {
  780. $diaspora_enabled = false;
  781. }
  782. if (!$thread_allow) {
  783. $ostatus_disabled = true;
  784. }
  785. if ($ssl_policy != intval(Config::get('system','ssl_policy'))) {
  786. if ($ssl_policy == SSL_POLICY_FULL) {
  787. q("UPDATE `contact` SET
  788. `url` = REPLACE(`url` , 'http:' , 'https:'),
  789. `photo` = REPLACE(`photo` , 'http:' , 'https:'),
  790. `thumb` = REPLACE(`thumb` , 'http:' , 'https:'),
  791. `micro` = REPLACE(`micro` , 'http:' , 'https:'),
  792. `request` = REPLACE(`request`, 'http:' , 'https:'),
  793. `notify` = REPLACE(`notify` , 'http:' , 'https:'),
  794. `poll` = REPLACE(`poll` , 'http:' , 'https:'),
  795. `confirm` = REPLACE(`confirm`, 'http:' , 'https:'),
  796. `poco` = REPLACE(`poco` , 'http:' , 'https:')
  797. WHERE `self` = 1"
  798. );
  799. q("UPDATE `profile` SET
  800. `photo` = REPLACE(`photo` , 'http:' , 'https:'),
  801. `thumb` = REPLACE(`thumb` , 'http:' , 'https:')
  802. WHERE 1 "
  803. );
  804. } elseif ($ssl_policy == SSL_POLICY_SELFSIGN) {
  805. q("UPDATE `contact` SET
  806. `url` = REPLACE(`url` , 'https:' , 'http:'),
  807. `photo` = REPLACE(`photo` , 'https:' , 'http:'),
  808. `thumb` = REPLACE(`thumb` , 'https:' , 'http:'),
  809. `micro` = REPLACE(`micro` , 'https:' , 'http:'),
  810. `request` = REPLACE(`request`, 'https:' , 'http:'),
  811. `notify` = REPLACE(`notify` , 'https:' , 'http:'),
  812. `poll` = REPLACE(`poll` , 'https:' , 'http:'),
  813. `confirm` = REPLACE(`confirm`, 'https:' , 'http:'),
  814. `poco` = REPLACE(`poco` , 'https:' , 'http:')
  815. WHERE `self` = 1"
  816. );
  817. q("UPDATE `profile` SET
  818. `photo` = REPLACE(`photo` , 'https:' , 'http:'),
  819. `thumb` = REPLACE(`thumb` , 'https:' , 'http:')
  820. WHERE 1 "
  821. );
  822. }
  823. }
  824. Config::set('system','ssl_policy',$ssl_policy);
  825. Config::set('system','maxloadavg',$maxloadavg);
  826. Config::set('system','maxloadavg_frontend',$maxloadavg_frontend);
  827. Config::set('system','min_memory',$min_memory);
  828. Config::set('system','optimize_max_tablesize',$optimize_max_tablesize);
  829. Config::set('system','optimize_fragmentation',$optimize_fragmentation);
  830. Config::set('system','poco_completion',$poco_completion);
  831. Config::set('system','poco_requery_days',$poco_requery_days);
  832. Config::set('system','poco_discovery',$poco_discovery);
  833. Config::set('system','poco_discovery_since',$poco_discovery_since);
  834. Config::set('system','poco_local_search',$poco_local_search);
  835. Config::set('system','nodeinfo',$nodeinfo);
  836. Config::set('config','sitename',$sitename);
  837. Config::set('config','hostname',$hostname);
  838. Config::set('config','sender_email', $sender_email);
  839. Config::set('system','suppress_tags',$suppress_tags);
  840. Config::set('system','shortcut_icon',$shortcut_icon);
  841. Config::set('system','touch_icon',$touch_icon);
  842. if ($banner == "") {
  843. // don't know why, but del_config doesn't work...
  844. q("DELETE FROM `config` WHERE `cat` = '%s' AND `k` = '%s' LIMIT 1",
  845. dbesc("system"),
  846. dbesc("banner")
  847. );
  848. } else {
  849. Config::set('system','banner', $banner);
  850. }
  851. if ($info == "") {
  852. Config::delete('config','info');
  853. } else {
  854. Config::set('config','info',$info);
  855. }
  856. Config::set('system','language', $language);
  857. Config::set('system','theme', $theme);
  858. if ($theme_mobile == '---') {
  859. Config::delete('system','mobile-theme');
  860. } else {
  861. Config::set('system','mobile-theme', $theme_mobile);
  862. }
  863. if ($singleuser == '---') {
  864. Config::delete('system','singleuser');
  865. } else {
  866. Config::set('system','singleuser', $singleuser);
  867. }
  868. Config::set('system', 'maximagesize', $maximagesize);
  869. Config::set('system', 'max_image_length', $maximagelength);
  870. Config::set('system', 'jpeg_quality', $jpegimagequality);
  871. Config::set('config', 'register_policy', $register_policy);
  872. Config::set('system', 'max_daily_registrations', $daily_registrations);
  873. Config::set('system', 'account_abandon_days', $abandon_days);
  874. Config::set('config', 'register_text', $register_text);
  875. Config::set('system', 'allowed_sites', $allowed_sites);
  876. Config::set('system', 'allowed_email', $allowed_email);
  877. Config::set('system', 'block_public', $block_public);
  878. Config::set('system', 'publish_all', $force_publish);
  879. Config::set('system', 'thread_allow', $thread_allow);
  880. Config::set('system', 'newuser_private', $newuser_private);
  881. Config::set('system', 'enotify_no_content', $enotify_no_content);
  882. Config::set('system', 'disable_embedded', $disable_embedded);
  883. Config::set('system', 'allow_users_remote_self', $allow_users_remote_self);
  884. Config::set('system', 'check_new_version_url', $check_new_version_url);
  885. Config::set('system', 'block_extended_register', $no_multi_reg);
  886. Config::set('system', 'no_openid', $no_openid);
  887. Config::set('system', 'no_regfullname', $no_regfullname);
  888. Config::set('system', 'community_page_style', $community_page_style);
  889. Config::set('system', 'max_author_posts_community_page', $max_author_posts_community_page);
  890. Config::set('system', 'verifyssl', $verifyssl);
  891. Config::set('system', 'proxyuser', $proxyuser);
  892. Config::set('system', 'proxy', $proxy);
  893. Config::set('system', 'curl_timeout', $timeout);
  894. Config::set('system', 'dfrn_only', $dfrn_only);
  895. Config::set('system', 'ostatus_disabled', $ostatus_disabled);
  896. Config::set('system', 'ostatus_full_threads', $ostatus_full_threads);
  897. Config::set('system', 'diaspora_enabled', $diaspora_enabled);
  898. Config::set('config', 'private_addons', $private_addons);
  899. Config::set('system', 'force_ssl', $force_ssl);
  900. Config::set('system', 'hide_help', $hide_help);
  901. if ($itemcache != '') {
  902. $itemcache = App::realpath($itemcache);
  903. }
  904. Config::set('system', 'itemcache', $itemcache);
  905. Config::set('system', 'itemcache_duration', $itemcache_duration);
  906. Config::set('system', 'max_comments', $max_comments);
  907. if ($temppath != '') {
  908. $temppath = App::realpath($temppath);
  909. }
  910. Config::set('system', 'temppath', $temppath);
  911. if ($basepath != '') {
  912. $basepath = App::realpath($basepath);
  913. }
  914. Config::set('system', 'basepath', $basepath);
  915. Config::set('system', 'proxy_disabled', $proxy_disabled);
  916. Config::set('system', 'only_tag_search', $only_tag_search);
  917. Config::set('system', 'worker_queues', $worker_queues);
  918. Config::set('system', 'worker_dont_fork', $worker_dont_fork);
  919. Config::set('system', 'worker_fastlane', $worker_fastlane);
  920. Config::set('system', 'frontend_worker', $worker_frontend);
  921. Config::set('system', 'rino_encrypt', $rino);
  922. info(t('Site settings updated.').EOL);
  923. goaway('admin/site');
  924. return; // NOTREACHED
  925. }
  926. /**
  927. * @brief Generate Admin Site subpage
  928. *
  929. * This function generates the main configuration page of the admin panel.
  930. *
  931. * @param App $a
  932. * @return string
  933. */
  934. function admin_page_site(App $a) {
  935. /* Installed langs */
  936. $lang_choices = get_available_languages();
  937. if (strlen(Config::get('system','directory_submit_url')) &&
  938. !strlen(Config::get('system','directory'))) {
  939. Config::set('system','directory', dirname(Config::get('system','directory_submit_url')));
  940. Config::delete('system','directory_submit_url');
  941. }
  942. /* Installed themes */
  943. $theme_choices = array();
  944. $theme_choices_mobile = array();
  945. $theme_choices_mobile["---"] = t("No special theme for mobile devices");
  946. $files = glob('view/theme/*');
  947. if ($files) {
  948. $allowed_theme_list = Config::get('system', 'allowed_themes');
  949. foreach ($files as $file) {
  950. if (intval(file_exists($file.'/unsupported')))
  951. continue;
  952. $f = basename($file);
  953. // Only show allowed themes here
  954. if (($allowed_theme_list != '') && !strstr($allowed_theme_list, $f)) {
  955. continue;
  956. }
  957. $theme_name = ((file_exists($file.'/experimental')) ? sprintf("%s - \x28Experimental\x29", $f) : $f);
  958. if (file_exists($file.'/mobile')) {
  959. $theme_choices_mobile[$f] = $theme_name;
  960. } else {
  961. $theme_choices[$f] = $theme_name;
  962. }
  963. }
  964. }
  965. /* Community page style */
  966. $community_page_style_choices = array(
  967. CP_NO_COMMUNITY_PAGE => t("No community page"),
  968. CP_USERS_ON_SERVER => t("Public postings from users of this site"),
  969. CP_GLOBAL_COMMUNITY => t("Global community page")
  970. );
  971. /* OStatus conversation poll choices */
  972. $ostatus_poll_choices = array(
  973. "-2" => t("Never"),
  974. "-1" => t("At post arrival"),
  975. "0" => t("Frequently"),
  976. "60" => t("Hourly"),
  977. "720" => t("Twice daily"),
  978. "1440" => t("Daily")
  979. );
  980. $poco_discovery_choices = array(
  981. "0" => t("Disabled"),
  982. "1" => t("Users"),
  983. "2" => t("Users, Global Contacts"),
  984. "3" => t("Users, Global Contacts/fallback"),
  985. );
  986. $poco_discovery_since_choices = array(
  987. "30" => t("One month"),
  988. "91" => t("Three months"),
  989. "182" => t("Half a year"),
  990. "365" => t("One year"),
  991. );
  992. /* get user names to make the install a personal install of X */
  993. $user_names = array();
  994. $user_names['---'] = t('Multi user instance');
  995. $users = q("SELECT `username`, `nickname` FROM `user`");
  996. foreach ($users as $user) {
  997. $user_names[$user['nickname']] = $user['username'];
  998. }
  999. /* Banner */
  1000. $banner = Config::get('system','banner');
  1001. if ($banner == false) {
  1002. $banner = '<a href="https://friendi.ca"><img id="logo-img" src="images/friendica-32.png" alt="logo" /></a><span id="logo-text"><a href="https://friendi.ca">Friendica</a></span>';
  1003. }
  1004. $banner = htmlspecialchars($banner);
  1005. $info = Config::get('config','info');
  1006. $info = htmlspecialchars($info);
  1007. // Automatically create temporary paths
  1008. get_temppath();
  1009. get_itemcachepath();
  1010. //echo "<pre>"; var_dump($lang_choices); die("</pre>");
  1011. /* Register policy */
  1012. $register_choices = array(
  1013. REGISTER_CLOSED => t("Closed"),
  1014. REGISTER_APPROVE => t("Requires approval"),
  1015. REGISTER_OPEN => t("Open")
  1016. );
  1017. $ssl_choices = array(
  1018. SSL_POLICY_NONE => t("No SSL policy, links will track page SSL state"),
  1019. SSL_POLICY_FULL => t("Force all links to use SSL"),
  1020. SSL_POLICY_SELFSIGN => t("Self-signed certificate, use SSL for local links only (discouraged)")
  1021. );
  1022. $check_git_version_choices = array(
  1023. "none" => t("Don't check"),
  1024. "master" => t("check the stable version"),
  1025. "develop" => t("check the development version")
  1026. );
  1027. if ($a->config['hostname'] == "") {
  1028. $a->config['hostname'] = $a->get_hostname();
  1029. }
  1030. $diaspora_able = ($a->get_path() == "");
  1031. $optimize_max_tablesize = Config::get('system','optimize_max_tablesize', 100);
  1032. if ($optimize_max_tablesize < -1) {
  1033. $optimize_max_tablesize = -1;
  1034. }
  1035. if ($optimize_max_tablesize == 0) {
  1036. $optimize_max_tablesize = 100;
  1037. }
  1038. $t = get_markup_template("admin_site.tpl");
  1039. return replace_macros($t, array(
  1040. '$title' => t('Administration'),
  1041. '$page' => t('Site'),
  1042. '$submit' => t('Save Settings'),
  1043. '$republish' => t('Republish users to directory'),
  1044. '$registration' => t('Registration'),
  1045. '$upload' => t('File upload'),
  1046. '$corporate' => t('Policies'),
  1047. '$advanced' => t('Advanced'),
  1048. '$portable_contacts' => t('Auto Discovered Contact Directory'),
  1049. '$performance' => t('Performance'),
  1050. '$worker_title' => t('Worker'),
  1051. '$relocate'=> t('Relocate - WARNING: advanced function. Could make this server unreachable.'),
  1052. '$baseurl' => System::baseUrl(true),
  1053. // name, label, value, help string, extra data...
  1054. '$sitename' => array('sitename', t("Site name"), $a->config['sitename'],''),
  1055. '$hostname' => array('hostname', t("Host name"), $a->config['hostname'], ""),
  1056. '$sender_email' => array('sender_email', t("Sender Email"), $a->config['sender_email'], t("The email address your server shall use to send notification emails from."), "", "", "email"),
  1057. '$banner' => array('banner', t("Banner/Logo"), $banner, ""),
  1058. '$shortcut_icon' => array('shortcut_icon', t("Shortcut icon"), Config::get('system','shortcut_icon'), t("Link to an icon that will be used for browsers.")),
  1059. '$touch_icon' => array('touch_icon', t("Touch icon"), Config::get('system','touch_icon'), t("Link to an icon that will be used for tablets and mobiles.")),
  1060. '$info' => array('info', t('Additional Info'), $info, sprintf(t('For public servers: you can add additional information here that will be listed at %s/siteinfo.'), get_server())),
  1061. '$language' => array('language', t("System language"), Config::get('system','language'), "", $lang_choices),
  1062. '$theme' => array('theme', t("System theme"), Config::get('system','theme'), t("Default system theme - may be over-ridden by user profiles - <a href='#' id='cnftheme'>change theme settings</a>"), $theme_choices),
  1063. '$theme_mobile' => array('theme_mobile', t("Mobile system theme"), Config::get('system', 'mobile-theme', '---'), t("Theme for mobile devices"), $theme_choices_mobile),
  1064. '$ssl_policy' => array('ssl_policy', t("SSL link policy"), (string) intval(Config::get('system','ssl_policy')), t("Determines whether generated links should be forced to use SSL"), $ssl_choices),
  1065. '$force_ssl' => array('force_ssl', t("Force SSL"), Config::get('system','force_ssl'), t("Force all Non-SSL requests to SSL - Attention: on some systems it could lead to endless loops.")),
  1066. '$hide_help' => array('hide_help', t("Hide help entry from navigation menu"), Config::get('system','hide_help'), t("Hides the menu entry for the Help pages from the navigation menu. You can still access it calling /help directly.")),
  1067. '$singleuser' => array('singleuser', t("Single user instance"), Config::get('system', 'singleuser', '---'), t("Make this instance multi-user or single-user for the named user"), $user_names),
  1068. '$maximagesize' => array('maximagesize', t("Maximum image size"), Config::get('system','maximagesize'), t("Maximum size in bytes of uploaded images. Default is 0, which means no limits.")),
  1069. '$maximagelength' => array('maximagelength', t("Maximum image length"), Config::get('system','max_image_length'), t("Maximum length in pixels of the longest side of uploaded images. Default is -1, which means no limits.")),
  1070. '$jpegimagequality' => array('jpegimagequality', t("JPEG image quality"), Config::get('system','jpeg_quality'), t("Uploaded JPEGS will be saved at this quality setting [0-100]. Default is 100, which is full quality.")),
  1071. '$register_policy' => array('register_policy', t("Register policy"), $a->config['register_policy'], "", $register_choices),
  1072. '$daily_registrations' => array('max_daily_registrations', t("Maximum Daily Registrations"), Config::get('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.")),
  1073. '$register_text' => array('register_text', t("Register text"), $a->config['register_text'], t("Will be displayed prominently on the registration page.")),
  1074. '$abandon_days' => array('abandon_days', t('Accounts abandoned after x days'), Config::get('system','account_abandon_days'), t('Will not waste system resources polling external sites for abandonded accounts. Enter 0 for no time limit.')),
  1075. '$allowed_sites' => array('allowed_sites', t("Allowed friend domains"), Config::get('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")),
  1076. '$allowed_email' => array('allowed_email', t("Allowed email domains"), Config::get('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")),
  1077. '$block_public' => array('block_public', t("Block public"), Config::get('system','block_public'), t("Check to block public access to all otherwise public personal pages on this site unless you are currently logged in.")),
  1078. '$force_publish' => array('publish_all', t("Force publish"), Config::get('system','publish_all'), t("Check to force all profiles on this site to be listed in the site directory.")),
  1079. '$global_directory' => array('directory', t("Global directory URL"), Config::get('system','directory'), t("URL to the global directory. If this is not set, the global directory is completely unavailable to the application.")),
  1080. '$thread_allow' => array('thread_allow', t("Allow threaded items"), Config::get('system','thread_allow'), t("Allow infinite level threading for items on this site.")),
  1081. '$newuser_private' => array('newuser_private', t("Private posts by default for new users"), Config::get('system','newuser_private'), t("Set default post permissions for all new members to the default privacy group rather than public.")),
  1082. '$enotify_no_content' => array('enotify_no_content', t("Don't include post content in email notifications"), Config::get('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.")),
  1083. '$private_addons' => array('private_addons', t("Disallow public access to addons listed in the apps menu."), Config::get('config','private_addons'), t("Checking this box will restrict addons listed in the apps menu to members only.")),
  1084. '$disable_embedded' => array('disable_embedded', t("Don't embed private images in posts"), Config::get('system','disable_embedded'), t("Don't replace locally-hosted private photos in posts with an embedded copy of the image. This means that contacts who receive posts containing private photos will have to authenticate and load each image, which may take a while.")),
  1085. '$allow_users_remote_self' => array('allow_users_remote_self', t('Allow Users to set remote_self'), Config::get('system','allow_users_remote_self'), t('With checking this, every user is allowed to mark every contact as a remote_self in the repair contact dialog. Setting this flag on a contact causes mirroring every posting of that contact in the users stream.')),
  1086. '$no_multi_reg' => array('no_multi_reg', t("Block multiple registrations"), Config::get('system','block_extended_register'), t("Disallow users to register additional accounts for use as pages.")),
  1087. '$no_openid' => array('no_openid', t("OpenID support"), !Config::get('system','no_openid'), t("OpenID support for registration and logins.")),
  1088. '$no_regfullname' => array('no_regfullname', t("Fullname check"), !Config::get('system','no_regfullname'), t("Force users to register with a space between firstname and lastname in Full name, as an antispam measure")),
  1089. '$community_page_style' => array('community_page_style', t("Community Page Style"), Config::get('system','community_page_style'), t("Type of community page to show. 'Global community' shows every public posting from an open distributed network that arrived on this server."), $community_page_style_choices),
  1090. '$max_author_posts_community_page' => array('max_author_posts_community_page', t("Posts per user on community page"), Config::get('system','max_author_posts_community_page'), t("The maximum number of posts per user on the community page. (Not valid for 'Global Community')")),
  1091. '$ostatus_disabled' => array('ostatus_disabled', t("Enable OStatus support"), !Config::get('system','ostatus_disabled'), t("Provide built-in OStatus \x28StatusNet, GNU Social etc.\x29 compatibility. All communications in OStatus are public, so privacy warnings will be occasionally displayed.")),
  1092. '$ostatus_full_threads' => array('ostatus_full_threads', t("Only import OStatus threads from our contacts"), Config::get('system','ostatus_full_threads'), t("Normally we import every content from our OStatus contacts. With this option we only store threads that are started by a contact that is known on our system.")),
  1093. '$ostatus_not_able' => t("OStatus support can only be enabled if threading is enabled."),
  1094. '$diaspora_able' => $diaspora_able,
  1095. '$diaspora_not_able' => t("Diaspora support can't be enabled because Friendica was installed into a sub directory."),
  1096. '$diaspora_enabled' => array('diaspora_enabled', t("Enable Diaspora support"), Config::get('system','diaspora_enabled'), t("Provide built-in Diaspora network compatibility.")),
  1097. '$dfrn_only' => array('dfrn_only', t('Only allow Friendica contacts'), Config::get('system','dfrn_only'), t("All contacts must use Friendica protocols. All other built-in communication protocols disabled.")),
  1098. '$verifyssl' => array('verifyssl', t("Verify SSL"), Config::get('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.")),
  1099. '$proxyuser' => array('proxyuser', t("Proxy user"), Config::get('system','proxyuser'), ""),
  1100. '$proxy' => array('proxy', t("Proxy URL"), Config::get('system','proxy'), ""),
  1101. '$timeout' => array('timeout', t("Network timeout"), (x(Config::get('system','curl_timeout'))?Config::get('system','curl_timeout'):60), t("Value is in seconds. Set to 0 for unlimited (not recommended).")),
  1102. '$maxloadavg' => array('maxloadavg', t("Maximum Load Average"), ((intval(Config::get('system','maxloadavg')) > 0)?Config::get('system','maxloadavg'):50), t("Maximum system load before delivery and poll processes are deferred - default 50.")),
  1103. '$maxloadavg_frontend' => array('maxloadavg_frontend', t("Maximum Load Average (Frontend)"), ((intval(Config::get('system','maxloadavg_frontend')) > 0)?Config::get('system','maxloadavg_frontend'):50), t("Maximum system load before the frontend quits service - default 50.")),
  1104. '$min_memory' => array('min_memory', t("Minimal Memory"), ((intval(Config::get('system','min_memory')) > 0)?Config::get('system','min_memory'):0), t("Minimal free memory in MB for the poller. Needs access to /proc/meminfo - default 0 (deactivated).")),
  1105. '$optimize_max_tablesize'=> array('optimize_max_tablesize', t("Maximum table size for optimization"), $optimize_max_tablesize, t("Maximum table size (in MB) for the automatic optimization - default 100 MB. Enter -1 to disable it.")),
  1106. '$optimize_fragmentation'=> array('optimize_fragmentation', t("Minimum level of fragmentation"), ((intval(Config::get('system','optimize_fragmentation')) > 0)?Config::get('system','optimize_fragmentation'):30), t("Minimum fragmenation level to start the automatic optimization - default value is 30%.")),
  1107. '$poco_completion' => array('poco_completion', t("Periodical check of global contacts"), Config::get('system','poco_completion'), t("If enabled, the global contacts are checked periodically for missing or outdated data and the vitality of the contacts and servers.")),
  1108. '$poco_requery_days' => array('poco_requery_days', t("Days between requery"), Config::get('system','poco_requery_days'), t("Number of days after which a server is requeried for his contacts.")),
  1109. '$poco_discovery' => array('poco_discovery', t("Discover contacts from other servers"), (string) intval(Config::get('system','poco_discovery')), t("Periodically query other servers for contacts. You can choose between 'users': the users on the remote system, 'Global Contacts': active contacts that are known on the system. The fallback is meant for Redmatrix servers and older friendica servers, where global contacts weren't available. The fallback increases the server load, so the recommened setting is 'Users, Global Contacts'."), $poco_discovery_choices),
  1110. '$poco_discovery_since' => array('poco_discovery_since', t("Timeframe for fetching global contacts"), (string) intval(Config::get('system','poco_discovery_since')), t("When the discovery is activated, this value defines the timeframe for the activity of the global contacts that are fetched from other servers."), $poco_discovery_since_choices),
  1111. '$poco_local_search' => array('poco_local_search', t("Search the local directory"), Config::get('system','poco_local_search'), t("Search the local directory instead of the global directory. When searching locally, every search will be executed on the global directory in the background. This improves the search results when the search is repeated.")),
  1112. '$nodeinfo' => array('nodeinfo', t("Publish server information"), Config::get('system','nodeinfo'), t("If enabled, general server and usage data will be published. The data contains the name and version of the server, number of users with public profiles, number of posts and the activated protocols and connectors. See <a href='http://the-federation.info/'>the-federation.info</a> for details.")),
  1113. '$check_new_version_url' => array('check_new_version_url', t("Check upstream version"), Config::get('system', 'check_new_version_url'), t("Enables checking for new Friendica versions at github. If there is a new version, you will be informed in the admin panel overview."), $check_git_version_choices),
  1114. '$suppress_tags' => array('suppress_tags', t("Suppress Tags"), Config::get('system','suppress_tags'), t("Suppress showing a list of hashtags at the end of the posting.")),
  1115. '$itemcache' => array('itemcache', t("Path to item cache"), Config::get('system','itemcache'), t("The item caches buffers generated bbcode and external images.")),
  1116. '$itemcache_duration' => array('itemcache_duration', t("Cache duration in seconds"), Config::get('system','itemcache_duration'), t("How long should the cache files be hold? Default value is 86400 seconds (One day). To disable the item cache, set the value to -1.")),
  1117. '$max_comments' => array('max_comments', t("Maximum numbers of comments per post"), Config::get('system','max_comments'), t("How much comments should be shown for each post? Default value is 100.")),
  1118. '$temppath' => array('temppath', t("Temp path"), Config::get('system','temppath'), t("If you have a restricted system where the webserver can't access the system temp path, enter another path here.")),
  1119. '$basepath' => array('basepath', t("Base path to installation"), Config::get('system','basepath'), t("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.")),
  1120. '$proxy_disabled' => array('proxy_disabled', t("Disable picture proxy"), Config::get('system','proxy_disabled'), t("The picture proxy increases performance and privacy. It shouldn't be used on systems with very low bandwith.")),
  1121. '$only_tag_search' => array('only_tag_search', t("Only search in tags"), Config::get('system','only_tag_search'), t("On large systems the text search can slow down the system extremely.")),
  1122. '$relocate_url' => array('relocate_url', t("New base url"), System::baseUrl(), t("Change base url for this server. Sends relocate message to all Friendica and Diaspora* contacts of all users.")),
  1123. '$rino' => array('rino', t("RINO Encryption"), intval(Config::get('system','rino_encrypt')), t("Encryption layer between nodes."), array("Disabled", "RINO1 (deprecated)", "RINO2")),
  1124. '$worker_queues' => array('worker_queues', t("Maximum number of parallel workers"), Config::get('system','worker_queues'), t("On shared hosters set this to 2. On larger systems, values of 10 are great. Default value is 4.")),
  1125. '$worker_dont_fork' => array('worker_dont_fork', t("Don't use 'proc_open' with the worker"), Config::get('system','worker_dont_fork'), t("Enable this if your system doesn't allow the use of 'proc_open'. This can happen on shared hosters. If this is enabled you should increase the frequency of poller calls in your crontab.")),
  1126. '$worker_fastlane' => array('worker_fastlane', t("Enable fastlane"), Config::get('system','worker_fastlane'), t("When enabed, the fastlane mechanism starts an additional worker if processes with higher priority are blocked by processes of lower priority.")),
  1127. '$worker_frontend' => array('worker_frontend', t('Enable frontend worker'), Config::get('system','frontend_worker'), sprintf(t('When enabled the Worker process is triggered when backend access is performed (e.g. messages being delivered). On smaller sites you might want to call %s/worker on a regular basis via an external cron job. You should only enable this option if you cannot utilize cron/scheduled jobs on your server.'), System::baseUrl())),
  1128. '$form_security_token' => get_form_security_token("admin_site")
  1129. ));
  1130. }
  1131. /**
  1132. * @brief Generates admin panel subpage for DB syncronization
  1133. *
  1134. * This page checks if the database of friendica is in sync with the specs.
  1135. * Should this not be the case, it attemps to sync the structure and notifies
  1136. * the admin if the automatic process was failing.
  1137. *
  1138. * The returned string holds the HTML code of the page.
  1139. *
  1140. * @param App $a
  1141. * @return string
  1142. **/
  1143. function admin_page_dbsync(App $a) {
  1144. $o = '';
  1145. if ($a->argc > 3 && intval($a->argv[3]) && $a->argv[2] === 'mark') {
  1146. Config::set('database', 'update_'.intval($a->argv[3]), 'success');
  1147. $curr = Config::get('system','build');
  1148. if (intval($curr) == intval($a->argv[3])) {
  1149. Config::set('system','build',intval($curr) + 1);
  1150. }
  1151. info(t('Update has been marked successful').EOL);
  1152. goaway('admin/dbsync');
  1153. }
  1154. if (($a->argc > 2) && (intval($a->argv[2]) || ($a->argv[2] === 'check'))) {
  1155. require_once("include/dbstructure.php");
  1156. $retval = update_structure(false, true);
  1157. if (!$retval) {
  1158. $o .= sprintf(t("Database structure update %s was successfully applied."), DB_UPDATE_VERSION)."<br />";
  1159. Config::set('database', 'dbupdate_'.DB_UPDATE_VERSION, 'success');
  1160. } else {
  1161. $o .= sprintf(t("Executing of database structure update %s failed with error: %s"),
  1162. DB_UPDATE_VERSION, $retval)."<br />";
  1163. }
  1164. if ($a->argv[2] === 'check') {
  1165. return $o;
  1166. }
  1167. }
  1168. if ($a->argc > 2 && intval($a->argv[2])) {
  1169. require_once('update.php');
  1170. $func = 'update_'.intval($a->argv[2]);
  1171. if (function_exists($func)) {
  1172. $retval = $func();
  1173. if ($retval === UPDATE_FAILED) {
  1174. $o .= sprintf(t("Executing %s failed with error: %s"), $func, $retval);
  1175. }
  1176. elseif ($retval === UPDATE_SUCCESS) {
  1177. $o .= sprintf(t('Update %s was successfully applied.', $func));
  1178. Config::set('database',$func, 'success');
  1179. } else {
  1180. $o .= sprintf(t('Update %s did not return a status. Unknown if it succeeded.'), $func);
  1181. }
  1182. } else {
  1183. $o .= sprintf(t('There was no additional update function %s that needed to be called.'), $func)."<br />";
  1184. Config::set('database',$func, 'success');
  1185. }
  1186. return $o;
  1187. }
  1188. $failed = array();
  1189. $r = q("SELECT `k`, `v` FROM `config` WHERE `cat` = 'database' ");
  1190. if (dbm::is_result($r)) {
  1191. foreach ($r as $rr) {
  1192. $upd = intval(substr($rr['k'],7));
  1193. if ($upd < 1139 || $rr['v'] === 'success') {
  1194. continue;
  1195. }
  1196. $failed[] = $upd;
  1197. }
  1198. }
  1199. if (! count($failed)) {
  1200. $o = replace_macros(get_markup_template('structure_check.tpl'),array(
  1201. '$base' => System::baseUrl(true),
  1202. '$banner' => t('No failed updates.'),
  1203. '$check' => t('Check database structure'),
  1204. ));
  1205. } else {
  1206. $o = replace_macros(get_markup_template('failed_updates.tpl'),array(
  1207. '$base' => System::baseUrl(true),
  1208. '$banner' => t('Failed Updates'),
  1209. '$desc' => t('This does not include updates prior to 1139, which did not return a status.'),
  1210. '$mark' => t('Mark success (if update was manually applied)'),
  1211. '$apply' => t('Attempt to execute this update step automatically'),
  1212. '$failed' => $failed
  1213. ));
  1214. }
  1215. return $o;
  1216. }
  1217. /**
  1218. * @brief Process data send by Users admin page
  1219. *
  1220. * @param App $a
  1221. */
  1222. function admin_page_users_post(App $a) {
  1223. $pending = (x($_POST, 'pending') ? $_POST['pending'] : array());
  1224. $users = (x($_POST, 'user') ? $_POST['user'] : array());
  1225. $nu_name = (x($_POST, 'new_user_name') ? $_POST['new_user_name'] : '');
  1226. $nu_nickname = (x($_POST, 'new_user_nickname') ? $_POST['new_user_nickname'] : '');
  1227. $nu_email = (x($_POST, 'new_user_email') ? $_POST['new_user_email'] : '');
  1228. $nu_language = Config::get('system', 'language');
  1229. check_form_security_token_redirectOnErr('/admin/users', 'admin_users');
  1230. if (!($nu_name === "") && !($nu_email === "") && !($nu_nickname === "")) {
  1231. require_once('include/user.php');
  1232. $result = create_user(array('username'=>$nu_name, 'email'=>$nu_email,
  1233. 'nickname'=>$nu_nickname, 'verified'=>1, 'language'=>$nu_language));
  1234. if (! $result['success']) {
  1235. notice($result['message']);
  1236. return;
  1237. }
  1238. $nu = $result['user'];
  1239. $preamble = deindent(t('
  1240. Dear %1$s,
  1241. the administrator of %2$s has set up an account for you.'));
  1242. $body = deindent(t('
  1243. The login details are as follows:
  1244. Site Location: %1$s
  1245. Login Name: %2$s
  1246. Password: %3$s
  1247. You may change your password from your account "Settings" page after logging
  1248. in.
  1249. Please take a few moments to review the other account settings on that page.
  1250. You may also wish to add some basic information to your default profile
  1251. (on the "Profiles" page) so that other people can easily find you.
  1252. We recommend setting your full name, adding a profile photo,
  1253. adding some profile "keywords" (very useful in making new friends) - and
  1254. perhaps what country you live in; if you do not wish to be more specific
  1255. than that.
  1256. We fully respect your right to privacy, and none of these items are necessary.
  1257. If you are new and do not know anybody here, they may help
  1258. you to make some new and interesting friends.
  1259. Thank you and welcome to %4$s.'));
  1260. $preamble = sprintf($preamble, $nu['username'], $a->config['sitename']);
  1261. $body = sprintf($body, System::baseUrl(), $nu['email'], $result['password'], $a->config['sitename']);
  1262. notification(array(
  1263. 'type' => SYSTEM_EMAIL,
  1264. 'to_email' => $nu['email'],
  1265. 'subject'=> sprintf(t('Registration details for %s'), $a->config['sitename']),
  1266. 'preamble'=> $preamble,
  1267. 'body' => $body));
  1268. }
  1269. if (x($_POST,'page_users_block')) {
  1270. foreach ($users as $uid) {
  1271. q("UPDATE `user` SET `blocked` = 1-`blocked` WHERE `uid` = %s",
  1272. intval($uid)
  1273. );
  1274. }
  1275. notice(sprintf(tt("%s user blocked/unblocked", "%s users blocked/unblocked", count($users)), count($users)));
  1276. }
  1277. if (x($_POST,'page_users_delete')) {
  1278. require_once("include/Contact.php");
  1279. foreach ($users as $uid) {
  1280. user_remove($uid);
  1281. }
  1282. notice(sprintf(tt("%s user deleted", "%s users deleted", count($users)), count($users)));
  1283. }
  1284. if (x($_POST,'page_users_approve')) {
  1285. require_once("mod/regmod.php");
  1286. foreach ($pending as $hash) {
  1287. user_allow($hash);
  1288. }
  1289. }
  1290. if (x($_POST,'page_users_deny')) {
  1291. require_once("mod/regmod.php");
  1292. foreach ($pending as $hash) {
  1293. user_deny($hash);
  1294. }
  1295. }
  1296. goaway('admin/users');
  1297. return; // NOTREACHED
  1298. }
  1299. /**
  1300. * @brief Admin panel subpage for User management
  1301. *
  1302. * This function generates the admin panel page for user management of the
  1303. * node. It offers functionality to add/block/delete users and offers some
  1304. * statistics about the userbase.
  1305. *
  1306. * The returned string holds the HTML code of the page.
  1307. *
  1308. * @param App $a
  1309. * @return string
  1310. */
  1311. function admin_page_users(App $a) {
  1312. if ($a->argc>2) {
  1313. $uid = $a->argv[3];
  1314. $user = q("SELECT `username`, `blocked` FROM `user` WHERE `uid` = %d", intval($uid));
  1315. if (count($user) == 0) {
  1316. notice('User not found'.EOL);
  1317. goaway('admin/users');
  1318. return ''; // NOTREACHED
  1319. }
  1320. switch($a->argv[2]) {
  1321. case "delete":
  1322. check_form_security_token_redirectOnErr('/admin/users', 'admin_users', 't');
  1323. // delete user
  1324. require_once("include/Contact.php");
  1325. user_remove($uid);
  1326. notice(sprintf(t("User '%s' deleted"), $user[0]['username']).EOL);
  1327. break;
  1328. case "block":
  1329. check_form_security_token_redirectOnErr('/admin/users', 'admin_users', 't');
  1330. q("UPDATE `user` SET `blocked` = %d WHERE `uid` = %s",
  1331. intval(1-$user[0]['blocked']),
  1332. intval($uid)
  1333. );
  1334. notice(sprintf(($user[0]['blocked']?t("User '%s' unblocked"):t("User '%s' blocked")) , $user[0]['username']).EOL);
  1335. break;
  1336. }
  1337. goaway('admin/users');
  1338. return ''; // NOTREACHED
  1339. }
  1340. /* get pending */
  1341. $pending = q("SELECT `register`.*, `contact`.`name`, `user`.`email`
  1342. FROM `register`
  1343. LEFT JOIN `contact` ON `register`.`uid` = `contact`.`uid`
  1344. LEFT JOIN `user` ON `register`.`uid` = `user`.`uid`;");
  1345. /* get users */
  1346. $total = q("SELECT COUNT(*) AS `total` FROM `user` WHERE 1");
  1347. if (count($total)) {
  1348. $a->set_pager_total($total[0]['total']);
  1349. $a->set_pager_itemspage(100);
  1350. }
  1351. /* ordering */
  1352. $valid_orders = array(
  1353. 'contact.name',
  1354. 'user.email',
  1355. 'user.register_date',
  1356. 'user.login_date',
  1357. 'lastitem_date',
  1358. 'user.page-flags'
  1359. );
  1360. $order = "contact.name";
  1361. $order_direction = "+";
  1362. if (x($_GET,'o')) {
  1363. $new_order = $_GET['o'];
  1364. if ($new_order[0] === "-") {
  1365. $order_direction = "-";
  1366. $new_order = substr($new_order,1);
  1367. }
  1368. if (in_array($new_order, $valid_orders)) {
  1369. $order = $new_order;
  1370. }
  1371. if (x($_GET,'d')) {
  1372. $new_direction = $_GET['d'];
  1373. }
  1374. }
  1375. $sql_order = "`".str_replace('.','`.`',$order)."`";
  1376. $sql_order_direction = ($order_direction === "+")?"ASC":"DESC";
  1377. $users = q("SELECT `user`.*, `contact`.`name`, `contact`.`url`, `contact`.`micro`, `user`.`account_expired`, `contact`.`last-item` AS `lastitem_date`
  1378. FROM `user`
  1379. INNER JOIN `contact` ON `contact`.`uid` = `user`.`uid` AND `contact`.`self`
  1380. WHERE `user`.`verified`
  1381. ORDER BY $sql_order $sql_order_direction LIMIT %d, %d",
  1382. intval($a->pager['start']),
  1383. intval($a->pager['itemspage'])
  1384. );
  1385. //echo "<pre>$users"; killme();
  1386. $adminlist = explode(",", str_replace(" ", "", $a->config['admin_email']));
  1387. $_setup_users = function ($e) use ($adminlist) {
  1388. $accounts = array(
  1389. t('Normal Account'),
  1390. t('Automatic Follower Account'),
  1391. t('Public Forum Account'),
  1392. t('Automatic Friend Account')
  1393. );
  1394. $e['page-flags'] = $accounts[$e['page-flags']];
  1395. $e['register_date'] = relative_date($e['register_date']);
  1396. $e['login_date'] = relative_date($e['login_date']);
  1397. $e['lastitem_date'] = relative_date($e['lastitem_date']);
  1398. //$e['is_admin'] = ($e['email'] === $a->config['admin_email']);
  1399. $e['is_admin'] = in_array($e['email'], $adminlist);
  1400. $e['is_deletable'] = (intval($e['uid']) != local_user());
  1401. $e['deleted'] = ($e['account_removed']?relative_date($e['account_expires_on']):False);
  1402. return $e;
  1403. };
  1404. $users = array_map($_setup_users, $users);
  1405. // Get rid of dashes in key names, Smarty3 can't handle them
  1406. // and extracting deleted users
  1407. $tmp_users = array();
  1408. $deleted = array();
  1409. while (count($users)) {
  1410. $new_user = array();
  1411. foreach (array_pop($users) as $k => $v) {
  1412. $k = str_replace('-','_',$k);
  1413. $new_user[$k] = $v;
  1414. }
  1415. if ($new_user['deleted']) {
  1416. array_push($deleted, $new_user);
  1417. } else {
  1418. array_push($tmp_users, $new_user);
  1419. }
  1420. }
  1421. //Reversing the two array, and moving $tmp_users to $users
  1422. array_reverse($deleted);
  1423. while (count($tmp_users)) {
  1424. array_push($users, array_pop($tmp_users));
  1425. }
  1426. $th_users = array_map(null,
  1427. array(t('Name'), t('Email'), t('Register date'), t('Last login'), t('Last item'), t('Account')),
  1428. $valid_orders
  1429. );
  1430. $t = get_markup_template("admin_users.tpl");
  1431. $o = replace_macros($t, array(
  1432. // strings //
  1433. '$title' => t('Administration'),
  1434. '$page' => t('Users'),
  1435. '$submit' => t('Add User'),
  1436. '$select_all' => t('select all'),
  1437. '$h_pending' => t('User registrations waiting for confirm'),
  1438. '$h_deleted' => t('User waiting for permanent deletion'),
  1439. '$th_pending' => array(t('Request date'), t('Name'), t('Email')),
  1440. '$no_pending' => t('No registrations.'),
  1441. '$pendingnotetext' => t('Note from the user'),
  1442. '$approve' => t('Approve'),
  1443. '$deny' => t('Deny'),
  1444. '$delete' => t('Delete'),
  1445. '$block' => t('Block'),
  1446. '$unblock' => t('Unblock'),
  1447. '$siteadmin' => t('Site admin'),
  1448. '$accountexpired' => t('Account expired'),
  1449. '$h_users' => t('Users'),
  1450. '$h_newuser' => t('New User'),
  1451. '$th_deleted' => array(t('Name'), t('Email'), t('Register date'), t('Last login'), t('Last item'), t('Deleted since')),
  1452. '$th_users' => $th_users,
  1453. '$order_users' => $order,
  1454. '$order_direction_users' => $order_direction,
  1455. '$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?'),
  1456. '$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?'),
  1457. '$form_security_token' => get_form_security_token("admin_users"),
  1458. // values //
  1459. '$baseurl' => System::baseUrl(true),
  1460. '$pending' => $pending,
  1461. 'deleted' => $deleted,
  1462. '$users' => $users,
  1463. '$newusername' => array('new_user_name', t("Name"), '', t("Name of the new user.")),
  1464. '$newusernickname' => array('new_user_nickname', t("Nickname"), '', t("Nickname of the new user.")),
  1465. '$newuseremail' => array('new_user_email', t("Email"), '', t("Email address of the new user."), '', '', 'email'),
  1466. ));
  1467. $o .= paginate($a);
  1468. return $o;
  1469. }
  1470. /**
  1471. * @brief Plugins admin page
  1472. *
  1473. * This function generates the admin panel page for managing plugins on the
  1474. * friendica node. If a plugin name is given a single page showing the details
  1475. * for this addon is generated. If no name is given, a list of available
  1476. * plugins is shown.
  1477. *
  1478. * The template used for displaying the list of plugins and the details of the
  1479. * plugin are the same as used for the templates.
  1480. *
  1481. * The returned string returned hulds the HTML code of the page.
  1482. *
  1483. * @param App $a
  1484. * @return string
  1485. */
  1486. function admin_page_plugins(App $a) {
  1487. /*
  1488. * Single plugin
  1489. */
  1490. if ($a->argc == 3) {
  1491. $plugin = $a->argv[2];
  1492. if (!is_file("addon/$plugin/$plugin.php")) {
  1493. notice(t("Item not found."));
  1494. return '';
  1495. }
  1496. if (x($_GET,"a") && $_GET['a']=="t") {
  1497. check_form_security_token_redirectOnErr('/admin/plugins', 'admin_themes', 't');
  1498. // Toggle plugin status
  1499. $idx = array_search($plugin, $a->plugins);
  1500. if ($idx !== false) {
  1501. unset($a->plugins[$idx]);
  1502. uninstall_plugin($plugin);
  1503. info(sprintf(t("Plugin %s disabled."), $plugin));
  1504. } else {
  1505. $a->plugins[] = $plugin;
  1506. install_plugin($plugin);
  1507. info(sprintf(t("Plugin %s enabled."), $plugin));
  1508. }
  1509. Config::set("system","addon", implode(", ",$a->plugins));
  1510. goaway('admin/plugins');
  1511. return ''; // NOTREACHED
  1512. }
  1513. // display plugin details
  1514. require_once('library/markdown.php');
  1515. if (in_array($plugin, $a->plugins)) {
  1516. $status="on"; $action= t("Disable");
  1517. } else {
  1518. $status="off"; $action= t("Enable");
  1519. }
  1520. $readme=Null;
  1521. if (is_file("addon/$plugin/README.md")) {
  1522. $readme = file_get_contents("addon/$plugin/README.md");
  1523. $readme = Markdown($readme, false);
  1524. } elseif (is_file("addon/$plugin/README")) {
  1525. $readme = "<pre>". file_get_contents("addon/$plugin/README") ."</pre>";
  1526. }
  1527. $admin_form="";
  1528. if (is_array($a->plugins_admin) && in_array($plugin, $a->plugins_admin)) {
  1529. @require_once("addon/$plugin/$plugin.php");
  1530. $func = $plugin.'_plugin_admin';
  1531. $func($a, $admin_form);
  1532. }
  1533. $t = get_markup_template("admin_plugins_details.tpl");
  1534. return replace_macros($t, array(
  1535. '$title' => t('Administration'),
  1536. '$page' => t('Plugins'),
  1537. '$toggle' => t('Toggle'),
  1538. '$settings' => t('Settings'),
  1539. '$baseurl' => System::baseUrl(true),
  1540. '$plugin' => $plugin,
  1541. '$status' => $status,
  1542. '$action' => $action,
  1543. '$info' => get_plugin_info($plugin),
  1544. '$str_author' => t('Author: '),
  1545. '$str_maintainer' => t('Maintainer: '),
  1546. '$admin_form' => $admin_form,
  1547. '$function' => 'plugins',
  1548. '$screenshot' => '',
  1549. '$readme' => $readme,
  1550. '$form_security_token' => get_form_security_token("admin_themes"),
  1551. ));
  1552. }
  1553. /*
  1554. * List plugins
  1555. */
  1556. if (x($_GET,"a") && $_GET['a']=="r") {
  1557. check_form_security_token_redirectOnErr(System::baseUrl().'/admin/plugins', 'admin_themes', 't');
  1558. reload_plugins();
  1559. info("Plugins reloaded");
  1560. goaway(System::baseUrl().'/admin/plugins');
  1561. }
  1562. $plugins = array();
  1563. $files = glob("addon/*/");
  1564. if ($files) {
  1565. foreach ($files as $file) {
  1566. if (is_dir($file)) {
  1567. list($tmp, $id)=array_map("trim", explode("/",$file));
  1568. $info = get_plugin_info($id);
  1569. $show_plugin = true;
  1570. // If the addon is unsupported, then only show it, when it is enabled
  1571. if ((strtolower($info["status"]) == "unsupported") && !in_array($id, $a->plugins)) {
  1572. $show_plugin = false;
  1573. }
  1574. // Override the above szenario, when the admin really wants to see outdated stuff
  1575. if (Config::get("system", "show_unsupported_addons")) {
  1576. $show_plugin = true;
  1577. }
  1578. if ($show_plugin) {
  1579. $plugins[] = array($id, (in_array($id, $a->plugins)?"on":"off") , $info);
  1580. }
  1581. }
  1582. }
  1583. }
  1584. $t = get_markup_template("admin_plugins.tpl");
  1585. return replace_macros($t, array(
  1586. '$title' => t('Administration'),
  1587. '$page' => t('Plugins'),
  1588. '$submit' => t('Save Settings'),
  1589. '$reload' => t('Reload active plugins'),
  1590. '$baseurl' => System::baseUrl(true),
  1591. '$function' => 'plugins',
  1592. '$plugins' => $plugins,
  1593. '$pcount' => count($plugins),
  1594. '$noplugshint' => sprintf(t('There are currently no plugins available on your node. You can find the official plugin repository at %1$s and might find other interesting plugins in the open plugin registry at %2$s'), 'https://github.com/friendica/friendica-addons', 'http://addons.friendi.ca'),
  1595. '$form_security_token' => get_form_security_token("admin_themes"),
  1596. ));
  1597. }
  1598. /**
  1599. * @param array $themes
  1600. * @param string $th
  1601. * @param int $result
  1602. */
  1603. function toggle_theme(&$themes,$th,&$result) {
  1604. for($x = 0; $x < count($themes); $x ++) {
  1605. if ($themes[$x]['name'] === $th) {
  1606. if ($themes[$x]['allowed']) {
  1607. $themes[$x]['allowed'] = 0;
  1608. $result = 0;
  1609. }
  1610. else {
  1611. $themes[$x]['allowed'] = 1;
  1612. $result = 1;
  1613. }
  1614. }
  1615. }
  1616. }
  1617. /**
  1618. * @param array $themes
  1619. * @param string $th
  1620. * @return int
  1621. */
  1622. function theme_status($themes,$th) {
  1623. for($x = 0; $x < count($themes); $x ++) {
  1624. if ($themes[$x]['name'] === $th) {
  1625. if ($themes[$x]['allowed']) {
  1626. return 1;
  1627. }
  1628. else {
  1629. return 0;
  1630. }
  1631. }
  1632. }
  1633. return 0;
  1634. }
  1635. /**
  1636. * @param array $themes
  1637. * @return string
  1638. */
  1639. function rebuild_theme_table($themes) {
  1640. $o = '';
  1641. if (count($themes)) {
  1642. foreach ($themes as $th) {
  1643. if ($th['allowed']) {
  1644. if (strlen($o)) {
  1645. $o .= ',';
  1646. }
  1647. $o .= $th['name'];
  1648. }
  1649. }
  1650. }
  1651. return $o;
  1652. }
  1653. /**
  1654. * @brief Themes admin page
  1655. *
  1656. * This function generates the admin panel page to control the themes available
  1657. * on the friendica node. If the name of a theme is given as parameter a page
  1658. * with the details for the theme is shown. Otherwise a list of available
  1659. * themes is generated.
  1660. *
  1661. * The template used for displaying the list of themes and the details of the
  1662. * themes are the same as used for the plugins.
  1663. *
  1664. * The returned string contains the HTML code of the admin panel page.
  1665. *
  1666. * @param App $a
  1667. * @return string
  1668. */
  1669. function admin_page_themes(App $a) {
  1670. $allowed_themes_str = Config::get('system','allowed_themes');
  1671. $allowed_themes_raw = explode(',',$allowed_themes_str);
  1672. $allowed_themes = array();
  1673. if (count($allowed_themes_raw)) {
  1674. foreach ($allowed_themes_raw as $x) {
  1675. if (strlen(trim($x))) {
  1676. $allowed_themes[] = trim($x);
  1677. }
  1678. }
  1679. }
  1680. $themes = array();
  1681. $files = glob('view/theme/*');
  1682. if ($files) {
  1683. foreach ($files as $file) {
  1684. $f = basename($file);
  1685. // Is there a style file?
  1686. $theme_files = glob('view/theme/'.$f.'/style.*');
  1687. // If not then quit
  1688. if (count($theme_files) == 0) {
  1689. continue;
  1690. }
  1691. $is_experimental = intval(file_exists($file.'/experimental'));
  1692. $is_supported = 1-(intval(file_exists($file.'/unsupported')));
  1693. $is_allowed = intval(in_array($f,$allowed_themes));
  1694. if ($is_allowed || $is_supported || Config::get("system", "show_unsupported_themes")) {
  1695. $themes[] = array('name' => $f, 'experimental' => $is_experimental, 'supported' => $is_supported, 'allowed' => $is_allowed);
  1696. }
  1697. }
  1698. }
  1699. if (! count($themes)) {
  1700. notice(t('No themes found.'));
  1701. return '';
  1702. }
  1703. /*
  1704. * Single theme
  1705. */
  1706. if ($a->argc == 3) {
  1707. $theme = $a->argv[2];
  1708. if (! is_dir("view/theme/$theme")) {
  1709. notice(t("Item not found."));
  1710. return '';
  1711. }
  1712. if (x($_GET,"a") && $_GET['a']=="t") {
  1713. check_form_security_token_redirectOnErr('/admin/themes', 'admin_themes', 't');
  1714. // Toggle theme status
  1715. toggle_theme($themes,$theme,$result);
  1716. $s = rebuild_theme_table($themes);
  1717. if ($result) {
  1718. install_theme($theme);
  1719. info(sprintf('Theme %s enabled.',$theme));
  1720. } else {
  1721. uninstall_theme($theme);
  1722. info(sprintf('Theme %s disabled.',$theme));
  1723. }
  1724. Config::set('system','allowed_themes',$s);
  1725. goaway('admin/themes');
  1726. return ''; // NOTREACHED
  1727. }
  1728. // display theme details
  1729. require_once('library/markdown.php');
  1730. if (theme_status($themes,$theme)) {
  1731. $status="on"; $action= t("Disable");
  1732. } else {
  1733. $status="off"; $action= t("Enable");
  1734. }
  1735. $readme = Null;
  1736. if (is_file("view/theme/$theme/README.md")) {
  1737. $readme = file_get_contents("view/theme/$theme/README.md");
  1738. $readme = Markdown($readme, false);
  1739. } elseif (is_file("view/theme/$theme/README")) {
  1740. $readme = "<pre>". file_get_contents("view/theme/$theme/README") ."</pre>";
  1741. }
  1742. $admin_form = "";
  1743. if (is_file("view/theme/$theme/config.php")) {
  1744. function __get_theme_admin_form(App $a, $theme) {
  1745. $orig_theme = $a->theme;
  1746. $orig_page = $a->page;
  1747. $orig_session_theme = $_SESSION['theme'];
  1748. require_once("view/theme/$theme/theme.php");
  1749. require_once("view/theme/$theme/config.php");
  1750. $_SESSION['theme'] = $theme;
  1751. $init = $theme."_init";
  1752. if (function_exists($init)) {
  1753. $init($a);
  1754. }
  1755. if (function_exists("theme_admin")) {
  1756. $admin_form = theme_admin($a);
  1757. }
  1758. $_SESSION['theme'] = $orig_session_theme;
  1759. $a->theme = $orig_theme;
  1760. $a->page = $orig_page;
  1761. return $admin_form;
  1762. }
  1763. $admin_form = __get_theme_admin_form($a, $theme);
  1764. }
  1765. $screenshot = array(get_theme_screenshot($theme), t('Screenshot'));
  1766. if (! stristr($screenshot[0],$theme)) {
  1767. $screenshot = null;
  1768. }
  1769. $t = get_markup_template("admin_plugins_details.tpl");
  1770. return replace_macros($t, array(
  1771. '$title' => t('Administration'),
  1772. '$page' => t('Themes'),
  1773. '$toggle' => t('Toggle'),
  1774. '$settings' => t('Settings'),
  1775. '$baseurl' => System::baseUrl(true),
  1776. '$plugin' => $theme,
  1777. '$status' => $status,
  1778. '$action' => $action,
  1779. '$info' => get_theme_info($theme),
  1780. '$function' => 'themes',
  1781. '$admin_form' => $admin_form,
  1782. '$str_author' => t('Author: '),
  1783. '$str_maintainer' => t('Maintainer: '),
  1784. '$screenshot' => $screenshot,
  1785. '$readme' => $readme,
  1786. '$form_security_token' => get_form_security_token("admin_themes"),
  1787. ));
  1788. }
  1789. // reload active themes
  1790. if (x($_GET,"a") && $_GET['a']=="r") {
  1791. check_form_security_token_redirectOnErr(System::baseUrl().'/admin/themes', 'admin_themes', 't');
  1792. if ($themes) {
  1793. foreach ($themes as $th) {
  1794. if ($th['allowed']) {
  1795. uninstall_theme($th['name']);
  1796. install_theme($th['name']);
  1797. }
  1798. }
  1799. }
  1800. info("Themes reloaded");
  1801. goaway(System::baseUrl().'/admin/themes');
  1802. }
  1803. /*
  1804. * List themes
  1805. */
  1806. $xthemes = array();
  1807. if ($themes) {
  1808. foreach ($themes as $th) {
  1809. $xthemes[] = array($th['name'],(($th['allowed']) ? "on" : "off"), get_theme_info($th['name']));
  1810. }
  1811. }
  1812. $t = get_markup_template("admin_plugins.tpl");
  1813. return replace_macros($t, array(
  1814. '$title' => t('Administration'),
  1815. '$page' => t('Themes'),
  1816. '$submit' => t('Save Settings'),
  1817. '$reload' => t('Reload active themes'),
  1818. '$baseurl' => System::baseUrl(true),
  1819. '$function' => 'themes',
  1820. '$plugins' => $xthemes,
  1821. '$pcount' => count($themes),
  1822. '$noplugshint' => sprintf(t('No themes found on the system. They should be paced in %1$s'),'<code>/view/themes</code>'),
  1823. '$experimental' => t('[Experimental]'),
  1824. '$unsupported' => t('[Unsupported]'),
  1825. '$form_security_token' => get_form_security_token("admin_themes"),
  1826. ));
  1827. }
  1828. /**
  1829. * @brief Prosesses data send by Logs admin page
  1830. *
  1831. * @param App $a
  1832. */
  1833. function admin_page_logs_post(App $a) {
  1834. if (x($_POST,"page_logs")) {
  1835. check_form_security_token_redirectOnErr('/admin/logs', 'admin_logs');
  1836. $logfile = ((x($_POST,'logfile')) ? notags(trim($_POST['logfile'])) : '');
  1837. $debugging = ((x($_POST,'debugging')) ? true : false);
  1838. $loglevel = ((x($_POST,'loglevel')) ? intval(trim($_POST['loglevel'])) : 0);
  1839. Config::set('system','logfile', $logfile);
  1840. Config::set('system','debugging', $debugging);
  1841. Config::set('system','loglevel', $loglevel);
  1842. }
  1843. info(t("Log settings updated."));
  1844. goaway('admin/logs');
  1845. return; // NOTREACHED
  1846. }
  1847. /**
  1848. * @brief Generates admin panel subpage for configuration of the logs
  1849. *
  1850. * This function take the view/templates/admin_logs.tpl file and generates a
  1851. * page where admin can configure the logging of friendica.
  1852. *
  1853. * Displaying the log is separated from the log config as the logfile can get
  1854. * big depending on the settings and changing settings regarding the logs can
  1855. * thus waste bandwidth.
  1856. *
  1857. * The string returned contains the content of the template file with replaced
  1858. * macros.
  1859. *
  1860. * @param App $a
  1861. * @return string
  1862. */
  1863. function admin_page_logs(App $a) {
  1864. $log_choices = array(
  1865. LOGGER_NORMAL => 'Normal',
  1866. LOGGER_TRACE => 'Trace',
  1867. LOGGER_DEBUG => 'Debug',
  1868. LOGGER_DATA => 'Data',
  1869. LOGGER_ALL => 'All'
  1870. );
  1871. if (ini_get('log_errors')) {
  1872. $phplogenabled = t('PHP log currently enabled.');
  1873. } else {
  1874. $phplogenabled = t('PHP log currently disabled.');
  1875. }
  1876. $t = get_markup_template("admin_logs.tpl");
  1877. return replace_macros($t, array(
  1878. '$title' => t('Administration'),
  1879. '$page' => t('Logs'),
  1880. '$submit' => t('Save Settings'),
  1881. '$clear' => t('Clear'),
  1882. '$baseurl' => System::baseUrl(true),
  1883. '$logname' => Config::get('system','logfile'),
  1884. // name, label, value, help string, extra data...
  1885. '$debugging' => array('debugging', t("Enable Debugging"),Config::get('system','debugging'), ""),
  1886. '$logfile' => array('logfile', t("Log file"), Config::get('system','logfile'), t("Must be writable by web server. Relative to your Friendica top-level directory.")),
  1887. '$loglevel' => array('loglevel', t("Log level"), Config::get('system','loglevel'), "", $log_choices),
  1888. '$form_security_token' => get_form_security_token("admin_logs"),
  1889. '$phpheader' => t("PHP logging"),
  1890. '$phphint' => t("To enable logging of PHP errors and warnings you can add the following to the .htconfig.php file of your installation. The filename set in the 'error_log' line is relative to the friendica top-level directory and must be writeable by the web server. The option '1' for 'log_errors' and 'display_errors' is to enable these options, set to '0' to disable them."),
  1891. '$phplogcode' => "error_reporting(E_ERROR | E_WARNING | E_PARSE);\nini_set('error_log','php.out');\nini_set('log_errors','1');\nini_set('display_errors', '1');",
  1892. '$phplogenabled' => $phplogenabled,
  1893. ));
  1894. }
  1895. /**
  1896. * @brief Generates admin panel subpage to view the Friendica log
  1897. *
  1898. * This function loads the template view/templates/admin_viewlogs.tpl to
  1899. * display the systemlog content. The filename for the systemlog of friendica
  1900. * is relative to the base directory and taken from the config entry 'logfile'
  1901. * in the 'system' category.
  1902. *
  1903. * Displaying the log is separated from the log config as the logfile can get
  1904. * big depending on the settings and changing settings regarding the logs can
  1905. * thus waste bandwidth.
  1906. *
  1907. * The string returned contains the content of the template file with replaced
  1908. * macros.
  1909. *
  1910. * @param App $a
  1911. * @return string
  1912. */
  1913. function admin_page_viewlogs(App $a) {
  1914. $t = get_markup_template("admin_viewlogs.tpl");
  1915. $f = Config::get('system','logfile');
  1916. $data = '';
  1917. if (!file_exists($f)) {
  1918. $data = t("Error trying to open <strong>$f</strong> log file.\r\n<br/>Check to see if file $f exist and is readable.");
  1919. } else {
  1920. $fp = fopen($f, 'r');
  1921. if (!$fp) {
  1922. $data = t("Couldn't open <strong>$f</strong> log file.\r\n<br/>Check to see if file $f is readable.");
  1923. } else {
  1924. $fstat = fstat($fp);
  1925. $size = $fstat['size'];
  1926. if ($size != 0) {
  1927. if ($size > 5000000 || $size < 0) {
  1928. $size = 5000000;
  1929. }
  1930. $seek = fseek($fp,0-$size,SEEK_END);
  1931. if ($seek === 0) {
  1932. $data = escape_tags(fread($fp,$size));
  1933. while (! feof($fp)) {
  1934. $data .= escape_tags(fread($fp,4096));
  1935. }
  1936. }
  1937. }
  1938. fclose($fp);
  1939. }
  1940. }
  1941. return replace_macros($t, array(
  1942. '$title' => t('Administration'),
  1943. '$page' => t('View Logs'),
  1944. '$data' => $data,
  1945. '$logname' => Config::get('system','logfile')
  1946. ));
  1947. }
  1948. /**
  1949. * @brief Prosesses data send by the features admin page
  1950. *
  1951. * @param App $a
  1952. */
  1953. function admin_page_features_post(App $a) {
  1954. check_form_security_token_redirectOnErr('/admin/features', 'admin_manage_features');
  1955. logger('postvars: '.print_r($_POST,true),LOGGER_DATA);
  1956. $arr = array();
  1957. $features = get_features(false);
  1958. foreach ($features as $fname => $fdata) {
  1959. foreach (array_slice($fdata, 1) as $f) {
  1960. $feature = $f[0];
  1961. $feature_state = 'feature_' . $feature;
  1962. $featurelock = 'featurelock_' . $feature;
  1963. if (x($_POST, $feature_state)) {
  1964. $val = intval($_POST[$feature_state]);
  1965. } else {
  1966. $val = 0;
  1967. }
  1968. Config::set('feature',$feature,$val);
  1969. if (x($_POST, $featurelock)) {
  1970. Config::set('feature_lock', $feature, $val);
  1971. } else {
  1972. Config::delete('feature_lock', $feature);
  1973. }
  1974. }
  1975. }
  1976. goaway('admin/features');
  1977. return; // NOTREACHED
  1978. }
  1979. /**
  1980. * @brief Subpage for global additional feature management
  1981. *
  1982. * This functin generates the subpage 'Manage Additional Features'
  1983. * for the admin panel. At this page the admin can set preferences
  1984. * for the user settings of the 'additional features'. If needed this
  1985. * preferences can be locked through the admin.
  1986. *
  1987. * The returned string contains the HTML code of the subpage 'Manage
  1988. * Additional Features'
  1989. *
  1990. * @param App $a
  1991. * @return string
  1992. */
  1993. function admin_page_features(App $a) {
  1994. if ((argc() > 1) && (argv(1) === 'features')) {
  1995. $arr = array();
  1996. $features = get_features(false);
  1997. foreach ($features as $fname => $fdata) {
  1998. $arr[$fname] = array();
  1999. $arr[$fname][0] = $fdata[0];
  2000. foreach (array_slice($fdata,1) as $f) {
  2001. $set = Config::get('feature',$f[0], $f[3]);
  2002. $arr[$fname][1][] = array(
  2003. array('feature_' .$f[0],$f[1],$set,$f[2],array(t('Off'), t('On'))),
  2004. array('featurelock_' .$f[0],sprintf(t('Lock feature %s'),$f[1]),(($f[4] !== false) ? "1" : ''),'',array(t('Off'), t('On')))
  2005. );
  2006. }
  2007. }
  2008. $tpl = get_markup_template("admin_settings_features.tpl");
  2009. $o .= replace_macros($tpl, array(
  2010. '$form_security_token' => get_form_security_token("admin_manage_features"),
  2011. '$title' => t('Manage Additional Features'),
  2012. '$features' => $arr,
  2013. '$submit' => t('Save Settings'),
  2014. ));
  2015. return $o;
  2016. }
  2017. }