Sspanel monthly billing, modify the go version of the Code "Web 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.

In the previous blog I implemented the MySQL API modification, this one is the Web API. At first I thought Orvice is in the PHP API control, see the API discovery is not (or WEBAPI direct control, modify convenient = =), database modification, etc. please go to see a portal

Find the user struct, path shadowsocks-go-mu\mu\webapi\user.go

Structure modification, note that the field and JSON fields here cannot be the same, otherwise it will not resolve, the first letter uppercase can be

Type User struct {id             int    ' JSON: ' ID ' ' Port           int ' JSON: ' Port '    ' Passwd         string ' JSON: ' Passwd ' Method         string ' JSON: ' method ' ' Enable         int    ' JSON: ' Enable ' ' transferenable Int64  ' JSON: ' transfer_enable ' ' U              Int64  ' json: "U" ' d              Int64  ' JSON: "D" '//End time End_time       Int64  ' JSON: "End_time" '// Now time Now_time       Int64  ' JSON: "Now_time" '//package type Package_type   int    ' JSON: "Package_type" '}

Control method Modification

Func (U User) isenable () bool {if u.enable = = 0 {return false}if u.transferenable < (u.u + u.d) {return false}//if expired, deactivated User if U.now_time > u.end_time {return False}return true}

Because the now_time here need to be obtained from the background, it is also necessary to modify the Sspanel code (local read time will be at risk of inconsistent time, not recommended)

PHP MVC code changed very painful = = because the SQL operation is modular, it needs to be lazy, find the API file, path app/controllers/mu/usercontroller.php, modify the Index method code

    User List public    function Index ($request, $response, $args)    {        $users = User::all ();        Returns the current timestamp to the data in        foreach ($users as $user) {            $user->now_time = time ();        }        $res = [            "ret" + = 1,            "msg" = "OK",            "data" and "= $users        ];        return $this->echojson ($response, $res);    }

The user does not have the Now_time field in the original code, so you also need to add the Now_time field to the user table, put it behind the end_time, type int, and the default value is arbitrary.

After the change, the PHP directly to your site root directory to manually modify the


in doubt, you can add group discussion, group number 256950656



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.