security.html 15 KB

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