|
@@ -1,16 +1,24 @@
|
|
|
+#include "terminal.h"
|
|
|
+#include "utils.h"
|
|
|
+#include "wordplay.h"
|
|
|
+#include <ctype.h>
|
|
|
#include <fcntl.h>
|
|
|
+#include <fstream>
|
|
|
+#include <iostream>
|
|
|
#include <pty.h>
|
|
|
+#include <sstream>
|
|
|
#include <stdio.h>
|
|
|
+#include <stdlib.h> // random()
|
|
|
#include <string.h>
|
|
|
+#include <string>
|
|
|
+#include <strings.h> // strcasecmp
|
|
|
#include <sys/select.h>
|
|
|
#include <sys/wait.h>
|
|
|
#include <termios.h>
|
|
|
+#include <time.h>
|
|
|
#include <unistd.h>
|
|
|
|
|
|
-#include <fstream>
|
|
|
-#include <iostream>
|
|
|
-#include <sstream>
|
|
|
-#include <string>
|
|
|
+struct console_details console;
|
|
|
|
|
|
/*
|
|
|
We get the username/fullname from tailing the node logs,
|
|
@@ -19,16 +27,8 @@ and reading the user.dat file.
|
|
|
std::string username;
|
|
|
std::string fullname;
|
|
|
|
|
|
-using namespace std;
|
|
|
-
|
|
|
// #include <signal.h> // handle Ctrl-C/SIGINT
|
|
|
|
|
|
-#include <strings.h> // strcasecmp
|
|
|
-#include <time.h>
|
|
|
-
|
|
|
-#include <ctype.h>
|
|
|
-#include <stdlib.h> // random()
|
|
|
-
|
|
|
/* Log level guideline:
|
|
|
* - ZF_LOG_FATAL - happened something impossible and absolutely unexpected.
|
|
|
* Process can't continue and must be terminated.
|
|
@@ -65,6 +65,7 @@ using namespace std;
|
|
|
// zf_log.h is included.
|
|
|
|
|
|
// LOGGING with file output
|
|
|
+
|
|
|
#include "zf_log.h"
|
|
|
|
|
|
FILE *g_log_file;
|
|
@@ -93,13 +94,6 @@ void log_flush(void) { fflush(g_log_file); }
|
|
|
|
|
|
// END LOGGING
|
|
|
|
|
|
-#include "terminal.h"
|
|
|
-#include "utils.h"
|
|
|
-
|
|
|
-struct console_details console;
|
|
|
-
|
|
|
-#include "wordplay.h"
|
|
|
-
|
|
|
/*
|
|
|
What is the name of the actual, real Mystic executable
|
|
|
that we'll be executing and mangling?
|
|
@@ -149,18 +143,18 @@ int locate_user(const char *alias) {
|
|
|
return 1;
|
|
|
}
|
|
|
|
|
|
-ifstream logfile;
|
|
|
-streampos log_pos;
|
|
|
+std::ifstream logfile;
|
|
|
+std::streampos log_pos;
|
|
|
|
|
|
void open_mystic_log(void) {
|
|
|
- string mystic_logfile;
|
|
|
+ std::string mystic_logfile;
|
|
|
{
|
|
|
- ostringstream buffer;
|
|
|
+ std::ostringstream buffer;
|
|
|
|
|
|
buffer << "logs/node" << node << ".log";
|
|
|
mystic_logfile = buffer.str();
|
|
|
};
|
|
|
- logfile.open(mystic_logfile, ios_base::in | ios_base::ate);
|
|
|
+ logfile.open(mystic_logfile, std::ios_base::in | std::ios_base::ate);
|
|
|
// Ok, we're at the end of the file. Or should be.
|
|
|
if (logfile.is_open()) {
|
|
|
ZF_LOGD("Log %s open", (const char *)mystic_logfile.c_str());
|
|
@@ -175,24 +169,24 @@ void scan_mystic_log(void) {
|
|
|
if (logfile.is_open()) {
|
|
|
int again = 0;
|
|
|
do {
|
|
|
- string line = find_new_text(logfile, log_pos);
|
|
|
+ std::string line = find_new_text(logfile, log_pos);
|
|
|
if (line.empty())
|
|
|
return;
|
|
|
again = 1;
|
|
|
|
|
|
ZF_LOGD("mystic log: %s", (const char *)line.c_str());
|
|
|
// Ok, we have a line, look for interesting details
|
|
|
- if (line.find("New user application") != string::npos) {
|
|
|
+ if (line.find("New user application") != std::string::npos) {
|
|
|
ZF_LOGE("New User");
|
|
|
}
|
|
|
|
|
|
size_t pos;
|
|
|
pos = line.find("Created Account: ");
|
|
|
- if (pos != string::npos) {
|
|
|
+ if (pos != std::string::npos) {
|
|
|
pos += 18 - 1;
|
|
|
// Ok, find the end '#'
|
|
|
size_t len = line.find('#', pos);
|
|
|
- if (len != string::npos) {
|
|
|
+ if (len != std::string::npos) {
|
|
|
username = line.substr(pos, len - pos - 1);
|
|
|
ZF_LOGE("New User: %s", (const char *)username.c_str());
|
|
|
// once we know this works -- lookup user's record
|
|
@@ -202,10 +196,10 @@ void scan_mystic_log(void) {
|
|
|
}
|
|
|
}
|
|
|
pos = line.find(" logged in");
|
|
|
- if (pos != string::npos) {
|
|
|
+ if (pos != std::string::npos) {
|
|
|
--pos;
|
|
|
size_t len = line.rfind(' ', pos);
|
|
|
- if (len != string::npos) {
|
|
|
+ if (len != std::string::npos) {
|
|
|
len++;
|
|
|
username = line.substr(len, pos + 1 - len);
|
|
|
ZF_LOGE("User: %s", (const char *)username.c_str());
|
|
@@ -366,9 +360,9 @@ int main(int argc, char *argv[]) {
|
|
|
return 2;
|
|
|
}
|
|
|
|
|
|
- string logfile;
|
|
|
+ std::string logfile;
|
|
|
{
|
|
|
- ostringstream buffer;
|
|
|
+ std::ostringstream buffer;
|
|
|
|
|
|
buffer << "horrible_harry_" << node << ".log";
|
|
|
logfile = buffer.str();
|
|
@@ -447,9 +441,9 @@ int main(int argc, char *argv[]) {
|
|
|
This doesn't need to be static -- because it is part of
|
|
|
main. Once main ends, we're done.
|
|
|
*/
|
|
|
- string buffer;
|
|
|
+ std::string buffer;
|
|
|
buffer.reserve(BSIZE * 2);
|
|
|
- string play;
|
|
|
+ std::string play;
|
|
|
play.reserve(4096);
|
|
|
|
|
|
int zmodem = 0;
|
|
@@ -561,10 +555,10 @@ int main(int argc, char *argv[]) {
|
|
|
if (zmodem) {
|
|
|
// Ok, we're zmodem mode -- is it time to exit?
|
|
|
size_t zend = buffer.find("\x1b[0m");
|
|
|
- if (zend != string::npos)
|
|
|
+ if (zend != std::string::npos)
|
|
|
zmodem = 0;
|
|
|
zend = buffer.find("\x1b[1;1H");
|
|
|
- if (zend != string::npos)
|
|
|
+ if (zend != std::string::npos)
|
|
|
zmodem = 0;
|
|
|
if (!zmodem)
|
|
|
ZF_LOGD("Zmodem end");
|
|
@@ -572,7 +566,7 @@ int main(int argc, char *argv[]) {
|
|
|
// Should we be in zmodem mode?
|
|
|
size_t zstart = buffer.find("**\x18"
|
|
|
"B0");
|
|
|
- if (zstart != string::npos) {
|
|
|
+ if (zstart != std::string::npos) {
|
|
|
zmodem = 1;
|
|
|
ZF_LOGD("Zmodem start");
|
|
|
}
|
|
@@ -593,7 +587,7 @@ int main(int argc, char *argv[]) {
|
|
|
size_t pos = buffer.rfind("\r\n");
|
|
|
// rstrnstr(buffer, size, "\r\n");
|
|
|
// >= 0) {
|
|
|
- if (pos != string::npos) {
|
|
|
+ if (pos != std::string::npos) {
|
|
|
// found something!
|
|
|
|
|
|
pos += 2;
|