Linux の
OpenSCAP と
OpenSCAPには
Mezzanine の
0. 前提
以下の
OS
CentOS release 6.7 (Final)Python Version
Python 2.7.8Package (必要そうな
ものだけ 抜粋)
Django (1.10)
Mezzanine (4.2.0)
1. OpenSCAPの インストール方法
以下の
記載の
2. やったこと
以下、
2-1. django application を 作成する
DASHBOARD に
django application を
アプリケーション作成
python2.7 manage.py startapp mezzanine_extentions
settings.py に
アプリケーションを 追加 INSTALLED_APPS = ( "mezzanine_extentions", ... )
2-2. OpenSCAP の レポートを 生成する django command を 作成する
cron で
相当手抜きな command に
mezzanine_extentions/management/commands/run_scap.py
# -*- coding: utf-8 -*- from __future__ import print_function from django.core.management.base import BaseCommand from django.conf import settings import subprocess class Command(BaseCommand): def handle(self, *args, **options): print ("-------------------------------------------") print ("run scap START") print ("-------------------------------------------") oscap_xccdf_cmds = [] oscap_xccdf_cmds.append("oscap") oscap_xccdf_cmds.append("xccdf") oscap_xccdf_cmds.append("eval") oscap_xccdf_cmds.append("--report") oscap_xccdf_cmds.append(settings.XCCDF_REPORTS_PATH) oscap_xccdf_cmds.append(settings.XCCDF_FILE_PATH) d = subprocess.check_output(oscap_xccdf_cmds) print(d) oscap_oval_cmds = [] oscap_oval_cmds.append("oscap") oscap_oval_cmds.append("oval") oscap_oval_cmds.append("eval") oscap_oval_cmds.append("--report") oscap_oval_cmds.append(settings.OVAL_REPORTS_PATH) oscap_oval_cmds.append(settings.OVAL_FILE_PATH) d = subprocess.check_output(oscap_oval_cmds) print(d) print ("--------------------------------------------") print ("run scap END") print ("-------------------------")
補足
作成には、
以下の 記事を 参考に しました。
[Python2.7] subprocess の使い 方まとめ - Qiita OpenSCAP の
定義ファイルパスと レポートパスは settings.pyから 指定するようにしました。
2-4. テンプレートタグと、 テンプレートHTMLの 作成
mezzanine_extentions/templatetags/mezzanine_extentions_tags.py 静的リンクのみなので、
何もしない テンプレートです。 from __future__ import unicode_literals from mezzanine import template register = template.Library() @register.inclusion_tag("admin/includes/mezzanine_extentions_scap.html") def scap(): """ Dashboard widget for displaying a reports link. """ pass
mezzanine_extentions/templates/admin/includes/mezzanine_extentions_scap.html 特に
翻訳ファイルを 作ったわけではないですが、
{% trans %}
テンプレートタグ でリンク名称を 記載しました。
div
タグに指定している class="module"
は他の dashboardの テンプレート内で 使われている タグに なります。
このタグ内の h2
、h3
はそれぞれ 背景色が 変わります。 {% load i18n mezzanine_tags %} <div class="module" id="scap_module"> <h2>SCAP reports</h2> <h3><a href="{% url 'oval_report' %}">{% trans "OVAL reports" %}</a></h2> <h3><a href="{% url 'xccdf_report' %}">{% trans "XCCDF reports" %}</a></h2> </div>
2-5. views.pyの 作成
- mezzanine_extentions/views.py
@staff_member_required
デコレータで、ログインしている 人しか、
閲覧不可としました。
静的HTMLの取得方法は いい 方法が わからず、 レポートファイルを openして、
取得した結果を そのまま <wbr>HttpResonse
で返すようにしました。 from django.http import HttpResponse from django.contrib.admin.views.decorators import staff_member_required from django.conf import settings # Create your views here. @staff_member_required def oval_report(request): html = open(settings.OVAL_REPORTS_PATH, "r").read() return HttpResponse(html) @staff_member_required def xccdf_report(request): html = open(settings.XCCDF_REPORTS_PATH, "r").read() return HttpResponse(html)
2-6 urls.pyの 作成
- urls.py
from __future__ import unicode_literals from django.conf.urls import url from mezzanine_extentions import views urlpatterns = [ url("^oval_report/$", views.oval_report, name="oval_report"), url("^xccdf_report/$", views.xccdf_report, name="xccdf_report"), ]
2-7 mezzanine の settings.py と、 urls.py の 編集
settings.py の
“mezzanine_extentions_tags.scap を 追加
DASHBOARDには、3列表示されています。
2列目に追加しました。 DASHBOARD_TAGS = ( ("mezzanine_tags.app_list",), ("admin_backup_tags.admin_backup", "mezzanine_extentions_tags.scap", "comment_tags.recent_comments",), ("mezzanine_tags.recent_actions",),)
url.py に
作成した アプリケーションの url include を 追加 import mezzanine_extentions.urls urlpatterns += i18n_patterns(url("^xyz_monotalk_admin/", include(mezzanine_extentions.urls))
あとは
やった
3. HTTP サーバーを 再起動して、 ログイン
HTTPサーバーを
2列目に
リンクを
管理者だけが
以上です。
コメント