本文整理匯總了Golang中github.com/c-darwin/dcoin-go/packages/utils.Mobile函數的典型用法代碼示例。如果您正苦於以下問題:Golang Mobile函數的具體用法?Golang Mobile怎麽用?Golang Mobile使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Mobile函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Login
func (c *Controller) Login() (string, error) {
var pool_tech_works int
funcMap := template.FuncMap{
"noescape": func(s string) template.HTML {
return template.HTML(s)
},
}
data, err := static.Asset("static/templates/login.html")
if err != nil {
return "", err
}
modal, err := static.Asset("static/templates/modal.html")
if err != nil {
return "", err
}
t := template.Must(template.New("template").Funcs(funcMap).Parse(string(data)))
t = template.Must(t.Parse(string(modal)))
b := new(bytes.Buffer)
// есть ли установочный пароль и был ли начально записан ключ
var setupPassword bool
if !c.Community {
setupPassword_, err := c.Single("SELECT setup_password FROM config").String()
if err != nil {
return "", err
}
myKey, err := c.GetMyPublicKey(c.MyPrefix)
if err != nil {
return "", err
}
if len(myKey) == 0 && (len(setupPassword_) > 0 || setupPassword_ == string(utils.DSha256(""))) {
setupPassword = true
}
}
//fmt.Println(c.Lang)
// проверим, не идут ли тех. работы на пуле
if len(c.NodeConfig["pool_admin_user_id"]) > 0 && c.NodeConfig["pool_admin_user_id"] != utils.Int64ToStr(c.UserId) && c.NodeConfig["pool_tech_works"] == "1" && c.Community {
pool_tech_works = 1
} else {
pool_tech_works = 0
}
err = t.ExecuteTemplate(b, "login", &loginStruct{
Lang: c.Lang,
MyModalIdName: "myModalLogin",
UserID: c.UserId,
PoolTechWorks: pool_tech_works,
SetupPassword: setupPassword,
Community: c.Community,
Desktop: utils.Desktop(),
Mobile: utils.Mobile()})
if err != nil {
return "", err
}
return b.String(), nil
}
示例2: Chat
func (c *Controller) Chat() (string, error) {
myChatName := utils.Int64ToStr(c.SessUserId)
// возможно у отпарвителя есть ник
name, err := c.Single(`SELECT name FROM users WHERE user_id = ?`, c.SessUserId).String()
if err != nil {
return "", utils.ErrInfo(err)
}
if len(name) > 0 {
myChatName = name
}
TemplateStr, err := makeTemplate("chat", "chat", &chatPage{
Community: c.Community,
CountSignArr: c.CountSignArr,
CountSign: c.CountSign,
Lang: c.Lang,
ShowSignData: c.ShowSignData,
SignData: "",
MyChatName: myChatName,
UserId: c.SessUserId,
IOS: utils.IOS(),
Mobile: utils.Mobile()})
if err != nil {
return "", utils.ErrInfo(err)
}
return TemplateStr, nil
}
示例3: Upgrade5
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
}
示例4: StartDaemons
func StartDaemons() {
utils.DaemonsChans = nil
daemonsStart := map[string]func(chBreaker chan bool, chAnswer chan string){"UnbanNodes": UnbanNodes, "FirstChangePkey": FirstChangePkey, "TestblockIsReady": TestblockIsReady, "TestblockGenerator": TestblockGenerator, "TestblockDisseminator": TestblockDisseminator, "Shop": Shop, "ReductionGenerator": ReductionGenerator, "QueueParserTx": QueueParserTx, "QueueParserTestblock": QueueParserTestblock, "QueueParserBlocks": QueueParserBlocks, "PctGenerator": PctGenerator, "Notifications": Notifications, "NodeVoting": NodeVoting, "MaxPromisedAmountGenerator": MaxPromisedAmountGenerator, "MaxOtherCurrenciesGenerator": MaxOtherCurrenciesGenerator, "ElectionsAdmin": ElectionsAdmin, "Disseminator": Disseminator, "Confirmations": Confirmations, "Connector": Connector, "Clear": Clear, "CleaningDb": CleaningDb, "CfProjects": CfProjects, "BlocksCollection": BlocksCollection, "Exchange": Exchange, "AutoUpdate": AutoUpdate}
if utils.Mobile() {
daemonsStart = map[string]func(chBreaker chan bool, chAnswer chan string){"UnbanNodes": UnbanNodes, "FirstChangePkey": FirstChangePkey, "QueueParserTx": QueueParserTx, "Notifications": Notifications, "Disseminator": Disseminator, "Confirmations": Confirmations, "Connector": Connector, "Clear": Clear, "CleaningDb": CleaningDb, "BlocksCollection": BlocksCollection}
}
if *utils.TestRollBack == 1 {
daemonsStart = map[string]func(chBreaker chan bool, chAnswer chan string){"BlocksCollection": BlocksCollection}
}
if len(configIni["daemons"]) > 0 && configIni["daemons"] != "null" {
daemonsConf := strings.Split(configIni["daemons"], ",")
for _, fns := range daemonsConf {
log.Debug("start daemon %s", fns)
fmt.Println("start daemon ", fns)
var chBreaker chan bool = make(chan bool, 1)
var chAnswer chan string = make(chan string, 1)
utils.DaemonsChans = append(utils.DaemonsChans, &utils.DaemonsChansType{ChBreaker: chBreaker, ChAnswer: chAnswer})
go daemonsStart[fns](chBreaker, chAnswer)
}
} else if configIni["daemons"] != "null" {
for dName, fns := range daemonsStart {
log.Debug("start daemon %s", dName)
fmt.Println("start daemon ", fns)
var chBreaker chan bool = make(chan bool, 1)
var chAnswer chan string = make(chan string, 1)
utils.DaemonsChans = append(utils.DaemonsChans, &utils.DaemonsChansType{ChBreaker: chBreaker, ChAnswer: chAnswer})
go fns(chBreaker, chAnswer)
}
}
}
示例5: SetPassword
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
}
示例6: Upgrade4
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
}
示例7: Notifications
func (c *Controller) Notifications() (string, error) {
if c.SessRestricted != 0 {
return "", utils.ErrInfo(errors.New("Permission denied"))
}
var err error
data, err := c.OneRow(`
SELECT email,
sms_http_get_request,
use_smtp,
smtp_server,
smtp_port,
smtp_ssl,
smtp_auth,
smtp_username,
smtp_password
FROM ` + c.MyPrefix + `my_table
`).String()
if err != nil {
return "", utils.ErrInfo(err)
}
myNotifications := make(map[string]map[string]string)
myNotifications_, err := c.GetAll("SELECT * FROM "+c.MyPrefix+"my_notifications ORDER BY sort ASC", -1)
for _, data := range myNotifications_ {
myNotifications[data["name"]] = map[string]string{"mobile": data["mobile"], "email": data["email"], "sms": data["sms"], "important": data["important"]}
}
log.Debug("myNotifications", myNotifications)
TemplateStr, err := makeTemplate("notifications", "notifications", ¬ificationsPage{
Alert: c.Alert,
Lang: c.Lang,
CountSignArr: c.CountSignArr,
ShowSignData: c.ShowSignData,
SignData: "",
MyNotifications: myNotifications,
NodeAdmin: c.NodeAdmin,
LangInt: c.LangInt,
Mobile: utils.Mobile(),
Data: data})
if err != nil {
return "", utils.ErrInfo(err)
}
return TemplateStr, nil
}
示例8: Upgrade1
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
}
示例9: Upgrade0
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
}
示例10: ElectionsAdmin
func ElectionsAdmin(chBreaker chan bool, chAnswer chan string) {
defer func() {
if r := recover(); r != nil {
log.Error("daemon Recovered", r)
panic(r)
}
}()
const GoroutineName = "ElectionsAdmin"
d := new(daemon)
d.DCDB = DbConnect(chBreaker, chAnswer, GoroutineName)
if d.DCDB == nil {
return
}
d.goRoutineName = GoroutineName
d.chAnswer = chAnswer
d.chBreaker = chBreaker
if utils.Mobile() {
d.sleepTime = 3600
} else {
d.sleepTime = 60
}
if !d.CheckInstall(chBreaker, chAnswer, GoroutineName) {
return
}
d.DCDB = DbConnect(chBreaker, chAnswer, GoroutineName)
if d.DCDB == nil {
return
}
err = d.notMinerSetSleepTime(1800)
if err != nil {
log.Error("%v", err)
return
}
BEGIN:
for {
log.Info(GoroutineName)
MonitorDaemonCh <- []string{GoroutineName, utils.Int64ToStr(utils.Time())}
// проверим, не нужно ли нам выйти из цикла
if CheckDaemonsRestart(chBreaker, chAnswer, GoroutineName) {
break BEGIN
}
err, restart := d.dbLock()
if restart {
break BEGIN
}
if err != nil {
if d.dPrintSleep(err, d.sleepTime) {
break BEGIN
}
continue BEGIN
}
blockId, err := d.GetBlockId()
if err != nil {
if d.unlockPrintSleep(utils.ErrInfo(err), d.sleepTime) {
break BEGIN
}
continue BEGIN
}
if blockId == 0 {
if d.unlockPrintSleep(utils.ErrInfo("blockId == 0"), d.sleepTime) {
break BEGIN
}
continue BEGIN
}
_, _, myMinerId, _, _, _, err := d.TestBlock()
if err != nil {
if d.unlockPrintSleep(utils.ErrInfo(err), d.sleepTime) {
break BEGIN
}
continue BEGIN
}
// а майнер ли я ?
if myMinerId == 0 {
if d.unlockPrintSleep(utils.ErrInfo(err), d.sleepTime) {
break BEGIN
}
continue BEGIN
}
variables, err := d.GetAllVariables()
curTime := utils.Time()
// проверим, прошло ли 2 недели с момента последнего обновления
adminTime, err := d.Single("SELECT time FROM admin").Int64()
if err != nil {
if d.unlockPrintSleep(utils.ErrInfo(err), d.sleepTime) {
break BEGIN
}
continue BEGIN
}
if curTime-adminTime <= variables.Int64["new_pct_period"] {
if d.unlockPrintSleep(utils.ErrInfo("14 day error"), d.sleepTime) {
break BEGIN
}
//.........這裏部分代碼省略.........
示例11: Clear
/*
если табла была очищена, то в parser.rollbackAI будет 0, поэтому нелья чистить таблы под нуль
*/
func Clear(chBreaker chan bool, chAnswer chan string) {
defer func() {
if r := recover(); r != nil {
log.Error("daemon Recovered", r)
panic(r)
}
}()
const GoroutineName = "Clear"
d := new(daemon)
d.DCDB = DbConnect(chBreaker, chAnswer, GoroutineName)
if d.DCDB == nil {
return
}
d.goRoutineName = GoroutineName
d.chAnswer = chAnswer
d.chBreaker = chBreaker
if utils.Mobile() {
d.sleepTime = 1800
} else {
d.sleepTime = 60
}
if !d.CheckInstall(chBreaker, chAnswer, GoroutineName) {
return
}
d.DCDB = DbConnect(chBreaker, chAnswer, GoroutineName)
if d.DCDB == nil {
return
}
BEGIN:
for {
log.Info(GoroutineName)
MonitorDaemonCh <- []string{GoroutineName, utils.Int64ToStr(utils.Time())}
// проверим, не нужно ли нам выйти из цикла
if CheckDaemonsRestart(chBreaker, chAnswer, GoroutineName) {
break BEGIN
}
err, restart := d.dbLock()
if restart {
break BEGIN
}
if err != nil {
if d.dPrintSleep(err, d.sleepTime) {
break BEGIN
}
continue BEGIN
}
blockId, err := d.GetBlockId()
if err != nil {
if d.unlockPrintSleep(utils.ErrInfo(err), d.sleepTime) {
break BEGIN
}
continue BEGIN
}
if blockId == 0 {
if d.unlockPrintSleep(utils.ErrInfo("blockId == 0"), d.sleepTime) {
break BEGIN
}
continue BEGIN
}
log.Debug("blockId: %d", blockId)
variables, err := d.GetAllVariables()
if err != nil {
if d.unlockPrintSleep(utils.ErrInfo(err), d.sleepTime) {
break BEGIN
}
continue BEGIN
}
// чистим log_transactions каждые 15 минут. Удаляем данные, которые старше 36 часов.
// Можно удалять и те, что старше rollback_blocks_2 + погрешность для времени транзакции (5-15 мин),
// но пусть будет 36 ч. - с хорошим запасом.
err = d.ExecSql("DELETE FROM log_transactions WHERE time < ?", utils.Time()-86400*3)
if err != nil {
if d.unlockPrintSleep(utils.ErrInfo(err), d.sleepTime) {
break BEGIN
}
continue BEGIN
}
// через rollback_blocks_2 с запасом 14400 блоков чистим таблу log_votes где есть del_block_id
// при этом, если проверяющих будет мало, то табла может захламиться незаконченными голосованиями
err = d.ExecSql("DELETE FROM log_votes WHERE del_block_id < ? AND del_block_id > 0", blockId-variables.Int64["rollback_blocks_2"]-14400)
if err != nil {
if d.unlockPrintSleep(utils.ErrInfo(err), d.sleepTime) {
break BEGIN
}
continue BEGIN
}
// через 14400 блоков чистим таблу wallets_buffer где есть del_block_id
err = d.ExecSql("DELETE FROM wallets_buffer WHERE del_block_id < ? AND del_block_id > 0", blockId-variables.Int64["rollback_blocks_2"]-14400)
//.........這裏部分代碼省略.........
示例12: Index
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()
//.........這裏部分代碼省略.........
示例13: Ajax
//.........這裏部分代碼省略.........
if utils.DB == nil || utils.DB.DB == nil {
log.Error("utils.DB == nil")
dbInit = false
}
if dbInit {
c.Variables, err = c.GetAllVariables()
var communityUsers []int64
communityUsers, err = c.GetCommunityUsers()
if err != nil {
log.Error("%v", err)
}
c.CommunityUsers = communityUsers
if len(communityUsers) > 0 {
c.Community = true
}
if c.Community {
poolAdminUserId, err := c.GetPoolAdminUserId()
if err != nil {
log.Error("%v", err)
}
c.PoolAdminUserId = poolAdminUserId
if c.SessUserId == poolAdminUserId {
c.PoolAdmin = true
}
c.MyPrefix = utils.Int64ToStr(sessUserId) + "_"
} else {
c.PoolAdmin = true
}
c.NodeAdmin, err = c.NodeAdminAccess(c.SessUserId, c.SessRestricted)
if err != nil {
log.Error("%v", err)
}
}
}
c.dbInit = dbInit
c.Parameters, err = c.GetParameters()
log.Debug("parameters=", c.Parameters)
lang := GetLang(w, r, c.Parameters)
log.Debug("lang", lang)
c.Lang = globalLangReadOnly[lang]
c.LangInt = int64(lang)
if lang == 42 {
c.TimeFormat = "2006-01-02 15:04:05"
} else {
c.TimeFormat = "2006-02-01 15:04:05"
}
if dbInit {
myNotice, err := c.GetMyNoticeData(sessRestricted, sessUserId, c.MyPrefix, globalLangReadOnly[lang])
if err != nil {
log.Error("%v", err)
}
c.MyNotice = myNotice
config, err := c.GetNodeConfig()
if err != nil {
log.Error("%v", err)
}
c.NodeConfig = config
// валюты
c.CurrencyList, err = c.GetCurrencyList(false)
if err != nil {
log.Error("%v", err)
}
}
r.ParseForm()
controllerName := r.FormValue("controllerName")
log.Debug("controllerName=", controllerName)
html := ""
//w.Header().Set("Access-Control-Allow-Origin", "*")
if ok, _ := regexp.MatchString(`^(?i)RestartDb|RewritePrimaryKeySave|SendPromisedAmountToPool|SaveEmailAndSendTestMess|sendMobile|DebugInfo|rewritePrimaryKey|EImportData|EDataBaseDump|AlertFromAdmin|Update|UpdateDcoin|exchangeAdmin|newPhoto|NodeConfigControl|SaveDecryptComment|EncryptChatMessage|GetChatMessages|SendToTheChat|SaveToken|SendToPool|CheckSetupPassword|getBlock|AcceptNewKeyStatus|availableKeys|ClearDbLite|ClearDb|UploadVideo|DcoinKey|SynchronizationBlockchain|PoolAddUsers|SaveQueue|AlertMessage|Menu|SaveHost|GetMinerDataMap|SignUpInPool|Check_sign|PoolDataBaseDump|GetSellerData|GenerateNewPrimaryKey|GenerateNewNodeKey|CheckNode|SignLogin|SaveNotifications|ProgressBar|MinersMap|GetMinerData|EncryptComment|Logout|SaveVideo|SaveShopData|SaveRaceCountry|MyNoticeData|HolidaysList|ClearVideo|CheckCfCurrency|WalletsListCfProject|SendTestEmail|SendSms|SaveUserCoords|SaveGeolocation|SaveEmailSms|Profile|DeleteVideo|CropPhoto$`, controllerName); !ok {
html = "Access denied 0"
} else {
pages := "RestartDb|DebugInfo|CheckSetupPassword|AcceptNewKeyStatus|availableKeys|CfCatalog|CfPagePreview|CfStart|Check_sign|CheckNode|GetBlock|GetMinerData|GetMinerDataMap|GetSellerData|Index|IndexCf|InstallStep0|InstallStep1|InstallStep2|Login|SynchronizationBlockchain|UpdatingBlockchain|Menu|SignUpInPool|SignLogin"
if utils.Mobile() { // На IOS можно сгенерить ключ без сессии
pages += "|DcoinKey"
}
if ok, _ := regexp.MatchString(`^(?i)`+pages+`$`, controllerName); !ok && c.SessUserId <= 0 {
html = "Access denied 1"
} else {
// без БД будет выдавать панику
if ok, _ := regexp.MatchString(`^(?i)GetChatMessages$`, controllerName); ok && !dbInit {
html = "Please wait. nill dbInit"
} else {
// вызываем контроллер в зависимости от шаблона
html, err = CallController(c, controllerName)
if err != nil {
log.Error("ajax error: %v", err)
}
}
}
}
w.Write([]byte(html))
}
示例14: FirstChangePkey
func FirstChangePkey(chBreaker chan bool, chAnswer chan string) {
defer func() {
if r := recover(); r != nil {
log.Error("daemon Recovered", r)
panic(r)
}
}()
const GoroutineName = "FirstChangePkey"
d := new(daemon)
d.DCDB = DbConnect(chBreaker, chAnswer, GoroutineName)
if d.DCDB == nil {
return
}
d.goRoutineName = GoroutineName
d.chAnswer = chAnswer
d.chBreaker = chBreaker
if utils.Mobile() {
d.sleepTime = 360
} else {
d.sleepTime = 60
}
if !d.CheckInstall(chBreaker, chAnswer, GoroutineName) {
return
}
d.DCDB = DbConnect(chBreaker, chAnswer, GoroutineName)
if d.DCDB == nil {
return
}
BEGIN:
for {
log.Info(GoroutineName)
MonitorDaemonCh <- []string{GoroutineName, utils.Int64ToStr(utils.Time())}
// проверим, не нужно ли нам выйти из цикла
if CheckDaemonsRestart(chBreaker, chAnswer, GoroutineName) {
break BEGIN
}
community, err := d.GetCommunityUsers()
if err != nil {
if d.dPrintSleep(err, d.sleepTime) {
break BEGIN
}
continue BEGIN
}
var uids []int64
if len(community) > 0 {
uids = community
} else {
myuid, err := d.GetMyUserId("")
if err != nil {
if d.dPrintSleep(err, d.sleepTime) {
break BEGIN
}
continue BEGIN
}
uids = append(uids, myuid)
}
log.Debug("uids %v", uids)
var status, myPrefix string
for _, uid := range uids {
if len(community) > 0 {
myPrefix = utils.Int64ToStr(uid) + "_"
}
status, err = d.Single(`SELECT status FROM ` + myPrefix + `my_table`).String()
if err != nil {
if d.dPrintSleep(err, d.sleepTime) {
break BEGIN
}
continue BEGIN
}
log.Debug("status: %v / myPrefix: %v", status, myPrefix)
if status == "waiting_accept_new_key" {
// если ключ кто-то сменил
userPublicKey, err := d.GetUserPublicKey(uid)
if err != nil {
if d.dPrintSleep(err, d.sleepTime) {
break BEGIN
}
continue BEGIN
}
myUserPublicKey, err := d.GetMyPublicKey(myPrefix)
if err != nil {
if d.dPrintSleep(err, d.sleepTime) {
break BEGIN
}
continue BEGIN
}
if !bytes.Equal(myUserPublicKey, []byte(userPublicKey)) {
log.Debug("myUserPublicKey:%s != userPublicKey:%s", utils.BinToHex(myUserPublicKey), utils.BinToHex(userPublicKey))
// удаляем старый ключ
err = d.ExecSql(`DELETE FROM ` + myPrefix + `my_keys`)
if err != nil {
if d.dPrintSleep(err, d.sleepTime) {
break BEGIN
}
continue BEGIN
//.........這裏部分代碼省略.........
示例15: TestblockIsReady
func TestblockIsReady(chBreaker chan bool, chAnswer chan string) {
defer func() {
if r := recover(); r != nil {
log.Error("daemon Recovered", r)
panic(r)
}
}()
const GoroutineName = "TestblockIsReady"
d := new(daemon)
d.DCDB = DbConnect(chBreaker, chAnswer, GoroutineName)
if d.DCDB == nil {
return
}
d.goRoutineName = GoroutineName
d.chAnswer = chAnswer
d.chBreaker = chBreaker
if utils.Mobile() {
d.sleepTime = 3600
} else {
d.sleepTime = 1
}
if !d.CheckInstall(chBreaker, chAnswer, GoroutineName) {
return
}
err = d.notMinerSetSleepTime(1800)
if err != nil {
log.Error("%v", err)
return
}
BEGIN:
for {
log.Info(GoroutineName)
MonitorDaemonCh <- []string{GoroutineName, utils.Int64ToStr(utils.Time())}
// проверим, не нужно ли нам выйти из цикла
if CheckDaemonsRestart(chBreaker, chAnswer, GoroutineName) {
break BEGIN
}
LocalGateIp, err := d.GetMyLocalGateIp()
if err != nil {
if d.dPrintSleep(utils.ErrInfo(err), d.sleepTime) {
break BEGIN
}
continue
}
if len(LocalGateIp) > 0 {
if d.dPrintSleep(utils.ErrInfo(errors.New("len(LocalGateIp) > 0")), d.sleepTime) {
break BEGIN
}
continue
}
// сколько нужно спать
prevBlock, myUserId, myMinerId, currentUserId, level, levelsRange, err := d.TestBlock()
if err != nil {
if d.dPrintSleep(utils.ErrInfo(err), d.sleepTime) {
break BEGIN
}
continue
}
log.Info("%v", prevBlock, myUserId, myMinerId, currentUserId, level, levelsRange)
if myMinerId == 0 {
log.Debug("myMinerId == 0")
if d.dSleep(d.sleepTime) {
break BEGIN
}
continue
}
sleepData, err := d.GetSleepData()
sleep := d.GetIsReadySleep(prevBlock.Level, sleepData["is_ready"])
prevHeadHash := prevBlock.HeadHash
// Если случится откат или придет новый блок, то testblock станет неактуален
startSleep := utils.Time()
for i := 0; i < int(sleep); i++ {
err, restart := d.dbLock()
if restart {
break BEGIN
}
if err != nil {
if d.dPrintSleep(err, d.sleepTime) {
break BEGIN
}
continue BEGIN
}
newHeadHash, err := d.Single("SELECT head_hash FROM info_block").String()
if err != nil {
if d.dPrintSleep(utils.ErrInfo(err), d.sleepTime) {
break BEGIN
}
continue
}
d.dbUnlock()
//.........這裏部分代碼省略.........