From a1de03c4c40eb38cfa1f01fcdf88b3048ff23105 Mon Sep 17 00:00:00 2001 From: Marcel Date: Sun, 23 Oct 2016 12:16:47 +0200 Subject: [PATCH 1/5] Add experimentelle Funktion zum Firmware download auf remote servern --- ffrouter_parsen.function.php | 293 ++++++++++++++++++++++++----------- 1 file changed, 204 insertions(+), 89 deletions(-) diff --git a/ffrouter_parsen.function.php b/ffrouter_parsen.function.php index 22ab452..e1e57cf 100644 --- a/ffrouter_parsen.function.php +++ b/ffrouter_parsen.function.php @@ -4,106 +4,221 @@ * @copyright 2016 Caspar Armster, Freifunk Hennef/Freie Netzwerker e.V. (www.freifunk-hennef.de / www.freie-netzwerker.de) * @license Licensed under GPLv3 */ -if(!is_dir($firmware_download_path)) { - throw new Exception("Firmwareverzeichnis existiert nicht!"); -} -$err = 0; -for( $i=0; $ihersteller, $router_tmp[$x]['hersteller']) == 0) && (strcasecmp($router[$z]->modell, $router_tmp[$x]['modell']) == 0) && (strcasecmp($router[$z]->version, $router_tmp[$x]['version']) == 0)) { - $entinst = $entwicklung[$i].$installation[$j]; - $entinstlink = $entwicklung[$i].$installation[$j]."link"; - $router[$z]->$entinst = 1; - $router[$z]->$entinstlink = $firmware_download_path.$entwicklung[$i]."/".$installation[$j]."/".$files[$entwicklung[$i]][$installation[$j]][$x]; - $router_neu = 0; - break; + } else { + $pos = stripos($files[$entwicklung[$i]][$installation[$j]][$x], 'manifest'); + if($pos !== false) { + array_splice($files[$entwicklung[$i]][$installation[$j]], $x, 1); + $x--; } } } - if($router_neu == 1) { - $z = count($router); - $router[$z] = new ffrouter(); - $router[$z]->hersteller = $router_tmp[$x]['hersteller']; - $router[$z]->version = $router_tmp[$x]['version']; - $router[$z]->modell = $router_tmp[$x]['modell']; - $entinst = $entwicklung[$i].$installation[$j]; - $entinstlink = $entwicklung[$i].$installation[$j]."link"; - $router[$z]->$entinst = 1; - $router[$z]->$entinstlink = $firmware_download_path.$entwicklung[$i]."/".$installation[$j]."/".$files[$entwicklung[$i]][$installation[$j]][$x]; + } + } + } + } + for( $i=0; $ihersteller, $router_tmp[$x]['hersteller']) == 0) && (strcasecmp($router[$z]->modell, $router_tmp[$x]['modell']) == 0) && (strcasecmp($router[$z]->version, $router_tmp[$x]['version']) == 0)) { + $entinst = $entwicklung[$i].$installation[$j]; + $entinstlink = $entwicklung[$i].$installation[$j]."link"; + $router[$z]->$entinst = 1; + $router[$z]->$entinstlink = $firmware_download_path.$entwicklung[$i]."/".$installation[$j]."/".$files[$entwicklung[$i]][$installation[$j]][$x]; + $router_neu = 0; + break; + } + } + } + if($router_neu == 1) { + $z = count($router); + $router[$z] = new ffrouter(); + $router[$z]->hersteller = $router_tmp[$x]['hersteller']; + $router[$z]->version = $router_tmp[$x]['version']; + $router[$z]->modell = $router_tmp[$x]['modell']; + $entinst = $entwicklung[$i].$installation[$j]; + $entinstlink = $entwicklung[$i].$installation[$j]."link"; + $router[$z]->$entinst = 1; + $router[$z]->$entinstlink = $firmware_download_path.$entwicklung[$i]."/".$installation[$j]."/".$files[$entwicklung[$i]][$installation[$j]][$x]; + } + } + } + } + $router_tmp = array(); + } + } +}else{ + //Check if URL is reachable + if (!@fopen($firmware_download_path,"r")) { + throw new Exception("Firmwareverzeichnis offline oder nicht existent!"); + } + + //Check if URL has index file (refer to https://forums.phpfreaks.com/topic/112764-using-scandir-on-other-websites/?p=579166 <- scandir has problem with index files) + if ((@fopen($firmware_download_path."/index.htm","r"))||(@fopen($firmware_download_path."/index.html","r"))||(@fopen($firmware_download_path."/index.php","r"))) { + throw new Exception("Firmwareverzeichnis darf keine index files besitzen!"); + } + + $err = 0; + for( $i=0; $ihersteller, $router_tmp[$x]['hersteller']) == 0) && (strcasecmp($router[$z]->modell, $router_tmp[$x]['modell']) == 0) && (strcasecmp($router[$z]->version, $router_tmp[$x]['version']) == 0)) { + $entinst = $entwicklung[$i].$installation[$j]; + $entinstlink = $entwicklung[$i].$installation[$j]."link"; + $router[$z]->$entinst = 1; + $router[$z]->$entinstlink = $firmware_download_path.$entwicklung[$i]."/".$installation[$j]."/".$files[$entwicklung[$i]][$installation[$j]][$x]; + $router_neu = 0; + break; + } + } + } + if($router_neu == 1) { + $z = count($router); + $router[$z] = new ffrouter(); + $router[$z]->hersteller = $router_tmp[$x]['hersteller']; + $router[$z]->version = $router_tmp[$x]['version']; + $router[$z]->modell = $router_tmp[$x]['modell']; + $entinst = $entwicklung[$i].$installation[$j]; + $entinstlink = $entwicklung[$i].$installation[$j]."link"; + $router[$z]->$entinst = 1; + $router[$z]->$entinstlink = $firmware_download_path.$entwicklung[$i]."/".$installation[$j]."/".$files[$entwicklung[$i]][$installation[$j]][$x]; + } + } + } + } + $router_tmp = array(); + } } } + for( $i=0; $ihersteller))) { if(is_file(strtolower("router_images/".$router[$i]->hersteller."/".$router[$i]->modell."-".$router[$i]->version.".jpg"))) { From 36744ee505dac6cb88cf1dbed5d3c36a95046353 Mon Sep 17 00:00:00 2001 From: Marcel Date: Sun, 23 Oct 2016 16:29:50 +0200 Subject: [PATCH 2/5] It Works! --- ffrouter_parsen.function.php | 49 ++++++++++++++++++++++++++++-------- 1 file changed, 39 insertions(+), 10 deletions(-) diff --git a/ffrouter_parsen.function.php b/ffrouter_parsen.function.php index e1e57cf..7ebb863 100644 --- a/ffrouter_parsen.function.php +++ b/ffrouter_parsen.function.php @@ -4,6 +4,31 @@ * @copyright 2016 Caspar Armster, Freifunk Hennef/Freie Netzwerker e.V. (www.freifunk-hennef.de / www.freie-netzwerker.de) * @license Licensed under GPLv3 */ +function remoteFileExists($url) { + $curl = curl_init($url); + + //don't fetch the actual page, you only want to check the connection is ok + curl_setopt($curl, CURLOPT_NOBODY, true); + + //do request + $result = curl_exec($curl); + + $ret = false; + + //if request did not fail + if ($result !== false) { + //if request was ok, check response code + $statusCode = curl_getinfo($curl, CURLINFO_HTTP_CODE); + + if ($statusCode == 200) { + $ret = true; + } + } + + curl_close($curl); + + return $ret; +} if (filter_var($community[$community_id]["download_path"], FILTER_VALIDATE_URL) === FALSE) { if(!is_dir($firmware_download_path)) { throw new Exception("Firmwareverzeichnis existiert nicht!"); @@ -107,35 +132,39 @@ if (filter_var($community[$community_id]["download_path"], FILTER_VALIDATE_URL) } }else{ //Check if URL is reachable - if (!@fopen($firmware_download_path,"r")) { + if (!remoteFileExists($firmware_download_path)) { throw new Exception("Firmwareverzeichnis offline oder nicht existent!"); } //Check if URL has index file (refer to https://forums.phpfreaks.com/topic/112764-using-scandir-on-other-websites/?p=579166 <- scandir has problem with index files) - if ((@fopen($firmware_download_path."/index.htm","r"))||(@fopen($firmware_download_path."/index.html","r"))||(@fopen($firmware_download_path."/index.php","r"))) { + if ((@remoteFileExists($firmware_download_path."/index.htm"))||(@remoteFileExists($firmware_download_path."/index.html"))||(@remoteFileExists($firmware_download_path."/index.php"))) { throw new Exception("Firmwareverzeichnis darf keine index files besitzen!"); } - + $err = 0; for( $i=0; $i]+)/', file_get_contents($firmware_download_path.$entwicklung[$i]."/".$installation[$j]."/"), $files_in_HTTP); + foreach($files_in_HTTP["0"] as $key=>$value){ + $files_in_HTTP["0"][$key]=substr($value, 6); + } + $files[$entwicklung[$i]][$installation[$j]] = array_slice($files_in_HTTP["0"], 1); for( $x=0; $x Date: Sun, 23 Oct 2016 20:30:19 +0200 Subject: [PATCH 3/5] Fix Models and optimize Speed --- ffrouter_parsen.function.php | 92 ++++++++++++++++++------------------ 1 file changed, 45 insertions(+), 47 deletions(-) diff --git a/ffrouter_parsen.function.php b/ffrouter_parsen.function.php index 7ebb863..7029d7c 100644 --- a/ffrouter_parsen.function.php +++ b/ffrouter_parsen.function.php @@ -29,18 +29,22 @@ function remoteFileExists($url) { return $ret; } + if (filter_var($community[$community_id]["download_path"], FILTER_VALIDATE_URL) === FALSE) { if(!is_dir($firmware_download_path)) { throw new Exception("Firmwareverzeichnis existiert nicht!"); } $err = 0; - for( $i=0; $ihersteller, $router_tmp[$x]['hersteller']) == 0) && (strcasecmp($router[$z]->modell, $router_tmp[$x]['modell']) == 0) && (strcasecmp($router[$z]->version, $router_tmp[$x]['version']) == 0)) { $entinst = $entwicklung[$i].$installation[$j]; @@ -136,44 +142,33 @@ if (filter_var($community[$community_id]["download_path"], FILTER_VALIDATE_URL) throw new Exception("Firmwareverzeichnis offline oder nicht existent!"); } - //Check if URL has index file (refer to https://forums.phpfreaks.com/topic/112764-using-scandir-on-other-websites/?p=579166 <- scandir has problem with index files) - if ((@remoteFileExists($firmware_download_path."/index.htm"))||(@remoteFileExists($firmware_download_path."/index.html"))||(@remoteFileExists($firmware_download_path."/index.php"))) { - throw new Exception("Firmwareverzeichnis darf keine index files besitzen!"); - } - $err = 0; - for( $i=0; $i]+)/', file_get_contents($firmware_download_path.$entwicklung[$i]."/".$installation[$j]."/"), $files_in_HTTP); - foreach($files_in_HTTP["0"] as $key=>$value){ - $files_in_HTTP["0"][$key]=substr($value, 6); - } - $files[$entwicklung[$i]][$installation[$j]] = array_slice($files_in_HTTP["0"], 1); - for( $x=0; $x]+)/', file_get_contents($firmware_download_path.$entwicklung[$i]."/".$installation[$j]."/"), $files_in_HTTP); + foreach($files_in_HTTP["0"] as $key=>$value){ + if (strpos($value, 'manifest') !== false) { + unset($files_in_HTTP["0"][$key]); } } + foreach($files_in_HTTP["0"] as $key=>$value){ + $files_in_HTTP["0"][$key]=substr($value, 6); + } + $files[$entwicklung[$i]][$installation[$j]] = array_slice($files_in_HTTP["0"], 1); } } } - for( $i=0; $ihersteller, $router_tmp[$x]['hersteller']) == 0) && (strcasecmp($router[$z]->modell, $router_tmp[$x]['modell']) == 0) && (strcasecmp($router[$z]->version, $router_tmp[$x]['version']) == 0)) { $entinst = $entwicklung[$i].$installation[$j]; @@ -247,8 +245,8 @@ if (filter_var($community[$community_id]["download_path"], FILTER_VALIDATE_URL) } } } - -for( $i=0; $ihersteller))) { if(is_file(strtolower("router_images/".$router[$i]->hersteller."/".$router[$i]->modell."-".$router[$i]->version.".jpg"))) { $router[$i]->imagefront = strtolower("router_images/".$router[$i]->hersteller."/".$router[$i]->modell."-".$router[$i]->version.".jpg"); From f78270511403cd3b45802d77663222a37fdab410 Mon Sep 17 00:00:00 2001 From: Marcel Date: Sun, 23 Oct 2016 20:37:58 +0200 Subject: [PATCH 4/5] Fix Syntax error --- ffrouter_parsen.function.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ffrouter_parsen.function.php b/ffrouter_parsen.function.php index 7029d7c..97fb36a 100644 --- a/ffrouter_parsen.function.php +++ b/ffrouter_parsen.function.php @@ -44,7 +44,7 @@ if (filter_var($community[$community_id]["download_path"], FILTER_VALIDATE_URL) $variante[$entwicklung[$i]][$installation[$j]] = 1; $files[$entwicklung[$i]][$installation[$j]] = array_slice(scandir($firmware_download_path.$entwicklung[$i]."/".$installation[$j]."/"), 2); $file_count = count($files[$entwicklung[$i]][$installation[$j]]); - for( $x=0; $x<$file_count); $x++ ) { + for( $x=0; $x<$file_count; $x++ ) { if(is_dir($firmware_download_path.$entwicklung[$i]."/".$installation[$j]."/".$files[$entwicklung[$i]][$installation[$j]][$x])) { array_splice($files[$entwicklung[$i]][$installation[$j]], $x, 1); $x--; @@ -81,7 +81,7 @@ if (filter_var($community[$community_id]["download_path"], FILTER_VALIDATE_URL) for( $j=0; $j<$installation_count; $j++ ) { if($variante[$entwicklung[$i]][$installation[$j]] == 1) { $file_count = count($files[$entwicklung[$i]][$installation[$j]]); - for( $x=0; $x<$file_count); $x++) { + for( $x=0; $x<$file_count; $x++) { for( $y=0; $y<$anzahl_hersteller; $y++) { if($pos = stripos($files[$entwicklung[$i]][$installation[$j]][$x], $hersteller[$y]['filename'], $pos_hersteller[$entwicklung[$i]][$installation[$j]]-1) !== false) { $router_tmp[$x]['hersteller'] = $hersteller[$y]['name']; From 03e6b6e878f1a06d245f9e08ac0cefbc5e7e95f0 Mon Sep 17 00:00:00 2001 From: Marcel Date: Sun, 23 Oct 2016 20:40:40 +0200 Subject: [PATCH 5/5] Fix Var Bug --- ffrouter_parsen.function.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ffrouter_parsen.function.php b/ffrouter_parsen.function.php index 97fb36a..605f20d 100644 --- a/ffrouter_parsen.function.php +++ b/ffrouter_parsen.function.php @@ -188,7 +188,7 @@ if (filter_var($community[$community_id]["download_path"], FILTER_VALIDATE_URL) for( $j=0; $j<$installation_count; $j++ ) { if($variante[$entwicklung[$i]][$installation[$j]] == 1) { $file_count = count($files[$entwicklung[$i]][$installation[$j]]); - for( $x=0; $x<$some_count; $x++) { + for( $x=0; $x<$file_count; $x++) { $anzahl_hersteller = count($hersteller); for( $y=0; $y<$anzahl_hersteller; $y++) { if($pos = stripos($files[$entwicklung[$i]][$installation[$j]][$x], $hersteller[$y]['filename'], $pos_hersteller[$entwicklung[$i]][$installation[$j]]-1) !== false) {