📜 ⬆️ ⬇️

BILLmanager. Now with the help of shell scripts you can sell anything



Today, the majority of providers, in addition to standard hosting services, domains and SSL, also 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 connection requests are broken? Automate the process, of course! Recently, BILLmanager has another solution for automating sales, and we want to tell about it.

The article will discuss how to set up selling non-standard services in our billing platform using shell scripts on your own.

Perhaps experienced users will ask: “But for BILLmanager, there are additional modules, why are shell scripts?” The fact is that scripts are easier to write: a programmer is not needed; knowledgeable BASH system administrator is enough.
')
So, let's think: what services will require scripting. Offhand comes several options: to sell activation keys to a particular software, to provide space on the ftp server for backup storage, to implement streaming, to trade in blueberry muffins and smoothies . Of course, the list can be continued, it is limited only by fantasy.

Consider the 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 needed: to order, suspend, resume and terminate access.

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

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

So let's get started. Suppose in our case the file server is 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 use the parameters that BILLmanager generates automatically: this way we also get the service ID, because 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 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" 


Service hooked up. We will make a mechanism to suspend access in case the balance on the client’s account ends. On the received ID we cause usermod and we change the home directory on / 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, it is necessary to return the possibility of receiving 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" 


Everything, writing the code is complete. We copy the implemented scripts to a separate directory on the machine from which the cards will be distributed, and use “chmod + x” on them. In addition, you should check that the ftp server “looks” 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.

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. In the next step, we specify the IP address of the ftp server, fill in the authentication data and the path to the folder with the scripts. After clicking on “Next”, enter the arbitrary name of the handler. Then re-select the type of product, specify the name, processor and prices. It remains to indicate the additional parameters that are passed from the open.sh script. In the product types, select the type you just created, click “Parameters”, “Create”. We create 2 parameters in accordance with the open.sh script, mark the checkbox “Show on opening” in them, and also select “Employee” in the drop-down list “Access for change”.

Settings are made, and now the service can be connected to customers.

So, the shell scripts theme is revealed. We are happy to answer your questions, and we will also be grateful for the feedback on the article. Successes in developing services!

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

Source: https://habr.com/ru/post/307008/


All Articles