// 一个发起Post请求的按钮 // url: 将把url转化为表单并使用Post方法提交 // title: 按钮上面的字 // 在当前页面打开连接 //不支持一个 key 里塞多个 value 的 url func NewPostButton(urlStr string, title string) kmgView.HtmlRenderer { formAction, err := url.Parse(urlStr) kmgErr.PanicIfError(err) query, err := url.ParseQuery(formAction.RawQuery) kmgErr.PanicIfError(err) formAction.RawQuery = "" id := kmgRand.MustCryptoRandToReadableAlphaNum(10) form := Form{ Id: id, NoSubmit: true, Url: formAction.String(), InputList: []kmgView.HtmlRenderer{}, IsHidden: true, } for k, v := range query { form.InputList = append(form.InputList, InputHidden{ Name: k, Value: v[0], }) } button := Button{ FormId: id, Type: ButtonTypeButton, Content: kmgView.String(title), Size: ButtonSizeExtraSmall, Color: ButtonColorInfo, } return kmgView.Html(form.HtmlRender() + button.HtmlRender()) }
func RunCmdWithPassword(cmd, password string) { cmdTpl := `#!/usr/bin/expect -f spawn %s expect "assword:" send "%s\r" interact` cmd = fmt.Sprintf(cmdTpl, cmd, password) tmpName := kmgRand.MustCryptoRandToReadableAlphaNum(5) tmpPath := "/tmp/" + tmpName kmgFile.MustAppendFile(tmpPath, []byte(cmd)) defer kmgFile.MustDelete(tmpPath) os.Setenv("HOME", kmgSys.GetCurrentUserHomeDir()) kmgCmd.CmdSlice([]string{tmpPath}).MustStdioRun() }
func (config DialogOpenWithButton) HtmlRender() string { targetId := "dialog_" + kmgRand.MustCryptoRandToReadableAlphaNum(10) return `<button type="button" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#` + targetId + `"> ` + kmgXss.H(config.ButtonTitle) + ` </button> <div class="modal fade" id="` + targetId + `" tabindex="-1" role="dialog"> <div class="modal-dialog" role="document"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button> </div> <div class="modal-body"> ` + config.DialogContent.HtmlRender() + ` </div> </div> </div> </div> ` }
func (d DropDown) HtmlRender() string { if d.id == "" { d.id = kmgRand.MustCryptoRandToReadableAlphaNum(20) } return tplDropDown(d) }
// 返回一个新的临时文件目录,保证父级目录存在,保证文件不存在. func NewTmpFilePath() string { return "/tmp/kmg_" + kmgRand.MustCryptoRandToReadableAlphaNum(8) }