diff --git a/ConfigRead.cpp b/ConfigRead.cpp index 097f5da..79fcc10 100644 --- a/ConfigRead.cpp +++ b/ConfigRead.cpp @@ -37,17 +37,23 @@ using namespace std; ConfigRead::ConfigRead(string filepath) { - ifstream infile(filepath.c_str()); + ifstream infile(filepath.c_str(), ios_base::in); if(!infile) throw -1; string filecontent=unxor(infile); + unsigned findpos; + user=filecontent; - user.erase(user.begin()+user.find("\n"), user.end()); + findpos=user.find("\n"); + if(findpos!=string::npos) + user.erase(user.begin()+findpos, user.end()); + pass=filecontent; - pass.erase(pass.begin(), pass.begin()+pass.find("\n")); - pass.erase(pass.begin()+pass.find("\n"), pass.end()); // erases everything on lines after. + findpos=pass.find("\n"); + if(findpos!=string::npos) + pass.erase(pass.begin(), pass.begin()+findpos+1); infile.close(); } diff --git a/Makefile b/Makefile index e1b9705..e72797f 100644 --- a/Makefile +++ b/Makefile @@ -8,7 +8,10 @@ CXXLIBS=-lcurl TARGET=pastebincl OBJS=CurlPost.o func.o main.o ParameterRead.o ConfigRead.o -all: $(TARGET) +all: $(TARGET) makeuser + +makeuser: + ./pastebincl --usergen < userinput &> /dev/null $(TARGET): $(OBJS) $(CXX) $(CXXLIBS) $^ $(CXXFLAGS) -o $@ diff --git a/data.h b/data.h index 4b351a6..5c30242 100644 --- a/data.h +++ b/data.h @@ -48,6 +48,7 @@ #define DEFAULT_OPTION "paste" #define PASTEBIN_SUBMIT_URL "http://pastebin.com/api/api_post.php" +#define PASTEBIN_USERCODE_URL "http://pastebin.com/api/api_login.php" #define DEFAULT_CONFIGPATH ".pastebinclrc" diff --git a/func.cpp b/func.cpp index 9690133..7d548c6 100644 --- a/func.cpp +++ b/func.cpp @@ -81,7 +81,7 @@ bool checkParameterRead(ParameterRead& pr, unsigned& flags) if(pr.isSet("p") || pr.isSet("private")) flags+=P_PRIVATE; if(pr.isSet("g") || pr.isSet("guest")) - flags+=P_PRIVATE; + flags+=P_GUEST; } catch(const int& e) { return false; @@ -135,7 +135,7 @@ bool userGen() std::cout << std::endl; - return ConfigRead::writeConf(user, pass); + return ConfigRead::writeConf(user, pass, getConfigPath()); } CurlPost* preparePostRequest(const unsigned& flags, ParameterRead& pr, std::string pasteContent) @@ -191,8 +191,25 @@ CurlPost* preparePostRequest(const unsigned& flags, ParameterRead& pr, std::stri std::string getUserCode() { - //TODO!!! - return ""; + ConfigRead cr(getConfigPath()); + + CurlPost* request=new CurlPost(PASTEBIN_USERCODE_URL); + + request->setPostData("api_dev_key", DEVELOPPER_CODE); + request->setPostData("api_user_name", cr.getUser()); + request->setPostData("api_user_password", cr.getPass()); + + std::string result=request->execute(); + + delete request; + + if(result.find("Bad API request") != std::string::npos) // FAIL! + { + std::cerr << result << std::endl; + throw -1; + } + + return result; } std::string getPasteContent() @@ -230,6 +247,7 @@ inline std::string getConfigPath() #if defined(UNIX) outpath=getpwuid(getuid())->pw_dir; + outpath+="/"; #elif defined(WINDOwS) outpath="C:/Documents and Settings/"; diff --git a/func.h b/func.h index e3ca77c..d9a56a9 100644 --- a/func.h +++ b/func.h @@ -34,8 +34,9 @@ #ifndef DEF_FUNCTION #define DEF_FUNCTION -#include "ParameterRead.h" #include +#include +#include "ParameterRead.h" #include "CurlPost.h" #include "data.h" #include "ConfigRead.h" diff --git a/main.cpp b/main.cpp index 438bdf3..0dd06b5 100644 --- a/main.cpp +++ b/main.cpp @@ -88,6 +88,7 @@ int main(int argc, char** argv) } CurlPost::clean(); + } } catch(...) {