Revision 94abc2c7 src/com/rackspace/cloud/android/PithosLoginActivity.java
b/src/com/rackspace/cloud/android/PithosLoginActivity.java | ||
---|---|---|
2 | 2 |
|
3 | 3 |
|
4 | 4 |
|
5 |
|
|
6 |
|
|
5 | 7 |
import java.net.URLDecoder; |
6 |
import java.util.Date; |
|
8 |
import java.util.HashMap; |
|
9 |
import java.util.Map; |
|
7 | 10 |
import java.util.StringTokenizer; |
8 |
import java.util.regex.Matcher; |
|
9 |
import java.util.regex.Pattern; |
|
10 | 11 |
|
11 | 12 |
import org.apache.http.impl.cookie.BasicClientCookie; |
12 | 13 |
|
... | ... | |
16 | 17 |
import android.net.http.SslError; |
17 | 18 |
import android.os.Build; |
18 | 19 |
import android.os.Bundle; |
19 |
import android.text.format.DateFormat; |
|
20 | 20 |
import android.text.method.PasswordTransformationMethod; |
21 | 21 |
import android.util.Log; |
22 | 22 |
import android.webkit.CookieManager; |
... | ... | |
56 | 56 |
CookieSyncManager.createInstance(this); |
57 | 57 |
CookieSyncManager.getInstance().startSync(); |
58 | 58 |
CookieSyncManager.getInstance().sync(); |
59 |
String loginUrl ="https://plus.pithos.grnet.gr/im/login/";//invitation?code=3219662435709009446"); |
|
59 |
//String loginUrl ="https://plus.pithos.grnet.gr/im/login/";//invitation?code=3219662435709009446");
|
|
60 | 60 |
/* |
61 | 61 |
CookieManager.getInstance().setCookie(loginUrl, "_pithos2_a='';expires=Mon, 17 Oct 2010 10:47:11 UTC;"); |
62 | 62 |
CookieManager.getInstance().removeExpiredCookie(); |
63 | 63 |
CookieManager.getInstance().removeSessionCookie();*/ |
64 |
CookieManager.getInstance().removeAllCookie(); |
|
64 |
//CookieManager.getInstance().removeAllCookie();
|
|
65 | 65 |
final WebView webview = (WebView) findViewById(R.id.browser);//new WebView(this); |
66 | 66 |
webview.getSettings().setJavaScriptEnabled(true); |
67 | 67 |
// webview.setHttpAuthUsernamePassword("vho.grnet.gr", "VHO login", |
... | ... | |
76 | 76 |
//webview.getSettings().setDefaultZoom(ZoomDensity.); |
77 | 77 |
if(Build.VERSION.SDK_INT!=7) |
78 | 78 |
webview.getSettings().setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN); |
79 |
|
|
79 |
|
|
80 | 80 |
webview.setWebViewClient(new WebViewClient() { |
81 | 81 |
|
82 | 82 |
public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error){ |
... | ... | |
92 | 92 |
|
93 | 93 |
public void onPageFinished(WebView view, String url) { |
94 | 94 |
super.onPageFinished(view, url); |
95 |
//webview.loadUrl("javascript:window.HTMLOUT.showHTML('<head>'+document.getElementsByTagName('html')[0].innerHTML+'</head>');"); |
|
96 |
//CookieSyncManager.getInstance().sync(); |
|
97 | 95 |
|
98 |
String cookie = CookieManager.getInstance().getCookie(url); |
|
99 |
Log.i("LOGIN COOKIE",url+" c: "+cookie); |
|
96 |
CookieSyncManager.getInstance().sync(); |
|
100 | 97 |
|
101 |
if(null!=cookie && cookie.startsWith("_pithos2_a")){ |
|
102 |
try { |
|
103 |
String value = URLDecoder.decode(parseRawCookie(cookie).getValue()); |
|
104 |
StringTokenizer str = new StringTokenizer(value,"|"); |
|
105 |
if(str.countTokens()==2){ |
|
106 |
String u = str.nextToken(); |
|
107 |
String t = str.nextToken(); |
|
108 |
Log.i("value",value); |
|
109 |
Log.i("s1",u); |
|
110 |
Log.i("s2",t); |
|
111 |
exit(u,t); |
|
98 |
String cookie = CookieManager.getInstance().getCookie(url); |
|
99 |
Log.i("LOGIN COOKIE",url+" c: "+cookie +" "+cookie.contains("_pithos2_a")); |
|
100 |
/*if(url.indexOf('?')!=-1){ |
|
101 |
String q = url.substring(url.indexOf('?'),url.length()); |
|
102 |
Log.i("LOGIN COOKIE",url+" c: "+q); |
|
103 |
Map<String,String> params = getQueryMap(q); |
|
104 |
String token = params.get("token"); |
|
105 |
String user = params.get("user"); |
|
106 |
if(token!=null&&user!=null) |
|
107 |
exit(user,token); |
|
108 |
|
|
109 |
}*/ |
|
110 |
if(null!=cookie && cookie.contains("_pithos2_a")){ |
|
111 |
StringTokenizer str1 = new StringTokenizer(cookie,";"); |
|
112 |
while(str1.hasMoreTokens()){ |
|
113 |
String cc = str1.nextToken(); |
|
114 |
Log.i("LOGIN","token:"+cc); |
|
115 |
if(cc.trim().startsWith("_pithos2_a")){ |
|
116 |
Log.i("LOGIN COOKIE INSIDE",url+" c: "+cc); |
|
117 |
try { |
|
118 |
String value = URLDecoder.decode(parseRawCookie(cc).getValue()); |
|
119 |
StringTokenizer str = new StringTokenizer(value,"|"); |
|
120 |
if(str.countTokens()==2){ |
|
121 |
String u = str.nextToken(); |
|
122 |
String t = str.nextToken(); |
|
123 |
Log.i("value",value); |
|
124 |
Log.i("s1",u); |
|
125 |
Log.i("s2",t); |
|
126 |
exit(u,t); |
|
127 |
return; |
|
128 |
} |
|
129 |
|
|
130 |
//exit(s[0], s[1]); |
|
131 |
} catch (Exception e) { |
|
132 |
// TODO Auto-generated catch block |
|
133 |
e.printStackTrace(); |
|
134 |
} |
|
112 | 135 |
} |
113 |
|
|
114 |
//exit(s[0], s[1]); |
|
115 |
} catch (Exception e) { |
|
116 |
// TODO Auto-generated catch block |
|
117 |
e.printStackTrace(); |
|
118 | 136 |
} |
137 |
|
|
119 | 138 |
} |
120 | 139 |
} |
121 | 140 |
|
... | ... | |
180 | 199 |
webview.loadUrl(loginUrl);//invitation?code=3219662435709009446"); |
181 | 200 |
//webview.loadUrl("http://www.google.gr"); |
182 | 201 |
} |
202 |
|
|
203 |
public static Map<String, String> getQueryMap(String query) { |
|
204 |
String[] params = query.split("&"); |
|
205 |
Map<String, String> map = new HashMap<String, String>(); |
|
206 |
for (String param : params) { |
|
207 |
String name = param.split("=")[0]; |
|
208 |
String value = param.split("=")[1]; |
|
209 |
if(param.endsWith("==")) |
|
210 |
value=value+"=="; |
|
211 |
else if(param.endsWith("=")) |
|
212 |
value=value+"="; |
|
213 |
|
|
214 |
Log.d("DD",name +" "+value); |
|
215 |
map.put(name, value); |
|
216 |
} |
|
217 |
return map; |
|
218 |
} |
|
183 | 219 |
void exit(String username,String token){ |
184 | 220 |
Log.i("LOGINA",username+" "+token); |
185 | 221 |
Intent result = new Intent(); |
... | ... | |
224 | 260 |
|
225 | 261 |
return cookie; |
226 | 262 |
} |
263 |
|
|
264 |
private String lastHtml; |
|
265 |
|
|
266 |
public void setLastHtml(String lastHtml) { |
|
267 |
this.lastHtml = lastHtml; |
|
268 |
} |
|
269 |
|
|
270 |
public String getLastHtml() { |
|
271 |
return lastHtml; |
|
272 |
} |
|
273 |
class MyJavaScriptInterface { |
|
274 |
|
|
275 |
public void showHTML(String html) { |
|
276 |
setLastHtml(html); |
|
277 |
|
|
278 |
} } |
|
279 |
|
|
280 |
private String getHtmlValue(String substring, String html){ String |
|
281 |
result=null; boolean found = false; found = html.contains(substring); if |
|
282 |
(found) { int indx = html.indexOf(substring); StringBuffer res = new |
|
283 |
StringBuffer(); for (int i = indx + substring.length(); i < html |
|
284 |
.length(); i++) { char c = html.charAt(i); if (c == '<') break; |
|
285 |
res.append(c); } |
|
286 |
|
|
287 |
result = res.toString(); result = result.trim(); |
|
288 |
|
|
289 |
} return result; } |
|
290 |
|
|
227 | 291 |
} |
Also available in: Unified diff