コード例 #1
0
def f_history():
    if request.method == "GET":
        action = actions.Action()
        history = action.history()
        return dumps(history)
    else:
        abort(405)
コード例 #2
0
ファイル: panel_actions.py プロジェクト: ivanleoncz/Shell-WA
def f_actions():
    if request.method == "GET":
        if "logged_in" in session:
            action = actions.Action()
            list_actions = action.show()
            return dumps(list_actions)
        abort(401)  # Not Authorized (must authenticate)
    else:
        abort(405)  # Method Not Allowed
コード例 #3
0
ファイル: panel_actions.py プロジェクト: ivanleoncz/Shell-WA
def f_actions_run(action_id):
    if request.method == "GET":
        if "logged_in" in session:
            username = request.cookies.get("username")
            action = actions.Action()
            result = action.run(action_id, username)
            return str(result)
        return redirect("/login")
    else:
        abort(405)  # Method Not Allowed
コード例 #4
0
ファイル: panel_actions.py プロジェクト: ivanleoncz/Shell-WA
def f_actions_update(action_id):
    if request.method == "GET":
        if "logged_in" in session:
            api_uri = "http://127.0.0.1:5000/api/v1.0/actions" + "/" + action_id
            update_action = actions.Action()
            r = requests.get(api_uri)
            return render_template("action_form.html", action_data=r.text)
        return redirect("/login")
    else:
        abort(405)  # Method Not Allowed
コード例 #5
0
def f_actions(action_id=None):
    if request.method == "POST":
        # Create
        name = request.form.get("name")
        command = request.form.get("command")
        new_action = actions.Action()
        result = new_action.create(name, command)
        return str(result)
    elif request.method == "GET":
        # Read
        if action_id is None:
            created_actions = actions.Action()
            result = created_actions.show()
            return str(result)
        else:
            created_action = actions.Action()
            result = created_action.show(action_id)
            return str(result)
    elif request.method == "PUT":
        # Update
        if actions_id is not None:
            name = request.form.get("name")
            command = request.form.get("command")
            update_action = actions.Actions()
            result = update_action.update(action_id, name, command)
            return str(result)
        else:
            abort(400)  # Bad Request
    elif request.method == "DELETE":
        # Delete
        if action_id is not None:
            delete_action = actions.Actions()
            result = delete_action.delete(action_id)
            return str(result)
        else:
            abort(400)  # Bad Request
    else:
        abort(405)  # Method Not Allowed
コード例 #6
0
ファイル: tests.py プロジェクト: ivanleoncz/Shell-WA
#!/usr/bin/python3

import unittest
from app.modules import actions

action = actions.Action("/app/modules")


class Test(unittest.TestCase):

    action_id = "1"
    name = "Create File"
    command = "touch /tmp/file.new"
    user = "******"

    def test01_create_action(self):
        self.assertEqual(action.create(Test.name, Test.command), "OK")

    def test02_read_action(self):
        self.assertIsInstance(action.read(Test.action_id), list)

    def test03_read_all_actions(self):
        self.assertIsInstance(action.read(), list)

    def test04_update_action(self):
        self.assertEqual(
            action.update(Test.action_id, Test.name, Test.command), "OK")

    def test05_delete_action(self):
        self.assertEqual(action.delete(Test.command), "OK")