Class: ZimbraWall::Request
- Inherits:
-
Object
- Object
- ZimbraWall::Request
- Defined in:
- lib/zimbra_wall/request.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
Returns the value of attribute body.
-
#headers ⇒ Object
Returns the value of attribute headers.
-
#parser ⇒ Object
Returns the value of attribute parser.
Instance Method Summary collapse
- #auth_request? ⇒ Boolean
- #auth_request_params? ⇒ Boolean
- #auth_username ⇒ Object
- #auth_zco_username ⇒ Object
- #auth_zimbraId ⇒ Object
- #blank_password_from_body ⇒ Object
-
#default_auth_request? ⇒ Boolean
This is the post Auth request sent by Webmail, ActiveSync and POP and IMAP.
-
#initialize(connection, parser = nil) ⇒ Request
constructor
A new instance of Request.
- #modify_query_field(field, value) ⇒ Object
- #port ⇒ Object
- #route_request? ⇒ Boolean
- #user_token ⇒ Object
- #zco_auth_request? ⇒ Boolean
Constructor Details
#initialize(connection, parser = nil) ⇒ Request
Returns a new instance of Request.
7 8 9 10 11 |
# File 'lib/zimbra_wall/request.rb', line 7 def initialize(connection, parser = nil) @body = connection.body @headers = connection.headers @parser = parser end |
Instance Attribute Details
#body ⇒ Object
Returns the value of attribute body.
5 6 7 |
# File 'lib/zimbra_wall/request.rb', line 5 def body @body end |
#headers ⇒ Object
Returns the value of attribute headers.
5 6 7 |
# File 'lib/zimbra_wall/request.rb', line 5 def headers @headers end |
#parser ⇒ Object
Returns the value of attribute parser.
5 6 7 |
# File 'lib/zimbra_wall/request.rb', line 5 def parser @parser end |
Instance Method Details
#auth_request? ⇒ Boolean
13 14 15 |
# File 'lib/zimbra_wall/request.rb', line 13 def auth_request? default_auth_request? || zco_auth_request? end |
#auth_request_params? ⇒ Boolean
33 34 35 36 |
# File 'lib/zimbra_wall/request.rb', line 33 def auth_request_params? uri = Addressable::URI.parse("#{@headers['Origin']}/?#{@body}") uri.query_values["loginOp"] == "login" end |
#auth_username ⇒ Object
69 70 71 72 |
# File 'lib/zimbra_wall/request.rb', line 69 def auth_username uri = Addressable::URI.parse("http://localhost/?#{@body}") uri.query_values["username"] end |
#auth_zco_username ⇒ Object
63 64 65 66 67 |
# File 'lib/zimbra_wall/request.rb', line 63 def auth_zco_username # Hold on, we have to dig deeper xml = XmlSimple.xml_in @body xml["Body"].first["AuthRequest"].first["account"].first["content"] end |
#auth_zimbraId ⇒ Object
59 60 61 |
# File 'lib/zimbra_wall/request.rb', line 59 def auth_zimbraId headers["Auth-User"] end |
#blank_password_from_body ⇒ Object
27 28 29 30 31 |
# File 'lib/zimbra_wall/request.rb', line 27 def blank_password_from_body params = CGI::parse(@body) params['password'] = [''] URI.encode_www_form params end |
#default_auth_request? ⇒ Boolean
This is the post Auth request sent by Webmail, ActiveSync and POP and IMAP
18 19 20 |
# File 'lib/zimbra_wall/request.rb', line 18 def default_auth_request? @parser.http_method == 'POST' && @parser.request_url == '/' && @headers["Cookie"] = "ZM_TEST=true" && auth_request_params? end |
#modify_query_field(field, value) ⇒ Object
38 39 40 41 42 |
# File 'lib/zimbra_wall/request.rb', line 38 def modify_query_field(field, value) uri = Addressable::URI.parse("#{@headers['Referer']}?#{@body}") uri.query_values[field] = value uri.query_values end |
#port ⇒ Object
48 49 50 51 |
# File 'lib/zimbra_wall/request.rb', line 48 def port return ZimbraWall::Config::ROUTE_REQUEST_PORT if route_request? return ZimbraWall::Config::AUTH_REQUEST_PORT if auth_request? end |
#route_request? ⇒ Boolean
44 45 46 |
# File 'lib/zimbra_wall/request.rb', line 44 def route_request? @parser.request_url == ZimbraWall::Config::ROUTE_URL end |
#user_token ⇒ Object
53 54 55 56 57 |
# File 'lib/zimbra_wall/request.rb', line 53 def user_token return auth_username if default_auth_request? return auth_zimbraId if route_request? return auth_zco_username if zco_auth_request? end |
#zco_auth_request? ⇒ Boolean
22 23 24 |
# File 'lib/zimbra_wall/request.rb', line 22 def zco_auth_request? @parser.http_method == 'POST' && @parser.request_url == "/service/soap/AuthRequest" && @headers["User-Agent"].match(/Zimbra-ZCO/) end |