Executing a bash file on server once a new signup is done

Executing a bash file on server once a new signup is done

by mina bebawy -
Number of replies: 4

I have created a custom field in the signup filed and I want once the user click on the create my account button

the data in this filed is stored in a variable in a bash file in the server and this bash file is executed then the account name is stored in another custom field

is it possible?

Average of ratings: -
In reply to mina bebawy

Re: Executing a bash file on server once a new signup is done

by Mark Johnson -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Hi mina,

It would help if you can tell us what end result you're trying to achieve (that is, what your bash script is actually doing and why), then we might be able to point you down the appropriate path.

Broadly speaking, yes, you could write a plugin that defines an event observer for the core\event\user_created event, that executes your bash script via a system() call or something similar.

However, if you're writing PHP to do this anyway, it might be tidier (and safer) to do your processing directly in the event observer.

In reply to Mark Johnson

Re: Executing a bash file on server once a new signup is done

by mina bebawy -

Hi Mark

Thank you for your reply

This is the bash file


#!/bin/bash

#This file was created on 27/08/2018


OLDIFS=$IFS

IFS=";"


/usr/local/eosio/bin/cleos -u https://eos.greymass.com wallet unlock -n eatscience14 --password PASSWORD;

while read apub apvt


do

        user=$(/usr/local/eosio/bin/cleos -u https://eos.greymass.com get accounts $apub | perl -ne 'if(/\s+"([^"]+)"[^:]/){print $1."\n"}');

        /usr/local/eosio/bin/cleos -u https://eos.greymass.com set account permission $user active $apub owner -p $user@owner;

done < $1

IFS=$OLDIFS


First of all I want to save the public key entered by the student in the custom field pub_key to be stored in a variable called apub which can be used in the bash file once a new signup occurs and the bash file executes


the bash file change the active key of a pre-created accounts with the new public key entered by the student.

Then I want to store the user variable from the bash file in a custom filed called EOS_Account in mysql database

Can we do that?

In reply to mina bebawy

Re: Executing a bash file on server once a new signup is done

by Mark Johnson -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Ok, I'm not clear on exactly what this does, but googling suggests it's something to do with registering accounts on a blockchain.  Is it something to do with user authentication?

Basically, what I said before seems like the most likely solution.  You can write a moodle plugin that defines an event observer for the user_created event.  This should be supplied with the user's data (you might have to do an extra query to get your custom field), which you can then use to call your shell script using exec().

You'll probably want to make a couple of changes to your shell script.  Firstly, you'll want to let it  accept the value you're sending it as an argument, rather than using `read`.  Then, you'll want to `echo $user` at the end of the script, so that it will be returned by exec() and you can insert it into the database.

One very important point is that since you're accepting a value from a user and passing it to a shell command, make sure you clean it properly using escapeshellarg() before you pass it to exec().  You probably want to add some extra validation to make sure its in the expected format before you do anything with it as well.

In reply to Mark Johnson

Re: Executing a bash file on server once a new signup is done

by mina bebawy -

Thank you Mark

I will try this and I will post the updates here too