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 +4 -4
- data/bin/autoremote +10 -0
- data/lib/autoremote.rb +12 -6
- data/lib/autoremote/version.rb +1 -1
- metadata +2 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: a342da83ca1bb192892e144c1c806745f60f1ec7
         | 
| 4 | 
            +
              data.tar.gz: 0cda4445d977ff6c01143e5b19c8258ce36efbf6
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 069d130dcaaf0128597c61239e446c70ccda93d753f9b2fc03d1959773fe5375c54529ce3c4a438536a027c32bff741d43a8dbad808f8f9b7b6b8469c58c921c
         | 
| 7 | 
            +
              data.tar.gz: f8e8184c36845b564dfc2536d7e8df6f404e2be9fbf69a0e04ff1e90c2222342daae357a9b34ec57ef6a26fb7df8b7ee383ac91d0bb1146673d0fc83fecdccd0
         | 
    
        data/bin/autoremote
    CHANGED
    
    | @@ -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"
         | 
    
        data/lib/autoremote.rb
    CHANGED
    
    | @@ -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 | 
            -
                 | 
| 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 | 
            -
                     | 
| 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  | 
| 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 )
         | 
    
        data/lib/autoremote/version.rb
    CHANGED
    
    
    
        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 | 
            +
              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- | 
| 11 | 
            +
            date: 2015-01-19 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: bundler
         |