tcpfiletransfer 0.0.5 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/bin/sendfile +15 -6
- data/lib/filetransfer/ftserver.rb +2 -1
- data/lib/filetransfer/httpserver.rb +12 -1
- data/lib/filetransfer/notifier.rb +1 -1
- data/lib/filetransfer/server.rb +6 -1
- data/lib/filetransfer.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c6c7f4fef199c5858b707c3ff5cc74365fcf8c577a43ee6beed17842b315680a
|
4
|
+
data.tar.gz: 9251b887e474654b553bceada578c06308765f5dee659e8d51785fe659c7c200
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 99599794d083185fe86953e77497ecb22d138ed763032b5d15a2de3b5c7cbe2ed68e1e02ed0c8458b7e060d4cc3cad2b902a1882c81dbfc051bd77b85e0ab6f5
|
7
|
+
data.tar.gz: 16e268c86d36233496e1e3ebd933eb03c7d2829a302ef40ccdf8318f3995c1a43bac31837919b2407d7e65543c1f4b53e92acd6beb9587d5221d46223c3870bb
|
data/bin/sendfile
CHANGED
@@ -5,25 +5,34 @@ require "socket"
|
|
5
5
|
originalpath = ARGV[0] || `zenity --file-selection --title='Send File'`.chomp
|
6
6
|
exit(1) if (!ARGV[0] && $?.exitstatus == 1)
|
7
7
|
|
8
|
-
path = originalpath.gsub(" ", "`")
|
8
|
+
path = File.expand_path(originalpath).gsub(" ", "`")
|
9
9
|
name = originalpath.split("/").last.gsub(" ", "_")
|
10
10
|
|
11
|
+
if File.directory?(path)
|
12
|
+
`zenity --error --text="Error: #{path} is a folder." --no-wrap --title="Send File"`
|
13
|
+
exit(1)
|
14
|
+
end
|
15
|
+
|
11
16
|
recipient = ""
|
12
17
|
loop do
|
13
|
-
recipient = ARGV[1] || `zenity --text="Recipient\\n(Leave blank to
|
18
|
+
recipient = ARGV[1] || `zenity --text="Recipient\\n(Leave blank to search for available recipients)" --entry --title='Send File'`.chomp
|
14
19
|
exit(1) if $?.exitstatus == 1
|
15
20
|
|
16
21
|
if recipient == ""
|
17
|
-
`
|
18
|
-
hosts =
|
19
|
-
`zenity --
|
22
|
+
`nmap -Pn -p8021 --open 192.168.0.0/24 | grep -oP '([\\w-]+\\s\\(((25[0-5]|(2[0-4]|1\\d|[1-9]|)\\d)\\.?\\b){4}\\)|((25[0-5]|(2[0-4]|1\\d|[1-9]|)\\d)\\.?\\b){4})' | tee ~/.tmphosts | zenity --progress --pulsate --no-cancel --text="Searcing for available devices" --title="Searching..." --auto-close`
|
23
|
+
hosts = File.read("#{Dir.home}/.tmphosts")
|
24
|
+
recipient = `zenity --list --title="Avalable recipients" --text="Choose a device" --column="Available Recipients" #{hosts.split("\n").map{|h|"'#{h}'"}.join(" ")}`.match(/((25[0-5]|(2[0-4]|1\d|[1-9]|)\d)\.?\b){4}/).to_s
|
25
|
+
break if recipient != ""
|
26
|
+
exit(1) if $?.exitstatus == 1
|
20
27
|
else
|
21
28
|
break
|
22
29
|
end
|
23
30
|
end
|
24
31
|
|
32
|
+
recipient = IPSocket.getaddress(recipient)
|
33
|
+
|
25
34
|
server = TCPSocket.new("127.0.0.1", 8021)
|
26
|
-
server.puts "FTSUBMIT #{name} #{path}"
|
35
|
+
server.puts "FTSUBMIT #{name} #{path} #{recipient}"
|
27
36
|
fileid = server.gets
|
28
37
|
|
29
38
|
file_size = '%.2f' % (File.size(originalpath).to_f / 2**20)
|
@@ -13,9 +13,10 @@ module FileTransfer
|
|
13
13
|
def self.handle_file_submission(initdata, client)
|
14
14
|
filename = initdata[1]
|
15
15
|
filepath = initdata[2].gsub("`", " ")
|
16
|
+
dest_ip = initdata[3]
|
16
17
|
|
17
18
|
fileid = self.genfileid(6)
|
18
|
-
$active_transfers[?/ + fileid] = {name: filename, path: filepath}
|
19
|
+
$active_transfers[?/ + fileid] = {name: filename, path: filepath, dest_ip: dest_ip}
|
19
20
|
client.puts fileid
|
20
21
|
client.close
|
21
22
|
end
|
@@ -4,7 +4,10 @@ module FileTransfer
|
|
4
4
|
path = initdata[1].split("/")
|
5
5
|
decline = (path[2] == "decline")
|
6
6
|
path = ?/ + path[1]
|
7
|
+
sock_domain, remote_port, remote_hostname, remote_ip = client.peeraddr
|
8
|
+
|
7
9
|
if decline
|
10
|
+
`zenity --error --title="Transfer Declined" --text="Your transfer to #{remote_hostname} has been declined." --no-wrap`
|
8
11
|
$active_transfers.delete(path)
|
9
12
|
client.puts "HTTP/1.0 200\r\nContent-Type: text/plain\r\n\r\nTransfer declined"
|
10
13
|
client.close
|
@@ -23,7 +26,15 @@ module FileTransfer
|
|
23
26
|
client.close
|
24
27
|
return
|
25
28
|
end
|
26
|
-
|
29
|
+
|
30
|
+
if client.peeraddr[2] != file[:dest_ip]
|
31
|
+
client.puts "HTTP/1.0 403\r\nContent-Type: text/plain\r\n\r\nRequest from forbidden IP."
|
32
|
+
client.close
|
33
|
+
return
|
34
|
+
end
|
35
|
+
|
36
|
+
`zenity --info --title="Transfer Accepted" --text="Your transfer to #{remote_hostname} has been accepted." --no-wrap`
|
37
|
+
client.puts "HTTP/1.0 200\r\nContent-Length: #{File.size file[:path]}\r\nContent-Type: application/octet-stream\r\nContent-Disposition: attachment; filename=\"#{file[:name]}\"\r\n\r\n#{IO.binread(file[:path])}"
|
27
38
|
$active_transfers.delete(path)
|
28
39
|
client.close
|
29
40
|
end
|
@@ -9,7 +9,7 @@ module FileTransfer
|
|
9
9
|
|
10
10
|
x=system("zenity --question --icon-name=document-save-symbolic.symbolic --no-wrap --text=\"#{notification_body}\" --title='#{notification_title}'")
|
11
11
|
if x
|
12
|
-
file_location = `zenity --file-selection --save --filename=#{filename.chomp}`.chomp
|
12
|
+
file_location = `zenity --title="Save file" --file-selection --save --filename=#{filename.chomp}`.chomp
|
13
13
|
if file_location == ""
|
14
14
|
f=open(accept_link + "/decline")
|
15
15
|
f.read
|
data/lib/filetransfer/server.rb
CHANGED
@@ -15,7 +15,12 @@ module FileTransfer
|
|
15
15
|
elsif initdata[0] == "FTSEND"
|
16
16
|
FTserver.handle_client(initdata, client)
|
17
17
|
elsif initdata[0] == "FTSUBMIT"
|
18
|
-
|
18
|
+
if client.peeraddr[2] == "127.0.0.1"
|
19
|
+
FTserver.handle_file_submission(initdata, client)
|
20
|
+
else
|
21
|
+
client.puts "ERROR FILE_SUBMIT_NOTLOCAL"
|
22
|
+
client.close
|
23
|
+
end
|
19
24
|
else
|
20
25
|
client.close
|
21
26
|
end
|
data/lib/filetransfer.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tcpfiletransfer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matthias Lee
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-04-10 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: An easy way to transfer files over TCP between linux computers
|
14
14
|
email: matthias@matthiasclee.com
|