Skip to content

Commit 625507b

Browse files
Upload for pre-alpha-0.0.1
1 parent eace108 commit 625507b

6 files changed

Lines changed: 254 additions & 0 deletions

File tree

SWSH.sln

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 15
4+
VisualStudioVersion = 15.0.26430.16
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SWSH", "SWSH\SWSH.csproj", "{6A30C4D1-0E4F-49B9-B2B2-D210923CE44C}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{6A30C4D1-0E4F-49B9-B2B2-D210923CE44C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{6A30C4D1-0E4F-49B9-B2B2-D210923CE44C}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{6A30C4D1-0E4F-49B9-B2B2-D210923CE44C}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{6A30C4D1-0E4F-49B9-B2B2-D210923CE44C}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
EndGlobal

SWSH/App.config

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<configuration>
3+
<startup>
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
5+
</startup>
6+
</configuration>

SWSH/Program.cs

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
using Renci.SshNet;
2+
using System.IO;
3+
4+
using System;
5+
using System.Collections.Generic;
6+
using System.Linq;
7+
using System.Text;
8+
using System.Threading.Tasks;
9+
10+
namespace SWSH {
11+
class Program {
12+
static string _command = "", _version = "pre-alpha-0.0.1", _mainDirectory = "swsh-data/";
13+
static void Main(string[] args) {
14+
__version();
15+
Console.Write("swsh --help or -h for help.\n\n");
16+
__start();
17+
}
18+
public static void __start() {
19+
while (true) {
20+
__color("swsh> ", ConsoleColor.DarkGray);
21+
_command = Console.ReadLine();
22+
if (_command.StartsWith("swsh")) {
23+
_command = _command.Replace("swsh", "").Trim();
24+
if (_command == "--version" || _command == "-v") __version();
25+
else if (_command == "--add" || _command == "-a") {
26+
__color("exit", ConsoleColor.Red);
27+
Console.Write(" or ");
28+
__color("-e", ConsoleColor.Red);
29+
Console.Write(" to cancel.\n");
30+
Console.Write("Path to private key: ");
31+
var key = Console.ReadLine();
32+
__checkexit(key);
33+
Console.Write("Username: ");
34+
var usr = Console.ReadLine();
35+
__checkexit(usr);
36+
Console.Write("Server: ");
37+
var svr = Console.ReadLine();
38+
__checkexit(svr);
39+
getNick:
40+
Console.Write("Unique Nickname: ");
41+
var nkn = Console.ReadLine();
42+
if (File.Exists(_mainDirectory + nkn + ".swsh")) {
43+
__color("ERROR: ", ConsoleColor.Red);
44+
Console.WriteLine("SWSH -> {0} -> nickname exists", nkn);
45+
goto getNick;
46+
}
47+
if (nkn.Trim() == string.Empty) goto getNick;
48+
String[] data = new String[] { key, usr, svr };
49+
if (!Directory.Exists(_mainDirectory)) Directory.CreateDirectory(_mainDirectory);
50+
File.WriteAllLines(_mainDirectory + nkn + ".swsh", data);
51+
} else if (_command == "--help" || _command == "-h") {
52+
Console.WriteLine("--version -v: -Check the version of swsh.");
53+
Console.WriteLine("--add -a: -Add a new connection.");
54+
Console.WriteLine("--connect [nickname] -c [nickname]: -Connects to Server over SSH.");
55+
Console.WriteLine("--help -h: -Displays this help.");
56+
Console.WriteLine("exit: Exits.");
57+
Console.WriteLine("\n\nNOTES:\n[1] cd .. is not supported.");
58+
} else if (_command.StartsWith("--connect") || _command.StartsWith("-c")) {
59+
#region SSH Control
60+
var ccinfo = (_command.StartsWith("--connect")) ? __CreateConnectionInfo(_command.Remove(0, 10)) : __CreateConnectionInfo(_command.Remove(0, 3));
61+
if (ccinfo != null) {
62+
Console.Write("Waiting for response from {0}@{1}...\n", ccinfo.Username, ccinfo.Host);
63+
using (var ssh = new SshClient(ccinfo)) {
64+
ssh.Connect();
65+
__color("Connected to "+ ccinfo.Username + "@" + ccinfo.Host + "...\n", ConsoleColor.Green);
66+
string pwd = " ", home = "";
67+
home = pwd = ssh.CreateCommand("echo $HOME").Execute();
68+
while (true) {
69+
if (pwd == home) pwd = "~";
70+
__color(pwd, ConsoleColor.Green);
71+
Console.Write(":/ $ ");
72+
_command = Console.ReadLine();
73+
if (_command == "exit")
74+
break;
75+
else if (_command.StartsWith("cd ")) {
76+
_command = _command.Remove(0, 3);
77+
if (_command.StartsWith("/")) pwd = _command;
78+
else if (_command.StartsWith("./")) pwd += "/" + _command.Remove(0, 2);
79+
else if (_command.StartsWith("..")) {
80+
__color("ERROR: ", ConsoleColor.Red);
81+
Console.Write("SWSH -> cd {0} -> Operation not allowed. Run \"swsh -h\" and see Note #1.\n", _command);
82+
} else pwd += "/" + _command;
83+
} else if (_command == "clear") Console.Clear();
84+
else {
85+
var result = ssh.CreateCommand("cd " + pwd + "; " + _command).Execute();
86+
Console.Write(result);
87+
}
88+
}
89+
ssh.Disconnect();
90+
}
91+
__color("Connection to "+ ccinfo.Username + "@" + ccinfo.Host + ", closed.\n", ConsoleColor.Yellow);
92+
} else break;
93+
#endregion
94+
}
95+
} else if (_command == "exit") break;
96+
}
97+
}
98+
public static void __version() {
99+
Console.Write(" ______ _______ __ __\n / ___/ | / / ___// / / /\n \\__ \\| | /| / /\\__ \\/ /_/ / \n ___/ /| |/ |/ /___/ / __ / \n/____/ |__/|__//____/_/ /_/ \n Secure Windows Shell \n");
100+
Console.Write("\nRelease: {0}\n{1}", _version, "(c) Muhammad Muzzammil & Nabeel Omer\n");
101+
}
102+
public static void __color(string message, ConsoleColor cc) {
103+
Console.ForegroundColor = cc;
104+
Console.Write(message);
105+
Console.ResetColor();
106+
}
107+
public static void __checkexit(string keyword) {
108+
if (keyword == "exit" || keyword == "-e") __start();
109+
}
110+
public static ConnectionInfo __CreateConnectionInfo(string nickname) {
111+
if (File.Exists(_mainDirectory + nickname + ".swsh")) {
112+
string privateKeyFilePath = File.ReadAllLines(_mainDirectory + nickname + ".swsh")[0],
113+
user = File.ReadAllLines(_mainDirectory + nickname + ".swsh")[1],
114+
server = File.ReadAllLines(_mainDirectory + nickname + ".swsh")[2];
115+
ConnectionInfo connectionInfo;
116+
using (var stream = new FileStream(privateKeyFilePath, FileMode.Open, FileAccess.Read)) {
117+
var privateKeyFile = new PrivateKeyFile(stream);
118+
AuthenticationMethod authenticationMethod = new PrivateKeyAuthenticationMethod(user, privateKeyFile);
119+
connectionInfo = new ConnectionInfo(server, user, authenticationMethod);
120+
}
121+
return connectionInfo;
122+
}else {
123+
__color("ERROR: ", ConsoleColor.Red);
124+
Console.WriteLine("SWSH -> {0} -> nickname does not exists", nickname);
125+
__start();
126+
return null;
127+
}
128+
}
129+
}
130+
}

SWSH/Properties/AssemblyInfo.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// General Information about an assembly is controlled through the following
6+
// set of attributes. Change these attribute values to modify the information
7+
// associated with an assembly.
8+
[assembly: AssemblyTitle("SWSH")]
9+
[assembly: AssemblyDescription("")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("")]
12+
[assembly: AssemblyProduct("SWSH")]
13+
[assembly: AssemblyCopyright("Copyright © 2017")]
14+
[assembly: AssemblyTrademark("")]
15+
[assembly: AssemblyCulture("")]
16+
17+
// Setting ComVisible to false makes the types in this assembly not visible
18+
// to COM components. If you need to access a type in this assembly from
19+
// COM, set the ComVisible attribute to true on that type.
20+
[assembly: ComVisible(false)]
21+
22+
// The following GUID is for the ID of the typelib if this project is exposed to COM
23+
[assembly: Guid("6a30c4d1-0e4f-49b9-b2b2-d210923ce44c")]
24+
25+
// Version information for an assembly consists of the following four values:
26+
//
27+
// Major Version
28+
// Minor Version
29+
// Build Number
30+
// Revision
31+
//
32+
// You can specify all the values or you can default the Build and Revision Numbers
33+
// by using the '*' as shown below:
34+
// [assembly: AssemblyVersion("1.0.*")]
35+
[assembly: AssemblyVersion("1.0.0.0")]
36+
[assembly: AssemblyFileVersion("1.0.0.0")]

SWSH/SWSH.csproj

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{6A30C4D1-0E4F-49B9-B2B2-D210923CE44C}</ProjectGuid>
8+
<OutputType>Exe</OutputType>
9+
<RootNamespace>SWSH</RootNamespace>
10+
<AssemblyName>SWSH</AssemblyName>
11+
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
12+
<FileAlignment>512</FileAlignment>
13+
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
14+
</PropertyGroup>
15+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
16+
<PlatformTarget>AnyCPU</PlatformTarget>
17+
<DebugSymbols>true</DebugSymbols>
18+
<DebugType>full</DebugType>
19+
<Optimize>false</Optimize>
20+
<OutputPath>bin\Debug\</OutputPath>
21+
<DefineConstants>DEBUG;TRACE</DefineConstants>
22+
<ErrorReport>prompt</ErrorReport>
23+
<WarningLevel>4</WarningLevel>
24+
</PropertyGroup>
25+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
26+
<PlatformTarget>AnyCPU</PlatformTarget>
27+
<DebugType>pdbonly</DebugType>
28+
<Optimize>true</Optimize>
29+
<OutputPath>bin\Release\</OutputPath>
30+
<DefineConstants>TRACE</DefineConstants>
31+
<ErrorReport>prompt</ErrorReport>
32+
<WarningLevel>4</WarningLevel>
33+
</PropertyGroup>
34+
<ItemGroup>
35+
<Reference Include="Renci.SshNet, Version=2016.0.0.0, Culture=neutral, PublicKeyToken=1cee9f8bde3db106, processorArchitecture=MSIL">
36+
<HintPath>..\packages\SSH.NET.2016.0.0\lib\net40\Renci.SshNet.dll</HintPath>
37+
</Reference>
38+
<Reference Include="System" />
39+
<Reference Include="System.Core" />
40+
<Reference Include="System.Xml.Linq" />
41+
<Reference Include="System.Data.DataSetExtensions" />
42+
<Reference Include="Microsoft.CSharp" />
43+
<Reference Include="System.Data" />
44+
<Reference Include="System.Net.Http" />
45+
<Reference Include="System.Xml" />
46+
</ItemGroup>
47+
<ItemGroup>
48+
<Compile Include="Program.cs" />
49+
<Compile Include="Properties\AssemblyInfo.cs" />
50+
</ItemGroup>
51+
<ItemGroup>
52+
<None Include="App.config" />
53+
<None Include="packages.config" />
54+
</ItemGroup>
55+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
56+
</Project>

SWSH/packages.config

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<packages>
3+
<package id="SSH.NET" version="2016.0.0" targetFramework="net452" />
4+
</packages>

0 commit comments

Comments
 (0)