2
0

security.html 15 KB

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