ROOT
6.30.04
Reference Guide
All
Namespaces
Files
Pages
httpaccess.C
Go to the documentation of this file.
1
/// \file
2
/// \ingroup tutorial_http
3
/// This program demonstrates access control to the THttpServer with digest methods.
4
/// Authentication file auth.txt was generated with following shell commands:
5
/// ~~~
6
/// [shell] htdigest -c auth.txt root guest
7
/// typing <empty> password for guest account
8
/// [shell] htdigest auth.txt root admin
9
/// typing 'admin' as password for admin account
10
/// ~~~
11
/// When macro started and opening in browser with url
12
/// ~~~
13
/// http://localhost:8080
14
/// ~~~
15
/// User name and password will be requested. One should
16
/// either specify guest account without password or
17
/// admin account with password 'admin'
18
///
19
/// User with guest account only can monitor histograms
20
/// User with admin account see commands, which can be executed
21
///
22
/// \macro_code
23
///
24
/// \author Sergey Linev
25
26
#include "
TH1.h
"
27
#include "
TH2.h
"
28
#include "
TRandom3.h
"
29
#include "
TSystem.h
"
30
#include "
THttpServer.h
"
31
32
void
httpaccess()
33
{
34
// create histograms
35
TH1D *hpx =
new
TH1D(
"hpx"
,
"This is the px distribution"
,100,-4,4);
36
hpx->SetFillColor(48);
37
hpx->SetDirectory(0);
38
TH2D *hpxpy =
new
TH2D(
"hpxpy"
,
"py vs px"
,40,-4,4,40,-4,4);
39
hpxpy->SetDirectory(0);
40
41
if
(gSystem->AccessPathName(
"auth.txt"
)!=0) {
42
printf(
"Please start macro from directory where auth.txt file is available\n"
);
43
printf(
"It required to supply authentication information for the http server\n"
);
44
return
;
45
}
46
47
// start http server
48
THttpServer* serv =
new
THttpServer(
"http:8080?auth_file=auth.txt&auth_domain=root"
);
49
50
// or start FastCGI server, where host server (like Apache or lighttpd) should enable own authentication
51
// for apache one should add correspondent module and authentication for fastcgi location
52
// for lighttpd one add following lines to configuration file:
53
// server.modules += ( "mod_auth" )
54
// auth.backend = "htdigest"
55
// auth.backend.htdigest.userfile = "/srv/auth/auth.txt"
56
// auth.require = ( "/root.app" => ( "method" => "digest", "realm" => "root", "require" => "valid-user" ))
57
// THttpServer* serv = new THttpServer("fastcgi:9000");
58
59
// One could specify location of newer version of JSROOT
60
// serv->SetJSROOT("https://root.cern.ch/js/latest/");
61
// serv->SetJSROOT("http://jsroot.gsi.de/latest/");
62
63
// register histograms
64
serv->Register(
"/"
, hpx);
65
serv->Register(
"/"
, hpxpy);
66
67
// register commands, invoking object methods
68
serv->RegisterCommand(
"/ResetHPX"
,
"/hpx/->Reset();"
,
"button;rootsys/icons/ed_delete.png"
);
69
serv->SetItemField(
"/ResetHPX"
,
"_update_item"
,
"hpx"
);
// let browser update histogram view after commands execution
70
serv->RegisterCommand(
"/ResetHPXPY"
,
"/hpxpy/->Reset();"
,
"button;rootsys/icons/bld_delete.png"
);
71
serv->SetItemField(
"/ResetHPXPY"
,
"_update_item"
,
"hpxpy"
);
// let browser update histogram view after commands execution
72
// here also example how command with arguments can be invoked
73
serv->RegisterCommand(
"/RebinHPX"
,
"/hpx/->Rebin(%arg1%);"
,
"button;rootsys/icons/ed_execute.png"
);
74
serv->SetItemField(
"/RebinHPX"
,
"_update_item"
,
"hpx"
);
// let browser update histogram view after commands execution
75
76
// these two commands fully hidden for other accounts,
77
// only admin can see and execute these commands
78
serv->Restrict(
"/ResetHPX"
,
"visible=admin"
);
79
serv->Restrict(
"/ResetHPXPY"
,
"visible=admin"
);
80
81
// this command visible for other, but will be refused (return false)
82
// when executed from any other account
83
serv->Restrict(
"/RebinHPX"
,
"allow=admin"
);
84
85
// Fill histograms randomly
86
TRandom3 random;
87
Float_t px, py;
88
const
Long_t kUPDATE = 1000;
89
Long_t cnt = 0;
90
while
(kTRUE) {
91
random.Rannor(px,py);
92
hpx->Fill(px);
93
hpxpy->Fill(px,py);
94
95
// IMPORTANT: one should regularly call ProcessEvents
96
if
(cnt++ % kUPDATE == 0) {
97
if
(gSystem->ProcessEvents())
break
;
98
}
99
}
100
}
TSystem.h
THttpServer.h
TH2.h
TH1.h
TRandom3.h
tutorials
http
httpaccess.C
Generated on Tue May 5 2020 14:03:46 for ROOT by
1.8.5