diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 45ea341..02d8264 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -2,13 +2,13 @@ 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 - + def get_conf @config = Hash.new output = `cat configure.conf`.split("\n") output.each do |t| if t.include? "project_path=" - @config["project_path"] = t.split("project_path=")[1] + @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=" @@ -23,14 +23,14 @@ class ApplicationController < ActionController::Base 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(" ") @@ -44,7 +44,7 @@ class ApplicationController < ActionController::Base puts @files return @files end - + def checkDir files = file_directory(params[:path]) render :json => {:file => files , :current => @current_dir} diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index 16490f4..93b6311 100644 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -11,7 +11,7 @@ class HomeController < ApplicationController current_dir = params[:current_dir] directory_name = params[:directory_name] puts "mkdir #{current_dir}/#{directory_name}" - `mkdir #{current_dir}/#{directory_name}` + `sudo mkdir #{current_dir}/#{directory_name}` redirect_to '/home/index' end @@ -19,7 +19,7 @@ class HomeController < ApplicationController def delete_file file_name = params[:file_name] puts "rm #{file_name} -rf" - `rm #{file_name} -rf` + `sudo rm #{file_name} -rf` redirect_to '/home/index' end end diff --git a/app/controllers/volume_controller.rb b/app/controllers/volume_controller.rb index d362a5e..cbf4a71 100644 --- a/app/controllers/volume_controller.rb +++ b/app/controllers/volume_controller.rb @@ -1,89 +1,107 @@ class VolumeController < ApplicationController - def index - file_directory("/mnt") - get_conf - info = get_volume_info.split("\n") - if info.blank? - flash[:danger] = "Check Server" - else - parse_info(info) + def index + file_directory("/mnt") + get_conf + info = get_volume_info.split("\n") + if info.blank? + flash[:danger] = "Check Server" + else + parse_info(info) + end end - end - - def parse_info(info) - @volumes = Array.new - volume = Hash.new - df = get_df - info << "\n" - info.each do |t| - next if t.equal? info.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 - @volumes << volume + + def parse_info(info) + @volumes = Array.new volume = Hash.new - end + df = get_df + info << "\n" + info.each do |t| + next if t.equal? info.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 + @volumes << volume + volume = Hash.new + end + end end - end - def get_df - return `df -P` - end + def get_df + return `df -P` + end - def get_volume_info - return `sshpass -p#{@config["host_password"]} ssh #{@config["host_port"]} #{@config["host_user"]}@#{@config["host_ip"]} gluster volume info` - end - - def file_upload - file_name = params[:file] - uploader = AvatarUploader.new - uploader.store!(file_name) - redirect_to '/volume/info' - end - - def volume_mount - @config = get_conf - volume_name = params[:volume_name] - mount_point = params[:mount_point] - puts "mount -t glusterfs " + @config["host_ip"] + ":/" + volume_name + " " + mount_point - `mount -t glusterfs #{@config["host_ip"]}:/#{volume_name} #{mount_point}` - redirect_to '/volume/index' - end - - def volume_unmount - @config = get_conf - volume_name = params[:volume_name] - puts "umount " + @config["host_ip"] + ":/" + volume_name - `umount #{@config["host_ip"]}:/#{volume_name}` - redirect_to '/volume/index' - end + def get_volume_info + return `sshpass -p#{@config["host_password"]} ssh #{@config["host_port"]} #{@config["host_user"]}@#{@config["host_ip"]} \ + gluster volume info` + end - def volume_stop - @config = get_conf - volume_name = params[:volume_name] - puts "gluster volume stop " + volume_name - `yes | sshpass -p#{@config["host_password"]} ssh #{@config["host_port"]} #{@config["host_user"]}@#{@config["host_ip"]} gluster volume stop #{volume_name}` - redirect_to '/volume/index' - end + def file_upload + file_name = params[:file] + uploader = AvatarUploader.new + uploader.store!(file_name) + redirect_to '/volume/info' + end - def volume_start - @config = get_conf - volume_name = params[:volume_name] - puts "gluster volume start " + volume_name - `sshpass -p#{@config["host_password"]} ssh #{@config["host_port"]} #{@config["host_user"]}@#{@config["host_ip"]} gluster volume start #{volume_name}` - redirect_to '/volume/index' - end - - - def volume_delete - @config = get_conf - volume_name = params[:volume_name] - puts "gluster volume delete " + volume_name - `yes | sshpass -p#{@config["host_password"]} ssh #{@config["host_port"]} #{@config["host_user"]}@#{@config["host_ip"]} gluster volume delete #{volume_name}` - redirect_to '/volume/index' - end + def volume_mount + @config = get_conf + volume_name = params[:volume_name] + mount_point = params[:mount_point] + puts "mount -t glusterfs " + @config["host_ip"] + ":/" + volume_name + " " + mount_point + `mount -t glusterfs #{@config["host_ip"]}:/#{volume_name} #{mount_point}` + redirect_to '/volume/index' + end + + def volume_unmount + @config = get_conf + volume_name = params[:volume_name] + puts "umount " + @config["host_ip"] + ":/" + volume_name + `umount #{@config["host_ip"]}:/#{volume_name}` + redirect_to '/volume/index' + end + + def volume_create + volume_name = params[:volume_name] + bricks = params[:bricks] + bricks_str = "" + bricks.each do |t| + bricks_str << t + bricks_str << " " + end + puts "gluster volume create " + volume_name + " " + bricks_str + "force" + `sshpass -p#{@config["host_password"]} ssh #{@config["host_port"]} #{@config["host_user"]}@#{@config["host_ip"]} \ + gluster volume create #{volume_name} #{bricks_str} force` + redirect_to '/volume/index' + end + + def volume_stop + @config = get_conf + volume_name = params[:volume_name] + puts "gluster volume stop " + volume_name + `yes | sshpass -p#{@config["host_password"]} ssh #{@config["host_port"]} #{@config["host_user"]}@#{@config["host_ip"]} \ + gluster volume stop #{volume_name}` + redirect_to '/volume/index' + end + + def volume_start + @config = get_conf + volume_name = params[:volume_name] + puts "gluster volume start " + volume_name + `sshpass -p#{@config["host_password"]} ssh #{@config["host_port"]} #{@config["host_user"]}@#{@config["host_ip"]} \ + gluster volume start #{volume_name}` + redirect_to '/volume/index' + end + + + def volume_delete + @config = get_conf + volume_name = params[:volume_name] + puts "gluster volume delete " + volume_name + `yes | sshpass -p#{@config["host_password"]} ssh #{@config["host_port"]} #{@config["host_user"]}@#{@config["host_ip"]} \ + gluster volume delete #{volume_name}` + redirect_to '/volume/index' + end end diff --git a/app/views/volume/index.html.erb b/app/views/volume/index.html.erb index 3b8089d..8a668db 100644 --- a/app/views/volume/index.html.erb +++ b/app/views/volume/index.html.erb @@ -1,268 +1,376 @@ - -