security.html 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  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">
  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">{{ 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">{{ 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. <div class="col-xs-offset-3 col-xs-6">
  88. <input type="hidden" name="_csrf" value="{{ csrf() }}">
  89. <button type="submit" class="btn btn-primary">{{ t('Update') }}</button>
  90. </div>
  91. </div>
  92. </fieldset>
  93. </form>
  94. <!-- prevent XSS link -->
  95. <div class="mt-5">
  96. <legend>{{ t('security_setting.xss_prevent_setting') }}</legend>
  97. <div class="text-center">
  98. <a class="flexbox" style="font-size: large;" href="/admin/markdown/#preventXSS">
  99. <i class="fa-fw icon-login"></i> {{ t('security_setting.xss_prevent_setting_link') }}
  100. </a>
  101. </div>
  102. </div>
  103. <form action="/_api/admin/security/mechanism" method="post" class="form-horizontal mt-5" id="mechanismSetting" role="form">
  104. <fieldset>
  105. <legend class="alert-anchor">{{ t('Selecting authentication mechanism') }}</legend>
  106. <p class="alert alert-info"><b>{{ t("security_setting.note") }}: </b>{{ t("security_setting.require_server_restart_change_auth") }}</p>
  107. <div class="form-group">
  108. <div class="col-xs-6">
  109. <h4>
  110. <div class="radio radio-primary">
  111. <input type="radio" id="radioPassportAuthMech" name="settingForm[security:isEnabledPassport]" value="true"
  112. {% if true === settingForm['security:isEnabledPassport'] %}checked="checked"{% endif %}>
  113. <label for="radioPassportAuthMech">
  114. <a href="http://passportjs.org/" target="_blank">
  115. <img src="/images/admin/security/passport-logo.svg" class="passport-logo"> Passport
  116. </a> {{ t("security_setting.auth_mechanism") }} <small class="text-success">({{ t("security_setting.recommended") }})</small>
  117. </label>
  118. </div>
  119. </h4>
  120. <ul>
  121. <li>{{ t("security_setting.username_email_password") }}</li>
  122. <li>{{ t("security_setting.ldap_auth") }}</li>
  123. <li>{{ t("security_setting.saml_auth") }}</li>
  124. <li>{{ t("security_setting.google_auth2") }}</li>
  125. <li>{{ t("security_setting.github_auth2") }}</li>
  126. <li>{{ t("security_setting.twitter_auth2") }}</li>
  127. <li class="text-muted">(TBD) <del>{{ t("security_setting.facebook_auth2") }}</del></li>
  128. </ul>
  129. </div>
  130. <div class="col-xs-6">
  131. <h4>
  132. <div class="radio radio-primary">
  133. <input type="radio" id="radioCrowiAuthMech" name="settingForm[security:isEnabledPassport]" value="false"
  134. {% if !settingForm['security:isEnabledPassport'] %}checked="checked"{% endif %}>
  135. <label for="radioCrowiAuthMech">
  136. Crowi Classic {{ t("security_setting.auth_mechanism") }}
  137. </label>
  138. </div>
  139. </h4>
  140. <ul>
  141. <li>{{ t("security_setting.username_email_password") }}</li>
  142. <li class="text-muted">
  143. {{ t("security_setting.google_auth2") }}
  144. <ul><li>{{ t("security_setting.google_auth2_by_crowi_desc") }}</li></ul>
  145. </li>
  146. </ul>
  147. </div>
  148. </div>
  149. <div class="form-group">
  150. <div class="col-xs-offset-5 col-xs-6">
  151. <input type="hidden" name="_csrf" value="{{ csrf() }}">
  152. <button type="submit" class="btn btn-primary">{{ t('Update') }}</button>
  153. </div>
  154. </div>
  155. </fieldset>
  156. </form>
  157. <div class="auth-mechanism-configurations m-t-10">
  158. <legend>{{ t('security_setting.Authentication mechanism settings') }}</legend>
  159. {% set isOfficialConfigurationVisible = !isEnabledPassport() %}
  160. <div class="official-crowi-auth-settings" {% if !isOfficialConfigurationVisible %}style="display: none;"{% endif %}>
  161. {% set isRestartingServerNeeded = isPassportLocalStrategySetup() %}
  162. <p class="alert alert-warning"
  163. {% if !isRestartingServerNeeded %}style="display: none;"{% endif %}>
  164. <b>
  165. <i class="icon-exclamation" aria-hidden="true"></i>
  166. {{ t("security_setting.require_server_restart") }}
  167. </b>
  168. {{ t("security_setting.server_on_passport_auth") }}
  169. </p>
  170. <form action="/_api/admin/security/google" method="post" class="form-horizontal" id="googleSetting" role="form"
  171. {% if isRestartingServerNeeded %}style="opacity: 0.4;"{% endif %}>
  172. <fieldset>
  173. <h4>{{ t("security_setting.google_setting") }}</h4>
  174. <p class="well alert-anchor">
  175. {{ t("security_setting.connect_api_manager") }}
  176. </p>
  177. <ol class="help-block">
  178. <li>{{ t("security_setting.access_api_manager", "https://console.cloud.google.com/apis/credentials", "API Manager") }}</li>
  179. <li>{{ t("security_setting.create_project") }}</li>
  180. <li>{{ t("security_setting.create_auth_to_oauth") }}</li>
  181. <ol>
  182. <li>{{ t("security_setting.select_webapp") }}</li>
  183. <li>{{ t("security_setting.change_redirect_url") }}</li>
  184. </ol>
  185. </ol>
  186. <div class="form-group">
  187. <label for="settingForm[google:clientId]" class="col-xs-3 control-label">{{ t("security_setting.clientID") }}</label>
  188. <div class="col-xs-6">
  189. <input class="form-control" type="text" name="settingForm[google:clientId]" value="{{ settingForm['google:clientId'] }}">
  190. </div>
  191. </div>
  192. <div class="form-group">
  193. <label for="settingForm[google:clientSecret]" class="col-xs-3 control-label">{{ t("security_setting.client_secret") }}</label>
  194. <div class="col-xs-6">
  195. <input class="form-control" type="text" name="settingForm[google:clientSecret]" value="{{ settingForm['google:clientSecret'] }}">
  196. </div>
  197. </div>
  198. <div class="form-group">
  199. <div class="col-xs-offset-3 col-xs-6">
  200. <input type="hidden" name="_csrf" value="{{ csrf() }}">
  201. <button type="submit" class="btn btn-primary">{{ t('Update') }}</button>
  202. </div>
  203. </div>
  204. </fieldset>
  205. </form>
  206. </div>
  207. {#
  208. # passport settings nav
  209. #}
  210. {% set isPassportConfigurationVisible = settingForm['security:isEnabledPassport'] %}
  211. <div class="passport-settings" {% if !isPassportConfigurationVisible %}style="display: none;"{% endif %}>
  212. {% set isRestartingServerNeeded = !isPassportLocalStrategySetup() %}
  213. <p class="alert alert-warning"
  214. {% if !isRestartingServerNeeded %}style="display: none;"{% endif %}>
  215. <b>
  216. <i class="icon-exclamation" aria-hidden="true"></i>
  217. {{ t("security_setting.require_server_restart") }}
  218. </b>
  219. {{ t("security_setting.server_on_crowi_auth") }}
  220. </p>
  221. <ul class="nav nav-tabs" role="tablist" {% if isRestartingServerNeeded %}style="opacity: 0.4;"{% endif %}>
  222. <li class="active">
  223. <a href="#passport-ldap" data-toggle="tab" role="tab"><i class="fa fa-sitemap"></i> LDAP</a>
  224. </li>
  225. <li>
  226. <a href="#passport-saml" data-toggle="tab" role="tab"><i class="fa fa-key"></i> SAML</a>
  227. </li>
  228. <li>
  229. <a href="#passport-google-oauth" data-toggle="tab" role="tab"><i class="fa fa-google"></i> Google</a>
  230. </li>
  231. <li>
  232. <a href="#passport-github" data-toggle="tab" role="tab"><i class="fa fa-github"></i> GitHub</a>
  233. </li>
  234. <li class="tbd">
  235. <a href="#passport-twitter" data-toggle="tab" role="tab"><i class="fa fa-twitter"></i> Twitter</a>
  236. </li>
  237. <li class="tbd">
  238. <a href="#passport-facebook" data-toggle="tab" role="tab"><i class="fa fa-facebook"></i> (TBD) Facebook</a>
  239. </li>
  240. </ul>
  241. <div class="tab-content p-t-10" {% if isRestartingServerNeeded %}style="opacity: 0.4;"{% endif %}>
  242. <div id="passport-ldap" class="tab-pane active" role="tabpanel" >
  243. {% include './widget/passport/ldap.html' with { settingForm: settingForm } %}
  244. </div>
  245. <div id="passport-saml" class="tab-pane" role="tabpanel" >
  246. {% include './widget/passport/saml.html' %}
  247. </div>
  248. <div id="passport-google-oauth" class="tab-pane" role="tabpanel">
  249. {% include './widget/passport/google-oauth.html' %}
  250. </div>
  251. <div id="passport-facebook" class="tab-pane" role="tabpanel">
  252. {% include './widget/passport/facebook.html' %}
  253. </div>
  254. <div id="passport-twitter" class="tab-pane" role="tabpanel">
  255. {% include './widget/passport/twitter.html' %}
  256. </div>
  257. <div id="passport-github" class="tab-pane" role="tabpanel">
  258. {% include './widget/passport/github.html' %}
  259. </div>
  260. </div><!-- /.tab-content -->
  261. </div>
  262. </div><!-- /.auth-mechanism-configurations -->
  263. </div>
  264. </div>
  265. <script>
  266. $('#generalSetting, #samlSetting, #googleSetting, #mechanismSetting, #githubSetting, #twitterSetting').each(function() {
  267. $(this).submit(function()
  268. {
  269. function showMessage(formId, msg, status) {
  270. $('#' + formId + ' > .alert').remove();
  271. $('#' + formId ).find('.alert').remove();
  272. if (!status) {
  273. status = 'success';
  274. }
  275. var $message = $('<p class="alert"></p>');
  276. $message.addClass('alert-' + status);
  277. $message.html(msg.replace('\n', '<br>'));
  278. $message.insertAfter('#' + formId + ' .alert-anchor');
  279. if (status == 'success') {
  280. setTimeout(function()
  281. {
  282. $message.fadeOut({
  283. complete: function() {
  284. $message.remove();
  285. }
  286. });
  287. }, 5000);
  288. }
  289. }
  290. var $form = $(this);
  291. var $id = $form.attr('id');
  292. var $button = $('button', this);
  293. $button.attr('disabled', 'disabled');
  294. var jqxhr = $.post($form.attr('action'), $form.serialize(), function(data)
  295. {
  296. if (data.status) {
  297. showMessage($id, '更新しました Updated');
  298. } else {
  299. showMessage($id, data.message, 'danger');
  300. }
  301. })
  302. .fail(function() {
  303. showMessage($id, 'エラーが発生しました Error', 'danger');
  304. })
  305. .always(function() {
  306. $button.prop('disabled', false);
  307. });
  308. return false;
  309. });
  310. });
  311. // switch display according to on / off of radio buttons
  312. $('input[name="settingForm[security:isEnabledPassport]"]:radio').change(function() {
  313. const isEnabledPassport = ($(this).val() === "true");
  314. if (isEnabledPassport) {
  315. $('.official-crowi-auth-settings').hide(400);
  316. $('.passport-settings').show(400);
  317. }
  318. else {
  319. $('.official-crowi-auth-settings').show(400);
  320. $('.passport-settings').hide(400);
  321. }
  322. });
  323. </script>
  324. </div>
  325. {% endblock content_main %}
  326. {% block content_footer %}
  327. {% endblock content_footer %}