Skip to content

Commit 2ff0ce7

Browse files
committed
recover
1 parent 250e9b2 commit 2ff0ce7

4 files changed

Lines changed: 302 additions & 0 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
.htaccess
2+
.htaccess

.ssh/id_rsa

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
-----BEGIN RSA PRIVATE KEY-----
2+
MIIEogIBAAKCAQEAwVSYKaYEJ4IFgpw1MQTjK1vxWFAvWR4VAeGxccOR2dXTBieA
3+
SdkGNseDcQByiqch5zGsOFk2TnmLqjO5ydZ1sMhtIcpoK5HS4I5ljY/00Cx+EwK+
4+
VfTt8irXbpwDFTxKrLaaBE9xhBYCC9lfQXkdRWz2zoOo4vFb9gjPi/75US0m2OO1
5+
loAT+DwgJmRfoDAAnnMa8LreXEb3Pttt8r8+18xuSLiko4ofFN28quC8a9VF4WkC
6+
9UXnSZo0q7rEarlCtnqF06nlSd8xHPQoFIGdHp4qM1Fgb1EXInNZCyVtZJ2eslAv
7+
CVnKsXNXBkUiXQffPEL18A8oLxwgXN+8+pd52wIDAQABAoIBABSvXGh4XtFrU/OZ
8+
iwdnonatK7FrQuWiFlVRNI8bgatw+VcbOtqr4cJSrnmUtqynHTWDVw3gXbMfxhW7
9+
2xEBZS45A5Qt999RhuKH2c2/rU3otMSL8pl3z02tz8cB4kKPZN3925TCez7KrAVg
10+
iJSUxND8y5tk8tj1QgWdA7fS3BIXNwcXTlCDxrtsWwXj44oedTPsDyXXlBI7fLhr
11+
6C6HXxn3IOJvU+q7wtk6NCv2YeADALsMk8AM6btmGgB7eYuXe3wtnC5uL1H7wDJS
12+
goM7IOKgQqFygC3aYqkEysuBQpwx94L6KvXf6hv7ri2hor3MePH+NYjRSoNhrtcW
13+
rr/WJqECgYEA4xwJmWoGgYiV+YllQTjfZ1GqSe5IjR5RFYhNTf1MgXrsmrIcJrYC
14+
mlfaLzNxlcaQwDPt/GTSa/otFMvJ5kutA25mfZrKjFkYa/uRZjbg0POI8kKSYxXV
15+
SON4ICypTX6dxXwHl6t6gjJXsDmoSSB2Q43C5o53tQeXa265p8NEYl0CgYEA2eyF
16+
NlITX+/mwVQqJaHNVnmSO7Emv0leCwtg+la5XH4Wxx5FORHnZ+7rZ9s6qDzSANtJ
17+
taND9IIbSycm+QafVqjcFmLYILX1RpaNqUSrTs5PAK08hUuppFsKRUVwEo5bbGGY
18+
QX8QNKOykr6Zn0f8/W9xnq1tRSDwi7haJoCZ+ZcCgYAHHw7x/5AaqbTCMVu6ctUW
19+
gUoMrWsa+bNjMHX0Fxg6Cye2JhWZ5SUpv814o21RW/uX+0jgHC0484xMVaOMFB1l
20+
uSV/lMX7JqQMZsQFZ30fMDPAHPRIJRwd//v5Tk00v96knaIDUH4z7O4w+W3cdScg
21+
MSbGYftA8u79kGhD6WyQhQKBgAxKOnkFx/HxJaJhjL7ykRH/aS/UncrL6HHXAnEb
22+
0vhUZBR2sJC3YcWKw9vnkTdLtsw1kcKcooh3jfJ/EsOYjAPnIgJhMK8nk92XQAX7
23+
yW14VRxEqNUbn0WVnM6rS9bAEIfcOSn4cIGHedqsxR0mgi4Iyu+X+EGdyfMXQn5J
24+
YmWhAoGAeMOshUoOnnjk3GBTqEKpYNrfvFm5ndQv9BWKfANI3KnFMvCEJ7AE71W9
25+
0gPcLcu6pUmu8FzLU0pQRrLb4hLAi84/TTJC+GLcWic0Q/0vwhd8r2Q6/g5wVCMA
26+
S3XG0JxL/5XCy6w0k+s1Y2C4UN8DmOwrEVtY7RhNxXB/NdrX9tI=
27+
-----END RSA PRIVATE KEY-----

.ssh/id_rsa.pub

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDBVJgppgQnggWCnDUxBOMrW/FYUC9ZHhUB4bFxw5HZ1dMGJ4BJ2QY2x4NxAHKKpyHnMaw4WTZOeYuqM7nJ1nWwyG0hymgrkdLgjmWNj/TQLH4TAr5V9O3yKtdunAMVPEqstpoET3GEFgIL2V9BeR1FbPbOg6ji8Vv2CM+L/vlRLSbY47WWgBP4PCAmZF+gMACecxrwut5cRvc+223yvz7XzG5IuKSjih8U3byq4Lxr1UXhaQL1RedJmjSrusRquUK2eoXTqeVJ3zEc9CgUgZ0eniozUWBvURcic1kLJW1knZ6yUC8JWcqxc1cGRSJdB988QvXwDygvHCBc37z6l3nb root@codeyourcloud.com

server.js

Lines changed: 273 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,273 @@
1+
"use strict";
2+
process.title = 'codeyourcloud';
3+
var webSocketsServerPort = 8080;
4+
var fs = require('fs');
5+
var Connection = require('ssh2');
6+
var webSocketServer = require('websocket').server;
7+
var https = require('http');//https
8+
/*
9+
var options = {
10+
key: fs.readFileSync("../../../../etc/ssl/private/www.codeyourcloud.com.key"),
11+
cert: fs.readFileSync("../../../../etc/ssl/certs/www.codeyourcloud.com.crt"),
12+
ca: fs.readFileSync("../../../../etc/ssl/certs/www.codeyourcloud.com-geotrust.crt")
13+
};*/
14+
var server = https.createServer(function(req, res){}); //options
15+
16+
server.listen(webSocketsServerPort, function() {
17+
console.log((new Date()) + " Server is listening on port " + webSocketsServerPort);
18+
});
19+
var wsServer = new webSocketServer({
20+
httpServer: server
21+
});
22+
/******************
23+
******************
24+
*****************
25+
***************
26+
**************
27+
************
28+
**********
29+
********
30+
******
31+
***
32+
*/
33+
var sessionIndex = [];
34+
//for every client, the index of the session
35+
/*
36+
the index is the id
37+
the actual connections
38+
*/
39+
var FILE = [];
40+
/*
41+
the fileids of the respectice clients
42+
LINES UP WITH ARRAYS
43+
*/
44+
var sessions = [];
45+
/*
46+
stores the indexes of the people in various sessions
47+
*/
48+
var total = 0;
49+
50+
var clients = [];
51+
/*
52+
#############
53+
CONNECTING
54+
#############
55+
1. you get the client id
56+
2. SERVER gets the fileid, locates the proper session and FILE
57+
2a. if there is no fileid, MAKE ONE
58+
3. index added to the proper session
59+
###################
60+
SAVING TO ALL PEOPLE IN A SESSION
61+
###################
62+
1. get client id
63+
2. all of the people in the session, except for the original person, SAVE
64+
!remember...the session is the INDEXES which can be located in the clients array
65+
*/
66+
//
67+
/*********
68+
SSH
69+
********/
70+
var ssh_port;
71+
var ssh_host;
72+
var ssh_login;
73+
var ssh_pass;
74+
//
75+
//
76+
wsServer.on('request', function(request) {
77+
//console.log((new Date()) + ' Connection from origin ' + request.origin + '.');
78+
var connection = request.accept(null, request.origin);
79+
connection.id = ++total;
80+
if(clients.length < connection.id){
81+
clients.push(connection);
82+
}
83+
/********
84+
THE IMPORTANT PART
85+
********/
86+
connection.on('message', function(message) {
87+
try{
88+
var json = JSON.parse(message.utf8Data);
89+
if(json.type === "request"){
90+
if(json.data === "init"){
91+
addToSession(json.session, connection.id);
92+
connection.send(JSON.stringify({type: "init", id: connection.id, session: sessionIndex[connection.id-1]}));
93+
94+
}
95+
}
96+
if(json.type === "command"){
97+
if(json.command === "save"){
98+
var array = sessions[sessionIndex[connection.id - 1]];
99+
for(var i = 0; i < array.length; i++){
100+
if(array[i] !== connection.id){
101+
clients[array[i]-1].send(JSON.stringify({type:"command",command:"save"}));
102+
}
103+
}
104+
}
105+
if(json.command === "rename"){
106+
var newTitle = json.title;
107+
var array = sessions[sessionIndex[connection.id - 1]];
108+
for(var i = 0; i < array.length; i++){
109+
if(array[i] !== connection.id){
110+
clients[array[i]-1].send(JSON.stringify({type:"command",command:"rename", title: newTitle}));
111+
}
112+
}
113+
}
114+
if(json.command === "mode"){
115+
var newMode = json.mode;
116+
var array = sessions[sessionIndex[connection.id - 1]];
117+
for(var i = 0; i < array.length; i++){
118+
if(array[i] !== connection.id){
119+
clients[array[i]-1].send(JSON.stringify({type:"command",command:"mode", mode: newMode}));
120+
}
121+
}
122+
}
123+
if(json.command === "theme"){
124+
var newTheme = json.theme;
125+
var array = sessions[sessionIndex[connection.id - 1]];
126+
for(var i = 0; i < array.length; i++){
127+
if(array[i] !== connection.id){
128+
clients[array[i]-1].send(JSON.stringify({type:"command",command:"theme", theme: newTheme}));
129+
}
130+
}
131+
}
132+
}
133+
if(json.type === "comment"){
134+
var text = json.comment;
135+
var name = json.sender;
136+
var mail = json.email;
137+
//
138+
var output = name + "\n" + mail + "\n" + text + "\n*******************************\n";
139+
fs.appendFile('comments.txt', output, function (err) {
140+
141+
});
142+
}
143+
if(json.type === "update"){
144+
145+
var array = sessions[sessionIndex[connection.id - 1]];
146+
for(var i = 0; i < array.length; i++){
147+
148+
clients[array[i]-1].send(JSON.stringify({type:"update", name: json.name}));
149+
}
150+
151+
}
152+
/********
153+
SSH
154+
*********/
155+
if(json.type === "ssh"){
156+
if(json.ssh === "init"){
157+
//
158+
ssh_port = json.port;
159+
ssh_host = json.host;
160+
ssh_login = json.login;
161+
ssh_pass = json.password;
162+
startSSH();
163+
}
164+
if(json.ssh === "folder"){
165+
ssh_dir(json.path);
166+
}
167+
}
168+
}
169+
catch(e){
170+
}
171+
});
172+
// user disconnected
173+
connection.on('close', function(connection) {
174+
try{
175+
var index = connection.id - 1;
176+
var id = connection.id;
177+
var s = sessionIndex[index];
178+
sessionIndex.splice(index, 1);
179+
clients.splice(index, 1);
180+
181+
var ind = sessions[s].indexOf(id);
182+
sessions[s].splice(ind, 1);
183+
if(session[s].length === 0){
184+
sessions.splice(s,1);
185+
}
186+
FILE.splice(s, 1);
187+
188+
}
189+
catch(e){}
190+
});
191+
192+
function addToSession(session, id){
193+
for(var i = 0; i < FILE.length; i++){
194+
if(FILE[i] === session){
195+
sessionIndex.push(i);
196+
sessions[i].push(id);
197+
return;
198+
}
199+
}
200+
addSession(session);
201+
addToSession(session, id);
202+
}
203+
function addSession(session){
204+
FILE.push(session);
205+
var index = FILE.indexOf(session);
206+
sessions[index] = [];
207+
}
208+
function removeSession(session){
209+
var index = FILE.indexOf(session);
210+
//
211+
FILE.splice(index,1);
212+
sessions.split(index,1);
213+
}
214+
/***********
215+
SSH
216+
************/
217+
var c;
218+
function startSSH(){
219+
c = new Connection();
220+
c.on('ready', function() {
221+
ssh_dir('/');
222+
});
223+
c.on('error', function(err) {
224+
//console.log('Connection :: error :: ' + err);
225+
});
226+
c.on('end', function() {
227+
//console.log('Connection :: end');
228+
});
229+
c.on('close', function(had_error) {
230+
//console.log('Connection :: close');
231+
});
232+
c.connect({
233+
host: ssh_host,
234+
port: ssh_port,
235+
username: ssh_login,
236+
password: ssh_pass
237+
});
238+
ssh_dir('/');
239+
}
240+
function stopSSH(){
241+
sftp.close(handle, function(err) {
242+
if (err) throw err;
243+
//console.log('SFTP :: Handle closed');
244+
sftp.end();
245+
});
246+
}
247+
function ssh_dir(path){
248+
c.sftp(function(err, sftp) {
249+
if (err){
250+
connection.send(JSON.stringify({type: "bad"}));
251+
throw err;
252+
}
253+
connection.send(JSON.stringify({type: "ok"}));
254+
sftp.on('end', function() {
255+
});
256+
sftp.opendir(path, function readdir(err, handle) {
257+
if (err) throw err;
258+
sftp.readdir(handle, function(err, list) {
259+
if (err) throw err;
260+
if (list === false) {
261+
return;
262+
}
263+
var array = [];
264+
for(var i = 0; i < list.length; i++){
265+
array.push(list[i].filename);
266+
}
267+
connection.send(JSON.stringify({type: "ssh", ssh: "folder", path: path, data: array}));
268+
readdir(undefined, handle);
269+
});
270+
});
271+
});
272+
}
273+
});

0 commit comments

Comments
 (0)