summaryrefslogtreecommitdiff
path: root/Source/Applications/PaperWork/PaperWork.cpp
blob: 89cb00b97af1d8b00999b0ad2619c256a3090c29 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include <App/ShellApp.proto.h>
#include <Binding/FSNode.class.h>
#include <TextFile.class.h>

#define DEFAULT_SHELL "/Applications/Shell/Shell.app"
#define PAPERWORK_PATH "/System/Applications/PaperWork.app"

class PaperWork : public ShellApp {
	public:
	PaperWork() : ShellApp("PaperWork.app", "Melon's init/login manager") {
		addFlag("s", "shell", "Define the default shell to launch", FT_STR, DEFAULT_SHELL);
		addFlag("l", "login", "Act as a login manager");
		addFlag("i", "init", "Act as a init manager", FT_BOOL, "on");
	}
	int run();
};

APP(PaperWork);

int PaperWork::run() {
	String act = "init";
	if (bFlag("login")) act = "login";

	if (act == "init") {
		while (1) {
			Process p = Process::run(PAPERWORK_PATH);
			if (p.valid()) {
				p.setInVT(invt);
				p.setOutVT(outvt);
				p.pushArg("--login");
				p.start();
				p.wait();	
			} else {
				return 1;
			}
		}
	} else if (act == "login") {
		FSNode welcome = FS::find("/System/Configuration/Welcome");
		if (welcome.valid() && welcome.type() == NT_FILE) {
			TextFile f("/System/Configuration/Welcome");
			while (!f.eof()) outvt << f.readLine() << ENDL;
		} else {
			outvt << "Logging in to Melon\n";
		}
		String user, pw;
		while (1) {
			outvt << "Username: " << FLUSH;
			user = invt.get();
			outvt << "Password: " << FLUSH;
			pw = invt.readLine(false);
			if (!Process::get().authenticatePW(user, pw)) {
				outvt << "Authentication failed.\n\n";
				continue;
			}
			outvt << "What shell to run [" << sFlag("shell") << "]? "<< FLUSH;
			String sh = invt.get();
			if (sh == "") sh = sFlag("shell");
			Process p = Process::run(sh);
			if (p.valid()) {
				p.setInVT(invt);
				p.setOutVT(outvt);
				p.start();
				p.wait();	
				outvt << "\n\n";
			} else {
				outvt << "Could not run application : " << sh << ENDL;
				return 1;
			}
			return 0;
		}
	}
}