te')); return $arr; } /* 遍历用户所有主题 * @param $uid 用户ID * @param int $page 页数 * @param int $pagesize 每页记录条数 * @param bool $desc 排序方式 TRUE降序 FALSE升序 * @param string $key 返回的数组用那一列的值作为 key * @param array $col 查询哪些列 */ function thread_tid_find_by_uid($uid, $page = 1, $pagesize = 1000, $desc = TRUE, $key = 'tid', $col = array()) { if (empty($uid)) return array(); $orderby = TRUE == $desc ? -1 : 1; $arr = thread_tid__find($cond = array('uid' => $uid), array('tid' => $orderby), $page, $pagesize, $key, $col); return $arr; } // 遍历栏目下tid 支持数组 $fid = array(1,2,3) function thread_tid_find_by_fid($fid, $page = 1, $pagesize = 1000, $desc = TRUE) { if (empty($fid)) return array(); $orderby = TRUE == $desc ? -1 : 1; $arr = thread_tid__find($cond = array('fid' => $fid), array('tid' => $orderby), $page, $pagesize, 'tid', array('tid', 'verify_date')); return $arr; } function thread_tid_delete($tid) { if (empty($tid)) return FALSE; $r = thread_tid__delete(array('tid' => $tid)); return $r; } function thread_tid_count() { $n = thread_tid__count(); return $n; } // 统计用户主题数 大数量下严谨使用非主键统计 function thread_uid_count($uid) { $n = thread_tid__count(array('uid' => $uid)); return $n; } // 统计栏目主题数 大数量下严谨使用非主键统计 function thread_fid_count($fid) { $n = thread_tid__count(array('fid' => $fid)); return $n; } ?>javascript - Open terminal from html using href ssh: url with command line options - Stack Overflow
最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Open terminal from html using href ssh: url with command line options - Stack Overflow

programmeradmin3浏览0评论

I'd like to create a url link that launches terminal (from webpage or browser such as chrome or safari) and ssh's to a box and launches remote mands (for example ls), in terminal it would look like: ssh [email protected] 'ls'

I've tried:

<a href='ssh://[email protected] "ls"'>SSH with ls</a>

but this does nothing. and this works (without any mands):

<a href='ssh://[email protected]'>SSH</a>

Is this possible in HTML? I'll also accept answers that use Javascript.

I'd like to create a url link that launches terminal (from webpage or browser such as chrome or safari) and ssh's to a box and launches remote mands (for example ls), in terminal it would look like: ssh [email protected] 'ls'

I've tried:

<a href='ssh://[email protected] "ls"'>SSH with ls</a>

but this does nothing. and this works (without any mands):

<a href='ssh://[email protected]'>SSH</a>

Is this possible in HTML? I'll also accept answers that use Javascript.

Share Improve this question asked Feb 28, 2018 at 18:47 hagopehagope 5,5317 gold badges39 silver badges52 bronze badges 7
  • You would need to have the user set what program the browser instructs to handle SSH links – Luca Kiebel Commented Feb 28, 2018 at 19:00
  • thats fine, assuming they are using Terminal.app on Mac os – hagope Commented Feb 28, 2018 at 19:16
  • This isn't really a programming question. If you search for "ssh url handler" and maybe add the target browser & platform, you'll find various pages discussing how to set this up. – Kenster Commented Feb 28, 2018 at 19:25
  • @Kenster no luck with that search – hagope Commented Feb 28, 2018 at 20:42
  • This is not possible using Terminal.app. It is still possible with iTerm if that works for you and not without a specific profile in iTerm. So by default you can't make it work across system without some configuration – Tarun Lalwani Commented Mar 14, 2018 at 9:27
 |  Show 2 more ments

3 Answers 3

Reset to default 8 +50

I have looked at multiple sources and tried different binations and e to below understanding

  • There was no standard defined for the SSH URI to specify mands. So it is up to the process taking the input to understand how to use it
  • By default Terminal.app handles the SSH url and there is no documentation that it supports mand
  • The app receiving the URL, doesn't get the URL as an argument, it needs to fetch it using some event. You can refer here for the same
  • You can configure iTerm to handle SSH handler and access the URL that was passed as describe here
  • You can create a custom app that handles the URL and does support mands and other things you want

Doing it using iTerm

You create a new profile and enable SSH URL handler in the same

So used below sample page

<html>
<body>
<a href="ssh://vagrant@vm/ls -alh">ls -alh</a>
</body>
</html>

And below mand in my iTerm SSH profile

/usr/bin/ssh $$USER$$@$$HOST$$  $(echo $$PATH$$ | tr -d '/')

And the result was

Of course you want to run a python script or something and pass it these values and let it do such things for additional functionalities. But this shows how you could achieve such a setup

Key References

url scheme for ssh: Calling mand on remote host

https://unix.stackexchange./questions/75668/why-doesnt-the-ssh-mand-follow-rfc-on-uri

https://groups.google./forum/#!topic/iterm2-discuss/r0Rk_WZaGWk

http://www.rubicode./Software/Bundles.html#RCDefaultApp

https://superuser./questions/379342/setting-iterm2-as-the-default-terminal-osx-lion

https://apple.stackexchange./questions/46666/how-to-access-a-clicked-url-in-a-url-handler-application-created-in-automator

https://support.shotgunsoftware./hc/en-us/munity/posts/209485898-Launching-External-Applications-using-Custom-Protocols-under-OSX

I'm not very sure if this will help, but have you considered using a proxy / bridge to connect to server using SSH? For example: https://github./novnc/websockify

Websockify is a WebSocket to TCP proxy/bridge. This allows a browser to connect to any application/server/service.

This way instead of relying on SSH Client, you can directly municate with server from your JS code.

For Mac users on Big Sur 11.6 you can in fact do this with Apple apps. A simple test will show.

  1. Open up Notes.app or TextEdit.app and create some text.
  2. Select a word or sentence and hit Edit → Attach link (⌘K)
  3. Create the url as ssh://user@host or ssh://host in the dialog.

Viola!

发布评论

评论列表(0)

  1. 暂无评论