3 Commits
1.1 ... master

Author SHA1 Message Date
Ken Moore
d018263559 Reverse the pkg repo enabled logic.
default to enabled, look for no/false section to disable.
Seems to fix the issue with a repo config file not including the enabled section at all, but pkg still using it.
2019-05-23 19:51:51 -04:00
Ken Moore
b7fa03d2b8 Fix up sysadm to work with the corrupted/modified version of the pkg config files that sysup now auto-generates. 2018-12-11 09:32:29 -05:00
Ken Moore
f467df4133 Cleanup some config-file logic and other random file-handling 2018-11-28 08:15:31 -05:00
3 changed files with 37 additions and 29 deletions

View File

@@ -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();

View File

@@ -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

View File

@@ -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!";
@@ -193,11 +191,13 @@ 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
} }
@@ -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);