Пример #1
0
func main() {
	c := sh.Command("sleep", "3")
	c.Start()
	err := c.WaitTimeout(time.Second * 1)
	if err != nil {
		fmt.Printf("timeout should happend: %v\n", err)
	}
	// timeout should be a session
	out, err := sh.Command("sleep", "2").SetTimeout(time.Second).Output()
	fmt.Printf("output:(%s), err(%v)\n", string(out), err)

	out, err = sh.Command("echo", "hello").SetTimeout(time.Second).Output()
	fmt.Printf("output:(%s), err(%v)\n", string(out), err)
}
Пример #2
0
func ShowLog() (string, error) {
	output, err := sh.Command("sh", "shells/log.sh").Output()
	if err != nil {
		return "", err
	}
	return string(output), nil
}
Пример #3
0
func svnUp(paths ...string) (int, JSON.Type, error) {

	var path string

	if len(paths) > 0 {
		path = paths[0]
	} else {
		path = svnDir
	}

	output, err := sh.Command("svn", "up", path).SetTimeout(time.Second * 30).Output()
	if err != nil {
		return -1, nil, helper.NewError("svn up command error", err)
	}

	lines := strings.Split(helper.Trim(string(output)), "\n")

	list := JSON.Type{}
	regLine := regexp.MustCompile(`^([U|D|A])\s+(.*)`)
	version := getVersion(lines[len(lines)-1])

	for _, line := range lines {
		if matches := regLine.FindAllStringSubmatch(line, -1); matches != nil {
			for _, match := range matches {
				a := match[1]
				path := match[2]
				path = path[len(svnDir):]
				list[path] = action.ParseAction(a)
			}
		}
	}

	return version, list, nil
}
Пример #4
0
func Revert(path string) error {
	root := filepath.Join(backupPath, path)
	err := utils.PathEnable(root)
	if err != nil {
		return err
	}

	_, err = sh.Command("rm", "-rf", deployPath).Output()
	if err != nil {
		return err
	}

	_, err = sh.Command("cp", "-r", root, deployPath).Output()
	if err != nil {
		return err
	}

	return nil
}
Пример #5
0
func handler(w http.ResponseWriter, r *http.Request) {
	q := r.FormValue("q")
	if len(q) < 0 {
		log.Fatal("q?")
	}

	out, err := sh.Command("./citationParseBulk", "\""+q+"\"").Output()
	if err != nil {
		log.Fatal(err)
	}

	w.Write(out)
}
Пример #6
0
func Minesweeper(rawurl string) (report *MinesweeperReport) {
	report = &MinesweeperReport{}
	report.Url = rawurl
	report.CreatedAt = time.Now().UTC().Format(time.UnixDate)

	args := []string{"--load-images=no", "--ignore-ssl-errors=yes", "--ssl-protocol=any", "--web-security=no", phantomScript, rawurl, options.UserAgent, strconv.Itoa(options.WaitAround)}
	out, err := sh.Command("phantomjs", args).SetTimeout(time.Second * 10).Output()
	if err != nil {
		report.Verdict = "error"
		report.Error = "exec phantomjs: " + err.Error()
		return
	}

	var urls []string

	lines := bytes.Split(out, []byte("\n"))
	for _, line := range lines {
		if bytes.HasPrefix(line, []byte("RESOURCE ")) {
			jsonResource := line[bytes.Index(line, []byte(" "))+1:]
			resource := MinesweeperReportResource{}
			err := json.Unmarshal(jsonResource, &resource)
			if err != nil {
				report.Verdict = "error"
				report.Error = "json unmarshal resource: " + err.Error()
				return
			}
			report.Resources = append(report.Resources, resource)

			urls = append(urls, resource.Url)
		}

		if bytes.HasPrefix(line, []byte("CHANGE ")) {
			jsonChange := line[bytes.Index(line, []byte(" "))+1:]
			change := MinesweeperReportChange{}
			err := json.Unmarshal(jsonChange, &change)
			if err != nil {
				report.Verdict = "error"
				report.Error = "json unmarshal change: " + err.Error()
				return
			}
			if strings.HasPrefix(change.Content, "[") {
				change.Content = strings.TrimPrefix(change.Content, "[")
				change.Content = strings.TrimSuffix(change.Content, "]")
			}
			if strings.HasPrefix(change.Context, "[") {
				change.Context = strings.TrimPrefix(change.Context, "[")
				change.Context = strings.TrimSuffix(change.Context, "]")
			}
			report.Changes = append(report.Changes, change)
		}
	}

	report.Hits = blacklist.Check(bls, urls)

	report.Verdict = "ok"
	if len(report.Hits) > 0 {
		report.Verdict = "suspicious"
	}

	return
}
Пример #7
0
func main() {
	sh.Command("curl", "-d", "''", "http://localhost:8000/mpesa").Run()
}
Пример #8
0
func init() {
	task.New("host.ProcStat", func(this *task.Task) interface{} {

		if IsConnected == false {
			return nil
		}
		cpu := proc.CPUPercent()
		mem := proc.MEMPercent()
		CallRpc("ReportUsage", rpc.UsageArgs{Detail.Id, cpu, mem})

		return nil
	}, time.Second*1)

	task.New("host.Deploy", func(this *task.Task) interface{} {

		if IsConnected == false {
			return nil
		}

		if deploying {
			this.Enable = false
			return nil
		}

		var err error

		deploying = true
		this.Enable = false
		defer func() {
			deploying = false
			if err != nil {
				log.Println(err)
				broadcastAll(Error, err.Error())
			} else {
				broadcastAll(Message, "deploy complete")
				time.Sleep(time.Second * 2)
				broadcastAll(Finish, "")
			}
		}()

		broadcastAll(Start, "mvn compiling..")
		err = helper.GetCMDOutputWithComplete(sh.Command("sh", shDir+"compile.sh").SetTimeout(time.Second * 60).Output())
		if err != nil {
			err = helper.NewError("mvn compile error!", err)
			return nil
		}

		broadcastAll(Message, "killing java..")
		if err = helper.GetCMDOutputWithComplete(sh.Command("sh", shDir+"kill.sh").SetTimeout(time.Second * 30).Output()); err != nil {
			err = helper.NewError("kill java error!", err)
			return nil
		}

		broadcastAll(Message, "backup whole project..")
		if err = helper.GetCMDOutputWithComplete(sh.Command("sh", shDir+"backup.sh").SetTimeout(time.Second * 30).Output()); err != nil {
			err = helper.NewError("backup error!", err)
			return nil
		}

		broadcastAll(Message, "execute mvn war:exploded")
		if err = helper.GetCMDOutputWithComplete(sh.Command("sh", shDir+"exploded.sh").SetTimeout(time.Second * 30).Output()); err != nil {
			err = helper.NewError("mvn war:exploded error!", err)
			return nil
		}

		broadcastAll(Message, "starting server..")
		if err = helper.GetCMDOutputWithComplete(sh.Command("sh", shDir+"startup.sh").SetTimeout(time.Second * 30).Output()); err != nil {
			err = helper.NewError("server start error!", err)
			return nil
		}

		return nil
	})
}