tcpfiletransfer 0.0.6 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e05f1f2443f8672ad35b72d470ebaee0c906cf686d9e94fb010757d1d62dcb42
4
- data.tar.gz: af5dcbb81340ddc9794f94c64401adccaba2fe0d2c39666016adb01d979c6644
3
+ metadata.gz: 8e0a0809c3a57508d72d20251e9add6bfc72b8817eefd27fca7b91b934b478d3
4
+ data.tar.gz: fabdf4f66b9f720e6ff0eaeeef9de12eb7866637155e7b2b6c4917ee962666dc
5
5
  SHA512:
6
- metadata.gz: adc96bd9d1709741b31603b6874f61028ccb92b032dc0b4351fc010c00974adeb0138d3ea0111c29c904225a711460f3673568ef156c93abed835ea846b4960b
7
- data.tar.gz: bb99ab26bca1a85e3d760cbcc63a47f2fe1d6f3c41d8763c2f603d0b79762968f361bb472e0f7fb48c4be6167793220644c233d14675cf273f9ee80240ba745f
6
+ metadata.gz: 26982483ee4507c81bdd955eee74a57a60db263febb8dedcd2ea4ec3484257f52008886c817028c5497ff8dfa774b47ef181950ca4424467765f961544a9c9e2
7
+ data.tar.gz: d998a476a2782b5c17ddb06e6f59890f2192b1be64063764c06c0ccc59e61b02447f8c71492e4eb5659d002a8fdba3eb21666166be6d2c2ca7deaf51b43101cb
data/bin/sendfile CHANGED
@@ -5,12 +5,18 @@ 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
19
+ break if ARGV[1]
14
20
  exit(1) if $?.exitstatus == 1
15
21
 
16
22
  if recipient == ""
@@ -24,8 +30,10 @@ loop do
24
30
  end
25
31
  end
26
32
 
33
+ recipient = IPSocket.getaddress(recipient)
34
+
27
35
  server = TCPSocket.new("127.0.0.1", 8021)
28
- server.puts "FTSUBMIT #{name} #{path}"
36
+ server.puts "FTSUBMIT #{name} #{path} #{recipient}"
29
37
  fileid = server.gets
30
38
 
31
39
  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
+
36
+ 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])}"
30
37
  `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])}"
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.1"
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.1
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