/************************************************ * * * * * **********************************************/ #ifndef __FCGICOMMISSIONING_H #define __FCGICOMMISSIONING_H #include "fcgio.h" #include #include #include #include #include #include #include #include #include #include #include #include /* Constant declarations */ const int STDIN_MAX = 1000000; const int NUM_ATTEMPTS = 3; const int AASID_LENGTH = 30; const int MAX_GET = 4096; /* header declarations */ const std::string HEADER = "Content-type:application/json\r\n\r\n"; /* message declarations */ const std::string ERR_MALDATA = "Submitted data is malformed"; const std::string ERR_BADAASID = "aasID is incorrect or missing"; const std::string ERR_PWMISMATCH = "Password verification failed. Password mismatch"; const std::string ERR_USRMISMATCH = "username does not match request entry."; const std::string ERR_NOPASS = "No password given"; const std::string ERR_ILLEGALUSRNAME = "Username is not permitted. Attempt new username"; //TEST COOOODE //const std::string DEBUG ="Content-type:text/plain\r\n"; const std::string ERROR_PARSE = "Content-type: application/json\r\n\r\n{\r\n\"error\" : \"Json input failed to parse\",\r\n\"status\" : \"failed\"\r\n}\n"; //END TEST COOOOODE const std::string MSG_NEWPASSWD = "New password: "; const std::string MSG_RETYPEPASS = "Retype new password: "; const std::string MSG_SUCCESS = "Change password success!"; /* aasType declarations */ const std::string AASTYPE_QSTN = "question; input hide"; const std::string AASTYPE_INFO = "info"; const std::string AASTYPE_ERR = "error"; /* popen cmd declarations */ const std::string POPEN_CLOSEALL = "/usr/sbin/start-stop-daemon -S -p /var/run/commissionoff.pid -b -a /bin/bash -- -c /usr/libexec/commission/off.sh"; const std::string POPEN_MTS_UBPW = "/sbin/mts-ubpasswd -up"; /* popen cmd generators */ std::string passwd_cmd_gen(std::string pw); std::string useradd_cmd_gen(std::string usr); /* function headers */ /****************************************************************************** * begin_fcgi * * Begin_fcgi holds the main code loop for the commissioning.fcgi binary. The * basic flow is as follow: * * open log and initialize the fcgx request environment * * set the streambuffers to utilize fcgi stream buffers * * receive a request * * handle the requests. * * If all requests are correct, create a user * * end fcgi commissioning * * ***************************************************************************/ int begin_fcgi(); /* helper functions */ /****************************************************************************** * properInput * * properInput receives a Json::Value and determines if its contents is a * message properly formatted for fcgicommissioning input. Proper input is: * * username : * aasID : * aasAnswer : * * returns true if properly formed, false if improper * ***************************************************************************/ bool properInput(Json::Value jobj); /****************************************************************************** * legalName * * legalName checks if the requested username already exists or is implemented * by the system. Returns true if the name is available, false if used or * unavailable * ***************************************************************************/ bool legalName(std::string name); /****************************************************************************** * confirmCommissioning * * confirmCommissioning returns a simple, standardized confirmation message that * fcgicommissioning is in fact up and running. Used when no POST data is given, * but instead a GET is requested by the user. * ***************************************************************************/ std::string confirmCommissioning(); /****************************************************************************** * printMsg * * printMsg formulates the response data fcgicommissioning returns after the * user POSTs a properly formed JSON request. Values it requires are: * * is_commission: true if a pending commissioning attempt is occuring, false * if there is no current commissioning requests yet logged. * * atmpt_cntr: The amount of attempts the user has left to return proper data. * printMsg automatically iterates the attempts left whenever the * is_err flag is set, and resets the atmpt_cntr and is_commission * states when all attempts are consumed, resetting the commission * attempt to the beginning. * * pw: the password the user has requested. * * is_err: true if the message being sent is an error message, false if * it is a successful message * * aasid: the aasid the system has stored to check against user requests. * * errorMsg: receives a string that represents the standardized error messages * to return to the user. These error messages are declared as 'const' * values within commission_func.h * * aasType: a string that represents the aas message type the user is currently * receiving. These aasType messages are declares as 'const' values * within commission_func.h * * ***************************************************************************/ std::string printMsg(bool &is_commission, int &atmpt_cntr, std::string &pw, bool is_err, std::string aasid, std::string errorMsg, std::string aastype); /***************************************************************************** * get_request_content * * Parses the FCGX request sent by the user and returns its value as string data * ***************************************************************************/ std::string get_request_content(const FCGX_Request &request); /******************************************************************************** * gen_aasid * * generates an aasid to represent the current commissioning session. This value is * stored by fcgicommissioning throughout a successful commissioning attempt to * check against valid messages, and is reset when a user exhausts their commissioning * attempts and needs to start over. * ******************************************************************************/ std::string gen_aasid(); #endif /* ~__FCGICOMMISSIONING_H */