easy-mysql 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/easy-mysql.rb +31 -27
  2. metadata +11 -11
data/lib/easy-mysql.rb CHANGED
@@ -3,8 +3,6 @@ require 'rainbow'
3
3
 
4
4
  class EasyMysql
5
5
  def self.driver
6
- puts " easy-mysql, created by Connor McArthur "
7
-
8
6
  begin
9
7
  new_mysql_user_info = self.getInputAndMakeMySQLUser
10
8
  new_linux_user_info = self.getInputAndMakeLinuxUser
@@ -12,15 +10,17 @@ class EasyMysql
12
10
  return false
13
11
  end
14
12
 
15
- puts "\r\nMySQL".background(:yellow).bright
16
- puts "Username: {#new_mysql_user_info.username}"
17
- puts "Password: {#new_mysql_user_info.password}"
18
-
19
- puts "\r\nLinux User".background(:yellow).bright
20
- puts "Username: {#new_linux_user_info.username}"
21
- puts "Password: {#new_linux_user_info.password}"
22
-
23
- puts "\r\nSUCCESS!".background(:red).bright
13
+ puts
14
+ puts "MySQL".bright
15
+ puts "Username: " + new_mysql_user_info[:username]
16
+ puts "Password: " + new_mysql_user_info[:password]
17
+ puts
18
+ puts "Linux User".bright
19
+ puts "Username: " + new_linux_user_info[:username]
20
+ puts "Password: " + new_linux_user_info[:password]
21
+ puts ""
22
+ puts "SUCCESS!\n\r".background(:green).color(:black).bright
23
+ puts ""
24
24
  end
25
25
 
26
26
  def self.getInputAndMakeLinuxUser
@@ -36,19 +36,21 @@ class EasyMysql
36
36
 
37
37
  new_linux_user_info = self.addLinuxUser(linux_username)
38
38
  self.setUpLinuxUserFilesystem(linux_username, linux_pubkey)
39
+
40
+ return new_linux_user_info
39
41
  end
40
42
 
41
43
  def self.addLinuxUser(username)
42
44
  group = username
43
45
  password = self.makeRandomPassword
44
46
 
45
- output = `useradd -p #{password.crypt("JU")} -g #{group} #{username}`
47
+ output = `useradd -p #{password.crypt("JU")} #{username}`
46
48
 
47
49
  unless $?.to_i == 0
48
50
  raise $?
49
51
  end
50
52
 
51
- return { username: username, password: password }
53
+ return { :username => username, :password => password }
52
54
  end
53
55
 
54
56
  def self.setUpLinuxUserFilesystem(username, pubkeytext)
@@ -57,11 +59,12 @@ class EasyMysql
57
59
  Dir.mkdir("/home/#{username}/.ssh") unless File.exists?("/home/#{username}/.ssh")
58
60
 
59
61
  File.open("/home/#{username}/.ssh/authorized_keys", 'w') do |file|
60
- file.write pubkeytext
62
+ file.write pubkeytext + "\n"
61
63
  end
62
64
 
63
65
  `chown -R #{username}:#{username} /home/#{username}`
64
- `chmod -R 0600 /home/#{username}/.ssh`
66
+ `chmod -R 0700 /home/#{username}/.ssh`
67
+ `chmod 0600 /home/#{username}/.ssh/authorized_keys`
65
68
  rescue => e
66
69
  puts "\r\nERROR! #{e.message}".background(:red).bright
67
70
  raise e
@@ -77,9 +80,11 @@ class EasyMysql
77
80
  mysql_admin_password = gets.chomp
78
81
 
79
82
  begin
80
- connection = self.makeMySQLConnection(mysql_admin_username, mysql_admin_password)
83
+ connection = Mysql::new('127.0.0.1', mysql_admin_username, mysql_admin_password)
81
84
  rescue => e
82
- puts "\r\nERROR! #{e.message}".background(:red).bright
85
+ puts ""
86
+ puts "ERROR! #{e.message}\n".background(:red).bright
87
+ puts ""
83
88
  raise e
84
89
  end
85
90
 
@@ -89,17 +94,15 @@ class EasyMysql
89
94
  mysql_new_username = gets.chomp
90
95
 
91
96
  begin
92
- new_user = self.addMySQLUser(connection, mysql_new_username)
97
+ new_mysql_user_info = self.addMySQLUser(connection, mysql_new_username)
93
98
  rescue => e
94
- puts "\r\nERROR! #{e.message}".background(:red).bright
99
+ puts ""
100
+ puts "ERROR! #{e.message}\n".background(:red).bright
101
+ puts ""
95
102
  raise e
96
103
  end
97
104
 
98
- return new_user
99
- end
100
-
101
- def self.makeMySQLConnection(username, password)
102
- Mysql::new('127.0.0.1', username, password)
105
+ return new_mysql_user_info
103
106
  end
104
107
 
105
108
  def self.addMySQLUser(connection, new_username)
@@ -107,11 +110,12 @@ class EasyMysql
107
110
 
108
111
  new_password = self.makeRandomPassword
109
112
 
110
- query = "GRANT SELECT ON *.* TO `#{new_username}`@`127.0.0.1` IDENTIFIED BY '#{new_password}'";
113
+ query = "GRANT SELECT ON *.* TO `#{new_username}`@`localhost` IDENTIFIED BY '#{new_password}'";
114
+ puts query
111
115
 
112
116
  connection.query(query)
113
117
 
114
- return { username: new_username, password: new_password }
118
+ return { :username => new_username, :password => new_password }
115
119
  end
116
120
 
117
121
  def self.makeRandomPassword(len = 24)
@@ -129,7 +133,7 @@ class EasyMysql
129
133
  return (97+rand(26)).chr
130
134
  else
131
135
  # numbers
132
- return rand(9)
136
+ return rand(9).to_s
133
137
  end
134
138
  end
135
139
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: easy-mysql
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,42 +9,42 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-06-20 00:00:00.000000000 Z
12
+ date: 2013-06-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: mysql
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
- - - '='
19
+ - - ! '>='
20
20
  - !ruby/object:Gem::Version
21
- version: 2.9.1
21
+ version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  none: false
26
26
  requirements:
27
- - - '='
27
+ - - ! '>='
28
28
  - !ruby/object:Gem::Version
29
- version: 2.9.1
29
+ version: '0'
30
30
  - !ruby/object:Gem::Dependency
31
31
  name: rainbow
32
32
  requirement: !ruby/object:Gem::Requirement
33
33
  none: false
34
34
  requirements:
35
- - - '='
35
+ - - ! '>='
36
36
  - !ruby/object:Gem::Version
37
- version: 1.1.4
37
+ version: '0'
38
38
  type: :runtime
39
39
  prerelease: false
40
40
  version_requirements: !ruby/object:Gem::Requirement
41
41
  none: false
42
42
  requirements:
43
- - - '='
43
+ - - ! '>='
44
44
  - !ruby/object:Gem::Version
45
- version: 1.1.4
45
+ version: '0'
46
46
  description: A simple way to set up a secure MySQL connection.
47
- email: connormcarthur11@gmail.com
47
+ email:
48
48
  executables:
49
49
  - easy-mysql
50
50
  extensions: []