Skip to content

Commit

Permalink
added validation for new connection method
Browse files Browse the repository at this point in the history
  • Loading branch information
flouc001 committed Jan 5, 2017
1 parent f1f656b commit aeaeb45
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
4 changes: 2 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@
</select>
<span id=cn_ssh_tnl_pass_wr><input id=cn_ssh_tnl_pass type=password></span>
<span id=cn_ssh_tnl_key_wr hidden><input id=cn_ssh_tnl_key name=ssh_tnl_key><button id=cn_ssh_tnl_key_dots>Browse...</button></span>
<p><label for=cn_ssh_tnl_port><u>R</u>IDE Port:</label>
<input id=cn_ssh_tnl_port name=ride_port size=4 placeholder=4502>
<p><label for=cn_ssh_ride_port><u>R</u>IDE Port:</label>
<input id=cn_ssh_ride_port name=ride_port size=4 placeholder=4502>
</div>
<div id=cn_tcp_dtl>
<p><label for=cn_tcp_host><u>H</u>ost</label> and <label for=cn_tcp_port><u>p</u>ort:</label>
Expand Down
8 changes: 5 additions & 3 deletions src/cn.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,13 @@ const rq=node_require,fs=rq('fs'),cp=rq('child_process'),net=rq('net'),os=rq('os
q.exe.readOnly=!!q.exes.value
}
,validate=x=>{
const t=x.type,h=x.host,p=x.port
const t=x.type,h=x.host,p=x.port,tn=x.ssh_tnl
if((t==='connect'||t==='start'&&x.ssh)&&!h)
{$.err('"host" is required',_=>{(t==='connect'?q.tcp_host:q.ssh_host).select()});return}
{$.err('"host" is required',_=>{(t==='connect'?x.ssh_tnl?q.ssh_tnl_host:q.tcp_host:q.ssh_host).select()});return}
if((t==='connect'||t==='start'&&x.ssh||t==='listen')&&p&&(!/^\d*$/.test(p)||+p<1||+p>0xffff))
{$.err('Invalid port',_=>{(t==='connect'?q.tcp_port:t==='start'?q.ssh_port:q.listen_port).select()});return}
{$.err('Invalid port',_=>{(t==='connect'?x.ssh_tnl?q.ssh_tnl_port:q.tcp_port:t==='start'?q.ssh_port:q.listen_port).select()});return}
if((t==='connect'&&x.ssh_tnl)&&x.ride_port&&(!/^\d*$/.test(x.ride_port)||+x.ride_port<1||+x.ride_port>0xffff))
{$.err('Invalid RIDE port',_=>{q.ssh_ride_port.select()});return}
if(t==='start'){
const a=(x.env||'').split('\n')
for(let i=0;i<a.length;i++)if(!KV.test(a[i])&&!WS.test(a[i]))
Expand Down

0 comments on commit aeaeb45

Please sign in to comment.