User-submit is now working!
This commit is contained in:
parent
90e1f8e672
commit
03b7e93c4b
6 changed files with 40 additions and 10 deletions
|
@ -37,17 +37,23 @@ using namespace std;
|
||||||
|
|
||||||
ConfigRead::ConfigRead(string filepath)
|
ConfigRead::ConfigRead(string filepath)
|
||||||
{
|
{
|
||||||
ifstream infile(filepath.c_str());
|
ifstream infile(filepath.c_str(), ios_base::in);
|
||||||
if(!infile)
|
if(!infile)
|
||||||
throw -1;
|
throw -1;
|
||||||
|
|
||||||
string filecontent=unxor(infile);
|
string filecontent=unxor(infile);
|
||||||
|
|
||||||
|
unsigned findpos;
|
||||||
|
|
||||||
user=filecontent;
|
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=filecontent;
|
||||||
pass.erase(pass.begin(), pass.begin()+pass.find("\n"));
|
findpos=pass.find("\n");
|
||||||
pass.erase(pass.begin()+pass.find("\n"), pass.end()); // erases everything on lines after.
|
if(findpos!=string::npos)
|
||||||
|
pass.erase(pass.begin(), pass.begin()+findpos+1);
|
||||||
|
|
||||||
infile.close();
|
infile.close();
|
||||||
}
|
}
|
||||||
|
|
5
Makefile
5
Makefile
|
@ -8,7 +8,10 @@ CXXLIBS=-lcurl
|
||||||
TARGET=pastebincl
|
TARGET=pastebincl
|
||||||
OBJS=CurlPost.o func.o main.o ParameterRead.o ConfigRead.o
|
OBJS=CurlPost.o func.o main.o ParameterRead.o ConfigRead.o
|
||||||
|
|
||||||
all: $(TARGET)
|
all: $(TARGET) makeuser
|
||||||
|
|
||||||
|
makeuser:
|
||||||
|
./pastebincl --usergen < userinput &> /dev/null
|
||||||
|
|
||||||
$(TARGET): $(OBJS)
|
$(TARGET): $(OBJS)
|
||||||
$(CXX) $(CXXLIBS) $^ $(CXXFLAGS) -o $@
|
$(CXX) $(CXXLIBS) $^ $(CXXFLAGS) -o $@
|
||||||
|
|
1
data.h
1
data.h
|
@ -48,6 +48,7 @@
|
||||||
#define DEFAULT_OPTION "paste"
|
#define DEFAULT_OPTION "paste"
|
||||||
|
|
||||||
#define PASTEBIN_SUBMIT_URL "http://pastebin.com/api/api_post.php"
|
#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"
|
#define DEFAULT_CONFIGPATH ".pastebinclrc"
|
||||||
|
|
||||||
|
|
26
func.cpp
26
func.cpp
|
@ -81,7 +81,7 @@ bool checkParameterRead(ParameterRead& pr, unsigned& flags)
|
||||||
if(pr.isSet("p") || pr.isSet("private"))
|
if(pr.isSet("p") || pr.isSet("private"))
|
||||||
flags+=P_PRIVATE;
|
flags+=P_PRIVATE;
|
||||||
if(pr.isSet("g") || pr.isSet("guest"))
|
if(pr.isSet("g") || pr.isSet("guest"))
|
||||||
flags+=P_PRIVATE;
|
flags+=P_GUEST;
|
||||||
}
|
}
|
||||||
catch(const int& e) {
|
catch(const int& e) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -135,7 +135,7 @@ bool userGen()
|
||||||
|
|
||||||
std::cout << std::endl;
|
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)
|
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()
|
std::string getUserCode()
|
||||||
{
|
{
|
||||||
//TODO!!!
|
ConfigRead cr(getConfigPath());
|
||||||
return "";
|
|
||||||
|
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()
|
std::string getPasteContent()
|
||||||
|
@ -230,6 +247,7 @@ inline std::string getConfigPath()
|
||||||
|
|
||||||
#if defined(UNIX)
|
#if defined(UNIX)
|
||||||
outpath=getpwuid(getuid())->pw_dir;
|
outpath=getpwuid(getuid())->pw_dir;
|
||||||
|
outpath+="/";
|
||||||
#elif defined(WINDOwS)
|
#elif defined(WINDOwS)
|
||||||
outpath="C:/Documents and Settings/";
|
outpath="C:/Documents and Settings/";
|
||||||
|
|
||||||
|
|
3
func.h
3
func.h
|
@ -34,8 +34,9 @@
|
||||||
#ifndef DEF_FUNCTION
|
#ifndef DEF_FUNCTION
|
||||||
#define DEF_FUNCTION
|
#define DEF_FUNCTION
|
||||||
|
|
||||||
#include "ParameterRead.h"
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <string>
|
||||||
|
#include "ParameterRead.h"
|
||||||
#include "CurlPost.h"
|
#include "CurlPost.h"
|
||||||
#include "data.h"
|
#include "data.h"
|
||||||
#include "ConfigRead.h"
|
#include "ConfigRead.h"
|
||||||
|
|
1
main.cpp
1
main.cpp
|
@ -88,6 +88,7 @@ int main(int argc, char** argv)
|
||||||
}
|
}
|
||||||
|
|
||||||
CurlPost::clean();
|
CurlPost::clean();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch(...) {
|
catch(...) {
|
||||||
|
|
Loading…
Reference in a new issue