Subversion Repositories eFlore/Applications.cel

Rev

Rev 1793 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1793 Rev 1802
Line 132... Line 132...
132
 
132
 
133
 
133
 
134
function auth() {
134
function auth() {
-
 
135
	// TODO: CURLOPT_NETRC + Cel API support
135
	// TODO: CURLOPT_NETRC + Cel API support
136
	if(!defined('EMAIL') || !defined('PASS') || ! EMAIL || ! PASS) return FALSE;
Line 136... Line 137...
136
	if(!defined('EMAIL') || !defined('PASS') || ! EMAIL || ! PASS) return FALSE;
137
	if(defined('COOKIE') && COOKIE) return TRUE;
Line 137... Line 138...
137
	$URL = DOMAIN . '/jrest/User/' . EMAIL . '/' . PASS;
138
	$URL = DOMAIN . '/jrest/User/' . EMAIL . '/' . PASS;
Line 143... Line 144...
143
	curl_setopt($ch,CURLOPT_HEADER, true);
144
	curl_setopt($ch,CURLOPT_HEADER, true);
144
	curl_setopt($ch,CURLOPT_RETURNTRANSFER, TRUE);
145
	curl_setopt($ch,CURLOPT_RETURNTRANSFER, TRUE);
Line 145... Line 146...
145
 
146
 
146
	$result = curl_exec($ch);
147
	$result = curl_exec($ch);
147
	curl_close($ch);
148
	curl_close($ch);
148
	$sess = array();
149
	$sess = $id = array();
-
 
150
	preg_match('/.*PHPSESSID=(\w+)/', $result, $sess);
-
 
151
	preg_match('/"id_utilisateur":"(\d+)"/', $result, $id);
149
	preg_match('/.*PHPSESSID=(\w+).*/', $result, $sess);
152
	if(DEBUG) fwrite(STDERR, "curl \"".$URL ."\" : {$sess[1]} / {$id[1]}\n");
150
	if(isset($sess[1])) {
153
	if(isset($sess[1])) {
-
 
154
		define('COOKIE', $sess[1]);
-
 
155
		if(!defined('USER')) {
-
 
156
			if(!isset($id[1])) return FALSE;
-
 
157
			define('USER', $id[1]);
151
		define('COOKIE', $sess[1]);
158
		}
152
		return true;
159
		return TRUE;
153
	}
160
	}
154
	return false;
161
	return FALSE;
Line 155... Line 162...
155
}
162
}
156
 
163
 
157
function genCSV($d = Array()) {
164
function genCSV($d = Array()) {
Line 184... Line 191...
184
		'upload' => '@' . $d . ';filename=test.csv',
191
		'upload' => '@' . $d . ';filename=test.csv',
185
		'utilisateur' => USER
192
		'utilisateur' => USER
186
	));
193
	));
Line 187... Line 194...
187
 
194
 
-
 
195
	curl_setopt($ch,CURLOPT_RETURNTRANSFER, TRUE);
-
 
196
 
-
 
197
	if(DEBUG) fwrite(STDERR, "curl -F \"upload=@$d;filename=test.csv\" -F utilisateur=" . USER . " \"$URL\"\n");
188
	curl_setopt($ch,CURLOPT_RETURNTRANSFER, TRUE);
198
 
189
	//execute post
199
	//execute post
190
	$result = curl_exec($ch);
200
	$result = curl_exec($ch);
191
	curl_close($ch);
201
	curl_close($ch);
192
	return $result;
202
	return $result;