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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
|
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <unistd.h>
#include <list>
#include <sys/types.h>
#include <sys/wait.h>
#include "Handle.h"
#include "Task.h"
#include "TaskMan.h"
#include "HttpServ.h"
#include "Socket.h"
#include "config.h"
#include "Message.h"
#include "Menu.h"
#include "Exceptions.h"
#include "Form.h"
#include "Confirm.h"
#include "Table.h"
#include "InPipe.h"
#include "Image.h"
#include "CopyJob.h"
#include "IRC.h"
#include "Main.h"
#include "gettext.h"
InPipe * in;
class ad_run : public Task {
public:
ad_run(Variables * av, Variables * ahds, Handle * ah) : v(*av), hds(*ahds), h(ah) {
SetBurst();
}
virtual ~ad_run() {}
virtual String GetName() { return "Action dynamique"; }
protected:
virtual int Do() throw (GeneralException) {
pid_t p;
switch (current) {
case 0:
if (!(p = fork())) {
execlp("uptime", "uptime", NULL);
}
current = 1;
WaitFor(p);
Suspend(TASK_ON_HOLD);
case 1:
(*in) >> ut;
if (!(p = fork())) {
execlp("uname", "uname", "-a", NULL);
}
current = 2;
WaitFor(p);
Suspend(TASK_ON_HOLD);
case 2:
(*in) >> un;
for (int i = 0; i < hds.GetNb(); i++) {
shds += hds[i] + "<BR>\n";
}
m = new Message("Action dynamique",
String("Vous avez choisi l'action dynamique. L'uptime de la machine est '") +
ut + "' et sa définition complète est '" + un + "'<BR><BR><BR>Voici la liste des entêtes:<BR><BR>" + shds, "");
current = 3;
WaitFor(m->Do(&v, &hds, h));
Suspend(TASK_ON_HOLD);
case 3:
delete m;
testimg = new Image(100, 100);
testimg->Prepare();
testoutput = new Output("TestImg.tga");
current = 4;
WaitFor(new CopyJob(testimg, testoutput, -1, true, true));
Suspend(TASK_ON_HOLD);
case 4:
return TASK_DONE;
}
return TASK_DONE;
}
private:
Variables v, hds;
Handle * h;
String ut, un, shds;
Action * m;
Image * testimg;
Output * testoutput;
};
class ad_t : public Action {
public:
ad_t() : Action("menu6") { }
virtual ~ad_t() { }
virtual String GetTitle() { return "Action dynamique"; }
virtual Task * Do(Variables * v, Variables * hds, Handle * h) {
return new ad_run(v, hds, h);
}
};
Action * ad = new ad_t();
class dostop_t : public Action {
public:
dostop_t() : Action("dostop") { }
virtual ~dostop_t() { }
virtual String GetTitle() { return "Arret du serveur"; }
virtual Task * Do(Variables * v, Variables * hds, Handle * h) {
TaskMan::Stop();
return 0;
}
};
Action * dostop = new dostop_t();
String Noms[] = {"Champ1", "Champ2", "Champ3"};
String Defaults[] = {"Default1", "Default2", 0};
String Invites[] = {"Champ 1:", "Champ 2:", "Champ 3:"};
String Options[] = {"Option1", "Option2", ""};
String ODescs[] = {"Description 1", "Description 2", ""};
String * Lists[] = {0, 0, Options};
String * Descs[] = {0, 0, ODescs};
String Titres[] = {"Titre 1", "Titre 2", "Titre 3"};
String Cells[] = {"L1C1", "L1C2", "L1C3", "L2C1", "L2C2", "L2C3", "L3C1", "L3C2", "L3C3", "L4C1", "L4C2", "L4C3"};
Action * a1 = new Message("Action 1", "Vous avez cliqué sur l'option 1 du menu", "menu1");
Action * a2 = new Table("Petite table", "menu2", Titres, Cells, 3, 4);
Action * a3 = new Message("Test d'image",
"Voici un test d'affichage d'image:"
"<center><table border=0><td><tr><img src=\"/image/nobis-logo-small.jpg\"></tr></td></table></center>",
"menu3");
Action * a4 = new Form("Test de formulaire...", "menu4", "Rentrez des trucs...", Noms, Invites, Defaults, Lists, Descs, 3);
Action * a5 = new Confirm("Confirmation", "Oui ou non?", "menu5", 0, 0);
Action * java = new Message("Applet JAVA",
"\n"
"<center>\n"
"<APPLET CODE = \"TestApplet.class\" CODEBASE =\"/image\" WIDTH = 400 HEIGHT = 50>\n"
"</APPLET>\n"
"</center>\n", "java");
Action * up = new Message("Test d'upload",
"\n"
"<FORM ENCTYPE=\"multipart/form-data\" ACTION=\"/bin/start\" METHOD=POST>\n"
"<INPUT TYPE=\"hidden\" name=\"MAX_FILE_SIZE\" value=\"1000\">\n"
"Send this file: <INPUT NAME=\"userfile\" TYPE=\"file\">\n"
"<INPUT TYPE=\"submit\" VALUE=\"Send File\">\n"
"</FORM>\n", "upload");
Action * stop = new Confirm("Stopper", "Stopper le serveur?", "stop", dostop, 0);
Action * Liste[] = {a1, a2, a3, a4, a5, ad, java, up, stop};
String Labels[] = {"Action 1", "Action 2", "Action 3", "Action 4", "Action 5", "Action dynamique", "Essai de java", "Test d'upload", "Stop"};
CODE_BEGINS
Action * buildmenu(void) {
Action * m = new Menu("Menu Principal", "start", Labels, Liste, 9);
return m;
}
int startup() throw (GeneralException) {
int c;
String port = "1500";
std::list<String> testlist;
testlist.push_front("poide");
in = new InPipe();
in->Hook();
String test = "poide\n", r;
std::cout << test;
std::cout.flush();
(*in) >> r;
if (r != "poide") {
printm(M_ERROR, "The stdout redirect has failed.\n");
exit(-1);
}
while ((c = getopt(argc, argv, "p:")) != EOF) {
switch (c) {
case 'p':
port = optarg;
break;
default:
printm(M_BARE, String(_("Usage: ")) + argv[0] + " [-p port]\n");
exit(-1);
}
}
try {
HttpServ h(buildmenu(), port.to_int(), "testing");
// IRC i("botalacon");
// i.Connect();
// i.MainLoop();
TaskMan::MainLoop();
}
catch (GeneralException e) {
std::cerr << "Main function got an exception: '" << e.GetMsg() << "'.\n";
exit(-1);
}
catch (...) {
std::cerr << "Unknow exception.\n" << std::endl;
exit(-1);
}
delete in;
return 0;
}
CODE_ENDS
|