mirror of
https://github.com/outbackdingo/sysadm.git
synced 2026-01-28 10:20:22 +00:00
Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d018263559 | ||
|
|
b7fa03d2b8 | ||
|
|
f467df4133 |
@@ -159,6 +159,7 @@ void EventWatcher::CheckLogFiles(){
|
|||||||
void EventWatcher::ReadLPLogFile(){
|
void EventWatcher::ReadLPLogFile(){
|
||||||
//Open/Read any new info in the file
|
//Open/Read any new info in the file
|
||||||
QFile LPlogfile(LPLOG);
|
QFile LPlogfile(LPLOG);
|
||||||
|
if( !LPlogfile.exists() ){ return; }
|
||||||
if( !LPlogfile.open(QIODevice::ReadOnly) ){ return; } //could not open file
|
if( !LPlogfile.open(QIODevice::ReadOnly) ){ return; } //could not open file
|
||||||
QTextStream STREAM(&LPlogfile);
|
QTextStream STREAM(&LPlogfile);
|
||||||
qint64 LPlog_pos = CONFIG->value("internal/"+QString(WS_MODE ? "ws" : "tcp")+"/lp-log-pos",0).toLongLong();
|
qint64 LPlog_pos = CONFIG->value("internal/"+QString(WS_MODE ? "ws" : "tcp")+"/lp-log-pos",0).toLongLong();
|
||||||
@@ -259,7 +260,8 @@ void EventWatcher::ReadLPRepFile(){
|
|||||||
QString repTotK = CONFIG->value("internal/"+QString(WS_MODE ? "ws" : "tcp")+"/lp-rep-totk","").toString();
|
QString repTotK = CONFIG->value("internal/"+QString(WS_MODE ? "ws" : "tcp")+"/lp-rep-totk","").toString();
|
||||||
QString lastSize = CONFIG->value("internal/"+QString(WS_MODE ? "ws" : "tcp")+"/lp-rep-lastsize","").toString();
|
QString lastSize = CONFIG->value("internal/"+QString(WS_MODE ? "ws" : "tcp")+"/lp-rep-lastsize","").toString();
|
||||||
//Open/Read any new info in the file
|
//Open/Read any new info in the file
|
||||||
QFile LPlogfile(LPLOG);
|
QFile LPlogfile(tmpLPRepFile);
|
||||||
|
if( !LPlogfile.exists() ){ return; }
|
||||||
if( !LPlogfile.open(QIODevice::ReadOnly) ){ return; } //could not open file
|
if( !LPlogfile.open(QIODevice::ReadOnly) ){ return; } //could not open file
|
||||||
QTextStream STREAM(&LPlogfile);
|
QTextStream STREAM(&LPlogfile);
|
||||||
qint64 LPrep_pos = CONFIG->value("internal/"+QString(WS_MODE ? "ws" : "tcp")+"/lp-rep-pos",0).toLongLong();
|
qint64 LPrep_pos = CONFIG->value("internal/"+QString(WS_MODE ? "ws" : "tcp")+"/lp-rep-pos",0).toLongLong();
|
||||||
|
|||||||
@@ -379,13 +379,20 @@ QJsonArray PKG::list_repos(bool updated){
|
|||||||
QDir confdir(repodirs[d]);
|
QDir confdir(repodirs[d]);
|
||||||
QStringList confs = confdir.entryList(QStringList() << "*.conf", QDir::Files);
|
QStringList confs = confdir.entryList(QStringList() << "*.conf", QDir::Files);
|
||||||
for(int i=0; i<confs.length(); i++){
|
for(int i=0; i<confs.length(); i++){
|
||||||
QStringList repoinfo = General::readTextFile(confdir.absoluteFilePath(confs[i])).join("\n").split("\n}");
|
QStringList contents = General::readTextFile(confdir.absoluteFilePath(confs[i]));
|
||||||
|
//Scan for any comments on the top of the file and remove them
|
||||||
|
for(int l=0; l<contents.length(); l++){
|
||||||
|
if(contents[l].isEmpty() || contents[l].startsWith("#")){ contents.removeAt(l); l--; }
|
||||||
|
else{ break; }
|
||||||
|
}
|
||||||
|
QStringList repoinfo = contents.join("\n").split("\n}");
|
||||||
for(int j=0; j<repoinfo.length(); j++){
|
for(int j=0; j<repoinfo.length(); j++){
|
||||||
//qDebug() << "Repoinfo:" << repoinfo[j];
|
qDebug() << "Repoinfo:" << repoinfo[j];
|
||||||
QString repo = repoinfo[j].section(":",0,0).simplified();
|
QString repo = repoinfo[j].section(":",0,0).simplified();
|
||||||
QString enabled = repoinfo[j].section("enabled:",1,-1).section(":",0,0).toLower();
|
QString enabled = repoinfo[j].section("enabled:",1,-1).section(":",0,0).toLower();
|
||||||
bool isEnabled = (enabled.contains("yes") || enabled.contains("true"));
|
bool isEnabled = true;
|
||||||
//qDebug() << "Checking Repo:" << repo << enabled << isEnabled;
|
if(enabled.contains("no") || enabled.contains("false")){ isEnabled = false; }
|
||||||
|
qDebug() << "Checking Repo:" << repo << enabled << isEnabled;
|
||||||
if(QFile::exists(dbdir.arg(repo)) && isEnabled){ found << repo; }
|
if(QFile::exists(dbdir.arg(repo)) && isEnabled){ found << repo; }
|
||||||
} //loop over repos listed in conf
|
} //loop over repos listed in conf
|
||||||
} //loop over confs in repodir
|
} //loop over confs in repodir
|
||||||
|
|||||||
@@ -37,18 +37,17 @@ void MessageOutput(QtMsgType type, const QMessageLogContext &context, const QStr
|
|||||||
break;
|
break;
|
||||||
case QtWarningMsg:
|
case QtWarningMsg:
|
||||||
txt = QString("WARNING: %1").arg(msg);
|
txt = QString("WARNING: %1").arg(msg);
|
||||||
txt += "\n Context: "+QString(context.file)+" Line: "+QString(context.line)+" Function: "+QString(context.function);
|
|
||||||
break;
|
break;
|
||||||
case QtCriticalMsg:
|
case QtCriticalMsg:
|
||||||
txt = QString("CRITICAL: %1").arg(msg);
|
txt = QString("CRITICAL: %1").arg(msg);
|
||||||
txt += "\n Context: "+QString(context.file)+" Line: "+QString(context.line)+" Function: "+QString(context.function);
|
|
||||||
break;
|
break;
|
||||||
case QtFatalMsg:
|
case QtFatalMsg:
|
||||||
txt = QString("FATAL: %1").arg(msg);
|
txt = QString("FATAL: %1").arg(msg);
|
||||||
txt += "\n Context: "+QString(context.file)+" Line: "+QString(context.line)+" Function: "+QString(context.function);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
if( type!=QtDebugMsg && !QString(context.file).isEmpty() ){
|
||||||
|
txt += "\n Context: "+QString(context.file)+" Line: "+QString(context.line)+" Function: "+QString(context.function);
|
||||||
|
}
|
||||||
QTextStream out(&logfile);
|
QTextStream out(&logfile);
|
||||||
out << txt;
|
out << txt;
|
||||||
if(!txt.endsWith("\n")){ out << "\n"; }
|
if(!txt.endsWith("\n")){ out << "\n"; }
|
||||||
@@ -79,7 +78,6 @@ qDebug() << " \"bridge_export_key [file]\": Export the public SSL key the serve
|
|||||||
|
|
||||||
int main( int argc, char ** argv )
|
int main( int argc, char ** argv )
|
||||||
{
|
{
|
||||||
|
|
||||||
//Check whether running as root
|
//Check whether running as root
|
||||||
if( getuid() != 0){
|
if( getuid() != 0){
|
||||||
qDebug() << "sysadm-server must be started as root!";
|
qDebug() << "sysadm-server must be started as root!";
|
||||||
@@ -121,7 +119,7 @@ int main( int argc, char ** argv )
|
|||||||
QSslCertificate cert(&cfile);
|
QSslCertificate cert(&cfile);
|
||||||
cfile.close();
|
cfile.close();
|
||||||
if(!cert.isNull()){
|
if(!cert.isNull()){
|
||||||
if(i+1<argc){
|
if(i+1<argc){
|
||||||
i++; QString filepath = argv[i];
|
i++; QString filepath = argv[i];
|
||||||
QFile outfile(filepath);
|
QFile outfile(filepath);
|
||||||
outfile.open(QIODevice::WriteOnly | QIODevice::Truncate);
|
outfile.open(QIODevice::WriteOnly | QIODevice::Truncate);
|
||||||
@@ -150,11 +148,11 @@ int main( int argc, char ** argv )
|
|||||||
if(!file.open(QIODevice::ReadOnly)){ qDebug() << "Could not open file:" << file.fileName(); }
|
if(!file.open(QIODevice::ReadOnly)){ qDebug() << "Could not open file:" << file.fileName(); }
|
||||||
else{
|
else{
|
||||||
QByteArray enc_key;
|
QByteArray enc_key;
|
||||||
if(file.fileName().endsWith(".crt")){
|
if(file.fileName().endsWith(".crt")){
|
||||||
QSslCertificate cert(&file, QSsl::Pem);
|
QSslCertificate cert(&file, QSsl::Pem);
|
||||||
if(!cert.isNull()){ enc_key = cert.publicKey().toPem(); }
|
if(!cert.isNull()){ enc_key = cert.publicKey().toPem(); }
|
||||||
}else if(file.fileName().endsWith(".key")){
|
}else if(file.fileName().endsWith(".key")){
|
||||||
QSslKey key( &file, QSsl::Rsa, QSsl::Pem, QSsl::PublicKey);
|
QSslKey key( &file, QSsl::Rsa, QSsl::Pem, QSsl::PublicKey);
|
||||||
if(!key.isNull()){ enc_key = key.toPem(); }
|
if(!key.isNull()){ enc_key = key.toPem(); }
|
||||||
}else{
|
}else{
|
||||||
qDebug() << "Error: Unknown file type (need .crt or .key file)";
|
qDebug() << "Error: Unknown file type (need .crt or .key file)";
|
||||||
@@ -172,13 +170,13 @@ int main( int argc, char ** argv )
|
|||||||
if(QFile::exists(key)){
|
if(QFile::exists(key)){
|
||||||
QFile file(key);
|
QFile file(key);
|
||||||
QByteArray pubkey;
|
QByteArray pubkey;
|
||||||
if(file.open(QIODevice::ReadOnly)){
|
if(file.open(QIODevice::ReadOnly)){
|
||||||
QSslKey sslkey( &file, QSsl::Rsa, QSsl::Pem, QSsl::PublicKey);
|
QSslKey sslkey( &file, QSsl::Rsa, QSsl::Pem, QSsl::PublicKey);
|
||||||
if(!key.isNull()){ pubkey = sslkey.toPem(); }
|
if(!key.isNull()){ pubkey = sslkey.toPem(); }
|
||||||
else{ qDebug() << "Invalid Key file:" << file.fileName(); ok = false; }
|
else{ qDebug() << "Invalid Key file:" << file.fileName(); ok = false; }
|
||||||
file.close();
|
file.close();
|
||||||
}else{ qDebug() << "Could not open file:" << file.fileName(); ok = false; }
|
}else{ qDebug() << "Could not open file:" << file.fileName(); ok = false; }
|
||||||
}
|
}
|
||||||
if(ok){ ok = AuthorizationManager::RegisterCertificateInternal(user, key, nickname, email); }
|
if(ok){ ok = AuthorizationManager::RegisterCertificateInternal(user, key, nickname, email); }
|
||||||
if(ok){ qDebug() << "Key Added" << user << nickname; }
|
if(ok){ qDebug() << "Key Added" << user << nickname; }
|
||||||
else{ qDebug() << "Could not add key"; } */
|
else{ qDebug() << "Could not add key"; } */
|
||||||
@@ -193,18 +191,20 @@ int main( int argc, char ** argv )
|
|||||||
|
|
||||||
QCoreApplication a(argc, argv);
|
QCoreApplication a(argc, argv);
|
||||||
//Now load the config file
|
//Now load the config file
|
||||||
QStringList conf = ReadFile(CONFFILE).split("\n");
|
QString conf_file = CONFFILE;
|
||||||
|
if( !QFile::exists(conf_file) ){ conf_file.append(".dist"); } //no settings - use the default config
|
||||||
|
QStringList conf = ReadFile(conf_file).split("\n");
|
||||||
if(!conf.filter("[internal]").isEmpty()){
|
if(!conf.filter("[internal]").isEmpty()){
|
||||||
//Older QSettings file - move it to the new location
|
//Older QSettings file - move it to the new location
|
||||||
if(QFile::exists(SETTINGSFILE)){ QFile::remove(SETTINGSFILE); } //remove the new/empty settings file
|
if(QFile::exists(SETTINGSFILE)){ QFile::remove(SETTINGSFILE); } //remove the new/empty settings file
|
||||||
QFile::rename(CONFFILE, SETTINGSFILE);
|
QFile::copy(conf_file, SETTINGSFILE);
|
||||||
CONFIG->sync(); //re-sync settings structure
|
CONFIG->sync(); //re-sync settings structure
|
||||||
conf.clear(); //No config yet
|
conf.clear(); //No config yet
|
||||||
}
|
}
|
||||||
//Load the settings from the config file
|
//Load the settings from the config file
|
||||||
// - port number
|
// - port number
|
||||||
if(port==0){
|
if(port==0){
|
||||||
if(websocket){
|
if(websocket){
|
||||||
int index = conf.indexOf(QRegExp("PORT=*",Qt::CaseSensitive,QRegExp::Wildcard));
|
int index = conf.indexOf(QRegExp("PORT=*",Qt::CaseSensitive,QRegExp::Wildcard));
|
||||||
bool ok = false;
|
bool ok = false;
|
||||||
if(index>=0){ port = conf[index].section("=",1,1).toInt(&ok); }
|
if(index>=0){ port = conf[index].section("=",1,1).toInt(&ok); }
|
||||||
@@ -213,7 +213,7 @@ int main( int argc, char ** argv )
|
|||||||
int index = conf.indexOf(QRegExp("PORT_REST=*",Qt::CaseSensitive,QRegExp::Wildcard));
|
int index = conf.indexOf(QRegExp("PORT_REST=*",Qt::CaseSensitive,QRegExp::Wildcard));
|
||||||
bool ok = false;
|
bool ok = false;
|
||||||
if(index>=0){ port = conf[index].section("=",1,1).toInt(&ok); }
|
if(index>=0){ port = conf[index].section("=",1,1).toInt(&ok); }
|
||||||
if(port<=0 || !ok){ port = PORTNUMBER; }
|
if(port<=0 || !ok){ port = PORTNUMBER; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// - Blacklist options
|
// - Blacklist options
|
||||||
@@ -238,7 +238,7 @@ int main( int argc, char ** argv )
|
|||||||
rg = QRegExp("BRIDGE_CONNECTIONS_ONLY=*",Qt::CaseSensitive,QRegExp::Wildcard);
|
rg = QRegExp("BRIDGE_CONNECTIONS_ONLY=*",Qt::CaseSensitive,QRegExp::Wildcard);
|
||||||
if(!conf.filter(rg).isEmpty()){
|
if(!conf.filter(rg).isEmpty()){
|
||||||
BRIDGE_ONLY = conf.filter(rg).first().section("=",1,1).simplified().toLower()=="true";
|
BRIDGE_ONLY = conf.filter(rg).first().section("=",1,1).simplified().toLower()=="true";
|
||||||
}
|
}
|
||||||
|
|
||||||
//Setup the log file
|
//Setup the log file
|
||||||
LogManager::checkLogDir(); //ensure the logging directory exists
|
LogManager::checkLogDir(); //ensure the logging directory exists
|
||||||
@@ -254,18 +254,17 @@ int main( int argc, char ** argv )
|
|||||||
}
|
}
|
||||||
logfile.open(QIODevice::WriteOnly | QIODevice::Append);
|
logfile.open(QIODevice::WriteOnly | QIODevice::Append);
|
||||||
qInstallMessageHandler(MessageOutput);
|
qInstallMessageHandler(MessageOutput);
|
||||||
|
|
||||||
//Connect the background classes
|
//Connect the background classes
|
||||||
QObject::connect(DISPATCHER, SIGNAL(DispatchEvent(QJsonObject)), EVENTS, SLOT(DispatchEvent(QJsonObject)) );
|
QObject::connect(DISPATCHER, SIGNAL(DispatchEvent(QJsonObject)), EVENTS, SLOT(DispatchEvent(QJsonObject)) );
|
||||||
QObject::connect(DISPATCHER, SIGNAL(DispatchStarting(QString)), EVENTS, SLOT(DispatchStarting(QString)) );
|
QObject::connect(DISPATCHER, SIGNAL(DispatchStarting(QString)), EVENTS, SLOT(DispatchStarting(QString)) );
|
||||||
|
|
||||||
//Create the daemon
|
//Create the daemon
|
||||||
qDebug() << "Starting the PC-BSD sysadm server...." << (websocket ? "(WebSocket)" : "(TCP)");
|
qDebug() << "Starting the sysadm server...." << (websocket ? "(WebSocket)" : "(TCP)");
|
||||||
WebServer *w = new WebServer();
|
WebServer *w = new WebServer();
|
||||||
//Start the daemon
|
//Start the daemon
|
||||||
int ret = 1; //error return value
|
int ret = 1; //error return value
|
||||||
if( w->startServer(port, websocket) ){
|
if( w->startServer(port, websocket) ){
|
||||||
qDebug() << " - Configuration File:" << CONFIG->fileName();
|
//qDebug() << " - Configuration File:" << CONFIG->fileName();
|
||||||
QThread TBACK, TBACK2;
|
QThread TBACK, TBACK2;
|
||||||
EVENTS->moveToThread(&TBACK);
|
EVENTS->moveToThread(&TBACK);
|
||||||
DISPATCHER->moveToThread(&TBACK2);
|
DISPATCHER->moveToThread(&TBACK2);
|
||||||
@@ -283,7 +282,7 @@ int main( int argc, char ** argv )
|
|||||||
//Cleanup any globals
|
//Cleanup any globals
|
||||||
delete CONFIG;
|
delete CONFIG;
|
||||||
logfile.close();
|
logfile.close();
|
||||||
|
|
||||||
//Return
|
//Return
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user