[UP] add many more ion3 cfg -_-, powerfull, and add thinkpad xorg.conf/.Xmodmap,...
[arrow.git] / archlinux_conf / etc / ion3 / statusd_flashing.lua
blob7fcfea22fd6342d91cf3f98efce575935920f9e7
1 ------------------------------------------------------------------------------------
2 --
3 -- DESCRIPTION:
4 -- [ Multi Purpose Monitor for Ion3]
5 -- It detects if security logs, mboxes, maildirs, some files, etcetera were
6 -- changed. If they were changed in fact, shows a flashing (blinking) alarm with a
7 -- message text specified on settings (or default = !!).
8 --
9 -- If you specify your mail inbox it will do a flashing advise of new email.
10 -- If you specify a security log it will reflect your security warnings.
11 --
12 -- You could specify whatever files or directories that do you want to monitor.
13 --> All in Unix* like Oses is a file...
15 -- PLEASE READ THIS:
16 -- * This is another toy for Ion3.
17 -- ** It is not intended to replace or use Gamin, F.A.M. like libs.
18 -- *** This is not a full whistles and sparkles power security monitor like Tripwire.
19 -- **** It is not a good idea to rely on this script to take care of sensible information.
20 -- ***** The level of recursion is only of one level for directories.
21 -- It only provides a very simple way to know if:
23 -- -> Inode number was modified or
24 -- -> Size has changed or
25 -- -> User-group has changed or
26 -- -> Access permisions have changed or
27 -- -> Name changes (including file deletion and moving) then
28 -- ___________________________________________________________
29 -- It flashes a specified message for 'certain specified time'
30 --
31 -- PUPOSE:
32 -- To share a quick method for timers control and blinking patterns on Ion3 statusbars,
33 -- I mean, to fill statusbar(s) with annoying moving things. So don't use it ;]
35 ------- USAGE EXAMPLE : ------------------------------------------------------------
36 --
37 -- If you don't know how to get this working please refer to Ion manual pages,
38 -- Ion home page or some other scripts. Then, write something like this on cfg_statusd.lua :
39 --
40 -- mod_statusbar.create{
41 -- template = "whatever.. %flashing ..whatever", --> Modify this part.
42 -- },
43 --
44 ----> And add somethig like this to:
46 -- mod_statusbar.launch_statusd{
47 --
48 -- flashing = {
49 -- files = {"/mnt/Feed_My_Dog", "~/Mail"} --> The intended purpose files (logs, mail)
50 -- log = ".ion3/flashing.log" --> Some file in your $HOME[...] path.
51 -- NOTE: $HOME is assumed by 'log'.
52 -- Paths not in $HOME are invalid.
53 -- update_interval = 3000, --> Time in milliseconds to update info.
54 -- flash_interval = 300, --> Speed of flashing pattern. (msecs.)
55 -- alarm_message = "!!", --> Flashing Message (defaults are a good bet).
56 -- normal_message = "--", --> Normal status message.
57 -- turn_off = 60, --> This, avoids to show the annoying
58 -- message for ever. The value represents
59 -- }, cycles (10 * flash_interval msecs.)
60 -- }
61 ------------------------------------------------------------------------------------
62 --
63 -- LICENSE: GPL2 Copyright(C)2006 Mario GarcĂ­a H.
64 -- (See http://www.gnu.org/licenses/gpl.html to read complete license)
66 -- T.STAMP: Sun Dec 10 02:08:39 2006
68 -- DEPENDS: None at all.
70 -- INSECTS: You are the entomologist. You tell me.
72 -- NOTES ON USAGE:
73 -- - This script creates his own log of activity. You can choose a name and path on settings.
74 -- - If you remove the log, alarms will cease (rm -f *.log). Is not necessary to restart Ion.
75 -- - If you change the settings, the log will be auto-removed and re-written to reflect the changes
76 -- without false alarms.
77 -- - If, for some impossible circumstance, the status of some file or directory is normal again,
78 -- flashing will cease the annoying flashing thing by him self.
79 -- - If alarms are activated on certain time and you exit Ion current session, the
80 -- next session in Ion you will see the annoying thing on your screen... again.
81 -- - If you exit Ion and then you do changes to a file, the next time on Ion the alarms will do blinking.
82 -- - The minimum number for flashing interval (blink) is 300.
83 --
84 -- CONTACT:
85 -- G.H. < drosophila (at) Nmental (dot) com>
87 ------------------------------------------------------------------------------------
89 local defaults = {
90 files = { "~/.ion3" }, --> If you like so much Ion, this is the better default.
91 -- If you change this setting, the log will be auto-updated!
92 log = ".ion3/flashing.log", --> Where do you like to log? Paths not in $HOME [...]
93 -- are invalid. If you change this file, please, remove
94 -- your self the last file used. You are warned.
95 -- NOTE: $HOME is assumed by 'log'.
96 alarm_message = "!!", --> Put here the alarm message.
97 normal_message = "--", --> Put here the normal status message.
99 update_interval = 5*1000, --> Check your files every X milliseconds.
100 flash_interval = 400, --> Blinking interval in milliseconds.
101 turn_off = 500, --> Turn Off the alarm if it annoys you too much time:
102 -- (turn_off*flash_interval) milliseconds.
103 --> If you want permanent alarms: 3*999*999 is OK.
105 local settings = table.join(statusd.get_config("flashing"), defaults)
107 ---SOME INSANE LOCALS :-------------------------------------------------------------
109 local flashing_timer
110 local is_ok = true
111 local flash = false
112 local home = os.getenv("HOME")
113 local message_lenght = string.len(settings.alarm_message)
114 local turn_off = settings.turn_off
115 settings.flash_interval = settings.flash_interval > 299 and settings.flash_interval or 300
117 ---CONFIRM SOME INFO :--------------------------------------------------------------
119 local function confirm_someinfo()
120 local keys = table.concat(settings.files, " * ")
121 local log_file = home.."/"..settings.log
123 local check_status = function()
124 local check = io.popen("ls -liL --color=none "..table.concat(settings.files, " "))
125 local status = check:read("*a"); check:close()
126 return status
129 local new_log = function()
130 local new = io.open(log_file, "w")
131 if not new then
132 return false
133 else
134 new:write(keys.."\n"..check_status())
135 new:close()
136 os.execute("chmod 400 "..log_file)
137 new = io.open(log_file, "r")
138 local log = new:read("*a"); new:close()
139 return log
143 local check_changes = function()
144 local file = io.open(log_file, "r")
145 if not file then
146 return
147 else
148 local changes = file:read("*l"); file:close()
149 return changes ~= keys and
150 os.execute("rm -f "..log_file) or 1
154 if not turn_off then
155 turn_off = settings.turn_off --> Reinitialize turn_off if flash was done
156 is_ok = true
157 os.execute("rm -f "..log_file)
160 check_changes()
162 local file = io.open(log_file, "r")
163 local log = file == nil and new_log() or file:read("*a")
164 is_ok = keys.."\n"..check_status() == log
165 return
169 ---FLASHING PATERNS :---------------------------------------------------------------
171 local function flash_alarm()
172 turn_off = turn_off > 0 and turn_off - 1 or false --> Regresive shut down counter.
173 -- this is an extra ;>
174 local show = function()
175 statusd.inform("flashing", settings.alarm_message)
176 statusd.inform("flashing_hint", "critical")
177 return true
179 local hide = function()
180 statusd.inform("flashing", string.rep(".", message_lenght))
181 return false
183 flash = flash == false and show() or hide() --> Do the real hide and show (flash)
184 return
188 ---FUNCTIONS CALLINGS :-------------------------------------------------------------
190 local function update_timer()
191 confirm_someinfo() --> A function checking something ... and changing between states
192 if is_ok then
193 statusd.inform("flashing", settings.normal_message)
194 statusd.inform("flashing_hint", "normal")
195 flashing_timer:set(settings.update_interval, update_timer) --> Take different update_interval
196 else
197 flashing_timer:set(settings.flash_interval, update_timer) --> Take different update_interval
198 flash_alarm()
199 end
201 ------------------------------------------------------------------------------------
203 flashing_timer = statusd.create_timer()
204 update_timer()