autoremote 0.0.4 → 0.0.5

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
  SHA1:
3
- metadata.gz: 65f03c0bc3a9456d9a59737a15346bafffbdd567
4
- data.tar.gz: cb47099496f1c2bb2990c9858061a2fe3a44fcdc
3
+ metadata.gz: a342da83ca1bb192892e144c1c806745f60f1ec7
4
+ data.tar.gz: 0cda4445d977ff6c01143e5b19c8258ce36efbf6
5
5
  SHA512:
6
- metadata.gz: 6763d9e3e898fae41f26da4687f63d95c053fa6f0a3df8b691b25927345dce99918592762b0210ef4a298aff63c5ccc2af72689edaf043d37d0eba694f3fe8a0
7
- data.tar.gz: be3d51e59593f49c8926a61418a89e9f4c48d5c121934524a96652c828b66d907ab2963801cec46c8b1baeb18e46b09322d19d35eca33797c6ca6a83734067ee
6
+ metadata.gz: 069d130dcaaf0128597c61239e446c70ccda93d753f9b2fc03d1959773fe5375c54529ce3c4a438536a027c32bff741d43a8dbad808f8f9b7b6b8469c58c921c
7
+ data.tar.gz: f8e8184c36845b564dfc2536d7e8df6f404e2be9fbf69a0e04ff1e90c2222342daae357a9b34ec57ef6a26fb7df8b7ee383ac91d0bb1146673d0fc83fecdccd0
@@ -1,5 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
  require 'autoremote'
3
+ require 'rbconfig'
3
4
 
4
5
  def to_bool( string )
5
6
  return false if string.class == NilClass || string.empty? || string.downcase =~ (/^(false|f|no|n|nej|0)$/i)
@@ -61,6 +62,15 @@ elsif arg0 == "message" && ARGV[1] && ARGV[2]
61
62
  end
62
63
 
63
64
  elsif arg0 == "register" && ARGV[1] && ARGV[2]
65
+ if RbConfig::CONFIG['host_os'] =~ /mswin|msys|mingw|cygwin|bccwin|wince|emc/i
66
+ puts "Are you sure you want to register a windows computer?"
67
+ print "You will need an SSH server on the computer. (y/n)"
68
+ if ! to_bool($stdin.gets.chomp)
69
+ puts "Registering interrupted"
70
+ exit
71
+ end
72
+ end
73
+
64
74
  begin
65
75
  AutoRemote::registerOnDevice( ARGV[1], ARGV[2] )
66
76
  puts "Device registered successfully"
@@ -3,6 +3,7 @@ require "autoremote/exceptions"
3
3
  require 'sqlite3'
4
4
  require 'active_record'
5
5
  require 'net/http'
6
+ require 'socket'
6
7
 
7
8
  ## Establish the database connection
8
9
  ActiveRecord::Base.establish_connection(
@@ -23,7 +24,7 @@ ActiveRecord::Schema.define do
23
24
  end
24
25
 
25
26
  module AutoRemote
26
- REGCMD = "curl \"http://autoremotejoaomgcd.appspot.com/registerpc?key=%YOUR_KEY%&name=%DISPLAY_NAME%&id=%UNIQUE_ID%&type=linux&publicip=%PUBLIC_HOST%&localip=$(sudo ifconfig eth0 |grep \"inet addr\" |awk '{print $2}' |awk -F: '{print $2}')\""
27
+ REGURL = "http://autoremotejoaomgcd.appspot.com/registerpc?key=%YOUR_KEY%&name=%DISPLAY_NAME%&id=%UNIQUE_ID%&type=linux&publicip=%PUBLIC_HOST%&localip=%IP_ADDRESS%"
27
28
  MSGURL = "http://autoremotejoaomgcd.appspot.com/sendmessage?key=%YOUR_KEY%&message=%MESSAGE%&sender=%SENDER_ID%"
28
29
  VALIDATIONURL = "http://autoremotejoaomgcd.appspot.com/sendmessage?key=%YOUR_KEY%"
29
30
 
@@ -104,10 +105,10 @@ module AutoRemote
104
105
  # @param device [Device, String] A device object or the name of the device
105
106
  # @param remotehost [String] The public hostname or ip-address
106
107
  # @raise [AutoRemote::DeviceNotFound] if the device didn't exits
108
+ # @raise [AutoRemote::UnsupportedAction] if running from windows
107
109
  # @raise [TypeError] if message isn't a string or less than 5 characters
108
110
  # @return [void]
109
111
  def AutoRemote::registerOnDevice( device, remotehost )
110
-
111
112
  if ! device.kind_of?( Device ) && ! ( device = Device.find_by_name( device ) )
112
113
  raise self::DeviceNotFound
113
114
  elsif ! remotehost.kind_of?( String ) || remotehost.length < 5
@@ -115,14 +116,13 @@ module AutoRemote
115
116
  end
116
117
 
117
118
  hostname = `hostname`.strip
119
+ ipAddress = AutoRemote::getIpAddress.ip_address
118
120
 
119
121
  ## Perform the registration
120
- cmd = REGCMD.sub( /%YOUR_KEY%/, device.key ).sub(/%DISPLAY_NAME%/, hostname ).sub(/%UNIQUE_ID%/, hostname ).sub(/%PUBLIC_HOST%/, remotehost )
121
- result = system(cmd)
122
- puts
122
+ result = self.urlRequest( REGURL.sub( /%YOUR_KEY%/, device.key ).sub(/%DISPLAY_NAME%/, hostname ).sub(/%UNIQUE_ID%/, hostname ).sub(/%PUBLIC_HOST%/, remotehost ).sub(/%IP_ADDRESS%/, ipAddress ) )
123
123
 
124
124
  ## Check result
125
- if ! result
125
+ if result.body != "OK"
126
126
  raise self::AutoRemoteException, "Something went wrong when registering on the device"
127
127
  end
128
128
  end
@@ -136,6 +136,12 @@ module AutoRemote
136
136
  end
137
137
 
138
138
  private
139
+ # Gets the ip address of the system
140
+ # @return [String]
141
+ def AutoRemote::getIpAddress
142
+ return Socket.ip_address_list.detect{|ipInfo| ipInfo.ipv4_private?}
143
+ end
144
+
139
145
  # Performs a http request
140
146
  # @param url [String]
141
147
  def AutoRemote::urlRequest( url )
@@ -1,3 +1,3 @@
1
1
  module AutoRemote
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: autoremote
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - AltonV
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-18 00:00:00.000000000 Z
11
+ date: 2015-01-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler