-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
183 additions
and
237 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package modules | ||
|
||
import ( | ||
"DBTools/conf" | ||
"fmt" | ||
"log" | ||
"time" | ||
) | ||
|
||
func ChangePassword(user string) { | ||
rows, err := conf.DbS.Db.Query(fmt.Sprintf("SELECT user_pwd,salt,pwd_expire_time FROM irds_irdsdb.public.tb_user where user_name = '%s';", user)) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
defer rows.Close() | ||
origin_user_pwd := "" | ||
origin_salt := "" | ||
origin_pwd_expire_time := "" | ||
exchage_user_pwd := "57b303e3875c0e6834e388912a36215e044872f45b0d5bc01ef9eb47267a8292" | ||
exchange_expire_time := time.Now().AddDate(0, 0, 7) | ||
exchage_salt := "8e8c4210822e51efc34904279f8d716ce9a6c3f76f76d58690898eb08533ea76" | ||
for rows.Next() { | ||
err = rows.Scan(&origin_user_pwd, &origin_salt, &origin_pwd_expire_time) | ||
} | ||
fmt.Println(origin_user_pwd) | ||
fmt.Println(origin_salt) | ||
fmt.Println(origin_pwd_expire_time) | ||
query := ` | ||
UPDATE irds_irdsdb.public.tb_user | ||
SET | ||
user_pwd = $1, | ||
salt = $2, | ||
pwd_expire_time = $3 | ||
WHERE | ||
user_name = $4 | ||
` | ||
_, err = conf.DbS.Db.Exec(query, exchage_user_pwd, exchage_salt, exchange_expire_time, user) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
fmt.Printf("Exchange Success\nUser %s's Password Change To hik12345+\n", user) | ||
fmt.Printf("End?") | ||
fmt.Scanf("\n") | ||
_, err = conf.DbS.Db.Exec(query, origin_user_pwd, origin_salt, origin_pwd_expire_time, user) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
fmt.Println("User Info Restore.") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
package modules | ||
|
||
import ( | ||
"DBTools/conf" | ||
"DBTools/utils" | ||
"fmt" | ||
"github.com/jedib0t/go-pretty/table" | ||
"log" | ||
"os" | ||
) | ||
|
||
var users = make([]string, 0) | ||
|
||
func InfoGet() { | ||
fmt.Println(utils.ColorPrint(1, "******************User Info******************")) | ||
queryUser() | ||
fmt.Println(utils.ColorPrint(1, "******************Org Info******************")) | ||
quertOrg() | ||
fmt.Println(utils.ColorPrint(1, "******************Role Info******************")) | ||
quertRole() | ||
fmt.Println(utils.ColorPrint(1, "******************Region Info******************")) | ||
quertRegion() | ||
} | ||
func queryUser() { | ||
rows, err := conf.DbS.Db.Query("select user_name,usergroup_name from irds_irdsdb.public.tb_user;") | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
defer rows.Close() | ||
t := table.NewWriter() | ||
t.SetOutputMirror(os.Stdout) | ||
t.AppendHeader(table.Row{"USER_NAME", "USER_GROUP_NAME"}) | ||
for rows.Next() { | ||
var username string | ||
var user_group_name string | ||
err = rows.Scan(&username, &user_group_name) | ||
users = append(users, username) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
t.AppendRow(table.Row{username, user_group_name}) | ||
} | ||
err = rows.Err() | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
t.Render() | ||
} | ||
func quertOrg() { | ||
rows, err := conf.DbS.Db.Query("select org_id,org_name,org_index_code from irds_irdsdb.public.tb_org;") | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
defer rows.Close() | ||
t := table.NewWriter() | ||
t.SetOutputMirror(os.Stdout) | ||
t.AppendHeader(table.Row{"ORG_ID", "ORG_NAME", "ORG_INDEX_CODE"}) | ||
// 遍历查询结果 | ||
for rows.Next() { | ||
var org_id int | ||
var org_name string | ||
var org_index_code string | ||
err = rows.Scan(&org_id, &org_name, &org_index_code) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
t.AppendRow(table.Row{org_id, org_name, org_index_code}) | ||
} | ||
err = rows.Err() | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
t.Render() | ||
} | ||
func quertRegion() { | ||
rows, err := conf.DbS.Db.Query("select region_name,parent_id from irds_irdsdb.public.tb_region;") | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
defer rows.Close() | ||
t := table.NewWriter() | ||
t.SetOutputMirror(os.Stdout) | ||
t.AppendHeader(table.Row{"REGION_NAME", "PARENT_ID"}) | ||
// 遍历查询结果 | ||
for rows.Next() { | ||
var region_name string | ||
var parent_id string | ||
err = rows.Scan(®ion_name, &parent_id) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
t.AppendRow(table.Row{region_name, parent_id}) | ||
} | ||
err = rows.Err() | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
t.Render() | ||
} | ||
func quertRole() { | ||
rows, err := conf.DbS.Db.Query("select role_name,creator from irds_irdsdb.public.tb_role;") | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
defer rows.Close() | ||
t := table.NewWriter() | ||
t.SetOutputMirror(os.Stdout) | ||
t.AppendHeader(table.Row{"ROLE_NAME", "CREATOR"}) | ||
// 遍历查询结果 | ||
for rows.Next() { | ||
var role_name string | ||
var creator string | ||
err = rows.Scan(&role_name, &creator) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
t.AppendRow(table.Row{role_name, creator}) | ||
} | ||
err = rows.Err() | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
t.Render() | ||
} |
Oops, something went wrong.