POST */ curl_setopt($curl, CURLOPT_POST, true); /* [3] Manage post data =========================================================*/ /* (1) Set post data */ $postarray = [ 'token' => $hash, 'data' => $data ]; /* (2) Add renew if renew */ if( strlen($new) == 128 ) $postarray['renew'] = $new; /* (3) Parse postfiels to multipart format */ $postraw = "--$boundary"; foreach($postarray as $postkey=>$postvalue) $postraw .= "\r\nContent-Disposition: form-data; name=\"$postkey\"\r\n\r\n$postvalue\r\n--$boundary"; $postraw .= "--"; /* (4) Set postdata raw to curl */ curl_setopt($curl, CURLOPT_POSTFIELDS, $postraw); /* [4] Manage headers =========================================================*/ curl_setopt($curl, CURLOPT_HTTPHEADER, [ "Content-Type: multipart/form-data; boundary=$boundary", "Content-Length: ".strlen($postraw) ]); /* [5] Send and catch request response =========================================================*/ /* (1) Send and catch response */ $response = curl_exec($curl); /* (2) Close request */ curl_close($curl); /* (3) Return response as result */ if( $response === false ){ slog("Request error", 'api:sync'); return 127; } /* [6] Response management =========================================================*/ /* (1) Writes request to temporary pipe */ file_put_contents(TMP_DIR.'/api.response', $response); /* (2) Manage response deployement */ $deploy = syscall(SOURCE_DIR.'/lib/api/deploy'); /* (3) Return state */ return ($deploy === true); } echo api_request(); ?>