This repository was archived by the owner on Oct 31, 2023. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathlockscreen.lua
More file actions
executable file
·849 lines (757 loc) · 19.6 KB
/
Copy pathlockscreen.lua
File metadata and controls
executable file
·849 lines (757 loc) · 19.6 KB
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
local wibox = require('wibox')
local gears = require('gears')
local awful = require('awful')
local naughty = require('naughty')
local beautiful = require('beautiful')
local filesystem = gears.filesystem
local config_dir = filesystem.get_configuration_dir()
local dpi = beautiful.xresources.apply_dpi
local apps = require('configuration.apps')
local widget_icon_dir = config_dir .. 'configuration/user-profile/'
local config = require('configuration.config')
-- Add paths to package.cpath
package.cpath = package.cpath .. ';' .. config_dir .. '/library/?.so;' .. '/usr/lib/lua-pam/?.so;'
-- Configuration table
local locker_config = {
-- Clock mode
military_clock = config.module.lockscreen.military_clock or false,
-- Fallback password
fallback_password = function()
return config.module.lockscreen.fallback_password or 'toor'
end,
-- Capture a picture using webcam
capture_intruder = config.module.lockscreen.capture_intruder or false,
-- Save location, auto creates
face_capture_dir = config.module.lockscreen.face_capture_dir or '$(xdg-user-dir PICTURES)/Intruders/',
-- Blur background
blur_background = config.module.lockscreen.blur_background or false,
-- Background directory
bg_dir = config.module.lockscreen.bg_dir or (config_dir .. 'theme/wallpapers/'),
-- Default background
bg_image = config.module.lockscreen.bg_image or 'morning-wallpaper.jpg',
-- /tmp directory
tmp_wall_dir = config.module.lockscreen.tmp_wall_dir or '/tmp/awesomewm/' .. os.getenv('USER') .. '/'
}
-- Useful variables (DO NOT TOUCH THESE)
local input_password = nil
local lock_again = nil
local type_again = true
local capture_now = locker_config.capture_intruder
local locked_tag = nil
local uname_text = wibox.widget {
id = 'uname_text',
markup = '$USER',
font = 'Inter Bold 12',
align = 'center',
valign = 'center',
widget = wibox.widget.textbox
}
local caps_text = wibox.widget {
id = 'uname_text',
markup = 'Caps Lock is on',
font = 'Inter Italic 10',
align = 'center',
valign = 'center',
opacity = 0.0,
widget = wibox.widget.textbox
}
local profile_imagebox = wibox.widget {
id = 'user_icon',
image = widget_icon_dir .. 'default.svg',
resize = true,
forced_height = dpi(130),
forced_width = dpi(130),
clip_shape = gears.shape.circle,
widget = wibox.widget.imagebox
}
local clock_format = '<span font="Inter Bold 52">%H:%M</span>'
if not locker_config.military_clock then
clock_format = '<span font="Inter Bold 52">%I:%M %p</span>'
end
-- Create clock widget
local time = wibox.widget.textclock(clock_format, 1)
local wanted_text = wibox.widget {
markup = 'INTRUDER ALERT!',
font = 'Inter Bold 12',
align = 'center',
valign = 'center',
widget = wibox.widget.textbox
}
local msg_table = {
'This incident will be reported.',
'We are watching you.',
'We know where you live.',
'RUN!',
'Yamete, Oniichan~ uwu',
'This will self-destruct in 5 seconds!',
'Image successfully sent!',
'You\'re doomed!',
'Authentication failed!',
'I am watching you.',
'I know where you live.',
'RUN!',
'Your parents must be proud of you.'
}
local wanted_msg = wibox.widget {
markup = 'This incident will be reported!',
font = 'Inter Regular 10',
align = 'center',
valign = 'center',
widget = wibox.widget.textbox
}
local wanted_image = wibox.widget {
image = widget_icon_dir .. 'default.svg',
resize = true,
forced_height = dpi(120),
clip_shape = gears.shape.rounded_rect,
widget = wibox.widget.imagebox
}
local date_value = function()
local ordinal = nil
local date = os.date('%d')
local day = os.date('%A')
local month = os.date('%B')
local first_digit = string.sub(date, 0, 1)
local last_digit = string.sub(date, -1)
if first_digit == '0' then
date = last_digit
end
if last_digit == '1' and date ~= '11' then
ordinal = 'st'
elseif last_digit == '2' and date ~= '12' then
ordinal = 'nd'
elseif last_digit == '3' and date ~= '13' then
ordinal = 'rd'
else
ordinal = 'th'
end
return date .. ordinal .. ' of ' .. month .. ', ' .. day
end
local date = wibox.widget {
markup = date_value(),
font = 'Inter Bold 20',
align = 'center',
valign = 'center',
widget = wibox.widget.textbox
}
local circle_container = wibox.widget {
bg = beautiful.transparent,
forced_width = dpi(140),
forced_height = dpi(140),
shape = gears.shape.circle,
widget = wibox.container.background
}
local locker_arc = wibox.widget {
bg = beautiful.transparent,
forced_width = dpi(140),
forced_height = dpi(140),
shape = function(cr, width, height)
gears.shape.arc(cr, width, height, dpi(5), 0, (math.pi / 2), false, false)
end,
widget = wibox.container.background
}
local rotate_container = wibox.container.rotate()
local locker_widget = wibox.widget {
{
locker_arc,
widget = rotate_container
},
layout = wibox.layout.fixed.vertical
}
-- Rotation direction table
local rotation_direction = {'north', 'west', 'south', 'east'}
-- Red, Green, Yellow, Blue
local red = beautiful.system_red_dark
local green = beautiful.system_green_dark
local yellow = beautiful.system_yellow_dark
local blue = beautiful.system_blue_dark
-- Color table
local arc_color = {red, green, yellow, blue}
-- Processes
local locker = function(s)
local lockscreen = wibox {
screen = s,
visible = false,
ontop = true,
type = 'splash',
width = s.geometry.width,
height = s.geometry.height,
bg = beautiful.background,
fg = beautiful.fg_normal
}
-- Update username textbox
awful.spawn.easy_async_with_shell(
[[
sh -c '
fullname="$(getent passwd `whoami` | cut -d ':' -f 5 | cut -d ',' -f 1 | tr -d "\n")"
if [ -z "$fullname" ];
then
printf "$(whoami)@$(hostname)"
else
printf "$fullname"
fi
'
]],
function(stdout)
stdout = stdout:gsub('%\n','')
uname_text:set_markup(stdout)
end
)
local update_profile_pic = function()
awful.spawn.easy_async_with_shell(
apps.utils.update_profile,
function(stdout)
stdout = stdout:gsub('%\n','')
if not stdout:match('default') then
profile_imagebox:set_image(stdout)
else
profile_imagebox:set_image(widget_icon_dir .. 'default.svg')
end
end
)
end
-- Update image
gears.timer.start_new(
2,
function()
update_profile_pic()
end
)
local wanted_poster = awful.popup {
widget = {
{
{
wanted_text,
{
nil,
wanted_image,
nil,
expand = 'none',
layout = wibox.layout.align.horizontal
},
wanted_msg,
spacing = dpi(5),
layout = wibox.layout.fixed.vertical
},
margins = dpi(20),
widget = wibox.container.margin
},
bg = beautiful.background,
shape = gears.shape.rounded_rect,
widget = wibox.container.background
},
bg = beautiful.transparent,
type = 'utility',
ontop = true,
shape = gears.shape.rectangle,
maximum_width = dpi(250),
maximum_height = dpi(250),
hide_on_right_click = false,
preferred_anchors = {'middle'},
visible = false
}
-- Place wanted poster at the bottom of primary screen
awful.placement.top(
wanted_poster,
{
margins = {
top = dpi(10)
}
}
)
-- Check Capslock state
local check_caps = function()
awful.spawn.easy_async_with_shell(
'xset q | grep Caps | cut -d: -f3 | cut -d0 -f1 | tr -d \' \'',
function(stdout)
if stdout:match('on') then
caps_text.opacity = 1.0
else
caps_text.opacity = 0.0
end
caps_text:emit_signal('widget::redraw_needed')
end
)
end
-- Rotate the color arc on random direction
local locker_arc_rotate = function()
local direction = rotation_direction[math.random(#rotation_direction)]
local color = arc_color[math.random(#arc_color)]
rotate_container.direction = direction
locker_arc.bg = color
rotate_container:emit_signal('widget::redraw_needed')
locker_arc:emit_signal('widget::redraw_needed')
locker_widget:emit_signal('widget::redraw_needed')
end
-- Check webcam
local check_webcam = function()
awful.spawn.easy_async_with_shell(
'ls -l /dev/video* | grep /dev/video0',
function(stdout)
if not locker_config.capture_intruder then
capture_now = false
return
end
if not stdout:match('/dev/video0') then
capture_now = false
else
capture_now = true
end
end
)
end
check_webcam()
-- Snap an image of the intruder
local intruder_capture = function()
local capture_image = [[
save_dir="]] .. locker_config.face_capture_dir .. [["
date="$(date +%Y%m%d_%H%M%S)"
file_loc="${save_dir}SUSPECT-${date}.png"
if [ ! -d "$save_dir" ]; then
mkdir -p "$save_dir";
fi
ffmpeg -f video4linux2 -s 800x600 -i /dev/video0 -ss 0:0:2 -frames 1 "${file_loc}"
canberra-gtk-play -i camera-shutter &
echo "${file_loc}"
]]
-- Capture the filthy intruder face
awful.spawn.easy_async_with_shell(
capture_image,
function(stdout)
circle_container.bg = beautiful.transparent
-- Humiliate the intruder by showing his/her hideous face
wanted_image:set_image(stdout:gsub('%\n',''))
wanted_msg:set_markup(msg_table[math.random(#msg_table)])
wanted_poster.visible= true
awful.placement.top(
wanted_poster,
{
margins = {
top = dpi(10)
}
}
)
wanted_image:emit_signal('widget::redraw_needed')
type_again = true
end
)
end
-- Login failed
local stoprightthereyoucriminalscum = function()
circle_container.bg = red .. 'AA'
if capture_now then
intruder_capture()
else
gears.timer.start_new(
1,
function()
circle_container.bg = beautiful.transparent
type_again = true
end
)
end
end
-- Login successful
local generalkenobi_ohhellothere = function()
circle_container.bg = green .. 'AA'
-- Add a little delay before unlocking completely
gears.timer.start_new(
1,
function()
if capture_now then
-- Hide wanted poster
wanted_poster.visible = false
end
-- Hide all the lockscreen on all screen
for s in screen do
if s.index == 1 then
s.lockscreen.visible = false
else
s.lockscreen_extended.visible = false
end
end
circle_container.bg = beautiful.transparent
lock_again = true
type_again = true
-- Select old tag
-- And restore minimized focused client if there's any
if locked_tag then
locked_tag.selected = true
locked_tag = nil
end
local c = awful.client.restore()
if c then
c:emit_signal('request::activate')
c:raise()
end
end
)
end
-- A backdoor.
-- Sometimes I'm too lazy to type so I decided to create this.
-- Sometimes my genius is... it's almost frightening.
local back_door = function()
generalkenobi_ohhellothere()
end
-- Check module if valid
local module_check = function(name)
if package.loaded[name] then
return true
else
for _, searcher in ipairs(package.searchers or package.loaders) do
local loader = searcher(name)
if type(loader) == 'function' then
package.preload[name] = loader
return true
end
end
return false
end
end
-- Password/key grabber
local password_grabber = awful.keygrabber {
auto_start = true,
stop_event = 'release',
mask_event_callback = true,
keybindings = {
awful.key {
modifiers = {'Control'},
key = 'u',
on_press = function()
input_password = nil
end
},
awful.key {
modifiers = {'Mod1', 'Mod4', 'Shift', 'Control'},
key = 'Return',
on_press = function(self)
if not type_again then
return
end
self:stop()
-- Call backdoor
back_door()
end
}
},
keypressed_callback = function(self, mod, key, command)
if not type_again then
return
end
-- Clear input string
if key == 'Escape' then
-- Clear input threshold
input_password = nil
return
end
-- Accept only the single charactered key
-- Ignore 'Shift', 'Control', 'Return', 'F1', 'F2', etc., etc.
if #key == 1 then
locker_arc_rotate()
if input_password == nil then
input_password = key
return
end
input_password = input_password .. key
end
end,
keyreleased_callback = function(self, mod, key, command)
locker_arc.bg = beautiful.transparent
locker_arc:emit_signal('widget::redraw_needed')
if key == 'Caps_Lock' then
check_caps()
return
end
if not type_again then
return
end
-- Validation
if key == 'Return' then
-- Validate password
local authenticated = false
if input_password ~= nil then
-- If lua-pam library is 'okay'
if module_check('liblua_pam') then
local pam = require('liblua_pam')
authenticated = pam:auth_current_user(input_password)
else
-- Library doesn't exist or returns an error due to some reasons (read the manual)
-- Use fallback password data
authenticated = input_password == locker_config.fallback_password()
local rtfm = naughty.action {
name = 'Read Wiki',
icon_only = false
}
local dismiss = naughty.action {
name = 'Dismiss',
icon_only = false
}
rtfm:connect_signal(
'invoked',
function()
awful.spawn(
[[sh -c "
xdg-open 'https://github.com/manilarome/the-glorious-dotfiles/wiki'
"]],
false
)
end
)
naughty.notification({
app_name = 'Security',
title = 'WARNING',
message = 'You\'re using the fallback password! It\'s recommended to use the PAM Integration!',
urgency = 'critical',
actions = { rtfm, dismiss }
})
end
end
if authenticated then
-- Come in!
self:stop()
generalkenobi_ohhellothere()
else
-- F*ck off, you [REDACTED]!
stoprightthereyoucriminalscum()
end
-- Allow typing again and empty password container
type_again = false
input_password = nil
end
end
}
lockscreen : setup {
layout = wibox.layout.align.vertical,
expand = 'none',
nil,
{
layout = wibox.layout.align.horizontal,
expand = 'none',
nil,
{
layout = wibox.layout.fixed.vertical,
expand = 'none',
spacing = dpi(20),
{
{
layout = wibox.layout.align.horizontal,
expand = 'none',
nil,
time,
nil
},
{
layout = wibox.layout.align.horizontal,
expand = 'none',
nil,
date,
nil
},
expand = 'none',
layout = wibox.layout.fixed.vertical
},
{
layout = wibox.layout.fixed.vertical,
{
circle_container,
locker_widget,
{
layout = wibox.layout.align.vertical,
expand = 'none',
nil,
{
layout = wibox.layout.align.horizontal,
expand = 'none',
nil,
profile_imagebox,
nil
},
nil,
},
layout = wibox.layout.stack
},
uname_text,
caps_text
},
},
nil
},
nil
}
local show_lockscreen = function()
-- Why is there a lock_again variable?
-- It prevents the user to spam locking while in a process of authentication
-- Prevents a potential bug/problem
if lock_again == true or lock_again == nil then
-- Force update clock widget
time:emit_signal('widget::redraw_needed')
-- Check capslock status
check_caps()
-- Check webcam status
check_webcam()
-- Show all the lockscreen on each screen
for s in screen do
if s.index == 1 then
s.lockscreen.visible = true
else
s.lockscreen_extended.visible = true
end
end
-- Start keygrabbing, but with a little delay to
-- give some extra time for the free_keygrab function
gears.timer.start_new(
0.5,
function()
-- Start key grabbing for password
password_grabber:start()
end
)
-- Dont lock again
lock_again = false
end
end
local free_keygrab = function()
-- Kill rofi instance.
awful.spawn.with_shell('kill -9 $(pgrep rofi)')
-- Check if there's a keygrabbing instance.
-- If yes, stop it.
local keygrabbing_instance = awful.keygrabber.current_instance
if keygrabbing_instance then
keygrabbing_instance:stop()
end
-- Unselect all tags and minimize the focused client
-- These will fix the problem with virtualbox or
-- any other program that has keygrabbing enabled
if client.focus then
client.focus.minimized = true
end
for _, t in ipairs(mouse.screen.selected_tags) do
locked_tag = t
t.selected = false
end
end
awesome.connect_signal(
'module::lockscreen_show',
function()
if lock_again == true or lock_again == nil then
free_keygrab()
show_lockscreen()
end
end
)
return lockscreen
end
-- This lockscreen is for the extra/multi monitor
local locker_ext = function(s)
local extended_lockscreen = wibox {
screen = s,
visible = false,
ontop = true,
ontype = 'true',
x = s.geometry.x,
y = s.geometry.y,
width = s.geometry.width,
height = s.geometry.height,
bg = beautiful.background,
fg = beautiful.fg_normal
}
return extended_lockscreen
end
-- Create lockscreen for each screen
local create_lock_screens = function(s)
if s.index == 1 then
s.lockscreen = locker(s)
else
s.lockscreen_extended = locker_ext(s)
end
end
-- Don't show notification popups if the screen is locked
local check_lockscreen_visibility = function()
focused = awful.screen.focused()
if focused.lockscreen and focused.lockscreen.visible then
return true
end
if focused.lockscreen_extended and focused.lockscreen_extended.visible then
return true
end
return false
end
-- Notifications signal
naughty.connect_signal(
'request::display',
function(_)
if check_lockscreen_visibility() then
naughty.destroy_all_notifications(nil, 1)
end
end
)
-- Filter background image
local filter_bg_image = function(wall_name, index, ap, width, height)
-- Checks if the blur has to be blurred
local blur_filter_param = ''
if locker_config.blur_background then
blur_filter_param = '-filter Gaussian -blur 0x10'
end
-- Create imagemagick command
local magic = [[
sh -c "
if [ ! -d ]] .. locker_config.tmp_wall_dir ..[[ ];
then
mkdir -p ]] .. locker_config.tmp_wall_dir .. [[;
fi
convert -quality 100 -brightness-contrast -20x0 ]] .. ' ' .. blur_filter_param .. ' '.. locker_config.bg_dir .. wall_name ..
[[ -gravity center -crop ]] .. ap .. [[:1 +repage -resize ]] .. width .. 'x' .. height ..
[[! ]] .. locker_config.tmp_wall_dir .. index .. wall_name .. [[
"]]
return magic
end
-- Apply lockscreen background image
local apply_ls_bg_image = function(wall_name)
-- Iterate through all the screens and create a lockscreen for each of it
for s in screen do
local index = s.index .. '-'
-- Get screen geometry
local screen_width = s.geometry.width
local screen_height = s.geometry.height
-- Get the right resolution/aspect ratio that will be use as the background
local aspect_ratio = screen_width / screen_height
aspect_ratio = math.floor(aspect_ratio * 100) / 100
-- Create image filter command
local cmd = nil
cmd = filter_bg_image(wall_name, index, aspect_ratio, screen_width, screen_height)
-- Asign lockscreen to each screen
if s.index == 1 then
-- Primary screen
awful.spawn.easy_async_with_shell(
cmd,
function()
s.lockscreen.bgimage = locker_config.tmp_wall_dir .. index .. wall_name
end
)
else
-- Multihead screen/s
awful.spawn.easy_async_with_shell(
cmd,
function()
s.lockscreen_extended.bgimage = locker_config.tmp_wall_dir .. index .. wall_name
end
)
end
end
end
-- Create a lockscreen and its background for each screen on start-up
screen.connect_signal(
'request::desktop_decoration',
function(s)
create_lock_screens(s)
apply_ls_bg_image(locker_config.bg_image)
end
)
-- Regenerate lockscreens and its background if a screen was removed to avoid errors
screen.connect_signal(
'removed',
function(s)
create_lock_screens(s)
apply_ls_bg_image(locker_config.bg_image)
end
)