security.html 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. {% extends '../layout/admin.html' %}
  2. {% block html_title %}セキュリティ · {% endblock %}
  3. {% block content_head %}
  4. <div class="header-wrap">
  5. <header id="page-header">
  6. <h1 class="title" id="">カスタマイズ</h1>
  7. </header>
  8. </div>
  9. {% endblock %}
  10. {% block content_main %}
  11. <div class="content-main">
  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>基本設定</legend>
  36. <div class="form-group">
  37. <label for="settingForm[security:registrationMode]" class="col-xs-3 control-label">Basic認証</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="">パスワード</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. Basic認証を設定すると、ページ全体に共通の認証がかかります。<br>
  49. IDとパスワードは暗号化されずに送信されるのでご注意下さい。<br>
  50. </p>
  51. </div>
  52. </div>
  53. <div class="form-group">
  54. <label for="settingForm[security:restrictGuestMode]" class="col-xs-3 control-label">ゲストユーザーのアクセス</label>
  55. <div class="col-xs-6">
  56. <select class="form-control" 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">登録の制限</label>
  65. <div class="col-xs-6">
  66. <select class="form-control" 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">ここに入力した内容は、ヘッダー等に表示されます。</p>
  72. </div>
  73. </div>
  74. <div class="form-group">
  75. <label for="settingForm[security:registrationWhiteList]" class="col-xs-3 control-label">登録許可メールアドレスの<br>ホワイトリスト</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">登録可能なメールアドレスを制限することができます。例えば、会社で使う場合、<code>@crowi.wiki</code> などと記載すると、その会社のメールアドレスを持っている人のみ登録可能になります。<br>
  79. 1行に1メールアドレス入力してください。</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">更新</button>
  86. </div>
  87. </div>
  88. </fieldset>
  89. </form>
  90. <form action="/_api/admin/security/mechanism" method="post" class="form-horizontal" id="mechanismSetting" role="form">
  91. <fieldset>
  92. <legend>認証機構設定</legend>
  93. <p class="alert alert-info"><b>NOTE: </b>Reboot the server and apply the changes</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 class="text-muted">(TBD) <del>LDAP authentication</del></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">更新</button>
  128. </div>
  129. </div>
  130. </form>
  131. <div class="auth-mechanism-configurations">
  132. <form action="/_api/admin/security/google" method="post" class="form-horizontal official-crowi-auth-settings" id="googleSetting" role="form"
  133. {% if true === settingForm['security:isEnabledPassport'] %}style="display: none;"{% endif %}>
  134. <fieldset>
  135. <h3>Google 設定</h3>
  136. <p class="well">
  137. Google Cloud Platform の <a href="https://console.cloud.google.com/apis/credentials">API Manager</a>
  138. から OAuth2 Client ID を作成すると、Google アカウントにコネクトして登録やログインが可能になります。
  139. </p>
  140. <ol class="help-block">
  141. <li><a href="https://console.cloud.google.com/apis/credentials">API Manager</a> へアクセス</li>
  142. <li>プロジェクトを作成していない場合は作成してください</li>
  143. <li>「認証情報を作成」-> OAuthクライアントID</li>
  144. <ol>
  145. <li>「ウェブアプリケーション」を選択</li>
  146. <li>承認済みのリダイレクトURLに、 <code>https://${crowi.host}/google/callback</code> を入力<br>
  147. (<code>${crowi.host}</code>は環境に合わせて変更してください)</li>
  148. </ol>
  149. </ol>
  150. <div class="form-group">
  151. <label for="settingForm[google:clientId]" class="col-xs-3 control-label">Client ID</label>
  152. <div class="col-xs-6">
  153. <input class="form-control" type="text" name="settingForm[google:clientId]" value="{{ settingForm['google:clientId'] }}">
  154. </div>
  155. </div>
  156. <div class="form-group">
  157. <label for="settingForm[google:clientSecret]" class="col-xs-3 control-label">Client Secret</label>
  158. <div class="col-xs-6">
  159. <input class="form-control" type="text" name="settingForm[google:clientSecret]" value="{{ settingForm['google:clientSecret'] }}">
  160. </div>
  161. </div>
  162. <div class="form-group">
  163. <div class="col-xs-offset-3 col-xs-6">
  164. <input type="hidden" name="_csrf" value="{{ csrf() }}">
  165. <button type="submit" class="btn btn-primary">更新</button>
  166. </div>
  167. </div>
  168. </fieldset>
  169. </form>
  170. {#
  171. # passport settings nav
  172. #}
  173. <ul class="nav nav-tabs passport-settings" role="tablist" {% if !settingForm['security:isEnabledPassport'] %}style="display: none;"{% endif %}>
  174. <li class="active">
  175. <a href="#passport-ldap" data-toggle="tab" role="tab"><i class="fa fa-sitemap"></i> LDAP</a>
  176. </li>
  177. <li>
  178. <a href="#passport-google-oauth" data-toggle="tab" role="tab"><i class="fa fa-google"></i> Google OAuth</a>
  179. </li>
  180. <li>
  181. <a href="#passport-facebook" data-toggle="tab" role="tab"><i class="fa fa-facebook"></i> Facebook</a>
  182. </li>
  183. <li>
  184. <a href="#passport-twitter" data-toggle="tab" role="tab"><i class="fa fa-twitter"></i> Twitter</a>
  185. </li>
  186. <li>
  187. <a href="#passport-github" data-toggle="tab" role="tab"><i class="fa fa-github"></i> Github</a>
  188. </li>
  189. </ul>
  190. <div class="tab-content passport-settings" {% if !settingForm['security:isEnabledPassport'] %}style="display: none;"{% endif %}>
  191. <div id="passport-ldap" class="tab-pane active" role="tabpanel" >
  192. {% include './widget/passport/ldap.html' %}
  193. </div>
  194. <div id="passport-google-oauth" class="tab-pane" role="tabpanel">
  195. {% include './widget/passport/google-oauth.html' %}
  196. </div>
  197. <div id="passport-facebook" class="tab-pane" role="tabpanel">
  198. {% include './widget/passport/facebook.html' %}
  199. </div>
  200. <div id="passport-twitter" class="tab-pane" role="tabpanel">
  201. {% include './widget/passport/twitter.html' %}
  202. </div>
  203. <div id="passport-github" class="tab-pane" role="tabpanel">
  204. {% include './widget/passport/github.html' %}
  205. </div>
  206. </div><!-- /.tab-content -->
  207. </div><!-- /.auth-mechanism-configurations -->
  208. </div>
  209. </div>
  210. <script>
  211. $('#generalSetting, #googleSetting, #mechanismSetting').each(function() {
  212. $(this).submit(function()
  213. {
  214. function showMessage(formId, msg, status) {
  215. $('#' + formId + ' > .alert').remove();
  216. if (!status) {
  217. status = 'success';
  218. }
  219. var $message = $('<p class="alert"></p>');
  220. $message.addClass('alert-' + status);
  221. $message.html(msg.replace('\n', '<br>'));
  222. $message.insertAfter('#' + formId + ' legend');
  223. if (status == 'success') {
  224. setTimeout(function()
  225. {
  226. $message.fadeOut({
  227. complete: function() {
  228. $message.remove();
  229. }
  230. });
  231. }, 5000);
  232. }
  233. }
  234. var $form = $(this);
  235. var $id = $form.attr('id');
  236. var $button = $('button', this);
  237. $button.attr('disabled', 'disabled');
  238. var jqxhr = $.post($form.attr('action'), $form.serialize(), function(data)
  239. {
  240. if (data.status) {
  241. showMessage($id, '更新しました');
  242. } else {
  243. showMessage($id, data.message, 'danger');
  244. }
  245. })
  246. .fail(function() {
  247. showMessage($id, 'エラーが発生しました', 'danger');
  248. })
  249. .always(function() {
  250. $button.prop('disabled', false);
  251. });
  252. return false;
  253. });
  254. });
  255. // switch display according to on / off of radio buttons
  256. $('input[name="settingForm[security:isEnabledPassport]"]:radio').change(function() {
  257. const isEnabledPassport = ($(this).val() === "true");
  258. if (isEnabledPassport) {
  259. $('.official-crowi-auth-settings').hide(400);
  260. $('.passport-settings').show(400);
  261. }
  262. else {
  263. $('.official-crowi-auth-settings').show(400);
  264. $('.passport-settings').hide(400);
  265. }
  266. });
  267. </script>
  268. </div>
  269. {% endblock content_main %}
  270. {% block content_footer %}
  271. {% endblock content_footer %}