瀏覽代碼

remove useless file

Alanyeung's Windows Laptop 4 年之前
父節點
當前提交
dfa22f3d7c
共有 3 個文件被更改,包括 0 次插入554 次删除
  1. 0 196
      mod/disk/smart_1/common.disabled
  2. 0 156
      mod/disk/smart_1/smart.go_disabled
  3. 0 202
      mod/disk/smart_1/structure.go_disabled

+ 0 - 196
mod/disk/smart_1/common.disabled

@@ -1,196 +0,0 @@
-package smart
-
-import (
-	"os"
-    "log"
-	"net/http"
-	"strconv"
-	"strings"
-	"errors"
-	"encoding/base64"
-	"bufio"
-	"io/ioutil"
-	"time"
-)
-
-/*
-	SYSTEM COMMON FUNCTIONS
-
-	This is a system function that put those we usually use function but not belongs to
-	any module / system.
-
-	E.g. fileExists / IsDir etc
-
-*/
-
-/*
-	Basic Response Functions
-
-	Send response with ease
-*/
-//Send text response with given w and message as string
-func sendTextResponse(w http.ResponseWriter, msg string) {
-	w.Write([]byte(msg))
-}
-
-//Send JSON response, with an extra json header
-func sendJSONResponse(w http.ResponseWriter, json string) {
-	w.Header().Set("Content-Type", "application/json")
-	w.Write([]byte(json))
-}
-
-func sendErrorResponse(w http.ResponseWriter, errMsg string) {
-	w.Header().Set("Content-Type", "application/json")
-	w.Write([]byte("{\"error\":\"" + errMsg + "\"}"))
-}
-
-func sendOK(w http.ResponseWriter) {
-	w.Header().Set("Content-Type", "application/json")
-	w.Write([]byte("\"OK\""))
-}
-/*
-	The paramter move function (mv)
-
-	You can find similar things in the PHP version of ArOZ Online Beta. You need to pass in
-	r (HTTP Request Object)
-	getParamter (string, aka $_GET['This string])
-
-	Will return
-	Paramter string (if any)
-	Error (if error)
-
-*/
-func mv(r *http.Request, getParamter string, postMode bool) (string, error) {
-	if postMode == false {
-		//Access the paramter via GET
-		keys, ok := r.URL.Query()[getParamter]
-
-		if !ok || len(keys[0]) < 1 {
-			//log.Println("Url Param " + getParamter +" is missing")
-			return "", errors.New("GET paramter " + getParamter + " not found or it is empty")
-		}
-
-		// Query()["key"] will return an array of items,
-		// we only want the single item.
-		key := keys[0]
-		return string(key), nil
-	} else {
-		//Access the parameter via POST
-		r.ParseForm()
-		x := r.Form.Get(getParamter)
-		if len(x) == 0 || x == "" {
-			return "", errors.New("POST paramter " + getParamter + " not found or it is empty")
-		}
-		return string(x), nil
-	}
-
-}
-
-func stringInSlice(a string, list []string) bool {
-    for _, b := range list {
-        if b == a {
-            return true
-        }
-    }
-    return false
-}
-
-
-func fileExists(filename string) bool {
-    _, err := os.Stat(filename)
-    if os.IsNotExist(err) {
-        return false
-    }
-    return true
-}
-
-
-func IsDir(path string) bool{
-	if (fileExists(path) == false){
-		return false
-	}
-	fi, err := os.Stat(path)
-    if err != nil {
-        log.Fatal(err)
-        return false
-    }
-    switch mode := fi.Mode(); {
-    case mode.IsDir():
-        return true
-    case mode.IsRegular():
-        return false
-	}
-	return false
-}
-
-func inArray(arr []string, str string) bool {
-	for _, a := range arr {
-	   if a == str {
-		  return true
-	   }
-	}
-	return false
- }
-
- func timeToString(targetTime time.Time) string{
-	 return targetTime.Format("2006-01-02 15:04:05")
- }
-
- func IntToString(number int) string{
-	return strconv.Itoa(number)
- }
-
- func StringToInt(number string) (int, error){
-	return strconv.Atoi(number)
- }
-
- func StringToInt64(number string) (int64, error){
-	i, err := strconv.ParseInt(number, 10, 64)
-	if err != nil {
-		return -1, err
-	}
-	return i, nil
- }
-
- func Int64ToString(number int64) string{
-	convedNumber:=strconv.FormatInt(number,10)
-	return convedNumber
- }
-
- func GetUnixTime() int64{
-	return time.Now().Unix()
- }
-
- func LoadImageAsBase64(filepath string) (string, error){
-	if !fileExists(filepath){
-		return "", errors.New("File not exists")
-	}
-	f, _ := os.Open(filepath)
-    reader := bufio.NewReader(f)
-    content, _ := ioutil.ReadAll(reader)
-	encoded := base64.StdEncoding.EncodeToString(content)
-	return string(encoded), nil
- }
-
- //Get the IP address of the current authentication user
-func ReflectUserIP(w http.ResponseWriter, r *http.Request) {
-    requestPort,_ :=  mv(r, "port", false)
-    showPort := false;
-    if (requestPort == "true"){
-        //Show port as well
-        showPort = true;
-    }
-    IPAddress := r.Header.Get("X-Real-Ip")
-    if IPAddress == "" {
-        IPAddress = r.Header.Get("X-Forwarded-For")
-    }
-    if IPAddress == "" {
-        IPAddress = r.RemoteAddr
-    }
-    if (!showPort){
-        IPAddress = IPAddress[:strings.LastIndex(IPAddress, ":")]
-
-    }
-    w.Write([]byte(IPAddress))
-    return;
-}

+ 0 - 156
mod/disk/smart_1/smart.go_disabled

@@ -1,156 +0,0 @@
-package smart
-
-/*
-	DISK SMART Service Listener
-	Original author: alanyeung
-	Rewritten by tobychui in Oct 2020 for system arch upgrade
-
-	This module is not the core part of aroz online system.
-	If you want to remove disk smart handler (e.g. running in VM?)
-	remove the corrisponding code in disk.go
-*/
-
-import (
-	"encoding/json"
-	"log"
-	"net/http"
-	"os/exec"
-	"runtime"
-	"errors"
-	"time"
-)
-
-// SMART was used for storing all Devices data
-type SMART struct {
-	Port       string       `json:"Port"`
-	DriveSmart *DeviceSMART `json:"SMART"`
-}
-
-type SMARTListener struct{
-	SystemSmartExecutable string
-	LastScanTime int64
-	SMARTInformation []*SMART
-	ReadingInProgress bool
-}
-
-// DiskSmartInit Desktop script initiation
-func NewSmartListener() (*SMARTListener, error){
-	var SystemSmartExecutable string = ""
-
-	log.Println("Starting SMART mointoring")
-	if !(fileExists("system/disk/smart/win/smartctl.exe") || fileExists("system/disk/smart/linux/smartctl_arm") || fileExists("system/disk/smart/linux/smartctl_arm64") || fileExists("system/disk/smart/linux/smartctl_i386")) {
-		return &SMARTListener{}, errors.New("Smartctl.exe not found")
-	}
-	if runtime.GOOS == "windows" {
-		SystemSmartExecutable = "./system/disk/smart/win/smartctl.exe"
-	} else if runtime.GOOS == "linux" {
-		if runtime.GOARCH == "arm" {
-			SystemSmartExecutable = "./system/disk/smart/linux/smartctl_armv6"
-		}
-		if runtime.GOARCH == "arm64" {
-			SystemSmartExecutable = "./system/disk/smart/linux/smartctl_armv6"
-		}
-		if runtime.GOARCH == "386" {
-			SystemSmartExecutable = "./system/disk/smart/linux/smartctl_i386"
-		}
-		if runtime.GOARCH == "amd64" {
-			SystemSmartExecutable = "./system/disk/smart/linux/smartctl_i386"
-		}
-	} else {
-		return &SMARTListener{}, errors.New("Not supported platform")
-	}
-	return &SMARTListener{
-		SystemSmartExecutable: SystemSmartExecutable,
-		LastScanTime: 0,
-		SMARTInformation: []*SMART{},
-		ReadingInProgress: false,
-	},nil
-}
-
-// ReadSMART xxx
-func (s *SMARTListener)ReadSMART() []*SMART {
-	if time.Now().Unix()-s.LastScanTime > 30 {
-		if (s.ReadingInProgress == false){
-			//Set reading flag to true
-			s.ReadingInProgress = true;
-			s.SMARTInformation = []*SMART{}
-			//Scan disk
-			cmd := exec.Command(s.SystemSmartExecutable, "--scan", "--json=c")
-			out, _ := cmd.CombinedOutput()
-			Devices := new(DevicesList)
-			DevicesOutput := string(out)
-			json.Unmarshal([]byte(DevicesOutput), &Devices)
-			for _, element := range Devices.Devices {
-				//Load SMART for each drive
-				cmd := exec.Command(s.SystemSmartExecutable, "-i", element.Name, "-a", "--json=c")
-				out, err := cmd.CombinedOutput()
-				if err != nil{
-					//log.Println(string(out), err);
-				}
-				InvSMARTInformation := new(DeviceSMART)
-				SMARTOutput := string(out)
-				json.Unmarshal([]byte(SMARTOutput), &InvSMARTInformation)
-				if len(InvSMARTInformation.Smartctl.Messages) > 0 {
-					if InvSMARTInformation.Smartctl.Messages[0].Severity == "error" {
-						log.Println("[SMART Mointoring] Disk " + element.Name + " cannot be readed")
-					} else {
-						//putting everything into that struct array
-						n := SMART{Port: element.Name, DriveSmart: InvSMARTInformation}
-						s.SMARTInformation = append(s.SMARTInformation, &n)
-					}
-				} else {
-					//putting everything into that struct array
-					n := SMART{Port: element.Name, DriveSmart: InvSMARTInformation}
-					s.SMARTInformation = append(s.SMARTInformation, &n)
-				}
-
-			}
-			s.LastScanTime = time.Now().Unix()
-
-			//Set reading flag to false
-			s.ReadingInProgress = false;
-		}
-	}
-	return s.SMARTInformation
-}
-
-func (s *SMARTListener)GetSMART(w http.ResponseWriter, r *http.Request) {
-	jsonText, _ := json.Marshal(s.ReadSMART())
-	sendJSONResponse(w, string(jsonText))
-}
-
-func (s *SMARTListener)CheckDiskTable(w http.ResponseWriter, r *http.Request) {
-	disks, ok := r.URL.Query()["disk"]
-	if !ok || len(disks[0]) < 1 {
-		log.Println("Parameter DISK not found.")
-		return
-	}
-
-	DiskStatus := new(DeviceSMART)
-	for _, info := range s.ReadSMART() {
-		if info.Port == disks[0] {
-			DiskStatus = info.DriveSmart
-		}
-	}
-	JSONStr, _ := json.Marshal(DiskStatus.AtaSmartAttributes.Table)
-	//send!
-	sendJSONResponse(w, string(JSONStr))
-}
-
-func (s *SMARTListener)CheckDiskTestStatus(w http.ResponseWriter, r *http.Request) {
-	disks, ok := r.URL.Query()["disk"]
-	if !ok || len(disks[0]) < 1 {
-		log.Println("Parameter DISK not found.")
-		return
-	}
-
-	DiskTestStatus := new(DeviceSMART)
-	for _, info := range s.ReadSMART() {
-		if info.Port == disks[0] {
-			DiskTestStatus = info.DriveSmart
-		}
-	}
-	JSONStr, _ := json.Marshal(DiskTestStatus.AtaSmartData.SelfTest.Status)
-	//send!
-	sendJSONResponse(w, string(JSONStr))
-}

+ 0 - 202
mod/disk/smart_1/structure.go_disabled

@@ -1,202 +0,0 @@
-package smart
-
-// DevicesList was used for storing the disk scanning result
-type DevicesList struct {
-	JSONFormatVersion []int `json:"json_format_version"`
-	Smartctl          struct {
-		Version      []int    `json:"version"`
-		SvnRevision  string   `json:"svn_revision"`
-		PlatformInfo string   `json:"platform_info"`
-		BuildInfo    string   `json:"build_info"`
-		Argv         []string `json:"argv"`
-		Messages     []struct {
-			String   string `json:"string"`
-			Severity string `json:"severity"`
-		} `json:"messages"`
-		ExitStatus int `json:"exit_status"`
-	} `json:"smartctl"`
-	Devices []struct {
-		Name     string `json:"name"`
-		InfoName string `json:"info_name"`
-		Type     string `json:"type"`
-		Protocol string `json:"protocol"`
-	} `json:"devices"`
-}
-
-// DeviceSMART was used for storing each disk smart information
-type DeviceSMART struct {
-	JSONFormatVersion []int `json:"json_format_version"`
-	Smartctl          struct {
-		Version      []int    `json:"version"`
-		SvnRevision  string   `json:"svn_revision"`
-		PlatformInfo string   `json:"platform_info"`
-		BuildInfo    string   `json:"build_info"`
-		Argv         []string `json:"argv"`
-		Messages     []struct {
-			String   string `json:"string"`
-			Severity string `json:"severity"`
-		} `json:"messages"`
-		ExitStatus int `json:"exit_status"`
-	} `json:"smartctl"`
-	Device struct {
-		Name     string `json:"name"`
-		InfoName string `json:"info_name"`
-		Type     string `json:"type"`
-		Protocol string `json:"protocol"`
-	} `json:"device"`
-	ModelFamily  string `json:"model_family"`
-	ModelName    string `json:"model_name"`
-	SerialNumber string `json:"serial_number"`
-	Wwn          struct {
-		Naa int   `json:"naa"`
-		Oui int   `json:"oui"`
-		ID  int64 `json:"id"`
-	} `json:"wwn"`
-	FirmwareVersion string `json:"firmware_version"`
-	UserCapacity    struct {
-		Blocks int   `json:"blocks"`
-		Bytes  int64 `json:"bytes"`
-	} `json:"user_capacity"`
-	LogicalBlockSize   int  `json:"logical_block_size"`
-	PhysicalBlockSize  int  `json:"physical_block_size"`
-	RotationRate       int  `json:"rotation_rate"`
-	InSmartctlDatabase bool `json:"in_smartctl_database"`
-	AtaVersion         struct {
-		String     string `json:"string"`
-		MajorValue int    `json:"major_value"`
-		MinorValue int    `json:"minor_value"`
-	} `json:"ata_version"`
-	SataVersion struct {
-		String string `json:"string"`
-		Value  int    `json:"value"`
-	} `json:"sata_version"`
-	InterfaceSpeed struct {
-		Max struct {
-			SataValue      int    `json:"sata_value"`
-			String         string `json:"string"`
-			UnitsPerSecond int    `json:"units_per_second"`
-			BitsPerUnit    int    `json:"bits_per_unit"`
-		} `json:"max"`
-		Current struct {
-			SataValue      int    `json:"sata_value"`
-			String         string `json:"string"`
-			UnitsPerSecond int    `json:"units_per_second"`
-			BitsPerUnit    int    `json:"bits_per_unit"`
-		} `json:"current"`
-	} `json:"interface_speed"`
-	LocalTime struct {
-		TimeT   int    `json:"time_t"`
-		Asctime string `json:"asctime"`
-	} `json:"local_time"`
-	SmartStatus struct {
-		Passed bool `json:"passed"`
-	} `json:"smart_status"`
-	AtaSmartData struct {
-		OfflineDataCollection struct {
-			Status struct {
-				Value  int    `json:"value"`
-				String string `json:"string"`
-			} `json:"status"`
-			CompletionSeconds int `json:"completion_seconds"`
-		} `json:"offline_data_collection"`
-		SelfTest struct {
-			Status struct {
-				Value  int    `json:"value"`
-				String string `json:"string"`
-				Passed bool   `json:"passed"`
-			} `json:"status"`
-			PollingMinutes struct {
-				Short      int `json:"short"`
-				Extended   int `json:"extended"`
-				Conveyance int `json:"conveyance"`
-			} `json:"polling_minutes"`
-		} `json:"self_test"`
-		Capabilities struct {
-			Values                        []int `json:"values"`
-			ExecOfflineImmediateSupported bool  `json:"exec_offline_immediate_supported"`
-			OfflineIsAbortedUponNewCmd    bool  `json:"offline_is_aborted_upon_new_cmd"`
-			OfflineSurfaceScanSupported   bool  `json:"offline_surface_scan_supported"`
-			SelfTestsSupported            bool  `json:"self_tests_supported"`
-			ConveyanceSelfTestSupported   bool  `json:"conveyance_self_test_supported"`
-			SelectiveSelfTestSupported    bool  `json:"selective_self_test_supported"`
-			AttributeAutosaveEnabled      bool  `json:"attribute_autosave_enabled"`
-			ErrorLoggingSupported         bool  `json:"error_logging_supported"`
-			GpLoggingSupported            bool  `json:"gp_logging_supported"`
-		} `json:"capabilities"`
-	} `json:"ata_smart_data"`
-	AtaSctCapabilities struct {
-		Value                         int  `json:"value"`
-		ErrorRecoveryControlSupported bool `json:"error_recovery_control_supported"`
-		FeatureControlSupported       bool `json:"feature_control_supported"`
-		DataTableSupported            bool `json:"data_table_supported"`
-	} `json:"ata_sct_capabilities"`
-	AtaSmartAttributes struct {
-		Revision int `json:"revision"`
-		Table    []struct {
-			ID         int    `json:"id"`
-			Name       string `json:"name"`
-			Value      int    `json:"value"`
-			Worst      int    `json:"worst"`
-			Thresh     int    `json:"thresh"`
-			WhenFailed string `json:"when_failed"`
-			Flags      struct {
-				Value         int    `json:"value"`
-				String        string `json:"string"`
-				Prefailure    bool   `json:"prefailure"`
-				UpdatedOnline bool   `json:"updated_online"`
-				Performance   bool   `json:"performance"`
-				ErrorRate     bool   `json:"error_rate"`
-				EventCount    bool   `json:"event_count"`
-				AutoKeep      bool   `json:"auto_keep"`
-			} `json:"flags"`
-			Raw struct {
-				Value  int    `json:"value"`
-				String string `json:"string"`
-			} `json:"raw"`
-		} `json:"table"`
-	} `json:"ata_smart_attributes"`
-	PowerOnTime struct {
-		Hours   int `json:"hours"`
-		Minutes int `json:"minutes"`
-	} `json:"power_on_time"`
-	PowerCycleCount int `json:"power_cycle_count"`
-	Temperature     struct {
-		Current int `json:"current"`
-	} `json:"temperature"`
-	AtaSmartSelfTestLog struct {
-		Standard struct {
-			Revision int `json:"revision"`
-			Table    []struct {
-				Type struct {
-					Value  int    `json:"value"`
-					String string `json:"string"`
-				} `json:"type"`
-				Status struct {
-					Value  int    `json:"value"`
-					String string `json:"string"`
-					Passed bool   `json:"passed"`
-				} `json:"status,omitempty"`
-				LifetimeHours int `json:"lifetime_hours"`
-			} `json:"table"`
-			Count              int `json:"count"`
-			ErrorCountTotal    int `json:"error_count_total"`
-			ErrorCountOutdated int `json:"error_count_outdated"`
-		} `json:"standard"`
-	} `json:"ata_smart_self_test_log"`
-	AtaSmartSelectiveSelfTestLog struct {
-		Revision int `json:"revision"`
-		Table    []struct {
-			LbaMin int `json:"lba_min"`
-			LbaMax int `json:"lba_max"`
-			Status struct {
-				Value  int    `json:"value"`
-				String string `json:"string"`
-			} `json:"status"`
-		} `json:"table"`
-		Flags struct {
-			Value                int  `json:"value"`
-			RemainderScanEnabled bool `json:"remainder_scan_enabled"`
-		} `json:"flags"`
-		PowerUpScanResumeMinutes int `json:"power_up_scan_resume_minutes"`
-	} `json:"ata_smart_selective_self_test_log"`
-}