func p_wal(w http.ResponseWriter, r *http.Request) { if !ipchecker(r) { return } r.ParseForm() if checksid(r) && len(r.Form["wal"]) > 0 { wallet.LoadWallet(common.GocoinHomeDir + "wallet" + string(os.PathSeparator) + r.Form["wal"][0]) http.Redirect(w, r, "/wal", http.StatusFound) return } page := load_template("wallet.html") wal1 := load_template("wallet_qsw.html") addr := load_template("wallet_adr.html") page = strings.Replace(page, "{TOTAL_BTC}", fmt.Sprintf("%.8f", float64(wallet.LastBalance)/1e8), 1) page = strings.Replace(page, "{UNSPENT_OUTS}", fmt.Sprint(len(wallet.MyBalance)), 1) fis, er := ioutil.ReadDir(common.GocoinHomeDir + "wallet/") if er == nil { for i := range fis { if !fis[i].IsDir() && fis[i].Size() > 1 { s := strings.Replace(wal1, "{WALLET_NAME}", fis[i].Name(), -1) page = templ_add(page, "<!--ONEWALLET-->", s) } } } if wallet.MyWallet != nil { page = strings.Replace(page, "<!--WALLET_FILENAME-->", wallet.MyWallet.FileName, 1) wc, er := ioutil.ReadFile(wallet.MyWallet.FileName) if er == nil { page = strings.Replace(page, "{WALLET_DATA}", string(wc), 1) } for i := range wallet.MyWallet.Addrs { ad := addr ad = strings.Replace(ad, "<!--WAL_ADDR-->", wallet.MyWallet.Addrs[i].Enc58str, 1) lll := strings.SplitN(wallet.MyWallet.Addrs[i].Label, "@", 2) ad = strings.Replace(ad, "<!--WAL_LABEL-->", lll[0], 1) if len(lll) == 2 { ad = strings.Replace(ad, "<!--WAL_WALLET-->", lll[1], 1) } if btc, cnt := getbal(wallet.MyWallet.Addrs[i]); btc > 0 { ad = strings.Replace(ad, "<!--WAL_BALANCE-->", fmt.Sprintf("%.8f", float64(btc)/1e8), 1) ad = strings.Replace(ad, "<!--WAL_OUTCNT-->", fmt.Sprint(cnt), 1) } page = templ_add(page, "<!--ONE_WALLET_ADDR-->", ad) } page = strings.Replace(page, "{WALLET_NAME}", filepath.Base(wallet.MyWallet.FileName), 1) } else { strings.Replace(page, "<!--WALLET_FILENAME-->", "<i>no wallet loaded</i>", 1) page = strings.Replace(page, "{WALLET_NAME}", "", -1) } write_html_head(w, r) w.Write([]byte(page)) write_html_tail(w) }
func load_wallet(fn string) { if fn == "." { fmt.Println("Default wallet from", common.GocoinHomeDir+"wallet/DEFAULT") wallet.LoadWallet(common.GocoinHomeDir + "wallet/DEFAULT") } else if fn == "-" { fmt.Println("Reloading wallet from", wallet.MyWallet.FileName) wallet.LoadWallet(wallet.MyWallet.FileName) fmt.Println("Dumping current wallet from", wallet.MyWallet.FileName) } else if fn != "" { fmt.Println("Switching to wallet from", fn) wallet.LoadWallet(fn) } if wallet.MyWallet == nil { fmt.Println("No wallet loaded") return } for i := range wallet.MyWallet.Addrs { fmt.Println(" ", wallet.MyWallet.Addrs[i].String(), wallet.MyWallet.Addrs[i].Label()) } }
func arm_stealth(p string) { var buf, b2 [256]byte create := p != "" fmt.Print("Enter seed password of the stealth key (empty line to abort) : ") le := sys.ReadPassword(buf[:]) if le <= 0 { fmt.Println("Aborted") return } if create { fmt.Print("Re-enter the seed password : "******"The passwords you entered do not match") return } } nw := make([]byte, 32) btc.ShaHash(buf[:le], nw) // seed sys.ClearBuffer(buf[:le]) btc.ShaHash(nw, nw) // 1st key wallet.ArmedStealthSecrets = append(wallet.ArmedStealthSecrets, nw) if create { fmt.Println("You have created a new stealth scan-key. Make sure to not forget this password!") pk := btc.PublicFromPrivate(nw, true) fmt.Println("Public hexdump:", hex.EncodeToString(pk)) fmt.Println(" Go to your wallet machine and execute:") fmt.Println(" wallet -scankey", hex.EncodeToString(pk), "-prefix 0") fmt.Println(" (change the prefix to a different value if you want)") } fmt.Println("Stealth key number", len(wallet.ArmedStealthSecrets)-1, "has been stored in memory") fmt.Println("Reloading the current wallet...") usif.ExecUiReq(&usif.OneUiReq{Handler: func(p string) { wallet.LoadWallet(wallet.MyWallet.FileName) }}) show_prompt = false }
func show_balance(p string) { if p == "sum" { fmt.Print(wallet.DumpBalance(wallet.MyBalance, nil, false, true)) return } if p != "" { fmt.Println("Using wallet from file", p, "...") wallet.LoadWallet(p) } if wallet.MyWallet == nil { println("You have no loaded wallet") return } if len(wallet.MyWallet.Addrs) == 0 { println("Your loaded wallet has no addresses") return } fmt.Print(wallet.UpdateBalanceFolder()) fmt.Println("Your balance data has been saved to the 'balance/' folder.") fmt.Println("You nend to move this folder to your wallet PC, to spend the coins.") }
func p_wal(w http.ResponseWriter, r *http.Request) { if !ipchecker(r) { return } if checksid(r) { if len(r.Form["wal"]) > 0 { wallet.LoadWallet(common.GocoinHomeDir + "wallet" + string(os.PathSeparator) + r.Form["wal"][0]) http.Redirect(w, r, "/wal", http.StatusFound) return } if len(r.Form["setunused"]) > 0 { i, er := strconv.ParseUint(r.Form["setunused"][0], 10, 32) if er == nil && int(i) < len(wallet.MyWallet.Addrs) { if wallet.MoveToUnused(wallet.MyWallet.Addrs[i].Enc58str, wallet.MyWallet.Addrs[i].Extra.Wallet) { wallet.LoadWallet(wallet.MyWallet.FileName) } } http.Redirect(w, r, "/wal", http.StatusFound) return } } page := load_template("wallet.html") wal1 := load_template("wallet_qsw.html") addr := load_template("wallet_adr.html") page = strings.Replace(page, "{TOTAL_BTC}", fmt.Sprintf("%.8f", float64(wallet.LastBalance)/1e8), 1) page = strings.Replace(page, "{UNSPENT_OUTS}", fmt.Sprint(len(wallet.MyBalance)), 1) fis, er := ioutil.ReadDir(common.GocoinHomeDir + "wallet/") if er == nil { for i := range fis { if !fis[i].IsDir() && fis[i].Size() > 1 && fis[i].Name()[0] != '.' { s := strings.Replace(wal1, "{WALLET_NAME}", fis[i].Name(), -1) page = templ_add(page, "<!--ONEWALLET-->", s) } } } if wallet.MyWallet != nil { page = strings.Replace(page, "<!--WALLET_FILENAME-->", wallet.MyWallet.FileName, 1) wc, er := ioutil.ReadFile(wallet.MyWallet.FileName) if er == nil { page = strings.Replace(page, "{WALLET_DATA}", string(wc), 1) } for i := range wallet.MyWallet.Addrs { ad := addr lab := wallet.MyWallet.Addrs[i].Extra.Label if wallet.MyWallet.Addrs[i].Extra.Virgin { lab += " ***" } ad = strings.Replace(ad, "<!--WAL_ROW_IDX-->", fmt.Sprint(i), 1) ad = strings.Replace(ad, "<!--WAL_ADDR-->", wallet.MyWallet.Addrs[i].Enc58str, 1) ad = strings.Replace(ad, "<!--WAL_WALLET-->", html.EscapeString(wallet.MyWallet.Addrs[i].Extra.Wallet), 1) ad = strings.Replace(ad, "<!--WAL_LABEL-->", html.EscapeString(lab), 1) ms, msr := wallet.IsMultisig(wallet.MyWallet.Addrs[i]) if ms { if msr != nil { ad = strings.Replace(ad, "<!--WAL_MULTISIG-->", fmt.Sprintf("%d of %d", msr.KeysRequired, msr.KeysProvided), 1) } else { ad = strings.Replace(ad, "<!--WAL_MULTISIG-->", "Yes", 1) } } else { ad = strings.Replace(ad, "<!--WAL_MULTISIG-->", "No", 1) } if btc, cnt := getbal(wallet.MyWallet.Addrs[i]); btc > 0 { ad = strings.Replace(ad, "<!--WAL_BALANCE-->", fmt.Sprintf("%.8f", float64(btc)/1e8), 1) ad = strings.Replace(ad, "<!--WAL_OUTCNT-->", fmt.Sprint(cnt), 1) } else if wallet.MyWallet.Addrs[i].Extra.Virgin { // Do not display virgin addresses with zero balance continue } else if wallet.MyWallet.Addrs[i].Extra.Wallet != wallet.UnusedFileName && wallet.MyWallet.Addrs[i].Extra.Wallet != wallet.AddrBookFileName { ad = strings.Replace(ad, "<!--WAL_OUTCNT-->", fmt.Sprint("<a href=\"javascript:setunused(", i, ")\" title=\"Move to "+ wallet.UnusedFileName+"\"><img src=\"webui/del.png\"></a>"), 1) } page = templ_add(page, "<!--ONE_WALLET_ADDR-->", ad) } page = strings.Replace(page, "{WALLET_NAME}", filepath.Base(wallet.MyWallet.FileName), 1) } else { strings.Replace(page, "<!--WALLET_FILENAME-->", "<i>no wallet loaded</i>", 1) page = strings.Replace(page, "{WALLET_NAME}", "", -1) } write_html_head(w, r) w.Write([]byte(page)) write_html_tail(w) }
func main() { var ptr *byte if unsafe.Sizeof(ptr) < 8 { fmt.Println("WARNING: Gocoin client shall be build for 64-bit arch. It will likely crash now.") } fmt.Println("Gocoin client version", btc.SourcesTag) runtime.GOMAXPROCS(runtime.NumCPU()) // It seems that Go does not do it by default // Disable Ctrl+C signal.Notify(killchan, os.Interrupt, os.Kill) defer func() { if r := recover(); r != nil { err, ok := r.(error) if !ok { err = fmt.Errorf("pkg: %v", r) } fmt.Println("main panic recovered:", err.Error()) fmt.Println(string(debug.Stack())) network.NetCloseAll() common.CloseBlockChain() network.ClosePeerDB() utils.UnlockDatabaseDir() os.Exit(1) } }() host_init() // This will create the DB lock file and keep it open default_wallet_fn := common.GocoinHomeDir + "wallet" + string(os.PathSeparator) + wallet.DefaultFileName fi, _ := os.Stat(default_wallet_fn) if fi == nil || fi.IsDir() { fmt.Println(default_wallet_fn, "not found") old_wallet_location := common.GocoinHomeDir + "wallet.txt" // If there is wallet.txt rename it to default. fi, _ := os.Stat(old_wallet_location) if fi != nil && !fi.IsDir() { fmt.Println("Taking wallet.txt as", default_wallet_fn) os.Rename(old_wallet_location, default_wallet_fn) } else { fmt.Println("Creating empty default wallet at", default_wallet_fn) ioutil.WriteFile(default_wallet_fn, []byte(fmt.Sprintln("# Put your wallet's public addresses here")), 0660) } } // cache the current balance of all the addresses from the current wallet files wallet.FetchAllBalances() // ... and now load the dafault wallet wallet.LoadWallet(default_wallet_fn) if wallet.MyWallet != nil { wallet.UpdateBalance() fmt.Print(wallet.DumpBalance(wallet.MyBalance, nil, false, true)) } peersTick := time.Tick(5 * time.Minute) txPoolTick := time.Tick(time.Minute) netTick := time.Tick(time.Second) network.InitPeers(common.GocoinHomeDir) common.Last.Block = common.BlockChain.BlockTreeEnd common.Last.Time = time.Unix(int64(common.Last.Block.Timestamp()), 0) if common.Last.Time.After(time.Now()) { common.Last.Time = time.Now() } for k, v := range common.BlockChain.BlockIndex { network.ReceivedBlocks[k] = &network.OneReceivedBlock{Time: time.Unix(int64(v.Timestamp()), 0)} } if common.CFG.TextUI.Enabled { go textui.MainThread() } if common.CFG.WebUI.Interface != "" { fmt.Println("Starting WebUI at", common.CFG.WebUI.Interface, "...") go webui.ServerThread(common.CFG.WebUI.Interface) } for !usif.Exit_now { common.CountSafe("MainThreadLoops") for retryCachedBlocks { retryCachedBlocks = retry_cached_blocks() // We have done one per loop - now do something else if pending... if len(network.NetBlocks) > 0 || len(usif.UiChannel) > 0 { break } } common.Busy("") select { case s := <-killchan: fmt.Println("Got signal:", s) usif.Exit_now = true continue case newbl := <-network.NetBlocks: HandleNetBlock(newbl) case newtx := <-network.NetTxs: network.HandleNetTx(newtx, false) case newal := <-network.NetAlerts: fmt.Println("\007" + newal) textui.ShowPrompt() case cmd := <-usif.UiChannel: common.Busy("UI command") cmd.Handler(cmd.Param) cmd.Done.Done() continue case <-peersTick: network.ExpirePeers() case <-txPoolTick: network.ExpireTxs() case <-netTick: network.NetworkTick() case <-time.After(time.Second / 2): common.CountSafe("MainThreadTouts") if !retryCachedBlocks { common.Busy("common.BlockChain.Idle()") common.BlockChain.Idle() } continue } common.CountSafe("NetMessagesGot") } network.NetCloseAll() network.ClosePeerDB() if usif.DefragBlocksDB { defrag_db() } common.CloseBlockChain() utils.UnlockDatabaseDir() }
func main() { if btc.EC_Verify == nil { fmt.Println("WARNING: EC_Verify acceleration disabled. Enable EC_Verify wrapper if possible.") } var ptr *byte if unsafe.Sizeof(ptr) < 8 { fmt.Println("WARNING: Gocoin client shall be build for 64-bit arch. It will likely crash now.") } fmt.Println("Gocoin client version", btc.SourcesTag) runtime.GOMAXPROCS(runtime.NumCPU()) // It seems that Go does not do it by default // Disable Ctrl+C signal.Notify(killchan, os.Interrupt, os.Kill) defer func() { if r := recover(); r != nil { err, ok := r.(error) if !ok { err = fmt.Errorf("pkg: %v", r) } fmt.Println("main panic recovered:", err.Error()) fmt.Println(string(debug.Stack())) network.NetCloseAll() common.CloseBlockChain() network.ClosePeerDB() utils.UnlockDatabaseDir() os.Exit(1) } }() host_init() // This will create the DB lock file and keep it open // Clean up the DB lock file on exit // cache the current balance of all the addresses from the current wallet files wallet.FetchAllBalances() // ... and now switch to the dafault wallet wallet.LoadWallet(common.GocoinHomeDir + "wallet" + string(os.PathSeparator) + "DEFAULT") if wallet.MyWallet == nil { wallet.LoadWallet(common.GocoinHomeDir + "wallet.txt") } if wallet.MyWallet != nil { wallet.UpdateBalance() fmt.Print(wallet.DumpBalance(nil, false)) } peersTick := time.Tick(5 * time.Minute) txPoolTick := time.Tick(time.Minute) netTick := time.Tick(time.Second) network.InitPeers(common.GocoinHomeDir) common.Last.Block = common.BlockChain.BlockTreeEnd common.Last.Time = time.Unix(int64(common.Last.Block.Timestamp), 0) for k, v := range common.BlockChain.BlockIndex { network.ReceivedBlocks[k] = &network.OneReceivedBlock{Time: time.Unix(int64(v.Timestamp), 0)} } if common.CFG.TextUI.Enabled { go textui.MainThread() } if common.CFG.WebUI.Interface != "" { fmt.Println("Starting WebUI at", common.CFG.WebUI.Interface, "...") go webui.ServerThread(common.CFG.WebUI.Interface) } for !usif.Exit_now { common.CountSafe("MainThreadLoops") for retryCachedBlocks { retryCachedBlocks = retry_cached_blocks() // We have done one per loop - now do something else if pending... if len(network.NetBlocks) > 0 || len(usif.UiChannel) > 0 { break } } common.Busy("") select { case s := <-killchan: fmt.Println("Got signal:", s) usif.Exit_now = true continue case newbl := <-network.NetBlocks: HandleNetBlock(newbl) case newtx := <-network.NetTxs: network.HandleNetTx(newtx, false) case cmd := <-usif.UiChannel: common.Busy("UI command") cmd.Handler(cmd.Param) cmd.Done.Done() continue case <-peersTick: network.ExpirePeers() case <-txPoolTick: network.ExpireTxs() case <-netTick: network.NetworkTick() case <-time.After(time.Second / 2): common.CountSafe("MainThreadTouts") if !retryCachedBlocks { common.Busy("common.BlockChain.Idle()") common.BlockChain.Idle() } continue } common.CountSafe("NetMessagesGot") } network.NetCloseAll() network.ClosePeerDB() if usif.DefragBlocksDB { defrag_db() } common.CloseBlockChain() utils.UnlockDatabaseDir() }
func write_html_head(w http.ResponseWriter, r *http.Request) { sessid := sid(r) if sessid == "" { var sid [16]byte rand.Read(sid[:]) sessid = hex.EncodeToString(sid[:]) http.SetCookie(w, &http.Cookie{Name: "sid", Value: sessid}) } // Quick switch wallet if checksid(r) && len(r.Form["qwalsel"]) > 0 { wallet.LoadWallet(common.GocoinHomeDir + "wallet" + string(os.PathSeparator) + r.Form["qwalsel"][0]) http.Redirect(w, r, r.URL.Path, http.StatusFound) return } s := load_template("page_head.html") s = strings.Replace(s, "{VERSION}", btc.SourcesTag, 1) s = strings.Replace(s, "{SESSION_ID}", sessid, 1) if common.Testnet { s = strings.Replace(s, "{TESTNET}", "Testnet ", 1) } else { s = strings.Replace(s, "{TESTNET}", "", 1) } for i := range webuimenu { var x string if i > 0 && i < len(webuimenu)-1 { x = " | " } x += "<a " if r.URL.Path == webuimenu[i][0] { x += "class=\"menuat\" " } x += "href=\"" + webuimenu[i][0] + "\">" + webuimenu[i][1] + "</a>" if i == len(webuimenu)-1 { s = strings.Replace(s, "{MENU_LEFT}", "", 1) s = strings.Replace(s, "{MENU_RIGHT}", x, 1) } else { s = strings.Replace(s, "{MENU_LEFT}", x+"{MENU_LEFT}", 1) } } // Quick wallet switch fis, er := ioutil.ReadDir(common.GocoinHomeDir + "wallet/") if er == nil { for i := range fis { if !fis[i].IsDir() && fis[i].Size() > 1 && fis[i].Name()[0] != '.' { var ow string if wallet.MyWallet != nil && strings.HasSuffix(wallet.MyWallet.FileName, string(os.PathSeparator)+fis[i].Name()) { ow = "<option selected>" + fis[i].Name() + "</option>" } else { ow = "<option>" + fis[i].Name() + "</option>" } s = templ_add(s, "<!--QUICK_WALLET_SELECT-->", ow) } } } w.Write([]byte(s)) }
func p_cfg(w http.ResponseWriter, r *http.Request) { if !ipchecker(r) { return } common.LockCfg() defer common.UnlockCfg() if checksid(r) && len(r.Form["txponoff"]) > 0 { common.CFG.TXPool.Enabled = !common.CFG.TXPool.Enabled http.Redirect(w, r, "txs", http.StatusFound) return } if checksid(r) && len(r.Form["txronoff"]) > 0 { common.CFG.TXRoute.Enabled = !common.CFG.TXRoute.Enabled http.Redirect(w, r, "txs", http.StatusFound) return } if checksid(r) && len(r.Form["lonoff"]) > 0 { common.CFG.Net.ListenTCP = !common.CFG.Net.ListenTCP http.Redirect(w, r, "net", http.StatusFound) return } if checksid(r) && len(r.Form["drop"]) > 0 { network.DropPeer(r.Form["drop"][0]) http.Redirect(w, r, "net", http.StatusFound) return } if checksid(r) && len(r.Form["savecfg"]) > 0 { dat, _ := json.Marshal(&common.CFG) if dat != nil { ioutil.WriteFile(common.ConfigFile, dat, 0660) } http.Redirect(w, r, "/", http.StatusFound) return } if checksid(r) && len(r.Form["beepblock"]) > 0 { common.CFG.Beeps.NewBlock = !common.CFG.Beeps.NewBlock http.Redirect(w, r, "/", http.StatusFound) return } if checksid(r) && len(r.Form["freemem"]) > 0 { debug.FreeOSMemory() http.Redirect(w, r, "/", http.StatusFound) return } if r.Method == "POST" && len(r.Form["configjson"]) > 0 { e := json.Unmarshal([]byte(r.Form["configjson"][0]), &common.CFG) if e == nil { common.Reset() } if len(r.Form["save"]) > 0 { dat, _ := json.Marshal(&common.CFG) if dat != nil { ioutil.WriteFile(common.ConfigFile, dat, 0660) } } http.Redirect(w, r, "/", http.StatusFound) return } if r.Method == "POST" && len(r.Form["walletdata"]) > 0 && len(r.Form["walletfname"]) > 0 { fn := r.Form["walletfname"][0] if fn == "" { fn = wallet.DefaultFileName } fn = common.GocoinHomeDir + "wallet" + string(os.PathSeparator) + fn ioutil.WriteFile(fn, []byte(r.Form["walletdata"][0]), 0660) wallet.LoadWallet(fn) http.Redirect(w, r, "/wal", http.StatusFound) return } if r.Method == "POST" && len(r.Form["shutdown"]) > 0 { usif.Exit_now = true w.Write([]byte("Your node should shut down soon")) return } if checksid(r) && len(r.Form["mid"]) > 0 { v, e := strconv.ParseUint(r.Form["mid"][0], 10, 32) if e == nil && v < uint64(len(common.MinerIds)) { common.CFG.Beeps.MinerID = common.MinerIds[v][1] } else { common.CFG.Beeps.MinerID = "" } http.Redirect(w, r, "miners", http.StatusFound) return } }
func write_html_head(w http.ResponseWriter, r *http.Request) { start_time = time.Now() sessid := sid(r) if sessid == "" { sessid = new_session_id(w) } // Quick switch wallet if checksid(r) && len(r.Form["qwalsel"]) > 0 { wallet.LoadWallet(common.CFG.Walletdir + string(os.PathSeparator) + r.Form["qwalsel"][0]) http.Redirect(w, r, r.URL.Path, http.StatusFound) return } // If currently selected wallet is address book and we are not on the wallet page - switch to default if r.URL.Path != "/wal" && wallet.MyWallet != nil && strings.HasSuffix(wallet.MyWallet.FileName, string(os.PathSeparator)+wallet.AddrBookFileName) { wallet.LoadWallet(common.CFG.Walletdir + string(os.PathSeparator) + wallet.DefaultFileName) http.Redirect(w, r, r.URL.Path, http.StatusFound) return } s := load_template("page_head.html") s = strings.Replace(s, "{VERSION}", lib.Version, 1) s = strings.Replace(s, "{SESSION_ID}", sessid, 1) if r.URL.Path != "/" { s = strings.Replace(s, "{HELPURL}", "help#"+r.URL.Path[1:], 1) } else { s = strings.Replace(s, "{HELPURL}", "help", 1) } if common.Testnet { s = strings.Replace(s, "{TESTNET}", "Testnet ", 1) } else { s = strings.Replace(s, "{TESTNET}", "", 1) } for i := range webuimenu { var x string if i > 0 && i < len(webuimenu)-1 { x = " | " } x += "<a " if r.URL.Path == webuimenu[i][0] { x += "class=\"menuat\" " } x += "href=\"" + webuimenu[i][0] + "\">" + webuimenu[i][1] + "</a>" if i == len(webuimenu)-1 { s = strings.Replace(s, "{MENU_LEFT}", "", 1) s = strings.Replace(s, "{MENU_RIGHT}", x, 1) } else { s = strings.Replace(s, "{MENU_LEFT}", x+"{MENU_LEFT}", 1) } } // Quick wallet switch fis, er := ioutil.ReadDir(common.CFG.Walletdir + string(os.PathSeparator)) if er == nil { for i := range fis { if !fis[i].IsDir() && fis[i].Size() > 1 && fis[i].Name()[0] != '.' && fis[i].Name() != wallet.AddrBookFileName { var ow string if wallet.MyWallet != nil && strings.HasSuffix(wallet.MyWallet.FileName, string(os.PathSeparator)+fis[i].Name()) { ow = "<option selected>" + fis[i].Name() + "</option>" } else { ow = "<option>" + fis[i].Name() + "</option>" } s = templ_add(s, "<!--QUICK_WALLET_SELECT-->", ow) } } } w.Write([]byte(s)) }
func p_cfg(w http.ResponseWriter, r *http.Request) { if !ipchecker(r) { return } common.LockCfg() defer common.UnlockCfg() if r.Method == "POST" { if len(r.Form["configjson"]) > 0 { e := json.Unmarshal([]byte(r.Form["configjson"][0]), &common.CFG) if e == nil { common.Reset() } if len(r.Form["save"]) > 0 { common.SaveConfig() } http.Redirect(w, r, "/", http.StatusFound) return } if len(r.Form["walletdata"]) > 0 && len(r.Form["walletfname"]) > 0 { fn := r.Form["walletfname"][0] if fn != "" { fn = common.CFG.Walletdir + string(os.PathSeparator) + fn ioutil.WriteFile(fn, []byte(r.Form["walletdata"][0]), 0660) wallet.LoadWallet(fn) } http.Redirect(w, r, "/wal", http.StatusFound) return } if len(r.Form["shutdown"]) > 0 { usif.Exit_now = true w.Write([]byte("Your node should shut down soon")) return } return } // for any other GET we need a matching session-id if !checksid(r) { new_session_id(w) return } if len(r.Form["txponoff"]) > 0 { common.CFG.TXPool.Enabled = !common.CFG.TXPool.Enabled http.Redirect(w, r, "txs", http.StatusFound) return } if len(r.Form["txronoff"]) > 0 { common.CFG.TXRoute.Enabled = !common.CFG.TXRoute.Enabled http.Redirect(w, r, "txs", http.StatusFound) return } if len(r.Form["lonoff"]) > 0 { common.SetListenTCP(!common.IsListenTCP(), true) http.Redirect(w, r, "net", http.StatusFound) return } if len(r.Form["drop"]) > 0 { network.DropPeer(r.Form["drop"][0]) http.Redirect(w, r, "net", http.StatusFound) return } if len(r.Form["savecfg"]) > 0 { dat, _ := json.Marshal(&common.CFG) if dat != nil { ioutil.WriteFile(common.ConfigFile, dat, 0660) } http.Redirect(w, r, "/", http.StatusFound) return } if len(r.Form["beepblock"]) > 0 { common.CFG.Beeps.NewBlock = !common.CFG.Beeps.NewBlock http.Redirect(w, r, "/", http.StatusFound) return } if len(r.Form["freemem"]) > 0 { sys.FreeMem() http.Redirect(w, r, "/", http.StatusFound) return } if len(r.Form["mid"]) > 0 { v, e := strconv.ParseUint(r.Form["mid"][0], 10, 32) if e == nil && v < uint64(len(common.MinerIds)) { common.CFG.Beeps.MinerID = string(common.MinerIds[v].Tag) } else { common.CFG.Beeps.MinerID = "" } http.Redirect(w, r, "miners", http.StatusFound) return } }