diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index 801da4b..42ff39c 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -1,63 +1,80 @@
class ApplicationController < ActionController::Base
- # Prevent CSRF attacks by raising an exception.
- # For APIs, you may want to use :null_session instead.
- # protect_from_forgery with: :exception
+ # Prevent CSRF attacks by raising an exception.
+ # For APIs, you may want to use :null_session instead.
+ # protect_from_forgery with: :exception
- def get_conf
- @config = Hash.new
-
- one_node = Node.take
- if !one_node.nil?
- @config["host_name"] = one_node.host_name
- @config["host_ip"] = one_node.host_ip
- @config["user_name"] = one_node.user_name
- @config["user_password"] = one_node.user_password
+ def get_conf
+ config = Hash.new
+ one_node = Node.take
+ if !one_node.nil?
+ config["host_name"] = one_node.host_name
+ config["host_ip"] = one_node.host_ip
+ config["user_name"] = one_node.user_name
+ config["user_password"] = one_node.user_password
+ end
+ return config
end
-
- # output = `cat configure.conf`.split("\n")
- # output.each do |t|
- # if t.include? "project_path="
- # @config["project_path"] = t.split("project_path=")[1]
- # elsif t.include? "server_name="
- # @config["server_name"] = t.split("server_name=")[1]
- # elsif t.include? "host_user="
- # @config["host_user"] = t.split("host_user=")[1]
- # elsif t.include? "host_ip="
- # @config["host_ip"] = t.split("host_ip=")[1]
- # elsif t.include? "host_port=" and !t.split("host_port=")[1].nil?
- # @config["host_port"] = t.split("host_port=")[1] + " "
- # elsif t.include? "host_password="
- # @config["host_password"] = t.split("host_password=")[1]
- # end
- # end
-
-
- return @config
- end
- def file_directory(dir)
- @current_dir = dir
- dir_list = `ls #{@current_dir} -l`
- parsing_list = dir_list.split("\n")
- @files = Array.new
- file = Hash.new
-
- @total_list = parsing_list[0]
- for t in 1..(parsing_list.length-1)
- parsing_file = parsing_list[t].split(" ")
- file["auth"] = parsing_file[0]
- file["size"] = parsing_file[4]
- file["date"] = parsing_file[5] + " " + parsing_file[6] + " " + parsing_file[7]
- file["name"] = parsing_file[8]
- @files << file
- file = Hash.new
+ def get_conf_all
+ config = Array.new
+ config_each = Hash.new
+ all_node = Node.all
+ all_node.each do |one_node|
+ config_each["host_name"] = one_node.host_name
+ config_each["host_ip"] = one_node.host_ip
+ config_each["user_name"] = one_node.user_name
+ config_each["user_password"] = one_node.user_password
+ config << config_each
+ config_each = Hash.new
+ end
+ return config
end
- puts @files
- return @files
- end
- def checkDir
- files = file_directory(params[:path])
- render :json => {:file => files , :current => @current_dir}
- end
+ def get_df
+ df = Array.new
+ df_each = Hash.new
+ command = String.new
+ command << "df -hP"
+ puts command
+ output = `#{command}`.split("\n")
+ output.each do |t|
+ next if t.equal? output.first
+ s = t.split(' ')
+ df_each['Filesystem'] = s[0]
+ df_each['Size'] = s[1]
+ df_each['Used'] = s[2]
+ df_each['Avail'] = s[3]
+ df_each['Use%'] = s[4]
+ df_each['Mounted on'] = s[5]
+ df << df_each
+ df_each = Hash.new
+ end
+ return df
+ end
+
+ def file_directory(dir)
+ @current_dir = dir
+ dir_list = `ls #{@current_dir} -l`
+ parsing_list = dir_list.split("\n")
+ @files = Array.new
+ file = Hash.new
+
+ @total_list = parsing_list[0]
+ for t in 1..(parsing_list.length-1)
+ parsing_file = parsing_list[t].split(" ")
+ file["auth"] = parsing_file[0]
+ file["size"] = parsing_file[4]
+ file["date"] = parsing_file[5] + " " + parsing_file[6] + " " + parsing_file[7]
+ file["name"] = parsing_file[8]
+ @files << file
+ file = Hash.new
+ end
+ puts @files
+ return @files
+ end
+
+ def checkDir
+ files = file_directory(params[:path])
+ render :json => {:file => files , :current => @current_dir}
+ end
end
diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb
index c3d0cc0..1b0f11b 100644
--- a/app/controllers/home_controller.rb
+++ b/app/controllers/home_controller.rb
@@ -1,31 +1,38 @@
class HomeController < ApplicationController
- def index
- @current_dir = "/mnt"
- file_directory(@current_dir)
- end
- def file_download
- @file_name = params[:file_name].gsub(" ", "/")
- if !@file_name.nil?
- send_file @file_name
- else
- puts "file name is nil"
- redirect_to '/home/index'
- end
- end
+ def index
+ @current_dir = "/mnt"
+ file_directory(@current_dir)
+ end
- def make_directory
- current_dir = params[:current_dir]
- directory_name = params[:directory_name]
- puts "mkdir #{current_dir}/#{directory_name}"
- `sudo mkdir #{current_dir}/#{directory_name}`
- redirect_to '/home/index'
- end
+ def file_download
+ @file_name = params[:file_name].gsub(" ", "/")
+ if !@file_name.nil?
+ send_file @file_name
+ else
+ puts "file name is nil"
+ redirect_to '/home/index'
+ end
+ end
- def delete_file
- file_name = params[:file_name]
- puts "rm #{file_name} -rf"
- `sudo rm #{file_name} -rf`
- redirect_to '/home/index'
- end
+ def make_directory
+ current_dir = params[:current_dir]
+ directory_name = params[:directory_name]
+ # make directory
+ command = String.new
+ command << "sudo mkdir #{current_dir}/#{directory_name}"
+ puts command
+ `#{command}`
+ redirect_to '/home/index'
+ end
+
+ def delete_file
+ file_name = params[:file_name]
+ # delete file
+ command = String.new
+ command << "sudo rm -rf #{file_name}"
+ puts command
+ `#{command}`
+ redirect_to '/home/index'
+ end
end
diff --git a/app/controllers/volume_controller.rb b/app/controllers/volume_controller.rb
index ada0be3..86d380f 100644
--- a/app/controllers/volume_controller.rb
+++ b/app/controllers/volume_controller.rb
@@ -2,11 +2,6 @@ class VolumeController < ApplicationController
def index
file_directory("/mnt")
- get_conf
- end
-
- def get_df
- return `df -P`
end
def file_upload
@@ -14,64 +9,71 @@ class VolumeController < ApplicationController
mnt_dir = String.new
mnt_dest = String.new
file = params[:file]
- s = df.split("\n")
- s.each do |t|
- if t.include? params[:volume_name]
- mnt_dir = t.split(" ")[5]
+ df.each do |t|
+ if t['Filesystem'].include? params[:volume_name]
+ mnt_dir = t['Mounted on']
end
end
mnt_dest = mnt_dir + "/" + file.original_filename
# change permission
command = String.new
- command << "sudo chmod 777 " + mnt_dir
+ command << "sudo chmod 777 #{mnt_dir}"
puts command
`#{command}`
+ # upload file
u = AvatarUploader.new(mnt_dir)
u.store!(file)
redirect_to '/volume/index'
end
def volume_mount
- get_conf
+ conf = get_conf
volume_name = params[:volume_name]
mount_point = params[:mount_point]
# make command string
command = String.new
- command << "sudo mount -t glusterfs " + @config["host_ip"].to_s + ":/" + volume_name + " " + mount_point
+ command << "sudo mount -t glusterfs #{conf['host_ip']}:/#{volume_name} #{mount_point}"
puts command
`#{command}`
redirect_to '/volume/index'
end
def volume_unmount
- get_conf
+ conf = get_conf
volume_name = params[:volume_name]
# make command string
command = String.new
- command << "sudo umount " + @config["host_ip"].to_s + ":/" + volume_name
+ command << "sudo umount #{conf['host_ip']}:/#{volume_name}"
puts command
`#{command}`
redirect_to '/volume/index'
end
def volume_create
- get_conf
+ conf = get_conf
volume_name = params[:volume_name]
volume_type = params[:volume_type]
num_of_brick = params[:num_of_brick]
bricks = params[:bricks]
# make command string
command = String.new
- command << "sshpass -p" + @config["user_password"].to_s
- command << " ssh "
-
- command << @config["user_name"].to_s + "@" + @config["host_ip"].to_s
- command << " gluster volume create " + volume_name + " "
+ command << "sshpass -p#{conf['user_password']} "
+ command << "ssh #{conf['user_name']}@#{conf['host_ip']} "
+ command << "gluster volume create #{volume_name} "
if !volume_type.include? "Distribute"
- command << volume_type.downcase + " " + num_of_brick + " "
+ command << "#{volume_type.downcase} #{num_of_brick}"
end
+ conf_all = get_conf_all
bricks.each do |t|
- command << t + " "
+ host_name = t.split(":/")[0]
+ brick_name = t.split(":/")[1]
+ host_ip = ""
+ conf_all.each do |u|
+ next if !u['host_name'].eql? host_name
+ host_ip = u['host_ip']
+ end
+ brick = "#{host_ip}:/#{brick_name}"
+ command << "#{brick} "
end
command << "force"
puts command
@@ -80,45 +82,39 @@ class VolumeController < ApplicationController
end
def volume_stop
- get_conf
+ conf = get_conf
volume_name = params[:volume_name]
# make command string
command = String.new
- command << "yes | sshpass -p" + @config["user_password"].to_s
- command << " ssh "
-
- command << @config["user_name"].to_s + "@" + @config["host_ip"].to_s
- command << " gluster volume stop " + volume_name
+ command << "yes | sshpass -p#{conf['user_password']} "
+ command << "ssh #{conf['user_name']}@#{conf['host_ip']} "
+ command << "gluster volume stop #{volume_name}"
puts command
`#{command}`
redirect_to '/volume/index'
end
def volume_start
- get_conf
+ conf = get_conf
volume_name = params[:volume_name]
# make command string
command = String.new
- command << "sshpass -p" + @config["user_password"].to_s
- command << " ssh "
-
- command << @config["user_name"].to_s + "@" + @config["host_ip"].to_s
- command << " gluster volume start " + volume_name.to_s
+ command << "sshpass -p#{conf['user_password']} "
+ command << "ssh #{conf['user_name']}@#{conf['host_ip']} "
+ command << " gluster volume start #{volume_name}"
puts command
`#{command}`
redirect_to '/volume/index'
end
def volume_delete
- get_conf
+ conf = get_conf
volume_name = params[:volume_name]
# make command string
command = String.new
- command << "yes | sshpass -p" + @config["user_password"].to_s
- command << " ssh "
-
- command << @config["user_name"].to_s + "@" + @config["host_ip"].to_s
- command << " gluster volume delete " + volume_name
+ command << "yes | sshpass -p#{conf['user_password']} "
+ command << "ssh #{conf['user_name']}@#{conf['host_ip']} "
+ command << " gluster volume delete #{volume_name}"
puts command
`#{command}`
redirect_to '/volume/index'
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index de6be79..674c794 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -1,2 +1,52 @@
module ApplicationHelper
+
+ def get_conf
+ config = Hash.new
+ one_node = Node.take
+ if !one_node.nil?
+ config["host_name"] = one_node.host_name
+ config["host_ip"] = one_node.host_ip
+ config["user_name"] = one_node.user_name
+ config["user_password"] = one_node.user_password
+ end
+ return config
+ end
+
+ def get_conf_all
+ config = Array.new
+ config_each = Hash.new
+ all_node = Node.all
+ all_node.each do |one_node|
+ config_each["host_name"] = one_node.host_name
+ config_each["host_ip"] = one_node.host_ip
+ config_each["user_name"] = one_node.user_name
+ config_each["user_password"] = one_node.user_password
+ config << config_each
+ config_each = Hash.new
+ end
+ return config
+ end
+
+ def get_df
+ df = Array.new
+ df_each = Hash.new
+ command = String.new
+ command << "df -hP"
+ puts command
+ output = `#{command}`.split("\n")
+ output.each do |t|
+ next if t.equal? output.first
+ s = t.split(' ')
+ df_each['Filesystem'] = s[0]
+ df_each['Size'] = s[1]
+ df_each['Used'] = s[2]
+ df_each['Avail'] = s[3]
+ df_each['Use%'] = s[4]
+ df_each['Mounted on'] = s[5]
+ df << df_each
+ df_each = Hash.new
+ end
+ return df
+ end
+
end
diff --git a/app/helpers/volume_helper.rb b/app/helpers/volume_helper.rb
index 0e37078..eef9b81 100644
--- a/app/helpers/volume_helper.rb
+++ b/app/helpers/volume_helper.rb
@@ -1,43 +1,28 @@
module VolumeHelper
- def get_conf
- @config = Hash.new
-
- one_node = Node.take
- if !one_node.nil?
- @config["host_name"] = one_node.host_name
- @config["host_ip"] = one_node.host_ip
- @config["user_name"] = one_node.user_name
- @config["user_password"] = one_node.user_password
- end
- return @config
- end
-
- def get_volumes
+ def volumes
volumes = Array.new
volume = Hash.new
- command = "df -P"
- df = `#{command}`
conf = get_conf
- command = "sshpass -p#{conf['user_password']} ssh #{conf['user_name']}@#{conf['host_ip']} gluster volume info"
- info = `#{command}`.split("\n")
- info << "\n"
- info.each do |t|
- next if t.equal? info.first
+ df = get_df
+ command = String.new
+ command << "sshpass -p#{conf['user_password']} "
+ command << "ssh #{conf['user_name']}@#{conf['host_ip']} "
+ command << "gluster volume info"
+ puts command
+ output = `#{command}`.split("\n")
+ output << "\n"
+ output.each do |t|
+ next if t.equal? output.first
if t.include? ":"
temp = t.split(":")
volume[temp[0]] = temp[1]
else
- String state = (df.include? volume['Volume Name'].delete(' ')) ? "mounted" : "unmounted"
- volume['Mount State'] = state
- if state.eql? "mounted"
- s = df.split("\n")
- s.each do |t|
- if t.include? volume['Volume Name'].delete(' ')
- mnt_point = t.split(" ")[5]
- volume['Mount Point'] = mnt_point
- end
- end
+ volume['Mount State'] = "unmounted"
+ df.each do |u|
+ next if !u['Filesystem'].include? volume['Volume Name'].delete(' ')
+ volume['Mount State'] = "mounted"
+ volume['Mount Point'] = u['Mounted on']
end
volumes << volume
volume = Hash.new
@@ -47,8 +32,7 @@ module VolumeHelper
end
def volume_info(volume)
- params = ['Type', 'Volume ID', 'Status', 'Number of Bricks', 'Transport-type',
- 'Bricks', 'Options Reconfigured', 'Mount State', 'Mount Point']
+ params = ['Type', 'Volume ID', 'Status', 'Number of Bricks', 'Transport-type', 'Bricks', 'Options Reconfigured', 'Mount State', 'Mount Point']
html = ''
html << "
"
params.each do |t|
diff --git a/app/views/home/index.html.erb b/app/views/home/index.html.erb
index 96abcc8..c8907b8 100644
--- a/app/views/home/index.html.erb
+++ b/app/views/home/index.html.erb
@@ -1,19 +1,9 @@
-
-
-
-
-
-
-
Dash Board
+
+
+
+
+
+
+
+
+
+
Total Users
+
2500
+
4% From last Week
+
-