posty_cli 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'http://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in posty_cli.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,22 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ posty_cli (1.0.0)
5
+ json
6
+ rest-client
7
+ thor
8
+
9
+ GEM
10
+ remote: http://rubygems.org/
11
+ specs:
12
+ json (1.8.0)
13
+ mime-types (1.23)
14
+ rest-client (1.6.7)
15
+ mime-types (>= 1.16)
16
+ thor (0.18.1)
17
+
18
+ PLATFORMS
19
+ ruby
20
+
21
+ DEPENDENCIES
22
+ posty_cli!
data/LICENSE.txt ADDED
@@ -0,0 +1,77 @@
1
+ All rights are at (C) posty-soft.de 2013
2
+
3
+ Developers:
4
+
5
+ Florian Schmidhuber
6
+ eMail: fschmidhuber@posty-soft.de
7
+
8
+ Thomas Berendt
9
+ eMail: tberendt@posty-soft.de
10
+
11
+ Benjamin Heller
12
+ eMail: bheller@posty-soft.de
13
+
14
+ Lukas Weis
15
+ eMail: lweis@posty-soft.de
16
+
17
+
18
+
19
+ Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed.
20
+
21
+ This version of the GNU Lesser General Public License incorporates the terms and conditions of version 3 of the GNU General Public License, supplemented by the additional permissions listed below.
22
+ 0. Additional Definitions.
23
+
24
+ As used herein, “this License” refers to version 3 of the GNU Lesser General Public License, and the “GNU GPL” refers to version 3 of the GNU General Public License.
25
+
26
+ “The Library” refers to a covered work governed by this License, other than an Application or a Combined Work as defined below.
27
+
28
+ An “Application” is any work that makes use of an interface provided by the Library, but which is not otherwise based on the Library. Defining a subclass of a class defined by the Library is deemed a mode of using an interface provided by the Library.
29
+
30
+ A “Combined Work” is a work produced by combining or linking an Application with the Library. The particular version of the Library with which the Combined Work was made is also called the “Linked Version”.
31
+
32
+ The “Minimal Corresponding Source” for a Combined Work means the Corresponding Source for the Combined Work, excluding any source code for portions of the Combined Work that, considered in isolation, are based on the Application, and not on the Linked Version.
33
+
34
+ The “Corresponding Application Code” for a Combined Work means the object code and/or source code for the Application, including any data and utility programs needed for reproducing the Combined Work from the Application, but excluding the System Libraries of the Combined Work.
35
+ 1. Exception to Section 3 of the GNU GPL.
36
+
37
+ You may convey a covered work under sections 3 and 4 of this License without being bound by section 3 of the GNU GPL.
38
+ 2. Conveying Modified Versions.
39
+
40
+ If you modify a copy of the Library, and, in your modifications, a facility refers to a function or data to be supplied by an Application that uses the facility (other than as an argument passed when the facility is invoked), then you may convey a copy of the modified version:
41
+
42
+ a) under this License, provided that you make a good faith effort to ensure that, in the event an Application does not supply the function or data, the facility still operates, and performs whatever part of its purpose remains meaningful, or
43
+ b) under the GNU GPL, with none of the additional permissions of this License applicable to that copy.
44
+
45
+ 3. Object Code Incorporating Material from Library Header Files.
46
+
47
+ The object code form of an Application may incorporate material from a header file that is part of the Library. You may convey such object code under terms of your choice, provided that, if the incorporated material is not limited to numerical parameters, data structure layouts and accessors, or small macros, inline functions and templates (ten or fewer lines in length), you do both of the following:
48
+
49
+ a) Give prominent notice with each copy of the object code that the Library is used in it and that the Library and its use are covered by this License.
50
+ b) Accompany the object code with a copy of the GNU GPL and this license document.
51
+
52
+ 4. Combined Works.
53
+
54
+ You may convey a Combined Work under terms of your choice that, taken together, effectively do not restrict modification of the portions of the Library contained in the Combined Work and reverse engineering for debugging such modifications, if you also do each of the following:
55
+
56
+ a) Give prominent notice with each copy of the Combined Work that the Library is used in it and that the Library and its use are covered by this License.
57
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license document.
58
+ c) For a Combined Work that displays copyright notices during execution, include the copyright notice for the Library among these notices, as well as a reference directing the user to the copies of the GNU GPL and this license document.
59
+ d) Do one of the following:
60
+ 0) Convey the Minimal Corresponding Source under the terms of this License, and the Corresponding Application Code in a form suitable for, and under terms that permit, the user to recombine or relink the Application with a modified version of the Linked Version to produce a modified Combined Work, in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source.
61
+ 1) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (a) uses at run time a copy of the Library already present on the user's computer system, and (b) will operate properly with a modified version of the Library that is interface-compatible with the Linked Version.
62
+ e) Provide Installation Information, but only if you would otherwise be required to provide such information under section 6 of the GNU GPL, and only to the extent that such information is necessary to install and execute a modified version of the Combined Work produced by recombining or relinking the Application with a modified version of the Linked Version. (If you use option 4d0, the Installation Information must accompany the Minimal Corresponding Source and Corresponding Application Code. If you use option 4d1, you must provide the Installation Information in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source.)
63
+
64
+ 5. Combined Libraries.
65
+
66
+ You may place library facilities that are a work based on the Library side by side in a single library together with other library facilities that are not Applications and are not covered by this License, and convey such a combined library under terms of your choice, if you do both of the following:
67
+
68
+ a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities, conveyed under the terms of this License.
69
+ b) Give prominent notice with the combined library that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work.
70
+
71
+ 6. Revised Versions of the GNU Lesser General Public License.
72
+
73
+ The Free Software Foundation may publish revised and/or new versions of the GNU Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns.
74
+
75
+ Each version is given a distinguishing version number. If the Library as you received it specifies that a certain numbered version of the GNU Lesser General Public License “or any later version” applies to it, you have the option of following the terms and conditions either of that published version or of any later version published by the Free Software Foundation. If the Library as you received it does not specify a version number of the GNU Lesser General Public License, you may choose any version of the GNU Lesser General Public License ever published by the Free Software Foundation.
76
+
77
+ If the Library as you received it specifies that a proxy can decide whether future versions of the GNU Lesser General Public License shall apply, that proxy's public statement of acceptance of any version is permanent authorization for you to choose that version for the Library.
data/README.md ADDED
@@ -0,0 +1,55 @@
1
+ #posty\_cli
2
+ The posty\_cli is the command line interface of the posty softwarestack. It is developed to administrate a mailserver based on Postfix and Dovecot.
3
+
4
+ ##Requirements
5
+
6
+ You need to install ruby with the version 1.9.3 or later.
7
+ And a working terminal.
8
+
9
+ ##Installation
10
+
11
+ 1. You need to type following in your terminal
12
+
13
+ ``#~ gem install posty_cli``
14
+
15
+ 2. Next you need to create a config file in your home directory
16
+ Path:
17
+
18
+ ~.posty.yml
19
+
20
+ ```
21
+ #this is the posty Url put here your url where the posty-api is stored
22
+ :posty_api_url: http://posty-api.herokuapp.com/api/
23
+ #this is the version from the posty api
24
+ :posty_api_version: v1
25
+ ```
26
+
27
+ 3. Now you are able to work with posty_cli
28
+
29
+ ##Usage
30
+ When you have installed the posty\_cli you now able to work with the following command
31
+ ``#~ posty ``
32
+ now it shows you wich commands are possible to type in.
33
+ ###Example
34
+ ``#~ posty domain add test.com``
35
+ the first is our posty\_cli main command, the second is the section you would to edit, in this case it is the domain section. The third is what you would do in this section, the example shows to add a new domain. The last one is your new domainname. Very easy isn't it?
36
+
37
+ ## Test
38
+ coming soon...
39
+
40
+ ## Information
41
+
42
+ For more informations about posty please visit our website:
43
+ [www.posty-soft.org](http://www.posty-soft.org)
44
+
45
+ ### Bug reports
46
+
47
+ If you discover any bugs, feel free to create an issue on GitHub. Please add as much information as possible to help us fixing the possible bug. We also encourage you to help even more by forking and sending us a pull request.
48
+
49
+ ### License
50
+
51
+ LGPL v3 license. See LICENSE for details.
52
+
53
+ ### Copyright
54
+
55
+ All rights are at (C) [http://www.posty-soft.org](http://www.posty-soft.org) 2013
data/bin/posty ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ #starts the Thor cli => it is restricted by thor
3
+ require 'posty_cli/cli'
4
+ PostyCli::CLI.start
data/config.yml.sample ADDED
@@ -0,0 +1,5 @@
1
+ ---
2
+ #this is the posty Url put here your url where the posty-api is stored
3
+ :posty_api_url: http://posty-api.herokuapp.com/api/
4
+ #this is the version from the posty api
5
+ :posty_api_version: v1
@@ -0,0 +1,3 @@
1
+ ---
2
+ :posty_url: http://posty-api.herokuapp.com/api/
3
+ :posty_api_version: v1
data/lib/posty_cli.rb ADDED
@@ -0,0 +1,34 @@
1
+ #posty_cli is the main file to load all required gems and classes
2
+ require 'yaml'
3
+ require 'thor/shell/basic'
4
+ require 'thor/shell/color'
5
+ module PostyCli
6
+
7
+
8
+ autoload :Command, 'posty_cli/command'
9
+ autoload :Config, 'posty_cli/config'
10
+ autoload :Version, 'posty_cli/version'
11
+ autoload :RestClient, 'rest-client'
12
+ autoload :JSON, 'json'
13
+ autoload :Util, 'posty_cli/util'
14
+
15
+
16
+ CONFIG_PATH = '~/.posty.yml'
17
+ config = File.expand_path(CONFIG_PATH)
18
+
19
+
20
+ unless File.exist?(config)
21
+ File.open(File.expand_path(File.dirname(__FILE__) + "/../config.yml.sample", "r")) do |sample|
22
+ puts"Could not find a config file. Create a config file, '#{CONFIG_PATH}', form the following sample config"
23
+
24
+ puts("=" *15 + "END (Do not copy this line " + "=" *15)
25
+ while(line = sample.gets)
26
+ puts line
27
+ end
28
+ puts("="*15 + " END (Do not copy this line) "+ "=" *15)
29
+ end
30
+ exit(-1)
31
+ end
32
+ PostyCli::Config.load(config)
33
+ end
34
+
@@ -0,0 +1,43 @@
1
+ require 'thor'
2
+ require 'posty_cli'
3
+ require 'posty_cli/version'
4
+ require 'json'
5
+ #CLI class to set the headcommands and specified where the subcommands are
6
+ module PostyCli
7
+ class CLI < Thor
8
+
9
+
10
+ map "-v" => "version"
11
+ map "--version" => "version"
12
+
13
+ desc "--version", "print version"
14
+ long_desc <<-D
15
+ Print the Posty CLI tool version
16
+ D
17
+ def version
18
+ puts "Posty CLI version %s" % [PostyCli::VERSION]
19
+ end
20
+
21
+
22
+ desc "domain [SUBCOMMAND]", "perform an action on a domain"
23
+ long_desc <<-D
24
+ Perform an action on a domain. To see available subcommands use 'posty domain help'
25
+ D
26
+ subcommand "domain", PostyCli::Command::Domain
27
+
28
+ desc "user [SUBCOMMAND]", "perform an action on a user"
29
+ long_desc <<-D
30
+ Perform an action on a User. To see available subcommands use 'posty user help'
31
+ D
32
+ subcommand "user", PostyCli::Command::User
33
+
34
+ desc "alias [SUBCOMMAND]", "perform an action on a alias"
35
+ long_desc <<-D
36
+ Perform an action on a alias. To see available subcommands use 'posty alias help'
37
+ D
38
+ subcommand "alias", PostyCli::Command::Alias
39
+
40
+ end
41
+ end
42
+
43
+
@@ -0,0 +1,7 @@
1
+ module PostyCli
2
+ module Command
3
+ autoload :Domain, 'posty_cli/command/domain'
4
+ autoload :User, 'posty_cli/command/user'
5
+ autoload :Alias, 'posty_cli/command/alias'
6
+ end
7
+ end
@@ -0,0 +1,74 @@
1
+ module PostyCli
2
+ module Command
3
+ class Alias < Thor
4
+ #SHOW
5
+ map "-l" => "list"
6
+ map "--list" => "list"
7
+
8
+ desc "list[DOMAIN]", "lists all aliases"
9
+ long_desc <<-D
10
+ List all of the alias in the specified domain
11
+ D
12
+
13
+ def list(domain)
14
+ out = PostyCli::Util::Alias.get_all(domain)
15
+ print_table(out)
16
+ end
17
+
18
+
19
+
20
+ #ADD
21
+ desc "add [USER]@[DOMAIN] [ALIAS]", "add an alias"
22
+ long_desc <<-D
23
+ Add an alias to a specified user. You have to specify a name and the domain to create a alias.
24
+ [ALIAS] need to be specified with the regular expressions to an User because its the restriction for email adress.
25
+ $ posty alias add test@posty-soft.com test2
26
+ D
27
+ def add(name, ali)
28
+ split = name.split("\@")
29
+ if(PostyCli::Util::check_name(name))
30
+ json = {source: ali, destination: split[0]}.to_json
31
+ PostyCli::Util::Alias.create(json, name, split[1], ali)
32
+ else
33
+ puts "you have to enter a valid email adress, like test@posty-soft.de"
34
+ end
35
+ end
36
+
37
+ #EDIT
38
+ desc "edit [ALIAS]@[DOMAIN] [NEW_ALIAS]", "edit an specified user"
39
+ long_desc <<-D
40
+ Edit a specified alias on the domain. You have to enter [USER]@[DOMAIN] and the [NEW_ALIAS]
41
+ which include the new name of the alias.
42
+ $ posty alias edit test2@posty-soft.com test3
43
+ D
44
+ def edit(name, new_name)
45
+ split = name.split("\@")
46
+ if(name =~ /\@/ && split.length < 3 )
47
+ domain = split[1]
48
+ old_name = split[0]
49
+ json = {source: new_name}.to_json
50
+ PostyCli::Util::Alias.edit(json, domain, new_name, old_name, new_name)
51
+ else
52
+ puts "you have to enter a valid email adress like test@posty-soft.de"
53
+ end
54
+ end
55
+
56
+ #DELETE
57
+ desc "delete [ALIAS]@[DOMAIN]", "delete a specified alias from the given user"
58
+ long_desc <<-D
59
+ Delete a specified user on the server. You have to specify the domain you
60
+ would the user delete. [USER] will delete from the server entirely.
61
+ D
62
+ def delete(name)
63
+ split = name.split("\@")
64
+ if(name =~ /\@/ && split.length < 3 )
65
+ name_del = split[0]
66
+ domain = split[1]
67
+ if(yes? "Are you sure you want to delete #{name}? Yes\\No")
68
+ PostyCli::Util::Alias.delete(name_del, domain)
69
+ end
70
+ end
71
+ end
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,57 @@
1
+ module PostyCli
2
+ module Command
3
+ class Domain < Thor
4
+
5
+ #SHOW
6
+ map "-l" => "list"
7
+ map "--list" => "list"
8
+
9
+ desc "list", "list all domains"
10
+ long_desc <<-D
11
+ List all of the domains from your server
12
+ D
13
+
14
+ def list
15
+ out = PostyCli::Util::Domain.get_all
16
+ print_table(out)
17
+ end
18
+
19
+
20
+
21
+ #ADD
22
+ desc "add [DOMAIN]", "add a domain"
23
+ long_desc <<-D
24
+ Add a domain to your server. You have to specify a name to create a domain.
25
+ [DOMAIN] need to be specified with the regular expressions to a Domain.
26
+ $ posty domain add posty-soft.com
27
+ D
28
+ def add(name)
29
+ json = {name: name}.to_json
30
+ PostyCli::Util::Domain.create(json, name)
31
+ end
32
+
33
+ #EDIT
34
+ desc "edit [DOMAIN][NEW_DOMAIN]", "edit a specified domain"
35
+ long_desc <<-D
36
+ Edit a specified domain on the server. You have to enter [DOMAIN] and the [NEW_DOMAIN]
37
+ which include the new name of the domain.
38
+ D
39
+ def edit(name, new_name)
40
+ json = {name: new_name}.to_json
41
+ PostyCli::Util::Domain.edit(name, json, new_name)
42
+ end
43
+
44
+ #DELETE
45
+ desc "delete [DOMAIN]", "delete a specified domain"
46
+ long_desc <<-D
47
+ Delete a specified domain on the server. You have to specify the domain you
48
+ would delete. [DOMAIN] will delete from the server entirely.
49
+ D
50
+ def delete(name)
51
+ if(yes? "Are you sure you want to delete #{name}? Yes\\No")
52
+ PostyCli::Util::Domain.delete(name)
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,102 @@
1
+ require 'io/console'
2
+ module PostyCli
3
+ module Command
4
+ class User < Thor
5
+ #SHOW
6
+ map "-l" => "list"
7
+ map "--list" => "list"
8
+
9
+ desc "list [DOMAIN]", "list all users"
10
+ long_desc <<-D
11
+ List all of the user in the specified domain
12
+ D
13
+
14
+ def list(domain)
15
+ out = PostyCli::Util::User.get_all(domain)
16
+
17
+ print_table(out)
18
+
19
+ end
20
+
21
+
22
+
23
+ #ADD
24
+ desc "add [USER]@[DOMAIN]", "add an user"
25
+ long_desc <<-D
26
+ Add an User to a specified domain. You have to specify a name and the domain to create a user.
27
+ [USER] need to be specified with the regular expressions to an User because its the restriction for email adress.
28
+ $ posty user add posty-soft.com
29
+ D
30
+ def add(name)
31
+ split = name.split("\@")
32
+ if(name =~ /\@/ && split.length < 3 )
33
+ i = true
34
+ while i
35
+
36
+
37
+ puts "password:"
38
+ pw = STDIN.noecho(&:gets).chomp
39
+ puts "enter password again: "
40
+ if(STDIN.noecho(&:gets).chomp==pw)
41
+ json = {name: split[0], password: pw}.to_json
42
+ domain = split[1]
43
+
44
+ PostyCli::Util::User.create(json, domain, split[0])
45
+ i=false
46
+ else
47
+ puts "password not equal, sorry!!"
48
+ end
49
+ end
50
+ else
51
+ puts "you have to enter a valid email adress like test@posty-soft.de"
52
+ end
53
+ end
54
+
55
+ #EDIT
56
+ desc "edit [USER]@[DOMAIN] [NEW_USER]", "edit an specified user"
57
+ long_desc <<-D
58
+ Edit an specified user on the domain. You have to enter [USER]@[DOMAIN] and the [NEW_USER]
59
+ which include the new name of the user.
60
+ D
61
+ def edit(name, new_name)
62
+ split = name.split("\@")
63
+ if(name =~ /\@/ && split.length < 3 )
64
+ i = true
65
+ while i
66
+ puts "password:"
67
+ pw = STDIN.noecho(&:gets).chomp
68
+ puts "enter password again: "
69
+ if(STDIN.noecho(&:gets).chomp==pw)
70
+ json = {name: new_name, password: pw}.to_json
71
+ domain = split[1]
72
+
73
+ PostyCli::Util::User.edit(json, domain, new_name, split[0], new_name)
74
+ i=false
75
+ else
76
+ puts "password not equal, sorry!!"
77
+ end
78
+ end
79
+ else
80
+ puts "you have to enter a valid email adress like test@posty-soft.de"
81
+ end
82
+ end
83
+
84
+ #DELETE
85
+ desc "delete [USER]@[DOMAIN]", "delete a specified user from the given domain"
86
+ long_desc <<-D
87
+ Delete a specified user on the server. You have to specify the domain you
88
+ would the user delete. [USER] will delete from the server entirely.
89
+ D
90
+ def delete(name)
91
+ split = name.split("\@")
92
+ if(name =~ /\@/ && split.length < 3 )
93
+ name_del = split[0]
94
+ domain = split[1]
95
+ if(yes? "Are you sure you want to delete #{name}? Yes\\No")
96
+ PostyCli::Util::User.delete(name_del, domain)
97
+ end
98
+ end
99
+ end
100
+ end
101
+ end
102
+ end
@@ -0,0 +1,31 @@
1
+ module PostyCli
2
+ class Config
3
+ class << self
4
+ def load(source)
5
+ @config = {:posty_url => nil,:display_results_in_pager => false}
6
+
7
+ if source.is_a?(String)
8
+ raise "Config file #{source} not found" unless File.exist?(source)
9
+
10
+ config = YAML.load_file(source)
11
+ @config.merge! config if config
12
+
13
+ elsif source.is_a?(Hash)
14
+ @config.merge! source
15
+ end
16
+ end
17
+
18
+ def include?(key)
19
+ @config.include?(key)
20
+ end
21
+
22
+ def [](key)
23
+ @config[key]
24
+ end
25
+
26
+ def to_yaml
27
+ @config.to_yaml
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,81 @@
1
+ #Util class is required for all core requirements and autoload it
2
+
3
+ module PostyCli
4
+ module Util
5
+
6
+
7
+ autoload :Domain, 'posty_cli/util/domain'
8
+ autoload :User, 'posty_cli/util/user'
9
+ autoload :Alias, 'posty_cli/util/alias'
10
+
11
+ autoload :RestClient, 'rest_client'
12
+ autoload :URI, 'uri'
13
+ autoload :Socket, 'socket'
14
+ autoload :JSON, 'json'
15
+
16
+ def self.build_uri(name)
17
+ URI.join(PostyCli::Config[:posty_api_url], PostyCli::Config[:posty_api_version] + "/", name).to_s
18
+ end
19
+
20
+ def self.check_name(name)
21
+ split = name.split("\@")
22
+ if(name =~ /\@/ && split.length < 3)
23
+ return true
24
+ else
25
+ return false
26
+ end
27
+ end
28
+
29
+ def self.check_url(domain)
30
+ puts "You have to enter a valid URL. You should read http://de.wikipedia.org/wiki/Uniform_Resource_Locator. Because #{domain} cant be a valid domain name"
31
+ end
32
+
33
+
34
+
35
+ def self.check_response_code(response, mes)
36
+
37
+
38
+ if response =~ /401/
39
+ ## Unauthorized
40
+ puts "User token was not present or is not valid."
41
+ exit 1
42
+ elsif response =~ /400/
43
+ ##name already taken
44
+ mes = JSON.parse(mes)
45
+ mes["error"].each do |key, value|
46
+ value.each do |value|
47
+ puts key + ": " + value
48
+ end
49
+ end
50
+ elsif response =~ /403/
51
+ ## Forbidden
52
+ puts "You are not authorized to complete this action"
53
+ exit 1
54
+ elsif response =~ /404/
55
+ ## Not found
56
+
57
+ if(mes =~ /\{/)
58
+ mes2 = JSON.parse(mes)
59
+ puts "an error occurred: " + mes2["error"]
60
+ exit 1
61
+ else
62
+ puts "URL " + mes
63
+ exit 1
64
+ end
65
+
66
+
67
+ elsif response =~ /405/
68
+ ## Method not allowed
69
+ puts "This request is not supported."
70
+ exit 1
71
+ elsif response =~ /409/
72
+ ## Conflicting resource
73
+ puts "A conflicting resource already exists."
74
+ exit 1
75
+ elsif response =~ /500/
76
+ ## Server error
77
+ puts "Oops. Something went wrong. Please try again."
78
+ end
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,87 @@
1
+ require 'socket'
2
+ module PostyCli
3
+ module Util
4
+ class Alias
5
+ #Get all domains
6
+ def self.get_all(domain)
7
+ #Array to keep the rest-output
8
+ @tabletmp = []
9
+ begin
10
+ url = PostyCli::Util.build_uri("domains/#{domain}/aliases")
11
+ #begin to prepare rest or end with a rescue
12
+ res = RestClient.get (url)
13
+ data = JSON.parse(res)
14
+ data.each do |blub|
15
+ @tabletmp << blub["virtual_alias"]["source"] +" ==> "+ blub["virtual_alias"]["destination"] +"\@"+ domain
16
+ end
17
+
18
+ rescue SocketError => e #error for no network connection
19
+ puts "Could not contact the server. Please check connectivity!"
20
+ exit 1
21
+ rescue URI::Error => e
22
+ PostyCli::Util.check_url(domain)
23
+ rescue Exception => e #error that pass the http code and the message to the Util class
24
+
25
+ PostyCli::Util.check_response_code(e.message, e.response)
26
+ end
27
+ #output the Domains with index
28
+
29
+ tablesel = @tabletmp.map.with_index{ |a, i| [i+1, *a]}
30
+
31
+
32
+ end
33
+
34
+ #ADD a alias to a user
35
+ def self.create(json, email, domain, screen)
36
+ begin
37
+ #begin to prepare rest or end with a rescue
38
+ url = PostyCli::Util.build_uri("domains/#{domain}/aliases")
39
+ res = RestClient.post(url, json, :content_type => :json, :accept => :json)
40
+ puts "Alias #{screen} for #{email} is created"
41
+
42
+ rescue SocketError => e #error for no network connection
43
+ puts "Could not contact the server. Please check connectivity!"
44
+ exit 1
45
+ rescue URI::Error => e
46
+ PostyCli::Util.check_url(domain)
47
+ rescue Exception => e #error that pass the http code and the message to the Util class
48
+
49
+ PostyCli::Util.check_response_code(e.message, e.response)
50
+ end
51
+ end
52
+
53
+ def self.delete(name, domain)
54
+ begin
55
+ #begin to prepare rest or end with a rescue
56
+ url = PostyCli::Util.build_uri("domains/#{domain}/aliases/#{name}")
57
+ res = RestClient.delete(url)
58
+ puts "the alias #{name} is deleted"
59
+ rescue SocketError => e #error for no network connection
60
+ puts "Could not contact the server. Please check connectivity!"
61
+ exit 1
62
+ rescue URI::Error => e
63
+ PostyCli::Util.check_url(domain)
64
+ rescue Exception => e #error that pass the http code and the message to the Util class
65
+ PostyCli::Util.check_response_code(e.message, e.response)
66
+ end
67
+ end
68
+
69
+ #EDIT
70
+ def self.edit(json, domain, new_name, old, screen)
71
+ begin
72
+ #begin to prepare rest or end with a rescue
73
+ url = PostyCli::Util.build_uri("domains/#{domain}/aliases/#{old}")
74
+ res = RestClient.put(url, json, :content_type => :json, :accept => :json)
75
+ puts("you have edit the alias #{old} into #{screen}")
76
+ rescue SocketError => e #error for no network connection
77
+ puts "Could not contact the server. Please check connectivity!"
78
+ exit 1
79
+ rescue URI::Error => e
80
+ PostyCli::Util.check_url(domain)
81
+ rescue Exception => e #error that pass the http code and the message to the Util class
82
+ PostyCli::Util.check_response_code(e.message, e.response)
83
+ end
84
+ end
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,72 @@
1
+ module PostyCli
2
+ module Util
3
+ class Domain
4
+
5
+ #Get all Domains
6
+ def self.get_all()
7
+ @tabletmp = []
8
+ begin
9
+ url = PostyCli::Util.build_uri("domains")
10
+ response = RestClient.get (url)
11
+ rescue SocketError => e #error for no network connection
12
+ puts "Could not contact the server. Please check connectivity!"
13
+ exit 1
14
+ rescue URI::Error => e
15
+ PostyCli::Util.check_url(url)
16
+ rescue Exception => e #error that pass the http code and the message to the Util class
17
+ PostyCli::Util.check_response_code(e.message, e.response)
18
+ end
19
+ data = JSON.parse(response)
20
+ data.each do |blub|
21
+ @tabletmp << blub["virtual_domain"]["name"]
22
+ end
23
+ tablesel = @tabletmp.map.with_index{ |a, i| [i+1, *a]}
24
+
25
+ end
26
+ #ADD
27
+ def self.create(name, screen)
28
+ begin
29
+ url = PostyCli::Util.build_uri("domains")
30
+ response = RestClient.post(url,
31
+ name, :content_type => :json, :accept => :json)
32
+ puts "Domain #{screen} is created"
33
+
34
+ rescue SocketError => e #error for no network connection
35
+ puts "Could not contact the server. Please check connectivity!"
36
+ exit 1
37
+ rescue URI::Error => e
38
+ PostyCli::Util.check_url(url)
39
+ rescue Exception => e #error that pass the http code and the message to the Util class
40
+ PostyCli::Util.check_response_code(e.message, e.response)
41
+ end
42
+ end
43
+
44
+ def self.delete(name)
45
+ begin
46
+ url = PostyCli::Util.build_uri("domains/#{name}")
47
+ response = RestClient.delete(url)
48
+ puts "domain #{name} is deleted"
49
+
50
+ rescue SocketError => e
51
+ puts "Could not contact the server. Please check connectivity!"
52
+ exit 1
53
+ rescue Exception => e
54
+ PostyCli::Util.check_response_code(e.message, e.response )
55
+ end
56
+ end
57
+
58
+ def self.edit(name, new_name, screen)
59
+ begin
60
+ url = PostyCli::Util.build_uri("domains/#{name}")
61
+ response = RestClient.put(url, new_name, :content_type => :json, :accept => :json)
62
+ puts("you have edit the domain #{name} into #{screen}")
63
+ rescue SocketError => e
64
+ puts "Could not contact the server. Please check connectivity!"
65
+ exit 1
66
+ rescue Exception => e
67
+ PostyCli::Util.check_response_code(e.message, e.response )
68
+ end
69
+ end
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,83 @@
1
+ require 'socket'
2
+ module PostyCli
3
+ module Util
4
+ class User
5
+ #Get all Users
6
+ def self.get_all(domain)
7
+ #Array to keep the rest-output
8
+ @tabletmp = []
9
+ #begin to prepare rest or end with a rescue
10
+ begin
11
+ url = PostyCli::Util.build_uri("domains/#{domain}/users")
12
+ response = RestClient.get (url)
13
+ data = JSON.parse(response)
14
+ data.each do |blub|
15
+ @tabletmp << blub["virtual_user"]["name"] +"\@"+ domain
16
+ end
17
+ rescue SocketError => e #error for no network connection
18
+ puts "Could not contact the server. Please check connectivity!"
19
+ exit 1
20
+ rescue URI::Error => e
21
+ puts e
22
+ rescue Exception => e #error that pass the http code and the message to the Util class
23
+ PostyCli::Util.check_response_code(e.message, e.response )
24
+ end
25
+ tablesel = @tabletmp.map.with_index{ |a, i| [i+1, *a]}
26
+ end
27
+
28
+ #ADD a user to domain
29
+ def self.create(json, domain, screen)
30
+
31
+ begin
32
+ #begin to prepare rest or end with a rescue
33
+ url = PostyCli::Util.build_uri("domains/#{domain}/users")
34
+ @response = RestClient.post(url, json, :content_type => :json, :accept => :json)
35
+ puts "User #{screen} in #{domain} is created"
36
+ rescue SocketError => e #error for no network connection
37
+ puts "Could not contact the server. Please check connectivity!"
38
+ exit 1
39
+ rescue URI::Error => e
40
+ PostyCli::Util.check_url(domain)
41
+ rescue Exception => e #error that pass the http code and the message to the Util class
42
+ PostyCli::Util.check_response_code(e.message, e.response)
43
+ end
44
+ end
45
+
46
+ def self.delete(name, domain)
47
+
48
+ begin
49
+ #begin to prepare rest or end with a rescue
50
+ url = PostyCli::Util.build_uri("domains/#{domain}/users/#{name}")
51
+ response = RestClient.delete(url)
52
+ puts "the user #{name} is deleted"
53
+ rescue SocketError => e #error for no network connection
54
+ puts "Could not contact the server. Please check connectivity!"
55
+ exit 1
56
+ rescue URI::Error => e
57
+ PostyCli::Util.check_url(domain)
58
+ rescue Exception => e #error that pass the http code and the message to the Util class
59
+
60
+ PostyCli::Util.check_response_code(e.message, e.response)
61
+ end
62
+ end
63
+
64
+ #EDIT
65
+ def self.edit(json, domain, new_name, old, screen)
66
+ begin
67
+ #begin to prepare rest or end with a rescue
68
+ url = PostyCli::Util.build_uri("domains/#{domain}/users/#{old}")
69
+ response = RestClient.put(url, json, :content_type => :json, :accept => :json)
70
+ puts("you have edit the user #{old} into #{screen}")
71
+ rescue SocketError => e #error for no network connection
72
+ puts "Could not contact the server. Please check connectivity!"
73
+ exit 1
74
+ rescue URI::Error => e
75
+ PostyCli::Util.check_url(domain)
76
+ rescue Exception => e #error that pass the http code and the message to the Util class
77
+
78
+ PostyCli::Util.check_response_code(e.message, e.response)
79
+ end
80
+ end
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,4 @@
1
+ #version inerhits the current version
2
+ module PostyCli
3
+ VERSION = '1.0.0'
4
+ end
Binary file
data/posty_cli.gemspec ADDED
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'posty_cli/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "posty_cli"
8
+ gem.version = PostyCli::VERSION
9
+ gem.authors = ["Thomas Berendt", "Florian Schmidhuber"]
10
+ gem.email = ["team@posty-soft.de"]
11
+ gem.description = %q{Posty Command Line Tool}
12
+ gem.summary = %q{This tool brings the functionality of the Posty Administration tool to the command line}
13
+ gem.homepage = "https://github.com/posty/posty_cli"
14
+ gem.license = "LGPL v3"
15
+ gem.files = Dir["**/*"]
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_runtime_dependency "thor"
21
+ gem.add_runtime_dependency "json"
22
+ gem.add_runtime_dependency "rest-client"
23
+ end
@@ -0,0 +1,3 @@
1
+
2
+
3
+
data/spec/user_spec.rb ADDED
File without changes
metadata ADDED
@@ -0,0 +1,123 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: posty_cli
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Thomas Berendt
9
+ - Florian Schmidhuber
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2013-06-25 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: thor
17
+ requirement: !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: '0'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ! '>='
29
+ - !ruby/object:Gem::Version
30
+ version: '0'
31
+ - !ruby/object:Gem::Dependency
32
+ name: json
33
+ requirement: !ruby/object:Gem::Requirement
34
+ none: false
35
+ requirements:
36
+ - - ! '>='
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ type: :runtime
40
+ prerelease: false
41
+ version_requirements: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ - !ruby/object:Gem::Dependency
48
+ name: rest-client
49
+ requirement: !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :runtime
56
+ prerelease: false
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ! '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ description: Posty Command Line Tool
64
+ email:
65
+ - team@posty-soft.de
66
+ executables:
67
+ - posty
68
+ extensions: []
69
+ extra_rdoc_files: []
70
+ files:
71
+ - posty_cli-0.0.1.gem
72
+ - Gemfile
73
+ - posty_cli-1.0.0.gem
74
+ - posty_cli.gemspec
75
+ - config.yml.sample
76
+ - LICENSE.txt
77
+ - spec/user_spec.rb
78
+ - spec/spec_helper.rb
79
+ - bin/posty
80
+ - Gemfile.lock
81
+ - config.yml.sample~
82
+ - README.md
83
+ - lib/posty_cli.rb
84
+ - lib/posty_cli/util/alias.rb
85
+ - lib/posty_cli/util/domain.rb
86
+ - lib/posty_cli/util/user.rb
87
+ - lib/posty_cli/version.rb
88
+ - lib/posty_cli/util.rb
89
+ - lib/posty_cli/command/alias.rb
90
+ - lib/posty_cli/command/domain.rb
91
+ - lib/posty_cli/command/user.rb
92
+ - lib/posty_cli/cli.rb
93
+ - lib/posty_cli/command.rb
94
+ - lib/posty_cli/config.rb
95
+ homepage: https://github.com/posty/posty_cli
96
+ licenses:
97
+ - LGPL v3
98
+ post_install_message:
99
+ rdoc_options: []
100
+ require_paths:
101
+ - lib
102
+ required_ruby_version: !ruby/object:Gem::Requirement
103
+ none: false
104
+ requirements:
105
+ - - ! '>='
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ required_rubygems_version: !ruby/object:Gem::Requirement
109
+ none: false
110
+ requirements:
111
+ - - ! '>='
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ requirements: []
115
+ rubyforge_project:
116
+ rubygems_version: 1.8.25
117
+ signing_key:
118
+ specification_version: 3
119
+ summary: This tool brings the functionality of the Posty Administration tool to the
120
+ command line
121
+ test_files:
122
+ - spec/user_spec.rb
123
+ - spec/spec_helper.rb