social_stream-presence 0.0.2 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. data/Rakefile +7 -0
  2. data/app/assets/audio/chat/onMessageAudio.mp3 +0 -0
  3. data/app/assets/audio/chat/onMessageAudio.wav +0 -0
  4. data/app/assets/images/black_arrow3.png +0 -0
  5. data/app/assets/images/status/available.png +0 -0
  6. data/app/assets/images/status/away.png +0 -0
  7. data/app/assets/images/status/dnd.png +0 -0
  8. data/app/assets/javascripts/jquery-ui-1.8.14.custom.min.js +789 -0
  9. data/app/assets/javascripts/jquery.tools.min.js +17 -0
  10. data/app/assets/javascripts/jquery.tools.tooltip.js +11 -0
  11. data/app/assets/javascripts/jquery.ui.chatbox.js +260 -0
  12. data/app/assets/javascripts/social_stream-presence.js +2 -0
  13. data/app/assets/javascripts/store.js +20 -0
  14. data/app/assets/javascripts/strophe.js +3612 -0
  15. data/app/assets/javascripts/xmpp_client.js +494 -0
  16. data/app/assets/stylesheets/chat.css +239 -0
  17. data/app/assets/stylesheets/jquery.ui.chatbox.css +54 -0
  18. data/app/assets/stylesheets/social_stream-presence.css +3 -0
  19. data/app/controllers/xmpp_controller.rb +223 -0
  20. data/app/helpers/xmpp_helper.rb +20 -0
  21. data/app/views/xmpp/_chat.html.erb +63 -0
  22. data/app/views/xmpp/_chat_connecting.html.erb +8 -0
  23. data/app/views/xmpp/_chat_contacts.html.erb +46 -0
  24. data/app/views/xmpp/_chat_off.html.erb +35 -0
  25. data/app/views/xmpp/active_users.html.erb +33 -0
  26. data/app/views/xmpp/chat.html.erb +13 -0
  27. data/app/views/xmpp/index.html +19 -0
  28. data/app/views/xmpp/test.html.erb +11 -0
  29. data/config/routes.rb +15 -0
  30. data/db/migrate/20110711111408_add_connected_column_to_user.rb +9 -0
  31. data/db/migrate/20110928135031_add_status_column_to_user.rb +9 -0
  32. data/ejabberd/conf/ejabberd.cfg +625 -0
  33. data/ejabberd/conf/ejabberdctl.cfg +154 -0
  34. data/ejabberd/conf/inetrc +3 -0
  35. data/ejabberd/conf/server.pem +37 -0
  36. data/ejabberd/conf/ssconfig.cfg +32 -0
  37. data/ejabberd/ejabberd_scripts/authentication_script +117 -0
  38. data/ejabberd/ejabberd_scripts/authentication_script_org +114 -0
  39. data/ejabberd/ejabberd_scripts/compile_module +34 -0
  40. data/ejabberd/ejabberd_scripts/emanagement +245 -0
  41. data/ejabberd/ejabberd_scripts/generate_random_password +18 -0
  42. data/ejabberd/ejabberd_scripts/kill_authentication_script.sh +13 -0
  43. data/ejabberd/ejabberd_scripts/reset_connection_script +55 -0
  44. data/ejabberd/ejabberd_scripts/reset_logs.sh +23 -0
  45. data/ejabberd/ejabberd_scripts/set_connection_script +48 -0
  46. data/ejabberd/ejabberd_scripts/set_presence_script +48 -0
  47. data/ejabberd/ejabberd_scripts/show_config.sh +30 -0
  48. data/ejabberd/ejabberd_scripts/start_ejabberd.sh +68 -0
  49. data/ejabberd/ejabberd_scripts/stop_ejabberd.sh +12 -0
  50. data/ejabberd/ejabberd_scripts/synchronize_presence_script +57 -0
  51. data/ejabberd/ejabberd_scripts/unset_connection_script +48 -0
  52. data/ejabberd/mod_admin_extra/mod_admin_extra.beam +0 -0
  53. data/ejabberd/mod_admin_extra/mod_admin_extra.erl +1560 -0
  54. data/ejabberd/mod_sspresence/mod_sspresence.beam +0 -0
  55. data/ejabberd/mod_sspresence/mod_sspresence.erl +257 -0
  56. data/lib/social_stream-presence.rb +19 -2
  57. data/lib/social_stream/migrations/presence.rb +9 -0
  58. data/lib/social_stream/presence/engine.rb +62 -0
  59. data/lib/social_stream/presence/models/buddy_manager.rb +76 -0
  60. data/lib/social_stream/presence/version.rb +5 -0
  61. data/lib/tasks/presence/synchronize.rake +63 -0
  62. data/social_stream-presence.gemspec +4 -4
  63. metadata +69 -11
  64. data/.project +0 -17
@@ -0,0 +1,154 @@
1
+ #
2
+ # In this file you can configure options that are passed by ejabberdctl
3
+ # to the erlang runtime system when starting ejabberd
4
+ #
5
+
6
+ #' POLL: Kernel polling ([true|false])
7
+ #
8
+ # The kernel polling option requires support in the kernel.
9
+ # Additionally, you need to enable this feature while compiling Erlang.
10
+ #
11
+ # Default: true
12
+ #
13
+ #POLL=true
14
+
15
+ #.
16
+ #' SMP: SMP support ([enable|auto|disable])
17
+ #
18
+ # Explanation in Erlang/OTP documentation:
19
+ # enable: starts the Erlang runtime system with SMP support enabled.
20
+ # This may fail if no runtime system with SMP support is available.
21
+ # auto: starts the Erlang runtime system with SMP support enabled if it
22
+ # is available and more than one logical processor are detected.
23
+ # disable: starts a runtime system without SMP support.
24
+ #
25
+ # Default: auto
26
+ #
27
+ #SMP=auto
28
+
29
+ #.
30
+ #' ERL_MAX_PORTS: Maximum number of simultaneously open Erlang ports
31
+ #
32
+ # ejabberd consumes two or three ports for every connection, either
33
+ # from a client or from another Jabber server. So take this into
34
+ # account when setting this limit.
35
+ #
36
+ # Default: 32000
37
+ # Maximum: 268435456
38
+ #
39
+ #ERL_MAX_PORTS=32000
40
+
41
+ #.
42
+ #' FIREWALL_WINDOW: Range of allowed ports to pass through a firewall
43
+ #
44
+ # If Ejabberd is configured to run in cluster, and a firewall is blocking ports,
45
+ # it's possible to make Erlang use a defined range of port (instead of dynamic
46
+ # ports) for node communication.
47
+ #
48
+ # Default: not defined
49
+ # Example: 4200-4210
50
+ #
51
+ #FIREWALL_WINDOW=
52
+
53
+ #.
54
+ #' INET_DIST_INTERFACE: IP address where this Erlang node listens other nodes
55
+ #
56
+ # This communication is used by ejabberdctl command line tool,
57
+ # and in a cluster of several ejabberd nodes.
58
+ # Notice that the IP address must be specified in the Erlang syntax.
59
+ #
60
+ # Default: {127,0,0,1}
61
+ #
62
+ INET_DIST_INTERFACE={127,0,0,1}
63
+
64
+ #.
65
+ #' ERL_EPMD_ADDRESS: IP addresses where epmd listens for connections
66
+ #
67
+ # IMPORTANT: This option works only in Erlang/OTP R14B03 and newer.
68
+ #
69
+ # This environment variable may be set to a comma-separated
70
+ # list of IP addresses, in which case the epmd daemon
71
+ # will listen only on the specified address(es) and on the
72
+ # loopback address (which is implicitly added to the list if it
73
+ # has not been specified). The default behaviour is to listen on
74
+ # all available IP addresses.
75
+ #
76
+ # Default: 0.0.0.0
77
+ #
78
+ #ERL_EPMD_ADDRESS=127.0.0.1
79
+
80
+ #.
81
+ #' ERL_PROCESSES: Maximum number of Erlang processes
82
+ #
83
+ # Erlang consumes a lot of lightweight processes. If there is a lot of activity
84
+ # on ejabberd so that the maximum number of processes is reached, people will
85
+ # experience greater latency times. As these processes are implemented in
86
+ # Erlang, and therefore not related to the operating system processes, you do
87
+ # not have to worry about allowing a huge number of them.
88
+ #
89
+ # Default: 250000
90
+ # Maximum: 268435456
91
+ #
92
+ #ERL_PROCESSES=250000
93
+
94
+ #.
95
+ #' ERL_MAX_ETS_TABLES: Maximum number of ETS and Mnesia tables
96
+ #
97
+ # The number of concurrent ETS and Mnesia tables is limited. When the limit is
98
+ # reached, errors will appear in the logs:
99
+ # ** Too many db tables **
100
+ # You can safely increase this limit when starting ejabberd. It impacts memory
101
+ # consumption but the difference will be quite small.
102
+ #
103
+ # Default: 1400
104
+ #
105
+ #ERL_MAX_ETS_TABLES=1400
106
+
107
+ #.
108
+ #' ERL_OPTIONS: Additional Erlang options
109
+ #
110
+ # The next variable allows to specify additional options passed to erlang while
111
+ # starting ejabberd. Some useful options are -noshell, -detached, -heart. When
112
+ # ejabberd is started from an init.d script options -noshell and -detached are
113
+ # added implicitly. See erl(1) for more info.
114
+ #
115
+ # It might be useful to add "-pa /usr/local/lib/ejabberd/ebin" if you
116
+ # want to add local modules in this path.
117
+ #
118
+ # Default: ""
119
+ #
120
+ #ERL_OPTIONS=""
121
+
122
+ #.
123
+ #' ERLANG_NODE: Erlang node name
124
+ #
125
+ # The next variable allows to explicitly specify erlang node for ejabberd
126
+ # It can be given in different formats:
127
+ # ERLANG_NODE=ejabberd
128
+ # Lets erlang add hostname to the node (ejabberd uses short name in this case)
129
+ # ERLANG_NODE=ejabberd@hostname
130
+ # Erlang uses node name as is (so make sure that hostname is a real
131
+ # machine hostname or you'll not be able to control ejabberd)
132
+ # ERLANG_NODE=ejabberd@hostname.domainname
133
+ # The same as previous, but erlang will use long hostname
134
+ # (see erl (1) manual for details)
135
+ #
136
+ # Default: ejabberd
137
+ #
138
+ #ERLANG_NODE=ejabberd
139
+
140
+ #.
141
+ #' EJABBERD_PID_PATH: ejabberd PID file
142
+ #
143
+ # Indicate the full path to the ejabberd Process identifier (PID) file.
144
+ # If this variable is defined, ejabberd writes the PID file when starts,
145
+ # and deletes it when stops.
146
+ # Remember to create the directory and grant write permission to ejabberd.
147
+ #
148
+ # Default: don't write PID file
149
+ #
150
+ #EJABBERD_PID_PATH=/var/run/ejabberd/ejabberd.pid
151
+
152
+ #.
153
+ #'
154
+ # vim: foldmarker=#',#. foldmethod=marker:
@@ -0,0 +1,3 @@
1
+ {lookup,["file","native"]}.
2
+ {host,{127,0,0,1}, ["localhost","hostalias"]}.
3
+ {file, resolv, "/etc/resolv.conf"}.
@@ -0,0 +1,37 @@
1
+ -----BEGIN CERTIFICATE-----
2
+ MIIDvDCCAyWgAwIBAgIJAOBE76dYOsdsMA0GCSqGSIb3DQEBBAUAMIGbMQswCQYD
3
+ VQQGEwJGUjEMMAoGA1UECBMDSURGMQ4wDAYDVQQHEwVQYXJpczEXMBUGA1UEChMO
4
+ VGVzdCBTZXJ2ZXIgUDExFDASBgNVBAsTC1Byb2Nlc3Mtb25lMRcwFQYDVQQDEw5N
5
+ aWNrYWVsIFJlbW9uZDEmMCQGCSqGSIb3DQEJARYXY29udGFjdEBwcm9jZXNzLW9u
6
+ ZS5uZXQwHhcNMDYwMzAzMTYwNjQ2WhcNMTYwMjI5MTYwNjQ2WjCBmzELMAkGA1UE
7
+ BhMCRlIxDDAKBgNVBAgTA0lERjEOMAwGA1UEBxMFUGFyaXMxFzAVBgNVBAoTDlRl
8
+ c3QgU2VydmVyIFAxMRQwEgYDVQQLEwtQcm9jZXNzLW9uZTEXMBUGA1UEAxMOTWlj
9
+ a2FlbCBSZW1vbmQxJjAkBgkqhkiG9w0BCQEWF2NvbnRhY3RAcHJvY2Vzcy1vbmUu
10
+ bmV0MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC8sZ/Wb2GqYPL43OBzBNz0
11
+ gFT1iDZMLLgpMYqBZElKul7GGCdLZElgqVYm8KRxPIiRd5BPbueNkhw/YhhcQAay
12
+ 4+Ef7Y6zdjXAsYGtYhdmms6icCk1RxIMa2TvJ6dZlraV2KJdNExxhMtSyj3NBVs4
13
+ 276RcZSukN2AR4/pziWysQIDAQABo4IBBDCCAQAwHQYDVR0OBBYEFMBW8llnB7AA
14
+ hu9u+ivBndDdbmLTMIHQBgNVHSMEgcgwgcWAFMBW8llnB7AAhu9u+ivBndDdbmLT
15
+ oYGhpIGeMIGbMQswCQYDVQQGEwJGUjEMMAoGA1UECBMDSURGMQ4wDAYDVQQHEwVQ
16
+ YXJpczEXMBUGA1UEChMOVGVzdCBTZXJ2ZXIgUDExFDASBgNVBAsTC1Byb2Nlc3Mt
17
+ b25lMRcwFQYDVQQDEw5NaWNrYWVsIFJlbW9uZDEmMCQGCSqGSIb3DQEJARYXY29u
18
+ dGFjdEBwcm9jZXNzLW9uZS5uZXSCCQDgRO+nWDrHbDAMBgNVHRMEBTADAQH/MA0G
19
+ CSqGSIb3DQEBBAUAA4GBAGtYeVL7BlksuXf79V/WfBPosKD4yVzs7P9GsgS/D10T
20
+ HMIRbjIOma4IVy8Es/UBJ0Q4gPojVg4lPo3xv/PSgSDJfbcJyWjSbAh0eGvHtNc5
21
+ 4GnYVx5ox0o0MBR8Mt0ChbwA5QMSo6bqc5tRK6+B+ib4ELix7MCSq3wdh7HcuL9D
22
+ -----END CERTIFICATE-----
23
+ -----BEGIN RSA PRIVATE KEY-----
24
+ MIICXQIBAAKBgQC8sZ/Wb2GqYPL43OBzBNz0gFT1iDZMLLgpMYqBZElKul7GGCdL
25
+ ZElgqVYm8KRxPIiRd5BPbueNkhw/YhhcQAay4+Ef7Y6zdjXAsYGtYhdmms6icCk1
26
+ RxIMa2TvJ6dZlraV2KJdNExxhMtSyj3NBVs4276RcZSukN2AR4/pziWysQIDAQAB
27
+ AoGADl1DOrK975dzx6gg2gCrxV0jmpFk+MWKu3APCCyXO74WSuQ50Y5v25Dogwxc
28
+ qFYgW1qLvNBHhkpyJg0Up6kkGUalWNgdX/D63QMA/HeSLIpuUsoTGt/F3yu5wcaJ
29
+ 8y+WVZ5fcNK+rSYyNdnxv0+euazr2HUpfe5zqscGMdT5kDECQQDop9vLcop4aPkd
30
+ h5e/AJt6irb/GQt7MBYZzxI+lof8SoASyL3EcMjZI002JCLXWirOX47eO7G7v/D1
31
+ v7feRz3dAkEAz6CIqd9nHPT1QNmhb6QANC6Cy1PzQdAOjxz+0CRHzPBOy+bnHI00
32
+ 921RQdCiJ/KEp4olDrTVOMkjbKa928kM5QJBAJspuBDLZ0Y+3EWxdKbSBN+JO9qO
33
+ HXYe795ul8BeLHs6RIhCkS09+vW18Xy2RPZTEFFqsaHNNg/9RvrezgXUhZECQQCp
34
+ Tk3Cv9J0cWeALzcOM1ybMIYlSVqmgwMsPkem8L6/5gFLEgnJZXgYf0LweTGRg5ga
35
+ inK3cEwilxnU4o8VJvflAkBcd/gsVklKfr0Z+vcfjoXsIAN5DoWQYozo7omUIudS
36
+ 5wjh6y5uYtkhazIJRxNUi9WMfKqhnrje0NfG+p+Sxs7J
37
+ -----END RSA PRIVATE KEY-----
@@ -0,0 +1,32 @@
1
+ #Social Stream Presence: ejabberd config
2
+
3
+ #Ejabberd node server domain
4
+ server_domain=trapo
5
+
6
+ #Scripts Path
7
+ scripts_path=/home/aldo/ejabberd-2.1.8_scripts
8
+
9
+ #Source path: uncomment to compile ejabberd social stream module
10
+ source_path=/home/aldo/ejabberd-2.1.8_source/src
11
+
12
+ #It is also necessary to modify the file: /etc/ejabberd/ejabberd.cfg
13
+ #%%{auth_method, external}.
14
+ #%%{extauth_program, "scripts_path/authentication_script"}.
15
+
16
+ #API REST
17
+ auth_api=http://0.0.0.0:3000/users/sign_in
18
+ set_connection_api=http://0.0.0.0:3000/xmpp/setConnection
19
+ unset_connection_api=http://0.0.0.0:3000/xmpp/unsetConnection
20
+ reset_connection_api=http://0.0.0.0:3000/xmpp/resetConnection
21
+ synchronize_presence_api=http://0.0.0.0:3000/xmpp/synchronizePresence
22
+ set_presence_api=http://0.0.0.0:3000/xmpp/setPresence
23
+ unset_presence_api=http://0.0.0.0:3000/xmpp/unsetPresence
24
+
25
+ #Social Stream Login
26
+ ss_login=social_stream-presence
27
+
28
+ #Social Stream PASSWORD
29
+ ss_password=DnVCB8G|R$VGmZ@2?5=CYS8z)NrL@LuQ&LTCUh^9B(DF4gC&sQpfbCMbaNKEdNrGYkT4L5zxM0wNWs5q3?ww(b&0d5fK87z^BmgJMMF2SKXT9pEk^UEcch!GX!Avf5GT9)j@FpHe)4RH)BK7J98u!sUmJHUN(Je6aBmn!FtZ4Ab5h8$|nsvUt3Jkq?21HOH$r0sDyJZZvGOCgFS2EKw@0wXsJRHYVRPBe&Eb!1X55e55bQ^h2AW&^R70TK0m)Fu8
30
+
31
+ #Ejabberd Server Password
32
+ ejabberd_password=G&s6GBnO)anw2Ene%K12Cb=0quj@uDmA
@@ -0,0 +1,117 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'logger'
4
+ require 'rest_client'
5
+
6
+ $stdout.sync = true
7
+ $stdin.sync = true
8
+
9
+ path = "/var/log/ejabberd/auth.log"
10
+ file = File.open(path, File::WRONLY | File::APPEND | File::CREAT)
11
+ file.sync = true
12
+ $logger = Logger.new(file)
13
+ $logger.level = Logger::DEBUG
14
+
15
+ $logger.info "#{Process.pid}: Starting ejabberd authentication service"
16
+
17
+
18
+ def getOption(option)
19
+ File.open('/etc/ejabberd/ssconfig.cfg', 'r') do |f1|
20
+ while line = f1.gets
21
+ line = line.gsub(/\n/,'')
22
+ if line.match(/^#/)
23
+ #Comments
24
+ elsif line.match(/^#{option}/)
25
+ return line.gsub(/#{option}/,'')
26
+ end
27
+ end
28
+ end
29
+ return "Undefined"
30
+ end
31
+
32
+ $accessUrl = getOption("auth_api=")
33
+ $sslogin = getOption("ss_login=")
34
+ $sspass = getOption("ss_password=")
35
+
36
+
37
+ def auth(username, password)
38
+
39
+ #[TEST ONLY] Allow everybody
40
+ #return true
41
+
42
+ #[TEST] Admin password
43
+ #if username == "admin" and password == "pass"
44
+ # return true
45
+ #end
46
+
47
+ #Social Stream password
48
+ if username == $sslogin and password == $sspass
49
+ return true
50
+ end
51
+
52
+ begin
53
+ response = RestClient.post $accessUrl, :user => { :email => username , :password => password }
54
+
55
+ if response.code == 201
56
+ return true
57
+ else
58
+ return false
59
+ end
60
+
61
+ rescue => e
62
+
63
+ unless e.class.name == "RestClient::Unauthorized" and e.message == "401 Unauthorized"
64
+ $logger.error "#{Process.pid}: Exception in auth(username, password)"
65
+ $logger.error "#{Process.pid}: #{e.class.name}: #{e.message}"
66
+ end
67
+
68
+ return false
69
+ end
70
+
71
+ end
72
+
73
+
74
+ loop do
75
+ begin
76
+ $stdin.eof? # wait for input
77
+ start = Time.now
78
+
79
+ msg = $stdin.read(2)
80
+ length = msg.unpack('n').first
81
+
82
+ msg = $stdin.read(length)
83
+ cmd, *data = msg.split(":")
84
+
85
+ $logger.info "#{Process.pid}: Incoming Request: '#{cmd}'"
86
+ success = case cmd
87
+
88
+ when "auth"
89
+ $logger.info "#{Process.pid}: Authenticating #{data[0]}@#{data[1]}"
90
+ $logger.info "#{Process.pid}: With password #{data[2]}"
91
+ #password = data[2]
92
+
93
+ #Authorization condition for LOGIN
94
+ auth(data[0], data[2])
95
+
96
+
97
+ when "isuser"
98
+
99
+ $logger.info "#{Process.pid}: Isuser #{data[0]}@#{data[1]}"
100
+
101
+ #Authorization condition for ISUSER (Add buddys)
102
+ true
103
+
104
+ else
105
+ false
106
+ end
107
+
108
+ bool = success ? 1 : 0
109
+ $stdout.write [2, bool].pack("nn")
110
+ $logger.info "#{Process.pid}: Response: #{success ? "success" : "failure"}"
111
+ rescue => e
112
+ $logger.error "#{Process.pid}: #{e.class.name}: #{e.message}"
113
+ $logger.error "#{Process.pid}: " + e.backtrace.join("\n\t")
114
+ $logger.error "#{Process.pid}: Finish process"
115
+ break
116
+ end
117
+ end
@@ -0,0 +1,114 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'logger'
4
+ require 'rest_client'
5
+
6
+ $stdout.sync = true
7
+ $stdin.sync = true
8
+
9
+ path = "/var/log/ejabberd/auth.log"
10
+ file = File.open(path, File::WRONLY | File::APPEND | File::CREAT)
11
+ file.sync = true
12
+ $logger = Logger.new(file)
13
+ $logger.level = Logger::DEBUG
14
+
15
+ $logger.info "#{Process.pid}: Starting ejabberd authentication service"
16
+
17
+
18
+ def getOption(option)
19
+ File.open('/etc/ejabberd/ssconfig.cfg', 'r') do |f1|
20
+ while line = f1.gets
21
+ line = line.gsub(/\n/,'')
22
+ if line.match(/^#/)
23
+ #Comments
24
+ elsif line.match(/^#{option}/)
25
+ return line.gsub(/#{option}/,'')
26
+ end
27
+ end
28
+ end
29
+ return "Undefined"
30
+ end
31
+
32
+ $accessUrl = getOption("auth_api=")
33
+ $sslogin = getOption("ss_login=")
34
+ $sspass = getOption("ss_password=")
35
+
36
+
37
+ def auth(username, password)
38
+
39
+ #[TEST] Admin password
40
+ if username == "admin" and password == "pass"
41
+ return true
42
+ end
43
+
44
+ #Social Stream password
45
+ if username == $sslogin and password == $sspass
46
+ return true
47
+ end
48
+
49
+ begin
50
+ response = RestClient.post $accessUrl, :user => { :email => username , :password => password }
51
+
52
+ if response.code == 201
53
+ return true
54
+ else
55
+ return false
56
+ end
57
+
58
+ rescue => e
59
+
60
+ unless e.class.name == "RestClient::Unauthorized" and e.message == "401 Unauthorized"
61
+ $logger.error "#{Process.pid}: Exception in auth(username, password)"
62
+ $logger.error "#{Process.pid}: #{e.class.name}: #{e.message}"
63
+ end
64
+
65
+ return false
66
+ end
67
+
68
+ end
69
+
70
+
71
+ loop do
72
+ begin
73
+ $stdin.eof? # wait for input
74
+ start = Time.now
75
+
76
+ msg = $stdin.read(2)
77
+ length = msg.unpack('n').first
78
+
79
+ msg = $stdin.read(length)
80
+ cmd, *data = msg.split(":")
81
+
82
+ $logger.info "#{Process.pid}: Incoming Request: '#{cmd}'"
83
+ success = case cmd
84
+
85
+ when "auth"
86
+ $logger.info "#{Process.pid}: Authenticating #{data[0]}@#{data[1]}"
87
+ $logger.info "#{Process.pid}: With password #{data[2]}"
88
+ #password = data[2]
89
+
90
+ #Authorization condition for LOGIN
91
+ auth(data[0], data[2])
92
+
93
+
94
+ when "isuser"
95
+
96
+ $logger.info "#{Process.pid}: Isuser #{data[0]}@#{data[1]}"
97
+
98
+ #Authorization condition for ISUSER (Add buddys)
99
+ true
100
+
101
+ else
102
+ false
103
+ end
104
+
105
+ bool = success ? 1 : 0
106
+ $stdout.write [2, bool].pack("nn")
107
+ $logger.info "#{Process.pid}: Response: #{success ? "success" : "failure"}"
108
+ rescue => e
109
+ $logger.error "#{Process.pid}: #{e.class.name}: #{e.message}"
110
+ $logger.error "#{Process.pid}: " + e.backtrace.join("\n\t")
111
+ $logger.error "#{Process.pid}: Finish process"
112
+ break
113
+ end
114
+ end