Compare commits

...

10 Commits

Author SHA1 Message Date
Framawiki
d9f75dc9d4 Add version in useragent 2017-05-09 10:12:01 +02:00
Framawiki
3160b2f25f Add "--help" in README.md 2017-05-09 10:12:01 +02:00
Framawiki
7d0ad8b550 Print output on a new line 2017-05-09 10:12:01 +02:00
Framawiki
885c4f441c Small changes 2017-05-09 10:12:01 +02:00
Framawiki
950094775c Add support of "~/.stikkit/private" 2017-05-09 10:12:01 +02:00
efbdaa0c6d Added support for -l <lang> and /etc/stikkit/apikey 2017-05-09 10:10:42 +02:00
Petr Bena
dcba663d8d Merge pull request #4 from Pitriss/master
Added support for apikey, and reading apikey / expiry from conf
2015-12-08 14:51:43 +01:00
Pitriss
d65aee1cbf Merge pull request #1 from stevesbrain/master
Added configuration file doco
2015-10-26 06:45:05 +01:00
Steve Divskinsy
c2aa1ca3d1 Added configuration file doco
Bit more detailed configuration file doco added to ensure it's obvious to new users - I had to take a look at the source code to know which files do which. This prevents others from having to do the same
2015-10-26 15:58:33 +10:30
BuildTools
14ad63ba98 Added support for apikey, and reading apikey / expiry from conf 2015-09-28 20:29:23 +02:00
5 changed files with 121 additions and 5 deletions

View File

@ -31,14 +31,16 @@ Checkout this repository
cd stikkit cd stikkit
cmake . cmake .
make make
make install sudo make install
``` ```
NOTE: you need to have libcurl-dev installed in your system NOTE: you need to have `libcurl-dev` installed in your system
Usage Usage
===== =====
See `stikkit --help` for detailed help about options.
``` ```
stikkit -b url stikkit -b url
# now type text and hit ctrl+d to exit # now type text and hit ctrl+d to exit
@ -50,9 +52,22 @@ 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
- *private* - If you want to mark the paste as private (not visible in recent pastes), create this empty file
Tips Tips
===== =====
Do you have a server and want to setup default pastebin site for all users in system? Do you have a server and want to setup default pastebin site for all users in system?
Create /etc/stikkit/url which contains the url of default pastebin site. Users will be able to override it, but by default everyone on system will use this Create `/etc/stikkit/url` which contains the url of default pastebin site. Users will be able to override it, but by default everyone on system will use this

View File

@ -30,6 +30,8 @@ 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 = "";
string Configuration::Lang = "";
void Configuration::Init() void Configuration::Init()
{ {
@ -48,6 +50,17 @@ void Configuration::Init()
} }
f.close(); f.close();
} }
if (stat("/etc/stikkit/apikey", &st) != -1)
{
ifstream f;
f.open("/etc/stikkit/apikey");
string line;
if (getline(f, line))
{
Configuration::Apikey = line;
}
f.close();
}
if (stat(string(homedir + "/.stikkit").c_str(), &st) == -1) if (stat(string(homedir + "/.stikkit").c_str(), &st) == -1)
{ {
mkdir(string(homedir + "/.stikkit").c_str(), 0750); mkdir(string(homedir + "/.stikkit").c_str(), 0750);
@ -61,6 +74,53 @@ 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();
//Lang
ifstream flang;
flang.open(string(homedir + "/.stikkit/lang").c_str());
string linelang;
if(getline(flang, linelang))
{
Configuration::Lang = linelang;
}
flang.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();
//private
std::ifstream fpriv(homedir + "/.stikkit/private");
if(fpriv.good())
{
Configuration::Private = true;
}
} }
if (Configuration::Author.length() < 1) if (Configuration::Author.length() < 1)
{ {

View File

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

View File

@ -103,6 +103,18 @@ 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::Lang.length() > 0)
{
post += "&lang=";
post += curl_easy_escape(curl, Stikkit::Configuration::Lang.c_str(), Stikkit::Configuration::Lang.length());
}
if (Stikkit::Configuration::Author.length() > 0) if (Stikkit::Configuration::Author.length() > 0)
{ {
post += "&name="; post += "&name=";
@ -117,14 +129,17 @@ int main(int argc, char *argv[])
post += "&private=1"; post += "&private=1";
if (Stikkit::Configuration::Expiry != "0") if (Stikkit::Configuration::Expiry != "0")
post += "&expire=" + Stikkit::Configuration::Expiry; post += "&expire=" + Stikkit::Configuration::Expiry;
string useragent;
useragent = "Stikkit " + Stikkit::Configuration::Version + " (https://github.com/benapetr/stikkit/)";
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback);
curl_easy_setopt(curl, CURLOPT_URL, Stikkit::Configuration::URL.c_str()); curl_easy_setopt(curl, CURLOPT_URL, Stikkit::Configuration::URL.c_str());
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, post.c_str()); curl_easy_setopt(curl, CURLOPT_POSTFIELDS, post.c_str());
curl_easy_setopt(curl, CURLOPT_USERAGENT, "stikkit"); curl_easy_setopt(curl, CURLOPT_USERAGENT, useragent.c_str());
/* Perform the request, res will get the return code */ /* Perform the request, res will get the return HTTP code */
res = curl_easy_perform(curl); res = curl_easy_perform(curl);
/* Check for errors */ /* Check for errors */
cerr << "\n";
if(res != CURLE_OK) if(res != CURLE_OK)
{ {
cerr << "curl_easy_perform() failed: " << curl_easy_strerror(res) << endl; cerr << "curl_easy_perform() failed: " << curl_easy_strerror(res) << endl;

View File

@ -95,6 +95,28 @@ 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;
}
} else if (text.at(0) == 'l')
{
if (this->argc > x + 1 && !this->argv[x + 1][0] != '-')
{
x++;
Configuration::Lang = this->argv[x];
} else
{
cerr << "Parameter -l requires an argument for it to work!" << endl;
return true;
}
} }
text = text.substr(1); text = text.substr(1);
} }
@ -149,6 +171,8 @@ 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"\
" -l <lang>: Set paste lang for syntax highlighting\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"\