tcpfiletransfer 0.0.6 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e05f1f2443f8672ad35b72d470ebaee0c906cf686d9e94fb010757d1d62dcb42
4
- data.tar.gz: af5dcbb81340ddc9794f94c64401adccaba2fe0d2c39666016adb01d979c6644
3
+ metadata.gz: c6c7f4fef199c5858b707c3ff5cc74365fcf8c577a43ee6beed17842b315680a
4
+ data.tar.gz: 9251b887e474654b553bceada578c06308765f5dee659e8d51785fe659c7c200
5
5
  SHA512:
6
- metadata.gz: adc96bd9d1709741b31603b6874f61028ccb92b032dc0b4351fc010c00974adeb0138d3ea0111c29c904225a711460f3673568ef156c93abed835ea846b4960b
7
- data.tar.gz: bb99ab26bca1a85e3d760cbcc63a47f2fe1d6f3c41d8763c2f603d0b79762968f361bb472e0f7fb48c4be6167793220644c233d14675cf273f9ee80240ba745f
6
+ metadata.gz: 99599794d083185fe86953e77497ecb22d138ed763032b5d15a2de3b5c7cbe2ed68e1e02ed0c8458b7e060d4cc3cad2b902a1882c81dbfc051bd77b85e0ab6f5
7
+ data.tar.gz: 16e268c86d36233496e1e3ebd933eb03c7d2829a302ef40ccdf8318f3995c1a43bac31837919b2407d7e65543c1f4b53e92acd6beb9587d5221d46223c3870bb
data/bin/sendfile CHANGED
@@ -5,9 +5,14 @@ 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
18
  recipient = ARGV[1] || `zenity --text="Recipient\\n(Leave blank to search for available recipients)" --entry --title='Send File'`.chomp
@@ -24,8 +29,10 @@ loop do
24
29
  end
25
30
  end
26
31
 
32
+ recipient = IPSocket.getaddress(recipient)
33
+
27
34
  server = TCPSocket.new("127.0.0.1", 8021)
28
- server.puts "FTSUBMIT #{name} #{path}"
35
+ server.puts "FTSUBMIT #{name} #{path} #{recipient}"
29
36
  fileid = server.gets
30
37
 
31
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
@@ -27,8 +27,14 @@ module FileTransfer
27
27
  return
28
28
  end
29
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
+
30
36
  `zenity --info --title="Transfer Accepted" --text="Your transfer to #{remote_hostname} has been accepted." --no-wrap`
31
- client.puts "HTTP/1.0 200\r\nContent-Type: application/octet-stream\r\nContent-Disposition: attachment; filename=\"#{file[:name]}\"\r\n\r\n#{File.read(file[:path])}"
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])}"
32
38
  $active_transfers.delete(path)
33
39
  client.close
34
40
  end
@@ -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
- FTserver.handle_file_submission(initdata, client)
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
@@ -5,7 +5,7 @@ module FileTransfer
5
5
  @@files = ['server.rb', 'notifier.rb', 'httpserver.rb', 'ftserver.rb']
6
6
 
7
7
  def self.version
8
- "0.0.6"
8
+ "0.1.0"
9
9
  end
10
10
 
11
11
  def self.file_paths(relative:false)
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.6
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-03-27 00:00:00.000000000 Z
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