login_records 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/LICENCE +21 -0
- data/ext/extconf.rb +13 -0
- data/ext/login_records.c +67 -0
- data/lib/login_records.rb +3 -0
- data/lib/login_records/version.rb +5 -0
- metadata +49 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: bcab735dc5e17c94520381018a41e6eca41f1a27ed49749c04dd16ec4882da8c
|
|
4
|
+
data.tar.gz: 61c9cc1608848aeb981e5a160fca671c4cacc007a4226fb446eb9d37bd86bf6d
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: d15fc66dda2a1514790ac7a979a86356a9350c30e0a9fece223ce44b38a993b7ca709d9d8d66c0f67451ae4be7a3773ff850fd3668c2fdbb9dc14474054f4ad0
|
|
7
|
+
data.tar.gz: 8bbb56adadd36759dc0344c88fac4f92e315a34a858b48fabbdab3276352b406e54e1fa75b7dad08bd82ab7c3aac3a69d1cb22d20b2224adb9224bd591d1b652
|
data/LICENCE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021 Sourav Goswami
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
data/ext/extconf.rb
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
require 'mkmf'
|
|
2
|
+
|
|
3
|
+
$CFLAGS << ' -O3'
|
|
4
|
+
|
|
5
|
+
unless have_const('linux') || RbConfig::CONFIG['arch'].to_s[/linux/]
|
|
6
|
+
abort('Platform is not linux')
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
unless have_header('utmpx.h') && have_header('ruby.h')
|
|
10
|
+
abort("Your system doesn't have utmpx.h.")
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
create_makefile 'login_records/login_records'
|
data/ext/login_records.c
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
#include <utmpx.h>
|
|
2
|
+
#include <paths.h>
|
|
3
|
+
#include "ruby.h"
|
|
4
|
+
|
|
5
|
+
void read_log(VALUE ary, char *log_path) {
|
|
6
|
+
if(access(log_path, R_OK))
|
|
7
|
+
return ;
|
|
8
|
+
|
|
9
|
+
struct utmpx data ;
|
|
10
|
+
|
|
11
|
+
FILE *log = fopen(log_path, "rb") ;
|
|
12
|
+
unsigned int sizeof_data = sizeof(data) ;
|
|
13
|
+
|
|
14
|
+
char *line, *id, *user, *host ;
|
|
15
|
+
short type ;
|
|
16
|
+
unsigned int pid, session ;
|
|
17
|
+
unsigned long long sec, usec ;
|
|
18
|
+
|
|
19
|
+
VALUE hash ;
|
|
20
|
+
|
|
21
|
+
while(fread(&data, sizeof_data, 1, log) == 1) {
|
|
22
|
+
hash = rb_hash_new() ;
|
|
23
|
+
|
|
24
|
+
type = data.ut_type ;
|
|
25
|
+
pid = data.ut_pid ;
|
|
26
|
+
line = data.ut_line ;
|
|
27
|
+
id = data.ut_id ;
|
|
28
|
+
user = data.ut_user ;
|
|
29
|
+
host = data.ut_host ;
|
|
30
|
+
session = data.ut_session ;
|
|
31
|
+
|
|
32
|
+
sec = data.ut_tv.tv_sec ;
|
|
33
|
+
usec = data.ut_tv.tv_usec ;
|
|
34
|
+
|
|
35
|
+
rb_hash_aset(hash, ID2SYM(rb_intern("type")), INT2FIX(type)) ;
|
|
36
|
+
rb_hash_aset(hash, ID2SYM(rb_intern("pid")), UINT2NUM(pid)) ;
|
|
37
|
+
rb_hash_aset(hash, ID2SYM(rb_intern("line")), rb_str_new_cstr(line)) ;
|
|
38
|
+
rb_hash_aset(hash, ID2SYM(rb_intern("id")), rb_str_new_cstr(id)) ;
|
|
39
|
+
rb_hash_aset(hash, ID2SYM(rb_intern("user")), rb_str_new_cstr(user)) ;
|
|
40
|
+
rb_hash_aset(hash, ID2SYM(rb_intern("host")), rb_str_new_cstr(host)) ;
|
|
41
|
+
rb_hash_aset(hash, ID2SYM(rb_intern("session")), UINT2NUM(session)) ;
|
|
42
|
+
rb_hash_aset(hash, ID2SYM(rb_intern("time")), rb_time_new(sec, usec)) ;
|
|
43
|
+
|
|
44
|
+
rb_ary_push(ary, hash) ;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
fclose(log) ;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
VALUE wtmp(VALUE obj) {
|
|
51
|
+
VALUE ary = rb_ary_new() ;
|
|
52
|
+
read_log(ary, _PATH_WTMP) ;
|
|
53
|
+
return ary ;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
VALUE utmp(VALUE obj) {
|
|
57
|
+
VALUE ary = rb_ary_new() ;
|
|
58
|
+
read_log(ary, _PATH_UTMP) ;
|
|
59
|
+
return ary ;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
void Init_login_records() {
|
|
63
|
+
VALUE _login_records = rb_define_module("LoginRecords") ;
|
|
64
|
+
|
|
65
|
+
rb_define_module_function(_login_records, "wtmp", wtmp, 0) ;
|
|
66
|
+
rb_define_module_function(_login_records, "utmp", utmp, 0) ;
|
|
67
|
+
}
|
metadata
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: login_records
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Sourav Goswami
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2021-01-26 00:00:00.000000000 Z
|
|
12
|
+
dependencies: []
|
|
13
|
+
description: LoginRecords Allows you to read UTML and WMTP files on Linux
|
|
14
|
+
email:
|
|
15
|
+
- souravgoswami@protonmail.com
|
|
16
|
+
executables: []
|
|
17
|
+
extensions:
|
|
18
|
+
- ext/extconf.rb
|
|
19
|
+
extra_rdoc_files: []
|
|
20
|
+
files:
|
|
21
|
+
- LICENCE
|
|
22
|
+
- ext/extconf.rb
|
|
23
|
+
- ext/login_records.c
|
|
24
|
+
- lib/login_records.rb
|
|
25
|
+
- lib/login_records/version.rb
|
|
26
|
+
homepage: https://github.com/Souravgoswami/login_records
|
|
27
|
+
licenses:
|
|
28
|
+
- MIT
|
|
29
|
+
metadata: {}
|
|
30
|
+
post_install_message:
|
|
31
|
+
rdoc_options: []
|
|
32
|
+
require_paths:
|
|
33
|
+
- lib
|
|
34
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
35
|
+
requirements:
|
|
36
|
+
- - ">="
|
|
37
|
+
- !ruby/object:Gem::Version
|
|
38
|
+
version: '2.1'
|
|
39
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
40
|
+
requirements:
|
|
41
|
+
- - ">="
|
|
42
|
+
- !ruby/object:Gem::Version
|
|
43
|
+
version: '0'
|
|
44
|
+
requirements: []
|
|
45
|
+
rubygems_version: 3.1.4
|
|
46
|
+
signing_key:
|
|
47
|
+
specification_version: 4
|
|
48
|
+
summary: LoginRecords Allows you to read UTML and WMTP files on Linux
|
|
49
|
+
test_files: []
|