func (c *Controller) SetPassword() (string, error) { TemplateStr, err := makeTemplate("set_password", "setPassword", &setPasswordPage{ Lang: c.Lang, IOS: utils.IOS(), Android: utils.Android(), Mobile: utils.Mobile()}) if err != nil { return "", utils.ErrInfo(err) } return TemplateStr, nil }
func Index(w http.ResponseWriter, r *http.Request) { r.ParseForm() parameters_ := make(map[string]interface{}) err := json.Unmarshal([]byte(r.PostFormValue("parameters")), ¶meters_) if err != nil { log.Error("%v", err) } log.Debug("parameters_=%", parameters_) parameters := make(map[string]string) for k, v := range parameters_ { parameters[k] = utils.InterfaceToStr(v) } lang := GetLang(w, r, parameters) sess, err := globalSessions.SessionStart(w, r) if err != nil { log.Error("%v", err) } defer sess.SessionRelease(w) sessUserId := GetSessUserId(sess) var key, myPrefix, status string var communityUsers []int64 var chatEnabled, analyticsDisabled string if utils.DB != nil && utils.DB.DB != nil { communityUsers, err = utils.DB.GetCommunityUsers() if err != nil { log.Error("%v", err) } if len(communityUsers) > 0 { myPrefix = utils.Int64ToStr(sessUserId) + "_" } status, err := utils.DB.Single("SELECT status FROM " + myPrefix + "my_table").String() // чтобы нельзя было зайти по локалке // :: - для маков if ok, _ := regexp.MatchString(`(\:\:)|(127\.0\.0\.1)`, r.RemoteAddr); ok { if status != "waiting_accept_new_key" && status != "waiting_set_new_key" { key, err = utils.DB.Single("SELECT private_key FROM " + myPrefix + "my_keys WHERE block_id = (SELECT max(block_id) FROM " + myPrefix + "my_keys)").String() if err != nil { log.Error("%v", err) } } } chatEnabled, err = utils.DB.Single(`SELECT chat_enabled FROM config`).String() if err != nil { log.Error("%v", err) } analyticsDisabled, err = utils.DB.Single(`SELECT analytics_disabled FROM config`).String() if err != nil { log.Error("%v", err) } } showIOSMenu := true // Когда меню не выдаем if utils.DB == nil || utils.DB.DB == nil { showIOSMenu = false } else { if status == "my_pending" { showIOSMenu = false } } if sessUserId == 0 { showIOSMenu = false } if showIOSMenu && utils.DB != nil && utils.DB.DB != nil { blockData, err := utils.DB.GetInfoBlock() if err != nil { log.Error("%v", err) } wTime := int64(12) wTimeReady := int64(2) log.Debug("wTime: %v / utils.Time(): %v / blockData[time]: %v", wTime, utils.Time(), utils.StrToInt64(blockData["time"])) // если время менее 12 часов от текущего, то выдаем не подвержденные, а просто те, что есть в блокчейне if utils.Time()-utils.StrToInt64(blockData["time"]) < 3600*wTime { lastBlockData, err := utils.DB.GetLastBlockData() if err != nil { log.Error("%v", err) } log.Debug("lastBlockData[lastBlockTime]: %v", lastBlockData["lastBlockTime"]) log.Debug("time.Now().Unix(): %v", utils.Time()) if utils.Time()-lastBlockData["lastBlockTime"] >= 3600*wTimeReady { showIOSMenu = false } } else { showIOSMenu = false } } if showIOSMenu && !utils.Mobile() { showIOSMenu = false } mobile := utils.Mobile() if ok, _ := regexp.MatchString("(?i)(iPod|iPhone|iPad|Android)", r.UserAgent()); ok { mobile = true } ios := utils.IOS() if ok, _ := regexp.MatchString("(?i)(iPod|iPhone|iPad)", r.UserAgent()); ok { ios = true } android := utils.Android() if ok, _ := regexp.MatchString("(?i)(Android)", r.UserAgent()); ok { android = true } var upgrade3 string if len(r.FormValue("upgrade3")) > 0 { upgrade3 = "1" } var upgrade4 string if len(r.FormValue("upgrade4")) > 0 { upgrade4 = "1" } formKey := r.FormValue("key") if len(formKey) > 0 { key = formKey // пишем в сессию, что бы ctrl+F5 не сбрасывал ключ (для авто-входа с dcoin.club) sess.Set("private_key", key) } else if len(key) == 0 { key = GetSessPrivateKey(w, r) } key = strings.Replace(key, "\r", "\n", -1) key = strings.Replace(key, "\n\n", "\n", -1) key = strings.Replace(key, "\n", "\\\n", -1) setLang := r.FormValue("lang") data, err := static.Asset("static/templates/index.html") t := template.New("template") t, err = t.Parse(string(data)) if err != nil { log.Error("%v", err) } b := new(bytes.Buffer) err = t.Execute(b, &index{ Upgrade3: upgrade3, Upgrade4: upgrade4, DbOk: true, Lang: globalLangReadOnly[lang], Key: key, SetLang: setLang, ShowIOSMenu: showIOSMenu, /*IOS: true, Android: false, Mobile: true})*/ IOS: ios, Android: android, ChatEnabled: chatEnabled, AnalyticsDisabled: analyticsDisabled, Mobile: mobile}) if err != nil { log.Error("%v", err) } w.Write(b.Bytes()) }
func (c *Controller) ChangePrimaryKey() (string, error) { var err error txType := "ChangePrimaryKey" txTypeId := utils.TypeInt(txType) timeNow := utils.Time() var myKeys []map[string]string if c.SessRestricted == 0 { myKeys, err = c.GetAll(`SELECT * FROM `+c.MyPrefix+`my_keys ORDER BY id DESC`, -1) } statusArray := map[string]string{"my_pending": c.Lang["local_pending"], "approved": c.Lang["status_approved"]} // узнаем, когда последний раз была смена ключа, чтобы не показывать юзеру страницу смены lastChangeKeyTime, err := c.Single("SELECT time FROM log_time_primary_key WHERE user_id = ? ORDER BY time DESC", c.SessUserId).Int64() if err != nil { return "", utils.ErrInfo(err) } limitsText := strings.Replace(c.Lang["change_primary_key_limits_text"], "[limit]", utils.Int64ToStr(c.Variables.Int64["limit_primary_key"]), -1) limitsText = strings.Replace(limitsText, "[period]", c.Periods[c.Variables.Int64["limit_primary_key_period"]], -1) var lastTxQueueTx, lastTxTx bool lastTx, err := c.GetLastTx(c.SessUserId, utils.TypesToIds([]string{"ChangePrimaryKey"}), 1, c.TimeFormat) lastTxFormatted := "" if len(lastTx) > 0 { lastTxFormatted, _ = utils.MakeLastTx(lastTx, c.Lang) if len(lastTx[0]["queue_tx"]) > 0 { lastTxQueueTx = true } if len(lastTx[0]["tx"]) > 0 { lastTxTx = true } } TemplateStr, err := makeTemplate("change_primary_key", "changePrimaryKey", &changePrimaryKeyPage{ Alert: c.Alert, Lang: c.Lang, ShowSignData: c.ShowSignData, SignData: "", UserId: c.SessUserId, CountSignArr: c.CountSignArr, LimitsText: limitsText, LastTxQueueTx: lastTxQueueTx, LastTxTx: lastTxTx, LastTxFormatted: lastTxFormatted, LastChangeKeyTime: lastChangeKeyTime, LastTx: lastTx, MyKeys: myKeys, StatusArray: statusArray, TimeNow: timeNow, TxType: txType, IOS: utils.IOS(), Android: utils.Android(), Mobile: utils.Mobile(), TxTypeId: txTypeId}) if err != nil { return "", utils.ErrInfo(err) } return TemplateStr, nil }
func (c *Controller) DcoinKey() (string, error) { var err error c.r.ParseForm() // на IOS/Android запрос ключа идет без сессии из objective C (UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://127.0.0.1:8089/ajax?controllerName=dcoinKey&ios=1"]]];) local := false // чтобы по локалке никто не украл приватный ключ if ok, _ := regexp.MatchString(`^(\:\:)|(127\.0\.0\.1)(:[0-9]+)?$`, c.r.RemoteAddr); ok { local = true } if utils.Mobile() && c.SessUserId == 0 && !local { return "", utils.ErrInfo(errors.New("Not local request from " + c.r.RemoteAddr)) } privKey := "" if len(c.r.FormValue("first")) > 0 { privKey, err = c.Single(`SELECT private_key FROM ` + c.MyPrefix + `my_keys WHERE status='my_pending'`).String() if err != nil { return "", utils.ErrInfo(err) } } else { privKey, _ = utils.GenKeys() } paramNoPass := utils.ParamType{X: 176, Y: 100, Width: 100, Bg_path: "static/img/k_bg.png"} paramPass := utils.ParamType{X: 167, Y: 93, Width: 118, Bg_path: "static/img/k_bg_pass.png"} var param utils.ParamType var privateKey string if len(c.r.FormValue("password")) > 0 { privateKey_, err := utils.Encrypt(utils.Md5(c.r.FormValue("password")), []byte(privKey)) privateKey = base64.StdEncoding.EncodeToString(privateKey_) if err != nil { return "", utils.ErrInfo(err) } param = paramPass } else { privateKey = strings.Replace(privKey, "-----BEGIN RSA PRIVATE KEY-----", "", -1) privateKey = strings.Replace(privateKey, "-----END RSA PRIVATE KEY-----", "", -1) param = paramNoPass } ios := false if ok, _ := regexp.MatchString("(iPod|iPhone|iPad)", c.r.UserAgent()); ok { ios = true } if len(c.r.FormValue("ios")) > 0 { ios = true } if ios || utils.Android() { buffer, err := utils.KeyToImg(privateKey, "", c.SessUserId, c.TimeFormat, param) if err != nil { return "", utils.ErrInfo(err) } c.w.Header().Set("Content-Type", "image/png") c.w.Header().Set("Content-Length", utils.IntToStr(len(buffer.Bytes()))) c.w.Header().Set("Content-Disposition", `attachment; filename="Dcoin-private-key-`+utils.Int64ToStr(c.SessUserId)+`.png"`) if _, err := c.w.Write(buffer.Bytes()); err != nil { return "", utils.ErrInfo(errors.New("unable to write image")) } } else { c.w.Header().Set("Content-Type", "text/plain") c.w.Header().Set("Content-Length", utils.IntToStr(len(privateKey))) c.w.Header().Set("Content-Disposition", `attachment; filename="Dcoin-private-key-`+utils.Int64ToStr(c.SessUserId)+`.txt"`) if _, err := c.w.Write([]byte(privateKey)); err != nil { return "", utils.ErrInfo(errors.New("unable to write text")) } } return "", nil }