-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbridge.php
executable file
·124 lines (111 loc) · 3.65 KB
/
bridge.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#!/usr/bin/php -qC
<?php
/**
* eGroupWare digital ROCK Rankings - bridge to old ROCK programs
*
* Use fuse and sshfs to mount old granit filesystem to webserver eg:
* granit: ssh -R2022:localhost:22 [email protected]
* www: sshfs -o reconnect,cache_stat_timeout=0 -p 2022 ralf@localhost:/var/www/html/2010/10_arco /var/www/ifsc-climbing
.org/2010/10_arco
*
* @link http://www.egroupware.org
* @package admin
* @author Ralf Becker <RalfBecker-AT-outdoor-training.de>
* @copyright (c) 2010 by Ralf Becker <RalfBecker-AT-outdoor-training.de>
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
* @version $Id$
*/
function die_usage()
{
$cmd = basename($_SERVER['argv'][0]);
die("Usage: $cmd account[@domain] password WetId rock_route heat\n");
}
ini_set('display_errors',false);
// utf8 support
if (!extension_loaded('mbstring')) dl('mbstring.so');
if (ini_get('mbstring.func_overload') != 7) echo "mbstring.func_overload=7 required!!!\n\n";
if (php_sapi_name() !== 'cli') // security precaution: forbit calling display demon as web-page
{
die('<h1>bridge.php must NOT be called as web-page --> exiting !!!</h1>');
}
elseif ($_SERVER['argc'] < 6)
{
die_usage();
}
// this is kind of a hack, as the autocreate_session_callback can not change the type of the loaded account-class
// so we need to make sure the right one is loaded by setting the domain before the header gets included.
@list(,$_REQUEST['domain']) = explode('@',$_SERVER['argv'][1]);
if (!is_writable(ini_get('session.save_path')) && is_dir('/tmp')) ini_set('session.save_path','/tmp'); // regular users may have no rights to apache's session dir
$GLOBALS['egw_info'] = array(
'flags' => array(
'currentapp' => 'ranking',
'noheader' => true,
'autocreate_session_callback' => 'user_pass_from_argv',
)
);
include(dirname(dirname(__FILE__)).'/header.inc.php');
ob_end_flush();
/**
* callback if the session-check fails, redirects via xajax to login.php
*
* @param array &$account account_info with keys 'login', 'passwd' and optional 'passwd_type'
* @return boolean/string true if we allow the access and account is set, a sessionid or false otherwise
*/
function user_pass_from_argv(&$account)
{
$account = array(
'login' => $_SERVER['argv'][1],
'passwd' => $_SERVER['argv'][2],
'passwd_type' => 'text',
);
//print_r($account);
if (!($sessionid = $GLOBALS['egw']->session->create($account)))
{
echo "Wrong account or -password !!!\n\n";
die_usage();
}
if (!$GLOBALS['egw_info']['user']['apps']['ranking']) // will be tested by the header too, but whould give html error-message
{
echo "Permission denied !!!\n\n";
die_usage();
}
return $sessionid;
}
require_once(EGW_INCLUDE_ROOT.'/ranking/inc/class.boresult.inc.php');
$boresult = new boresult();
if (!($comp = $boresult->comp->read($_SERVER['argv'][3])))
{
die("Compeitition {$_SERVER['argv'][3]} NOT found!");
}
$rock_route = $_SERVER['argv'][4];
// todo: detect heat from $rock_route
$heat = (int)$_SERVER['argv'][5];
$base_path = '/var/www/html';
list(,$wettk) = explode('.',$rock_route);
$year = 2000 + substr($wettk,0,2);
$file = $base_path.'/'.$year.'/'.$wettk.'/'.$rock_route.'.php';
if (!file_exists($file))
{
die("Rock export file $file NOT found!\n\n");
}
$last_mtime = null;
while(true)
{
clearstatcache();
$mtime = @filemtime($file);
if (file_exists($file) && (is_null($last_mtime) || $last_mtime != $mtime))
{
$imported = $boresult->import_rock($file,$comp,$heat);
echo date('Y-m-d H:i:s ');
if (is_int($imported))
{
echo "$imported participants imported.\n";
$last_mtime = $mtime;
}
else
{
echo "Error: $imported\n";
}
}
usleep(500000); // sleep for a half sec
}