mirror of
https://github.com/benapetr/stikkit.git
synced 2025-04-25 20:41:20 -05:00
improved
This commit is contained in:
parent
003f4afdfb
commit
27018e73b4
@ -8,6 +8,12 @@
|
||||
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
//GNU General Public License for more details.
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <pwd.h>
|
||||
#include "configuration.hpp"
|
||||
using namespace Stikkit;
|
||||
using namespace std;
|
||||
@ -15,5 +21,52 @@ using namespace std;
|
||||
unsigned int Configuration::Verbosity = 0;
|
||||
string Configuration::Source = "";
|
||||
string Configuration::URL = "";
|
||||
string Configuration::Expiry = "60";
|
||||
string Configuration::Author = "";
|
||||
string Configuration::Version = "1.0.0";
|
||||
string Configuration::Title = "";
|
||||
string Configuration::Home = "";
|
||||
string Configuration::DefaultURL = "";
|
||||
|
||||
void Configuration::Init()
|
||||
{
|
||||
struct stat st;
|
||||
struct passwd *pw = getpwuid(getuid());
|
||||
string homedir = pw->pw_dir;
|
||||
Configuration::Home = homedir;
|
||||
if (stat("/etc/stikkit/url", &st) != -1)
|
||||
{
|
||||
ifstream f;
|
||||
f.open("/etc/stikkit/url");
|
||||
string line;
|
||||
if (getline(f, line))
|
||||
{
|
||||
Configuration::DefaultURL = line;
|
||||
}
|
||||
f.close();
|
||||
}
|
||||
if (stat(string(homedir + "/.stikkit").c_str(), &st) == -1)
|
||||
{
|
||||
mkdir(string(homedir + "/.stikkit").c_str(), 0750);
|
||||
} else
|
||||
{
|
||||
ifstream f;
|
||||
f.open(string(homedir + "/.stikkit/url").c_str());
|
||||
string line;
|
||||
if(getline(f, line))
|
||||
{
|
||||
Configuration::DefaultURL = line;
|
||||
}
|
||||
f.close();
|
||||
}
|
||||
}
|
||||
|
||||
void Configuration::Store()
|
||||
{
|
||||
ofstream myfile (string(Configuration::Home + "/.stikkit/url").c_str());
|
||||
if (myfile.is_open())
|
||||
{
|
||||
myfile << Configuration::URL << "\n";
|
||||
myfile.close();
|
||||
}
|
||||
}
|
||||
|
@ -20,12 +20,18 @@ namespace Stikkit
|
||||
class Configuration
|
||||
{
|
||||
public:
|
||||
static void Init();
|
||||
static void Store();
|
||||
static unsigned int Verbosity;
|
||||
static string URL;
|
||||
static string Source;
|
||||
static string Input;
|
||||
static string Author;
|
||||
static string Title;
|
||||
static string Version;
|
||||
static string Expiry;
|
||||
static string DefaultURL;
|
||||
static string Home;
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -10,6 +10,7 @@
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <unistd.h>
|
||||
#include <curl/curl.h>
|
||||
#include "configuration.hpp"
|
||||
#include "terminalparser.hpp"
|
||||
@ -26,6 +27,7 @@ static size_t WriteCallback(void *contents, size_t size, size_t nmemb)
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
Stikkit::Configuration::Init();
|
||||
Stikkit::TerminalParser *t = new Stikkit::TerminalParser(argc, argv);
|
||||
if (t->Parse())
|
||||
{
|
||||
@ -33,10 +35,42 @@ int main(int argc, char *argv[])
|
||||
return 0;
|
||||
}
|
||||
delete t;
|
||||
if (!Stikkit::Configuration::Author.length())
|
||||
{
|
||||
char buffer[200];
|
||||
if (getlogin_r(buffer, 200))
|
||||
{
|
||||
Stikkit::Configuration::Author = buffer;
|
||||
}
|
||||
}
|
||||
if (!Stikkit::Configuration::URL.length())
|
||||
{
|
||||
Stikkit::Syslog::ErrorLog("No URL to stikked server provided, use stikkit -b <URL>");
|
||||
return 20;
|
||||
if (Stikkit::Configuration::DefaultURL.length() > 0)
|
||||
{
|
||||
Stikkit::Configuration::URL = Stikkit::Configuration::DefaultURL;
|
||||
} else
|
||||
{
|
||||
Stikkit::Syslog::ErrorLog("No URL to stikked server provided, use stikkit -b <URL>");
|
||||
return 20;
|
||||
}
|
||||
}
|
||||
if (!Stikkit::Configuration::DefaultURL.length())
|
||||
{
|
||||
std::cout << "There is no default URL stored in configuration files, do you want to set " <<
|
||||
Stikkit::Configuration::URL << " as a default URL? (y/n)";
|
||||
string response;
|
||||
std::cin >> response;
|
||||
if (response == "y" || response == "n")
|
||||
{
|
||||
if (response[0] == 'y')
|
||||
{
|
||||
Stikkit::Configuration::Store();
|
||||
}
|
||||
} else
|
||||
{
|
||||
Stikkit::Syslog::ErrorLog("Invalid option!");
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
Stikkit::Configuration::URL += "/api/create";
|
||||
std::string line;
|
||||
|
@ -106,6 +106,8 @@ void TerminalParser::DisplayHelp()
|
||||
|
||||
cout << "Stikkit - open source pastebin uploader for Stikked\n\n"\
|
||||
"Parameters:\n"\
|
||||
" -a <name>: Specify author name\n"\
|
||||
" -b <url>: Specify URL of Stikked server\n"\
|
||||
" -v: Increases verbosity\n"\
|
||||
" --version: Display a version\n"\
|
||||
" -h | --help: Display this help\n\n"\
|
||||
|
Loading…
x
Reference in New Issue
Block a user