1 | unit ModuleZdechovNET;
|
---|
2 |
|
---|
3 | interface
|
---|
4 |
|
---|
5 | uses
|
---|
6 | Classes, SysUtils, ModularSystem, WebPage, RobotsPage,
|
---|
7 | WebSession, DateUtils, ModuleBase, ModuleUser, IPTVPage,
|
---|
8 | InternetPage, HostingPage, HistoryPage, DocumentsPage, VoIPPage,
|
---|
9 | LinksPage, PlansPage, ServerInfoPage, WebCamPage, User,
|
---|
10 | NetworkPage, AboutPage, ContactPage, ProjectsPage;
|
---|
11 |
|
---|
12 | type
|
---|
13 |
|
---|
14 | { TModuleZdechovNET }
|
---|
15 |
|
---|
16 | TModuleZdechovNET = class(TModule)
|
---|
17 | private
|
---|
18 | InternetPage: TInternetPage;
|
---|
19 | HostingPage: THostingPage;
|
---|
20 | HistoryPage: THistoryPage;
|
---|
21 | DocumentsPage: TDocumentsPage;
|
---|
22 | VoIPPage: TVoIPPage;
|
---|
23 | LinksPage: TLinksPage;
|
---|
24 | ContactPage: TContactPage;
|
---|
25 | ServerInfoPage: TServerInfoPage;
|
---|
26 | WebCamPage: TWebCamPage;
|
---|
27 | PlansPage: TPlansPage;
|
---|
28 | NetworkPage: TNetworkPage;
|
---|
29 | ProjectsPage: TProjectsPage;
|
---|
30 | AboutPage: TAboutPage;
|
---|
31 | IPTVPage: TIPTVPage;
|
---|
32 | RobotsPage: TRobotsPage;
|
---|
33 | procedure Footer(Session: TWebSession);
|
---|
34 | procedure GeneratePage(ASession: TWebSession; Page: TWebPage);
|
---|
35 | procedure TopMenu(Session: TWebSession);
|
---|
36 | public
|
---|
37 | ModuleBase: TModuleBase;
|
---|
38 | ModuleUser: TModuleUser;
|
---|
39 | Raw: Boolean;
|
---|
40 | constructor Create(Owner: TComponent); override;
|
---|
41 | destructor Destroy; override;
|
---|
42 | procedure Start; override;
|
---|
43 | procedure Stop; override;
|
---|
44 | procedure Install; override;
|
---|
45 | procedure Uninstall; override;
|
---|
46 | end;
|
---|
47 |
|
---|
48 |
|
---|
49 | implementation
|
---|
50 |
|
---|
51 | uses
|
---|
52 | Core, SqlDatabase, XmlClasses, HtmlClasses, Utils;
|
---|
53 |
|
---|
54 | { TModuleZdechovNET }
|
---|
55 |
|
---|
56 | constructor TModuleZdechovNET.Create(Owner: TComponent);
|
---|
57 | begin
|
---|
58 | inherited;
|
---|
59 | Identification := 'ZdechovNET';
|
---|
60 | Title := 'ZdechovNET web';
|
---|
61 | Version := '1.0';
|
---|
62 | License := 'GNU/LGPL v3';
|
---|
63 | Author := 'Chronosoft';
|
---|
64 | Dependencies.Add('User');
|
---|
65 | Dependencies.Add('Base');
|
---|
66 |
|
---|
67 | // Pages
|
---|
68 | InternetPage := TInternetPage.Create(nil);
|
---|
69 | HostingPage := THostingPage.Create(nil);
|
---|
70 | HistoryPage := THistoryPage.Create(nil);
|
---|
71 | DocumentsPage := TDocumentsPage.Create(nil);
|
---|
72 | VoIPPage := TVoIPPage.Create(nil);
|
---|
73 | LinksPage := TLinksPage.Create(nil);
|
---|
74 | ContactPage := TContactPage.Create(nil);
|
---|
75 | ServerInfoPage := TServerInfoPage.Create(nil);
|
---|
76 | WebCamPage := TWebCamPage.Create(nil);
|
---|
77 | PlansPage := TPlansPage.Create(nil);
|
---|
78 | NetworkPage := TNetworkPage.Create(nil);
|
---|
79 | ProjectsPage := TProjectsPage.Create(nil);
|
---|
80 | AboutPage := TAboutPage.Create(nil);
|
---|
81 | IPTVPage := TIPTVPage.Create(nil);
|
---|
82 | RobotsPage := TRobotsPage.Create(nil);
|
---|
83 | end;
|
---|
84 |
|
---|
85 | destructor TModuleZdechovNET.Destroy;
|
---|
86 | begin
|
---|
87 | FreeAndNil(IPTVPage);
|
---|
88 | FreeAndNil(AboutPage);
|
---|
89 | FreeAndNil(InternetPage);
|
---|
90 | FreeAndNil(HostingPage);
|
---|
91 | FreeAndNil(HistoryPage);
|
---|
92 | FreeAndNil(DocumentsPage);
|
---|
93 | FreeAndNil(VoIPPage);
|
---|
94 | FreeAndNil(LinksPage);
|
---|
95 | FreeAndNil(ContactPage);
|
---|
96 | FreeAndNil(ServerInfoPage);
|
---|
97 | FreeAndNil(WebCamPage);
|
---|
98 | FreeAndNil(PlansPage);
|
---|
99 | FreeAndNil(NetworkPage);
|
---|
100 | FreeAndNil(ProjectsPage);
|
---|
101 | FreeAndNil(RobotsPage);
|
---|
102 | inherited;
|
---|
103 | end;
|
---|
104 |
|
---|
105 | procedure TModuleZdechovNET.Start;
|
---|
106 | begin
|
---|
107 | BeforeStart;
|
---|
108 | ModuleBase := TModuleBase(Manager.FindModuleByName('Base'));
|
---|
109 | ModuleBase.OnGeneratePage := GeneratePage;
|
---|
110 | ModuleUser := TModuleUser(Manager.FindModuleByName('User'));
|
---|
111 | with ModuleBase, Pages do begin
|
---|
112 | //OnGeneratePage := OnGeneratePage;
|
---|
113 |
|
---|
114 | RegisterPage(InternetPage, 'internet');
|
---|
115 | RegisterPage(HostingPage, 'hosting');
|
---|
116 | RegisterPage(HistoryPage, 'historie');
|
---|
117 | RegisterPage(DocumentsPage, 'dokumenty');
|
---|
118 | RegisterPage(VoIPPage, 'voip');
|
---|
119 | RegisterPage(LinksPage, 'odkazy');
|
---|
120 | RegisterPage(ContactPage, 'kontakt');
|
---|
121 | RegisterPage(WebCamPage, 'kamery');
|
---|
122 | RegisterPage(PlansPage, 'plany');
|
---|
123 | RegisterPage(NetworkPage, 'sit');
|
---|
124 | RegisterPage(ProjectsPage, 'projekty');
|
---|
125 | RegisterPage(AboutPage, '');
|
---|
126 | RegisterPage(IPTVPage, 'televize');
|
---|
127 | RegisterPage(RobotsPage, 'robots.txt');
|
---|
128 | {$IFDEF DEBUG}
|
---|
129 | RegisterPage(ServerInfoPage, 'serverinfo');
|
---|
130 | {$ENDIF}
|
---|
131 | end;
|
---|
132 | AfterStart;
|
---|
133 | end;
|
---|
134 |
|
---|
135 | procedure TModuleZdechovNET.Stop;
|
---|
136 | begin
|
---|
137 | BeforeStop;
|
---|
138 | with ModuleBase, Pages do begin
|
---|
139 | UnregisterPage(IPTVPage);
|
---|
140 | UnregisterPage(AboutPage);
|
---|
141 | UnregisterPage(InternetPage);
|
---|
142 | UnregisterPage(HostingPage);
|
---|
143 | UnregisterPage(HistoryPage);
|
---|
144 | UnregisterPage(DocumentsPage);
|
---|
145 | UnregisterPage(VoIPPage);
|
---|
146 | UnregisterPage(LinksPage);
|
---|
147 | UnregisterPage(ContactPage);
|
---|
148 | UnregisterPage(WebCamPage);
|
---|
149 | UnregisterPage(PlansPage);
|
---|
150 | UnregisterPage(NetworkPage);
|
---|
151 | UnregisterPage(ProjectsPage);
|
---|
152 | UnregisterPage(RobotsPage);
|
---|
153 | {$IFDEF DEBUG}
|
---|
154 | UnregisterPage(ServerInfoPage);
|
---|
155 | {$ENDIF}
|
---|
156 | end;
|
---|
157 | ModuleBase := nil;
|
---|
158 | ModuleUser := nil;
|
---|
159 | AfterStop;
|
---|
160 | end;
|
---|
161 |
|
---|
162 | procedure TModuleZdechovNET.Install;
|
---|
163 | var
|
---|
164 | DbRows: TDbRows;
|
---|
165 | begin
|
---|
166 | try
|
---|
167 | DbRows := TDbRows.Create;
|
---|
168 |
|
---|
169 | Core.Core.CommonDatabase.Query(DbRows,
|
---|
170 | 'CREATE TABLE IF NOT EXISTS `VPSHosting` (' +
|
---|
171 | ' `Id` int(11) NOT NULL AUTO_INCREMENT,' +
|
---|
172 | ' `Name` varchar(255) NOT NULL,' +
|
---|
173 | ' `Memory` varchar(255) NOT NULL,' +
|
---|
174 | ' `Space` varchar(255) NOT NULL,' +
|
---|
175 | ' `Internet` varchar(255) NOT NULL,' +
|
---|
176 | ' `CPU` varchar(255) NOT NULL,' +
|
---|
177 | ' `Price` int(11) NOT NULL,' +
|
---|
178 | ' PRIMARY KEY (`Id`)' +
|
---|
179 | ') ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;');
|
---|
180 |
|
---|
181 | Core.Core.CommonDatabase.Query(DbRows,
|
---|
182 | 'CREATE TABLE IF NOT EXISTS `History` (' +
|
---|
183 | ' `Id` int(11) NOT NULL AUTO_INCREMENT,' +
|
---|
184 | ' `Date` date NOT NULL,' +
|
---|
185 | ' `Text` text COLLATE utf8_czech_ci NOT NULL,' +
|
---|
186 | ' PRIMARY KEY (`Id`)' +
|
---|
187 | ') ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_czech_ci AUTO_INCREMENT=1 ;');
|
---|
188 |
|
---|
189 | Core.Core.CommonDatabase.Query(DbRows,
|
---|
190 | 'CREATE TABLE IF NOT EXISTS `Webcam` (' +
|
---|
191 | ' `Id` int(11) NOT NULL AUTO_INCREMENT,' +
|
---|
192 | ' `Name` varchar(255) CHARACTER SET utf8 COLLATE utf8_czech_ci NOT NULL,' +
|
---|
193 | ' `Description` text CHARACTER SET utf8 COLLATE utf8_czech_ci NOT NULL,' +
|
---|
194 | ' `ImageName` varchar(255) CHARACTER SET utf8 COLLATE utf8_czech_ci NOT NULL,' +
|
---|
195 | ' `ImageURL` varchar(255) CHARACTER SET utf8 COLLATE utf8_czech_ci NOT NULL,' +
|
---|
196 | ' `ImagePeriod` int(11) NOT NULL,' +
|
---|
197 | ' `Width` int(11) NOT NULL,' +
|
---|
198 | ' `Height` int(11) NOT NULL,' +
|
---|
199 | ' `Enabled` int(11) NOT NULL DEFAULT "1",' +
|
---|
200 | ' `DeviceType` varchar(255) NOT NULL,' +
|
---|
201 | ' PRIMARY KEY (`Id`)' +
|
---|
202 | ') ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;');
|
---|
203 |
|
---|
204 | Core.Core.CommonDatabase.Query(DbRows,
|
---|
205 | ' CREATE TABLE IF NOT EXISTS `Plans` (' +
|
---|
206 | ' `Id` int(11) NOT NULL AUTO_INCREMENT,' +
|
---|
207 | ' `TimeCreate` datetime NOT NULL,' +
|
---|
208 | ' `TimeFinished` datetime DEFAULT NULL,' +
|
---|
209 | ' `Description` text COLLATE utf8_czech_ci NOT NULL,' +
|
---|
210 | ' `Conclusion` text COLLATE utf8_czech_ci NOT NULL,' +
|
---|
211 | ' `Public` int(11) NOT NULL DEFAULT "0",' +
|
---|
212 | ' PRIMARY KEY (`Id`),' +
|
---|
213 | ' KEY `TimeCreate` (`TimeCreate`),' +
|
---|
214 | ' KEY `TimeFinished` (`TimeFinished`)' +
|
---|
215 | ') ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_czech_ci AUTO_INCREMENT=1 ;');
|
---|
216 |
|
---|
217 | Core.Core.CommonDatabase.Query(DbRows,
|
---|
218 | 'CREATE TABLE IF NOT EXISTS `HostedProject` (' +
|
---|
219 | ' `Id` int(11) NOT NULL AUTO_INCREMENT,' +
|
---|
220 | ' `Name` varchar(255) COLLATE utf8_czech_ci NOT NULL,' +
|
---|
221 | ' `Homepage` varchar(255) COLLATE utf8_czech_ci NOT NULL,' +
|
---|
222 | ' `User` int(255) NOT NULL COMMENT "User.Id",' +
|
---|
223 | ' `TimeCreate` datetime NOT NULL,' +
|
---|
224 | ' `Server` int(11) DEFAULT NULL COMMENT "NetworkDevice.Id",' +
|
---|
225 | ' `Active` int(11) NOT NULL DEFAULT "1",' +
|
---|
226 | ' `WebHosting` int(11) NOT NULL,' +
|
---|
227 | ' PRIMARY KEY (`Id`)' +
|
---|
228 | ') ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_czech_ci AUTO_INCREMENT=1 ;');
|
---|
229 |
|
---|
230 | finally
|
---|
231 | DbRows.Free;
|
---|
232 | end;
|
---|
233 |
|
---|
234 | inherited;
|
---|
235 | end;
|
---|
236 |
|
---|
237 | procedure TModuleZdechovNET.Uninstall;
|
---|
238 | var
|
---|
239 | DbRows: TDbRows;
|
---|
240 | begin
|
---|
241 | inherited;
|
---|
242 | ModuleBase.OnGeneratePage := nil;
|
---|
243 | try
|
---|
244 | DbRows := TDbRows.Create;
|
---|
245 | Core.Core.CommonDatabase.Query(DbRows, 'DROP TABLE IF EXISTS `HostedProject`');
|
---|
246 | Core.Core.CommonDatabase.Query(DbRows, 'DROP TABLE IF EXISTS `Plans`');
|
---|
247 | Core.Core.CommonDatabase.Query(DbRows, 'DROP TABLE IF EXISTS `Webcam`');
|
---|
248 | Core.Core.CommonDatabase.Query(DbRows, 'DROP TABLE IF EXISTS `VPSHosting`');
|
---|
249 | Core.Core.CommonDatabase.Query(DbRows, 'DROP TABLE IF EXISTS `History`');
|
---|
250 | finally
|
---|
251 | DbRows.Free;
|
---|
252 | end;
|
---|
253 | end;
|
---|
254 |
|
---|
255 | procedure TModuleZdechovNET.Footer(Session: TWebSession);
|
---|
256 | var
|
---|
257 | Tag: TXMLTag;
|
---|
258 | AdminTag: TXMLTag;
|
---|
259 | EmailTag: TXMLTag;
|
---|
260 | ExecutionTimeTag: TXMLTag;
|
---|
261 | UsedMemoryTag: TXMLTag;
|
---|
262 | TextNode: TXmlString;
|
---|
263 | begin
|
---|
264 | with Session do
|
---|
265 | with HtmlDocument.Body.SubItems.AddList do begin
|
---|
266 | ClassId := 'Footer';
|
---|
267 | with SubItems.AddString do begin
|
---|
268 | Text := TCore(MainModule).Admin;
|
---|
269 | end;
|
---|
270 | with SubItems.AddString do begin
|
---|
271 | Text := TCore(MainModule).AdminEmail;
|
---|
272 | end;
|
---|
273 | if TCore(MainModule).ShowRuntimeInfo then begin
|
---|
274 | with SubItems.AddString do begin
|
---|
275 | Text := 'Doba generování: ' +
|
---|
276 | FloatToStr(Round(((Now - TimeStart) / OneMillisecond) * 100) / 100) + ' s / '; // + ini_get('max_execution_time') + ' s';
|
---|
277 | end;
|
---|
278 | with SubItems.AddString do begin
|
---|
279 | //Text := 'Použitá paměť: ' + System.PrefixMultiplier.AddPrefixMultipliers(memory_get_peak_usage(FALSE), 'B').' / '.ini_get('memory_limit').'B';
|
---|
280 | end;
|
---|
281 | end;
|
---|
282 | end;
|
---|
283 | end;
|
---|
284 |
|
---|
285 | procedure TModuleZdechovNET.TopMenu(Session: TWebSession);
|
---|
286 | var
|
---|
287 | Output: THtmlString;
|
---|
288 | begin
|
---|
289 | Output := THtmlString.Create;
|
---|
290 | Session.HtmlDocument.Body.SubItems.Insert(1, Output);
|
---|
291 | with Output do begin
|
---|
292 | Text := '<div class="Navigation">';
|
---|
293 | // Visitor
|
---|
294 | Text := Text + '<ul class="MenuItem">' +
|
---|
295 | '<li>' + MakeLink('Úvod', NavigationLink('/')) + '</li>' +
|
---|
296 | '<li>' + MakeLink('Internet', NavigationLink('/internet/')) + '</li>' +
|
---|
297 | '<li>' + MakeLink('Televize', NavigationLink('/televize/')) + '</li>' +
|
---|
298 | '<li>' + MakeLink('Hosting', NavigationLink('/hosting/')) + '</li>' +
|
---|
299 | '<li>' + MakeLink('VoIP', NavigationLink('/voip/')) + '</li>' +
|
---|
300 | '<li>' + MakeLink('Síť', NavigationLink('/sit/')) + '</li>' +
|
---|
301 | '<li>' + MakeLink('Odkazy', NavigationLink('/odkazy/')) + '</li>' +
|
---|
302 | '<li>' + MakeLink('Kontakt', NavigationLink('/kontakt/')) + '</li>' +
|
---|
303 | '<li>' + MakeLink('Kamery', NavigationLink('/kamery/')) + '</li>' +
|
---|
304 | '<li><a href="https://mail.zdechov.net/">Pošta</a></li>' +
|
---|
305 | '<li><a href="https://wiki.zdechov.net/">Wiki</a></li>' +
|
---|
306 | '</ul><ul class="MenuItem2">'; //<li> </li>';
|
---|
307 | if False and Assigned(ModuleBase.Pages.FindByName('uzivatel')) then begin
|
---|
308 | if ModuleUser.UserOnline.User = UnknownUser then begin
|
---|
309 | Text := Text + '</ul>' +
|
---|
310 | '<ul class="MenuItem2">' +
|
---|
311 | '<li>' + MakeLink('Přihlášení', NavigationLink('/uzivatel/prihlaseni/')) + '</li>' +
|
---|
312 | '<li>' + MakeLink('Registrace', NavigationLink('/uzivatel/registrace/')) + '</li>' +
|
---|
313 | '<li></li>';
|
---|
314 | // $Output .= '<li>'.$this->System->HTML->MakeLink($this->System->Translate('UserRegistration'), $this->System->MakeLink('UserList', 'Register')).'</li>';
|
---|
315 | end else begin
|
---|
316 | Text := Text + '</ul>' +
|
---|
317 | '<ul class="MenuItem2">' +
|
---|
318 | '<li>' + ModuleUser.User.FullName + '</li>' +
|
---|
319 | '<li>' + MakeLink('Odhlášení', NavigationLink('/uzivatel/odhlaseni/')) + '</li>' +
|
---|
320 | '<li>' + MakeLink('Profil', NavigationLink('/uzivatel/profil/')) + '</li>';
|
---|
321 | end;
|
---|
322 | end else Text := Text + '</ul><ul class="MenuItem2">';
|
---|
323 | Text := Text + '</ul></div>';
|
---|
324 | end;
|
---|
325 | end;
|
---|
326 |
|
---|
327 | procedure TModuleZdechovNET.GeneratePage(ASession: TWebSession; Page: TWebPage);
|
---|
328 | var
|
---|
329 | I: Integer;
|
---|
330 | TitleTag: THtmlString;
|
---|
331 | TopMenuTag: THtmlString;
|
---|
332 | begin
|
---|
333 | with ASession do begin
|
---|
334 | if Page.Raw then begin
|
---|
335 | Response.Content.WriteString(HtmlDocument.Body.AsXmlElement.AsString);
|
---|
336 | end else begin
|
---|
337 | HtmlDocument.ContentLanguage := 'cs';
|
---|
338 | GlobalTitle := 'ZděchovNET';
|
---|
339 | HtmlDocument.Styles.Add(NavigationLink('/Style/' + TCore(MainModule).Style + '/Style.css'));
|
---|
340 | HtmlDocument.Scripts.Add(NavigationLink('/Style/' + TCore(MainModule).Style + '/Global.js'));
|
---|
341 | HtmlDocument.Scripts.Add(NavigationLink('/Style/' + TCore(MainModule).Style + '/jquery.js'));
|
---|
342 | HtmlDocument.FavIcon := NavigationLink('/images/favicon.ico');
|
---|
343 |
|
---|
344 | TitleTag := THtmlString.Create;
|
---|
345 | HtmlDocument.Body.SubItems.Insert(0, TitleTag);
|
---|
346 | TopMenu(ASession);
|
---|
347 | //Page.Page.OnProduce(HandlerData);
|
---|
348 | HtmlDocument.Title := Page.Caption;
|
---|
349 | TitleTag.Text := '<div class="TitlePanel"><span class="GlobalTitle">' + GlobalTitle +
|
---|
350 | '</span> - ' + HtmlDocument.Title + '</div>';
|
---|
351 | HtmlDocument.Title := GlobalTitle + ' - ' + HtmlDocument.Title;
|
---|
352 | with HtmlDocument.AsXmlDocument do
|
---|
353 | try
|
---|
354 | Formated := TCore(MainModule).FormatHTML;
|
---|
355 | Response.Content.WriteString(AsString);
|
---|
356 | finally
|
---|
357 | Free;
|
---|
358 | end;
|
---|
359 | end;
|
---|
360 | end;
|
---|
361 | end;
|
---|
362 |
|
---|
363 | end.
|
---|
364 |
|
---|