Sspanel monthly billing, modify the go version of the code "MySQL API"

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.

Start thanks to the author of Sspanel Orvice great God! " reprint Please specify"

Bo Master recently in the construction of Sspanel v3, the middle pit really a lot of, I turn back to add, SS server side I chose Orvice shadowsocks-go mu version, because the author is based on the mechanism of flow control, in fact, unscrupulous traders are through time control (233), So I'm going to make a change based on the author and add the time limit.

Note: This version is based on the way Mysqlapi,webapi is modified to make the

I added two fields to the user table of the Sspanel data: End_time int, expiry date (1970 timestamp), Package_type int package type (none, month, three months, half year, one years).


Specific can be based on their actual needs of the changes.

First, we find the user control code, in Shadowsocks-go-mu\mu\mysql\mysql.go, where the author reads the data in MySQL with a struct.

Type User struct {id             intport           intpasswd         stringmethod         stringenable         inttransferenable intu              Intd              int}

Need to add our newly added three fields in it (because I don't know how the go language gets the timestamp, so I read it directly from SQL, there is a benefit that if you configure multiple servers, you can keep time synchronized, not local time)

End_time        int//Read server current timestamp from MySQL now_time        intpackage_type   int

Find a way to read database data and assign values to the above fields

Func (c *client) getusers () ([]user. User, error) {log. Log.info ("Get MySQL users") var datas []*user//queries the database plus the new field rows, err: = C.db.model (user{}). Select ("ID, passwd, port, Method,enable,transfer_enable,u,d,end_time,unix_timestamp (LocalTime ()) as Now_time, Package_type "). Rows () if err! = Nil {log. Log.error (ERR) var users []user. Userreturn users, Err}defer rows. Close () for rows. Next () {var data user//will read the expiry time and Account type Assignment err: = rows. Scan (&data.id, &data.passwd, &data.port, &data.method, &data.enable, &data.transferenable, &DATA.U, &DATA.D, &data.end_time, &data.now_time, &data.package_type) if err! = Nil {log. Log.error (err) Continue}datas = append (datas, &data)}log. Log.info (Len (datas)) Users: = Make ([]user. User, Len (datas)) for k, V: = range Datas {users[k] = V}return users, nil}

Next, find the control method to increase the expiration auto-disconnect

Func (U *user) isenable () bool {if u.enable = = 0 {return false}if u.u+u.d > u.transferenable {return false}//if expired, deactivate user I F u.now_time > U.end_time {return False}return true}


Above, re-compile after the change, replace the original MU file, the server restart can




Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.