ig3tool 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,111 +0,0 @@
1
- module Ig3tool
2
- class Interne < ActiveRecord::Base
3
-
4
- set_table_name "internes"
5
- set_nonauto_primary_key "username"
6
-
7
- belongs_to :person,
8
- :class_name => "Person",
9
- :foreign_key => "username"
10
-
11
- validates_uniqueness_of :username
12
- validates_presence_of :username, :saldo, :afgesloten, :person
13
-
14
-
15
- def afgesloten?
16
- not afgesloten.zero?
17
- end
18
-
19
-
20
- def print(amount, message)
21
- check_amount(amount)
22
- log_transaction(amount, self.username, "IG Printsys", message)
23
- decrease(amount)
24
- end
25
-
26
- def refundprint(amount, message)
27
- check_amount(amount)
28
- log_transaction(amount, "IG Printsys", self.username, message)
29
- increase(amount)
30
- end
31
-
32
- def buy(amount, message)
33
- check_amount(amount)
34
- log_transaction(amount, self.username, "IG Shop", message)
35
- decrease(amount)
36
- end
37
-
38
-
39
- def deposit(who, amount, message)
40
- check_amount(amount)
41
- log_transaction(amount, who, self.username, message)
42
- increase(amount)
43
- end
44
-
45
-
46
- def retract(who, amount, message)
47
- check_amount(amount)
48
- log_transaction(amount, self.username, who, message)
49
- decrease(amount)
50
- end
51
- end
52
-
53
- private
54
-
55
- def log_transaction(amount, from, to, message)
56
- it = InterneTransaction.new
57
- it.donor = from
58
- it.recipient = to
59
- it.amount = amount
60
- it.time = Time.now
61
- it.message = message
62
- it.save!
63
- end
64
-
65
- def check_amount(amount)
66
- if amount < 0
67
- raise NoPositiveAmount
68
- end
69
- end
70
-
71
-
72
-
73
- # XXX : send automatic warning mail when saldo < 0 :)
74
- # muhahaha
75
- def decrease(amount)
76
- if not afgesloten?
77
- Interne.transaction do
78
- reload()
79
- self.saldo -= amount
80
- save!
81
- end
82
- else
83
- raise Afgesloten
84
- end
85
- rescue
86
- raise TransactionFailed
87
- end
88
-
89
- def increase(amount)
90
- if not afgesloten?
91
- Interne.transaction do
92
- reload()
93
- self.saldo += amount
94
- save!
95
- end
96
- else
97
- raise Afgesloten
98
- end
99
- rescue
100
- raise TransactionFailed
101
- end
102
-
103
-
104
- class InterneTransaction < ActiveRecord::Base
105
-
106
- set_table_name "internes_transactions"
107
- validates_presence_of :amount, :time, :message, :donor, :recipient
108
-
109
- end
110
-
111
- end
@@ -1,104 +0,0 @@
1
- =begin
2
-
3
- beetje stuff om te authen naar ldap
4
- bvb:
5
- bitch?("joske", "dejoszijnpasswd")
6
- => true/false
7
-
8
- TODO: filteren op debugger!
9
-
10
- =end
11
-
12
- require 'mymd5'
13
-
14
- begin
15
-
16
- require "ldap"
17
-
18
- class IGLDAP < LDAP::Conn
19
- DN = "cn=Proxyuser,dc=infogroep,dc=be"
20
- PASS = "pRoxyAuth"
21
- BASE_DN = "dc=infogroep,dc=be"
22
- PEOPLE_DN = "ou=People,dc=infogroep,dc=be"
23
- LDAP_HOST = "infogroep.be"
24
- LDAP_PORT = 389
25
- PROTOCOL_VERSION = 3
26
-
27
- def initialize (host = LDAP_HOST, version = PROTOCOL_VERSION)
28
- super( host, LDAP_PORT )
29
- set_option( LDAP::LDAP_OPT_PROTOCOL_VERSION, version )
30
- return self
31
- end
32
-
33
- def bind(dn = DN, pass = PASS)
34
- super( dn, pass )
35
- end
36
-
37
- def self.bitchke?(user, pass)
38
- begin
39
- conn = IGLDAP.new.bind
40
- attrs = %w{uid userPassword}
41
- filter = "uid=#{user}"
42
- result = conn.search2(IGLDAP::PEOPLE_DN, LDAP::LDAP_SCOPE_SUBTREE,filter, attrs)
43
-
44
- passr = result.first["userPassword"].first.gsub(/\{crypt\}/, "")
45
-
46
-
47
- match = passr.match(/(\$.+\$.+\$)(.*)/)
48
- #salt = match[1]
49
- salt = match[1].gsub(/\$1\$/, "").delete("$")
50
- passh = match[2]
51
- #pass.crypt(salt) == passr
52
- crypt(pass, :md5, salt) == passr
53
- rescue Exception => e
54
- false
55
- end
56
- end
57
-
58
- end
59
-
60
- rescue
61
-
62
- require 'net/ldap'
63
- include Net
64
-
65
- class IGLDAP
66
- DN = "cn=Proxyuser,dc=infogroep,dc=be"
67
- PASS = "pRoxyAuth"
68
- BASE_DN = "dc=infogroep,dc=be"
69
- PEOPLE_DN = "ou=People,dc=infogroep,dc=be"
70
- LDAP_HOST = "infogroep.be"
71
- LDAP_PORT = 389
72
- PROTOCOL_VERSION = 3
73
-
74
- def initialize
75
- @conn = Net::LDAP.new( {:host => LDAP_HOST, :port => LDAP_PORT, :auth => { :method => :simple, :username => DN, :password => PASS }} )
76
- end
77
-
78
- def bind
79
- @conn.bind
80
- @conn
81
- end
82
-
83
- def self.bitchke?(user, pass)
84
- begin
85
- conn = IGLDAP.new.bind
86
- attrs = %w{uid userPassword}
87
- filter = "uid=#{user}"
88
- result = conn.search(:base => PEOPLE_DN, :filter => filter)
89
-
90
- passr = result.first["userPassword"].first.gsub(/\{crypt\}/, "")
91
-
92
- match = passr.match(/(\$.+\$.+\$)(.*)/)
93
- salt = match[1].gsub(/\$1\$/, "").delete("$")
94
- #salt = match[1]
95
- passh = match[2]
96
- crypt(pass, :md5, salt) == passr
97
- #pass.crypt(salt) == passr
98
- rescue Exception => e
99
- false
100
- end
101
- end
102
-
103
- end
104
- end
data/lib/log.rb DELETED
@@ -1,25 +0,0 @@
1
- module Ig3tool
2
-
3
- class LogEntry < ActiveRecord::Base
4
-
5
- set_table_name "log"
6
-
7
- validates_presence_of :system,
8
- :subsystem,
9
- :timestamp,
10
- :message
11
-
12
- end
13
-
14
- class Logger
15
-
16
- def self.log(system, subsystem, message)
17
- LogEntry.create(:system => system.to_s,
18
- :timestamp => Time.now.to_i,
19
- :subsystem => subsystem.to_s,
20
- :message => message.to_s)
21
- end
22
-
23
- end
24
-
25
- end
@@ -1,32 +0,0 @@
1
- module Ig3tool
2
- class Membership < ActiveRecord::Base
3
- set_table_name "Memberships"
4
- set_nonauto_primary_key :barcode
5
-
6
- validates_uniqueness_of :barcode
7
-
8
- validates_presence_of :barcode,
9
- :username,
10
- :year,
11
- :status
12
-
13
- validates_inclusion_of :status,
14
- :in => ["debugger",
15
- "ex-debugger",
16
- "member",
17
- "honorary member"]
18
-
19
- belongs_to :person,
20
- :class_name => "Person",
21
- :foreign_key => "username"
22
-
23
- def self.member?(barcode)
24
- begin
25
- membership = find(barcode)
26
- membership.year == Time.werkjaar
27
- rescue ActiveRecord::RecordNotFound
28
- false
29
- end
30
- end
31
- end
32
- end
@@ -1,95 +0,0 @@
1
- require 'English'
2
- require 'base64'
3
- require 'md5'
4
- require 'sha1'
5
-
6
- ITOA64 = "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
7
-
8
-
9
- def crypt(password, algo = :md5, salt = nil, magic='$1$')
10
-
11
- salt ||= generate_salt(8)
12
-
13
- case algo
14
- when :md5, :sha1, :rmd160
15
- require "digest/#{algo}"
16
- when :sha256, :sha384, :sha512
17
- require "digest/sha2"
18
- else
19
- raise(ArgumentError, "unknown algorithm")
20
- end
21
- digest_class = Digest.const_get(algo.to_s.upcase)
22
-
23
- # The password first, since that is what is most unknown. Then our magic string. Then the raw salt.
24
- m = digest_class.new
25
- m.update(password + magic + salt)
26
-
27
- # Then just as many characters of the MD5(pw,salt,pw)
28
- mixin = digest_class.new.update(password + salt + password).digest
29
- password.length.times do |i|
30
- m.update(mixin[i % 16].chr)
31
- end
32
-
33
- # Then something really weird...
34
- # Also really broken, as far as I can tell. -m
35
- i = password.length
36
- while i != 0
37
- if (i & 1) != 0
38
- m.update("\x00")
39
- else
40
- m.update(password[0].chr)
41
- end
42
- i >>= 1
43
- end
44
-
45
- final = m.digest
46
-
47
- # and now, just to make sure things don't run too fast
48
- 1000.times do |i|
49
- m2 = digest_class.new
50
-
51
- if (i & 1) != 0
52
- m2.update(password)
53
- else
54
- m2.update(final)
55
- end
56
-
57
- if (i % 3) != 0
58
- m2.update(salt)
59
- end
60
- if (i % 7) != 0
61
- m2.update(password)
62
- end
63
-
64
- if (i & 1) != 0
65
- m2.update(final)
66
- else
67
- m2.update(password)
68
- end
69
-
70
- final = m2.digest
71
- end
72
-
73
- # This is the bit that uses to64() in the original code.
74
-
75
- rearranged = ""
76
-
77
- [ [0, 6, 12], [1, 7, 13], [2, 8, 14], [3, 9, 15], [4, 10, 5] ].each do |a, b, c|
78
-
79
- v = final[a] << 16 | final[b] << 8 | final[c]
80
-
81
- 4.times do
82
- rearranged += ITOA64[v & 0x3f].chr
83
- v >>= 6
84
- end
85
- end
86
-
87
- v = final[11]
88
-
89
- 2.times do
90
- rearranged += ITOA64[v & 0x3f].chr
91
- v >>= 6
92
- end
93
-
94
- magic + salt + '$' + rearranged
95
- end
@@ -1,143 +0,0 @@
1
- require 'utils'
2
-
3
- module Ig3tool
4
-
5
- class Person < ActiveRecord::Base
6
-
7
- set_table_name "people"
8
- set_nonauto_primary_key :username
9
-
10
- # XXX wat willen we dat aanwezig is?
11
- validates_presence_of :username,
12
- :email,
13
- :first_name,
14
- :last_name
15
-
16
- validates_uniqueness_of :username,
17
- :email
18
-
19
- has_one :interne,
20
- :class_name => "Interne",
21
- :foreign_key => "username"
22
-
23
- # breekt horribly met to_yaml, zucht
24
- # has_one :membership,
25
- # :conditions => ["year = ?", Time.werkjaar],
26
- # :class_name => 'Membership',
27
- # :foreign_key => "username"
28
-
29
- has_many :memberships,
30
- :class_name => "Membership",
31
- :foreign_key => "username",
32
- :order => "year desc"
33
-
34
- has_one :print_user,
35
- :class_name => "PrintUser",
36
- :foreign_key => "username"
37
- # :dependent => :destroy # destroyes printuser when person gets deleted
38
- # XXX do we want that?
39
-
40
- def membership
41
- if !memberships.empty? and memberships[0].year == Time.werkjaar
42
- memberships[0]
43
- else
44
- nil
45
- end
46
- end
47
-
48
- def username=(newusername)
49
- write_attribute(:username, newusername)
50
- end
51
-
52
- def member?
53
- not membership.nil?
54
- end
55
-
56
- def honorarymember?
57
- member? and membership.status == "honorary member"
58
- end
59
-
60
- def exhonorarymember?
61
- not honorarymember? and not memberships.find(:all).find_all{|m| m.status == "honorary member"}.empty?
62
- end
63
-
64
- def debugger?
65
- (not interne.nil?) and (interne.afgesloten != 1) and member? and (membership.status == "debugger")
66
- end
67
-
68
- def exdebugger?
69
- (not debugger?) and (not memberships.find(:all).find_all{|m| m.status == "debugger" or m.status == "ex-debugger"}.empty?)
70
- end
71
-
72
- def self.everybody
73
- find(:all)
74
- end
75
-
76
- def self.members
77
- find(:all).find_all{|p| p.member?}
78
- end
79
-
80
- def self.nonmembers
81
- find(:all).find_all{|p| p.membership.nil?}
82
- end
83
-
84
- def self.debuggers
85
- find(:all).find_all{|p| p.debugger?}
86
- end
87
-
88
- def self.exdebuggers
89
- find(:all).find_all{|p| p.exdebugger?}
90
- end
91
-
92
- def self.honorarymembers
93
- find(:all).find_all{|p| p.honorarymember?}
94
- end
95
-
96
- def self.exhonorarymembers
97
- find(:all).find_all{|p| p.exhonorarymember?}
98
- end
99
-
100
- def unbugger!
101
- raise NotADebugger unless debugger?
102
- raise SaldoNotZero if interne.saldo != 0
103
-
104
- interne.afgesloten = true
105
- membership.status = "member"
106
-
107
- transaction do
108
- print_user.remove_aliases
109
-
110
- membership.save!
111
- interne.save!
112
- end
113
- end
114
-
115
- def bugger!
116
- raise NotAMember unless member?
117
- raise IG3Error, "already a debugger" if debugger?
118
-
119
- membership.status = "debugger"
120
-
121
- # interne
122
- self.interne = i = Interne.new
123
- i.username = username
124
- i.saldo = 0
125
- i.afgesloten = false
126
-
127
- transaction do
128
- # centjes overzetten
129
- if print_user.saldo > 0
130
- i.deposit("printaccount", print_user.saldo, "printkrediet")
131
- # XXX print krediet?
132
- # print_user.saldo = 0
133
- end
134
-
135
- membership.save!
136
- i.save!
137
- end
138
- end
139
-
140
- end
141
-
142
-
143
- end