-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.py
130 lines (120 loc) · 4.47 KB
/
setup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# -*- coding: utf-8 -*-
from setuphelpers import *
import base64
import configparser
configfile='conf.ini'
config = configparser.ConfigParser()
config.read(configfile, encoding='utf-8')
title = config.get('message','title')
subtile = config.get('message','subtile')
message = (config.get('message','message').replace(config.get('message','message')[0],"").replace(config.get('message','message')[-1],"")).splitlines()
signature = config.get('message','signature')
logo_link = config.get('message','logo_link')
popup_start_time = config.get('task','popup_start_time')
popup_end_time = config.get('task','popup_end_time')
popup_end_time = config.get('task','popup_end_time')
task_name = config.get('task','task_name')
task_enabled = config.getboolean('task','task_enabled')
popup_directly = config.getboolean('task','popup_directly')
popup_at_logon = config.getboolean('task','popup_at_logon')
popup_after_unlock_session = config.getboolean('task','popup_after_unlock_session')
group_objectSid_filter = config.get('task','group_objectSid_filter')
def install():
uninstall()
create_task_xml(b64_msg=convert_message_to_html_b64(msg=message))
run(f'schtasks /create /tn "{task_name}" /xml "{task_name}.xml"')
def uninstall():
if task_exists(task_name):
delete_task(task_name)
def audit():
if task_exists(task_name):
print(f'La tâche planifiée "{task_name}" est bien présente sur le poste')
return "OK"
else:
print(f"La tâche planifiée {task_name} n'existe pas")
install()
return "WARNING"
def convert_message_to_html_b64(msg=None):
[msg.insert(item*2,"<br>") for item in range (0,len(msg))]
html_code = """<h1>
<p style="text-align: center; color: red">%s</p>
<div style="clear:both"></div>
</h1>
<h2 style="text-align: center;">%s</h2>
<br>
%s
<br>
<br>
<b>%s</b>
<br>
<br>
<center>
<img src="%s" alt="Image" style="width:100px;height:100px;"/>
</center>
<br><br>""" % (title,subtile,('\n'.join(msg)),signature,logo_link)
return (base64.b64encode(html_code.encode("utf8"))).decode("ascii")
def create_task_xml(b64_msg=None):
xml_data = """<?xml version="1.0" encoding="UTF-16"?>
<Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
<RegistrationInfo>
<Date>2021-05-21T13:29:24.4192635</Date>
<Author>WAPT</Author>
<URI>\%s</URI>
</RegistrationInfo>
<Triggers>
<LogonTrigger>
<StartBoundary>%s</StartBoundary>
<EndBoundary>%s</EndBoundary>
<Enabled>%s</Enabled>
</LogonTrigger>
<SessionStateChangeTrigger>
<StartBoundary>%s</StartBoundary>
<EndBoundary>%s</EndBoundary>
<Enabled>%s</Enabled>
<StateChange>SessionUnlock</StateChange>
</SessionStateChangeTrigger>
<RegistrationTrigger>
<StartBoundary>%s</StartBoundary>
<EndBoundary>%s</EndBoundary>
<Enabled>%s</Enabled>
</RegistrationTrigger>
</Triggers>
<Principals>
<Principal id="Author">
<GroupId>%s</GroupId>
<RunLevel>LeastPrivilege</RunLevel>
</Principal>
</Principals>
<Settings>
<MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>
<DisallowStartIfOnBatteries>true</DisallowStartIfOnBatteries>
<StopIfGoingOnBatteries>true</StopIfGoingOnBatteries>
<AllowHardTerminate>true</AllowHardTerminate>
<StartWhenAvailable>false</StartWhenAvailable>
<RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable>
<IdleSettings>
<StopOnIdleEnd>true</StopOnIdleEnd>
<RestartOnIdle>true</RestartOnIdle>
</IdleSettings>
<AllowStartOnDemand>true</AllowStartOnDemand>
<Enabled>%s</Enabled>
<Hidden>false</Hidden>
<RunOnlyIfIdle>false</RunOnlyIfIdle>
<WakeToRun>false</WakeToRun>
<ExecutionTimeLimit>PT1H</ExecutionTimeLimit>
<Priority>7</Priority>
</Settings>
<Actions Context="Author">
<Exec>
<Command>waptmessage</Command>
<Arguments>-b %s -s 800X900</Arguments>
</Exec>
</Actions>
</Task>""" % (task_name,
popup_start_time,popup_end_time,str(popup_at_logon).lower(),
popup_start_time,popup_end_time,str(popup_after_unlock_session).lower(),
popup_start_time,popup_end_time,str(popup_directly).lower(),
group_objectSid_filter,str(task_enabled).lower(),
b64_msg)
with open(f"{task_name}.xml", "w+") as xml:
xml.write(xml_data)