Filename | /var/www/foswikidev/core/lib/Foswiki/Plugins/ConfigurePlugin.pm |
Statements | Executed 85 statements in 1.61ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 2.71ms | 7.79ms | BEGIN@38 | Foswiki::Plugins::ConfigurePlugin::
1 | 1 | 1 | 2.23ms | 2.41ms | BEGIN@44 | Foswiki::Plugins::ConfigurePlugin::
1 | 1 | 1 | 1.47ms | 4.99ms | BEGIN@42 | Foswiki::Plugins::ConfigurePlugin::
1 | 1 | 1 | 384µs | 754µs | BEGIN@37 | Foswiki::Plugins::ConfigurePlugin::
1 | 1 | 1 | 342µs | 450µs | BEGIN@36 | Foswiki::Plugins::ConfigurePlugin::
1 | 1 | 1 | 291µs | 369µs | BEGIN@43 | Foswiki::Plugins::ConfigurePlugin::
1 | 1 | 1 | 172µs | 217µs | BEGIN@40 | Foswiki::Plugins::ConfigurePlugin::
1 | 1 | 1 | 78µs | 3.70ms | initPlugin | Foswiki::Plugins::ConfigurePlugin::
5 | 1 | 1 | 24µs | 24µs | _JSONwrap | Foswiki::Plugins::ConfigurePlugin::
1 | 1 | 1 | 15µs | 41µs | BEGIN@34 | Foswiki::Plugins::ConfigurePlugin::
1 | 1 | 1 | 14µs | 27µs | BEGIN@31 | Foswiki::Plugins::ConfigurePlugin::
1 | 1 | 1 | 12µs | 21µs | BEGIN@162 | Foswiki::Plugins::ConfigurePlugin::
1 | 1 | 1 | 11µs | 43µs | BEGIN@51 | Foswiki::Plugins::ConfigurePlugin::
1 | 1 | 1 | 10µs | 24µs | BEGIN@149 | Foswiki::Plugins::ConfigurePlugin::
1 | 1 | 1 | 10µs | 14µs | BEGIN@32 | Foswiki::Plugins::ConfigurePlugin::
1 | 1 | 1 | 5µs | 5µs | BEGIN@53 | Foswiki::Plugins::ConfigurePlugin::
1 | 1 | 1 | 5µs | 5µs | BEGIN@39 | Foswiki::Plugins::ConfigurePlugin::
1 | 1 | 1 | 4µs | 4µs | BEGIN@41 | Foswiki::Plugins::ConfigurePlugin::
0 | 0 | 0 | 0s | 0s | __ANON__[:171] | Foswiki::Plugins::ConfigurePlugin::
0 | 0 | 0 | 0s | 0s | TO_JSON | Regexp::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | # See bottom of file for default license and copyright information | ||||
2 | |||||
3 | # Note on separation of concerns: Please *do not* add anything to this | ||||
4 | # plugin that is not specific to the Javascript 'configure' interface. | ||||
5 | # Generic functionality related to configuration should be implemented | ||||
6 | # in the core. The ConfigurePlugin is *just* for handling the UI, no more. | ||||
7 | |||||
8 | # Note that POD in this module is included in the documentation topic | ||||
9 | # by BuildContrib | ||||
10 | |||||
11 | =pod | ||||
12 | |||||
13 | ---++ Remote Procedure Call (RPC) interface | ||||
14 | |||||
15 | RPC calls are handled via the =JsonRpcContrib=. Callers must authenticate | ||||
16 | as admins, or the request will be rejected with a 403 status. | ||||
17 | |||||
18 | Note: If Foswiki is running in 'bootstrap' mode (without a !LocalSite.cfg) | ||||
19 | then *all* calls are automatically assumed to be from an admin. As soon | ||||
20 | as a !LocalSite.cfg is put in place, then the authentication set up | ||||
21 | therein will apply, and users are required to logged in as admins. | ||||
22 | |||||
23 | Entry points for each of the static methods published by the | ||||
24 | Foswiki::Configure::Query class are supported. See that class for | ||||
25 | descriptions. | ||||
26 | |||||
27 | =cut | ||||
28 | |||||
29 | package Foswiki::Plugins::ConfigurePlugin; | ||||
30 | |||||
31 | 2 | 28µs | 2 | 41µs | # spent 27µs (14+14) within Foswiki::Plugins::ConfigurePlugin::BEGIN@31 which was called:
# once (14µs+14µs) by Foswiki::Plugin::BEGIN@2.9 at line 31 # spent 27µs making 1 call to Foswiki::Plugins::ConfigurePlugin::BEGIN@31
# spent 14µs making 1 call to strict::import |
32 | 2 | 36µs | 2 | 18µs | # spent 14µs (10+4) within Foswiki::Plugins::ConfigurePlugin::BEGIN@32 which was called:
# once (10µs+4µs) by Foswiki::Plugin::BEGIN@2.9 at line 32 # spent 14µs making 1 call to Foswiki::Plugins::ConfigurePlugin::BEGIN@32
# spent 4µs making 1 call to warnings::import |
33 | 1 | 700ns | our $VERSION = '1.01'; | ||
34 | 2 | 28µs | 2 | 67µs | # spent 41µs (15+26) within Foswiki::Plugins::ConfigurePlugin::BEGIN@34 which was called:
# once (15µs+26µs) by Foswiki::Plugin::BEGIN@2.9 at line 34 # spent 41µs making 1 call to Foswiki::Plugins::ConfigurePlugin::BEGIN@34
# spent 26µs making 1 call to Exporter::import |
35 | |||||
36 | 2 | 99µs | 1 | 450µs | # spent 450µs (342+109) within Foswiki::Plugins::ConfigurePlugin::BEGIN@36 which was called:
# once (342µs+109µs) by Foswiki::Plugin::BEGIN@2.9 at line 36 # spent 450µs making 1 call to Foswiki::Plugins::ConfigurePlugin::BEGIN@36 |
37 | 2 | 87µs | 1 | 754µs | # spent 754µs (384+370) within Foswiki::Plugins::ConfigurePlugin::BEGIN@37 which was called:
# once (384µs+370µs) by Foswiki::Plugin::BEGIN@2.9 at line 37 # spent 754µs making 1 call to Foswiki::Plugins::ConfigurePlugin::BEGIN@37 |
38 | 2 | 118µs | 1 | 7.79ms | # spent 7.79ms (2.71+5.08) within Foswiki::Plugins::ConfigurePlugin::BEGIN@38 which was called:
# once (2.71ms+5.08ms) by Foswiki::Plugin::BEGIN@2.9 at line 38 # spent 7.79ms making 1 call to Foswiki::Plugins::ConfigurePlugin::BEGIN@38 |
39 | 2 | 20µs | 1 | 5µs | # spent 5µs within Foswiki::Plugins::ConfigurePlugin::BEGIN@39 which was called:
# once (5µs+0s) by Foswiki::Plugin::BEGIN@2.9 at line 39 # spent 5µs making 1 call to Foswiki::Plugins::ConfigurePlugin::BEGIN@39 |
40 | 2 | 86µs | 1 | 217µs | # spent 217µs (172+45) within Foswiki::Plugins::ConfigurePlugin::BEGIN@40 which was called:
# once (172µs+45µs) by Foswiki::Plugin::BEGIN@2.9 at line 40 # spent 217µs making 1 call to Foswiki::Plugins::ConfigurePlugin::BEGIN@40 |
41 | 2 | 19µs | 1 | 4µs | # spent 4µs within Foswiki::Plugins::ConfigurePlugin::BEGIN@41 which was called:
# once (4µs+0s) by Foswiki::Plugin::BEGIN@2.9 at line 41 # spent 4µs making 1 call to Foswiki::Plugins::ConfigurePlugin::BEGIN@41 |
42 | 2 | 102µs | 1 | 4.99ms | # spent 4.99ms (1.47+3.52) within Foswiki::Plugins::ConfigurePlugin::BEGIN@42 which was called:
# once (1.47ms+3.52ms) by Foswiki::Plugin::BEGIN@2.9 at line 42 # spent 4.99ms making 1 call to Foswiki::Plugins::ConfigurePlugin::BEGIN@42 |
43 | 2 | 101µs | 1 | 369µs | # spent 369µs (291+77) within Foswiki::Plugins::ConfigurePlugin::BEGIN@43 which was called:
# once (291µs+77µs) by Foswiki::Plugin::BEGIN@2.9 at line 43 # spent 369µs making 1 call to Foswiki::Plugins::ConfigurePlugin::BEGIN@43 |
44 | 2 | 130µs | 1 | 2.41ms | # spent 2.41ms (2.23+177µs) within Foswiki::Plugins::ConfigurePlugin::BEGIN@44 which was called:
# once (2.23ms+177µs) by Foswiki::Plugin::BEGIN@2.9 at line 44 # spent 2.41ms making 1 call to Foswiki::Plugins::ConfigurePlugin::BEGIN@44 |
45 | |||||
46 | 1 | 400ns | our $RELEASE = '18 Dec 2014'; | ||
47 | 1 | 200ns | our $SHORTDESCRIPTION = '=configure= interface using json-rpc'; | ||
48 | |||||
49 | 1 | 200ns | our $NO_PREFS_IN_TOPIC = 1; | ||
50 | |||||
51 | 2 | 55µs | 2 | 74µs | # spent 43µs (11+32) within Foswiki::Plugins::ConfigurePlugin::BEGIN@51 which was called:
# once (11µs+32µs) by Foswiki::Plugin::BEGIN@2.9 at line 51 # spent 43µs making 1 call to Foswiki::Plugins::ConfigurePlugin::BEGIN@51
# spent 32µs making 1 call to constant::import |
52 | |||||
53 | # spent 5µs within Foswiki::Plugins::ConfigurePlugin::BEGIN@53 which was called:
# once (5µs+0s) by Foswiki::Plugin::BEGIN@2.9 at line 60 | ||||
54 | # Note: if Foswiki is in bootstrap mode, Foswiki.pm will try | ||||
55 | # to require this module, thus executing this BEGIN block. | ||||
56 | |||||
57 | 1 | 1µs | $Foswiki::cfg{Plugins}{ConfigurePlugin}{Enabled} = 1; | ||
58 | 1 | 5µs | $Foswiki::cfg{Plugins}{ConfigurePlugin}{Module} = | ||
59 | 'Foswiki::Plugins::ConfigurePlugin'; | ||||
60 | 1 | 399µs | 1 | 5µs | } # spent 5µs making 1 call to Foswiki::Plugins::ConfigurePlugin::BEGIN@53 |
61 | |||||
62 | { | ||||
63 | # Required for JSON to serialise Regexp types. Simply | ||||
64 | # converts them to strings. | ||||
65 | 1 | 500ns | package Regexp; | ||
66 | |||||
67 | sub TO_JSON { | ||||
68 | my $regex = shift; | ||||
69 | $regex = "$regex"; | ||||
70 | return $regex; | ||||
71 | } | ||||
72 | } | ||||
73 | |||||
74 | # spent 3.70ms (78µs+3.62) within Foswiki::Plugins::ConfigurePlugin::initPlugin which was called:
# once (78µs+3.62ms) by Foswiki::Plugin::__ANON__[/var/www/foswikidev/core/lib/Foswiki/Plugin.pm:257] at line 250 of /var/www/foswikidev/core/lib/Foswiki/Plugin.pm | ||||
75 | 1 | 2µs | my ( $topic, $web, $user, $installWeb ) = @_; | ||
76 | |||||
77 | # No way to auto-register JsonRpcContrib, so we have to do it :-( | ||||
78 | 1 | 1µs | 1 | 12µs | Foswiki::Plugins::JQueryPlugin::registerPlugin( 'JsonRpc', # spent 12µs making 1 call to Foswiki::Plugins::JQueryPlugin::registerPlugin |
79 | 'Foswiki::Contrib::JsonRpcContrib::JQueryPlugin' ); | ||||
80 | |||||
81 | 1 | 2µs | 1 | 10µs | Foswiki::Plugins::JQueryPlugin::registerPlugin( 'Configure', # spent 10µs making 1 call to Foswiki::Plugins::JQueryPlugin::registerPlugin |
82 | 'Foswiki::Plugins::ConfigurePlugin::JQuery' ); | ||||
83 | |||||
84 | # Register each of the RPC methods with JsonRpcContrib | ||||
85 | 5 | 6µs | my @methods = | ||
86 | 5 | 1µs | map { $_ =~ s/^.*:://; $_ } | ||
87 | grep { defined &{$_} } | ||||
88 | 13 | 5µs | map { "Foswiki::Configure::Query::$_" } | ||
89 | 1 | 20µs | grep { $_ =~ m/^[a-z]/ } | ||
90 | keys %Foswiki::Configure::Query::; | ||||
91 | |||||
92 | 1 | 2µs | foreach my $method (@methods) { | ||
93 | |||||
94 | 5 | 16µs | 10 | 3.59ms | Foswiki::Contrib::JsonRpcContrib::registerMethod( 'configure', $method, # spent 3.57ms making 5 calls to Foswiki::Contrib::JsonRpcContrib::registerMethod, avg 714µs/call
# spent 24µs making 5 calls to Foswiki::Plugins::ConfigurePlugin::_JSONwrap, avg 5µs/call |
95 | _JSONwrap("Foswiki::Configure::Query::$method") ); | ||||
96 | } | ||||
97 | |||||
98 | # Bootstrap code. Capture the path for the "view" script from the URL | ||||
99 | # and stash it into a session variable for use by jsonrpc commands. | ||||
100 | # Or if it's not in the query, recover it from the session variable. | ||||
101 | # (jsonrpc uses POSTs, so the URL param isn't there. | ||||
102 | 1 | 2µs | 1 | 3µs | my $query = Foswiki::Func::getRequestObject(); # spent 3µs making 1 call to Foswiki::Func::getRequestObject |
103 | 1 | 200ns | my $viewpath; | ||
104 | 1 | 1µs | if ( $Foswiki::cfg{isBOOTSTRAPPING} && defined $query ) { | ||
105 | $viewpath = $query->param('VIEWPATH'); | ||||
106 | if ( defined $viewpath ) { | ||||
107 | $Foswiki::cfg{ScriptUrlPaths}{view} = $viewpath; | ||||
108 | $Foswiki::Plugins::SESSION->getLoginManager() | ||||
109 | ->setSessionValue( 'VIEWPATH', $viewpath ); | ||||
110 | print STDERR "AUTOCONFIG: Applied viewpath $viewpath from URL\n" | ||||
111 | if (Foswiki::Configure::Load::TRAUTO); | ||||
112 | } | ||||
113 | else { | ||||
114 | $viewpath = | ||||
115 | $Foswiki::Plugins::SESSION->getLoginManager() | ||||
116 | ->getSessionValue('VIEWPATH'); | ||||
117 | if ( defined $viewpath ) { | ||||
118 | $Foswiki::cfg{ScriptUrlPaths}{view} = $viewpath; | ||||
119 | print STDERR | ||||
120 | "AUTOCONFIG: Applied viewpath $viewpath from SESSION\n" | ||||
121 | if (Foswiki::Configure::Load::TRAUTO); | ||||
122 | } | ||||
123 | } | ||||
124 | |||||
125 | # pubdir is calculated relative from the bin dir. Now that we know that | ||||
126 | # short URL's might be in use, override the initial bootstrapped value | ||||
127 | # with a better guess. | ||||
128 | if ( defined $viewpath && $viewpath !~ m#/view# ) { | ||||
129 | print STDERR "AUTOCONFIG: Adjust PubUrlPath relative to viewpath\n"; | ||||
130 | $Foswiki::cfg{PubUrlPath} = $viewpath . '/pub'; | ||||
131 | } | ||||
132 | } | ||||
133 | |||||
134 | 1 | 4µs | return 1; | ||
135 | |||||
136 | } | ||||
137 | |||||
138 | # spent 24µs within Foswiki::Plugins::ConfigurePlugin::_JSONwrap which was called 5 times, avg 5µs/call:
# 5 times (24µs+0s) by Foswiki::Plugins::ConfigurePlugin::initPlugin at line 94, avg 5µs/call | ||||
139 | 5 | 2µs | my $method = shift; | ||
140 | return sub { | ||||
141 | my ( $session, $request ) = @_; | ||||
142 | |||||
143 | if ( $Foswiki::cfg{isVALID} ) { | ||||
144 | Foswiki::Configure::Auth::checkAccess( $session, 1 ); | ||||
145 | } | ||||
146 | |||||
147 | my $reporter = Foswiki::Configure::Reporter->new(); | ||||
148 | |||||
149 | 2 | 79µs | 2 | 39µs | # spent 24µs (10+14) within Foswiki::Plugins::ConfigurePlugin::BEGIN@149 which was called:
# once (10µs+14µs) by Foswiki::Plugin::BEGIN@2.9 at line 149 # spent 24µs making 1 call to Foswiki::Plugins::ConfigurePlugin::BEGIN@149
# spent 14µs making 1 call to strict::unimport |
150 | my $response; | ||||
151 | |||||
152 | eval { require Taint::Runtime; }; | ||||
153 | if ($@) { | ||||
154 | $response = &$method( $request->params(), $reporter ); | ||||
155 | } | ||||
156 | else { | ||||
157 | # Disable taint checking, it's more trouble than it's worth | ||||
158 | local $Taint::Runtime::TAINT = 0; | ||||
159 | $response = &$method( $request->params(), $reporter ); | ||||
160 | } | ||||
161 | |||||
162 | 2 | 117µs | 2 | 31µs | # spent 21µs (12+10) within Foswiki::Plugins::ConfigurePlugin::BEGIN@162 which was called:
# once (12µs+10µs) by Foswiki::Plugin::BEGIN@2.9 at line 162 # spent 21µs making 1 call to Foswiki::Plugins::ConfigurePlugin::BEGIN@162
# spent 10µs making 1 call to strict::import |
163 | unless ($response) { | ||||
164 | |||||
165 | # Should never get here | ||||
166 | die $method . " " | ||||
167 | . join( "\n", | ||||
168 | map { "$_->{level}: $_->{text}" } @{ $reporter->messages() } ); | ||||
169 | } | ||||
170 | return $response; | ||||
171 | } | ||||
172 | 5 | 29µs | } | ||
173 | |||||
174 | =pod | ||||
175 | |||||
176 | ---++ Invocation examples | ||||
177 | |||||
178 | Call using a URL of the format: | ||||
179 | |||||
180 | =%SCRIPTURL{"jsonrpc"}%/configure= | ||||
181 | |||||
182 | while POSTing a request encoded according to the JSON-RPC 2.0 specification: | ||||
183 | |||||
184 | <verbatim> | ||||
185 | { | ||||
186 | jsonrpc: "2.0", | ||||
187 | method: "getspec", | ||||
188 | params: { | ||||
189 | get : { keys: "{DataDir}" }, | ||||
190 | depth : 0 | ||||
191 | }, | ||||
192 | id: "caller's id" | ||||
193 | } | ||||
194 | </verbatim> | ||||
195 | |||||
196 | ---++ .spec format | ||||
197 | The format of .spec files is documented in detail in | ||||
198 | There are two node types in the .spec tree: | ||||
199 | |||||
200 | SECTIONs have: | ||||
201 | * =headline= (default =UNKNOWN=, the root is usually '') | ||||
202 | * =typename= (always =SECTION=) | ||||
203 | * =children= - array of child nodes (sections and keys) | ||||
204 | |||||
205 | Key entries (such as ={DataDir}=) have: | ||||
206 | * =keys= e.g. ={Store}{Cupboard}= | ||||
207 | * =typename= (from the .spec) | ||||
208 | * Other keys from the .spec e.g. =SIZE=, =FEEDBACK=, =CHECK= | ||||
209 | |||||
210 | =cut | ||||
211 | |||||
212 | 1 | 4µs | 1; | ||
213 | |||||
214 | __END__ |