BILLmanager. Now with shell scripts you can sell anything



    Today, most providers, in addition to standard hosting services, domains and SSL, provide various "non-hosting" services. For example, VPN or streaming. The question arises: how to organize their connection for the client in BILLmanager? You can give access manually, but what if the applications for connecting the breakthrough? Automate the process, of course! Recently, another solution for sales automation has appeared in BILLmanager, and we want to talk about it.

    The article will discuss how to use custom shell scripts to configure the sale of non-standard services in our billing platform.


    Perhaps, experienced users will have a question: “But for BILLmanager there are additional modules, why shell scripts?” The fact is that scripts are easier to write: a programmer is not needed; A knowledgeable BASH system administrator is sufficient.

    So, let’s think: for what services scripting is required. Offhand there are several options: for selling activation keys to a particular software, for providing space on the ftp server for storing backups, for streaming, trading in blueberry muffins and smoothies . Of course, the list goes on, it is limited only by imagination.

    Consider an example of selling access to an ftp server with some valuable content. Let it be regularly updated vector maps of the area.

    Find out what are the technical requirements. According to the documentation , 4 scripts are required: for ordering, suspension, resumption and termination of access.

    The automatically generated username and password are transferred to the first script (open.sh), and some additional parameters necessary for the script to work can also be transferred. The output should be a line starting with “OK” and containing the parameter “--id”: a unique identifier for the created service. It is also allowed to return additional parameters; for example, a link to the ftp server to show it to the user who ordered the service.

    The remaining scripts (suspend.sh, resume.sh, close.sh) are passed the unique identifier of the created service (--id), and the output should contain the string “OK”.

    So let's get started. Let in our case the file server will be ProFTPD.

    In order to give the client access to the cards, you need to create a user and assign him a password. To do this, we will use the parameters that BILLmanager generates automatically: this way we also get the service ID, since the username is created unique. We get the values ​​from the parameter string, then call useradd, and then assign the password using passwd. It remains to return “OK”, the identifier, as well as the data for authorization on the server, in order to then transfer this information to the client.

    Result: open.sh
    #!/bin/bash
    for i
    do
    	if [ ${i:0:6}  = "--user" ] 
    	then
    		username=${i:7}
    	elif [ ${i:0:10} = "--password" ]
    	then
    		password=${i:11}
    	fi
    done
    useradd $username -d /home/ftp_folder -m -s /bin/false
    echo $password | passwd --stdin $username > /dev/null
    echo "OK --id=$username --username=$username --password=$password"
    


    The service is connected. We will create a mechanism to suspend access in case the balance on the client’s account runs out. Using the received ID, call usermod and change the home directory to / dev / null.

    Result: suspend.sh
    #!/bin/bash
    for i
    do
    	string=${i}
    	if [ ${string:0:4} = "--id" ]
    	then
    	username=${string:5}
    	fi
    done
    usermod -d /dev/null $username
    echo "OK"
    


    If payment is received, you must return the opportunity to receive cards. Again “call” usermod and return everything as it was.

    Result: resume.sh
    #!/bin/bash
    for i
    do
    	string=${i}
    	if [ ${string:0:4} = "--id" ]
    	then
    	username=${string:5}
    	fi
    done
    usermod -d /home/ftp_folder $username
    echo "OK"
    


    And finally, if the provision of the service for any reason is no longer planned, then you need to delete the user. Using the same identifier, run userdel.

    Result: close.sh
    #!/bin/bash
    for i
    do
    	string=${i}
    	if [ ${string:0:4} = "--id" ]
    	then
    	username=${string:5}
    	fi
    done
    userdel $username
    echo "OK"
    


    That's it, code writing is complete. We copy the implemented scripts into a separate directory on the machine, from where the cards will be dealt, and use “chmod + x” on them. In addition, you should check that the ftp server is “looking” in / etc / passwd. The AuthOrder line in the etc / proftpd.conf file is responsible for this. For everything to work, it must have mod_auth_unix.c in it.

    Now make the settings in BILLmanager. You need to create a new type of product, and then a tariff plan of this type. After that, select Shellscripts as the processing module and wait for the installation to complete. If there is a request to create a data center - create it. At the next stage, specify the IP address of the ftp server, fill in the authentication data and the path to the script folder. After clicking on “Next” we enter an arbitrary name for the handler. Then re-select the type of product, specify the names, processor and prices. It remains to identify additional parameters that are passed from the open.sh script. In the product types, select the newly created type, click “Parameters”, “Create”. We create 2 parameters in accordance with the open.sh script, check the box “Show at opening” in them,

    The settings are completed, and now the service can be connected to clients.

    So, the topic of shell scripts is revealed. We will be happy to answer your questions, and we will also be grateful for the feedback on the article. Good luck in the development of services!

    PS If you do not have BILLmanager installed, and you want to install it, deployment instructions can be found here .

    Also popular now: