diff --git a/README.md b/README.md index 0955090..be6a53d 100644 --- a/README.md +++ b/README.md @@ -50,6 +50,18 @@ url is an url to stikked server for example, if your server is http://something. The url parameter can be stored to configuration file (stikkit will ask you in case there is none in config file) +Configuration +===== + +The default configuration pulls the URL from /etc/stikkit/url - however, the better approach is to create your own config directory. The stikkit software will look for ".stikkit" in your home directory. + +Within this directory, there are a few key files worth creating. + + - *url* - Contains your base installation URL for stikked + - *apikey* - If your stikked installation requires an API key, save it in here + - *expiry* - The default expiry time (in minutes) for a paste, if needed + - *author* - The default author name if you wish to use one + Tips ===== diff --git a/stikkit/configuration.cpp b/stikkit/configuration.cpp index 0dddd2b..912836b 100644 --- a/stikkit/configuration.cpp +++ b/stikkit/configuration.cpp @@ -30,6 +30,7 @@ string Configuration::Home = ""; bool Configuration::NoExtras = false; string Configuration::Input = ""; string Configuration::DefaultURL = ""; +string Configuration::Apikey = ""; void Configuration::Init() { @@ -61,6 +62,36 @@ void Configuration::Init() Configuration::DefaultURL = line; } f.close(); + + //Apikey + ifstream fapi; + fapi.open(string(homedir + "/.stikkit/apikey").c_str()); + string lineapi; + if(getline(fapi, lineapi)) + { + Configuration::Apikey = lineapi; + } + fapi.close(); + + //expiry + ifstream fexp; + fexp.open(string(homedir + "/.stikkit/expiry").c_str()); + string lineexp; + if(getline(fexp, lineexp)) + { + Configuration::Expiry = lineexp; + } + fexp.close(); + + //author + ifstream fauth; + fauth.open(string(homedir + "/.stikkit/author").c_str()); + string lineauth; + if(getline(fauth, lineauth)) + { + Configuration::Author = lineauth; + } + fauth.close(); } if (Configuration::Author.length() < 1) { diff --git a/stikkit/configuration.hpp b/stikkit/configuration.hpp index 5cb2dc9..d0178b3 100644 --- a/stikkit/configuration.hpp +++ b/stikkit/configuration.hpp @@ -33,6 +33,7 @@ namespace Stikkit static string DefaultURL; static bool Private; static string Home; + static string Apikey; static bool NoExtras; }; } diff --git a/stikkit/main.cpp b/stikkit/main.cpp index d010650..75ee00b 100644 --- a/stikkit/main.cpp +++ b/stikkit/main.cpp @@ -103,6 +103,12 @@ int main(int argc, char *argv[]) readBuffer.clear(); string post = "text="; post += curl_easy_escape(curl, Stikkit::Configuration::Source.c_str(), Stikkit::Configuration::Source.length()); + if (Stikkit::Configuration::Apikey.length() > 0) + { + Stikkit::Configuration::URL += "?apikey="; + Stikkit::Configuration::URL += curl_easy_escape(curl, Stikkit::Configuration::Apikey.c_str(), Stikkit::Configuration::Apikey.length()); + } + if (Stikkit::Configuration::Author.length() > 0) { post += "&name="; diff --git a/stikkit/terminalparser.cpp b/stikkit/terminalparser.cpp index ab43b7e..d47af67 100644 --- a/stikkit/terminalparser.cpp +++ b/stikkit/terminalparser.cpp @@ -95,6 +95,17 @@ bool TerminalParser::Parse() cerr << "Parameter -i requires an argument for it to work!" << endl; return true; } + } else if (text.at(0) == 'k') + { + if (this->argc > x + 1 && !this->argv[x + 1][0] != '-') + { + x++; + Configuration::Apikey = this->argv[x]; + } else + { + cerr << "Parameter -k requires an argument for it to work!" << endl; + return true; + } } text = text.substr(1); } @@ -149,6 +160,7 @@ void TerminalParser::DisplayHelp() " -s: Display only RAW url of paste and no extra text\n"\ " -e : Set expiry in minutes, parameter needs\n"\ " to be a number, default: unlimited time\n"\ + " -k : Set api key for current server\n"\ " --version: Display a version\n"\ " -h | --help: Display this help\n\n"\ "Note: every argument in [brackets] is optional\n"\