Update top, footer
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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'
|
||||
|
||||
Reference in New Issue
Block a user