Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2017-18 Fixes #4

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ dependencies {
}
android {
compileSdkVersion 21
buildToolsVersion "21.0.1"
buildToolsVersion '25.0.0'

defaultConfig {
minSdkVersion 9
Expand Down
48 changes: 37 additions & 11 deletions app/src/main/java/com/manateams/scraper/TEAMSGradeRetriever.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@

import javax.net.ssl.SSLSocketFactory;


public class TEAMSGradeRetriever {


Expand All @@ -56,7 +55,7 @@ public TEAMSUserType getUserType(final String username) {
public String getNewCookie(final String username, final String password, final TEAMSUserType userType) {
try {
final String cStoneCookie = getAISDCookie(username, password);
final String TEAMSCookie = getTEAMSCookie(cStoneCookie, userType);
final String TEAMSCookie = getTEAMSCookie(username, password, userType);
return cStoneCookie + ';' + TEAMSCookie;
} catch (IOException e) {
e.printStackTrace();
Expand Down Expand Up @@ -135,15 +134,19 @@ public String postTEAMSLogin(final String username, final String password, final
}

private String getAISDCookie(final String username, final String password) throws IOException {
final String rawQuery = "cn=" + username + "&[password]=" + password;
final String query = URLEncoder.encode(rawQuery, "UTF-8");
final String rawQuery = "[Client.Hardware]=&[User.ViewportSize]=1920x954&cn=" + username + "&[password]=" + password;

final String[] headers = new String[]{
"User-Agent: QHAC",
"Accept: */*"
"Origin: https://my.austinisd.org",
"Upgrade-Insecure-Requests: 1",
"User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:55.0) Gecko/20100101 Firefox/55.0",
"Accept: */*",
"Referer: https://my.austinisd.org/LoginPolicy.jsp",
"Accept-Encoding: gzip, deflate, br",
"Accept-Language: en-US,en;q=0.8"
};

final String response = doRawPOSTRequest("my.austinisd.org", "/WebNetworkAuth/", headers, query);
final String response = doRawPOSTRequest("my.austinisd.org", "/WebNetworkAuth/", headers, rawQuery);

for (final String line : response.split("\n")) {
if (line.startsWith("Set-Cookie: CStoneSessionID=")) {
Expand All @@ -154,14 +157,17 @@ private String getAISDCookie(final String username, final String password) throw
return null;
}

private String getTEAMSCookie(final String AISDCookie, final TEAMSUserType userType) throws IOException {
private String getTEAMSCookie(final String username, final String password, final TEAMSUserType userType) throws IOException {

final String[] headers = new String[]{
"Cookie: " + AISDCookie,
"Upgrade-Insecure-Requests: 1",
"User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:55.0) Gecko/20100101 Firefox/55.0",
"Accept: */*",
"User-Agent: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36"
"Accept-Encoding: gzip, deflate, br",
"Accept-Language: en-US,en;q=0.8"
};

final String response = doRawPOSTRequest(userType.teamsHost(), "/selfserve/EntryPointSignOnAction.do?parent=" + userType.isParent(), headers, "");
final String response = doGETRequest("https://grades.austinisd.org/selfserve/EntryPointSignOnAction.do?parent=false");

for (final String line : response.split("\n")) {
if (line.startsWith("Set-Cookie: JSESSIONID=")) {
Expand Down Expand Up @@ -194,6 +200,26 @@ private String doPOSTRequest(final String url, final HashMap<String, String> hea
return responseString;
}

private String doGETRequest(final String url) {
final OkHttpClient client = new OkHttpClient();

Request request = new Request.Builder()
.url(url)
.header("User-Agent", "OkHttp Headers.java")
.get()
.build();

String responseString = null;
try {
Response response = client.newCall(request).execute();
if (!response.isSuccessful()) throw new IOException("Unexpected code " + response);
responseString = response.headers().toString();
} catch (IOException e) {
e.printStackTrace();
}
return responseString;
}

private String doRawPOSTRequest(final String host, final String path, final String[] headers, final String postData) throws IOException {
final Socket socket = SSLSocketFactory.getDefault().createSocket(host,
443);
Expand Down