admin.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  1. window.addEventListener('DOMContentLoaded', function(){
  2. $('#excludedGroups').each(function (index, element) {
  3. OC.Settings.setupGroupsSelect($(element));
  4. $(element).change(function(ev) {
  5. var groups = ev.val || [];
  6. groups = JSON.stringify(groups);
  7. OCP.AppConfig.setValue('core', $(this).attr('name'), groups);
  8. });
  9. });
  10. $('#loglevel').change(function(){
  11. $.post(OC.generateUrl('/settings/admin/log/level'), {level: $(this).val()},function(){
  12. OC.Log.reload();
  13. } );
  14. });
  15. $('#backgroundjobs span.crondate').tooltip({placement: 'top'});
  16. $('#backgroundjobs input').change(function(){
  17. if($(this).is(':checked')){
  18. var mode = $(this).val();
  19. if (mode === 'ajax' || mode === 'webcron' || mode === 'cron') {
  20. OCP.AppConfig.setValue('core', 'backgroundjobs_mode', mode, {
  21. success: function() {
  22. // clear cron errors on background job mode change
  23. OCP.AppConfig.deleteKey('core', 'cronErrors');
  24. }
  25. });
  26. }
  27. }
  28. });
  29. $('#shareAPIEnabled').change(function() {
  30. $('#shareAPI p:not(#enable)').toggleClass('hidden', !this.checked);
  31. });
  32. $('#enableEncryption').change(function() {
  33. $('#encryptionAPI div#EncryptionWarning').toggleClass('hidden');
  34. });
  35. $('#reallyEnableEncryption').click(function() {
  36. $('#encryptionAPI div#EncryptionWarning').toggleClass('hidden');
  37. $('#encryptionAPI div#EncryptionSettingsArea').toggleClass('hidden');
  38. OCP.AppConfig.setValue('core', 'encryption_enabled', 'yes');
  39. $('#enableEncryption').attr('disabled', 'disabled');
  40. });
  41. $('#startmigration').click(function(event){
  42. $(window).on('beforeunload.encryption', function(e) {
  43. return t('settings', 'Migration in progress. Please wait until the migration is finished');
  44. });
  45. event.preventDefault();
  46. $('#startmigration').prop('disabled', true);
  47. OC.msg.startAction('#startmigration_msg', t('settings', 'Migration started …'));
  48. $.post(OC.generateUrl('/settings/admin/startmigration'), '', function(data){
  49. OC.msg.finishedAction('#startmigration_msg', data);
  50. if (data['status'] === 'success') {
  51. $('#encryptionAPI div#selectEncryptionModules').toggleClass('hidden');
  52. $('#encryptionAPI div#migrationWarning').toggleClass('hidden');
  53. } else {
  54. $('#startmigration').prop('disabled', false);
  55. }
  56. $(window).off('beforeunload.encryption');
  57. });
  58. });
  59. $('#shareapiExpireAfterNDays').on('input', function() {
  60. this.value = this.value.replace(/\D/g, '');
  61. });
  62. $('#shareAPI input:not(.noJSAutoUpdate)').change(function() {
  63. var value = $(this).val();
  64. if ($(this).attr('type') === 'checkbox') {
  65. if (this.checked) {
  66. value = 'yes';
  67. } else {
  68. value = 'no';
  69. }
  70. }
  71. OCP.AppConfig.setValue('core', $(this).attr('name'), value);
  72. });
  73. $('#shareapiDefaultExpireDate').change(function() {
  74. $("#setDefaultExpireDate").toggleClass('hidden', !this.checked);
  75. });
  76. $('#shareapiDefaultInternalExpireDate').change(function() {
  77. $("#setDefaultInternalExpireDate").toggleClass('hidden', !this.checked);
  78. });
  79. $('#shareapiDefaultRemoteExpireDate').change(function() {
  80. $("#setDefaultRemoteExpireDate").toggleClass('hidden', !this.checked);
  81. });
  82. $('#publicShareDisclaimer').change(function() {
  83. $("#publicShareDisclaimerText").toggleClass('hidden', !this.checked);
  84. if(!this.checked) {
  85. savePublicShareDisclaimerText('');
  86. }
  87. });
  88. $('#shareApiDefaultPermissionsSection input').change(function(ev) {
  89. var $el = $('#shareApiDefaultPermissions');
  90. var $target = $(ev.target);
  91. var value = $el.val();
  92. if ($target.is(':checked')) {
  93. value = value | $target.val();
  94. } else {
  95. value = value & ~$target.val();
  96. }
  97. // always set read permission
  98. value |= OC.PERMISSION_READ;
  99. // this will trigger the field's change event and will save it
  100. $el.val(value).change();
  101. ev.preventDefault();
  102. return false;
  103. });
  104. var savePublicShareDisclaimerText = _.debounce(function(value) {
  105. var options = {
  106. success: function() {
  107. OC.msg.finishedSuccess('#publicShareDisclaimerStatus', t('core', 'Saved'));
  108. },
  109. error: function() {
  110. OC.msg.finishedError('#publicShareDisclaimerStatus', t('core', 'Not saved'));
  111. }
  112. };
  113. OC.msg.startSaving('#publicShareDisclaimerStatus');
  114. if (_.isString(value) && value !== '') {
  115. OCP.AppConfig.setValue('core', 'shareapi_public_link_disclaimertext', value, options);
  116. } else {
  117. $('#publicShareDisclaimerText').val('');
  118. OCP.AppConfig.deleteKey('core', 'shareapi_public_link_disclaimertext', options);
  119. }
  120. }, 500);
  121. $('#publicShareDisclaimerText').on('change, keyup', function() {
  122. savePublicShareDisclaimerText(this.value);
  123. });
  124. $('#shareapi_allow_share_dialog_user_enumeration').on('change', function() {
  125. $('#shareapi_restrict_user_enumeration_to_group_setting').toggleClass('hidden', !this.checked);
  126. $('#shareapi_restrict_user_enumeration_to_phone_setting').toggleClass('hidden', !this.checked);
  127. $('#shareapi_restrict_user_enumeration_combinewarning_setting').toggleClass('hidden', !this.checked);
  128. })
  129. $('#allowLinks').change(function() {
  130. $("#publicLinkSettings").toggleClass('hidden', !this.checked);
  131. $('#setDefaultExpireDate').toggleClass('hidden', !(this.checked && $('#shareapiDefaultExpireDate')[0].checked));
  132. });
  133. $('#mail_smtpauth').change(function() {
  134. if (!this.checked) {
  135. $('#mail_credentials').addClass('hidden');
  136. } else {
  137. $('#mail_credentials').removeClass('hidden');
  138. }
  139. });
  140. $('#mail_smtpmode').change(function() {
  141. if ($(this).val() !== 'smtp') {
  142. $('#setting_smtpauth').addClass('hidden');
  143. $('#setting_smtphost').addClass('hidden');
  144. $('#mail_smtpsecure_label').addClass('hidden');
  145. $('#mail_smtpsecure').addClass('hidden');
  146. $('#mail_credentials').addClass('hidden');
  147. $('#mail_sendmailmode_label, #mail_sendmailmode').removeClass('hidden');
  148. } else {
  149. $('#setting_smtpauth').removeClass('hidden');
  150. $('#setting_smtphost').removeClass('hidden');
  151. $('#mail_smtpsecure_label').removeClass('hidden');
  152. $('#mail_smtpsecure').removeClass('hidden');
  153. if ($('#mail_smtpauth').is(':checked')) {
  154. $('#mail_credentials').removeClass('hidden');
  155. }
  156. $('#mail_sendmailmode_label, #mail_sendmailmode').addClass('hidden');
  157. }
  158. });
  159. var changeEmailSettings = function() {
  160. if (OC.PasswordConfirmation.requiresPasswordConfirmation()) {
  161. OC.PasswordConfirmation.requirePasswordConfirmation(changeEmailSettings);
  162. return;
  163. }
  164. OC.msg.startSaving('#mail_settings_msg');
  165. $.ajax({
  166. url: OC.generateUrl('/settings/admin/mailsettings'),
  167. type: 'POST',
  168. data: $('#mail_general_settings_form').serialize(),
  169. success: function(){
  170. OC.msg.finishedSuccess('#mail_settings_msg', t('settings', 'Saved'));
  171. },
  172. error: function(xhr){
  173. OC.msg.finishedError('#mail_settings_msg', xhr.responseJSON);
  174. }
  175. });
  176. };
  177. var toggleEmailCredentials = function() {
  178. if (OC.PasswordConfirmation.requiresPasswordConfirmation()) {
  179. OC.PasswordConfirmation.requirePasswordConfirmation(toggleEmailCredentials);
  180. return;
  181. }
  182. OC.msg.startSaving('#mail_settings_msg');
  183. $.ajax({
  184. url: OC.generateUrl('/settings/admin/mailsettings/credentials'),
  185. type: 'POST',
  186. data: $('#mail_credentials_settings').serialize(),
  187. success: function(){
  188. OC.msg.finishedSuccess('#mail_settings_msg', t('settings', 'Saved'));
  189. },
  190. error: function(xhr){
  191. OC.msg.finishedError('#mail_settings_msg', xhr.responseJSON);
  192. }
  193. });
  194. };
  195. $('#mail_general_settings_form').change(changeEmailSettings);
  196. $('#mail_credentials_settings_submit').click(toggleEmailCredentials);
  197. $('#mail_smtppassword').click(function() {
  198. if (this.type === 'text' && this.value === '********') {
  199. this.type = 'password';
  200. this.value = '';
  201. }
  202. });
  203. $('#sendtestemail').click(function(event){
  204. event.preventDefault();
  205. OC.msg.startAction('#sendtestmail_msg', t('settings', 'Sending…'));
  206. $.ajax({
  207. url: OC.generateUrl('/settings/admin/mailtest'),
  208. type: 'POST',
  209. success: function(){
  210. OC.msg.finishedSuccess('#sendtestmail_msg', t('settings', 'Email sent'));
  211. },
  212. error: function(xhr){
  213. OC.msg.finishedError('#sendtestmail_msg', xhr.responseJSON);
  214. }
  215. });
  216. });
  217. $('#allowGroupSharing').change(function() {
  218. $('#allowGroupSharing').toggleClass('hidden', !this.checked);
  219. });
  220. $('#shareapiExcludeGroups').change(function() {
  221. $("#selectExcludedGroups").toggleClass('hidden', !this.checked);
  222. });
  223. var setupChecks = function () {
  224. // run setup checks then gather error messages
  225. $.when(
  226. OC.SetupChecks.checkWebDAV(),
  227. OC.SetupChecks.checkWellKnownUrl('GET', '/.well-known/webfinger', OC.theme.docPlaceholderUrl, $('#postsetupchecks').data('check-wellknown') === true, [200, 404], true),
  228. OC.SetupChecks.checkWellKnownUrl('GET', '/.well-known/nodeinfo', OC.theme.docPlaceholderUrl, $('#postsetupchecks').data('check-wellknown') === true, [200, 404], true),
  229. OC.SetupChecks.checkWellKnownUrl('PROPFIND', '/.well-known/caldav', OC.theme.docPlaceholderUrl, $('#postsetupchecks').data('check-wellknown') === true),
  230. OC.SetupChecks.checkWellKnownUrl('PROPFIND', '/.well-known/carddav', OC.theme.docPlaceholderUrl, $('#postsetupchecks').data('check-wellknown') === true),
  231. OC.SetupChecks.checkProviderUrl(OC.getRootPath() + '/ocm-provider/', OC.theme.docPlaceholderUrl, $('#postsetupchecks').data('check-wellknown') === true),
  232. OC.SetupChecks.checkProviderUrl(OC.getRootPath() + '/ocs-provider/', OC.theme.docPlaceholderUrl, $('#postsetupchecks').data('check-wellknown') === true),
  233. OC.SetupChecks.checkSetup(),
  234. OC.SetupChecks.checkGeneric(),
  235. OC.SetupChecks.checkWOFF2Loading(OC.filePath('core', '', 'fonts/NotoSans-Regular-latin.woff2'), OC.theme.docPlaceholderUrl),
  236. OC.SetupChecks.checkDataProtected()
  237. ).then(function (check1, check2, check3, check4, check5, check6, check7, check8, check9, check10, check11) {
  238. var messages = [].concat(check1, check2, check3, check4, check5, check6, check7, check8, check9, check10, check11);
  239. var $el = $('#postsetupchecks');
  240. $('#security-warning-state-loading').addClass('hidden');
  241. var hasMessages = false;
  242. var $errorsEl = $el.find('.errors');
  243. var $warningsEl = $el.find('.warnings');
  244. var $infoEl = $el.find('.info');
  245. for (var i = 0; i < messages.length; i++) {
  246. switch (messages[i].type) {
  247. case OC.SetupChecks.MESSAGE_TYPE_INFO:
  248. $infoEl.append('<li>' + messages[i].msg + '</li>');
  249. break;
  250. case OC.SetupChecks.MESSAGE_TYPE_WARNING:
  251. $warningsEl.append('<li>' + messages[i].msg + '</li>');
  252. break;
  253. case OC.SetupChecks.MESSAGE_TYPE_ERROR:
  254. default:
  255. $errorsEl.append('<li>' + messages[i].msg + '</li>');
  256. }
  257. }
  258. if ($errorsEl.find('li').length > 0) {
  259. $errorsEl.removeClass('hidden');
  260. hasMessages = true;
  261. }
  262. if ($warningsEl.find('li').length > 0) {
  263. $warningsEl.removeClass('hidden');
  264. hasMessages = true;
  265. }
  266. if ($infoEl.find('li').length > 0) {
  267. $infoEl.removeClass('hidden');
  268. hasMessages = true;
  269. }
  270. if (hasMessages) {
  271. $('#postsetupchecks-hint').removeClass('hidden');
  272. if ($errorsEl.find('li').length > 0) {
  273. $('#security-warning-state-failure').removeClass('hidden');
  274. } else {
  275. $('#security-warning-state-warning').removeClass('hidden');
  276. }
  277. } else {
  278. var securityWarning = $('#security-warning');
  279. if (securityWarning.children('ul').children().length === 0) {
  280. $('#security-warning-state-ok').removeClass('hidden');
  281. } else {
  282. $('#security-warning-state-failure').removeClass('hidden');
  283. }
  284. }
  285. });
  286. };
  287. if (document.getElementById('security-warning') !== null) {
  288. setupChecks();
  289. }
  290. });