configeditor.js 53 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302
  1. /*
  2. * Password Management Servlets (PWM)
  3. * http://www.pwm-project.org
  4. *
  5. * Copyright (c) 2006-2009 Novell, Inc.
  6. * Copyright (c) 2009-2017 The PWM Project
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  21. */
  22. "use strict";
  23. var PWM_CFGEDIT = PWM_CFGEDIT || {};
  24. var PWM_CONFIG = PWM_CONFIG || {};
  25. var PWM_MAIN = PWM_MAIN || {};
  26. var PWM_VAR = PWM_VAR || {};
  27. var PWM_SETTINGS = PWM_SETTINGS || {};
  28. PWM_VAR['outstandingOperations'] = 0;
  29. PWM_VAR['skippedSettingCount'] = 0;
  30. PWM_CFGEDIT.readSetting = function(keyName, valueWriter) {
  31. var modifiedOnly = PWM_CFGEDIT.readNavigationFilters()['modifiedSettingsOnly'];
  32. var maxLevel = parseInt(PWM_CFGEDIT.readNavigationFilters()['level']);
  33. PWM_VAR['outstandingOperations']++;
  34. PWM_CFGEDIT.handleWorkingIcon();
  35. var url = "editor?processAction=readSetting&key=" + keyName;
  36. if (PWM_CFGEDIT.readCurrentProfile()) {
  37. url = PWM_MAIN.addParamToUrl(url, 'profile', PWM_CFGEDIT.readCurrentProfile());
  38. }
  39. var loadFunction = function(data) {
  40. PWM_VAR['outstandingOperations']--;
  41. PWM_CFGEDIT.handleWorkingIcon();
  42. console.log('read data for setting ' + keyName);
  43. var resultValue = data['data']['value'];
  44. var isDefault = data['data']['isDefault'];
  45. var settingLevel = 0;
  46. if (PWM_SETTINGS['settings'][keyName] && PWM_SETTINGS['settings'][keyName]['level']) {
  47. settingLevel = PWM_SETTINGS['settings'][keyName]['level'];
  48. }
  49. var showSetting = (PWM_SETTINGS['settings'][keyName] && PWM_SETTINGS['settings'][keyName]['syntax'] == 'PROFILE') || (!modifiedOnly || !isDefault) && (maxLevel < 0 || settingLevel <= maxLevel );
  50. if (showSetting) {
  51. valueWriter(resultValue);
  52. PWM_MAIN.setStyle('outline_' + keyName,'display','inherit');
  53. PWM_CFGEDIT.updateSettingDisplay(keyName, isDefault);
  54. PWM_CFGEDIT.updateLastModifiedInfo(keyName, data);
  55. } else {
  56. PWM_MAIN.setStyle('outline_' + keyName,'display','none');
  57. PWM_VAR['skippedSettingCount']++;
  58. if (PWM_VAR['skippedSettingCount'] > 0 && PWM_MAIN.getObject('panel-skippedSettingInfo')) {
  59. PWM_MAIN.getObject('panel-skippedSettingInfo').innerHTML = "" + PWM_VAR['skippedSettingCount'] + " items are not shown due to filter settings."
  60. }
  61. }
  62. };
  63. var errorFunction = function(error) {
  64. PWM_VAR['outstandingOperations']--;
  65. PWM_CFGEDIT.handleWorkingIcon();
  66. PWM_MAIN.showDialog({title:PWM_MAIN.showString('Title_Error'),text:"Unable to communicate with server. Please refresh page."});
  67. console.log("error loading " + keyName + ", reason: " + error);
  68. };
  69. PWM_MAIN.ajaxRequest(url,loadFunction,{errorFunction:errorFunction});
  70. };
  71. PWM_CFGEDIT.updateLastModifiedInfo = function(keyName, data) {
  72. if (PWM_MAIN.getObject('panel-' + keyName + '-modifyTime')) {
  73. if (data['data']['modifyTime']) {
  74. PWM_MAIN.getObject('panel-' + keyName + '-modifyTime').innerHTML = 'Last Modified '
  75. + '<span id="panel-' + keyName + '-modifyTimestamp">' + data['data']['modifyTime'] + '</span>';
  76. PWM_MAIN.TimestampHandler.initElement(PWM_MAIN.getObject('panel-' + keyName + '-modifyTimestamp'));
  77. } else {
  78. PWM_MAIN.getObject('panel-' + keyName + '-modifyTime').innerHTML = '';
  79. }
  80. }
  81. if (PWM_MAIN.getObject('panel-' + keyName + '-modifyUser')) {
  82. if (data['data']['modifyUser']) {
  83. var output = 'Modified by ' + data['data']['modifyUser']['userDN'];
  84. if (data['data']['modifyUser']['ldapProfile'] && data['data']['modifyUser']['ldapProfile'] != "default") {
  85. output += ' [' + data['data']['modifyUser']['ldapProfile'] + ']';
  86. }
  87. PWM_MAIN.getObject('panel-' + keyName + '-modifyUser').innerHTML = output;
  88. } else {
  89. PWM_MAIN.getObject('panel-' + keyName + '-modifyUser').innerHTML = '';
  90. }
  91. }
  92. };
  93. PWM_CFGEDIT.writeSetting = function(keyName, valueData, nextAction) {
  94. PWM_VAR['outstandingOperations']++;
  95. PWM_CFGEDIT.handleWorkingIcon();
  96. var url = "editor?processAction=writeSetting&key=" + keyName;
  97. if (PWM_CFGEDIT.readCurrentProfile()) {
  98. url = PWM_MAIN.addParamToUrl(url,'profile',PWM_CFGEDIT.readCurrentProfile());
  99. }
  100. var loadFunction = function(data) {
  101. PWM_VAR['outstandingOperations']--;
  102. PWM_CFGEDIT.handleWorkingIcon();
  103. console.log('wrote data for setting ' + keyName);
  104. var isDefault = data['data']['isDefault'];
  105. PWM_CFGEDIT.updateSettingDisplay(keyName, isDefault);
  106. if (data['errorMessage']) {
  107. PWM_MAIN.showError(data['data']['errorMessage']);
  108. } else {
  109. PWM_MAIN.clearError();
  110. }
  111. if (nextAction !== undefined) {
  112. nextAction();
  113. }
  114. };
  115. var errorFunction = function(error) {
  116. PWM_VAR['outstandingOperations']--;
  117. PWM_CFGEDIT.handleWorkingIcon();
  118. PWM_MAIN.showDialog({title:PWM_MAIN.showString('Title_Error'),text:"Unable to communicate with server. Please refresh page."});
  119. console.log("error writing setting " + keyName + ", reason: " + error)
  120. };
  121. PWM_MAIN.ajaxRequest(url,loadFunction,{errorFunction:errorFunction,content:valueData});
  122. };
  123. PWM_CFGEDIT.resetSetting=function(keyName, nextAction) {
  124. var url = "editor?processAction=resetSetting&key=" + keyName;
  125. if (PWM_CFGEDIT.readCurrentProfile()) {
  126. url = PWM_MAIN.addParamToUrl(url,'profile',PWM_CFGEDIT.readCurrentProfile());
  127. }
  128. var loadFunction = function() {
  129. console.log('reset data for ' + keyName);
  130. if (nextAction !== undefined) {
  131. nextAction();
  132. }
  133. };
  134. PWM_MAIN.ajaxRequest(url,loadFunction);
  135. };
  136. PWM_CFGEDIT.handleWorkingIcon = function() {
  137. var iconElement = PWM_MAIN.getObject('working_icon');
  138. if (iconElement) {
  139. if (PWM_VAR['outstandingOperations'] > 0) {
  140. iconElement.style.visibility = 'visible';
  141. } else {
  142. iconElement.style.visibility = 'hidden';
  143. }
  144. }
  145. };
  146. PWM_CFGEDIT.updateSettingDisplay = function(keyName, isDefault) {
  147. require(["dojo"],function(dojo){
  148. var resetImageButton = PWM_MAIN.getObject('resetButton-' + keyName);
  149. var modifiedIcon = PWM_MAIN.getObject('modifiedNoticeIcon-' + keyName);
  150. var settingSyntax = '';
  151. try {
  152. settingSyntax = PWM_SETTINGS['settings'][keyName]['syntax'];
  153. } catch (e) { /* noop */ } //setting keys may not be loaded
  154. if (PWM_SETTINGS['settings'][keyName]) {
  155. if (PWM_MAIN.JSLibrary.arrayContains(PWM_SETTINGS['settings'][keyName]['flags'],'NoDefault')) {
  156. isDefault = true;
  157. }
  158. }
  159. if (!isDefault) {
  160. resetImageButton.style.visibility = 'visible';
  161. modifiedIcon.style.display = 'inline';
  162. try {
  163. dojo.addClass('title_' + keyName,"modified");
  164. dojo.addClass('titlePane_' + keyName,"modified");
  165. } catch (e) { /* noop */ }
  166. } else {
  167. resetImageButton.style.visibility = 'hidden';
  168. modifiedIcon.style.display = 'none';
  169. try {
  170. dojo.removeClass('title_' + keyName,"modified");
  171. dojo.removeClass('titlePane_' + keyName,"modified");
  172. } catch (e) { /* noop */ }
  173. }
  174. });
  175. };
  176. PWM_CFGEDIT.getSettingValueElement = function(settingKey) {
  177. var parentDiv = 'table_setting_' + settingKey;
  178. return PWM_MAIN.getObject(parentDiv);
  179. };
  180. PWM_CFGEDIT.clearDivElements = function(parentDiv) {
  181. var parentDivElement = PWM_MAIN.getObject(parentDiv);
  182. if (parentDivElement != null) {
  183. if (parentDivElement.hasChildNodes()) {
  184. while (parentDivElement.childNodes.length >= 1) {
  185. var firstChild = parentDivElement.firstChild;
  186. parentDivElement.removeChild(firstChild);
  187. }
  188. }
  189. }
  190. };
  191. PWM_CFGEDIT.addValueButtonRow = function(parentDiv, keyName, addFunction) {
  192. var buttonId = keyName + '-addValueButton';
  193. var newTableRow = document.createElement("tr");
  194. newTableRow.setAttribute("style", "border-width: 0");
  195. newTableRow.setAttribute("colspan", "5");
  196. var newTableData = document.createElement("td");
  197. newTableData.setAttribute("style", "border-width: 0;");
  198. var addItemButton = document.createElement("button");
  199. addItemButton.setAttribute("type", "button");
  200. addItemButton.setAttribute("id", buttonId);
  201. addItemButton.setAttribute("class", "btn");
  202. addItemButton.onclick = addFunction;
  203. addItemButton.innerHTML = "Add Value";
  204. newTableData.appendChild(addItemButton);
  205. var parentDivElement = PWM_MAIN.getObject(parentDiv);
  206. parentDivElement.appendChild(newTableRow);
  207. newTableRow.appendChild(newTableData);
  208. };
  209. PWM_CFGEDIT.readInitialTextBasedValue = function(key) {
  210. require(["dijit/registry"],function(registry){
  211. PWM_CFGEDIT.readSetting(key, function(dataValue) {
  212. PWM_MAIN.getObject('value_' + key).value = dataValue;
  213. PWM_MAIN.getObject('value_' + key).disabled = false;
  214. registry.byId('value_' + key).set('disabled', false);
  215. registry.byId('value_' + key).startup();
  216. try {registry.byId('value_' + key).validate(false);} catch (e) {}
  217. try {registry.byId('value_verify_' + key).validate(false);} catch (e) {}
  218. });
  219. });
  220. };
  221. PWM_CFGEDIT.saveConfiguration = function() {
  222. PWM_VAR['cancelHeartbeatCheck'] = true;
  223. PWM_MAIN.preloadAll(function(){
  224. var confirmText = PWM_CONFIG.showString('MenuDisplay_SaveConfig');
  225. var confirmFunction = function(){
  226. var url = "editor?processAction=finishEditing";
  227. var loadFunction = function(data) {
  228. if (data['error'] == true) {
  229. PWM_MAIN.showErrorDialog(data);
  230. } else {
  231. console.log('save completed');
  232. PWM_MAIN.showWaitDialog({title:'Save complete, restarting application...',loadFunction:function(){
  233. PWM_CONFIG.waitForRestart({location:'/'});
  234. }});
  235. }
  236. };
  237. PWM_MAIN.showWaitDialog({title:'Saving...',loadFunction:function(){
  238. PWM_MAIN.ajaxRequest(url,loadFunction);
  239. }});
  240. };
  241. PWM_CFGEDIT.showChangeLog(confirmText,confirmFunction);
  242. });
  243. };
  244. PWM_CFGEDIT.setConfigurationPassword = function(password) {
  245. if (password) {
  246. var url = "editor?processAction=setConfigurationPassword";
  247. var loadFunction = function(data) {
  248. if (data['error']) {
  249. PWM_MAIN.closeWaitDialog();
  250. PWM_MAIN.showDialog({title: PWM_MAIN.showString('Title_Error'), text: data['errorMessage']});
  251. } else {
  252. PWM_MAIN.closeWaitDialog();
  253. PWM_MAIN.showDialog({title: PWM_MAIN.showString('Title_Success'), text: data['successMessage']});
  254. }
  255. };
  256. var errorFunction = function(errorObj) {
  257. PWM_MAIN.closeWaitDialog();
  258. PWM_MAIN.showDialog ({title:PWM_MAIN.showString('Title_Error'),text:"error saving configuration password: " + errorObj});
  259. };
  260. PWM_MAIN.clearDijitWidget('dialogPopup');
  261. PWM_MAIN.showWaitDialog({loadFunction:function(){
  262. PWM_MAIN.ajaxRequest(url,loadFunction,{errorFunction:errorFunction,content:{password:password}});
  263. }});
  264. return;
  265. }
  266. var writeFunction = function(passwordValue) {
  267. PWM_CFGEDIT.setConfigurationPassword(passwordValue);
  268. };
  269. ChangePasswordHandler.popup('configPw','Configuration Password',writeFunction);
  270. };
  271. function handleResetClick(settingKey) {
  272. var label = PWM_SETTINGS['settings'][settingKey] ? PWM_SETTINGS['settings'][settingKey]['label'] : ' ';
  273. var dialogText = PWM_CONFIG.showString('Warning_ResetSetting',{value1:label});
  274. var titleText = 'Reset ' + label ? label : '';
  275. PWM_MAIN.showConfirmDialog({title:titleText,text:dialogText,okAction:function(){
  276. PWM_CFGEDIT.resetSetting(settingKey,function(){
  277. PWM_CFGEDIT.loadMainPageBody();
  278. });
  279. }});
  280. }
  281. PWM_CFGEDIT.initConfigEditor = function(nextFunction) {
  282. PWM_MAIN.addEventHandler('homeSettingSearch',['input','focus'],function(){PWM_CFGEDIT.processSettingSearch(PWM_MAIN.getObject('searchResults'));});
  283. PWM_MAIN.addEventHandler('button-navigationExpandAll','click',function(){PWM_VAR['navigationTree'].expandAll()});
  284. PWM_MAIN.addEventHandler('button-navigationCollapseAll','click',function(){PWM_VAR['navigationTree'].collapseAll()});
  285. PWM_MAIN.addEventHandler('cancelButton_icon','click',function(){PWM_CFGEDIT.cancelEditing()});
  286. PWM_MAIN.addEventHandler('saveButton_icon','click',function(){PWM_CFGEDIT.saveConfiguration()});
  287. PWM_MAIN.addEventHandler('setPassword_icon','click',function(){PWM_CFGEDIT.setConfigurationPassword()});
  288. PWM_MAIN.addEventHandler('referenceDoc_icon','click',function(){
  289. PWM_MAIN.newWindowOpen(PWM_GLOBAL['url-context'] + '/public/reference/','referencedoc');
  290. });
  291. PWM_MAIN.addEventHandler('macroDoc_icon','click',function(){ PWM_CFGEDIT.showMacroHelp(); });
  292. PWM_MAIN.addEventHandler('settingFilter_icon','click',function(){ PWM_CFGEDIT.showSettingFilter(); });
  293. PWM_MAIN.addEventHandler('button-closeMenu','click',function(){
  294. PWM_CFGEDIT.closeMenuPanel();
  295. });
  296. PWM_MAIN.addEventHandler('button-openMenu','click',function(){
  297. PWM_CFGEDIT.openMenuPanel();
  298. });
  299. PWM_CONFIG.heartbeatCheck();
  300. PWM_CFGEDIT.loadMainPageBody();
  301. console.log('completed initConfigEditor');
  302. if (nextFunction) {
  303. nextFunction();
  304. }
  305. };
  306. PWM_CFGEDIT.executeSettingFunction = function (setting, name, resultHandler, extraData) {
  307. var jsonSendData = {};
  308. jsonSendData['setting'] = setting;
  309. jsonSendData['function'] = name;
  310. jsonSendData['extraData'] = extraData;
  311. resultHandler = resultHandler !== undefined ? resultHandler : function(data) {
  312. var msgBody = '<div style="max-height: 400px; overflow-y: auto">' + data['successMessage'] + '</div>';
  313. PWM_MAIN.showDialog({width:700,title: 'Results', text: msgBody, okAction: function () {
  314. PWM_CFGEDIT.loadMainPageBody();
  315. }});
  316. };
  317. var requestUrl = "editor?processAction=executeSettingFunction";
  318. if (PWM_CFGEDIT.readCurrentProfile()) {
  319. requestUrl = PWM_MAIN.addParamToUrl(requestUrl,'profile',PWM_CFGEDIT.readCurrentProfile());
  320. }
  321. PWM_MAIN.showWaitDialog({loadFunction:function() {
  322. var loadFunction = function(data) {
  323. if (data['error']) {
  324. PWM_MAIN.showErrorDialog(data);
  325. } else {
  326. resultHandler(data);
  327. }
  328. };
  329. PWM_MAIN.ajaxRequest(requestUrl, loadFunction, {content:jsonSendData});
  330. }});
  331. };
  332. PWM_CFGEDIT.showChangeLog=function(confirmText, confirmFunction) {
  333. var url = "editor?processAction=readChangeLog";
  334. var loadFunction = function(data) {
  335. PWM_MAIN.closeWaitDialog();
  336. if (data['error']) {
  337. PWM_MAIN.showDialog({title: PWM_MAIN.showString("Title_Error"), text: data['errorMessage']});
  338. } else {
  339. var showChangeLogDialog = function() {
  340. var bodyText = '<div class="changeLogViewBox">';
  341. bodyText += data['data']['html'];
  342. bodyText += '</div>';
  343. if (data['data']['health']) {
  344. bodyText += '<br/><div>Configuration Concerns:</div>';
  345. bodyText += '<div><ul>';
  346. for (var i in data['data']['health']['records']) {
  347. var detail = data['data']['health']['records'][i]['detail'];
  348. bodyText += '<li>' + detail + '</li>';
  349. }
  350. bodyText += '</ul></div>';
  351. }
  352. if (confirmText != undefined) {
  353. bodyText += '<br/><div>' + confirmText + '</div>';
  354. }
  355. if (confirmFunction == undefined) {
  356. PWM_MAIN.showDialog({title: "Unsaved Configuration Editor Changes", text: bodyText, dialogClass:'wide', showClose: true});
  357. } else {
  358. PWM_MAIN.showConfirmDialog({title: "Unsaved Configuration Editor Changes", text: bodyText, dialogClass:'wide', showClose: true, okAction:confirmFunction});
  359. }
  360. };
  361. showChangeLogDialog()
  362. }
  363. };
  364. PWM_MAIN.showWaitDialog({loadFunction: function () {
  365. PWM_MAIN.ajaxRequest(url, loadFunction);
  366. }});
  367. };
  368. PWM_CFGEDIT.processSettingSearch = function(destinationDiv) {
  369. var iteration = 'settingSearchIteration' in PWM_VAR ? PWM_VAR['settingSearchIteration'] + 1 : 0;
  370. var startTime = new Date().getTime();
  371. PWM_VAR['settingSearchIteration'] = iteration;
  372. var resetDisplay = function() {
  373. PWM_MAIN.getObject('indicator-noResults').style.display = 'none';
  374. PWM_MAIN.getObject('indicator-searching').style.display = 'none';
  375. destinationDiv.style.visibility = 'hidden';
  376. destinationDiv.innerHTML = '';
  377. };
  378. var readSearchTerm = function() {
  379. if (!PWM_MAIN.getObject('homeSettingSearch') || !PWM_MAIN.getObject('homeSettingSearch') || PWM_MAIN.getObject('homeSettingSearch').value.length < 1) {
  380. return null;
  381. }
  382. return PWM_MAIN.getObject('homeSettingSearch').value;
  383. };
  384. console.log('beginning search #' + iteration);
  385. var url = "editor?processAction=search";
  386. var loadFunction = function(data) {
  387. resetDisplay();
  388. if (!readSearchTerm()) {
  389. resetDisplay();
  390. return;
  391. }
  392. if (!data) {
  393. console.log('search #' + iteration + ", no data returned");
  394. return;
  395. }
  396. if (data['error']) {
  397. console.log('search #' + iteration + ", error returned: " + data);
  398. PWM_MAIN.showErrorDialog(data);
  399. } else {
  400. var bodyText = '';
  401. var resultCount = 0;
  402. var elapsedTime = (new Date().getTime()) - startTime;
  403. if (PWM_MAIN.JSLibrary.isEmpty(data['data'])) {
  404. PWM_MAIN.getObject('indicator-noResults').style.display = 'inline';
  405. console.log('search #' + iteration + ', 0 results, ' + elapsedTime + 'ms');
  406. } else {
  407. for (var categoryIter in data['data']) {
  408. var category = data['data'][categoryIter];
  409. bodyText += '<div class="panel-searchResultCategory">' + categoryIter + '</div>';
  410. for (var settingIter in category) {
  411. var setting = category[settingIter];
  412. var profileID = setting['profile'];
  413. var linkID = 'link-' + setting['category'] + '-' + settingIter + (profileID ? profileID : '');
  414. var settingID = "search_" + (profileID ? profileID + '_' : '') + settingIter;
  415. bodyText += '<div><span id="' + linkID + '" class="panel-searchResultItem">';
  416. bodyText += PWM_SETTINGS['settings'][settingIter]['label'];
  417. bodyText += '</span>&nbsp;<span id="' + settingID + '_popup" class="btn-icon pwm-icon pwm-icon-info-circle"></span>';
  418. if (!setting['default']) {
  419. bodyText += '<span class="pwm-icon pwm-icon-pencil-square modifiedNoticeIcon" title="' + PWM_CONFIG.showString('Tooltip_ModifiedNotice') + '">&nbsp;</span>';
  420. }
  421. bodyText += '</div>';
  422. resultCount++;
  423. }
  424. }
  425. console.log('search #' + iteration + ', ' + resultCount + ' results, ' + elapsedTime + 'ms');
  426. destinationDiv.style.visibility = 'visible';
  427. destinationDiv.innerHTML = bodyText;
  428. for (var categoryIter in data['data']) {
  429. var category = data['data'][categoryIter];
  430. for (var iter in category) {
  431. (function (settingKey) {
  432. var setting = category[settingKey];
  433. var profileID = setting['profile'];
  434. var settingID = "search_" + (profileID ? profileID + '_' : '') + settingKey;
  435. var value = setting['value'];
  436. var toolBody = '<span style="font-weight: bold">Setting</span>';
  437. toolBody += '<br/>' + PWM_SETTINGS['settings'][settingKey]['label'] + '<br/><br/>';
  438. toolBody += '<span style="font-weight: bold">Description</span>';
  439. toolBody += '<br/>' + PWM_SETTINGS['settings'][settingKey]['description'] + '<br/><br/>';
  440. toolBody += '<span style="font-weight: bold">Value</span>';
  441. toolBody += '<br/>' + value.replace('\n', '<br/>') + '<br/>';
  442. PWM_MAIN.showDijitTooltip({
  443. id: settingID + '_popup',
  444. text: toolBody,
  445. width: 500
  446. });
  447. var linkID = 'link-' + setting['category'] + '-' + settingKey + (profileID ? profileID : '');
  448. PWM_MAIN.addEventHandler(linkID ,'click',function(){
  449. resetDisplay();
  450. PWM_MAIN.Preferences.writeSessionStorage('configEditor-lastSelected',{
  451. type:'category',
  452. category:setting['category'],
  453. setting:settingKey,
  454. profile:profileID
  455. });
  456. PWM_CFGEDIT.gotoSetting(setting['category'],settingKey,profileID);
  457. });
  458. }(iter));
  459. }
  460. }
  461. }
  462. }
  463. };
  464. var validationProps = {};
  465. validationProps['serviceURL'] = url;
  466. validationProps['readDataFunction'] = function(){
  467. resetDisplay();
  468. PWM_MAIN.getObject('indicator-searching').style.display = 'inline';
  469. var value = readSearchTerm();
  470. return {search:value,key:value};
  471. };
  472. validationProps['completeFunction'] = function() {
  473. PWM_MAIN.getObject('indicator-searching').style.display = 'none';
  474. };
  475. validationProps['processResultsFunction'] = loadFunction;
  476. PWM_MAIN.pwmFormValidator(validationProps);
  477. };
  478. PWM_CFGEDIT.gotoSetting = function(category,settingKey,profile) {
  479. console.log('going to setting... category=' + category + " settingKey=" + settingKey + " profile=" + profile);
  480. if (!category) {
  481. if (settingKey) {
  482. var settingInfo = PWM_SETTINGS['settings'][settingKey];
  483. if (settingInfo) {
  484. category = settingInfo['category'];
  485. }
  486. }
  487. }
  488. if (!settingKey && !category) {
  489. console.log('unable to goto setting: settingKey and category parameter are not specified');
  490. return;
  491. }
  492. if (settingKey && !(settingKey in PWM_SETTINGS['settings'])) {
  493. console.log('unable to goto setting: settingKey parameter "' + settingKey + '" is not valid');
  494. return;
  495. }
  496. if (!(category in PWM_SETTINGS['categories'])) {
  497. console.log('unable to goto setting: category parameter "' + category + '" is not valid');
  498. return;
  499. }
  500. PWM_CFGEDIT.setCurrentProfile(profile);
  501. PWM_CFGEDIT.displaySettingsCategory(category);
  502. if (PWM_SETTINGS['categories'][category]['menuLocation']) {
  503. var text = PWM_SETTINGS['categories'][category]['menuLocation'];
  504. if (PWM_SETTINGS['categories'][category]['profiles']) {
  505. text = text.replace('PROFILE',profile);
  506. }
  507. PWM_CFGEDIT.setBreadcrumbText(text);
  508. }
  509. var item = {};
  510. item['id'] = category;
  511. item['type'] = 'category';
  512. if (settingKey) {
  513. setTimeout(function(){
  514. var settingElement = PWM_CFGEDIT.getSettingValueElement(settingKey);
  515. console.log('navigating and highlighting setting ' + settingKey);
  516. //location.href = "#setting-" + settingKey;
  517. settingElement.scrollIntoView(true);
  518. if (settingElement.getBoundingClientRect().top < 100) {
  519. window.scrollBy(0, -100);
  520. }
  521. PWM_MAIN.flashDomElement('red','title_' + settingKey, 5000);
  522. },1000);
  523. }
  524. };
  525. PWM_CFGEDIT.setBreadcrumbText = function(text) {
  526. PWM_MAIN.getObject('currentPageDisplay').innerHTML = text;
  527. };
  528. PWM_CFGEDIT.cancelEditing = function() {
  529. var url = "editor?processAction=readChangeLog";
  530. PWM_MAIN.showWaitDialog({loadFunction:function(){
  531. var loadFunction = function(data) {
  532. if (data['error']) {
  533. PWM_MAIN.showDialog({title: PWM_MAIN.showString("Title_Error"), text: data['errorMessage']});
  534. } else {
  535. if (data['data']['modified'] == true) {
  536. var bodyText = '<div class="changeLogViewBox">';
  537. bodyText += data['data']['html'];
  538. bodyText += '</div><br/><div>';
  539. bodyText += PWM_CONFIG.showString('MenuDisplay_CancelConfig');
  540. bodyText += '</div>';
  541. PWM_MAIN.closeWaitDialog();
  542. PWM_MAIN.showConfirmDialog({dialogClass:'wide',showClose:true,allowMove:true,text:bodyText,okAction:
  543. function () {
  544. PWM_MAIN.showWaitDialog({loadFunction: function () {
  545. PWM_MAIN.ajaxRequest('editor?processAction=cancelEditing',function(){
  546. PWM_MAIN.goto('manager', {addFormID: true});
  547. });
  548. }});
  549. }
  550. });
  551. } else {
  552. PWM_MAIN.goto('manager', {addFormID: true});
  553. }
  554. }
  555. };
  556. PWM_MAIN.ajaxRequest(url, loadFunction);
  557. }});
  558. };
  559. PWM_CFGEDIT.showMacroHelp = function() {
  560. require(["dijit/Dialog"],function(Dialog) {
  561. var idName = 'macroPopup';
  562. PWM_MAIN.clearDijitWidget(idName);
  563. var theDialog = new Dialog({
  564. id: idName,
  565. title: 'Macro Help',
  566. style: "width: 750px",
  567. href: PWM_GLOBAL['url-resources'] + "/text/macroHelp.html"
  568. });
  569. var attempts = 0;
  570. // iframe takes indeterminate amount of time to load, so just retry till it apperas
  571. var loadFunction = function() {
  572. if (PWM_MAIN.getObject('input-testMacroInput')) {
  573. console.log('connected to macroHelpDiv');
  574. setTimeout(function(){
  575. PWM_MAIN.getObject('input-testMacroInput').focus();
  576. },500);
  577. PWM_MAIN.addEventHandler('button-testMacro','click',function(){
  578. PWM_MAIN.getObject('panel-testMacroOutput').innerHTML = PWM_MAIN.showString('Display_PleaseWait');
  579. var sendData = {};
  580. sendData['input'] = PWM_MAIN.getObject('input-testMacroInput').value;
  581. var url = "editor?processAction=testMacro";
  582. var loadFunction = function(data) {
  583. PWM_MAIN.getObject('panel-testMacroOutput').innerHTML = data['data'];
  584. };
  585. PWM_MAIN.ajaxRequest(url,loadFunction,{content:sendData});
  586. });
  587. } else {
  588. if (attempts < 50) {
  589. attempts++;
  590. setTimeout(loadFunction,100);
  591. }
  592. }
  593. };
  594. theDialog.show();
  595. loadFunction();
  596. });
  597. };
  598. PWM_CFGEDIT.showTimezoneList = function() {
  599. require(["dijit/Dialog"],function(Dialog) {
  600. var idName = 'timezonePopup';
  601. PWM_MAIN.clearDijitWidget(idName);
  602. var theDialog = new Dialog({
  603. id: idName,
  604. title: 'Timezones',
  605. style: "width: 750px",
  606. href: PWM_GLOBAL['url-context'] + "/public/reference/timezones.jsp"
  607. });
  608. theDialog.show();
  609. });
  610. };
  611. PWM_CFGEDIT.showDateTimeFormatHelp = function() {
  612. require(["dijit/Dialog"],function(Dialog) {
  613. var idName = 'dateTimePopup';
  614. PWM_MAIN.clearDijitWidget(idName);
  615. var theDialog = new Dialog({
  616. id: idName,
  617. title: 'Macro Help',
  618. style: "width: 700px",
  619. href: PWM_GLOBAL['url-resources'] + "/text/datetimeFormatHelp.html"
  620. });
  621. theDialog.show();
  622. });
  623. };
  624. PWM_CFGEDIT.ldapHealthCheck = function() {
  625. PWM_MAIN.showWaitDialog({loadFunction:function() {
  626. var url = "editor?processAction=ldapHealthCheck";
  627. url = PWM_MAIN.addParamToUrl(url,'profile',PWM_CFGEDIT.readCurrentProfile());
  628. var loadFunction = function(data) {
  629. PWM_MAIN.closeWaitDialog();
  630. if (data['error']) {
  631. PWM_MAIN.showDialog({title: PWM_MAIN.showString("Title_Error"), text: data['errorMessage']});
  632. } else {
  633. var bodyText = PWM_ADMIN.makeHealthHtml(data['data'],false,false);
  634. var profileName = PWM_CFGEDIT.readCurrentProfile();
  635. var titleText = PWM_MAIN.showString('Field_LdapProfile') + ": " + profileName;
  636. PWM_MAIN.showDialog({text:bodyText,title:titleText});
  637. }
  638. };
  639. PWM_MAIN.ajaxRequest(url,loadFunction);
  640. }});
  641. };
  642. PWM_CFGEDIT.databaseHealthCheck = function() {
  643. PWM_MAIN.showWaitDialog({title:'Checking database connection...',loadFunction:function(){
  644. var url = "editor?processAction=databaseHealthCheck";
  645. var loadFunction = function(data) {
  646. PWM_MAIN.closeWaitDialog();
  647. if (data['error']) {
  648. PWM_MAIN.showDialog({title: PWM_MAIN.showString("Title_Error"), text: data['errorMessage']});
  649. } else {
  650. var bodyText = PWM_ADMIN.makeHealthHtml(data['data'],false,false);
  651. var titleText = 'Database Connection Status';
  652. PWM_MAIN.showDialog({text:bodyText,title:titleText});
  653. }
  654. };
  655. PWM_MAIN.ajaxRequest(url,loadFunction);
  656. }});
  657. };
  658. PWM_CFGEDIT.httpsCertificateView = function() {
  659. PWM_MAIN.showWaitDialog({title:'Parsing...',loadFunction:function(){
  660. var url = "editor?processAction=httpsCertificateView";
  661. var loadFunction = function(data) {
  662. PWM_MAIN.closeWaitDialog();
  663. if (data['error']) {
  664. PWM_MAIN.showErrorDialog(data);
  665. } else {
  666. var bodyText = '<pre>' + data['data'] + '</pre>';
  667. var titleText = 'HTTPS Certificate';
  668. PWM_MAIN.showDialog({text:bodyText,title:titleText});
  669. }
  670. };
  671. PWM_MAIN.ajaxRequest(url,loadFunction);
  672. }});
  673. };
  674. PWM_CFGEDIT.smsHealthCheck = function() {
  675. require(["dojo/dom-form"], function(domForm){
  676. var dialogBody = '<p>' + PWM_CONFIG.showString('Warning_SmsTestData') + '</p><form id="smsCheckParametersForm"><table>';
  677. dialogBody += '<tr><td>To</td><td><input name="to" type="text" value="555-1212"/></td></tr>';
  678. dialogBody += '<tr><td>Message</td><td><input name="message" type="text" value="Test Message"/></td></tr>';
  679. dialogBody += '</table></form>';
  680. PWM_MAIN.showDialog({text:dialogBody,showCancel:true,title:'Test SMS connection',closeOnOk:false,okAction:function(){
  681. var formElement = PWM_MAIN.getObject("smsCheckParametersForm");
  682. var formData = domForm.toObject(formElement);
  683. var url = "editor?processAction=smsHealthCheck";
  684. PWM_MAIN.showWaitDialog({loadFunction:function(){
  685. var loadFunction = function(data) {
  686. if (data['error']) {
  687. PWM_MAIN.showErrorDialog(data);
  688. } else {
  689. var bodyText = PWM_ADMIN.makeHealthHtml(data['data'],false,false);
  690. var titleText = 'SMS Send Message Status';
  691. PWM_MAIN.showDialog({text:bodyText,title:titleText,showCancel:true});
  692. }
  693. };
  694. PWM_MAIN.ajaxRequest(url,loadFunction,{content:formData});
  695. }});
  696. }});
  697. });
  698. };
  699. PWM_CFGEDIT.selectTemplate = function(newTemplate) {
  700. PWM_MAIN.showConfirmDialog({
  701. text: PWM_CONFIG.showString('Warning_ChangeTemplate'),
  702. okAction: function () {
  703. PWM_MAIN.showWaitDialog({loadFunction: function () {
  704. var url = "editor?processAction=setOption&template=" + newTemplate;
  705. PWM_MAIN.ajaxRequest(url, function(){ PWM_MAIN.goto('editor'); });
  706. }});
  707. }
  708. });
  709. };
  710. PWM_CFGEDIT.loadMainPageBody = function() {
  711. PWM_CFGEDIT.drawNavigationMenu();
  712. var lastSelected = PWM_MAIN.Preferences.readSessionStorage('configEditor-lastSelected',null);
  713. if (lastSelected) {
  714. PWM_CFGEDIT.dispatchNavigationItem(lastSelected);
  715. } else {
  716. PWM_CFGEDIT.dispatchNavigationItem({id:'TEMPLATES',type:'category',category:'TEMPLATES'});
  717. }
  718. require(["dojo/io-query"],function(ioQuery){
  719. var uri = window.location.href;
  720. var queryString = uri.substring(uri.indexOf("?") + 1, uri.length);
  721. var queryParams = ioQuery.queryToObject(queryString);
  722. if (queryParams['processAction'] == 'gotoSetting') {
  723. PWM_CFGEDIT.gotoSetting(queryParams['category'],queryParams['settingKey'],queryParams['profile']);
  724. return;
  725. }
  726. });
  727. };
  728. PWM_CFGEDIT.displaySettingsCategory = function(category) {
  729. var settingsPanel = PWM_MAIN.getObject('settingsPanel');
  730. settingsPanel.innerHTML = '';
  731. console.log('loadingSettingsCategory: ' + category);
  732. if (!category) {
  733. settingsPanel.innerHTML = '';
  734. console.log('no selected category');
  735. return;
  736. }
  737. var htmlSettingBody = '';
  738. if (category == 'LDAP_BASE') {
  739. htmlSettingBody += '<div style="width: 100%; text-align: center">'
  740. + '<button class="btn" id="button-test-LDAP_BASE"><span class="btn-icon pwm-icon pwm-icon-bolt"></span>Test LDAP Profile</button>'
  741. + '</div>';
  742. } else if (category == 'DATABASE_SETTINGS') {
  743. htmlSettingBody += '<div style="width: 100%; text-align: center">'
  744. + '<button class="btn" id="button-test-DATABASE_SETTINGS"><span class="btn-icon pwm-icon pwm-icon-bolt"></span>Test Database Connection</button>'
  745. + '</div>';
  746. } else if (category == 'SMS_GATEWAY') {
  747. htmlSettingBody += '<div style="width: 100%; text-align: center">'
  748. + '<button class="btn" id="button-test-SMS"><span class="btn-icon pwm-icon pwm-icon-bolt"></span>Test SMS Settings</button>'
  749. + '</div>';
  750. }
  751. PWM_VAR['skippedSettingCount'] = 0;
  752. for (var loopSetting in PWM_SETTINGS['settings']) {
  753. (function(settingKey) {
  754. var settingInfo = PWM_SETTINGS['settings'][settingKey];
  755. if (settingInfo['category'] == category && !settingInfo['hidden']) {
  756. htmlSettingBody += PWM_CFGEDIT.drawHtmlOutlineForSetting(settingInfo);
  757. }
  758. })(loopSetting);
  759. }
  760. htmlSettingBody += '<div class="footnote" id="panel-skippedSettingInfo">';
  761. settingsPanel.innerHTML = htmlSettingBody;
  762. for (var loopSetting in PWM_SETTINGS['settings']) {
  763. (function(settingKey) {
  764. var settingInfo = PWM_SETTINGS['settings'][settingKey];
  765. if (settingInfo['category'] == category && !settingInfo['hidden']) {
  766. PWM_CFGEDIT.initSettingDisplay(settingInfo);
  767. }
  768. })(loopSetting);
  769. }
  770. if (category == 'LDAP_BASE') {
  771. PWM_MAIN.addEventHandler('button-test-LDAP_BASE', 'click', function(){PWM_CFGEDIT.ldapHealthCheck();});
  772. } else if (category == 'DATABASE_SETTINGS') {
  773. PWM_MAIN.addEventHandler('button-test-DATABASE_SETTINGS', 'click', function(){PWM_CFGEDIT.databaseHealthCheck();});
  774. } else if (category == 'SMS_GATEWAY') {
  775. PWM_MAIN.addEventHandler('button-test-SMS', 'click', function(){PWM_CFGEDIT.smsHealthCheck();});
  776. } else if (category == 'HTTPS_SERVER') {
  777. PWM_MAIN.addEventHandler('button-test-HTTPS_SERVER', 'click', function(){PWM_CFGEDIT.httpsCertificateView();});
  778. }
  779. PWM_CFGEDIT.applyGotoSettingHandlers();
  780. };
  781. PWM_CFGEDIT.drawProfileEditorPage = function(settingKey) {
  782. var settingsPanel = PWM_MAIN.getObject('settingsPanel');
  783. settingsPanel.innerHTML = '';
  784. var settingInfo = PWM_SETTINGS['settings'][settingKey];
  785. console.log('drawing profile-editor for setting-' + settingKey);
  786. settingsPanel.innerHTML = PWM_CFGEDIT.drawHtmlOutlineForSetting(settingInfo);
  787. PWM_CFGEDIT.initSettingDisplay(settingInfo);
  788. };
  789. PWM_CFGEDIT.drawHtmlOutlineForSetting = function(settingInfo, options) {
  790. options = options === undefined ? {} : options;
  791. var settingKey = settingInfo['key'];
  792. var settingLabel = settingInfo['label'];
  793. var htmlBody = '<div id="outline_' + settingKey + '" class="setting_outline" style="display:none">'
  794. + '<div class="setting_title" id="title_' + settingKey + '">'
  795. + '<a id="setting-' + settingKey + '" class="text">' + settingLabel + '</a>'
  796. + '<div class="pwm-icon pwm-icon-pencil-square modifiedNoticeIcon" title="' + PWM_CONFIG.showString('Tooltip_ModifiedNotice') + '" id="modifiedNoticeIcon-' + settingKey + '" style="display: none" ></div>';
  797. if (settingInfo['description']) {
  798. htmlBody += '<div class="pwm-icon pwm-icon-question-circle icon_button" title="' + PWM_CONFIG.showString('Tooltip_HelpButton') + '" id="helpButton-' + settingKey + '"></div>';
  799. }
  800. htmlBody += '<div style="visibility: hidden" class="pwm-icon pwm-icon-undo icon_button" title="' + PWM_CONFIG.showString('Tooltip_ResetButton') + '" id="resetButton-' + settingKey + '"></div>'
  801. + '</div>' // close title
  802. + '<div id="titlePane_' + settingKey + '" class="setting_body">';
  803. if (settingInfo['description']) {
  804. var prefs = PWM_MAIN.Preferences.readSessionStorage('helpExpanded',{});
  805. var expandHelp = settingKey in prefs;
  806. htmlBody += '<div class="pane-help" id="pane-help-' + settingKey + '" style="display:' + (expandHelp ? 'inherit' : 'none') + '">'
  807. + settingInfo['description'];
  808. if (settingInfo['placeholder']) {
  809. htmlBody += '<p><span style="font-weight:bold">Example: </span><code>' + settingInfo['placeholder'] + '</code></p>';
  810. }
  811. htmlBody += '</div>';
  812. }
  813. htmlBody += '<div class="pane-settingValue noborder" id="table_setting_' + settingKey + '">'
  814. + '</div>' // close setting;
  815. + '</div>' // close body
  816. + '<div class="footnote" style="width:100%"><span id="panel-' + settingKey + '-modifyTime"></span></div>'
  817. + '<div class="footnote" style="width:100%"><span id="panel-' + settingKey + '-modifyUser"></span></div>'
  818. + '</div>'; // close outline
  819. return htmlBody;
  820. };
  821. PWM_CFGEDIT.initSettingDisplay = function(setting, options) {
  822. var settingKey = setting['key'];
  823. options = options === undefined ? {} : options;
  824. PWM_MAIN.addEventHandler('helpButton-' + settingKey, 'click', function () {
  825. PWM_CFGEDIT.displaySettingHelp(settingKey);
  826. });
  827. PWM_MAIN.addEventHandler('setting-' + settingKey, 'click', function () {
  828. PWM_CFGEDIT.displaySettingHelp(settingKey);
  829. });
  830. PWM_MAIN.addEventHandler('resetButton-' + settingKey, 'click', function () {
  831. handleResetClick(settingKey);
  832. });
  833. switch (setting['syntax']) {
  834. case 'FORM':
  835. FormTableHandler.init(settingKey,{});
  836. break;
  837. case 'OPTIONLIST':
  838. OptionListHandler.init(settingKey);
  839. break;
  840. case 'CUSTOMLINKS':
  841. CustomLinkHandler.init(settingKey, {});
  842. break;
  843. case 'EMAIL':
  844. EmailTableHandler.init(settingKey);
  845. break;
  846. case 'ACTION':
  847. ActionHandler.init(settingKey);
  848. break;
  849. case 'PASSWORD':
  850. ChangePasswordHandler.init(settingKey);
  851. break;
  852. case 'NAMED_SECRET':
  853. NamedSecretHandler.init(settingKey);
  854. break;
  855. case 'NUMERIC':
  856. NumericValueHandler.init(settingKey);
  857. break;
  858. case 'DURATION':
  859. DurationValueHandler.init(settingKey);
  860. break;
  861. case 'STRING':
  862. StringValueHandler.init(settingKey);
  863. break;
  864. case 'TEXT_AREA':
  865. TextAreaValueHandler.init(settingKey);
  866. break;
  867. case 'SELECT':
  868. SelectValueHandler.init(settingKey);
  869. break;
  870. case 'BOOLEAN':
  871. BooleanHandler.init(settingKey);
  872. break;
  873. case 'LOCALIZED_STRING_ARRAY':
  874. MultiLocaleTableHandler.initMultiLocaleTable(settingKey);
  875. break;
  876. case 'STRING_ARRAY':
  877. case 'PROFILE':
  878. StringArrayValueHandler.init(settingKey);
  879. break;
  880. case 'LOCALIZED_STRING':
  881. case 'LOCALIZED_TEXT_AREA':
  882. LocalizedStringValueHandler.init(settingKey);
  883. break;
  884. case 'USER_PERMISSION':
  885. UserPermissionHandler.init(settingKey);
  886. break;
  887. case 'CHALLENGE':
  888. ChallengeSettingHandler.init(settingKey);
  889. break;
  890. case 'X509CERT':
  891. X509CertificateHandler.init(settingKey);
  892. break;
  893. case 'PRIVATE_KEY':
  894. PrivateKeyHandler.init(settingKey);
  895. break;
  896. case 'FILE':
  897. FileValueHandler.init(settingKey);
  898. break;
  899. case 'VERIFICATION_METHOD':
  900. VerificationMethodHandler.init(settingKey);
  901. break;
  902. case 'NONE':
  903. break;
  904. default:
  905. console.log ('unknown setting syntax type: ' + setting['syntax']);
  906. }
  907. };
  908. PWM_CFGEDIT.drawNavigationMenu = function() {
  909. PWM_MAIN.getObject('navigationTree').innerHTML = '';
  910. PWM_MAIN.setStyle('navigationTreeWrapper','display','none');
  911. var makeTreeFunction = function(menuTreeData) {
  912. require(["dojo/_base/window", "dojo/store/Memory", "dijit/tree/ObjectStoreModel", "dijit/Tree","dijit","dojo/domReady!"],
  913. function(win, Memory, ObjectStoreModel, Tree)
  914. {
  915. PWM_MAIN.clearDijitWidget('navigationTree');
  916. // Create test store, adding the getChildren() method required by ObjectStoreModel
  917. var myStore = new Memory({
  918. data: menuTreeData,
  919. getChildren: function(object){
  920. return this.query({parent: object.id});
  921. }
  922. });
  923. // Create the model
  924. var model = new ObjectStoreModel({
  925. store: myStore,
  926. query: {id: 'ROOT'},
  927. mayHaveChildren: function(object){
  928. return object.type == 'navigation';
  929. }
  930. });
  931. // Create the Tree.
  932. var tree = new Tree({
  933. model: model,
  934. persist: true,
  935. getIconClass: function(/*dojo.store.Item*/ item, /*Boolean*/ opened){
  936. return 'tree-noicon';
  937. },
  938. showRoot: false,
  939. openOnClick: true,
  940. id: 'navigationTree',
  941. onClick: function(item){
  942. PWM_MAIN.Preferences.writeSessionStorage('configEditor-lastSelected',item);
  943. PWM_CFGEDIT.dispatchNavigationItem(item);
  944. }
  945. });
  946. PWM_MAIN.getObject('navigationTree').innerHTML = '';
  947. tree.placeAt(PWM_MAIN.getObject('navigationTree'));
  948. tree.startup();
  949. PWM_MAIN.setStyle('navigationTreeWrapper','display','inherit');
  950. PWM_VAR['navigationTree'] = tree; // used for expand/collapse button events;
  951. console.log('completed menu tree drawing')
  952. }
  953. );
  954. };
  955. var url = 'editor?processAction=menuTreeData';
  956. var filterParams = PWM_CFGEDIT.readNavigationFilters();
  957. PWM_MAIN.ajaxRequest(url,function(data){
  958. var menuTreeData = data['data'];
  959. makeTreeFunction(menuTreeData);
  960. },{content:filterParams});
  961. };
  962. PWM_CFGEDIT.readNavigationFilters = function() {
  963. var result = {};
  964. result['modifiedSettingsOnly'] = 'settingFilter_modifiedSettingsOnly' in PWM_VAR ? PWM_VAR['settingFilter_modifiedSettingsOnly'] : false;
  965. result['level'] = 'settingFilter_level' in PWM_VAR ? PWM_VAR['settingFilter_level'] : 2;
  966. result['text'] = 'settingFilter_text' in PWM_VAR ? PWM_VAR['settingFilter_text'] : '';
  967. return result;
  968. };
  969. PWM_CFGEDIT.dispatchNavigationItem = function(item) {
  970. var currentID = item['id'];
  971. var type = item['type'];
  972. //debugger;
  973. if (type == 'navigation') {
  974. /* not used, nav tree set to auto-expand */
  975. } else if (type == 'category') {
  976. var category = item['category'];
  977. if (item['profile']) {
  978. PWM_CFGEDIT.gotoSetting(category,null,item['profile']);
  979. } else {
  980. PWM_CFGEDIT.gotoSetting(category);
  981. }
  982. } else if (type == 'displayText') {
  983. var keys = item['keys'];
  984. PWM_CFGEDIT.setBreadcrumbText('Display Text - ' + item['name']);
  985. PWM_CFGEDIT.drawDisplayTextPage(currentID,keys);
  986. } else if (type == 'profile') {
  987. var category = item['category'];
  988. PWM_CFGEDIT.gotoSetting(category,null,currentID);
  989. } else if (type == 'profileDefinition') {
  990. var profileSettingKey = item['profileSetting'];
  991. PWM_CFGEDIT.drawProfileEditorPage(profileSettingKey);
  992. }
  993. };
  994. PWM_CFGEDIT.drawDisplayTextPage = function(settingKey, keys) {
  995. var settingsPanel = PWM_MAIN.getObject('settingsPanel');
  996. var remainingLoads = keys.length;
  997. settingsPanel.innerHTML = '<div id="displaytext-loading-panel" style="width:100%; text-align: center">'
  998. + PWM_MAIN.showString('Display_PleaseWait') + '&nbsp;<span id="remainingCount"></div>';
  999. console.log('drawing displaytext-editor for setting-' + settingKey);
  1000. var htmlBody = '<div id="localetext-editor-wrapper" style="display:none">';
  1001. for (var key in keys) {
  1002. var displayKey = 'localeBundle-' + settingKey + '-' + keys[key];
  1003. var settingInfo = {};
  1004. settingInfo['key'] = displayKey;
  1005. settingInfo['label'] = keys[key];
  1006. htmlBody += PWM_CFGEDIT.drawHtmlOutlineForSetting(settingInfo,{showHelp:false});
  1007. }
  1008. settingsPanel.innerHTML = settingsPanel.innerHTML + htmlBody;
  1009. var initSetting = function(keyCounter) {
  1010. if (PWM_VAR['outstandingOperations'] > 5) {
  1011. setTimeout(function () { initSetting(keyCounter); }, 50);
  1012. return;
  1013. }
  1014. var displayKey = 'localeBundle-' + settingKey + '-' + keys[keyCounter];
  1015. var settingInfo = {};
  1016. settingInfo['key'] = displayKey;
  1017. settingInfo['label'] = keys[keyCounter];
  1018. settingInfo['syntax'] = 'NONE';
  1019. PWM_CFGEDIT.initSettingDisplay(settingInfo);
  1020. LocalizedStringValueHandler.init(displayKey,{required:true});
  1021. remainingLoads--;
  1022. PWM_MAIN.getObject('remainingCount').innerHTML = remainingLoads > 0 ? remainingLoads : '';
  1023. };
  1024. var delay = 5;
  1025. for (var key in keys) {
  1026. (function(keyCounter) {
  1027. setTimeout(function(){
  1028. initSetting(keyCounter);
  1029. },delay);
  1030. delay = delay + 5;
  1031. })(key);
  1032. }
  1033. var checkForFinishFunction = function() {
  1034. console.log('checking for finish function...');
  1035. setTimeout(function(){
  1036. if (PWM_VAR['outstandingOperations'] == 0) {
  1037. PWM_MAIN.getObject('displaytext-loading-panel').style.display = 'none';
  1038. PWM_MAIN.getObject('localetext-editor-wrapper').style.display = 'inherit';
  1039. } else {
  1040. setTimeout(checkForFinishFunction,100);
  1041. }
  1042. },100);
  1043. };
  1044. checkForFinishFunction();
  1045. };
  1046. PWM_CFGEDIT.initConfigSettingsDefinition=function(nextFunction) {
  1047. var clientConfigUrl = PWM_GLOBAL['url-context'] + "/private/config/editor?processAction=settingData";
  1048. var loadFunction = function(data) {
  1049. if (data['error'] == true) {
  1050. console.error('unable to load ' + clientConfigUrl + ', error: ' + data['errorDetail'])
  1051. } else {
  1052. for (var settingKey in data['data']) {
  1053. PWM_SETTINGS[settingKey] = data['data'][settingKey];
  1054. }
  1055. }
  1056. console.log('loaded client-configsettings data');
  1057. if (nextFunction) nextFunction();
  1058. };
  1059. var errorFunction = function(error) {
  1060. var errorMsg = 'unable to read config settings app-data: ' + error;
  1061. console.log(errorMsg);
  1062. if (!PWM_VAR['initError']) PWM_VAR['initError'] = errorMsg;
  1063. if (nextFunction) nextFunction();
  1064. };
  1065. PWM_MAIN.ajaxRequest(clientConfigUrl, loadFunction, {method:'GET',errorFunction:errorFunction});
  1066. };
  1067. PWM_CFGEDIT.displaySettingHelp = function(settingKey) {
  1068. console.log('toggle help for ' + settingKey);
  1069. var helpExpandedPrefs = PWM_MAIN.Preferences.readSessionStorage('helpExpanded',{});
  1070. var element = PWM_MAIN.getObject('pane-help-' + settingKey);
  1071. if (element) {
  1072. if (element.style.display == 'none') {
  1073. element.style.display = 'inherit';
  1074. helpExpandedPrefs[settingKey] = true;
  1075. } else {
  1076. element.style.display = 'none';
  1077. delete helpExpandedPrefs[settingKey];
  1078. }
  1079. PWM_MAIN.Preferences.writeSessionStorage('helpExpanded',helpExpandedPrefs);
  1080. }
  1081. };
  1082. PWM_CFGEDIT.showSettingFilter = function() {
  1083. var currentValues = PWM_CFGEDIT.readNavigationFilters();
  1084. var dialogBody = '<div><form id="form-settingFilter"><table class="" style="table-layout: fixed">';
  1085. dialogBody += '<tr><td>Setting Level</td><td><label>';
  1086. dialogBody += '<input type="range" min="0" max="2" name="input-settingLevel" id="input-settingLevel" value="' + currentValues['level'] + '" style="width:100px"/>';
  1087. dialogBody += '<span id="panel-settingLevelDescription"></span></label></td></tr>';
  1088. dialogBody += '<tr><td>Modified</td><td>';
  1089. dialogBody += '<input type="radio" name="input-modifiedSettingsOnly" id="input-modifiedSettingsOnly-all" ' + (!currentValues['modifiedSettingsOnly'] ? 'checked' : '') + '>All';
  1090. dialogBody += '<input type="radio" name="input-modifiedSettingsOnly" id="input-modifiedSettingsOnly-modified" ' + (currentValues['modifiedSettingsOnly'] ? 'checked' : '') + '>Modified';
  1091. //dialogBody += '</td></tr><tr><td>Text';
  1092. //dialogBody += '</td><td><input type="text" id="input-settingFilterText" class="inputfield" id="input-settingFilterText"/>';
  1093. dialogBody += '</td></tr>';
  1094. dialogBody += '</table></div></div>';
  1095. var updateSettingLevelDescription = function() {
  1096. var value = parseInt(PWM_MAIN.getObject('input-settingLevel').value);
  1097. var descriptionText = PWM_CONFIG.showString('Display_SettingFilter_Level_' + value);
  1098. PWM_MAIN.getObject('panel-settingLevelDescription').innerHTML = descriptionText;
  1099. };
  1100. var updateIcon = function() {
  1101. var isDefault = PWM_VAR['settingFilter_modifiedSettingsOnly'] == false && PWM_VAR['settingFilter_level'] == 2;
  1102. if (isDefault) {
  1103. PWM_MAIN.removeCssClass('settingFilter_icon', "modified");
  1104. } else {
  1105. PWM_MAIN.addCssClass('settingFilter_icon', "modified");
  1106. }
  1107. };
  1108. var updateVars = function() {
  1109. PWM_VAR['settingFilter_modifiedSettingsOnly'] = PWM_MAIN.getObject('input-modifiedSettingsOnly-modified').checked;
  1110. PWM_VAR['settingFilter_level'] = parseInt(PWM_MAIN.getObject('input-settingLevel').value);
  1111. //PWM_VAR['settingFilter_text'] = PWM_MAIN.getObject('input-settingFilterText').value;
  1112. updateSettingLevelDescription();
  1113. };
  1114. PWM_MAIN.showDialog({title:'Setting Filters',text:dialogBody,loadFunction:function(){
  1115. //PWM_MAIN.getObject('input-settingFilterText').value = currentValues['text'];
  1116. PWM_MAIN.addEventHandler('form-settingFilter','change',function(){
  1117. updateVars();
  1118. });
  1119. updateSettingLevelDescription();
  1120. },okAction:function(){
  1121. updateIcon();
  1122. PWM_CFGEDIT.loadMainPageBody();
  1123. }});
  1124. };
  1125. PWM_CFGEDIT.readCurrentProfile = function() {
  1126. return PWM_VAR['currentProfile'];
  1127. };
  1128. PWM_CFGEDIT.setCurrentProfile = function(profile) {
  1129. if (profile) {
  1130. PWM_VAR['currentProfile'] = profile;
  1131. } else {
  1132. delete PWM_VAR['currentProfile'];
  1133. }
  1134. };
  1135. PWM_CFGEDIT.applyGotoSettingHandlers = function() {
  1136. PWM_MAIN.doQuery('[data-gotoSettingLink]',function(element){
  1137. PWM_MAIN.addEventHandler(element,'click',function(){
  1138. var linkValue = element.getAttribute('data-gotoSettingLink');
  1139. PWM_CFGEDIT.gotoSetting(null,linkValue,null);
  1140. })
  1141. });
  1142. };
  1143. PWM_CFGEDIT.closeMenuPanel = function() {
  1144. console.log('action closeHeader');
  1145. PWM_MAIN.addCssClass('header-warning','nodisplay');
  1146. PWM_MAIN.removeCssClass('button-openMenu','nodisplay');
  1147. };
  1148. PWM_CFGEDIT.openMenuPanel = function() {
  1149. console.log('action openHeader');
  1150. PWM_MAIN.removeCssClass('header-warning','nodisplay');
  1151. PWM_MAIN.addCssClass('button-openMenu','nodisplay');
  1152. };