forked from langhorst/rdialog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
passwordform.rb
executable file
·97 lines (84 loc) · 1.98 KB
/
passwordform.rb
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
#!/usr/bin/env ruby
# [email protected] Apr-01-2014
require [File.expand_path(File.dirname(__FILE__)), '..', 'lib', 'mrdialog'].join('/')
require 'pp'
begin
ME = File.basename($0)
if ENV['CHANGE_TITLE']
if ME =~ /(.+)\.rb$/
base = $1
puts "\033]0;mrdialog - #{base}\007"
end
end
user = ''
uid = ''
gid = ''
home = ENV["HOME"]
id = `id`.chomp
if id =~ /^uid=(\d+)\((.+)\)\sgid=(\d+)\(.*$/
uid = $1
user = $2
gid = $3
end
dialog = MRDialog.new
dialog.clear = true
dialog.logger = Logger.new(ENV["HOME"] + "/dialog_" + ME + ".log")
text = <<EOF
Here is a possible piece of a configuration program.
EOF
items = []
form_data = Struct.new(:label, :ly, :lx, :item, :iy, :ix, :flen, :ilen)
data = form_data.new
data.label = "Username:"
data.ly = 1
data.lx = 1
data.item = user
data.iy = 1
data.ix = 10
data.flen = user.length + 10
data.ilen = 0
items.push(data.to_a)
data = form_data.new
data.label = "UID:"
data.ly = 2
data.lx = 1
data.item = uid.to_s
data.iy = 2
data.ix = 10
data.flen = uid.length + 10
data.ilen = 0
items.push(data.to_a)
data = form_data.new
data.label = "GID:"
data.ly = 3
data.lx = 1
data.item = gid.to_s
data.iy =3
data.ix = 10
data.flen = gid.length + 2
data.ilen = 0
items.push(data.to_a)
data = form_data.new
data.label = "HOME:"
data.ly = 4
data.lx = 1
data.item = home
data.iy = 4
data.ix = 10
data.flen = home.length + 40
data.ilen = 0
items.push(data.to_a)
dialog.insecure = true
dialog.title = "PASSWORDFORM"
result_hash = dialog.passwordform(text, items, 20, 50, 0)
if result_hash
puts "Resulting data:"
result_hash.each do |key, val|
puts " #{key} = #{val}"
end
end
rescue => e
puts "#{$!}"
t = e.backtrace.join("\n\t")
puts "Error: #{t}"
end