Created
June 14, 2013 03:30
-
-
Save yoshimov/5779267 to your computer and use it in GitHub Desktop.
Script source for Google Apps Script Service for changing Hikari Phone parameters.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Script-as-app template. | |
function doGet(e) { | |
var ret, num; | |
if (e != null) { | |
num = e.parameter.num; | |
} else { | |
num = "5"; | |
} | |
if (!hikariLogin()) { | |
ret = HtmlService.createHtmlOutput("login failed"); | |
return ret; | |
} | |
hikariChangeForwardingTime(num); | |
hikariLogout(); | |
return HtmlService.createHtmlOutput("OK"); | |
} | |
function getToken(content) { | |
if ((index = content.search(/name="org.apache.struts.taglib.html.TOKEN"/i)) >= 0) { | |
var token = content.substring(index).split("\"")[3]; | |
ScriptProperties.setProperty("token", token); | |
} | |
if ((index = content.search(/action="\/AGL_Logout.do"/i)) >= 0) { | |
var sub = content.substring(index); | |
if ((index = sub.search(/name="org.apache.struts.taglib.html.TOKEN"/i)) >= 0) { | |
var token = sub.substring(index).split("\"")[3]; | |
ScriptProperties.setProperty("loginToken", token); | |
} | |
} | |
} | |
function hikariLogin() { | |
// 初期画面 | |
var res = UrlFetchApp.fetch("https://www.hikari.ntt-east.net/AGL_Disp.do"); | |
var cookieStr = res.getHeaders()["Set-Cookie"]; | |
var content = res.getContentText(); | |
var index, oneTimeId; | |
if ((index = content.search(/name="oneTimeId"/i)) >= 0) { | |
oneTimeId = content.substring(index).split("\"")[3]; | |
} else { | |
return false; | |
} | |
// ログイン画面 | |
var phoneNo = ScriptProperties.getProperty("phoneNo"); | |
var password = ScriptProperties.getProperty("password"); | |
var params = {method: "POST", headers:{"Cookie": cookieStr}, payload: {"oneTimeId": oneTimeId, phoneNo: phoneNo, pass: password}}; | |
var res = UrlFetchApp.fetch("https://www.hikari.ntt-east.net/AGL_Login.do", params); | |
var content = res.getContentText(); | |
ScriptProperties.setProperty("cookie", res.getHeaders()["Set-Cookie"]); | |
getToken(content); | |
if (content.match(/AGS_Disp.do/i)) | |
return true; | |
return false; | |
} | |
function hikariLogout() { | |
// ログアウト | |
var token = ScriptProperties.getProperty("loginToken"); | |
var cookie = ScriptProperties.getProperty("cookie"); | |
var params = {method: "POST", headers:{"Cookie": cookie}, payload: {"org.apache.struts.taglib.html.TOKEN": token}}; | |
var res = UrlFetchApp.fetch("https://www.hikari.ntt-east.net/AGL_Logout.do", params); | |
if (res) | |
return true; | |
return false; | |
} | |
function hikariChangeForwardingTime(num) { | |
// トップメニューからボイスワープを選ぶ | |
var token = ScriptProperties.getProperty("token"); | |
var cookie = ScriptProperties.getProperty("cookie"); | |
var phoneNo = ScriptProperties.getProperty("phoneNo"); | |
var params = {method: "POST", headers:{"Cookie": cookie}, payload: {"org.apache.struts.taglib.html.TOKEN": token, serviceCode: "2", targetPhoneNo: phoneNo}}; | |
var res = UrlFetchApp.fetch("https://www.hikari.ntt-east.net/csa-cusvoicewarp/VUM_Disp.do", params); | |
// there is no set cookie header | |
// ScriptProperties.setProperty("cookie", res.getHeaders()["Set-Cookie"]); | |
getToken(res.getContentText()); | |
// 開始、停止を選ぶ | |
var token = ScriptProperties.getProperty("token"); | |
var params = {method: "POST", headers:{"Cookie": cookie}, payload: {"org.apache.struts.taglib.html.TOKEN": token}}; | |
var res = UrlFetchApp.fetch("https://www.hikari.ntt-east.net/csa-cusvoicewarp/VUS_Disp.do", params); | |
getToken(res.getContentText()); | |
// 秒数を指定(無応答時転送と話中時転送を組み合わせ) | |
var token = ScriptProperties.getProperty("token"); | |
var params = {method: "POST", headers:{"Cookie": cookie}, payload: {"org.apache.struts.taglib.html.TOKEN": token, transitionState: "110", noAnswerOrInCallingWaitTime: num}}; | |
var res = UrlFetchApp.fetch("https://www.hikari.ntt-east.net/csa-cusvoicewarp/VUS_Regist.do", params); | |
getToken(res.getContentText()); | |
// 初期メニューに戻る | |
var token = ScriptProperties.getProperty("loginToken"); | |
var params = {method: "POST", headers:{"Cookie": cookie}, payload: {"org.apache.struts.taglib.html.TOKEN": token}}; | |
var res = UrlFetchApp.fetch("https://www.hikari.ntt-east.net/AGS_Disp.do", params); | |
getToken(res.getContentText()); | |
return true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment