security.html 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412
  1. {% extends '../layout/admin.html' %}
  2. {% block html_title %}{{ customTitle(t('Security settings')) }} · {% endblock %}
  3. {% block content_header %}
  4. <div class="header-wrap">
  5. <header id="page-header">
  6. <h1 id="admin-title" class="title">{{ t('Security settings') }}</h1>
  7. </header>
  8. </div>
  9. {% endblock %}
  10. {% block content_main %}
  11. <div class="content-main admin-security">
  12. <div class="row">
  13. <div class="col-md-3">
  14. {% include './widget/menu.html' with {current: 'security'} %}
  15. </div>
  16. <div class="col-md-9">
  17. {% set smessage = req.flash('successMessage') %}
  18. {% if smessage.length %}
  19. <div class="alert alert-success">
  20. {% for e in smessage %}
  21. {{ e }}<br>
  22. {% endfor %}
  23. </div>
  24. {% endif %}
  25. {% set emessage = req.flash('errorMessage') %}
  26. {% if emessage.length %}
  27. <div class="alert alert-danger">
  28. {% for e in emessage %}
  29. {{ e }}<br>
  30. {% endfor %}
  31. </div>
  32. {% endif %}
  33. <form action="/_api/admin/security/general" method="post" class="form-horizontal" id="generalSetting" role="form">
  34. <fieldset>
  35. <legend class="alert-anchor">{{ t('security_setting.Security settings') }}</legend>
  36. <div class="form-group">
  37. <label for="settingForm[security:registrationMode]" class="col-xs-3 control-label">{{ t('Basic authentication') }}</label>
  38. <div class="col-xs-3">
  39. <label for="">ID</label>
  40. <input class="form-control" type="text" name="settingForm[security:basicName]" value="{{ settingForm['security:basicName']|default('') }}" {% if not isAclEnabled %}readonly{% endif%}>
  41. </div>
  42. <div class="col-xs-3">
  43. <label for="">{{ t('Password') }}</label>
  44. <input class="form-control" type="text" name="settingForm[security:basicSecret]" value="{{ settingForm['security:basicSecret']|default('') }}" {% if not isAclEnabled %}readonly{% endif%}>
  45. </div>
  46. <div class="col-xs-offset-3 col-xs-9">
  47. <p class="help-block small">
  48. {% if not isAclEnabled %}
  49. {{ t("security_setting.basic_acl_disable") }}<br>
  50. {% else %}
  51. {{ t("security_setting.common_authentication") }}<br>
  52. {{ t("security_setting.without_encryption") }}<br>
  53. {% endif %}
  54. </p>
  55. </div>
  56. </div>
  57. <div class="form-group">
  58. <label for="settingForm[security:restrictGuestMode]" class="col-xs-3 control-label">{{ t('Guest users access') }}</label>
  59. <div class="col-xs-6">
  60. <select class="form-control selectpicker" name="settingForm[security:restrictGuestMode]" value="{{ settingForm['security:restrictGuestMode'] }}">
  61. {% for modeValue, modeLabel in consts.restrictGuestMode %}
  62. <option value="{{ t(modeValue) }}" {% if modeValue == settingForm['security:restrictGuestMode'] %}selected{% endif %} >{{ t(modeLabel) }}</option>
  63. {% endfor %}
  64. </select>
  65. </div>
  66. </div>
  67. <div class="form-group">
  68. <label for="settingForm[security:registrationMode]" class="col-xs-3 control-label">{{ t('Register limitation') }}</label>
  69. <div class="col-xs-6">
  70. <select class="form-control selectpicker" name="settingForm[security:registrationMode]" value="{{ settingForm['security:registrationMode'] }}">
  71. {% for modeValue, modeLabel in consts.registrationMode %}
  72. <option value="{{ t(modeValue) }}" {% if modeValue == settingForm['security:registrationMode'] %}selected{% endif %} >{{ t(modeLabel) }}</option>
  73. {% endfor %}
  74. </select>
  75. <p class="help-block small">{{ t('The contents entered here will be shown in the header etc') }}</p>
  76. </div>
  77. </div>
  78. <div class="form-group">
  79. <label for="settingForm[security:registrationWhiteList]" class="col-xs-3 control-label">{{ t('The whitelist of registration permission E-mail address') }}</label>
  80. <div class="col-xs-8">
  81. <textarea class="form-control" type="textarea" name="settingForm[security:registrationWhiteList]" placeholder="{{ t('security_setting.example') }}: @growi.org">{{ settingForm['security:registrationWhiteList']|join('&#13')|raw }}</textarea>
  82. <p class="help-block small">{{ t("security_setting.restrict_emails") }}{{ t("security_setting.for_instance") }}<code>@growi.org</code>{{ t("security_setting.only_those") }}<br>
  83. {{ t("security_setting.insert_single") }}</p>
  84. </div>
  85. </div>
  86. <div class="form-group">
  87. {% set configName = 'settingForm[security:list-policy:hideRestrictedByOwner]' %}
  88. {% set configValue = settingForm['security:list-policy:hideRestrictedByOwner'] %}
  89. {% set isEnabled = !configValue %}
  90. <label for="{{configName}}" class="col-xs-3 control-label">{{ t("security_setting.page_listing_1") }}</label>
  91. <div class="col-xs-9">
  92. <div class="btn-group btn-toggle" data-toggle="buttons">
  93. <label class="btn btn-default btn-rounded btn-outline {% if isEnabled %}active{% endif %}" data-active-class="primary">
  94. <input name="{{configName}}" value="false" type="radio" {% if isEnabled %}checked{% endif %}> ON
  95. </label>
  96. <label class="btn btn-default btn-rounded btn-outline {% if !isEnabled %}active{% endif %}" data-active-class="default">
  97. <input name="{{configName}}" value="true" type="radio" {% if !isEnabled %}checked{% endif %}> OFF
  98. </label>
  99. </div>
  100. <p class="help-block small">
  101. {{ t("security_setting.page_listing_1_desc") }}
  102. </p>
  103. </div>
  104. </div>
  105. <div class="form-group">
  106. {% set configName = 'settingForm[security:list-policy:hideRestrictedByGroup]' %}
  107. {% set configValue = settingForm['security:list-policy:hideRestrictedByGroup'] %}
  108. {% set isEnabled = !configValue %}
  109. <label for="{{configName}}" class="col-xs-3 control-label">{{ t("security_setting.page_listing_2") }}</label>
  110. <div class="col-xs-9">
  111. <div class="btn-group btn-toggle" data-toggle="buttons">
  112. <label class="btn btn-default btn-rounded btn-outline {% if isEnabled %}active{% endif %}" data-active-class="primary">
  113. <input name="{{configName}}" value="false" type="radio" {% if isEnabled %}checked{% endif %}> ON
  114. </label>
  115. <label class="btn btn-default btn-rounded btn-outline {% if !isEnabled %}active{% endif %}" data-active-class="default">
  116. <input name="{{configName}}" value="true" type="radio" {% if !isEnabled %}checked{% endif %}> OFF
  117. </label>
  118. </div>
  119. <p class="help-block small">
  120. {{ t("security_setting.page_listing_2_desc") }}
  121. </p>
  122. </div>
  123. </div>
  124. <div class="form-group">
  125. <div class="col-xs-offset-3 col-xs-6">
  126. <input type="hidden" name="_csrf" value="{{ csrf() }}">
  127. <button type="submit" class="btn btn-primary">{{ t('Update') }}</button>
  128. </div>
  129. </div>
  130. </fieldset>
  131. </form>
  132. <!-- prevent XSS link -->
  133. <div class="mt-5">
  134. <legend>{{ t('security_setting.xss_prevent_setting') }}</legend>
  135. <div class="text-center">
  136. <a class="flexbox" style="font-size: large;" href="/admin/markdown/#preventXSS">
  137. <i class="fa-fw icon-login"></i> {{ t('security_setting.xss_prevent_setting_link') }}
  138. </a>
  139. </div>
  140. </div>
  141. <form action="/_api/admin/security/mechanism" method="post" class="form-horizontal mt-5" id="mechanismSetting" role="form">
  142. <fieldset>
  143. <legend class="alert-anchor">{{ t('Selecting authentication mechanism') }}</legend>
  144. <p class="alert alert-info"><b>{{ t("security_setting.note") }}: </b>{{ t("security_setting.require_server_restart_change_auth") }}</p>
  145. <div class="form-group">
  146. <div class="col-xs-6">
  147. <h4>
  148. <div class="radio radio-primary">
  149. <input type="radio" id="radioPassportAuthMech" name="settingForm[security:isEnabledPassport]" value="true"
  150. {% if true === settingForm['security:isEnabledPassport'] %}checked="checked"{% endif %}>
  151. <label for="radioPassportAuthMech">
  152. <a href="http://passportjs.org/" target="_blank">
  153. <img src="/images/admin/security/passport-logo.svg" class="passport-logo"> Passport
  154. </a> {{ t("security_setting.auth_mechanism") }} <small class="text-success">({{ t("security_setting.recommended") }})</small>
  155. </label>
  156. </div>
  157. </h4>
  158. <ul>
  159. <li>{{ t("security_setting.username_email_password") }}</li>
  160. <li>{{ t("security_setting.ldap_auth") }}</li>
  161. <li>{{ t("security_setting.saml_auth") }}</li>
  162. <li>{{ t("security_setting.google_auth2") }}</li>
  163. <li>{{ t("security_setting.github_auth2") }}</li>
  164. <li>{{ t("security_setting.twitter_auth2") }}</li>
  165. <li class="text-muted">(TBD) <del>{{ t("security_setting.facebook_auth2") }}</del></li>
  166. </ul>
  167. </div>
  168. <div class="col-xs-6">
  169. <h4>
  170. <div class="radio radio-primary">
  171. <input type="radio" id="radioCrowiAuthMech" name="settingForm[security:isEnabledPassport]" value="false"
  172. {% if !settingForm['security:isEnabledPassport'] %}checked="checked"{% endif %}>
  173. <label for="radioCrowiAuthMech">
  174. Crowi Classic {{ t("security_setting.auth_mechanism") }}
  175. </label>
  176. </div>
  177. </h4>
  178. <ul>
  179. <li>{{ t("security_setting.username_email_password") }}</li>
  180. <li class="text-muted">
  181. {{ t("security_setting.google_auth2") }}
  182. <ul><li>{{ t("security_setting.google_auth2_by_crowi_desc") }}</li></ul>
  183. </li>
  184. </ul>
  185. </div>
  186. </div>
  187. <div class="form-group">
  188. <div class="col-xs-offset-5 col-xs-6">
  189. <input type="hidden" name="_csrf" value="{{ csrf() }}">
  190. <button type="submit" class="btn btn-primary">{{ t('Update') }}</button>
  191. </div>
  192. </div>
  193. </fieldset>
  194. </form>
  195. <div class="auth-mechanism-configurations m-t-10">
  196. <legend>{{ t('security_setting.Authentication mechanism settings') }}</legend>
  197. {% set isOfficialConfigurationVisible = !isEnabledPassport() %}
  198. <div class="official-crowi-auth-settings" {% if !isOfficialConfigurationVisible %}style="display: none;"{% endif %}>
  199. {% set isRestartingServerNeeded = isPassportLocalStrategySetup() %}
  200. <p class="alert alert-warning"
  201. {% if !isRestartingServerNeeded %}style="display: none;"{% endif %}>
  202. <b>
  203. <i class="icon-exclamation" aria-hidden="true"></i>
  204. {{ t("security_setting.require_server_restart") }}
  205. </b>
  206. {{ t("security_setting.server_on_passport_auth") }}
  207. </p>
  208. <form action="/_api/admin/security/google" method="post" class="form-horizontal" id="googleSetting" role="form"
  209. {% if isRestartingServerNeeded %}style="opacity: 0.4;"{% endif %}>
  210. <fieldset>
  211. <h4>{{ t("security_setting.google_setting") }}</h4>
  212. <p class="well alert-anchor">
  213. {{ t("security_setting.connect_api_manager") }}
  214. </p>
  215. <ol class="help-block">
  216. <li>{{ t("security_setting.access_api_manager", "https://console.cloud.google.com/apis/credentials", "API Manager") }}</li>
  217. <li>{{ t("security_setting.create_project") }}</li>
  218. <li>{{ t("security_setting.create_auth_to_oauth") }}</li>
  219. <ol>
  220. <li>{{ t("security_setting.select_webapp") }}</li>
  221. <li>{{ t("security_setting.change_redirect_url") }}</li>
  222. </ol>
  223. </ol>
  224. <div class="form-group">
  225. <label for="settingForm[google:clientId]" class="col-xs-3 control-label">{{ t("security_setting.clientID") }}</label>
  226. <div class="col-xs-6">
  227. <input class="form-control" type="text" name="settingForm[google:clientId]" value="{{ settingForm['google:clientId'] }}">
  228. </div>
  229. </div>
  230. <div class="form-group">
  231. <label for="settingForm[google:clientSecret]" class="col-xs-3 control-label">{{ t("security_setting.client_secret") }}</label>
  232. <div class="col-xs-6">
  233. <input class="form-control" type="text" name="settingForm[google:clientSecret]" value="{{ settingForm['google:clientSecret'] }}">
  234. </div>
  235. </div>
  236. <div class="form-group">
  237. <div class="col-xs-offset-3 col-xs-6">
  238. <input type="hidden" name="_csrf" value="{{ csrf() }}">
  239. <button type="submit" class="btn btn-primary">{{ t('Update') }}</button>
  240. </div>
  241. </div>
  242. </fieldset>
  243. </form>
  244. </div>
  245. {#
  246. # passport settings nav
  247. #}
  248. {% set isPassportConfigurationVisible = settingForm['security:isEnabledPassport'] %}
  249. <div class="passport-settings" {% if !isPassportConfigurationVisible %}style="display: none;"{% endif %}>
  250. {% set isRestartingServerNeeded = !isPassportLocalStrategySetup() %}
  251. <p class="alert alert-warning"
  252. {% if !isRestartingServerNeeded %}style="display: none;"{% endif %}>
  253. <b>
  254. <i class="icon-exclamation" aria-hidden="true"></i>
  255. {{ t("security_setting.require_server_restart") }}
  256. </b>
  257. {{ t("security_setting.server_on_crowi_auth") }}
  258. </p>
  259. <ul class="nav nav-tabs" role="tablist" {% if isRestartingServerNeeded %}style="opacity: 0.4;"{% endif %}>
  260. <li class="active">
  261. <a href="#passport-ldap" data-toggle="tab" role="tab"><i class="fa fa-sitemap"></i> LDAP</a>
  262. </li>
  263. <li>
  264. <a href="#passport-saml" data-toggle="tab" role="tab"><i class="fa fa-key"></i> SAML</a>
  265. </li>
  266. <li>
  267. <a href="#passport-google-oauth" data-toggle="tab" role="tab"><i class="fa fa-google"></i> Google</a>
  268. </li>
  269. <li>
  270. <a href="#passport-github" data-toggle="tab" role="tab"><i class="fa fa-github"></i> GitHub</a>
  271. </li>
  272. <li>
  273. <a href="#passport-twitter" data-toggle="tab" role="tab"><i class="fa fa-twitter"></i> Twitter</a>
  274. </li>
  275. <li class="tbd">
  276. <a href="#passport-facebook" data-toggle="tab" role="tab"><i class="fa fa-facebook"></i> (TBD) Facebook</a>
  277. </li>
  278. </ul>
  279. <div class="tab-content p-t-10" {% if isRestartingServerNeeded %}style="opacity: 0.4;"{% endif %}>
  280. <div id="passport-ldap" class="tab-pane active" role="tabpanel" >
  281. {% include './widget/passport/ldap.html' with { settingForm: settingForm } %}
  282. </div>
  283. <div id="passport-saml" class="tab-pane" role="tabpanel" >
  284. {% include './widget/passport/saml.html' %}
  285. </div>
  286. <div id="passport-google-oauth" class="tab-pane" role="tabpanel">
  287. {% include './widget/passport/google-oauth.html' %}
  288. </div>
  289. <div id="passport-facebook" class="tab-pane" role="tabpanel">
  290. {% include './widget/passport/facebook.html' %}
  291. </div>
  292. <div id="passport-twitter" class="tab-pane" role="tabpanel">
  293. {% include './widget/passport/twitter.html' %}
  294. </div>
  295. <div id="passport-github" class="tab-pane" role="tabpanel">
  296. {% include './widget/passport/github.html' %}
  297. </div>
  298. </div><!-- /.tab-content -->
  299. </div>
  300. </div><!-- /.auth-mechanism-configurations -->
  301. </div>
  302. </div>
  303. <script>
  304. $('#generalSetting, #samlSetting, #googleSetting, #mechanismSetting, #githubSetting, #twitterSetting').each(function() {
  305. $(this).submit(function()
  306. {
  307. function showMessage(formId, msg, status) {
  308. $('#' + formId + ' > .alert').remove();
  309. $('#' + formId ).find('.alert').remove();
  310. if (!status) {
  311. status = 'success';
  312. }
  313. var $message = $('<p class="alert"></p>');
  314. $message.addClass('alert-' + status);
  315. $message.html(msg.replace('\n', '<br>'));
  316. $message.insertAfter('#' + formId + ' .alert-anchor');
  317. if (status == 'success') {
  318. setTimeout(function()
  319. {
  320. $message.fadeOut({
  321. complete: function() {
  322. $message.remove();
  323. }
  324. });
  325. }, 5000);
  326. }
  327. }
  328. var $form = $(this);
  329. var $id = $form.attr('id');
  330. var $button = $('button', this);
  331. $button.attr('disabled', 'disabled');
  332. var jqxhr = $.post($form.attr('action'), $form.serialize(), function(data)
  333. {
  334. if (data.status) {
  335. showMessage($id, '更新しました Updated');
  336. } else {
  337. showMessage($id, data.message, 'danger');
  338. }
  339. })
  340. .fail(function() {
  341. showMessage($id, 'エラーが発生しました Error', 'danger');
  342. })
  343. .always(function() {
  344. $button.prop('disabled', false);
  345. });
  346. return false;
  347. });
  348. });
  349. // switch display according to on / off of radio buttons
  350. $('input[name="settingForm[security:isEnabledPassport]"]:radio').change(function() {
  351. const isEnabledPassport = ($(this).val() === "true");
  352. if (isEnabledPassport) {
  353. $('.official-crowi-auth-settings').hide(400);
  354. $('.passport-settings').show(400);
  355. }
  356. else {
  357. $('.official-crowi-auth-settings').show(400);
  358. $('.passport-settings').hide(400);
  359. }
  360. });
  361. </script>
  362. </div>
  363. {% endblock content_main %}
  364. {% block content_footer %}
  365. {% endblock content_footer %}