-
Notifications
You must be signed in to change notification settings - Fork 77
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Filebrowser permissions #205
Merged
Merged
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
b253529
Using run_as_user to get permissions to files
javo 0f37172
89f9221
Modify retry parameters
javo f865563
Fix path and files name in windows
javo 4ccc9c3
Upload error response modified
javo d76065d
Reports url issue fixed
javo a0d82c0
Fix winattr on ubuntu
javo 0268cfe
path and name arguments fix
javo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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,130 @@ | ||
#!/usr/bin/env node | ||
|
||
var fs = require('fs'), | ||
path = require('path'), | ||
mime = require('mime'), | ||
common = require('./../../common'), | ||
needle = require('needle'); | ||
|
||
var config = common.config, | ||
protocol = config._values['control-panel'].protocol, | ||
host = config._values['control-panel'].host, | ||
url = protocol + '://' + host; | ||
|
||
var UPLOAD_SERVER = url + '/upload/upload', | ||
RESUMABLE_HEADER = 'X-Prey-Upload-Resumable', | ||
OPEN_TIMEOUT = 180000, | ||
READ_TIMEOUT = 2000; | ||
|
||
var PATH = 2, | ||
USER = 3, | ||
NAME = 4, | ||
SIZE = 5, | ||
FILE_ID = 6, | ||
RESUME = 7, | ||
PORT = 8; | ||
|
||
function main() { | ||
var argv = process.argv; | ||
var options = { | ||
path: argv[PATH], | ||
user: argv[USER], | ||
name: argv[NAME], | ||
size: argv[SIZE], | ||
file_id: argv[FILE_ID], | ||
resumable : argv[RESUME], | ||
port: argv[PORT] | ||
} | ||
Main(options, function(err) { | ||
if (err) { | ||
console.error(err); | ||
return; | ||
} | ||
}); | ||
} | ||
|
||
function Main(options, cb) { | ||
var file_path = options.path, | ||
file_id = options.file_id, | ||
file_size = parseInt(options.size), | ||
file_name = options.name, | ||
user = options.user; | ||
|
||
console.log("Uploading file: ", file_path, file_id); | ||
|
||
var file = { | ||
total: 0, | ||
path: file_path, | ||
user: user, | ||
id: file_id, | ||
size: file_size, | ||
resumable: options.resumable | ||
} | ||
retrieve_file(file, cb); | ||
} | ||
|
||
function retrieve_file(file, cb) { | ||
if (file.resumable == 'true') { | ||
console.log("Resumable file:", file.id); | ||
var url = UPLOAD_SERVER + '?uploadID=' + file.id; | ||
// Make a call to get the last byte processed by the upload server | ||
// in order to resume the upload from that position. | ||
needle.request('get', url, null, function(err, res) { | ||
if (err) { | ||
console.log(err); | ||
cb(err); | ||
return; | ||
} | ||
var data = JSON.parse(res.body); | ||
|
||
file.total = data.Total; | ||
get_file(file, cb); | ||
}) | ||
return; | ||
} | ||
get_file(file, cb); | ||
} | ||
|
||
function get_file(file, cb) { | ||
var buffsize = (file.size == 0) ? 1 : (file.size - file.total); | ||
var buf = new Buffer(buffsize); | ||
var fd = fs.openSync(file.path, "r"); | ||
|
||
fs.read(fd, buf, 0, file.size - file.total, file.total, function(err, read, buf) { | ||
if (err) { | ||
cb(err); | ||
return; | ||
} | ||
upload_file(file, buf, cb); | ||
}) | ||
} | ||
|
||
function upload_file(file, buf, cb) { | ||
var options = { | ||
open_timeout: OPEN_TIMEOUT, | ||
read_timeout: READ_TIMEOUT | ||
} | ||
|
||
if (file.total > 0) { | ||
RESUMABLE_HEADER = file.total; | ||
} | ||
var url = UPLOAD_SERVER + '?uploadID=' + file.id; | ||
|
||
needle.post(url, buf, options, function(err, res) { | ||
if (err) { | ||
console.log(err); | ||
cb(err); | ||
return; | ||
} | ||
var out = res.statusCode; | ||
if (out !== 200 && out !== 201) { | ||
var err = new Error('There was an error communicating with the server'); | ||
cb(err); | ||
return; | ||
} | ||
console.log("File succesfuly uploaded:", file.id); | ||
cb(null); // delete files | ||
}) | ||
} | ||
|
||
main(); |
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
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you simplify this?
argsv
for a non windows os could work withpath.resolve
, for instance?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've tried that before and it didn't work