Merge pull request #4 from Pitriss/master

Added support for apikey, and reading apikey / expiry from conf
This commit is contained in:
Petr Bena 2015-12-08 14:51:43 +01:00
commit dcba663d8d
5 changed files with 62 additions and 0 deletions

View File

@ -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) 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 Tips
===== =====

View File

@ -30,6 +30,7 @@ string Configuration::Home = "";
bool Configuration::NoExtras = false; bool Configuration::NoExtras = false;
string Configuration::Input = ""; string Configuration::Input = "";
string Configuration::DefaultURL = ""; string Configuration::DefaultURL = "";
string Configuration::Apikey = "";
void Configuration::Init() void Configuration::Init()
{ {
@ -61,6 +62,36 @@ void Configuration::Init()
Configuration::DefaultURL = line; Configuration::DefaultURL = line;
} }
f.close(); 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) if (Configuration::Author.length() < 1)
{ {

View File

@ -33,6 +33,7 @@ namespace Stikkit
static string DefaultURL; static string DefaultURL;
static bool Private; static bool Private;
static string Home; static string Home;
static string Apikey;
static bool NoExtras; static bool NoExtras;
}; };
} }

View File

@ -103,6 +103,12 @@ int main(int argc, char *argv[])
readBuffer.clear(); readBuffer.clear();
string post = "text="; string post = "text=";
post += curl_easy_escape(curl, Stikkit::Configuration::Source.c_str(), Stikkit::Configuration::Source.length()); 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) if (Stikkit::Configuration::Author.length() > 0)
{ {
post += "&name="; post += "&name=";

View File

@ -95,6 +95,17 @@ bool TerminalParser::Parse()
cerr << "Parameter -i requires an argument for it to work!" << endl; cerr << "Parameter -i requires an argument for it to work!" << endl;
return true; 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); text = text.substr(1);
} }
@ -149,6 +160,7 @@ void TerminalParser::DisplayHelp()
" -s: Display only RAW url of paste and no extra text\n"\ " -s: Display only RAW url of paste and no extra text\n"\
" -e <minutes>: Set expiry in minutes, parameter needs\n"\ " -e <minutes>: Set expiry in minutes, parameter needs\n"\
" to be a number, default: unlimited time\n"\ " to be a number, default: unlimited time\n"\
" -k <apikey>: Set api key for current server\n"\
" --version: Display a version\n"\ " --version: Display a version\n"\
" -h | --help: Display this help\n\n"\ " -h | --help: Display this help\n\n"\
"Note: every argument in [brackets] is optional\n"\ "Note: every argument in [brackets] is optional\n"\