Wettmannstaetten impot update & ofaa oaid scripts

This commit is contained in:
Frank Schubert
2023-07-11 11:43:15 +02:00
parent 2deeead7c6
commit 7c513a7595
10 changed files with 2781 additions and 11 deletions

View File

@@ -13,7 +13,7 @@ require_once(LIBDIR."/mvcfronk/mfBase/mfBaseController.php");
$me = new User(1);
$filename = __DIR__."/import/WMST Locations E-STMK.csv";
$filename = __DIR__."/import/SDIBuilding__Locations__FTTx__ Wettmannstaetten_20230711.csv";
$db = FronkDB::singleton(ADDRESSDB_DBHOST, ADDRESSDB_DBUSER, ADDRESSDB_DBPASS, ADDRESSDB_DBNAME);
$log = mfLoghandler::singleton();
@@ -40,16 +40,16 @@ while($csv = fgetcsv($input, 0, ";")) {
}
//echo implode(", ", $csv)."\n";
$gem_kz = trim($csv[1]);
$gem_name = trim($csv[11]);
$gem_kz = trim($csv[60]);
$gem_name = trim($csv[59]);
//$ort_kz = trim($csv[2]);
$plz_name = trim($csv[87]);
$plz_name = trim($csv[88]);
if(!$plz_name) {
$plz_name = $default_plz;
}
$ort_name = trim($csv[8]);
$strasse_hausnummer = trim($csv[7]);
$hausnummer_extref = trim($csv[65]);
$ort_name = trim($csv[31]);
$strasse_hausnummer = trim($csv[22]);
$hausnummer_extref = trim($csv[64]);
if(in_array($hausnummer_extref, $h_extrefs)) {
die("Hausnummer extref doppelt!\n");
}
@@ -61,22 +61,25 @@ while($csv = fgetcsv($input, 0, ";")) {
//var_dump($netzgebiet);exit;
$nutzung = trim($csv[6]);
$nutzung = trim($csv[30]);
//$funktion = trim($csv[6]);
/*if($nutzung != "Greenfield" && $funktion == "Greenfield") {
$nutzung = "Greenfield";
}*/
$unit_count = $csv[3];
$unit_count = $csv[78];
if(!$unit_count) $unit_count = 1;
$adrcd = false;
$adr = trim($csv[52]);
$adr = trim($csv[46]);
$adr_parts = explode("-", $adr);
if(count($adr_parts)) {
$adrcd = $adr_parts[0];
}
$fcp_name = $csv[49];
$rimo_id = $csv[96];
if(!$strasse_hausnummer) continue;
//echo "strasse: $strasse\n";
@@ -127,6 +130,9 @@ while($csv = fgetcsv($input, 0, ";")) {
$ort_name = "Wettmannstätten";
}
if($strasse_name == "Wohlsdorfer Straße" && $ort_name == "Preding") {
$gem_kz = 60324;
}
if(!$strasse_name && $nutzung != "Greenfield") {
die("Unbekanntes Adressformat\n");
@@ -237,6 +243,8 @@ while($csv = fgetcsv($input, 0, ";")) {
"gps_long" => $long,
"unit_count" => ($unit_count) ? $unit_count : 1,
"freigabe" => $default_freigabe,
"rimo_id" => $rimo_id,
"rimo_fcp_name" => $fcp_name
];
$hausnummer = ADBHausnummerModel::create($hausnummer_data);
//var_dump($hausnummer);exit;
@@ -263,6 +271,8 @@ while($csv = fgetcsv($input, 0, ";")) {
$hausnummer->gps_lat = (float)$lat;
$hausnummer->gps_long = (float)$long;
}
if($rimo_id) $hausnummer->rimo_id = $rimo_id;
if($fcp_name) $hausnummer->rimo_fcp_name = $fcp_name;
$hausnummer->freigabe = $default_freigabe;
$hausnummer->save();

View File

View File

@@ -0,0 +1,79 @@
#!/usr/bin/php
<?php
require_once __DIR__."/include/config.php";
require_once __DIR__."/include/rest.php";
if(!$access_token) {
$access_token = fetchAccessToken($oauth_url, $client_id, $client_secret, $default_scope);
if(!$access_token) {
die("Error getting access token");
}
}
$headers = [
"Authorization: Bearer $access_token",
"Accept: application/json",
"Content-type: application/json",
];
$content = [
"tenant" => $tenant,
"version" => "v8",
];
var_dump($content);
$c = 0;
$u = 0;
for($i = 0; $i < 621; $i++) {
$content['external_id'] = guidv4();
$output = postRestUrl($ep_request_oaid, $headers, $content, "application/json");
if($output == "__err__401") {
$access_token = fetchAccessToken($oauth_url, $client_id, $client_secret, $default_scope);
$headers = [
"Authorization: Bearer $access_token",
"Accept: application/json",
"Content-type: application/json",
];
$output = postRestUrl($ep_request_oaid, $headers, $content, "application/json");
}
//var_dump($output);exit;
$output_json = json_decode($output);
if(!is_object($output_json)) {
//var_dump($output);
echo "Output not JSON Object\n";
continue;
}
$c++;
$oaid = $output_json->oaid;
$tenant = $output_json->tenant;
$token = $output_json->token;
$status = $output_json->status;
$external_id = $output_json->external_id;
//echo "oaid: $oaid, tenant: $tenant, token: $token, status: $status, external_id: $external_id\n";
if($token == "requested") {
$confirm_url = str_replace("{oaid}", $oaid, $ep_confirm_oaid);
$out = putRestUrl($confirm_url, $headers, ["token" => "confirmed"], "application/json");
if($output == "__err__401") {
$access_token = fetchAccessToken($oauth_url, $client_id, $client_secret, $default_scope);
$headers = [
"Authorization: Bearer $access_token",
"Accept: application/json",
"Content-type: application/json",
];
$out = putRestUrl($confirm_url, $headers, ["token" => "confirmed"], "application/json");
$u++;
}
echo ".";
}
}
echo "Created $c, confirmed $u\n";

View File

@@ -0,0 +1,33 @@
#!/usr/bin/php
<?php
require_once __DIR__."/include/config.php";
require_once __DIR__."/include/rest.php";
if(!$access_token) {
$access_token = fetchAccessToken($oauth_url, $client_id, $client_secret, $default_scope);
if(!$access_token) {
die("Error getting access token");
}
}
$headers = [
"Authorization: Bearer $access_token",
"Accept: application/json",
];
$content = [
"version" => "v8",
"external_id" => guidv4()
];
$output = getRestUrl($ep_mgm_credits, $headers);
if($output == "__err__401") {
$access_token = fetchAccessToken($oauth_url, $client_id, $client_secret, $default_scope);
$headers = [
"Authorization: Bearer $access_token",
"Accept: application/json",
];
$output = getRestUrl($ep_mgm_credits, $headers);
}
var_dump($output);exit;

View File

@@ -0,0 +1 @@
eyJhbGciOiJSUzI1NiIsInR5cCIgOiAiSldUIiwia2lkIiA6ICI5TmkwTWZMaTB4LUlzOEEzc3V1ZlgxNVJiZlROTTRrUDJ2d1lackxvNWRVIn0.eyJleHAiOjE2ODU5Nzk5NTMsImlhdCI6MTY4NTk3OTY1MywianRpIjoiYTFlZTA2ZjUtZTk0Yy00YjE1LTk5ZGQtZjNkNDg5M2M1NDRkIiwiaXNzIjoiaHR0cHM6Ly9zc28ueWlvLmF0L2F1dGgvcmVhbG1zL29haWQiLCJhdWQiOlsiaHR0cHM6Ly9hcGkub2F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ErOVzqeCVufn_kxViUsxYQeVX8_8vNQydiOrgXED5aTLEG0csThKx4HMPh9KMZWiJ5R797OZMfqve7j5RYjDO0Ez44tv-w

View File

@@ -0,0 +1,28 @@
<?php
$oauth_url = "https://sso.yio.at/auth/realms/oaid/protocol/openid-connect/token";
$baseurl = "https://api.oaid.at/v1";
$client_id = "oaid.ofaa.esteiermark";
$client_secret = "4a5b09ed-956c-4721-bb53-3a144fc5f55a";
$tenant = "ofaa.esteiermark";
/*
$baseurl = "https://api-demo.oaid.at/v1";
$client_id = "oaid.demo.pip";
$client_secret = "6e74e7e8-0cc2-43df-83c2-12937452b916";
*/
$ep_mgm_credits = $baseurl."/pip/mgm/credits/";
$ep_list_oaids = $baseurl."/pip/codes/";
$ep_request_oaid = $baseurl."/pip/codes/";
$ep_confirm_oaid = $baseurl."/pip/codes/{oaid}/token/";
$default_scope = ["oaid:mgm:read","oaid:codes:read","oaid:codes:write"];
$access_token = "";
$token_file = __DIR__."/.access_token";
if(file_exists($token_file)) {
$access_token = file_get_contents($token_file);
}

View File

@@ -0,0 +1,142 @@
<?php
function fetchAccessToken($oauth_url, $client_id, $client_secret, $scopes = ["oaid:codes:read"]) {
//echo "called fetchAccessToken $oauth_url\n";
global $token_file;
global $access_token;
$headers = [
"Accept: application/json",
"Content-Type: application/x-www-form-urlencoded",
];
$post_content = [
"grant_type" => "client_credentials",
"client_id" => $client_id,
"client_secret" => $client_secret,
"scope" => implode(" ", $scopes),
];
$output = postRestUrl($oauth_url, $headers, $post_content);
$output_values = json_decode($output);
if(!is_object($output_values) || !property_exists($output_values, "access_token")) {
return false;
}
$access_token = $output_values->access_token;
file_put_contents($token_file, $access_token);
return $access_token;
}
function getRestUrl($url, $headers, $params = [], $debug = false) {
//echo "called getRestUrl $url\n";
$ctx_options = ["http" => [
"ignore_errors" => true,
"method" => "GET",
"header" => $headers,
]];
$_url = $url;
if(count($params)) {
$_url .= "?".http_build_query($params);
}
if($debug) {
var_dump($_url, $ctx_options);
exit;
}
$ctx = stream_context_create($ctx_options);
$output = file_get_contents($_url, false, $ctx);
foreach($http_response_header as $h_line) {
$m = [];
if(preg_match('/HTTP\/\d+(?:\.\d+) ([245]\d+)/', $h_line, $m)) {
$response_code = $m[1];
if(substr($response_code, 0, 1) == "2") {
return $output;
} elseif($response_code == "401") {
return "__err__401";
} else {
die("getRestUrl(): $h_line");
}
}
}
}
function putRestUrl($url, $headers, $content, $content_type = "application/x-www-form-urlencoded", $follow_location = true, $debug = false) {
return postRestUrl($url, $headers, $content, $content_type, $follow_location, $debug, 'PUT');
}
function postRestUrl($url, $headers, $content, $content_type = "application/x-www-form-urlencoded", $follow_location = true, $debug = false, $method = "POST") {
//echo "called postResturl $url\n";
$ctx_options = ["http" => [
"ignore_errors" => true,
"method" => "POST",
"header" => $headers,
]];
if(!$follow_location) {
$ctx_options["http"]["follow_location"] = false;
}
if($method == "PUT") {
$ctx_options["http"]["method"] = "PUT";
}
if($content_type == "application/x-www-form-urlencoded") {
$ctx_options["http"]["content"] = http_build_query($content);
}
if($content_type == "application/json") {
$ctx_options["http"]["content"] = json_encode($content);
}
if($debug) {
var_dump($url, $ctx_options);
exit;
}
$ctx = stream_context_create($ctx_options);
$output = file_get_contents($url, false, $ctx);
//var_dump($http_response_header);
if(!$follow_location) {
return $output;
}
foreach($http_response_header as $h_line) {
$m = [];
$status_code_types = "245";
if(!$follow_location) {
$status_code_types = "2345";
}
if(preg_match('/HTTP\/\d+(?:\.\d+) ([245]\d+)/', $h_line, $m)) {
$response_code = $m[1];
if(substr($response_code, 0, 1) == "2") {
return $output;
} elseif(substr($response_code, 0, 1) == "3") {
return $output;
} elseif($response_code == "401") {
return "__err__401";
} else {
die("postRestUrl(): $h_line\n");
}
}
}
}
function guidv4($data = null) {
// Generate 16 bytes (128 bits) of random data or use the data passed into the function.
$data = $data ?? random_bytes(16);
assert(strlen($data) == 16);
// Set version to 0100
$data[6] = chr(ord($data[6]) & 0x0f | 0x40);
// Set bits 6-7 to 10
$data[8] = chr(ord($data[8]) & 0x3f | 0x80);
// Output the 36 character UUID.
return vsprintf('%s%s-%s-%s-%s-%s%s%s', str_split(bin2hex($data), 4));
}

View File

@@ -0,0 +1,47 @@
#!/usr/bin/php
<?php
require_once __DIR__."/include/config.php";
require_once __DIR__."/include/rest.php";
if(!$access_token) {
$access_token = fetchAccessToken($oauth_url, $client_id, $client_secret, $default_scope);
if(!$access_token) {
die("Error getting access token");
}
}
//echo $access_token."\n";exit;
$headers[] = "Accept: application/json";
$headers[] = "Authorization: Bearer $access_token";
$page = 1;
while(1) {
$output = getRestUrl($ep_list_oaids, $headers, ["tenant"=> $tenant, "_page" => $page]);
if($output == "__err__401") {
$access_token = fetchAccessToken($oauth_url, $client_id, $client_secret, $default_scope);
$headers = [];
$headers[] = "Accept: application/json";
$headers[] = "Authorization: Bearer $access_token";
$output = getRestUrl($ep_list_oaids, $headers, ["tenant"=> $tenant, "_page" => $page]);
}
$output_values = json_decode($output);
if(!is_array($output_values) || !count($output_values)) {
/*echo "Leeres oder kein Json Array:";
echo $output."\n";*/
break;
}
if($page == 1) {
echo "ol_openaccessid;orig_externalid;orig_name\n";
}
foreach($output_values as $oaid_obj) {
echo $oaid_obj->oaid.";";
echo $oaid_obj->external_id.";";
echo ";";
echo "\n";
}
$page++;
}

File diff suppressed because it is too large Load Diff