Advertisement
Guest User

proxy2ch helper v6 (HTA)

a guest
Apr 5th, 2015
552
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 12.00 KB | None | 0 0
  1. <HTML XMLNS:HTA><HEAD><TITLE>proxy2ch helper - 初期化</TITLE>
  2. <META id=utf8n content="text/html; charset=UTF-8" http-equiv=Content-Type><HTA:APPLICATION applicationName="proxy2ch helper" innerBorder="no" navigable="yes" selection="no" singleInstance="yes" version="6"></HTA:APPLICATION>
  3. <SCRIPT type=text/javascript>
  4. var SWbemLocator = new ActiveXObject("WbemScripting.SWbemLocator");
  5. (function () {
  6.     var wbemImpersonationLevelImpersonate = 3;
  7.     SWbemLocator.security_.impersonationLevel = wbemImpersonationLevelImpersonate;
  8. })();
  9. var SWbemServices = SWbemLocator.connectServer(".", "root/cimv2");
  10. var $ = document.getElementById;
  11. function start() {
  12.     if (!/\\proxy2ch\.exe$/i.test($("executablePath").value)) {
  13.         alert("proxy2ch.exe の場所 (フルパス) を指定してください。");
  14.         selectExecutablePath();
  15.     }
  16.     if (!/\\proxy2ch\.exe$/i.test($("executablePath").value)) { return }
  17.     stop();
  18.     var commandLine = [ $("executablePath").value ];
  19.     if ($("port").value) {
  20.         commandLine.push("-p");
  21.         commandLine.push($("port").value);
  22.     }
  23.     if ($("timeout").value) {
  24.         commandLine.push("-t");
  25.         commandLine.push($("timeout").value);
  26.     }
  27.     if ($("agent").value) {
  28.         commandLine.push("-a");
  29.         commandLine.push($("agent").value);
  30.     }
  31.     if ($("global").checked) { commandLine.push("-g") }
  32.     if ($("proxyServer").value && $("proxyPort").value) {
  33.         commandLine.push("--proxy");
  34.         commandLine.push($("proxyServer").value + ":" + $("proxyPort").value);
  35.     }
  36.     if ($("appKey").value && $("hmacKey").value) {
  37.         commandLine.push("--api");
  38.         commandLine.push($("appKey").value + ":" + $("hmacKey").value);
  39.     }
  40.     if ($("apiAuthUa").value) {
  41.         commandLine.push("--api-auth-ua");
  42.         commandLine.push($("apiAuthUa").value);
  43.     }
  44.     if ($("apiDatUa").value) {
  45.         commandLine.push("--api-dat-ua");
  46.         commandLine.push($("apiDatUa").value);
  47.     }
  48.     if ($("apiAuthXua").value) {
  49.         commandLine.push("--api-auth-xua");
  50.         commandLine.push($("apiAuthXua").value);
  51.     }
  52.     if ($("apiDatXua").value) {
  53.         commandLine.push("--api-dat-xua");
  54.         commandLine.push($("apiDatXua").value);
  55.     }
  56.     if ($("chunked").checked) { commandLine.push("--chunked") }
  57.     if ($("verbose").checked) { commandLine.push("--verbose") }
  58.     if (/\.(?:log|txt)$/i.test($("logRedirect").value)) {
  59.         commandLine = ["cmd.exe", "/C", "@"].concat(commandLine); // "@" は cmd.exe のお節介対策
  60.         if ($("logOverWrite").checked) { commandLine.push("1>") }
  61.         if ($("logAppend").checked) { commandLine.push("1>>") }
  62.         commandLine.push($("logRedirect").value);
  63.         commandLine.push("2>&1");
  64.     }
  65.     for (var i = 0, l = commandLine.length; i < l; i++) {
  66.         if (/[\s"]/.test(commandLine[i])) { commandLine[i] = '"' + commandLine[i].replace(/"/g, '\\"') + '"' }
  67.     }
  68.     var startup = SWbemServices.get("Win32_ProcessStartup").spawnInstance_();
  69.     var SW_HIDE = 0;
  70.     var SW_NORMAL = 1;
  71.     var SW_SHOWMINNOACTIVE = 7;
  72.     if ($("hide").checked) { startup.showWindow = SW_HIDE }
  73.     if ($("normal").checked) { startup.showWindow = SW_NORMAL }
  74.     if ($("showminnoactive").checked) { startup.showWindow = SW_SHOWMINNOACTIVE }
  75.     var Win32_Process = SWbemServices.get("Win32_Process");
  76.     var method = Win32_Process.methods_("create");
  77.     var inParameters = method.inParameters.spawnInstance_();
  78.     inParameters.commandLine = commandLine.join(" ");
  79.     inParameters.currentDirectory = /^file:\/\/(.+\\)/i.exec(document.URL)[1];
  80.     inParameters.processStartupInformation = startup;
  81.     var outParameters = Win32_Process.execMethod_(method.name, inParameters);
  82.     switch (outParameters.returnValue) {
  83.         case 0: // 正常終了
  84.             $("processId").defaultValue = $("processId").value = outParameters.processId;
  85.             $("stopButton").disabled = false;
  86.             document.title = "proxy2ch helper - " + inParameters.commandLine;
  87.             if ($("autoClose").checked) { window.close() }
  88.             break;
  89.         case 2:
  90.             alert("アクセスが拒否されました。");
  91.             break;
  92.         case 3:
  93.             alert("権限がありません。");
  94.             break;
  95.         case 9:
  96.             alert("ファイルが見つかりません。");
  97.             break;
  98.         case 21:
  99.             alert("パラメーターが不正です。");
  100.             break;
  101.         case 8:
  102.         default:
  103.             alert("エラーが発生しました。");
  104.     }
  105. }
  106. function stop() {
  107.     var process = getProcess();
  108.     if (process) { process.terminate() }
  109.     $("processId").defaultValue = $("processId").value = "";
  110.     $("stopButton").disabled = true;
  111.     document.title = "proxy2ch helper - 停止中";
  112. }
  113. function save() {
  114.     var stream = new ActiveXObject("ADODB\x2eStream"); // アンチウィルス対策で "." を "\x2e"
  115.     stream.open();
  116.     stream.charset = document.charset;
  117.     for (var c = document.firstChild; c; c = c.nextSibling) { stream.writeText(c.outerHTML) }
  118.     stream.flush();
  119.     var adSaveCreateOverWrite = 2;
  120.     stream.saveToFile(/^file:\/\/(.+)/i.exec(document.URL)[1], adSaveCreateOverWrite);
  121.     stream.close();
  122. }
  123. function getProcess() {
  124.     if ($("processId").value) {
  125.         var query = "SELECT * FROM Win32_Process WHERE Name = 'proxy2ch.exe' AND ( ProcessId = " + $("processId").value + " OR ParentProcessId = " + $("processId").value + " )";
  126.         var wbemFlagForwardOnly = 32;
  127.         var wbemFlagReturnImmediately = 16;
  128.         var flags = wbemFlagForwardOnly | wbemFlagReturnImmediately;
  129.         var enumerator = new Enumerator(SWbemServices.execQuery(query, null, flags));
  130.         if (!enumerator.atEnd()) { return enumerator.item() }
  131.     }
  132.     return null;
  133. }
  134. function getUserAgent() {
  135.     var ie = new ActiveXObject("InternetExplorer.Application");
  136.     ie.navigate("about:blank");
  137.     var identifier = setInterval(function() {
  138.         if (!ie.busy) {
  139.             clearInterval(identifier);
  140.             var userAgent = ie.document.parentWindow.navigator.userAgent;
  141.             ie.quit();
  142.             ie = null;
  143.             CollectGarbage();
  144.             /* navigator.userAgent は冗長なので削る */
  145.             var match = /(.+?\()(.+)(\).*)/.exec(userAgent);
  146.             if (match) {
  147.                 var tokens = match[2].split(/; /g);
  148.                 for (var i = 0; i < tokens.length; i++) {
  149.                     if (!/^(?:compatible$|MSIE |Windows |W(?:in|OW)64|Trident\/|Touch$|rv:)/.test(tokens[i])) { delete tokens[i] }
  150.                 }
  151.                 userAgent = match[1] + tokens.join("; ").replace(/(?:; ){2,}/g, "; ") + match[3];
  152.             }
  153.             $("agent").value = userAgent;
  154.         }
  155.     },
  156.     100);
  157. }
  158. function selectExecutablePath() {
  159.     var defaultValue = $("executablePath").defaultValue;
  160.     var value = $("executablePath").value;
  161.     $("executablePathDialog").outerHTML = $("executablePathDialog").outerHTML.replace(/type=button/, "type=hidden");
  162.     $("executablePath").outerHTML = $("executablePath").outerHTML.replace(/INPUT/, "INPUT type=file");
  163.     $("executablePath").click();
  164.     $("executablePath").outerHTML = $("executablePath").outerHTML.replace(/ type=file/, "");
  165.     $("executablePathDialog").outerHTML = $("executablePathDialog").outerHTML.replace(/type=hidden/, "type=button");
  166.     $("executablePath").defaultValue = defaultValue;
  167.     if (!$("executablePath").value) { $("executablePath").value = value }
  168. }
  169. function selectLogRedirect() {
  170.     alert("ログ ファイルを選択する前に、対象ファイルを作成してください。存在しないファイル名を指定するとエラーになります。\n既存ファイルを選択する場合は、改変されても問題ないファイルであることを確認してください。");
  171.     var defaultValue = $("logRedirect").defaultValue;
  172.     var value = $("logRedirect").value;
  173.     $("logRedirectDialog").outerHTML = $("logRedirectDialog").outerHTML.replace(/type=button/, "type=hidden");
  174.     $("logRedirect").outerHTML = $("logRedirect").outerHTML.replace(/INPUT/, "INPUT type=file");
  175.     $("logRedirect").click();
  176.     $("logRedirect").outerHTML = $("logRedirect").outerHTML.replace(/ type=file/, "");
  177.     $("logRedirectDialog").outerHTML = $("logRedirectDialog").outerHTML.replace(/type=hidden/, "type=button");
  178.     $("logRedirect").defaultValue = defaultValue;
  179.     if (!$("logRedirect").value) { $("logRedirect").value = value }
  180. }
  181. window.onload = function () {
  182.     if (getProcess()) { return }
  183.     $("processId").defaultValue = $("processId").value = "";
  184.     $("stopButton").disabled = true;
  185.     document.title = "proxy2ch helper - 停止中";
  186.     if ($("autoStart").checked) { start() }
  187. }
  188. window.onunload = function () {
  189.     SWbemServices = null;
  190.     SWbemLocator = null;
  191.     CollectGarbage();
  192.     save();
  193. }
  194. </SCRIPT>
  195. <SCRIPT id=runOnce type=text/javascript>
  196. alert("起動時に「発行元を確認できませんでした。このソフトウェアを実行しますか?」という警告がでる場合は、「このファイル開く前に常に警告する(W)」のチェックをはずして実行してみてください。");
  197. $("utf8n").outerHTML = "";
  198. $("runOnce").outerHTML = "";
  199. </SCRIPT>
  200. </HEAD>
  201. <BODY bgColor=threedface>
  202. <FORM action=javascript:void(start())>
  203. <FIELDSET title="-p <port>"><LEGEND><LABEL for=port>ポート番号</LABEL></LEGEND><INPUT id=port> (デフォルト: 9080)</FIELDSET>
  204. <FIELDSET title="-t <timeout>"><LEGEND><LABEL for=timeout>タイムアウト秒数</LABEL></LEGEND><INPUT id=timeout> (デフォルト: 30)</FIELDSET>
  205. <FIELDSET title="-a <user-agent>"><LEGEND><LABEL for=agent>User-Agent</LABEL></LEGEND><INPUT id=agent size=100><INPUT onclick=javascript:void(getUserAgent()) type=button value=MSIE></FIELDSET>
  206. <FIELDSET title=-g><LEGEND><LABEL for=global>この PC 以外からも接続可</LABEL></LEGEND><INPUT id=global type=checkbox></FIELDSET>
  207. <FIELDSET title="--proxy <server:port>"><LEGEND><LABEL for=proxyServer>プロキシー経由 (サーバー : ポート番号)</LABEL></LEGEND><INPUT id=proxyServer size=50> : <INPUT id=proxyPort></FIELDSET>
  208. <FIELDSET title="--api <AppKey:HmacKey>"><LEGEND><LABEL for=appKey>API キー (AppKey : HmacKey)</LABEL></LEGEND><INPUT id=appKey size=50> : <INPUT id=hmacKey size=50></FIELDSET>
  209. <FIELDSET title="--api-auth-ua <user-agent>"><LEGEND><LABEL for=apiAuthUa>API 認証時の User-Agent</LABEL></LEGEND><INPUT id=apiAuthUa size=100></FIELDSET>
  210. <FIELDSET title="--api-dat-ua <user-agent>"><LEGEND><LABEL for=apiDatUa>API で DAT 取得時の User-Agent</LABEL></LEGEND><INPUT id=apiDatUa size=100></FIELDSET>
  211. <FIELDSET title="--api-auth-xua <X-2ch-UA>"><LEGEND><LABEL for=apiAuthXua>API 認証時の X-2ch-UA</LABEL></LEGEND><INPUT id=apiAuthXua size=100></FIELDSET>
  212. <FIELDSET title="--api-dat-xua <X-2ch-UA>"><LEGEND><LABEL for=apiDatXua>API で DAT 取得時の X-2ch-UA</LABEL></LEGEND><INPUT id=apiDatXua size=100></FIELDSET>
  213. <FIELDSET title=--chunked><LEGEND><LABEL for=chunked>Transfer-Encoding: chunked 維持</LABEL></LEGEND><INPUT id=chunked type=checkbox></FIELDSET>
  214. <FIELDSET title=--verbose><LEGEND><LABEL for=verbose>詳細ログ表示</LABEL></LEGEND><INPUT id=verbose type=checkbox></FIELDSET>
  215. <P><LABEL for=executablePath>proxy2ch.exe の場所 (フルパス)</LABEL>:<BR><INPUT id=executablePath size=100><INPUT onclick=javascript:void(selectExecutablePath()) id=executablePathDialog type=button value=" 参照... "><INPUT id=processId type=hidden></P>
  216. <P><LABEL for=logRedirect>ログ表示をリダイレクトしてファイルに保存 (フルパス)</LABEL>:<BR><INPUT id=logRedirect size=100><INPUT onclick=javascript:void(selectLogRedirect()) id=logRedirectDialog type=button value=" 参照... "><INPUT id=logOverWrite CHECKED type=radio name=redirectType><LABEL for=logOverWrite>上書き</LABEL><INPUT id=logAppend type=radio name=redirectType><LABEL for=logAppend>追記</LABEL><BR>&nbsp;<SMALL>※ 安全のため、<STRONG>".log" と ".txt" 以外の拡張子がついたファイルを指定しても無効</STRONG>になります。</SMALL></P>
  217. <P><INPUT id=autoStart type=checkbox><LABEL for=autoStart>helper を開いた時に proxy2ch が停止中なら自動的に開始</LABEL><BR><INPUT id=autoClose type=checkbox><LABEL for=autoClose>proxy2ch を開始したら自動的に helper を閉じる</LABEL></P>
  218. <P><INPUT id=normal CHECKED type=radio name=showWindow><LABEL for=normal>通常表示で実行</LABEL> <INPUT id=showminnoactive type=radio name=showWindow><LABEL for=showminnoactive>最小化で実行</LABEL> <INPUT id=hide type=radio name=showWindow><LABEL for=hide>非表示で実行</LABEL></P>
  219. <P><INPUT type=submit value=開始> <INPUT onclick=javascript:void(stop()) disabled id=stopButton type=button value=停止> <INPUT type=reset value=変更を破棄></P></FORM></BODY></HTML>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement