Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <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>
- <META content="text/html; charset=UTF-8" http-equiv=Content-Type>
- <SCRIPT type=text/javascript defer>
- var SW_HIDE = 0;
- var SW_NORMAL = 1;
- var SW_SHOWMINNOACTIVE = 7;
- var adSaveCreateOverWrite = 2;
- var wbemFlagForwardOnly = 32;
- var wbemFlagReturnImmediately = 16;
- var FileSystemObject = new ActiveXObject("Scripting.FileSystemObject");
- var SWbemLocator = new ActiveXObject("WbemScripting.SWbemLocator");
- var wbemImpersonationLevelImpersonate = 3;
- SWbemLocator.security_.impersonationLevel = wbemImpersonationLevelImpersonate;
- var SWbemServices = SWbemLocator.connectServer(".", "root/cimv2");
- var Win32_Process = SWbemServices.get("Win32_Process");
- var Win32_ProcessStartup = SWbemServices.get("Win32_ProcessStartup");
- var $ = document.getElementById;
- function start() {
- if (!$("executablePath").value) { throw new Error("proxy2ch.exe の場所を指定してください。") }
- if (!FileSystemObject.fileExists($("executablePath").value)) { throw new Error('"' + $("executablePath").value + '" が見つかりません。') }
- stop();
- var options = [];
- if ($("port").value) {
- options.push("-p");
- options.push($("port").value);
- }
- if ($("timeout").value) {
- options.push("-t");
- options.push($("timeout").value);
- }
- if ($("agent").value) {
- options.push("-a");
- options.push('"' + $("agent").value + '"');
- }
- if ($("global").checked) { options.push("-g") }
- if ($("connect").checked) { options.push("-c") }
- if ($("ipv4").checked) { options.push("-4") }
- if ($("proxyServer").value && $("proxyPort").value) {
- options.push("--proxy");
- options.push($("proxyServer").value + ":" + $("proxyPort").value);
- }
- if ($("appKey").value && $("hmacKey").value) {
- options.push("--api");
- options.push($("appKey").value + ":" + $("hmacKey").value);
- }
- if ($("apiAuthUa").value) {
- options.push("--api-auth-ua");
- options.push('"' + $("apiAuthUa").value + '"');
- }
- if ($("apiDatUa").value) {
- options.push("--api-dat-ua");
- options.push('"' + $("apiDatUa").value + '"');
- }
- if ($("apiAuthXua").value) {
- options.push("--api-auth-xua");
- options.push('"' + $("apiAuthXua").value + '"');
- }
- if ($("apiDatXua").value) {
- options.push("--api-dat-xua");
- options.push('"' + $("apiDatXua").value + '"');
- }
- if ($("apiServer").value) {
- options.push("--api-server");
- options.push($("apiServer").value);
- }
- if ($("bbsmenu").value) {
- options.push("--bbsmenu");
- options.push('"' + $("bbsmenu").value + '"');
- }
- if ($("chunked").checked) { options.push("--chunked") }
- if ($("verbose").checked) { options.push("--verbose") }
- var commandLine = '"' + $("executablePath").value + '" ' + options.join(" ");
- if ($("logRedirect").value) {
- commandLine = "cmd.exe /C ( " + commandLine + " ) 1>";
- if ($("append").checked) { commandLine += ">" }
- commandLine += ' "' + $("logRedirect").value + '" 2>&1';
- @if (false) // 条件付きコンパイルで無効化
- if ($("overWrite").checked) {
- // 以下で cmd.exe なしでも stderr をファイルに吐ける
- // proxy2ch は stderr にのみログを吐くようなので
- // PowerShell のある環境でログ上書きならこれで十分かも
- commandLine = "powershell.exe -NoLogo -Command \"&{ Start-Process -FilePath '" + $("executablePath").value + "'";
- if (options.length) { commandLine += " -ArgumentList '" + options.join("','").replace(/"/g, '\\"') + "'" }
- commandLine += " -NoNewWindow -RedirectStandardError '" + $("logRedirect").value + "' }\"";
- }
- @end
- (function(path) {
- var folder = FileSystemObject.getParentFolderName(path);
- if (!FileSystemObject.folderExists(folder)) {
- arguments.callee(folder);
- FileSystemObject.createFolder(folder);
- }
- })($("logRedirect").value);
- }
- var startup = Win32_ProcessStartup.spawnInstance_();
- if ($("normal").checked) { startup.showWindow = SW_NORMAL }
- else if ($("showminnoactive").checked) { startup.showWindow = SW_SHOWMINNOACTIVE }
- else if ($("hide").checked) { startup.showWindow = SW_HIDE }
- startup.title = "proxy2ch helper";
- var method = Win32_Process.methods_("create");
- var inParameters = method.inParameters.spawnInstance_();
- inParameters.commandLine = commandLine;
- inParameters.currentDirectory = FileSystemObject.getParentFolderName(location.pathname);
- inParameters.processStartupInformation = startup;
- var outParameters = Win32_Process.execMethod_(method.name, inParameters);
- switch (outParameters.returnValue) {
- case 0: // Successful Completion
- $("startButton").disabled = true;
- var query = "SELECT * FROM Win32_Process WHERE ExecutablePath = '" + $("executablePath").value.replace(/\\/g, "\\\\") + "' AND ( ProcessId = " + outParameters.processId + " OR ParentProcessId = " + outParameters.processId + " )";
- var flags = wbemFlagForwardOnly | wbemFlagReturnImmediately;
- (function() {
- var enumerator = new Enumerator(SWbemServices.execQuery(query, null, flags));
- if (enumerator.atEnd()) { setTimeout(arguments.callee, 10) }
- else {
- var process = enumerator.item();
- $("processId").defaultValue = $("processId").value = process.processId;
- $("creationDate").defaultValue = $("creationDate").value = process.creationDate;
- document.title = "proxy2ch helper - " + process.commandLine;
- $("stopButton").disabled = false;
- if ($("autoClose").checked) { close() }
- else { watchProcess(process) }
- }
- })();
- break;
- case 2: // Access Denied
- throw new Error("アクセスが拒否されました。");
- case 3: // Insufficient Privilege
- throw new Error("権限がありません。");
- case 9: // Path Not Found
- throw new Error("ファイルが見つかりません。");
- case 21: // Invalid Parameter
- throw new Error("パラメーターが不正です。");
- case 8: // Unknown failure
- default:
- throw new Error("エラーが発生しました。");
- }
- }
- function stop() {
- var process = getProcess();
- if (process) {
- process.terminate();
- if (getProcess()) { throw new Error("プロセスを停止できませんでした。") }
- }
- $("stopButton").disabled = true;
- document.title = "proxy2ch helper - 停止中";
- $("processId").defaultValue = $("processId").value = "";
- $("creationDate").defaultValue = $("creationDate").value = "";
- $("startButton").disabled = false;
- }
- function save() {
- var elements = document.getElementsByTagName("INPUT");
- for (var i = 0, l = elements.length; i < l; i++) {
- switch (elements[i].type) {
- case "hidden":
- break;
- case "checkbox":
- case "radio":
- elements[i].defaultChecked = elements[i].checked;
- break;
- default:
- elements[i].defaultValue = elements[i].value;
- elements[i].removeAttribute("lastValue"); // 属性扱いで書き出されてしまうので削除
- }
- }
- var stream = new ActiveXObject("ADODB\x2eStream"); // アンチウィルス対策で "." を "\x2e"
- try {
- stream.open();
- stream.charset = document.charset;
- stream.writeText(document.documentElement.outerHTML);
- stream.flush();
- stream.saveToFile(location.pathname, adSaveCreateOverWrite);
- stream.close();
- }
- catch (e) {
- if (stream.state) { stream.close() }
- throw e;
- }
- }
- function getProcess() {
- if ($("processId").value) {
- var query = "SELECT * FROM Win32_Process WHERE ExecutablePath = '" + $("executablePath").value.replace(/\\/g, "\\\\") + "' AND ProcessId = " + $("processId").value + " AND CreationDate = '" + $("creationDate").value + "'";
- var flags = wbemFlagForwardOnly | wbemFlagReturnImmediately;
- var enumerator = new Enumerator(SWbemServices.execQuery(query, null, flags));
- if (!enumerator.atEnd()) { return enumerator.item() }
- }
- }
- function watchProcess(process) {
- if (process) {
- var relPath = "Win32_Process.Handle='" + process.handle + "'";
- var identifier = setInterval(function() {
- try { SWbemServices.get(relPath) }
- catch (e) {
- clearInterval(identifier);
- stop();
- }
- }, 1000);
- }
- }
- function testFileName(regexp) {
- if (this.value && !regexp.test(this.value = FileSystemObject.getAbsolutePathName(this.value))) { this.value = this.lastValue != null ? this.lastValue : this.defaultValue }
- else { this.lastValue = this.value }
- }
- function selectFile() {
- var element = document.createElement("INPUT");
- element.type = "file";
- element.style.display = "none";
- this.parentNode.appendChild(element);
- element.click();
- element.parentNode.removeChild(element);
- this.value = element.value;
- this.onchange();
- }
- function explorer(file) {
- if (file) {
- var folder = FileSystemObject.getParentFolderName(file);
- if (FileSystemObject.fileExists(file)) { Win32_Process.create('explorer.exe /select,"' + file + '"', folder, null) }
- else if (FileSystemObject.folderExists(folder)) { Win32_Process.create('explorer.exe "' + folder + '"', folder, null) }
- else { throw new Error('"' + folder + '" が見つかりません。') }
- }
- }
- onload = function () {
- var process = getProcess();
- if (process) { watchProcess(process) }
- else if ($("autoStart").checked) { start() }
- else { stop() }
- }
- onunload = function () {
- FileSystemObject = null;
- SWbemLocator = null;
- SWbemServices = null;
- Win32_Process = null;
- Win32_ProcessStartup = null;
- CollectGarbage();
- save();
- }
- </SCRIPT>
- <SCRIPT id=runOnce type=text/javascript>
- setTimeout(function () {
- $("runOnce").parentNode.removeChild($("runOnce"));
- try { save() }
- catch (e) { alert("起動時に「発行元を確認できませんでした。このソフトウェアを実行しますか?」という警告がでる場合は、「このファイル開く前に常に警告する(W)」のチェックをはずして実行してみてください。") }
- alert("最初に、proxy2ch.exe の場所を指定してください。");
- selectFile.call($("executablePath"));
- $("executablePath").defaultValue = $("executablePath").value;
- }, 0);
- </SCRIPT>
- <STYLE type=text/css>
- BODY { background: threedface }
- INPUT.flat { border: threedshadow solid 1px }
- UL.note { font: smaller }
- </STYLE>
- </HEAD>
- <BODY>
- <FORM action=javascript:start()>
- <FIELDSET title="-p <port>"><LEGEND><LABEL for=port>ポート番号 (デフォルト: 9080)</LABEL></LEGEND><INPUT id=port class=flat></FIELDSET>
- <FIELDSET title="-t <timeout>"><LEGEND><LABEL for=timeout>タイムアウト秒数 (デフォルト: 30)</LABEL></LEGEND><INPUT id=timeout class=flat></FIELDSET>
- <FIELDSET title="-a <user-agent>"><LEGEND><LABEL for=agent>User-Agent</LABEL></LEGEND><INPUT id=agent class=flat size=100></FIELDSET>
- <FIELDSET title=-g><LEGEND><LABEL for=global>この PC 以外からも接続可 (デフォルト: この PC のみ)</LABEL></LEGEND><INPUT id=global type=checkbox></FIELDSET>
- <FIELDSET title=-c><LEGEND><LABEL for=connect>HTTP CONNECT を受け付ける</LABEL></LEGEND><INPUT id=connect type=checkbox></FIELDSET>
- <FIELDSET title=-4><LEGEND><LABEL for=ipv4>強制的に IPv4 で接続</LABEL></LEGEND><INPUT id=ipv4 type=checkbox></FIELDSET>
- <FIELDSET title="--proxy <server:port>"><LEGEND><LABEL for=proxyServer>プロキシー経由 (サーバー : ポート番号)</LABEL></LEGEND><INPUT id=proxyServer class=flat size=50> : <INPUT id=proxyPort class=flat></FIELDSET>
- <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>
- <FIELDSET title="--api-auth-ua <user-agent>"><LEGEND><LABEL for=apiAuthUa>API 認証時の User-Agent</LABEL></LEGEND><INPUT id=apiAuthUa class=flat size=100></FIELDSET>
- <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>
- <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>
- <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>
- <FIELDSET title="--api-server <server>"><LEGEND><LABEL for=apiServer>API のゲートウェイ</LABEL></LEGEND><INPUT id=apiServer class=flat size=50></FIELDSET>
- <FIELDSET title="--bbsmenu <URL>"><LEGEND><LABEL for=bbsmenu>HTML のリンク内の "5ch.net" を "2ch.net" に置き換えて返す URL</LABEL></LEGEND><INPUT id=bbsmenu class=flat size=100></FIELDSET>
- <FIELDSET title=--chunked><LEGEND><LABEL for=chunked>Transfer-Encoding: chunked を維持</LABEL></LEGEND><INPUT id=chunked type=checkbox></FIELDSET>
- <FIELDSET title=--verbose><LEGEND><LABEL for=verbose>詳細ログ出力</LABEL></LEGEND><INPUT id=verbose type=checkbox></FIELDSET>
- <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>
- <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>
- <UL class=note>
- <LI><INPUT onclick='javascript:selectFile.call($("logRedirect"))' type=button value=参照...> ボタンでログ ファイルを指定する場合は、対象ファイルを作成してから選択してください。存在しないファイルは指定できません。
- <LI>既存ファイルを指定する場合は、改変されても問題のないファイルであることを確認してください。
- <LI>安全のため、".log" と ".txt" 以外の拡張子を持つファイルが指定された場合は無視します。</LI></UL>
- <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>
- <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>
- <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