Advertisement
Guest User

proxy2ch helper v11 (HTA)

a guest
Oct 8th, 2017
1,777
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 15.08 KB | None | 0 0
  1. <HTML XMLNS:HTA><HEAD><TITLE>proxy2ch helper - 初期化中</TITLE><HTA:APPLICATION applicationName="proxy2ch helper" innerBorder="no" navigable="yes" selection="no" singleInstance="yes" version="11"></HTA:APPLICATION>
  2. <META content="text/html; charset=UTF-8" http-equiv=Content-Type>
  3. <SCRIPT type=text/javascript defer>
  4. var SW_HIDE = 0;
  5. var SW_NORMAL = 1;
  6. var SW_SHOWMINNOACTIVE = 7;
  7.  
  8. var adSaveCreateOverWrite = 2;
  9.  
  10. var wbemFlagForwardOnly = 32;
  11. var wbemFlagReturnImmediately = 16;
  12.  
  13. var FileSystemObject = new ActiveXObject("Scripting.FileSystemObject");
  14.  
  15. var SWbemLocator = new ActiveXObject("WbemScripting.SWbemLocator");
  16. var wbemImpersonationLevelImpersonate = 3;
  17. SWbemLocator.security_.impersonationLevel = wbemImpersonationLevelImpersonate;
  18.  
  19. var SWbemServices = SWbemLocator.connectServer(".", "root/cimv2");
  20.  
  21. var Win32_Process = SWbemServices.get("Win32_Process");
  22. var Win32_ProcessStartup = SWbemServices.get("Win32_ProcessStartup");
  23.  
  24. var $ = document.getElementById;
  25.  
  26. function start() {
  27.     if (!$("executablePath").value) { throw new Error("proxy2ch.exe の場所を指定してください。") }
  28.     if (!FileSystemObject.fileExists($("executablePath").value)) { throw new Error('"' + $("executablePath").value + '" が見つかりません。') }
  29.     stop();
  30.     var options = [];
  31.     if ($("port").value) {
  32.         options.push("-p");
  33.         options.push($("port").value);
  34.     }
  35.     if ($("timeout").value) {
  36.         options.push("-t");
  37.         options.push($("timeout").value);
  38.     }
  39.     if ($("agent").value) {
  40.         options.push("-a");
  41.         options.push('"' + $("agent").value + '"');
  42.     }
  43.     if ($("global").checked) { options.push("-g") }
  44.     if ($("connect").checked) { options.push("-c") }
  45.     if ($("ipv4").checked) { options.push("-4") }
  46.     if ($("proxyServer").value && $("proxyPort").value) {
  47.         options.push("--proxy");
  48.         options.push($("proxyServer").value + ":" + $("proxyPort").value);
  49.     }
  50.     if ($("appKey").value && $("hmacKey").value) {
  51.         options.push("--api");
  52.         options.push($("appKey").value + ":" + $("hmacKey").value);
  53.     }
  54.     if ($("apiAuthUa").value) {
  55.         options.push("--api-auth-ua");
  56.         options.push('"' + $("apiAuthUa").value + '"');
  57.     }
  58.     if ($("apiDatUa").value) {
  59.         options.push("--api-dat-ua");
  60.         options.push('"' + $("apiDatUa").value + '"');
  61.     }
  62.     if ($("apiAuthXua").value) {
  63.         options.push("--api-auth-xua");
  64.         options.push('"' + $("apiAuthXua").value + '"');
  65.     }
  66.     if ($("apiDatXua").value) {
  67.         options.push("--api-dat-xua");
  68.         options.push('"' + $("apiDatXua").value + '"');
  69.     }
  70.     if ($("apiServer").value) {
  71.         options.push("--api-server");
  72.         options.push($("apiServer").value);
  73.     }
  74.     if ($("bbsmenu").value) {
  75.         options.push("--bbsmenu");
  76.         options.push('"' + $("bbsmenu").value + '"');
  77.     }
  78.     if ($("chunked").checked) { options.push("--chunked") }
  79.     if ($("verbose").checked) { options.push("--verbose") }
  80.     var commandLine = '"' + $("executablePath").value + '" ' + options.join(" ");
  81.     if ($("logRedirect").value) {
  82.         commandLine = "cmd.exe /C ( " + commandLine + " ) 1>";
  83.         if ($("append").checked) { commandLine += ">" }
  84.         commandLine += ' "' + $("logRedirect").value + '" 2>&1';
  85.         @if (false) // 条件付きコンパイルで無効化
  86.         if ($("overWrite").checked) {
  87.             // 以下で cmd.exe なしでも stderr をファイルに吐ける
  88.             // proxy2ch は stderr にのみログを吐くようなので
  89.             // PowerShell のある環境でログ上書きならこれで十分かも
  90.             commandLine = "powershell.exe -NoLogo -Command \"&{ Start-Process -FilePath '" + $("executablePath").value + "'";
  91.             if (options.length) { commandLine += " -ArgumentList '" + options.join("','").replace(/"/g, '\\"') + "'" }
  92.             commandLine += " -NoNewWindow -RedirectStandardError '" + $("logRedirect").value + "' }\"";
  93.         }
  94.         @end
  95.         (function(path) {
  96.             var folder = FileSystemObject.getParentFolderName(path);
  97.             if (!FileSystemObject.folderExists(folder)) {
  98.                 arguments.callee(folder);
  99.                 FileSystemObject.createFolder(folder);
  100.             }
  101.         })($("logRedirect").value);
  102.     }
  103.     var startup = Win32_ProcessStartup.spawnInstance_();
  104.     if ($("normal").checked) { startup.showWindow = SW_NORMAL }
  105.     else if ($("showminnoactive").checked) { startup.showWindow = SW_SHOWMINNOACTIVE }
  106.     else if ($("hide").checked) { startup.showWindow = SW_HIDE }
  107.     startup.title = "proxy2ch helper";
  108.     var method = Win32_Process.methods_("create");
  109.     var inParameters = method.inParameters.spawnInstance_();
  110.     inParameters.commandLine = commandLine;
  111.     inParameters.currentDirectory = FileSystemObject.getParentFolderName(location.pathname);
  112.     inParameters.processStartupInformation = startup;
  113.     var outParameters = Win32_Process.execMethod_(method.name, inParameters);
  114.     switch (outParameters.returnValue) {
  115.     case 0: // Successful Completion
  116.         $("startButton").disabled = true;
  117.         var query = "SELECT * FROM Win32_Process WHERE ExecutablePath = '" + $("executablePath").value.replace(/\\/g, "\\\\") + "' AND ( ProcessId = " + outParameters.processId + " OR ParentProcessId = " + outParameters.processId + " )";
  118.         var flags = wbemFlagForwardOnly | wbemFlagReturnImmediately;
  119.         (function() {
  120.             var enumerator = new Enumerator(SWbemServices.execQuery(query, null, flags));
  121.             if (enumerator.atEnd()) { setTimeout(arguments.callee, 10) }
  122.             else {
  123.                 var process = enumerator.item();
  124.                 $("processId").defaultValue = $("processId").value = process.processId;
  125.                 $("creationDate").defaultValue = $("creationDate").value = process.creationDate;
  126.                 document.title = "proxy2ch helper - " + process.commandLine;
  127.                 $("stopButton").disabled = false;
  128.                 if ($("autoClose").checked) { close() }
  129.                 else { watchProcess(process) }
  130.             }
  131.         })();
  132.         break;
  133.     case 2: // Access Denied
  134.         throw new Error("アクセスが拒否されました。");
  135.     case 3: // Insufficient Privilege
  136.         throw new Error("権限がありません。");
  137.     case 9: // Path Not Found
  138.         throw new Error("ファイルが見つかりません。");
  139.     case 21: // Invalid Parameter
  140.         throw new Error("パラメーターが不正です。");
  141.     case 8: // Unknown failure
  142.     default:
  143.         throw new Error("エラーが発生しました。");
  144.     }
  145. }
  146.  
  147. function stop() {
  148.     var process = getProcess();
  149.     if (process) {
  150.         process.terminate();
  151.         if (getProcess()) { throw new Error("プロセスを停止できませんでした。") }
  152.     }
  153.     $("stopButton").disabled = true;
  154.     document.title = "proxy2ch helper - 停止中";
  155.     $("processId").defaultValue = $("processId").value = "";
  156.     $("creationDate").defaultValue = $("creationDate").value = "";
  157.     $("startButton").disabled = false;
  158. }
  159.  
  160. function save() {
  161.     var elements = document.getElementsByTagName("INPUT");
  162.     for (var i = 0, l = elements.length; i < l; i++) {
  163.         switch (elements[i].type) {
  164.         case "hidden":
  165.             break;
  166.         case "checkbox":
  167.         case "radio":
  168.             elements[i].defaultChecked = elements[i].checked;
  169.             break;
  170.         default:
  171.             elements[i].defaultValue = elements[i].value;
  172.             elements[i].removeAttribute("lastValue"); // 属性扱いで書き出されてしまうので削除
  173.         }
  174.     }
  175.     var stream = new ActiveXObject("ADODB\x2eStream"); // アンチウィルス対策で ".""\x2e"
  176.     try {
  177.         stream.open();
  178.         stream.charset = document.charset;
  179.         stream.writeText(document.documentElement.outerHTML);
  180.         stream.flush();
  181.         stream.saveToFile(location.pathname, adSaveCreateOverWrite);
  182.         stream.close();
  183.     }
  184.     catch (e) {
  185.         if (stream.state) { stream.close() }
  186.         throw e;
  187.     }
  188. }
  189.  
  190. function getProcess() {
  191.     if ($("processId").value) {
  192.         var query = "SELECT * FROM Win32_Process WHERE ExecutablePath = '" + $("executablePath").value.replace(/\\/g, "\\\\") + "' AND ProcessId = " + $("processId").value + " AND CreationDate = '" + $("creationDate").value + "'";
  193.         var flags = wbemFlagForwardOnly | wbemFlagReturnImmediately;
  194.         var enumerator = new Enumerator(SWbemServices.execQuery(query, null, flags));
  195.         if (!enumerator.atEnd()) { return enumerator.item() }
  196.     }
  197. }
  198.  
  199. function watchProcess(process) {
  200.     if (process) {
  201.         var relPath = "Win32_Process.Handle='" + process.handle + "'";
  202.         var identifier = setInterval(function() {
  203.             try { SWbemServices.get(relPath) }
  204.             catch (e) {
  205.                 clearInterval(identifier);
  206.                 stop();
  207.             }
  208.         }, 1000);
  209.     }
  210. }
  211.  
  212. function testFileName(regexp) {
  213.     if (this.value && !regexp.test(this.value = FileSystemObject.getAbsolutePathName(this.value))) { this.value = this.lastValue != null ? this.lastValue : this.defaultValue }
  214.     else { this.lastValue = this.value }
  215. }
  216.  
  217. function selectFile() {
  218.     var element = document.createElement("INPUT");
  219.     element.type = "file";
  220.     element.style.display = "none";
  221.     this.parentNode.appendChild(element);
  222.     element.click();
  223.     element.parentNode.removeChild(element);
  224.     this.value = element.value;
  225.     this.onchange();
  226. }
  227.  
  228. function explorer(file) {
  229.     if (file) {
  230.         var folder = FileSystemObject.getParentFolderName(file);
  231.         if (FileSystemObject.fileExists(file)) { Win32_Process.create('explorer.exe /select,"' + file + '"', folder, null) }
  232.         else if (FileSystemObject.folderExists(folder)) { Win32_Process.create('explorer.exe "' + folder + '"', folder, null) }
  233.         else { throw new Error('"' + folder + '" が見つかりません。') }
  234.     }
  235. }
  236.  
  237. onload = function () {
  238.     var process = getProcess();
  239.     if (process) { watchProcess(process) }
  240.     else if ($("autoStart").checked) { start() }
  241.     else { stop() }
  242. }
  243.  
  244. onunload = function () {
  245.     FileSystemObject = null;
  246.     SWbemLocator = null;
  247.     SWbemServices = null;
  248.     Win32_Process = null;
  249.     Win32_ProcessStartup = null;
  250.     CollectGarbage();
  251.     save();
  252. }
  253. </SCRIPT>
  254. <SCRIPT id=runOnce type=text/javascript>
  255. setTimeout(function () {
  256.     $("runOnce").parentNode.removeChild($("runOnce"));
  257.     try { save() }
  258.     catch (e) { alert("起動時に「発行元を確認できませんでした。このソフトウェアを実行しますか?」という警告がでる場合は、「このファイル開く前に常に警告する(W)」のチェックをはずして実行してみてください。") }
  259.     alert("最初に、proxy2ch.exe の場所を指定してください。");
  260.     selectFile.call($("executablePath"));
  261.     $("executablePath").defaultValue = $("executablePath").value;
  262. }, 0);
  263. </SCRIPT>
  264. <STYLE type=text/css>
  265. BODY { background: threedface }
  266. INPUT.flat { border: threedshadow solid 1px }
  267. UL.note { font: smaller }
  268. </STYLE>
  269. </HEAD>
  270. <BODY>
  271. <FORM action=javascript:start()>
  272. <FIELDSET title="-p <port>"><LEGEND><LABEL for=port>ポート番号 (デフォルト: 9080)</LABEL></LEGEND><INPUT id=port class=flat></FIELDSET>
  273. <FIELDSET title="-t <timeout>"><LEGEND><LABEL for=timeout>タイムアウト秒数 (デフォルト: 30)</LABEL></LEGEND><INPUT id=timeout class=flat></FIELDSET>
  274. <FIELDSET title="-a <user-agent>"><LEGEND><LABEL for=agent>User-Agent</LABEL></LEGEND><INPUT id=agent class=flat size=100></FIELDSET>
  275. <FIELDSET title=-g><LEGEND><LABEL for=global>この PC 以外からも接続可 (デフォルト: この PC のみ)</LABEL></LEGEND><INPUT id=global type=checkbox></FIELDSET>
  276. <FIELDSET title=-c><LEGEND><LABEL for=connect>HTTP CONNECT を受け付ける</LABEL></LEGEND><INPUT id=connect type=checkbox></FIELDSET>
  277. <FIELDSET title=-4><LEGEND><LABEL for=ipv4>強制的に IPv4 で接続</LABEL></LEGEND><INPUT id=ipv4 type=checkbox></FIELDSET>
  278. <FIELDSET title="--proxy <server:port>"><LEGEND><LABEL for=proxyServer>プロキシー経由 (サーバー : ポート番号)</LABEL></LEGEND><INPUT id=proxyServer class=flat size=50> : <INPUT id=proxyPort class=flat></FIELDSET>
  279. <FIELDSET title="--api <AppKey:HmacKey>"><LEGEND><LABEL for=appKey>API キー (AppKey : HmacKey)</LABEL></LEGEND><INPUT id=appKey class=flat size=50> : <INPUT id=hmacKey class=flat size=50></FIELDSET>
  280. <FIELDSET title="--api-auth-ua <user-agent>"><LEGEND><LABEL for=apiAuthUa>API 認証時の User-Agent</LABEL></LEGEND><INPUT id=apiAuthUa class=flat size=100></FIELDSET>
  281. <FIELDSET title="--api-dat-ua <user-agent>"><LEGEND><LABEL for=apiDatUa>API で DAT 取得時の User-Agent</LABEL></LEGEND><INPUT id=apiDatUa class=flat size=100></FIELDSET>
  282. <FIELDSET title="--api-auth-xua <X-2ch-UA>"><LEGEND><LABEL for=apiAuthXua>API 認証時の X-2ch-UA</LABEL></LEGEND><INPUT id=apiAuthXua class=flat size=100></FIELDSET>
  283. <FIELDSET title="--api-dat-xua <X-2ch-UA>"><LEGEND><LABEL for=apiDatXua>API で DAT 取得時の X-2ch-UA</LABEL></LEGEND><INPUT id=apiDatXua class=flat size=100></FIELDSET>
  284. <FIELDSET title="--api-server <server>"><LEGEND><LABEL for=apiServer>API のゲートウェイ</LABEL></LEGEND><INPUT id=apiServer class=flat size=50></FIELDSET>
  285. <FIELDSET title="--bbsmenu <URL>"><LEGEND><LABEL for=bbsmenu>HTML のリンク内の "5ch.net" を "2ch.net" に置き換えて返す URL</LABEL></LEGEND><INPUT id=bbsmenu class=flat size=100></FIELDSET>
  286. <FIELDSET title=--chunked><LEGEND><LABEL for=chunked>Transfer-Encoding: chunked を維持</LABEL></LEGEND><INPUT id=chunked type=checkbox></FIELDSET>
  287. <FIELDSET title=--verbose><LEGEND><LABEL for=verbose>詳細ログ出力</LABEL></LEGEND><INPUT id=verbose type=checkbox></FIELDSET>
  288. <P><LABEL for=executablePath>proxy2ch.exe の場所 (フルパス)</LABEL>:<BR><INPUT onchange=javascript:testFileName.call(this,/\\proxy2ch[^\\]*\.exe$/i) id=executablePath class=flat size=100><INPUT onclick='javascript:selectFile.call($("executablePath"))' type=button value=参照...><INPUT id=processId type=hidden><INPUT id=creationDate type=hidden></P>
  289. <P><LABEL for=logRedirect>ログ出力をリダイレクトしてファイルに保存 (フルパス)</LABEL>:<BR><INPUT onchange=javascript:testFileName.call(this,/\.(?:log|txt)$/i) id=logRedirect class=flat size=100><INPUT onclick='javascript:selectFile.call($("logRedirect"))' type=button value=参照...><INPUT onclick='javascript:explorer($("logRedirect").value)' type=button value=ファイルの場所を開く> <INPUT id=overWrite CHECKED type=radio name=redirectType><LABEL for=overWrite>上書き</LABEL> <INPUT id=append type=radio name=redirectType><LABEL for=append>追記</LABEL></P>
  290. <UL class=note>
  291. <LI><INPUT onclick='javascript:selectFile.call($("logRedirect"))' type=button value=参照...> ボタンでログ ファイルを指定する場合は、対象ファイルを作成してから選択してください。存在しないファイルは指定できません。
  292. <LI>既存ファイルを指定する場合は、改変されても問題のないファイルであることを確認してください。
  293. <LI>安全のため、".log" と ".txt" 以外の拡張子を持つファイルが指定された場合は無視します。</LI></UL>
  294. <P><INPUT id=autoStart type=checkbox><LABEL for=autoStart>proxy2ch helper を開いた時に proxy2ch が停止中なら自動的に開始</LABEL><BR><INPUT id=autoClose type=checkbox><LABEL for=autoClose>proxy2ch を開始したら自動的に proxy2ch helper を閉じる</LABEL></P>
  295. <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>
  296. <P><INPUT id=startButton type=submit value=開始> <INPUT onclick=javascript:stop() disabled id=stopButton type=button value=停止> <INPUT onclick=javascript:save() type=button value=保存> <INPUT type=reset value=復元></P></FORM></BODY></HTML>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement