mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2024-12-23 23:02:23 +00:00
Fix -h in zerotier-cli and move code to find auth token into LocalClient, also move auth token for mac into Mac-standard Library/Application Support location.
This commit is contained in:
parent
baea75f2df
commit
22b52858e0
@ -1,4 +1,4 @@
|
||||
QT += core gui widgets
|
||||
QT += core gui widgets network
|
||||
TARGET = "ZeroTier One"
|
||||
TEMPLATE = app
|
||||
|
||||
|
@ -79,6 +79,10 @@ void MainWindow::timerEvent(QTimerEvent *event)
|
||||
{
|
||||
event->accept();
|
||||
|
||||
#ifdef __APPLE__
|
||||
#else
|
||||
#endif
|
||||
|
||||
if (!zeroTierClient) {
|
||||
std::string dotAuthFile((QDir::homePath() + QDir::separator() + ".zeroTierOneAuthToken").toStdString());
|
||||
std::string authToken;
|
||||
|
25
main.cpp
25
main.cpp
@ -161,6 +161,9 @@ static int main(int argc,char **argv)
|
||||
return -2;
|
||||
}
|
||||
break;
|
||||
case 'h':
|
||||
printHelp(stdout,argv[0]);
|
||||
return 0;
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
@ -178,26 +181,10 @@ static int main(int argc,char **argv)
|
||||
}
|
||||
|
||||
if (!authToken.length()) {
|
||||
const char *home = getenv("HOME");
|
||||
if (home) {
|
||||
std::string dotZeroTierAuthToken(home);
|
||||
dotZeroTierAuthToken.push_back(ZT_PATH_SEPARATOR);
|
||||
dotZeroTierAuthToken.append(".zerotierOneAuthToken");
|
||||
if (!Utils::readFile(dotZeroTierAuthToken.c_str(),authToken)) {
|
||||
#ifndef __WINDOWS__
|
||||
#ifdef __APPLE__
|
||||
const char *systemAuthTokenPath = "/Library/Application Support/ZeroTier/One/authtoken.secret";
|
||||
#else
|
||||
const char *systemAuthTokenPath = "/var/lib/zerotier-one/authtoken.secret";
|
||||
#endif
|
||||
if (!Utils::readFile(systemAuthTokenPath,authToken)) {
|
||||
fprintf(stdout,"FATAL ERROR: no token specified on command line and could not read '%s' or '%s'"ZT_EOL_S,dotZeroTierAuthToken.c_str(),systemAuthTokenPath);
|
||||
return -2;
|
||||
}
|
||||
#else // __WINDOWS__
|
||||
fprintf(stdout,"FATAL ERROR: no token specified on command line and could not read '%s'"ZT_EOL_S,dotZeroTierAuthToken.c_str());
|
||||
if (!Utils::readFile(Node::LocalClient::authTokenDefaultUserPath().c_str(),authToken)) {
|
||||
if (!Utils::readFile(Node::LocalClient::authTokenDefaultSystemPath().c_str(),authToken)) {
|
||||
fprintf(stdout,"FATAL ERROR: no token specified on command line and could not read '%s' or '%s'"ZT_EOL_S,Node::LocalClient::authTokenDefaultSystemPath().c_str(),Node::LocalClient::authTokenDefaultUserPath().c_str());
|
||||
return -2;
|
||||
#endif // __WINDOWS__
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -188,6 +188,32 @@ std::vector<std::string> Node::LocalClient::splitLine(const char *line)
|
||||
return Utils::split(line," ","\\","\"");
|
||||
}
|
||||
|
||||
std::string Node::LocalClient::authTokenDefaultUserPath()
|
||||
{
|
||||
const char *home = getenv("HOME");
|
||||
if (home) {
|
||||
#ifdef __APPLE__
|
||||
return (std::string(home) + "/Library/Application Support/ZeroTier/One/authtoken.secret");
|
||||
#else
|
||||
return (std::string(home) + "/.zeroTierOneAuthToken");
|
||||
#endif
|
||||
}
|
||||
return std::string();
|
||||
}
|
||||
|
||||
std::string Node::LocalClient::authTokenDefaultSystemPath()
|
||||
{
|
||||
#ifdef __WINDOWS__
|
||||
// TODO
|
||||
#else
|
||||
#ifdef __APPLE__
|
||||
return "/Library/Application Support/ZeroTier/One/authtoken.secret";
|
||||
#else
|
||||
return "/var/lib/zerotier-one/authtoken.secret";
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
struct _NodeImpl
|
||||
{
|
||||
RuntimeEnvironment renv;
|
||||
|
@ -84,6 +84,16 @@ public:
|
||||
static std::vector<std::string> splitLine(const char *line);
|
||||
static inline std::vector<std::string> splitLine(const std::string &line) { return splitLine(line.c_str()); }
|
||||
|
||||
/**
|
||||
* @return Default path for user-local authorization token for the current user or empty string if cannot be determined
|
||||
*/
|
||||
static std::string authTokenDefaultUserPath();
|
||||
|
||||
/**
|
||||
* @return Default system path for auth token on this platform
|
||||
*/
|
||||
static std::string authTokenDefaultSystemPath();
|
||||
|
||||
private:
|
||||
// LocalClient is not copyable
|
||||
LocalClient(const LocalClient&);
|
||||
|
Loading…
Reference in New Issue
Block a user