Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
simplesamlphp
Manage
Activity
Members
Labels
Plan
Jira
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Perun
Perun ProxyIdP
v1
simplesamlphp
Commits
530acfb2
Commit
530acfb2
authored
7 years ago
by
Patrick Radtke
Browse files
Options
Downloads
Patches
Plain Diff
Allow CLI invocation of Cron
parent
d1cdc33a
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
modules/cron/bin/cron.php
+45
-0
45 additions, 0 deletions
modules/cron/bin/cron.php
modules/cron/lib/Cron.php
+61
-0
61 additions, 0 deletions
modules/cron/lib/Cron.php
modules/cron/www/cron.php
+6
-15
6 additions, 15 deletions
modules/cron/www/cron.php
with
112 additions
and
15 deletions
modules/cron/bin/cron.php
0 → 100644
+
45
−
0
View file @
530acfb2
#!/usr/bin/env php
<?php
/*
* This script can be used to invoke cron jobs from cli.
* You most likely want to execute as the user running your webserver.
* Example: su -s "/bin/sh" -c "php /var/simplesamlphp/modules/cron/bin/cron.php -t hourly" apache
*/
// This is the base directory of the SimpleSAMLphp installation
$baseDir
=
dirname
(
dirname
(
dirname
(
dirname
(
__FILE__
))));
// Add library autoloader.
require_once
(
$baseDir
.
'/lib/_autoload.php'
);
if
(
!
SimpleSAML\Module
::
isModuleEnabled
(
'cron'
))
{
echo
(
"You need to enable the cron module before this script can be used.
\n
"
);
echo
(
"You can enable it by running the following command:
\n
"
);
echo
(
' echo >"'
.
$baseDir
.
'/modules/cron/enable'
.
"
\"\n
"
);
exit
(
1
);
}
$options
=
getopt
(
"t:"
);
if
(
posix_getuid
()
===
0
)
{
echo
"Running as root is discouraged. Some cron jobs will generate files that would have the wrong ownership.
\n
"
;
echo
'Suggested invocation: su -s "/bin/sh" -c "php /var/simplesamlphp/modules/cron/bin/cron.php -t hourly" apache'
;
exit
(
3
);
}
if
(
!
array_key_exists
(
't'
,
$options
))
{
echo
"You must provide a tag (-t) option"
;
exit
(
2
);
}
$tag
=
$options
[
't'
];
$cron
=
new
sspmod_cron_Cron
();
if
(
!
$cron
->
isValidTag
(
$tag
))
{
echo
"Invalid tag option '
$tag
'.
\n
"
;
exit
(
2
);
}
$cronInfo
=
$cron
->
runTag
(
$tag
);
print_r
(
$cronInfo
);
exit
(
0
);
This diff is collapsed.
Click to expand it.
modules/cron/lib/Cron.php
0 → 100644
+
61
−
0
View file @
530acfb2
<?php
/**
* Handles interactions with SSP's cron system/hooks.
*/
class
sspmod_cron_Cron
{
/**
* The configuration for the Cron module
* @var SimpleSAML_Configuration
*/
private
$cronconfig
;
/*
* @param SimpleSAML_Configuration $cronconfig The cron configuration to use. If not specified defaults
* to `config/module_cron.php`
*/
public
function
__construct
(
SimpleSAML_Configuration
$cronconfig
=
null
)
{
if
(
$cronconfig
==
null
)
{
$cronconfig
=
SimpleSAML_Configuration
::
getConfig
(
'module_cron.php'
);
}
$this
->
cronconfig
=
$cronconfig
;
}
/**
* Invoke the cron hook for the given tag
* @param $tag string The tag to use. Must be valid in the cronConfig
* @return array the tag, and summary information from the run.
* @throws Exception If an invalid tag specified
*/
public
function
runTag
(
$tag
)
{
if
(
!
$this
->
isValidTag
(
$tag
))
{
throw
new
\Exception
(
"Invalid cron tag '
$tag
''"
);
}
$summary
=
array
();
$croninfo
=
array
(
'summary'
=>
&
$summary
,
'tag'
=>
$tag
,
);
SimpleSAML\Module
::
callHooks
(
'cron'
,
$croninfo
);
foreach
(
$summary
as
$s
)
{
SimpleSAML\Logger
::
debug
(
'Cron - Summary: '
.
$s
);
}
return
$croninfo
;
}
public
function
isValidTag
(
$tag
)
{
if
(
!
is_null
(
$this
->
cronconfig
->
getValue
(
'allowed_tags'
)))
{
return
in_array
(
$tag
,
$this
->
cronconfig
->
getArray
(
'allowed_tags'
));
}
return
true
;
}
}
This diff is collapsed.
Click to expand it.
modules/cron/www/cron.php
+
6
−
15
View file @
530acfb2
...
...
@@ -9,27 +9,18 @@ if (!is_null($cronconfig->getValue('key'))) {
exit
;
}
}
if
(
!
is_null
(
$cronconfig
->
getValue
(
'allowed_tags'
)))
{
if
(
!
in_array
(
$_REQUEST
[
'tag'
],
$cronconfig
->
getValue
(
'allowed_tags'
)))
{
SimpleSAML\Logger
::
error
(
'Cron - Illegal tag ['
.
$_REQUEST
[
'tag'
]
.
'].'
);
exit
;
}
$cron
=
new
sspmod_cron_Cron
(
$cronconfig
);
if
(
!
$cron
->
isValidTag
(
$_REQUEST
[
'tag'
]
))
{
SimpleSAML\Logger
::
error
(
'Cron - Illegal tag ['
.
$_REQUEST
[
'tag'
]
.
'].'
)
;
exit
;
}
$summary
=
array
();
$croninfo
=
array
(
'summary'
=>
&
$summary
,
'tag'
=>
$_REQUEST
[
'tag'
],
);
$url
=
\SimpleSAML\Utils\HTTP
::
getSelfURL
();
$time
=
date
(
DATE_RFC822
);
SimpleSAML\Module
::
callHooks
(
'cron'
,
$croninfo
);
foreach
(
$summary
AS
$s
)
{
SimpleSAML\Logger
::
debug
(
'Cron - Summary: '
.
$s
);
}
$croninfo
=
$cron
->
runTag
(
$_REQUEST
[
'tag'
]);
if
(
$cronconfig
->
getValue
(
'sendemail'
,
TRUE
)
&&
count
(
$summary
)
>
0
)
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment