security.html 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  1. {% extends '../layout/admin.html' %}
  2. {% block html_title %}{{ 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="{{ modeValue }}" {% if modeValue == settingForm['security:restrictGuestMode'] %}selected{% endif %} >{{ 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="{{ modeValue }}" {% if modeValue == settingForm['security:registrationMode'] %}selected{% endif %} >{{ 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="例: @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>@crowi.wiki</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>NOTE: </b>Restarting the server is needed if you switch the auth mechanism.</p>
  94. <div class="form-group">
  95. <div class="col-xs-6">
  96. <h4>
  97. <input type="radio" name="settingForm[security:isEnabledPassport]" value="false"
  98. {% if !settingForm['security:isEnabledPassport'] %}checked="checked"{% endif %}>
  99. Official Crowi authentication mechanism
  100. </h4>
  101. <ul>
  102. <li>Username, E-mail and Password authentication</li>
  103. <li>Google OAuth2 authentication</li>
  104. </ul>
  105. </div>
  106. <div class="col-xs-6">
  107. <h4>
  108. <input type="radio" name="settingForm[security:isEnabledPassport]" value="true"
  109. {% if true === settingForm['security:isEnabledPassport'] %}checked="checked"{% endif %}>
  110. <a href="http://passportjs.org/">
  111. <img src="/images/admin/security/passport-logo.svg" class="passport-logo"> Passport
  112. </a> authentication mechanism <small class="text-success">(Recommended)</small>
  113. </h4>
  114. <ul>
  115. <li>Username, E-mail and Password authentication</li>
  116. <li>LDAP authentication</li>
  117. <li class="text-muted">(TBD) <del>Google OAuth2 authentication</del></li>
  118. <li class="text-muted">(TBD) <del>Facebook OAuth2 authentication</del></li>
  119. <li class="text-muted">(TBD) <del>Twitter OAuth authentication</del></li>
  120. <li class="text-muted">(TBD) <del>Github OAuth2 authentication</del></li>
  121. </ul>
  122. </div>
  123. </div>
  124. <div class="form-group">
  125. <div class="col-xs-offset-5 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. <div class="auth-mechanism-configurations m-t-10">
  133. <legend>{{ t('security_setting.Authentication mechanism settings') }}</legend>
  134. {% set isOfficialConfigurationVisible = !isEnabledPassport() %}
  135. <div class="official-crowi-auth-settings" {% if !isOfficialConfigurationVisible %}style="display: none;"{% endif %}>
  136. {% set isRestartingServerNeeded = isPassportLocalStrategySetup() %}
  137. <p class="alert alert-warning"
  138. {% if !isRestartingServerNeeded %}style="display: none;"{% endif %}>
  139. <b>
  140. <i class="icon-exclamation" aria-hidden="true"></i>
  141. Restarting the server is needed.
  142. </b>
  143. The server is running with Passport authentication mechanism.
  144. </p>
  145. <form action="/_api/admin/security/google" method="post" class="form-horizontal" id="googleSetting" role="form"
  146. {% if isRestartingServerNeeded %}style="opacity: 0.4;"{% endif %}>
  147. <fieldset>
  148. <h4>Google 設定</h4>
  149. <p class="well alert-anchor">
  150. Google Cloud Platform の <a href="https://console.cloud.google.com/apis/credentials">API Manager</a>
  151. から OAuth2 Client ID を作成すると、Google アカウントにコネクトして登録やログインが可能になります。
  152. </p>
  153. <ol class="help-block">
  154. <li><a href="https://console.cloud.google.com/apis/credentials">API Manager</a> へアクセス</li>
  155. <li>プロジェクトを作成していない場合は作成してください</li>
  156. <li>「認証情報を作成」-> OAuthクライアントID</li>
  157. <ol>
  158. <li>「ウェブアプリケーション」を選択</li>
  159. <li>承認済みのリダイレクトURLに、 <code>https://${crowi.host}/google/callback</code> を入力<br>
  160. (<code>${crowi.host}</code>は環境に合わせて変更してください)</li>
  161. </ol>
  162. </ol>
  163. <div class="form-group">
  164. <label for="settingForm[google:clientId]" class="col-xs-3 control-label">Client ID</label>
  165. <div class="col-xs-6">
  166. <input class="form-control" type="text" name="settingForm[google:clientId]" value="{{ settingForm['google:clientId'] }}">
  167. </div>
  168. </div>
  169. <div class="form-group">
  170. <label for="settingForm[google:clientSecret]" class="col-xs-3 control-label">Client Secret</label>
  171. <div class="col-xs-6">
  172. <input class="form-control" type="text" name="settingForm[google:clientSecret]" value="{{ settingForm['google:clientSecret'] }}">
  173. </div>
  174. </div>
  175. <div class="form-group">
  176. <div class="col-xs-offset-3 col-xs-6">
  177. <input type="hidden" name="_csrf" value="{{ csrf() }}">
  178. <button type="submit" class="btn btn-primary">{{ t('Update') }}</button>
  179. </div>
  180. </div>
  181. </fieldset>
  182. </form>
  183. </div>
  184. {#
  185. # passport settings nav
  186. #}
  187. {% set isPassportConfigurationVisible = settingForm['security:isEnabledPassport'] %}
  188. <div class="passport-settings" {% if !isPassportConfigurationVisible %}style="display: none;"{% endif %}>
  189. {% set isRestartingServerNeeded = !isPassportLocalStrategySetup() %}
  190. <p class="alert alert-warning"
  191. {% if !isRestartingServerNeeded %}style="display: none;"{% endif %}>
  192. <b>
  193. <i class="icon-exclamation" aria-hidden="true"></i>
  194. Restarting the server is needed.
  195. </b>
  196. The server is running with Official Crowi authentication mechanism.
  197. </p>
  198. <ul class="nav nav-tabs" role="tablist" {% if isRestartingServerNeeded %}style="opacity: 0.4;"{% endif %}>
  199. <li class="active">
  200. <a href="#passport-ldap" data-toggle="tab" role="tab"><i class="icon-organization"></i> LDAP</a>
  201. </li>
  202. <li>
  203. <a href="#passport-google-oauth" data-toggle="tab" role="tab"><i class="icon-social-google"></i> Google OAuth</a>
  204. </li>
  205. <li>
  206. <a href="#passport-facebook" data-toggle="tab" role="tab"><i class="icon-social-facebook"></i> Facebook</a>
  207. </li>
  208. <li>
  209. <a href="#passport-twitter" data-toggle="tab" role="tab"><i class="icon-social-twitter"></i> Twitter</a>
  210. </li>
  211. <li>
  212. <a href="#passport-github" data-toggle="tab" role="tab"><i class="icon-social-github"></i> Github</a>
  213. </li>
  214. </ul>
  215. <div class="tab-content p-t-10" {% if isRestartingServerNeeded %}style="opacity: 0.4;"{% endif %}>
  216. <div id="passport-ldap" class="tab-pane active" role="tabpanel" >
  217. {% include './widget/passport/ldap.html' with { settingForm: settingForm } %}
  218. </div>
  219. <div id="passport-google-oauth" class="tab-pane" role="tabpanel">
  220. {% include './widget/passport/google-oauth.html' %}
  221. </div>
  222. <div id="passport-facebook" class="tab-pane" role="tabpanel">
  223. {% include './widget/passport/facebook.html' %}
  224. </div>
  225. <div id="passport-twitter" class="tab-pane" role="tabpanel">
  226. {% include './widget/passport/twitter.html' %}
  227. </div>
  228. <div id="passport-github" class="tab-pane" role="tabpanel">
  229. {% include './widget/passport/github.html' %}
  230. </div>
  231. </div><!-- /.tab-content -->
  232. </div>
  233. </div><!-- /.auth-mechanism-configurations -->
  234. </div>
  235. </div>
  236. <script>
  237. $('#generalSetting, #googleSetting, #mechanismSetting').each(function() {
  238. $(this).submit(function()
  239. {
  240. function showMessage(formId, msg, status) {
  241. $('#' + formId + ' > .alert').remove();
  242. if (!status) {
  243. status = 'success';
  244. }
  245. var $message = $('<p class="alert"></p>');
  246. $message.addClass('alert-' + status);
  247. $message.html(msg.replace('\n', '<br>'));
  248. $message.insertAfter('#' + formId + ' .alert-anchor');
  249. if (status == 'success') {
  250. setTimeout(function()
  251. {
  252. $message.fadeOut({
  253. complete: function() {
  254. $message.remove();
  255. }
  256. });
  257. }, 5000);
  258. }
  259. }
  260. var $form = $(this);
  261. var $id = $form.attr('id');
  262. var $button = $('button', this);
  263. $button.attr('disabled', 'disabled');
  264. var jqxhr = $.post($form.attr('action'), $form.serialize(), function(data)
  265. {
  266. if (data.status) {
  267. showMessage($id, '更新しました');
  268. } else {
  269. showMessage($id, data.message, 'danger');
  270. }
  271. })
  272. .fail(function() {
  273. showMessage($id, 'エラーが発生しました', 'danger');
  274. })
  275. .always(function() {
  276. $button.prop('disabled', false);
  277. });
  278. return false;
  279. });
  280. });
  281. // switch display according to on / off of radio buttons
  282. $('input[name="settingForm[security:isEnabledPassport]"]:radio').change(function() {
  283. const isEnabledPassport = ($(this).val() === "true");
  284. if (isEnabledPassport) {
  285. $('.official-crowi-auth-settings').hide(400);
  286. $('.passport-settings').show(400);
  287. }
  288. else {
  289. $('.official-crowi-auth-settings').show(400);
  290. $('.passport-settings').hide(400);
  291. }
  292. });
  293. </script>
  294. </div>
  295. {% endblock content_main %}
  296. {% block content_footer %}
  297. {% endblock content_footer %}