Commit f0312d77 by Danyi Bence

Merge branch 'master' of ssh://giccero.cloud.ik.bme.hu/cloud

parents 3d982ebc 5e4efb13
#Install
cp rdp.sh /usr/local/bin/rdp
cp enc.pl /usr/local/bin/enc.pl
cp rdp.desktop ~/.local/share/applications/
### Ezt lehet hogy érdemesebb kézzel vagy echo >> mlg kiderül
cp mimeapps.list ~/.local/share/applications/
#http://www.nomachine.com/ar/view.php?ar_id=AR01C00125
use strict;
use Time::localtime;
$::numValidCharList = 85;
$::dummyString = "{{{{";
#
#FOR TEST
#
my $password = @ARGV[0];
print $password,"\n";
my $scrambled_string = scrambleString($password);
print $scrambled_string,"\n";
sub getvalidCharList
{
my $pos = shift;
my @validCharList =
(
"!", "#", "\$", "%", "&", "(", ")", "*", "+", "-",
".", "0", "1", "2", "3", "4", "5", "6", "7", "8",
"9", ":", ";", "<", ">", "?", "@", "A", "B", "C",
"D", "E", "F", "G", "H", "I", "J", "K", "L", "M",
"N", "O", "P", "Q", "R", "S", "T", "U", "V", "W",
"X", "Y", "Z", "[", "]", "_", "a", "b", "c", "d",
"e", "f", "g", "h", "i", "j", "k", "l", "m", "n",
"o", "p", "q", "r", "s", "t", "u", "v", "w", "x",
"y", "z", "{", "|", "}"
);
return $validCharList[$pos];
}
sub encodePassword
{
my $p = shift;
my $sPass = ":";
my $sTmp = "";
if (!$p)
{
return "";
}
for (my $i = 0; $i < length($p); $i++)
{
my $c = substr($p,$i,1);
my $a=ord($c);
$sTmp=($a+$i+1).":";
$sPass .=$sTmp;
$sTmp = "";
}
return $sPass;
}
sub findCharInList
{
my $c = shift;
my $i = -1;
for (my $j = 0; $j < $::numValidCharList; $j++)
{
my $randchar = getvalidCharList($j);
if ($randchar eq $c)
{
$i = $j;
return $i;
}
}
return $i;
}
sub getRandomValidCharFromList
{
my $tm = localtime;
my $k = ($tm->sec);
return getvalidCharList($k);
}
sub scrambleString
{
my $s = shift;
my $sRet = "";
if (!$s)
{
return $s;
}
my $str = encodePassword($s);
if (length($str) < 32)
{
$sRet .= $::dummyString;
}
for ( my $iR = (length($str) - 1); $iR >= 0; $iR--)
{
#
#Reverse string.
#
$sRet .= substr($str,$iR,1);
}
if (length($sRet) < 32)
{
$sRet .= $::dummyString;
}
my $app=getRandomValidCharFromList();
my $k=ord($app);
my $l=$k + length($sRet) -2;
$sRet= $app.$sRet;
for (my $i1 = 1; $i1 < length($sRet); $i1++)
{
my $app2=substr($sRet,$i1,1);
my $j = findCharInList($app2);
if ($j == -1)
{
return $sRet;
}
my $i = ($j + $l * ($i1 + 1)) % $::numValidCharList;
my $car=getvalidCharList($i);
$sRet=substr_replace($sRet,$car,$i1,1);
}
my $c = (ord(getRandomValidCharFromList())) + 2;
my $c2=chr($c);
$sRet=$sRet.$c2;
return URLEncode($sRet);
}
sub URLEncode
{
my $theURL = $_[0];
$theURL =~ s/&/&amp;/g;
$theURL =~ s/\"\"/&quot;/g;
$theURL =~ s/\'/&#039;/g;
$theURL =~ s/</&lt;/g;
$theURL =~ s/>/&gt;/g;
return $theURL;
}
sub substr_replace
{
my $str = shift;
my $ch = shift;
my $pos = shift;
my $qt = shift;
my @list = split (//,$str);
my $count = 0;
my $tmp_str = '';
foreach my $key(@list)
{
if ($count != $pos)
{
$tmp_str .= $key;
}
else
{
$tmp_str .= $ch;
}
$count++;
}
return $tmp_str;
}
[Added Associations]
application/nx-session=gedit.desktop;
x-scheme-handler/rdp=rdp.desktop
x-scheme-handler/nx=rdp.desktop
[Default Applications]
text/html=chromium-browser.desktop
x-scheme-handler/http=chromium-browser.desktop
x-scheme-handler/https=chromium-browser.desktop
x-scheme-handler/about=chromium-browser.desktop
x-scheme-handler/unknown=chromium-browser.desktop
[Desktop Entry]
Name=RDP Client
Exec=/usr/local/bin/rdp %u
Icon=
Type=Application
Terminal=false
MimeType=x-scheme-handler/rdp;
#!/bin/bash
IFS=: read scheme user password host port<<<"$*"
case $scheme in
rdp)
tmp=$(mktemp)
rdesktop -khu -E -P -0 -f -u "$user" -p "$password" "$host":"$port" 2>$tmp
if grep '^ERROR' <$tmp
then
err="$(grep '^ERROR' $tmp)"
rm /home/user/.ssh/known_hosts
/usr/NX/bin/nxclient --dialog error --message "$err" &
fi
rm $tmp
;;
nx)
f=$(mktemp)
#pw=$(perl /usr/local/bin/enc.pl "$password"|tail -1|sed -e 's/\&/\&amp;/g' -e 's/</\&lt;/g' -e 's/"/&quot;/g' -e "s/'/\&apos;/g")
pw=$(perl /usr/local/bin/enc.pl "$password"|tail -1)
cat >"$f" <<A
<!DOCTYPE NXClientSettings>
<NXClientSettings application="nxclient" version="1.3" >
<group name="Advanced" >
<option key="Cache size" value="16" />
<option key="Cache size on disk" value="64" />
<option key="Current keyboard" value="true" />
<option key="Custom keyboard layout" value="" />
<option key="Disable DirectDraw" value="false" />
<option key="Disable ZLIB stream compression" value="false" />
<option key="Disable deferred updates" value="false" />
<option key="Enable HTTP proxy" value="false" />
<option key="Enable SSL encryption" value="true" />
<option key="Enable response time optimisations" value="false" />
<option key="Grab keyboard" value="false" />
<option key="HTTP proxy host" value="" />
<option key="HTTP proxy port" value="8080" />
<option key="HTTP proxy username" value="" />
<option key="Remember HTTP proxy password" value="false" />
<option key="Restore cache" value="true" />
<option key="StreamCompression" value="" />
</group>
<group name="Environment" >
<option key="CUPSD path" value="/usr/sbin/cupsd" />
</group>
<group name="General" >
<option key="Automatic reconnect" value="true" />
<option key="Command line" value="" />
<option key="Custom Unix Desktop" value="console" />
<option key="Desktop" value="gnome" />
<option key="Disable SHM" value="false" />
<option key="Disable emulate shared pixmaps" value="false" />
<option key="Link speed" value="lan" />
<option key="Remember password" value="true" />
<option key="Resolution" value="fullscreen" />
<option key="Resolution height" value="600" />
<option key="Resolution width" value="800" />
<option key="Server host" value="${host}" />
<option key="Server port" value="${port}" />
<option key="Session" value="unix" />
<option key="Spread over monitors" value="false" />
<option key="Use default image encoding" value="0" />
<option key="Use render" value="true" />
<option key="Use taint" value="true" />
<option key="Virtual desktop" value="false" />
<option key="XAgent encoding" value="true" />
<option key="displaySaveOnExit" value="true" />
<option key="xdm broadcast port" value="177" />
<option key="xdm list host" value="localhost" />
<option key="xdm list port" value="177" />
<option key="xdm mode" value="server decide" />
<option key="xdm query host" value="localhost" />
<option key="xdm query port" value="177" />
</group>
<group name="Images" >
<option key="Disable JPEG Compression" value="0" />
<option key="Disable all image optimisations" value="false" />
<option key="Disable backingstore" value="false" />
<option key="Disable composite" value="false" />
<option key="Image Compression Type" value="3" />
<option key="Image Encoding Type" value="0" />
<option key="Image JPEG Encoding" value="false" />
<option key="JPEG Quality" value="6" />
<option key="RDP Image Encoding" value="3" />
<option key="RDP JPEG Quality" value="6" />
<option key="RDP optimization for low-bandwidth link" value="false" />
<option key="Reduce colors to" value="" />
<option key="Use PNG Compression" value="true" />
<option key="VNC JPEG Quality" value="6" />
<option key="VNC images compression" value="3" />
</group>
<group name="Login" >
<option key="Auth" value="${pw}" />
<option key="Guest Mode" value="false" />
<option key="Guest password" value="" />
<option key="Guest username" value="" />
<option key="Login Method" value="nx" />
<option key="User" value="${user}" />
</group>
<group name="Services" >
<option key="Audio" value="false" />
<option key="IPPPort" value="631" />
<option key="IPPPrinting" value="false" />
<option key="Shares" value="false" />
</group>
<group name="VNC Session" >
<option key="Display" value="0" />
<option key="Remember" value="false" />
<option key="Server" value="" />
</group>
<group name="Windows Session" >
<option key="Application" value="" />
<option key="Authentication" value="2" />
<option key="Color Depth" value="8" />
<option key="Domain" value="" />
<option key="Image Cache" value="true" />
<option key="Password" value="EMPTY_PASSWORD" />
<option key="Remember" value="true" />
<option key="Run application" value="false" />
<option key="Server" value="" />
<option key="User" value="" />
</group>
<group name="share chosen" >
<option key="Share number" value="0" />
</group>
</NXClientSettings>
A
/usr/NX/bin/nxclient --session $f
;;
ssh)
#/usr/NX/bin/nxclient --dialog ok --message "Jelszó: $password" &
rm /home/user/.ssh/known_hosts
#rxvt-unicode -e sh -c "ssh $user@$host -p$port; sleep 2"
rxvt-unicode -e sh -c "sshpass -p "$password" ssh -o StrictHostKeyChecking=no $user@$host -p$port; sleep 2"
;;
*)
xmessage "$scheme is not supported."
;;
esac
echo "$*" >>/tmp/protolog
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment