Skip to content

Commit

Permalink
Release 0.14.4
Browse files Browse the repository at this point in the history
  • Loading branch information
wh1te909 committed Aug 1, 2022
2 parents 8554cb5 + 9b92d1b commit b174a89
Show file tree
Hide file tree
Showing 17 changed files with 113 additions and 22 deletions.
16 changes: 8 additions & 8 deletions .github/workflows/ci-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@ jobs:
name: Tests
strategy:
matrix:
python-version: ['3.10.4']
python-version: ["3.10.4"]

steps:
- uses: actions/checkout@v3

- uses: harmon758/postgresql-action@v1
with:
postgresql version: '14'
postgresql db: 'pipeline'
postgresql user: 'pipeline'
postgresql password: 'pipeline123456'
postgresql version: "14"
postgresql db: "pipeline"
postgresql user: "pipeline"
postgresql password: "pipeline123456"

- name: Setup Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
Expand All @@ -49,13 +49,13 @@ jobs:
pip install -r requirements.txt -r requirements-test.txt
- name: Codestyle black
working-directory: api/tacticalrmm
working-directory: api
run: |
black --exclude migrations/ --check tacticalrmm
if [ $? -ne 0 ]; then
exit 1
fi
- name: Run django tests
env:
GHACTIONS: "yes"
Expand Down
4 changes: 4 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
"editor.bracketPairColorization.enabled": true,
"editor.guides.bracketPairs": true,
"editor.formatOnSave": true,
"files.associations": {
"**/ansible/**/*.yml": "ansible",
"**/docker/**/docker-compose*.yml": "dockercompose"
},
"files.watcherExclude": {
"files.watcherExclude": {
"**/.git/objects/**": true,
Expand Down
6 changes: 6 additions & 0 deletions api/tacticalrmm/agents/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -532,12 +532,17 @@ def run_script(
wait: bool = False,
run_on_any: bool = False,
history_pk: int = 0,
run_as_user: bool = False,
) -> Any:

from scripts.models import Script

script = Script.objects.get(pk=scriptpk)

# always override if set on script model
if script.run_as_user:
run_as_user = True

parsed_args = script.parse_script_args(self, script.shell, args)

data = {
Expand All @@ -548,6 +553,7 @@ def run_script(
"code": script.code,
"shell": script.shell,
},
"run_as_user": run_as_user,
}

if history_pk != 0:
Expand Down
2 changes: 2 additions & 0 deletions api/tacticalrmm/agents/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ def run_script_email_results_task(
emails: list[str],
args: list[str] = [],
history_pk: int = 0,
run_as_user: bool = False,
):
agent = Agent.objects.get(pk=agentpk)
script = Script.objects.get(pk=scriptpk)
Expand All @@ -163,6 +164,7 @@ def run_script_email_results_task(
timeout=nats_timeout,
wait=True,
history_pk=history_pk,
run_as_user=run_as_user,
)
if r == "timeout":
DebugLog.error(
Expand Down
27 changes: 25 additions & 2 deletions api/tacticalrmm/agents/tests/test_agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,7 @@ def test_send_raw_cmd(self, mock_ret):
"cmd": "ipconfig",
"shell": "cmd",
"timeout": 30,
"run_as_user": False,
}
mock_ret.return_value = "nt authority\\system"
r = self.client.post(url, data, format="json")
Expand Down Expand Up @@ -538,6 +539,7 @@ def test_run_script(self, run_script, email_task):
"output": "wait",
"args": [],
"timeout": 15,
"run_as_user": False,
}

r = self.client.post(url, data, format="json")
Expand All @@ -547,7 +549,12 @@ def test_run_script(self, run_script, email_task):
raise AgentHistory.DoesNotExist

run_script.assert_called_with(
scriptpk=script.pk, args=[], timeout=18, wait=True, history_pk=hist.pk
scriptpk=script.pk,
args=[],
timeout=18,
wait=True,
history_pk=hist.pk,
run_as_user=False,
)
run_script.reset_mock()

Expand All @@ -559,6 +566,7 @@ def test_run_script(self, run_script, email_task):
"timeout": 15,
"emailMode": "default",
"emails": ["[email protected]", "[email protected]"],
"run_as_user": False,
}
r = self.client.post(url, data, format="json")
self.assertEqual(r.status_code, 200)
Expand All @@ -568,6 +576,7 @@ def test_run_script(self, run_script, email_task):
nats_timeout=18,
emails=[],
args=["abc", "123"],
run_as_user=False,
)
email_task.reset_mock()

Expand All @@ -581,6 +590,7 @@ def test_run_script(self, run_script, email_task):
nats_timeout=18,
emails=["[email protected]", "[email protected]"],
args=["abc", "123"],
run_as_user=False,
)

# test fire and forget
Expand All @@ -589,6 +599,7 @@ def test_run_script(self, run_script, email_task):
"output": "forget",
"args": ["hello", "world"],
"timeout": 22,
"run_as_user": True,
}

r = self.client.post(url, data, format="json")
Expand All @@ -598,7 +609,11 @@ def test_run_script(self, run_script, email_task):
raise AgentHistory.DoesNotExist

run_script.assert_called_with(
scriptpk=script.pk, args=["hello", "world"], timeout=25, history_pk=hist.pk
scriptpk=script.pk,
args=["hello", "world"],
timeout=25,
history_pk=hist.pk,
run_as_user=True,
)
run_script.reset_mock()

Expand All @@ -613,6 +628,7 @@ def test_run_script(self, run_script, email_task):
"timeout": 22,
"custom_field": custom_field.pk,
"save_all_output": True,
"run_as_user": False,
}

r = self.client.post(url, data, format="json")
Expand All @@ -627,6 +643,7 @@ def test_run_script(self, run_script, email_task):
timeout=25,
wait=True,
history_pk=hist.pk,
run_as_user=False,
)
run_script.reset_mock()

Expand All @@ -644,6 +661,7 @@ def test_run_script(self, run_script, email_task):
"timeout": 22,
"custom_field": custom_field.pk,
"save_all_output": False,
"run_as_user": False,
}

r = self.client.post(url, data, format="json")
Expand All @@ -658,6 +676,7 @@ def test_run_script(self, run_script, email_task):
timeout=25,
wait=True,
history_pk=hist.pk,
run_as_user=False,
)
run_script.reset_mock()

Expand All @@ -677,6 +696,7 @@ def test_run_script(self, run_script, email_task):
"timeout": 22,
"custom_field": custom_field.pk,
"save_all_output": False,
"run_as_user": False,
}

r = self.client.post(url, data, format="json")
Expand All @@ -691,6 +711,7 @@ def test_run_script(self, run_script, email_task):
timeout=25,
wait=True,
history_pk=hist.pk,
run_as_user=False,
)
run_script.reset_mock()

Expand All @@ -707,6 +728,7 @@ def test_run_script(self, run_script, email_task):
"output": "note",
"args": ["hello", "world"],
"timeout": 22,
"run_as_user": False,
}

r = self.client.post(url, data, format="json")
Expand All @@ -721,6 +743,7 @@ def test_run_script(self, run_script, email_task):
timeout=25,
wait=True,
history_pk=hist.pk,
run_as_user=False,
)
run_script.reset_mock()

Expand Down
15 changes: 13 additions & 2 deletions api/tacticalrmm/agents/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,7 @@ def send_raw_cmd(request, agent_id):
"command": request.data["cmd"],
"shell": shell,
},
"run_as_user": request.data["run_as_user"],
}

hist = AgentHistory.objects.create(
Expand Down Expand Up @@ -691,6 +692,7 @@ def run_script(request, agent_id):
script = get_object_or_404(Script, pk=request.data["script"])
output = request.data["output"]
args = request.data["args"]
run_as_user: bool = request.data["run_as_user"]
req_timeout = int(request.data["timeout"]) + 3

AuditLog.audit_script_run(
Expand All @@ -715,6 +717,7 @@ def run_script(request, agent_id):
timeout=req_timeout,
wait=True,
history_pk=history_pk,
run_as_user=run_as_user,
)
return Response(r)

Expand All @@ -728,6 +731,7 @@ def run_script(request, agent_id):
nats_timeout=req_timeout,
emails=emails,
args=args,
run_as_user=run_as_user,
)
elif output == "collector":
from core.models import CustomField
Expand All @@ -738,6 +742,7 @@ def run_script(request, agent_id):
timeout=req_timeout,
wait=True,
history_pk=history_pk,
run_as_user=run_as_user,
)

custom_field = CustomField.objects.get(pk=request.data["custom_field"])
Expand Down Expand Up @@ -766,13 +771,18 @@ def run_script(request, agent_id):
timeout=req_timeout,
wait=True,
history_pk=history_pk,
run_as_user=run_as_user,
)

Note.objects.create(agent=agent, user=request.user, note=r)
return Response(r)
else:
agent.run_script(
scriptpk=script.pk, args=args, timeout=req_timeout, history_pk=history_pk
scriptpk=script.pk,
args=args,
timeout=req_timeout,
history_pk=history_pk,
run_as_user=run_as_user,
)

return Response(f"{script.name} will now be run on {agent.hostname}")
Expand Down Expand Up @@ -907,7 +917,7 @@ def bulk(request):
shell,
request.data["timeout"],
request.user.username[:50],
run_on_offline=request.data["offlineAgents"],
request.data["run_as_user"],
)
return Response(f"Command will now be run on {len(agents)} agents")

Expand All @@ -919,6 +929,7 @@ def bulk(request):
request.data["args"],
request.data["timeout"],
request.user.username[:50],
request.data["run_as_user"],
)
return Response(f"{script.name} will now be run on {len(agents)} agents")

Expand Down
2 changes: 2 additions & 0 deletions api/tacticalrmm/alerts/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,7 @@ def handle_alert_failure(
wait=True,
full=True,
run_on_any=True,
run_as_user=False,
)

# command was successful
Expand Down Expand Up @@ -591,6 +592,7 @@ def handle_alert_resolve(
wait=True,
full=True,
run_on_any=True,
run_as_user=False,
)

# command was successful
Expand Down
2 changes: 2 additions & 0 deletions api/tacticalrmm/alerts/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1424,6 +1424,7 @@ def test_alert_actions(
"timeout": 30,
"script_args": [],
"payload": {"code": failure_action.code, "shell": failure_action.shell},
"run_as_user": False,
}

nats_cmd.assert_called_with(data, timeout=30, wait=True)
Expand Down Expand Up @@ -1452,6 +1453,7 @@ def test_alert_actions(
"timeout": 35,
"script_args": ["nice_arg"],
"payload": {"code": resolved_action.code, "shell": resolved_action.shell},
"run_as_user": False,
}

nats_cmd.assert_called_with(data, timeout=35, wait=True)
Expand Down
1 change: 1 addition & 0 deletions api/tacticalrmm/autotasks/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ def get_task_actions(self, obj):
),
"shell": script.shell,
"timeout": action["timeout"],
"run_as_user": script.run_as_user,
}
)
if actions_to_remove:
Expand Down
2 changes: 1 addition & 1 deletion api/tacticalrmm/core/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ def _get_failing_data(agents: "QuerySet[Any]") -> Dict[str, bool]:
and task.task_result.status == TaskStatus.FAILING
and task.alert_severity == AlertSeverity.WARNING
):
data["warning"]
data["warning"] = True

return data

Expand Down
18 changes: 18 additions & 0 deletions api/tacticalrmm/scripts/migrations/0018_script_run_as_user.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.0.6 on 2022-07-30 21:05

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('scripts', '0017_auto_20220311_0100'),
]

operations = [
migrations.AddField(
model_name='script',
name='run_as_user',
field=models.BooleanField(default=False),
),
]
1 change: 1 addition & 0 deletions api/tacticalrmm/scripts/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class Script(BaseAuditModel):
supported_platforms = ArrayField(
models.CharField(max_length=20), null=True, blank=True, default=list
)
run_as_user = models.BooleanField(default=False)

def __str__(self):
return self.name
Expand Down
Loading

0 comments on commit b174a89

Please sign in to comment.