func (c *Controller) Upgrade5() (string, error) { log.Debug("Upgrade5") geolocationLat := "" geolocationLon := "" geolocation, err := c.Single("SELECT geolocation FROM " + c.MyPrefix + "my_table").String() if err != nil { return "", utils.ErrInfo(err) } if len(geolocation) > 0 { x := strings.Split(geolocation, ", ") if len(x) == 2 { geolocationLat = x[0] geolocationLon = x[1] } } saveAndGotoStep := strings.Replace(c.Lang["save_and_goto_step"], "[num]", "7", -1) upgradeMenu := utils.MakeUpgradeMenu(5) TemplateStr, err := makeTemplate("upgrade_5", "upgrade5", &upgrade5Page{ Alert: c.Alert, Lang: c.Lang, SaveAndGotoStep: saveAndGotoStep, UpgradeMenu: upgradeMenu, GeolocationLat: geolocationLat, GeolocationLon: geolocationLon, UserId: c.SessUserId, Mobile: utils.Mobile()}) if err != nil { return "", utils.ErrInfo(err) } return TemplateStr, nil }
func (c *Controller) Upgrade4() (string, error) { log.Debug("Upgrade4") videoUrl := "" // есть ли загруженное видео. data, err := c.OneRow("SELECT video_url_id, video_type FROM " + c.MyPrefix + "my_table").String() if err != nil { return "", utils.ErrInfo(err) } switch data["video_type"] { case "youtube": videoUrl = "http://www.youtube.com/embed/" + data["video_url_id"] case "vimeo": videoUrl = "http://www.vimeo.com/embed/" + data["video_url_id"] case "youku": videoUrl = "http://www.youku.com/embed/" + data["video_url_id"] } saveAndGotoStep := strings.Replace(c.Lang["save_and_goto_step"], "[num]", "6", -1) upgradeMenu := utils.MakeUpgradeMenu(4) var userVideoMp4 string path := *utils.Dir + "/public/" + utils.Int64ToStr(c.SessUserId) + "_user_video.mp4" if _, err := os.Stat(path); err == nil { userVideoMp4 = "/public/" + utils.Int64ToStr(c.SessUserId) + "_user_video.mp4" } var userVideoWebm string path = *utils.Dir + "/public/" + utils.Int64ToStr(c.SessUserId) + "_user_video.webm" if _, err := os.Stat(path); err == nil { userVideoWebm = "/public/" + utils.Int64ToStr(c.SessUserId) + "_user_video.webm" } var userVideoOgg string path = *utils.Dir + "/public/" + utils.Int64ToStr(c.SessUserId) + "_user_video.ogg" if _, err := os.Stat(path); err == nil { userVideoOgg = "/public/" + utils.Int64ToStr(c.SessUserId) + "_user_video.ogg" } TemplateStr, err := makeTemplate("upgrade_4", "upgrade4", &upgrade4Page{ Alert: c.Alert, Lang: c.Lang, SaveAndGotoStep: saveAndGotoStep, UpgradeMenu: upgradeMenu, VideoUrl: videoUrl, UserVideoMp4: userVideoMp4, UserVideoWebm: userVideoWebm, UserVideoOgg: userVideoOgg, Mobile: utils.Mobile(), UserId: c.SessUserId}) if err != nil { return "", utils.ErrInfo(err) } return TemplateStr, nil }
func (c *Controller) Upgrade1() (string, error) { log.Debug("Upgrade1") userFace := "" /*userProfile := "" path := "public/"+utils.Int64ToStr(c.SessUserId)+"_user_profile.jpg" if _, err := os.Stat(path); err == nil { userProfile = path }*/ path := *utils.Dir + "/public/" + utils.Int64ToStr(c.SessUserId) + "_user_face.jpg" if _, err := os.Stat(path); err == nil { userFace = "/public/" + utils.Int64ToStr(c.SessUserId) + "_user_face.jpg" } step := "1" nextStep := "2" photoType := "face" photo := userFace saveAndGotoStep := strings.Replace(c.Lang["save_and_goto_step"], "[num]", "3", -1) upgradeMenu := utils.MakeUpgradeMenu(1) TemplateStr, err := makeTemplate("upgrade_1_and_2", "upgrade1And2", &upgrade1Page{ Alert: c.Alert, Lang: c.Lang, CountSignArr: c.CountSignArr, ShowSignData: c.ShowSignData, SaveAndGotoStep: saveAndGotoStep, UpgradeMenu: upgradeMenu, UserId: c.SessUserId, PhotoType: photoType, Photo: photo, Step: step, NextStep: nextStep, IOS: utils.IOS(), Mobile: utils.Mobile()}) if err != nil { return "", utils.ErrInfo(err) } return TemplateStr, nil }
func (c *Controller) Upgrade0() (string, error) { log.Debug("first_select: %v", c.Parameters["first_select"]) if c.Parameters["first_select"] == "1" { c.ExecSql(`UPDATE ` + c.MyPrefix + `my_table SET first_select=1`) } data, err := c.OneRow("SELECT race, country FROM " + c.MyPrefix + "my_table").Int() if err != nil { return "", utils.ErrInfo(err) } race := data["race"] country := 0 if race > 0 { country = data["country"] } saveAndGotoStep := strings.Replace(c.Lang["save_and_goto_step"], "[num]", "2", -1) upgradeMenu := utils.MakeUpgradeMenu(0) TemplateStr, err := makeTemplate("upgrade_0", "upgrade0", &upgrade0Page{ Alert: c.Alert, Lang: c.Lang, CountSignArr: c.CountSignArr, ShowSignData: c.ShowSignData, SaveAndGotoStep: saveAndGotoStep, UpgradeMenu: upgradeMenu, UserId: c.SessUserId, Countries: consts.Countries, Country: country, Race: race, Mobile: utils.Mobile()}) if err != nil { return "", utils.ErrInfo(err) } return TemplateStr, nil }
func (c *Controller) Upgrade6() (string, error) { log.Debug("Upgrade6") var hostType string hostData, err := c.OneRow("SELECT http_host, tcp_host FROM " + c.MyPrefix + "my_table").String() if err != nil { return "", utils.ErrInfo(err) } // в режиме пула выдаем только хост ноды log.Debug("c.Community: %v", c.Community) log.Debug("c.PoolAdminUserId: %v", c.PoolAdminUserId) if c.Community /*&& len(data["http_host"]) == 0 && len(data["tcp_host"]) == 0*/ { hostType = "pool" hostData, err = c.OneRow("SELECT http_host, tcp_host FROM miners_data WHERE user_id = ?", c.PoolAdminUserId).String() if err != nil { return "", utils.ErrInfo(err) } if len(hostData) == 0 { hostData["http_host"] = "null http_host in miners_data" hostData["tcp_host"] = "null tcp_host in miners_data" } } else { // если смогли подключиться из вне ip, err := utils.GetHttpTextAnswer("http://api.ipify.org") if err != nil { return "", utils.ErrInfo(err) } /*httpHost, err := c.Single("SELECT http_host FROM "+c.MyPrefix+"my_table").String() if err!=nil { return "", utils.ErrInfo(err) } port := "8089" if len(httpHost) > 0 { re := regexp.MustCompile(`https?:\/\/(?:[0-9a-z\_\.\-]+):([0-9]+)`) match := re.FindStringSubmatch(httpHost) if len(match) != 0 { port = match[1]; } }*/ conn, err := net.DialTimeout("tcp", ip+":8089", 3*time.Second) log.Debug("ip: %v", ip) if err != nil { // если не смогли подключиться, то в JS будем искать рабочий пул и региться на нем. и дадим юзеру указать другие хост:ip hostType = "findPool" } else { hostType = "normal" defer conn.Close() hostData["http_host"] = ip + ":8089" hostData["tcp_host"] = ip + ":8088" } } // проверим, есть ли необработанные ключи в локальной табле nodePrivateKey, err := c.Single("SELECT private_key FROM " + c.MyPrefix + "my_node_keys WHERE block_id = 0").String() if err != nil { return "", utils.ErrInfo(err) } if len(nodePrivateKey) == 0 { // сгенерим ключ для нода priv, pub := utils.GenKeys() err = c.ExecSql("INSERT INTO "+c.MyPrefix+"my_node_keys ( public_key, private_key ) VALUES ( [hex], ? )", pub, priv) if err != nil { return "", utils.ErrInfo(err) } nodePrivateKey = priv } var profileHash, faceHash, videoHash string if _, err := os.Stat(*utils.Dir + "/public/" + utils.Int64ToStr(c.SessUserId) + "_user_face.jpg"); err == nil { file, err := ioutil.ReadFile(*utils.Dir + "/public/" + utils.Int64ToStr(c.SessUserId) + "_user_face.jpg") if err != nil { return "", utils.ErrInfo(err) } faceHash = string(utils.DSha256(file)) } if _, err := os.Stat(*utils.Dir + "/public/" + utils.Int64ToStr(c.SessUserId) + "_user_profile.jpg"); err == nil { file, err := ioutil.ReadFile(*utils.Dir + "/public/" + utils.Int64ToStr(c.SessUserId) + "_user_profile.jpg") if err != nil { return "", utils.ErrInfo(err) } profileHash = string(utils.DSha256(file)) } if _, err := os.Stat(*utils.Dir + "/public/" + utils.Int64ToStr(c.SessUserId) + "_user_video.mp4"); err == nil { file, err := ioutil.ReadFile(*utils.Dir + "/public/" + utils.Int64ToStr(c.SessUserId) + "_user_video.mp4") if err != nil { return "", utils.ErrInfo(err) } videoHash = string(utils.DSha256(file)) } text, err := utils.GetHttpTextAnswer("http://dcoin.club/pools") if err != nil { return "", utils.ErrInfo(err) } var pools_ []string err = json.Unmarshal([]byte(text), &pools_) if err != nil { return "", utils.ErrInfo(err) } log.Debug("pools: %v", pools_) rows, err := c.Query(c.FormatQuery(` SELECT user_id, http_host FROM miners_data WHERE user_id IN (` + strings.Join(pools_, ",") + `)`)) if err != nil { return "", utils.ErrInfo(err) } defer rows.Close() pools := make(map[string]string) for rows.Next() { var user_id, http_host string err = rows.Scan(&user_id, &http_host) if err != nil { return "", utils.ErrInfo(err) } pools[user_id] = http_host } poolsJs := "" for userId, httpHost := range pools { poolsJs = poolsJs + "[" + userId + ",'" + httpHost + "']," } poolsJs = poolsJs[:len(poolsJs)-1] videoUrlId, err := c.Single("SELECT video_url_id FROM " + c.MyPrefix + "my_table").String() if err != nil { return "", utils.ErrInfo(err) } saveAndGotoStep := strings.Replace(c.Lang["save_and_goto_step"], "[num]", "8", -1) upgradeMenu := utils.MakeUpgradeMenu(6) TemplateStr, err := makeTemplate("upgrade_6", "upgrade6", &upgrade6Page{ Alert: c.Alert, Lang: c.Lang, SaveAndGotoStep: saveAndGotoStep, UpgradeMenu: upgradeMenu, ShowSignData: c.ShowSignData, SignData: "", CountSignArr: c.CountSignArr, HttpHost: hostData["http_host"], TcpHost: hostData["tcp_host"], Community: c.Community, HostType: hostType, ProfileHash: profileHash, FaceHash: faceHash, VideoHash: videoHash, NodePrivateKey: nodePrivateKey, Pools: template.JS(poolsJs), UserId: c.SessUserId, VideoUrlId: videoUrlId, Mobile: utils.Mobile()}) if err != nil { return "", utils.ErrInfo(err) } return TemplateStr, nil }
func (c *Controller) Upgrade7() (string, error) { log.Debug("Upgrade7") txType := "NewMiner" txTypeId := utils.TypeInt(txType) timeNow := utils.Time() // Формируем контент для подписи myTable, err := c.OneRow("SELECT user_id, race, country, geolocation, http_host, tcp_host, face_coords, profile_coords, video_url_id, video_type FROM " + c.MyPrefix + "my_table").String() if err != nil { return "", utils.ErrInfo(err) } if len(myTable["video_url_id"]) == 0 { myTable["video_url_id"] = "null" } if len(myTable["video_type"]) == 0 { myTable["video_type"] = "null" } var profileHash, faceHash string if _, err := os.Stat(*utils.Dir + "/public/" + utils.Int64ToStr(c.SessUserId) + "_user_face.jpg"); err == nil { file, err := ioutil.ReadFile(*utils.Dir + "/public/" + utils.Int64ToStr(c.SessUserId) + "_user_face.jpg") if err != nil { return "", utils.ErrInfo(err) } faceHash = string(utils.DSha256(file)) } if _, err := os.Stat(*utils.Dir + "/public/" + utils.Int64ToStr(c.SessUserId) + "_user_profile.jpg"); err == nil { file, err := ioutil.ReadFile(*utils.Dir + "/public/" + utils.Int64ToStr(c.SessUserId) + "_user_profile.jpg") if err != nil { return "", utils.ErrInfo(err) } profileHash = string(utils.DSha256(file)) } latitude := "0" longitude := "0" if len(myTable["geolocation"]) > 0 { x := strings.Split(myTable["geolocation"], ", ") latitude = x[0] longitude = x[1] } // проверим, есть ли не обработанные ключи в локальной табле nodePublicKey, err := c.Single("SELECT public_key FROM " + c.MyPrefix + "my_node_keys WHERE block_id = 0").String() if err != nil { return "", utils.ErrInfo(err) } if len(nodePublicKey) == 0 { // сгенерим ключ для нода priv, pub := utils.GenKeys() err = c.ExecSql("INSERT INTO "+c.MyPrefix+"my_node_keys ( public_key, private_key ) VALUES ( [hex], ? )", pub, priv) if err != nil { return "", utils.ErrInfo(err) } } else { nodePublicKey = string(utils.BinToHex([]byte(nodePublicKey))) } saveAndGotoStep := strings.Replace(c.Lang["save_and_goto_step"], "[num]", "9", -1) upgradeMenu := utils.MakeUpgradeMenu(7) var noExistsMp4 bool if _, err := os.Stat(*utils.Dir + "/public/" + utils.Int64ToStr(c.SessUserId) + "_user_video.mp4"); os.IsNotExist(err) { noExistsMp4 = true } TemplateStr, err := makeTemplate("upgrade_7", "upgrade7", &upgrade7Page{ Alert: c.Alert, Lang: c.Lang, CountSignArr: c.CountSignArr, ShowSignData: c.ShowSignData, UserId: c.SessUserId, TimeNow: timeNow, TxType: txType, TxTypeId: txTypeId, NoExistsMp4: noExistsMp4, SignData: fmt.Sprintf("%v,%v,%v,%v,%v,%v,%v,%v,%v,%v,%v,%v,%v,%v,%v,%v", txTypeId, timeNow, c.SessUserId, myTable["race"], myTable["country"], latitude, longitude, myTable["http_host"], myTable["tcp_host"], faceHash, profileHash, myTable["face_coords"], myTable["profile_coords"], myTable["video_type"], myTable["video_url_id"], nodePublicKey), SaveAndGotoStep: saveAndGotoStep, UpgradeMenu: upgradeMenu, Latitude: latitude, Longitude: longitude, NodePublicKey: nodePublicKey, ProfileHash: profileHash, FaceHash: faceHash, Data: myTable, MyTable: myTable, Mobile: utils.Mobile()}) if err != nil { return "", utils.ErrInfo(err) } return TemplateStr, nil }
func (c *Controller) Upgrade3() (string, error) { log.Debug("Upgrade3") userProfile := *utils.Dir + "/public/" + utils.Int64ToStr(c.SessUserId) + "_user_profile.jpg" userFace := *utils.Dir + "/public/" + utils.Int64ToStr(c.SessUserId) + "_user_face.jpg" if _, err := os.Stat(userProfile); os.IsNotExist(err) { userProfile = "" } else { userProfile = "public/" + utils.Int64ToStr(c.SessUserId) + "_user_profile.jpg?r=" + utils.IntToStr(utils.RandInt(0, 99999)) } if _, err := os.Stat(userFace); os.IsNotExist(err) { userFace = "" } else { userFace = "public/" + utils.Int64ToStr(c.SessUserId) + "_user_face.jpg?r=" + utils.IntToStr(utils.RandInt(0, 99999)) } log.Debug("userProfile: %s", userProfile) log.Debug("userFace: %s", userFace) // текущий набор точек для шаблонов examplePoints, err := c.GetPoints(c.Lang) if err != nil { return "", utils.ErrInfo(err) } // точки, которые юзер уже отмечал data, err := c.OneRow("SELECT face_coords, profile_coords FROM " + c.MyPrefix + "my_table").String() if err != nil { return "", utils.ErrInfo(err) } faceCoords := "" profileCoords := "" if len(data["face_coords"]) > 0 { faceCoords = data["face_coords"] profileCoords = data["profile_coords"] } saveAndGotoStep := strings.Replace(c.Lang["save_and_goto_step"], "[num]", "5", -1) upgradeMenu := utils.MakeUpgradeMenu(3) TemplateStr, err := makeTemplate("upgrade_3", "upgrade3", &upgrade3Page{ Alert: c.Alert, Lang: c.Lang, CountSignArr: c.CountSignArr, ShowSignData: c.ShowSignData, SaveAndGotoStep: saveAndGotoStep, UpgradeMenu: upgradeMenu, UserId: c.SessUserId, FaceCoords: faceCoords, ProfileCoords: profileCoords, UserProfile: userProfile, UserFace: userFace, ExamplePoints: examplePoints, IOS: utils.IOS(), Mobile: utils.Mobile()}) if err != nil { return "", utils.ErrInfo(err) } return TemplateStr, nil }