-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
philipp.voelkner
committed
Mar 8, 2017
0 parents
commit c25b6d9
Showing
20 changed files
with
1,182 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.DS_Store | ||
npm-debug.log | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
## 0.1.0 - First Release | ||
* Every feature added | ||
* Every bug fixed |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
Copyright (c) 2017 | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining | ||
a copy of this software and associated documentation files (the | ||
"Software"), to deal in the Software without restriction, including | ||
without limitation the rights to use, copy, modify, merge, publish, | ||
distribute, sublicense, and/or sell copies of the Software, and to | ||
permit persons to whom the Software is furnished to do so, subject to | ||
the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be | ||
included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | ||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | ||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | ||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# ftp-remote-edit package | ||
|
||
Edit files on your ftp server without a workspace. | ||
You do not need to download the whole project files from the server. | ||
Just connect and edit the files. On save the file is written to the server. | ||
|
||
![A screenshot of your package](https://f.cloud.github.com/assets/69169/2290250/c35d867a-a017-11e3-86be-cd7c5bf3ff9b.gif) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,229 @@ | ||
'use babel'; | ||
|
||
// import { View } from 'atom'; | ||
// import { CompositeDisposable } from 'atom'; | ||
|
||
import FileView from './file-view.js'; | ||
import ListView from './list-view.js'; | ||
import DirectoryView from './directory-view.js'; | ||
import Node from './Node.js'; | ||
import { File } from 'atom'; | ||
|
||
var ftpClient = require('ftp'); | ||
var FileSystem = require('fs'); | ||
const tempDirectory = require('os').tmpdir(); | ||
|
||
|
||
export default class Ftp { | ||
|
||
constructor(connection) { | ||
// Create root element | ||
this.connection = connection; | ||
|
||
} | ||
|
||
|
||
// Returns an object that can be retrieved when package is activated | ||
serialize() {} | ||
|
||
// Tear down any state and detach | ||
destroy() { | ||
this.element.remove(); | ||
} | ||
|
||
|
||
connectWithFtpServer (nodeJsFtpClient) { | ||
|
||
try { | ||
let ftpConfig = this.connection; | ||
nodeJsFtpClient.connect(ftpConfig); | ||
} catch (error) { | ||
console.log(error.message); | ||
} | ||
} | ||
|
||
isFileOnServer(path, callback) { | ||
|
||
var c = new ftpClient(); | ||
|
||
let directory = path.split('/'); | ||
directory.pop(); | ||
directory = directory.join('/'); | ||
|
||
c.on('ready', function() { | ||
c.list(directory, function(err, list) { | ||
|
||
if (err) { | ||
atom.showErrorMessage(err.message); | ||
c.end(); | ||
} else { | ||
c.end(); | ||
|
||
let file = list.find(function(item){ | ||
return item.name == path.split('/').slice(-1)[0]; | ||
}); | ||
|
||
callback(file); | ||
} | ||
|
||
}); | ||
}); | ||
|
||
this.connectWithFtpServer(c); | ||
|
||
} | ||
|
||
writeTextToFile (pathOnServer, pathOnDisk) { | ||
|
||
let promise = new Promise((resolve, reject) => { | ||
|
||
var c = new ftpClient(); | ||
|
||
c.on('ready', () => { | ||
c.get(pathOnServer, (err, stream) => { | ||
if(err) { | ||
atom.showErrorMessage(err.message); | ||
} else { | ||
stream.once('close', () => {c.end(); }); | ||
stream.once('finish', () => { resolve(true); }); | ||
stream.pipe(FileSystem.createWriteStream(pathOnDisk)); | ||
} | ||
}); | ||
}); | ||
|
||
this.connectWithFtpServer(c); | ||
}); | ||
|
||
return promise; | ||
} | ||
|
||
saveFileToServer (content, serverPath) { | ||
|
||
var c = new ftpClient(); | ||
|
||
c.on('ready', function() { | ||
c.put(content, serverPath, function(err, list) { | ||
|
||
if (err) { | ||
atom.showErrorMessage(err.message); | ||
} else { | ||
console.log('erfolgreich gespeichert'); | ||
} | ||
c.end(); | ||
}); | ||
}); | ||
|
||
this.connectWithFtpServer(c); | ||
|
||
} | ||
|
||
createDirectoriesAndFiles(ftpPath, list) { | ||
|
||
let promise = new Promise((resolve, reject) => { | ||
|
||
try { | ||
let ftpPanel = null; | ||
|
||
atom.workspace.getLeftPanels().forEach((panel) => { | ||
if(panel.getItem() instanceof Node) { | ||
ftpPanel = panel; | ||
return false; | ||
} | ||
}); | ||
|
||
let directories = list.filter((item) => {return item.type === 'd' && item.name !== '.' && item.name !== '..'; }); | ||
let files = list.filter((item) => { return item.type === '-'; }); | ||
|
||
|
||
let ul = new ListView(); | ||
if(ftpPath === "") { | ||
ftpPanel.getItem().getChildNodes()[0].append(ul); | ||
} else { | ||
function setDirectory(nodes) { | ||
let result = null; | ||
nodes.forEach((node) => { | ||
|
||
if(node.getPathOnServer() + '/' == ftpPath) { | ||
node.append(ul); | ||
return true; | ||
} | ||
|
||
if(node.getChildNodes().length > 0 ) { | ||
setDirectory(node.getChildNodes()); | ||
} | ||
}); | ||
|
||
} | ||
setDirectory(ftpPanel.getItem().getChildNodes()); | ||
} | ||
|
||
directories.forEach(function(element) { | ||
|
||
let pathOnFileSystem = ftpPath + element.name; | ||
pathOnFileSystem = pathOnFileSystem.replace('//', '/'); | ||
|
||
let li = new DirectoryView({name: element.name, pathOnServer: pathOnFileSystem}); | ||
ul.append(li); | ||
|
||
}, this); | ||
|
||
files.forEach(function(element) { | ||
|
||
let pathOnFileSystem = ftpPath + element.name; | ||
pathOnFileSystem = pathOnFileSystem.replace('//', '/'); | ||
|
||
let li = new FileView({name: element.name, pathOnServer: pathOnFileSystem}); | ||
ul.append(li); | ||
|
||
}, this); | ||
|
||
resolve(true); | ||
} catch (e) { | ||
reject(e); | ||
} | ||
|
||
}); | ||
|
||
return promise; | ||
|
||
} | ||
|
||
loadFtpTree(path = "") { | ||
|
||
let ftpPath = path + "/"; | ||
if(path == "" || path == null) ftpPath = ""; | ||
|
||
return this.loadDirectory(path).then((list) => { | ||
return this.createDirectoriesAndFiles(ftpPath, list); | ||
}); | ||
} | ||
|
||
loadDirectory (path) { | ||
|
||
let promise = new Promise((resolve, reject) => { | ||
|
||
var c = new ftpClient(); | ||
|
||
c.on('ready', function() { | ||
c.list(path, function(err, list) { | ||
if (err) { | ||
console.log(err); | ||
c.end(); | ||
reject(err); | ||
} else { | ||
c.end(); | ||
resolve(list); | ||
} | ||
|
||
}); | ||
}); | ||
|
||
this.connectWithFtpServer(c); | ||
|
||
}); | ||
|
||
return promise; | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
'use babel'; | ||
|
||
// import { View } from 'atom'; | ||
// import { CompositeDisposable } from 'atom'; | ||
|
||
export default class Node { | ||
|
||
constructor() { | ||
// Create root element | ||
this.childNodes = []; | ||
this.element = document.createElement('div'); | ||
} | ||
|
||
setConnection (connection) { | ||
this.connection = connection; | ||
} | ||
|
||
getConnection () { | ||
return this.connection; | ||
} | ||
|
||
append(element) { | ||
element.setConnection(this.connection); | ||
this.childNodes.push(element); | ||
this.element.appendChild(element.getElement()); | ||
} | ||
|
||
getPathOnServer() { | ||
return this.element.getAttribute('pathOnServer'); | ||
} | ||
|
||
getChildNodes() { | ||
return this.childNodes; | ||
} | ||
|
||
// Returns an object that can be retrieved when package is activated | ||
serialize() {} | ||
|
||
// Tear down any state and detach | ||
destroy() { | ||
this.element.remove(); | ||
} | ||
|
||
removeChildren() { | ||
this.childNodes = []; | ||
} | ||
|
||
getElement() { | ||
return this.element; | ||
} | ||
|
||
createLoader() { | ||
let loader = document.createElement('i'); | ||
loader.classList.add('spin'); | ||
loader.classList.add('loader'); | ||
return loader; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
'use babel'; | ||
|
||
// import { View } from 'atom'; | ||
// import { CompositeDisposable } from 'atom'; | ||
|
||
|
||
var crypto = require('crypto'); | ||
|
||
export default class Secure { | ||
|
||
constructor() { | ||
// Create root element | ||
} | ||
|
||
decrypt (password, text) { | ||
var decipher = crypto.createDecipher('aes-256-ctr', password); | ||
var dec = decipher.update(text, 'hex', 'utf8'); | ||
return dec; | ||
} | ||
|
||
encrypt (password, text) { | ||
var cipher = crypto.createCipher('aes-256-ctr', password); | ||
var crypted = cipher.update(text, 'utf8', 'hex'); | ||
crypted += cipher.final('hex'); | ||
return crypted; | ||
} | ||
|
||
checkPassword (password) { | ||
let passwordHash = atom.config.get('ftp-remote-edit.password'); | ||
|
||
if(this.decrypt(password, passwordHash) !== password) { | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
|
||
} |
Oops, something went wrong.