天融信快速登陆Linux+SecureCRT版本
// ==UserScript==
// @name 天融信快速登陆Linux+SecureCRT版本
// @namespace http://tampermonkey.net/
// @version 1.0
// @description 免除安装sso登陆组件的安装以及必须IE打开的限制
// @author jzjbyq
// @match https://*/iam/portal/sso/auth_list.jsp*
// @icon https://www.google.com/s2/favicons?domain=241.201
// @grant none
// @run-at document-end
// ==/UserScript==
(function() {
'use strict';
//存储自定义js内容
let m =`
<script>
//提取页面原本的js代码改了名字,修改putty的内容 原本提示"客户端控件未安装或被禁用",改为alert显示验证码。
function fast_sso1(auth_rdn) {
//生成一个24位的随机串
var str = randomString();
$.ajax({
url:'/iam/fast_sso.do',
type:'post',
async:false,
data:{"method" : "login", "auth_rdn" : auth_rdn, "encs" : RSAUtils.encs(str), "debug" : "1"},
dataType:'json',
success:function(data) {
if (data.result == 1) {
data.meta.str = str;
fast_sso_conn1(data.meta);
} else {
alert(data.msg);
}
},
error:function(XMLHttpRequest, textStatus, errorThrown){
alert("FAST SSO ERROR");
}
});
}
function fast_sso_conn1(meta) {
var res_type = meta.res_type;
var protocol = meta.protocol;
var login_tool = meta.login_tool;
// var app_client = meta.app_client;
var sso_start = meta.sso_start;
var start_mode = meta.start_mode;
if(res_type.endsWith(VM)){
if (PROL_XWIN == protocol || PROL_VNC == protocol) {
vnc_xwin(meta);
} else if (PROL_FTP == protocol || PROL_SFTP == protocol || PROL_SMB == protocol) {
xftp(meta);
} else if (PROL_SSH1 == protocol || PROL_SSH2 == protocol || PROL_TELNET == protocol) {
if(SCRT == login_tool){
scrt(meta);
} else if (PUTTY == login_tool){
putty(meta);
} else if (XSHELL == login_tool){
xshell(meta);
} else {
alert("login_tool error:" + login_tool);
}
} else if (PROL_RDP == protocol) {
if (PROL_RDP2 == protocol) {
rdp2(meta);
} else {
rdp(meta);
}
} else {
alert("登录错误");
}
}else if (res_type.endsWith(UNIX)) {
if (PROL_XWIN == protocol || PROL_VNC == protocol) {
vnc_xwin(meta);
} else if (PROL_FTP == protocol || PROL_SFTP == protocol) {
xftp(meta);
} else if (PROL_SSH1 == protocol || PROL_SSH2 == protocol || PROL_TELNET == protocol) {
if(SCRT == login_tool){
scrt(meta);
} else if (PUTTY == login_tool){
putty(meta);
} else if (XSHELL == login_tool){
xshell(meta);
} else {
alert("login_tool error:" + login_tool);
}
} else {
alert("登录错误");
}
} else if (res_type.endsWith(NETDEV)) {
if (PROL_SSH1 == protocol || PROL_SSH2 == protocol || PROL_TELNET == protocol) {
if(SCRT == login_tool){
scrt(meta);
} else if(PUTTY == login_tool){
putty(meta);
} else if (XSHELL == login_tool){
xshell(meta);
} else {
alert("login_tool error:" + login_tool);
}
} else {
alert("登录错误");
}
} else if (res_type.endsWith(WIN) || res_type.endsWith(AD)) {
if (PROL_RDP == protocol) {
rdp(meta);
} else if (PROL_RDP2 == protocol) {
rdp2(meta);
} else if (PROL_VNC == protocol) {
vnc_xwin(meta);
} else if (PROL_SMB == protocol || PROL_FTP == protocol) {
xftp(meta);
} else {
alert("登录错误");
}
} else if (res_type.endsWith(DB) || res_type.endsWith(DBS)) {
if (login_tool == PLSQL) {
oracle_plsql(meta);
} else if (login_tool == TOAD) {
oracle_toad(meta);
} else if (login_tool == MSSQL_2005_STUDIO || login_tool == MSSQL_2008_STUDIO) {
sqlserver(meta);
} else if (login_tool == MYSQL_FRONT) {
mysqlfront(meta);
} else if (login_tool == DB2TOAD){
db2toad(meta);
} else if (login_tool == SYBASE_CENTRAL) {
sybasecentral(meta);
} else if (login_tool == WINSQL) {
winsql(meta);
} else if (start_mode == SMODE_ISSUER) {
if (PROL_RDP2 == protocol) {
app2(meta);
} else {
app(meta);
}
} else {
alert("登录错误");
}
} else if (res_type.endsWith(CS) || res_type.endsWith(BS)) {
if (start_mode == SMODE_ISSUER) {
if (PROL_RDP2 == protocol) {
app2(meta);
} else {
app(meta);
}
} else if (start_mode == SMODE_DIRECT) {
direct_sso(meta);
} else {
alert("登录错误");
}
} else if (res_type.endsWith(MW)) {
if (start_mode == SMODE_ISSUER) {
if (PROL_RDP2 == protocol) {
app2(meta);
} else {
app(meta);
}
} else {
alert("登录错误");
}
} else {
alert("资源类型错误: " + res_type);
}
}
function xshell(meta) {
var fort_ip = getFortIp(meta.fortIp);
if (fort_ip == null) {
alert("单点登录错误: FORT_IP ERR");
return;
}
try{
sso_0.xshell_1(fort_ip, "22", "user", meta.sessionId, meta.acc_name + "@" + meta.res_ip, meta.res_ip, meta.acc_name);
} catch(err) {
alert("客户端控件未安装或被禁用!");
}
}
function putty(meta) {
var fort_ip = getFortIp(meta.fortIp);
if (fort_ip == null) {
alert("单点登录错误: FORT_IP ERR");
return;
}
//sso.run("sso_putty.exe","-ssh -P 22 -pw ROOTROOT root@192.168.1.2");
var sso_url = "-ssh -P 22 -pw "+ meta.sessionId +" user@" + fort_ip;
try{
sso.run("sso_putty.exe", sso_url);
} catch(err) {
//将sessionid写入剪切板======================================================
var clipBoardContent="";
var seorun="";
clipBoardContent = meta.sessionId;
//生成命令行内容并进行base64加密
seorun=window.btoa("ssh2 user@`+window.document.domain+` /P 22 /PASSWORD "+clipBoardContent);
//与本地mime协议进行通讯
window.open('x-ssh://'+seorun);
//alert("ssh2 user@`+window.document.domain+` /P 22 /PASSWORD "+clipBoardContent);
//alert('x-ssh://'+seorun);
//复制到剪切板示例
//copyText( clipBoardContent, function (){console.log('复制成功')});
//alert('已经将验证码复制到剪切板');
}
}
function scrt(meta) {
var fort_ip = getFortIp(meta.fortIp);
if (fort_ip == null) {
alert("单点登录错误: FORT_IP ERR");
return;
}
var title = meta.res_name + "(" + meta.res_ip + ")->" + meta.acc_name;
var sso_url = meta.sessionId + " ssh2 " + fort_ip + " 22 user " + meta.sessionId + " " + title;
if (meta.crt_mode != null && meta.crt_mode == "tab"){
try{
sso_url = sso_url + " -tab";
sso.run("scrt_agent.exe", sso_url);
} catch(err) {
alert("您所使用的SecureCRT版本不支持以选项卡方式打开");
}
} else {
try {
sso.run("scrt_agent.exe", sso_url);
} catch(err) {
alert("客户端控件未安装或被禁用!");
}
}
}
function copyText(text, callback){ // text: 要复制的内容, callback: 回调
var tag = document.createElement('input');
tag.setAttribute('id', 'cp_hgz_input');
tag.value = text;
document.getElementsByTagName('body')[0].appendChild(tag);
document.getElementById('cp_hgz_input').select();
document.execCommand('copy');
document.getElementById('cp_hgz_input').remove();
if(callback) {callback(text)}
}
</script>`
//修改fast_sso指向到新的fast_sso1
$("span[onclick^='fast_sso']").each(function() {
var clickValue = $(this).attr("onclick").replace("fast_sso", "fast_sso1");
$(this).attr("onclick", clickValue);
});
//将变量m存储的内容追加到页面中,测试不追加的话,脚本执行过就不存在了,无法继续调用。
$(m).appendTo("body");
})();