ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
httpaccess.C
Go to the documentation of this file.
1 #include "TH1.h"
2 #include "TH2.h"
3 #include "TRandom3.h"
4 #include "TSystem.h"
5 #include "THttpServer.h"
6 
7 void httpaccess()
8 {
9 // This program demonstrates access control to the THttpServer with digest methods.
10 // Authentication file auth.txt was generated with following shell commands:
11 // [shell] htdigest -c auth.txt root guest
12 // typing <empty> password for guest account
13 // [shell] htdigest auth.txt root admin
14 // typing 'admin' as password for admin account
15 // When macro started and opening in browser with url
16 // http://localhost:8080
17 // User name and password will be requested. One should
18 // either specify guest account without password or
19 // admin account with password 'admin'
20 //
21 // User with guest account only can monitor histograms
22 // User with admin account see commands, which can be executed
23 
24  // create histograms
25  TH1D *hpx = new TH1D("hpx","This is the px distribution",100,-4,4);
26  hpx->SetFillColor(48);
27  hpx->SetDirectory(0);
28  TH2D *hpxpy = new TH2D("hpxpy","py vs px",40,-4,4,40,-4,4);
29  hpxpy->SetDirectory(0);
30 
31  if (gSystem->AccessPathName("auth.txt")!=0) {
32  printf("Please start macro from directory where auth.txt file is available\n");
33  printf("It required to supply authentication information for the http server\n");
34  return;
35  }
36 
37  // start http server
38  THttpServer* serv = new THttpServer("http:8080?auth_file=auth.txt&auth_domain=root");
39 
40  // or start FastCGI server, where host server (like Apache or lighttpd) should enable own authentication
41  // for apache one should add correspondent module and authentication for fastcgi location
42  // for lighttpd one add following lines to configuration file:
43  // server.modules += ( "mod_auth" )
44  // auth.backend = "htdigest"
45  // auth.backend.htdigest.userfile = "/srv/auth/auth.txt"
46  // auth.require = ( "/root.app" => ( "method" => "digest", "realm" => "root", "require" => "valid-user" ))
47  // THttpServer* serv = new THttpServer("fastcgi:9000");
48 
49  // One could specify location of newer version of JSROOT
50  // serv->SetJSROOT("https://root.cern.ch/js/3.6/");
51 
52  // register histograms
53  serv->Register("/", hpx);
54  serv->Register("/", hpxpy);
55 
56  // register commands, invoking object methods
57  serv->RegisterCommand("/ResetHPX","/hpx/->Reset();", "button;rootsys/icons/ed_delete.png");
58  serv->SetItemField("/ResetHPX","_update_item", "hpx"); // let browser update histogram view after commands execution
59  serv->RegisterCommand("/ResetHPXPY","/hpxpy/->Reset();", "button;rootsys/icons/bld_delete.png");
60  serv->SetItemField("/ResetHPXPY","_update_item", "hpxpy"); // let browser update histogram view after commands execution
61  // here also example how command with arguments can be invoked
62  serv->RegisterCommand("/RebinHPX","/hpx/->Rebin(%arg1%);", "button;rootsys/icons/ed_execute.png");
63  serv->SetItemField("/RebinHPX","_update_item", "hpx"); // let browser update histogram view after commands execution
64 
65  // these two commands fully hidden for other accounts,
66  // only admin can see and execute these commands
67  serv->Restrict("/ResetHPX", "visible=admin");
68  serv->Restrict("/ResetHPXPY", "visible=admin");
69 
70  // this command visible for other, but will be refused (return false)
71  // when executed from any other account
72  serv->Restrict("/RebinHPX", "allow=admin");
73 
74  // Fill histograms randomly
76  Float_t px, py;
77  const Long_t kUPDATE = 1000;
78  Long_t cnt = 0;
79  while (kTRUE) {
80  random.Rannor(px,py);
81  hpx->Fill(px);
82  hpxpy->Fill(px,py);
83 
84  // IMPORTANT: one should regularly call ProcessEvents
85  if (cnt++ % kUPDATE == 0) {
86  if (gSystem->ProcessEvents()) break;
87  }
88  }
89 }
virtual Bool_t AccessPathName(const char *path, EAccessMode mode=kFileExists)
Returns FALSE if one can access a file using the specified access mode.
Definition: TSystem.cxx:1213
virtual Int_t Fill(Double_t x)
Increment bin with abscissa X by 1.
Definition: TH1.cxx:3159
virtual Bool_t ProcessEvents()
Process pending events (GUI, timers, sockets).
Definition: TSystem.cxx:420
virtual void Rannor(Float_t &a, Float_t &b)
Return 2 numbers distributed following a gaussian with mean=0 and sigma=1.
Definition: TRandom.cxx:460
Random number generator class based on M.
Definition: TRandom3.h:29
tuple random
Definition: hsimple.py:62
float Float_t
Definition: RtypesCore.h:53
virtual void SetDirectory(TDirectory *dir)
By default when an histogram is created, it is added to the list of histogram objects in the current ...
Definition: TH1.cxx:8266
TH2F * hpxpy
Definition: hcons.C:33
Float_t py
Definition: hprod.C:33
void httpaccess()
Definition: httpaccess.C:7
Bool_t Register(const char *subfolder, TObject *obj)
Register object in subfolder.
R__EXTERN TSystem * gSystem
Definition: TSystem.h:545
virtual void SetFillColor(Color_t fcolor)
Definition: TAttFill.h:50
1-D histogram with a double per channel (see TH1 documentation)}
Definition: TH1.h:613
long Long_t
Definition: RtypesCore.h:50
ClassImp(TMCParticle) void TMCParticle printf(": p=(%7.3f,%7.3f,%9.3f) ;", fPx, fPy, fPz)
Bool_t RegisterCommand(const char *cmdname, const char *method, const char *icon=0)
Register command which can be executed from web interface.
Float_t px
Definition: hprod.C:33
TH1F * hpx
Definition: hcons.C:32
const Bool_t kTRUE
Definition: Rtypes.h:91
Int_t Fill(Double_t)
Invalid Fill method.
Definition: TH2.cxx:287
Bool_t SetItemField(const char *fullname, const char *name, const char *value)
void Restrict(const char *path, const char *options)
Restrict access to specified object.
const char * cnt
Definition: TXMLSetup.cxx:75
2-D histogram with a double per channel (see TH1 documentation)}
Definition: TH2.h:297