security.html 15 KB

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