linux-utmpx 0.1.0
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/.github/workflows/main.yml +23 -0
- data/.gitignore +8 -0
- data/Gemfile +10 -0
- data/LICENSE.txt +21 -0
- data/README.md +46 -0
- data/Rakefile +12 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/lib/linux/utmpx.rb +11 -0
- data/lib/linux/utmpx/parser.rb +73 -0
- data/lib/linux/utmpx/type.rb +16 -0
- data/lib/linux/utmpx/version.rb +7 -0
- data/linux-utmpx.gemspec +37 -0
- metadata +87 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: c97e1b42f1cdb52f5e36237a34b1fd9a45725577d40fa95c2dc2af60bac191c7
|
4
|
+
data.tar.gz: 5f4fa12738f051bb224b1122883df78ca18f5825f16913a677cc93d446682101
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 11be5a0e6b534a53d2b9c2f32b2314c671f8fe9afb85977a5d009bcb4290fb3f65f86ef8390c1d9ce54e3ef4657705a638734ee1c1de8d1186149975ddaa3496
|
7
|
+
data.tar.gz: d0f6585ea4fd7a0a43a44b898c9d6b966f136a56605b67164e77e1f6b976cdbcac6cb5de296f2b1c65eb778d93d36063e8c14aac170de9ebc38d9e9bdd60bd71
|
@@ -0,0 +1,23 @@
|
|
1
|
+
name: Ruby
|
2
|
+
|
3
|
+
on: [push,pull_request]
|
4
|
+
|
5
|
+
jobs:
|
6
|
+
build:
|
7
|
+
runs-on: ubuntu-latest
|
8
|
+
strategy:
|
9
|
+
fail-fast: false
|
10
|
+
matrix:
|
11
|
+
ruby: [ '2.5', '2.6', '2.7', '3.0' ]
|
12
|
+
name: Ruby ${{ matrix.ruby }} unit testing on ubuntu-latest
|
13
|
+
steps:
|
14
|
+
- uses: actions/checkout@v2
|
15
|
+
- name: Set up Ruby
|
16
|
+
uses: ruby/setup-ruby@v1
|
17
|
+
with:
|
18
|
+
ruby-version: ${{ matrix.ruby }}
|
19
|
+
- name: Run the default task
|
20
|
+
run: |
|
21
|
+
gem install bundler
|
22
|
+
bundle install
|
23
|
+
TESTOPTS="--verbose" bundle exec rake
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2021 Kentaro Hayashi
|
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/README.md
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
# Linux::Utmpx::UtmpxParser
|
2
|
+
|
3
|
+
Helper library to parse /var/log/wtmp, /var/run/utmp.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'linux-utmpx'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle install
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install linux-utmpx
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
Read all records in `/var/log/wtmp`.
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
io = File.open("/var/log/wtmp")
|
27
|
+
parser = Linux::Utmpx::UtmpxParser.new
|
28
|
+
while !io.eof? do
|
29
|
+
puts parser.read(io)
|
30
|
+
end
|
31
|
+
```
|
32
|
+
|
33
|
+
|
34
|
+
## Development
|
35
|
+
|
36
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test-unit` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
37
|
+
|
38
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
39
|
+
|
40
|
+
## Contributing
|
41
|
+
|
42
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/fluent-lugins-nursery/linux-utmpx.
|
43
|
+
|
44
|
+
## License
|
45
|
+
|
46
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require "bundler/setup"
|
5
|
+
require "linux/utmpx"
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require "pry"
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require "irb"
|
15
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/lib/linux/utmpx.rb
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
module Linux
|
2
|
+
module Utmpx
|
3
|
+
# See /usr/include/bits/utmpx.h
|
4
|
+
|
5
|
+
class Exitstatus < BinData::Record
|
6
|
+
endian :little
|
7
|
+
int16 :e_termination
|
8
|
+
int16 :e_exit
|
9
|
+
end
|
10
|
+
|
11
|
+
class Uttv < BinData::Record
|
12
|
+
endian :little
|
13
|
+
int32 :tv_sec
|
14
|
+
int32 :tv_usec
|
15
|
+
end
|
16
|
+
|
17
|
+
class UtmpxParser < BinData::Record
|
18
|
+
UT_LINESIZE = 32
|
19
|
+
UT_NAMESIZE = 32
|
20
|
+
UT_HOSTSIZE = 256
|
21
|
+
UT_IDSIZE = 4
|
22
|
+
|
23
|
+
endian :little
|
24
|
+
|
25
|
+
int16 :ut_type
|
26
|
+
int16 :pad_type # Align
|
27
|
+
int32 :ut_pid
|
28
|
+
string :ut_line, :length => UT_LINESIZE, :trim_padding => true
|
29
|
+
string :ut_id, :length => UT_IDSIZE, :trim_padding => true
|
30
|
+
string :ut_user, :length => UT_NAMESIZE, :trim_padding => true
|
31
|
+
string :ut_host, :length => UT_HOSTSIZE, :trim_padding => true
|
32
|
+
exitstatus :ut_exit
|
33
|
+
int32 :ut_session
|
34
|
+
uttv :ut_tv
|
35
|
+
array :ut_addr_v6, :initial_length => 4 do
|
36
|
+
int32
|
37
|
+
end
|
38
|
+
string :reserved, :length => 20
|
39
|
+
|
40
|
+
def time
|
41
|
+
Time.at(ut_tv.tv_sec, ut_tv.tv_usec)
|
42
|
+
end
|
43
|
+
|
44
|
+
def type
|
45
|
+
Linux::Utmpx::Type.constants.each do |sym|
|
46
|
+
return sym if Linux::Utmpx::Type.const_get(sym) == ut_type
|
47
|
+
end
|
48
|
+
ut_type
|
49
|
+
end
|
50
|
+
|
51
|
+
def pid
|
52
|
+
ut_pid
|
53
|
+
end
|
54
|
+
|
55
|
+
def line
|
56
|
+
ut_line
|
57
|
+
end
|
58
|
+
|
59
|
+
def user
|
60
|
+
ut_user
|
61
|
+
end
|
62
|
+
|
63
|
+
def id
|
64
|
+
ut_id
|
65
|
+
end
|
66
|
+
|
67
|
+
def host
|
68
|
+
ut_host
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
73
|
+
end
|
data/linux-utmpx.gemspec
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "lib/linux/utmpx/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "linux-utmpx"
|
7
|
+
spec.version = Linux::Utmpx::VERSION
|
8
|
+
spec.authors = ["Kentaro Hayashi"]
|
9
|
+
spec.email = ["kenhys@gmail.com"]
|
10
|
+
|
11
|
+
spec.summary = "Helper library to read utmp, wtmp login records"
|
12
|
+
spec.description = "Library to read login records from /var/log/wtmp, /var/run/utmp"
|
13
|
+
spec.homepage = "https://github.com/fluent-plugins-nursery/linux-utmpx"
|
14
|
+
spec.license = "MIT"
|
15
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.4.0")
|
16
|
+
|
17
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
18
|
+
spec.metadata["source_code_uri"] = "https://github.com/fluent-plugins-nursery/linux-utmpx"
|
19
|
+
spec.metadata["changelog_uri"] = "https://github.com/fluent-plugins-nursery/linux-utmpx/CHANGELOG.md"
|
20
|
+
|
21
|
+
# Specify which files should be added to the gem when it is released.
|
22
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
23
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
24
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
|
25
|
+
end
|
26
|
+
spec.bindir = "exe"
|
27
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
28
|
+
spec.require_paths = ["lib"]
|
29
|
+
|
30
|
+
# Uncomment to register a new dependency of your gem
|
31
|
+
# spec.add_dependency "example-gem", "~> 1.0"
|
32
|
+
spec.add_dependency "bindata", "~> 2.4.8"
|
33
|
+
|
34
|
+
spec.add_development_dependency "test-unit", "~> 3.4.0"
|
35
|
+
# For more information and examples about making a new gem, checkout our
|
36
|
+
# guide at: https://bundler.io/guides/creating_gem.html
|
37
|
+
end
|
metadata
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: linux-utmpx
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Kentaro Hayashi
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-03-24 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bindata
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 2.4.8
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 2.4.8
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: test-unit
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 3.4.0
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 3.4.0
|
41
|
+
description: Library to read login records from /var/log/wtmp, /var/run/utmp
|
42
|
+
email:
|
43
|
+
- kenhys@gmail.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".github/workflows/main.yml"
|
49
|
+
- ".gitignore"
|
50
|
+
- Gemfile
|
51
|
+
- LICENSE.txt
|
52
|
+
- README.md
|
53
|
+
- Rakefile
|
54
|
+
- bin/console
|
55
|
+
- bin/setup
|
56
|
+
- lib/linux/utmpx.rb
|
57
|
+
- lib/linux/utmpx/parser.rb
|
58
|
+
- lib/linux/utmpx/type.rb
|
59
|
+
- lib/linux/utmpx/version.rb
|
60
|
+
- linux-utmpx.gemspec
|
61
|
+
homepage: https://github.com/fluent-plugins-nursery/linux-utmpx
|
62
|
+
licenses:
|
63
|
+
- MIT
|
64
|
+
metadata:
|
65
|
+
homepage_uri: https://github.com/fluent-plugins-nursery/linux-utmpx
|
66
|
+
source_code_uri: https://github.com/fluent-plugins-nursery/linux-utmpx
|
67
|
+
changelog_uri: https://github.com/fluent-plugins-nursery/linux-utmpx/CHANGELOG.md
|
68
|
+
post_install_message:
|
69
|
+
rdoc_options: []
|
70
|
+
require_paths:
|
71
|
+
- lib
|
72
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: 2.4.0
|
77
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
requirements: []
|
83
|
+
rubygems_version: 3.1.4
|
84
|
+
signing_key:
|
85
|
+
specification_version: 4
|
86
|
+
summary: Helper library to read utmp, wtmp login records
|
87
|
+
test_files: []
|