Skip to content

Commit f4b4067

Browse files
author
juan jose lopez
committed
add system of lock screen and suspend computer
1 parent 5175ac9 commit f4b4067

20 files changed

+243
-9
lines changed

ansible.yml

+5
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,8 @@
2727
gather_facts: true
2828
roles:
2929
- apple
30+
31+
- hosts: screen_lock
32+
gather_facts: true
33+
roles:
34+
- screen_lock

inventory/local/group_vars/all/all.yml

+9-1
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@ ldap_setup: true
55
kerberos_setup: true
66
sssd_setup: true
77
apple_blk_setup: true
8+
screen_lock_setup: true
89

910
main_uninstall: false
1011
bind9_uninstall: false
1112
ldap_uninstall: false
1213
kerberos_uninstall: false
1314
sssd_uninstall: false
1415
apple_blk_uninstall: false
16+
screen_lock_uninstall: false
1517

1618
domain: '{{ domainbase }}'
1719
openldap_org: '{{ organization }}'
@@ -20,4 +22,10 @@ sudoers: "SUDOers"
2022

2123
backup_hour: 1
2224
backup_minute: 24
23-
backup_days_to_delete: 10
25+
backup_days_to_delete: 10
26+
27+
#Lock screen and suspend computer
28+
name_lock: screen_lock
29+
time_lock: 600
30+
name_suspend: suspend
31+
time_suspend: 1800
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
---
2+
# vars file for universal-domain-controller

inventory/local/hosts.ini

+11-8
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
1-
node-1 ansible_host=192.168.1.44 ansible_port=22 ansible_user='usuario' ansible_sudo_pass=usuario ansible_ssh_private_key_file='~/.ssh/id_rsa.pub'
2-
node-2 ansible_host=192.168.1.36 ansible_port=22 ansible_user='usuario' ansible_sudo_pass=usuario ansible_ssh_private_key_file='~/.ssh/id_rsa.pub'
1+
node-1 ansible_host=192.168.1.35 ansible_port=22 ansible_user='usuario' ansible_sudo_pass=usuario ansible_ssh_private_key_file='~/.ssh/id_rsa.pub'
2+
node-2 ansible_host=192.168.1.33 ansible_port=22 ansible_user='usuario' ansible_sudo_pass=usuario ansible_ssh_private_key_file='~/.ssh/id_rsa.pub'
33

4-
; [bind9]
5-
; node-1
4+
[bind9]
5+
node-1
66

7-
; [ldap]
8-
; node-1
7+
[ldap]
8+
node-1
99

10-
; [kerberos]
11-
; node-1
10+
[kerberos]
11+
node-1
1212

1313
; [apple]
1414
; node-2
1515

1616
[sssd]
17+
node-2
18+
19+
[screen_lock]
1720
node-2

roles/ldap/tasks/install_openldap.yml

+1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454

5555
- include: config_openldap.yml
5656
- include: read_only_openldap.yml
57+
- include: time_lock_screen_and_suspend_openldap.yml
5758
- include: apple_openldap.yml
5859

5960
- name: Copy script backup and logrotate
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
- name: Generate ldif, time lock screen
2+
template:
3+
src: "ldap/slapd.d/time_lock_and_suspend_screen.ldif.j2"
4+
dest: "/etc/ldap/slapd.d/time_lock_and_suspend_screen.ldif"
5+
owner: root
6+
group: root
7+
mode: 0640
8+
9+
- name: Create user, time lock screen
10+
shell: 'ldapadd -x -D {{ openldap_bind_id }} -w {{ openldap_admin_password }} -f /etc/ldap/slapd.d/time_lock_and_suspend_screen.ldif'
11+
ignore_errors: yes
12+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
dn: cn={{ name_lock }},{{ openldap_base }}
2+
cn: {{ name_lock }}
3+
objectClass: organizationalRole
4+
description: {{ name_lock }}-{{ time_lock }}
5+
6+
dn: cn={{ name_suspend }},{{ openldap_base }}
7+
cn: {{ name_suspend }}
8+
objectClass: organizationalRole
9+
description: {{ name_suspend }}-{{ time_suspend }}

roles/screen_lock/README.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# SSSD Role
2+
3+
Guide: https://aws.nz/best-practice/sssd-ldap/

roles/screen_lock/defaults/main.yml

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
---

roles/screen_lock/handlers/main.yml

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
---
2+
# handlers file for screen-lock

roles/screen_lock/meta/main.yml

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
galaxy_info:
2+
author: Guadaltech
3+
description: BLK (Bind9 + LDAP + Kerberos)
4+
license: license (GPLv2, CC-BY, etc)
5+
min_ansible_version: 2.4
6+
platforms:
7+
- name: Ubuntu
8+
versions:
9+
- trusty
10+
- xenial
11+
galaxy_tags: ['kerberos', 'ldap', 'samba', 'sssd', 'xautolock', 'xss-lock', 'domain', 'ubuntu']
12+
dependencies: []
+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
- name: config_systemd | configuring xss
2+
template:
3+
src: "lock.service.j2"
4+
dest: "/etc/systemd/system/lock.service"
5+
owner: root
6+
group: root
7+
mode: 0755
8+
9+
10+
- name: Enable service xss and ensure it is not masked
11+
systemd:
12+
name: lock.service
13+
state: restarted
14+
daemon_reload: yes
15+
enabled: yes
16+
masked: no
17+
18+
- name: config_systemd | configuring xss
19+
template:
20+
src: "init-time-lock.sh.j2"
21+
dest: "/usr/bin/init-time-lock.sh"
22+
owner: root
23+
group: root
24+
mode: 0700
25+
26+
- include: config_suspend.yml
+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
- name: config_systemd | configuring suspend
2+
template:
3+
src: "suspend.service.j2"
4+
dest: "/etc/systemd/system/suspend.service"
5+
owner: root
6+
group: root
7+
mode: 0755
8+
9+
10+
- name: Enable service suspend and ensure it is not masked
11+
systemd:
12+
name: suspend.service
13+
state: restarted
14+
daemon_reload: yes
15+
enabled: yes
16+
masked: no
17+
18+
- name: config_systemd | configuring suspend
19+
template:
20+
src: "init-time-suspend.sh.j2"
21+
dest: "/usr/bin/init-time-suspend.sh"
22+
owner: root
23+
group: root
24+
mode: 0700
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
- name: Recursively remove service lock
2+
file:
3+
path: /etc/systemd/system/lock.service
4+
state: absent
5+
6+
- name: Recursively remove service suspend
7+
file:
8+
path: /etc/systemd/system/suspend.service
9+
state: absent
10+
11+
- name: Recursively remove script lock
12+
file:
13+
path: /usr/bin/init-time-lock.sh
14+
state: absent
15+
16+
- name: Recursively remove script suspend
17+
file:
18+
path: /usr/bin/init-time-suspend.sh
19+
state: absent

roles/screen_lock/tasks/main.yml

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
- include_tasks: config_lock.yml
3+
when: screen_lock_setup == true
4+
5+
- include_tasks: delete_config_lock.yml
6+
when: screen_lock_uninstall == true
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/bin/sh
2+
lock () {
3+
lock_second=$1
4+
for x in /tmp/.X11-unix/*; do
5+
for i in $(loginctl list-users | awk '{ print $1}' | tail -n +2 | head -n -2); do
6+
runuser -l $(id -un $i) -c "DISPLAY=\":${x#/tmp/.X11-unix/X}\" /usr/bin/xprintidle"
7+
time=$(runuser -l $(id -un $i) -c "DISPLAY=\":${x#/tmp/.X11-unix/X}\" /usr/bin/xprintidle")
8+
if [ $time ] ; then
9+
result=$(($time/1000))
10+
if [ $result -ge $lock_second ]; then
11+
/bin/loginctl lock-sessions
12+
fi
13+
fi
14+
done
15+
sleep 5
16+
done
17+
}
18+
19+
if ldapsearch -x -b "cn={{ name_lock }},{{ openldap_base }}" -H ldap://ldap.{{ domain }} ; then
20+
lock_second=$(ldapsearch -x -b "cn={{ name_lock }},{{ openldap_base }}" -H ldap://ldap.{{ domain }} | grep 'description' | cut -d '-' -f 2)
21+
echo "$lock_second" > /etc/lock
22+
else
23+
if -f /etc/lock ; then
24+
lock_second=$(cat /etc/lock)
25+
else
26+
echo "300" > /etc/lock
27+
lock_second=$(cat /etc/lock)
28+
fi
29+
fi
30+
31+
while :
32+
do
33+
lock $lock_second
34+
sleep 1
35+
done
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/bin/sh
2+
suspend () {
3+
suspend_second=$1
4+
for x in /tmp/.X11-unix/*; do
5+
for i in $(loginctl list-users | awk '{ print $1}' | tail -n +2 | head -n -2); do
6+
runuser -l $(id -un $i) -c "DISPLAY=\":${x#/tmp/.X11-unix/X}\" /usr/bin/xprintidle"
7+
time=$(runuser -l $(id -un $i) -c "DISPLAY=\":${x#/tmp/.X11-unix/X}\" /usr/bin/xprintidle")
8+
if [ $time ] ; then
9+
result=$(($time/1000))
10+
if [ $result -ge $suspend_second ]; then
11+
systemctl suspend
12+
fi
13+
fi
14+
done
15+
sleep 5
16+
done
17+
}
18+
19+
20+
if ldapsearch -x -b "cn={{ name_suspend }},{{ openldap_base }}" -H ldap://ldap.{{ domain }} ; then
21+
suspend_second=$(ldapsearch -x -b "cn={{ name_suspend }},{{ openldap_base }}" -H ldap://ldap.{{ domain }} | grep 'description' | cut -d '-' -f 2)
22+
echo "$suspend_second" > /etc/time_suspend
23+
else
24+
if ! -f /etc/time_suspend ; then
25+
suspend_second=$(cat /etc/time_suspend)
26+
else
27+
echo "300" > /etc/time_suspend
28+
suspend_second=$(cat /etc/time_suspend)
29+
fi
30+
fi
31+
32+
while :
33+
do
34+
suspend $suspend_second
35+
sleep 1
36+
done
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[Unit]
2+
Description=LOCK
3+
After=network.target
4+
StartLimitIntervalSec=0
5+
6+
[Service]
7+
Type=simple
8+
Restart=always
9+
RestartSec=1
10+
User=root
11+
ExecStart=/usr/bin/init-time-lock.sh
12+
13+
[Install]
14+
WantedBy=multi-user.target
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[Unit]
2+
Description=XAUTOLOCK-SUSPEND
3+
After=network.target
4+
StartLimitIntervalSec=0
5+
6+
[Service]
7+
Type=simple
8+
Restart=always
9+
RestartSec=1
10+
User=root
11+
ExecStart=/usr/bin/init-time-suspend.sh
12+
13+
[Install]
14+
WantedBy=multi-user.target

roles/screen_lock/vars/main.yml

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
---
2+
# vars file for sssd

0 commit comments

Comments
 (0)