2026-08-17 15:19:06 +00:00
( function ( ) {
"use strict" ;
2026-08-17 15:15:05 +00:00
const SDK = window . _ _HERMES _PLUGIN _SDK _ _ ;
2026-08-17 15:19:06 +00:00
const { React } = SDK ;
2026-09-03 04:47:45 +00:00
const { Card , CardHeader , CardTitle , CardContent } = SDK . components ;
2026-08-17 15:23:40 +00:00
2026-09-03 04:47:45 +00:00
async function fetchJSONAllowError ( path ) {
2026-09-03 04:27:30 +00:00
if ( SDK && SDK . fetchJSON ) {
2026-09-03 04:47:45 +00:00
try { return await SDK . fetchJSON ( path ) ; } catch ( e ) { if ( e && e . data ) return e . data ; throw e ; }
2026-09-03 04:27:30 +00:00
}
let url = path ;
try {
const cur = new URL ( window . location . href ) ;
const profile = cur . searchParams . get ( "profile" ) ;
if ( profile ) {
const u = new URL ( path , window . location . origin ) ;
if ( ! u . searchParams . get ( "profile" ) ) u . searchParams . set ( "profile" , profile ) ;
url = u . pathname + u . search ;
}
} catch ( _ ) { }
2026-09-03 04:47:45 +00:00
const res = await fetch ( url ) ;
2026-09-03 04:27:30 +00:00
const text = await res . text ( ) ;
2026-09-03 04:47:45 +00:00
try { return JSON . parse ( text ) ; } catch ( _ ) { return { status : "error" , message : text . slice ( 0 , 800 ) } ; }
2026-08-19 00:00:34 +00:00
}
2026-09-03 04:21:03 +00:00
function SSHXPage ( ) {
2026-09-03 04:47:45 +00:00
const [ link , setLink ] = React . useState ( null ) ;
const [ status , setStatus ] = React . useState ( "idle" ) ;
2026-09-03 04:30:52 +00:00
2026-09-03 04:47:45 +00:00
const check = React . useCallback ( async function ( ) {
2026-09-03 04:30:52 +00:00
try {
2026-09-03 04:47:45 +00:00
const r = await fetchJSONAllowError ( "/api/plugins/sshx-link/status" ) ;
if ( r . link ) { setLink ( r . link ) ; setStatus ( "running" ) ; }
else { setLink ( null ) ; setStatus ( r . status || "stopped" ) ; }
} catch ( _ ) { }
2026-09-03 04:30:52 +00:00
} , [ ] ) ;
2026-09-03 04:47:45 +00:00
React . useEffect ( function ( ) { check ( ) ; const t = setInterval ( check , 3000 ) ; return function ( ) { clearInterval ( t ) ; } } , [ check ] ) ;
2026-09-03 04:30:52 +00:00
2026-09-03 04:47:45 +00:00
if ( link ) {
2026-08-19 00:00:34 +00:00
return React . createElement ( Card , null ,
React . createElement ( CardHeader , null ,
2026-09-03 04:47:45 +00:00
React . createElement ( CardTitle , null , "sshx.io — Current Link" ) ,
React . createElement ( "p" , { className : "text-xs text-green-500" , style : { fontWeight : 600 } } , "● Active" )
2026-08-19 00:00:34 +00:00
) ,
React . createElement ( CardContent , null ,
2026-09-03 04:47:45 +00:00
React . createElement ( "a" , { href : link , target : "_blank" , rel : "noopener noreferrer" , style : { color : "#60a5fa" , fontSize : "1.05rem" , wordBreak : "break-all" , textDecoration : "underline" , display : "block" , fontWeight : 600 } } , link ) ,
React . createElement ( "p" , { className : "text-xs text-muted-foreground" , style : { marginTop : "0.5rem" } } , "Link hiện tại của shell sshx. Chỉ hiển thị — không tự chạy nền (hermes kill shell gây lỗi). Chạy thủ công trên host: nohup sshx --quiet > /tmp/sshx_link.txt 2>&1 &" )
2026-08-19 00:00:34 +00:00
)
) ;
}
2026-08-17 15:19:06 +00:00
return React . createElement ( Card , null ,
React . createElement ( CardHeader , null ,
2026-09-03 04:47:45 +00:00
React . createElement ( CardTitle , null , "sshx.io — Current Link" ) ,
React . createElement ( "p" , { className : "text-xs text-muted-foreground" } , "Chưa có shell đang chạy" )
2026-08-17 15:19:06 +00:00
) ,
React . createElement ( CardContent , null ,
2026-09-03 04:47:45 +00:00
React . createElement ( "p" , { className : "text-sm text-muted-foreground" } , "Không có link hiện tại. Plugin ở chế độ passive — không tự chạy sshx nền (hermes kill). Hãy chạy thủ công trên server:" ) ,
React . createElement ( "pre" , { style : { marginTop : "0.5rem" , background : "#111" , padding : "0.5rem" , borderRadius : "6px" , fontSize : "0.75rem" , overflow : "auto" } } , "nohup sshx --quiet > /tmp/sshx_link.txt 2>&1 &\ncat /tmp/sshx_link.txt" ) ,
React . createElement ( "p" , { className : "text-xs text-muted-foreground" , style : { marginTop : "0.5rem" } } , "Dashboard sẽ tự đọc /tmp/sshx_link.txt và hiện link ở đây, đồng thời tự refresh mỗi 3s." )
2026-08-17 15:19:06 +00:00
)
2026-08-17 15:15:05 +00:00
) ;
}
2026-09-03 04:21:03 +00:00
window . _ _HERMES _PLUGINS _ _ . register ( "sshx-link" , SSHXPage ) ;
2026-08-17 15:15:05 +00:00
} ) ( ) ;