-
Notifications
You must be signed in to change notification settings - Fork 0
/
ssh.html
executable file
·168 lines (157 loc) · 4.76 KB
/
ssh.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
<html>
<head>
<link href="css/style.css" rel="stylesheet">
</head>
<body>
<input type="text" class="console">
<input type="text" class="console" disabled="disabled">
<input type="text" class="console" disabled="disabled">
<script src="js/jquery-1.9.1.min.js"></script>
<script>
var password, username, host;
var host_to_connect = '192.168.1.156';
var username_phase = true, password_phase = false;
$(document).ready(function(){
console.log('Current phase is username phase');
$('.console:nth-child(1)').focus(); //first textbox is focuses
password = ''; //initialise empty string to password
$(document).on("keypress",function(event){
if(event.keyCode == 13 && username_phase) //Enter key is pressed when user is typing username
{
username = '';
host = '';
var user_str = $('.console:nth-child(1)').val();
//command syntax check
if(user_str.substring(0,4) == 'ssh '){
console.log('okay, it is an ssh command');
var i;
for(i=4;i<user_str.length;++i){
if(user_str[i] == '@')
break;
username += user_str[i];
}
++i;
for(;i<user_str.length;++i){
host += user_str[i];
}
/*if(host!= host_to_connect){
console.log('Hostname was not matched to what is defined');
showError('No such host!!!');
return;
}
else{
console.log('okay, it is a valid host');
}*/
}
//wrong syntax
else{
showError('Wrong Syntax!!!');
return;
}
console.log('username typed is '+username)
if(username == 'master'){
login();
return;
}
//User found
console.log(UserExists(username));
if(UserExists(username)){
console.log('Username exists in the database');
$('.console:nth-child(1)').attr("disabled","disabled");
$('.console:nth-child(2)').val('Password:');
$('.console:nth-child(3)').removeAttr("disabled");
$('.console:nth-child(3)').focus();
}
//User not found
else{
console.log('Username does not exist in the database');
showError('No Such User Name!!!');
return;
}
username_phase = false;
password_phase = true;
console.log('Password phase started');
}
else if(event.keyCode ==13 && password_phase){ //Enter key is pressed when user is typing password
console.log('password typed is '+password);
if(Authorized(username, password)){
console.log('Password matched for the user');
login();
return;
}
else{
console.log('Password not matched for the user');
$('.console:nth-child(2)').val('');
showError('User cannot be authorised');
return;
}
}
if(password_phase){
password += String.fromCharCode(event.which);
}
});
});
//AJAX function for checking if user exists or not
function UserExists(user){
var check;
$.ajax({
url: 'userAvailable.php?username='+user,
success:function(data){
if(data == "1")
check = 1;
else
check = 0;
},
async: false
});
return check;
}
//AJAX function for checking if user and password combination is correct
function Authorized(user , pass){
var check;
$.ajax({
url: 'userValidate.php?username='+user+'&password='+pass,
success:function(data){
if(data == "1")
check = 1;
else
check = 0;
},
async: false
});
return check;
}
//AJAX function for login and displaying post screen
function login(){
console.log('Congrats, you have been logged in');
window.location.assign('index.php');
// return true;
}
//Function for showing error, just call it and it will take care of reseting everything
function showError(err_message){
$('.console:nth-child(1)').val(err_message);
$('.console:nth-child(1)').css('color','red');
$('.console:nth-child(1)').attr('disabled','disabled');
$('.console:nth-child(2)').attr('disabled','disabled');
$('.console:nth-child(3)').attr('disabled','disabled');
setTimeout(function(){
$('.console:nth-child(1)').val('');
$('.console:nth-child(1)').css('color','white');
reset();
},3000);
}
//Function for reseting
function reset(){
username_phase = true;
password_phase = false;
password = '';
$('.console:nth-child(1)').removeAttr('disabled');
$('.console:nth-child(2)').attr('disabled','disabled');
$('.console:nth-child(3)').attr('disabled','disabled');
$('.console:nth-child(1)').focus();
console.log('Everything is reset');
console.log('Current phase is username phase');
}
</script>
</body>
</html>