#include "session_manager.h" #include "read_uses.h" session_manager::session_manager(conexion* con) { this->con=con; } bool session_manager::loggin(std::string username, std::string passwd){ this->con->write_string(username); this->con->write_string(passwd); std::string result; this->con->read_string(result,4); return result=="pass"; } bool session_manager::admin(){ std::string result; this->con->read_string(result,5); return result=="admin"; } int session_manager::install_command(std::string package){ this->con->write_string("exec"); read_uses uses(package); this->con->write_string(package); if(uses.exist_file()){ this->con->write_string("y"); this->con->write_string(*uses.get_uses()); }else{ this->con->write_string("n"); } std::string buffer; this->con->read_string(buffer,2); return atoi(buffer.data()); } int session_manager::remove_command(std::string package){ this->con->write_string("remv"); this->con->write_string(package); std::string buffer; this->con->read_string(buffer,2); return atoi(buffer.data()); } std::list session_manager::get_packages_info(){ std::list ret; std::string read; this->con->write_string("info"); while(true){ this->con->read_string(read,256); if(read=="end:info"){ break; } ret.push_back(read); } return ret; } std::list session_manager::get_users_info(){ std::list ret; std::string read; this->con->write_string("uinf"); while(true){ this->con->read_string(read,256); if(read=="end:info"){ break; } ret.push_back(read); } return ret; } void session_manager::create_user(std::string username, std::string password, bool admin){ this->con->write_string("cusr"); this->con->write_string(username); this->con->write_string(password); this->con->write_string(admin?"t":"f"); } void session_manager::remove_user(std::string username){ this->con->write_string("rusr"); this->con->write_string(username); }