proxyconf 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1bbabd57e0c9dbb2fc5ac698cbab7c5f80f315c5
4
+ data.tar.gz: 773be511c5379b86ebde0b7c3a6a5f9221ae21be
5
+ SHA512:
6
+ metadata.gz: 74e1a7b1b35010307f2ac19e5417d90b5cca1a5d3b183707bb287ad8eab4f7c98c065c57531d6560cf56ea9ba6551549a0153d6380437b9b6674b00008754ca8
7
+ data.tar.gz: df0cf38a60a3c3068894ead0e437b4b056d21341ee8615fda324c0fd9ae2b1e24fd3d8e78fabe297cd9d4bac04eee870f68ebcfe1beade862dd26d767e8adbee
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ .DS_Store
7
+ Gemfile.lock
8
+ InstalledFiles
9
+ _yardoc
10
+ coverage
11
+ doc/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in proxyconf.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 daixque
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,33 @@
1
+ # proxyconf
2
+
3
+ proxyconf is a proxy switcher for terminal.
4
+
5
+ proxyconf currently supports Mac only.
6
+
7
+ ## Installation
8
+
9
+ First, install proxyconf via gem.
10
+
11
+ $ gem install proxyconf
12
+
13
+ Second, setup using proxyconf-setup command
14
+
15
+ $ proxyconf-setup
16
+
17
+ then it creates ~/.proxyconf directory and append setting for proxyconf into your ~/.bash_profile.
18
+
19
+ ## Usage
20
+
21
+ Simply type proxyconf in your terminal.
22
+
23
+ $ proxyconf
24
+
25
+ Then proxyconf exports environment variable 'http_proxy', 'https_proxy' and 'ftp_proxy' based on your system preference.
26
+
27
+ ## Contributing
28
+
29
+ 1. Fork it
30
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
31
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
32
+ 4. Push to the branch (`git push origin my-new-feature`)
33
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $LOAD_PATH.unshift(File.join File.dirname(__FILE__), "../lib")
4
+ require 'proxyconf'
5
+
6
+ ProxyConf::Cli.start(ARGV)
@@ -0,0 +1,45 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'fileutils'
4
+
5
+ HOME = File.expand_path('~')
6
+ PROXYCONF_HOME = "#{HOME}/.proxyconf"
7
+
8
+ # copy template files into ~/.proxyconf
9
+ def create_proxyconf_home
10
+ FileUtils.mkdir_p PROXYCONF_HOME
11
+ template_path = File.join(File.dirname(__FILE__), '../template')
12
+ src = [
13
+ File.join(template_path, "proxyconf"),
14
+ File.join(template_path, "proxies")
15
+ ]
16
+ FileUtils.cp_r(src, PROXYCONF_HOME)
17
+ end
18
+
19
+ def write_proxyconf_setting(file)
20
+ file.puts
21
+ file.puts '[[ -s "$HOME/.proxyconf/proxyconf" ]] && source "$HOME/.proxyconf/proxyconf"'
22
+ end
23
+
24
+ # add proxyconf setting into .bash_profile or .bashrc
25
+ def update_bashconfig
26
+ bash_profile = "#{HOME}/.bash_profile"
27
+ bash_rc = "#{HOME}/.bashrc"
28
+ filepath = if File.exist?(bash_profile)
29
+ bash_profile
30
+ elsif File.exist?(bash_profile)
31
+ bash_profile
32
+ end
33
+ if filepath
34
+ File.open(filepath, 'a') do |file|
35
+ write_proxyconf_setting file
36
+ end
37
+ end
38
+ end
39
+
40
+ def setup
41
+ create_proxyconf_home
42
+ update_bashconfig
43
+ end
44
+
45
+ setup
@@ -0,0 +1,30 @@
1
+ require 'thor'
2
+ require 'proxyconf/mac'
3
+
4
+ module ProxyConf
5
+ class Cli < Thor
6
+ class << self
7
+ attr_accessor :engine
8
+ end
9
+
10
+ desc 'export', 'print export proxy command for current network'
11
+ def export
12
+ engine.export
13
+ end
14
+
15
+ desc 'active_network', 'show active network service name'
16
+ def active_network
17
+ puts engine.active_network
18
+ end
19
+
20
+ desc 'test', 'test'
21
+ def proxy_info
22
+ puts engine.proxy_info
23
+ end
24
+
25
+ private
26
+ def engine
27
+ self.class.engine
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,60 @@
1
+ require 'yaml'
2
+
3
+ module ProxyConf
4
+ class Mac
5
+ private
6
+
7
+ def scutil_query(key)
8
+ send_data = <<-"EOF"
9
+ open
10
+ get #{key}
11
+ d.show
12
+ close
13
+ EOF
14
+ #return
15
+ IO.popen("scutil", "r+") do |io|
16
+ io.puts send_data
17
+ io.close_write
18
+ io.readlines
19
+ end
20
+ end
21
+
22
+ def pick_value(lines, key)
23
+ lines.find { |line| line =~ key }.strip.split(':').last.strip
24
+ end
25
+
26
+ def get_primary_service_guid
27
+ lines = scutil_query "State:/Network/Global/IPv4"
28
+ pick_value(lines, /PrimaryService/)
29
+ end
30
+
31
+ def get_service_name(guid)
32
+ lines = scutil_query "Setup:/Network/Service/#{guid}"
33
+ pick_value(lines, /UserDefinedName/)
34
+ end
35
+
36
+ public
37
+
38
+ def active_network
39
+ guid = get_primary_service_guid
40
+ get_service_name(guid)
41
+ end
42
+
43
+ def proxy_info
44
+ active_service_name = active_network
45
+ src = `networksetup -getwebproxy "#{active_service_name}"`
46
+ info = YAML.load(src)
47
+ end
48
+
49
+ def export
50
+ info = proxy_info
51
+ proxy = ""
52
+ if info['Enabled']
53
+ proxy = "#{info['Server']}:#{info['Port']}"
54
+ end
55
+ puts "export http_proxy=#{proxy}"
56
+ puts "export ftp_proxy=#{proxy}"
57
+ puts "export https_proxy=#{proxy}"
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,4 @@
1
+ module ProxyConf
2
+ module Sh
3
+ end
4
+ end
@@ -0,0 +1,3 @@
1
+ module ProxyConf
2
+ VERSION = "0.0.1"
3
+ end
data/lib/proxyconf.rb ADDED
@@ -0,0 +1,10 @@
1
+ require "proxyconf/version"
2
+ require "proxyconf/cli"
3
+
4
+ module ProxyConf
5
+ end
6
+
7
+ if true
8
+ require "proxyconf/mac"
9
+ ProxyConf::Cli.engine = ProxyConf::Mac.new
10
+ end
data/proxyconf.gemspec ADDED
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'proxyconf/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "proxyconf"
8
+ spec.version = ProxyConf::VERSION
9
+ spec.authors = ["daixque"]
10
+ spec.email = ["daixque@gmail.com"]
11
+ spec.description = %q{proxyconf configurates proxy setting of terminal.}
12
+ spec.summary = %q{proxy switcher for terminal}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_dependency "thor"
24
+ end
@@ -0,0 +1,3 @@
1
+ export http_proxy=
2
+ export ftp_proxy=
3
+ export https_proxy=
@@ -0,0 +1,45 @@
1
+ #!/usr/bin/env bash
2
+
3
+ PROXYCONF_CMD=proxyconf-core
4
+ PROXYCONF_HOME=~/.proxyconf
5
+
6
+ __proxyconf_usage ()
7
+ {
8
+ cat <<EOF
9
+ usage:
10
+ $ proxyconf [command]
11
+
12
+ if command is not given, 'update' command will used.
13
+
14
+ commands:
15
+ update
16
+ update proxy setting for active network service.
17
+ help
18
+ show usage
19
+ EOF
20
+ }
21
+
22
+ __proxyconf_use ()
23
+ {
24
+ . $PROXYCONF_HOME/proxies/$1
25
+ echo "set proxy:" $http_proxy
26
+
27
+ }
28
+
29
+ __proxyconf_update ()
30
+ {
31
+ $PROXYCONF_CMD export > $PROXYCONF_HOME/proxies/current
32
+ __proxyconf_use current
33
+ }
34
+
35
+ proxyconf ()
36
+ {
37
+ case $1 in
38
+ "") __proxyconf_update ;;
39
+ "update") __proxyconf_update ;;
40
+ "help") __proxyconf_usage ;;
41
+ * )
42
+ echo "unknown command:" $1
43
+ echo "type 'proxyconf help' to show usage";;
44
+ esac
45
+ }
metadata ADDED
@@ -0,0 +1,103 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: proxyconf
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - daixque
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-11-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: thor
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: proxyconf configurates proxy setting of terminal.
56
+ email:
57
+ - daixque@gmail.com
58
+ executables:
59
+ - proxyconf-core
60
+ - proxyconf-setup
61
+ extensions: []
62
+ extra_rdoc_files: []
63
+ files:
64
+ - .gitignore
65
+ - Gemfile
66
+ - LICENSE.txt
67
+ - README.md
68
+ - Rakefile
69
+ - bin/proxyconf-core
70
+ - bin/proxyconf-setup
71
+ - lib/proxyconf.rb
72
+ - lib/proxyconf/cli.rb
73
+ - lib/proxyconf/mac.rb
74
+ - lib/proxyconf/sh.rb
75
+ - lib/proxyconf/version.rb
76
+ - proxyconf.gemspec
77
+ - template/proxies/current
78
+ - template/proxyconf
79
+ homepage: ''
80
+ licenses:
81
+ - MIT
82
+ metadata: {}
83
+ post_install_message:
84
+ rdoc_options: []
85
+ require_paths:
86
+ - lib
87
+ required_ruby_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - '>='
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ required_rubygems_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ requirements: []
98
+ rubyforge_project:
99
+ rubygems_version: 2.0.3
100
+ signing_key:
101
+ specification_version: 4
102
+ summary: proxy switcher for terminal
103
+ test_files: []