<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[Серый форум &mdash; WebSocket как инструмент удаленного администрирования]]></title>
		<link>https://forum.script-coding.com/viewtopic.php?id=9025</link>
		<atom:link href="https://forum.script-coding.com/extern.php?action=feed&amp;tid=9025&amp;type=rss" rel="self" type="application/rss+xml" />
		<description><![CDATA[Недавние сообщения в теме «WebSocket как инструмент удаленного администрирования».]]></description>
		<lastBuildDate>Sat, 28 Dec 2013 07:01:36 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: WebSocket как инструмент удаленного администрирования]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=78580#p78580</link>
			<description><![CDATA[<p>Создал <a href="https://github.com/dab00/ws-console">репозиторий на GitHub</a>, сделал <a href="https://github.com/joewalnes/websocketd/pull/24">pull request</a>, автор websocketd заценил и добавил ссылку на созданный проект в раздел <a href="https://github.com/joewalnes/websocketd#example-project">Example Project</a>. Happy End <img src="//forum.script-coding.com/img/smilies/smile.png" width="15" height="15" />.</p>]]></description>
			<author><![CDATA[null@example.com (dab00)]]></author>
			<pubDate>Sat, 28 Dec 2013 07:01:36 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=78580#p78580</guid>
		</item>
		<item>
			<title><![CDATA[WebSocket как инструмент удаленного администрирования]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=78147#p78147</link>
			<description><![CDATA[<p>Здравствуйте, уважаемые коллеги.<br />Хочу поделиться с вами одной интересной находкой - <a href="https://github.com/joewalnes/websocketd">websocketd</a>, а также <a href="http://www.daspot.ru/2013/12/websocket.html">своей реализацией</a> инструмента удаленного выполнения кода, основанной на websocketd.</p><p><a href="http://dab00.gweb.io/WS-console.html">Клиентская часть</a>:<br /></p><div class="codebox"><pre><code>
&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;head&gt;
  &lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=utf-8&quot;&gt;
  &lt;title&gt;WS-console&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;  
  IP: &lt;input id=&quot;ip&quot; type=&quot;text&quot; value=&quot;127.0.0.1&quot;&gt;
  Port: &lt;input id=&quot;port&quot; type=&quot;text&quot; value=&quot;8081&quot;&gt;&lt;br/&gt;  
  &lt;textarea id=&quot;txt&quot; cols=&quot;60&quot; rows=&quot;10&quot;&gt;&lt;/textarea&gt;&lt;br/&gt;
  &lt;input id=&quot;btn&quot; type=&quot;button&quot; value=&quot;R U N&quot;/&gt;
  &lt;input id=&quot;vbs&quot; type=&quot;radio&quot; name=&quot;code&quot; checked&gt; VBScript
  &lt;input id=&quot;js&quot; type=&quot;radio&quot; name=&quot;code&quot;&gt; JScript  
  &lt;pre id=&quot;log&quot;&gt;&lt;/pre&gt;
  &lt;script&gt;
    document.getElementById(&#039;txt&#039;).focus();
    btn.addEventListener(&#039;click&#039;, function(e) {
      var ip = document.getElementById(&#039;ip&#039;).value,
          port = document.getElementById(&#039;port&#039;).value,
          ws = new WebSocket(&#039;ws://&#039; + ip + &#039;:&#039; + port);
      ws.onopen = function() {
        log(&#039;CONNECTED&#039;);
        var d = document.all ? &#039;\r\n&#039; : &#039;\n&#039;;            
        var arr = txt.value.split(d);
        var js = document.getElementById(&#039;js&#039;), msg;
        if (js.checked) {
          for (var i=0; i&lt;arr.length; i++) {
            arr[i] = arr[i].replace(/(\/\*([\s\S]*?)\*\/)|(\/\/(.*)$)/g, &#039;&#039;);
          }
          msg = arr.join(&#039; &#039;);
        } else {
          var und = false;
          for (var i=0; i&lt;arr.length; i++) {
            if (arr[i].search(/ _$/) != -1) {
              arr[i] = arr[i].replace(/ _$/, &#039;&#039;);
              arr[i] += arr[i+1];
              arr.splice(i+1, 1);
              i--;
              continue;      
            }
            arr[i] = arr[i].replace(/^\s+|^\s*(?:&#039;|\brem\b).*$|(?:&#039;|\brem\b)[^(?:\&quot;|_$)].*$|\s+$/gi, &#039;&#039;);          
          }
          msg = arr.join(&#039; : &#039;);
        }        
        ws.send(msg);      
      };    
      ws.onmessage = function(e) {
        log(&#039;MESSAGE:   &#039; + e.data);
      };
      ws.onclose = function(e) {
        log(&#039;DISCONNECTED&#039;);
        log(&#039;Clean = &#039; + e.wasClean + &#039;, Code = &#039; + e.code + &#039;, Reason = &#039; + (e.reason || &#039;none&#039;));
      };
    });  
    function log(msg) {
      document.getElementById(&#039;log&#039;).innerText += msg + &#039;\n&#039;;
    }
  &lt;/script&gt;
&lt;/body&gt;
&lt;/html&gt;
</code></pre></div><p>Серверная часть.</p><p>На VBScript:<br />- console.vbs:<br /></p><div class="codebox"><pre><code>
Call Execute(WScript.StdIn.ReadLine())
</code></pre></div><p>- console.cmd:<br /></p><div class="codebox"><pre><code>
@echo off
cscript /nologo console.vbs
</code></pre></div><p>На JScript:<br />- console.js:<br /></p><div class="codebox"><pre><code>
eval(WScript.StdIn.ReadLine());
</code></pre></div><p>- console.cmd:<br /></p><div class="codebox"><pre><code>
@echo off
cscript /nologo console.js
</code></pre></div><p>Разумеется рядом со скриптом и командным файлом должен находиться websocketd.exe. <br />Кроме того демон должен быть запущен:<br /><em>websocketd --port 8081 console.cmd</em></p><p>Тестировал локально, думаю с удаленным выполнением проблем быть не должно, если открыть соответствующий порт. <br />Если кто найдет время и возможность попробовать, пожалуйста, оставьте ваши замечания, предложения.</p>]]></description>
			<author><![CDATA[null@example.com (dab00)]]></author>
			<pubDate>Sun, 15 Dec 2013 13:29:10 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=78147#p78147</guid>
		</item>
	</channel>
</rss>
