Small refactoring
This commit is contained in:
10
tftpboot/index.cnf
Normal file
10
tftpboot/index.cnf
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
[main]
|
||||||
|
tftp = /tftpboot
|
||||||
|
;firmware = /tftpboot/firmware
|
||||||
|
;settings = /tftpboot/settings
|
||||||
|
;wallpapers = /tftpboot/wallpapers
|
||||||
|
;ringtones = /tftpboot/ringtones
|
||||||
|
;locales = /tftpboot/locales
|
||||||
|
;countries = /tftpboot/locales/countries
|
||||||
|
;languages = /tftpboot/locales/languages
|
||||||
|
;deflanguages = /tftpboot/locales/languages/English_United_States
|
@@ -3,30 +3,38 @@
|
|||||||
// Written by Alex / github.com/PhantomVI
|
// Written by Alex / github.com/PhantomVI
|
||||||
//
|
//
|
||||||
|
|
||||||
// Setup should be moved to ini/json file
|
//Setup should be moved to ini/json file
|
||||||
|
|
||||||
// -- tftpboot path
|
// -- tftpboot path
|
||||||
$path['tftp'] = '/tftpboot';
|
$path['debug'] = 'off';
|
||||||
|
|
||||||
|
$ini_array = parse_ini_file('index.cnf');
|
||||||
|
if (!empty($ini_array)) {
|
||||||
|
foreach ($ini_array as $key => $value) {
|
||||||
|
$path[$key] = $value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (empty($path['tftp'])) $path['tftp'] = '/tftpboot';
|
||||||
|
|
||||||
$request = $_REQUEST;
|
$request = $_REQUEST;
|
||||||
$req_file = !empty($request['id']) ? $request['id'] : '';
|
$req_file = !empty($request['id']) ? $request['id'] : '';
|
||||||
|
|
||||||
// -- TFTPD - structure
|
// -- TFTPD - structure
|
||||||
$path['firmware'] = $path['tftp']. '/firmware';
|
|
||||||
$fw_suffix = array('bin', 'loads', 'sbn', 'sb2', 'sbin', 'zz', 'zup');
|
$fw_suffix = array('bin', 'loads', 'sbn', 'sb2', 'sbin', 'zz', 'zup');
|
||||||
|
|
||||||
$path['settings'] = $path['tftp']. '/settings';
|
|
||||||
//$settings_suffix = array('cnf.xml');
|
//$settings_suffix = array('cnf.xml');
|
||||||
|
|
||||||
$path['wallpapers'] = $path['tftp']. '/wallpapers';
|
|
||||||
|
|
||||||
$path['ringtones'] = $path['tftp']. '/ringtones';
|
|
||||||
$ringtones_list = array('distinctive.xml', 'distinctive.sgn', 'ringlist.xml', 'ringlist.sgn');
|
$ringtones_list = array('distinctive.xml', 'distinctive.sgn', 'ringlist.xml', 'ringlist.sgn');
|
||||||
|
|
||||||
$path['locales'] = $path['tftp']. '/locales';
|
if (empty($path['firmware'])) $path['firmware'] = $path['tftp']. '/firmware';
|
||||||
$path['countries'] = $path['tftp']. '/locales/countries';
|
if (empty($path['settings'])) $path['settings'] = $path['tftp']. '/settings';
|
||||||
$path['languages'] = $path['tftp']. '/locales/languages';
|
if (empty($path['wallpapers'])) $path['wallpapers'] = $path['tftp']. '/wallpapers';
|
||||||
$locale_list = array('-dictionary.', 'dictionary-ext.', '-dictionary.utf-8.', '-kate.xml', '-font.xml', '-tones.xml',
|
if (empty($path['ringtones'])) $path['ringtones'] = $path['tftp']. '/ringtones';
|
||||||
|
if (empty($path['locales'])) $path['locales'] = $path['tftp']. '/locales';
|
||||||
|
if (empty($path['countries'])) $path['countries'] = $path['tftp']. '/locales/countries';
|
||||||
|
if (empty($path['languages'])) $path['languages'] = $path['tftp']. '/locales/languages';
|
||||||
|
if (empty($path['deflanguages'])) $path['deflanguages'] = $path['languages']. '/English_United_States';
|
||||||
|
$locale_list = array('-dictionary.', 'dictionary-ext.', '-dictionary.utf-8.', '-kate.xml', '-font.xml', '-font.dat','-tones.xml',
|
||||||
'be-sccp.jar', 'tc-sccp.jar', 'td-sccp.jar', 'ipc-sccp.jar', 'mk-sccp.jar', '_locale.loads', 'i-button-help.xml');
|
'be-sccp.jar', 'tc-sccp.jar', 'td-sccp.jar', 'ipc-sccp.jar', 'mk-sccp.jar', '_locale.loads', 'i-button-help.xml');
|
||||||
|
|
||||||
|
|
||||||
@@ -35,45 +43,54 @@ $req_file_full_path = '' ;
|
|||||||
if (!empty($req_file)) {
|
if (!empty($req_file)) {
|
||||||
$signed = FALSE;
|
$signed = FALSE;
|
||||||
$req_data_ar = explode('/', $req_file);
|
$req_data_ar = explode('/', $req_file);
|
||||||
|
$req_data_len = count($req_data_ar) - 1;
|
||||||
|
|
||||||
$orig_req_file_name = end($req_data_ar);
|
$orig_req_file_name = end($req_data_ar);
|
||||||
$req_file_name = $orig_req_file_name;
|
$req_file_name = $orig_req_file_name;
|
||||||
$req_data_len = count($req_data_ar) - 1;
|
|
||||||
|
if (strpos('.sgn;', strtolower($orig_req_file_name).';') !== FALSE) { // handle signed files
|
||||||
|
$signed = TRUE;
|
||||||
|
$req_file_name = basename($orig_req_file_name, '.sgn'); // strip signed part
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if (file_exists($path['tftp'].$req_file_name)) // prevent "/../...//" browsing - (eliminate back door)
|
if (file_exists($path['tftp'].'/'.$orig_req_file_name)) // prevent "/../...//" browsing - (eliminate back door)
|
||||||
{
|
{
|
||||||
$req_file_full_path = $path['tftp'].$req_file_name;
|
$req_file_full_path = $path['tftp'].'/'.$req_file_name;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$tmp_file = explode('.', $req_file_name);
|
$tmp_file = explode('.', $req_file_name);
|
||||||
$tmp = end($tmp_file);
|
|
||||||
if (strpos(".sgn;", '.'.strtolower($tmp).';') !== FALSE) { // handle signed files
|
if (strpos_array($req_file_name, $fw_suffix,'any') !== FALSE) { // Firmware file was requested
|
||||||
$signed = TRUE;
|
|
||||||
$req_file_name = basename($req_file_name, ".sgn"); // strip signed part
|
|
||||||
}
|
|
||||||
|
|
||||||
if (strpos_array($fw_suffix, $req_file_name, 'any') !== FALSE) { // Firmware file was requested
|
|
||||||
$firmware_list = find_all_files($path['firmware']);
|
$firmware_list = find_all_files($path['firmware']);
|
||||||
$pos2 = strpos_array($firmware_list, $req_file_name, 'any'); // case unsensitive
|
$pos2 = strpos_array($firmware_list, $req_file_name, 'any'); // case unsensitive
|
||||||
if ($pos2 !== FALSE) { // Request Firmware
|
if ($pos2 !== FALSE) { // Request Firmware
|
||||||
$req_file_full_path = $firmware_list[$pos2];
|
$req_file_full_path = $firmware_list[$pos2];
|
||||||
}
|
}
|
||||||
print_r('<br>Requested Firmware:'. $req_file_full_path. '<br>');
|
if ($path['debug'] == 'on') print_r('<br>Requested Firmware: '. $req_file_full_path. '<br>');
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$tmp_file = '';
|
$tmp_file = '';
|
||||||
|
|
||||||
//if (strpos_array($settings_suffix, $req_file_name, 'any') !== FALSE) { // Request Settings
|
//if (strpos_array($req_file_name, $settings_suffix, 'any') !== FALSE) { // Request Settings
|
||||||
if (strpos(strtolower($req_file_name), '.cnf.xml') !== FALSE) { // Request Settings
|
if (strpos(strtolower($req_file_name), '.cnf.xml') !== FALSE) { // Request Settings
|
||||||
$tmp_file = $path['settings'].'/'.$req_file_name;
|
$tmp_file = $path['settings'].'/'.$req_file_name;
|
||||||
}
|
}
|
||||||
else if (strpos(strtolower($req_file), '/desktops/') !== FALSE) { // Request Wallpapers
|
else if (strpos(strtolower($req_file), '/desktops/') !== FALSE) { // Request Wallpapers
|
||||||
$tmp_file = $path['wallpapers'].'/'. $req_data_ar[$req_data_len-1].'/'. $req_data_ar[$req_data_len];
|
$tmp_file = $path['wallpapers'].'/'. $req_data_ar[$req_data_len-1].'/'. $req_file_name;
|
||||||
}
|
}
|
||||||
else if (strpos_array($ringtones_list, $req_file_name, 'any') !== FALSE) { // Request RingTones
|
else if (strpos_array($ringtones_list, $req_file_name, 'any') !== FALSE) { // Request RingTones
|
||||||
$tmp_file = $path['ringtones'].'/ringlist.xml';
|
$tmp_file = $path['ringtones'].'/ringlist.xml';
|
||||||
}
|
}
|
||||||
|
else if (strpos_array($req_file, $locale_list, 'any') !== FALSE) { // Request Languages
|
||||||
|
if (!empty($req_data_ar[$req_data_len-1])) {
|
||||||
|
$tmp_file = $path['languages'].'/'. $req_data_ar[$req_data_len-1].'/'. $req_file_name;
|
||||||
|
} else {
|
||||||
|
$tmp_file = $path['deflanguages'].'/'. $req_file_name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
else if (strpos(strtolower($req_file), '-tones.xml') !== FALSE) { // Request Countries
|
else if (strpos(strtolower($req_file), '-tones.xml') !== FALSE) { // Request Countries
|
||||||
@@ -92,10 +109,8 @@ if (!empty($req_file)) {
|
|||||||
$tmp_file = $path['languages'].'/'. $req_data_ar[$req_data_len-1].'/'. $req_data_ar[$req_data_len];
|
$tmp_file = $path['languages'].'/'. $req_data_ar[$req_data_len-1].'/'. $req_data_ar[$req_data_len];
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
else if (strpos_array($req_file, $locale_list, 'any') !== FALSE) { // Request Languages
|
if ($path['debug'] == 'on') print_r('<br>File : '. $req_file_name. ' not found.<br>');
|
||||||
$tmp_file = $path['languages'].'/'. $req_data_ar[$req_data_len-1].'/'. $req_data_ar[$req_data_len];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (empty($tmp_file)) {
|
if (empty($tmp_file)) {
|
||||||
die('ERROR: no match found.');
|
die('ERROR: no match found.');
|
||||||
}
|
}
|
||||||
@@ -104,15 +119,15 @@ if (!empty($req_file)) {
|
|||||||
}
|
}
|
||||||
if (!empty($req_file_full_path)) {
|
if (!empty($req_file_full_path)) {
|
||||||
if ($signed) {
|
if ($signed) {
|
||||||
$req_file_full_path = $req_file_full_path . '.sgn';
|
$req_file_full_path .= '.sgn';
|
||||||
}
|
}
|
||||||
if (!file_exists($req_file_full_path)) {
|
if (!file_exists($req_file_full_path)) {
|
||||||
die('Could not find:'. $req_file_full_path);
|
die('Could not find:'. $req_file_full_path);
|
||||||
}
|
}
|
||||||
print_r('<br>Returning:'. $req_file_full_path. '<br>');
|
if ($path['debug'] == 'on') print_r('<br>Returning: '. $req_file_full_path. '<br>');
|
||||||
file_force_download($req_file_full_path);
|
file_force_download($req_file_full_path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Helper functiosn
|
* Helper functiosn
|
||||||
@@ -143,8 +158,11 @@ function file_force_download($file) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Founds any string from array in array
|
||||||
|
*/
|
||||||
function strpos_array($haystack, $needles, $mode='any') {
|
function strpos_array($haystack, $needles, $mode='any') {
|
||||||
if (is_array($needles)) { // Handle multiple needles via recursive call
|
if (is_array($needles)) {
|
||||||
foreach ($needles as $str) {
|
foreach ($needles as $str) {
|
||||||
$pos = strpos_array($haystack, $str, $mode);
|
$pos = strpos_array($haystack, $str, $mode);
|
||||||
if ($pos !== FALSE) {
|
if ($pos !== FALSE) {
|
||||||
@@ -152,16 +170,29 @@ function strpos_array($haystack, $needles, $mode='any') {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (is_array($haystack) && ($mode == 'any')) {
|
if (is_array($haystack)) {
|
||||||
foreach ($haystack as $key => $substr) {
|
foreach ($haystack as $key => $subtr) {
|
||||||
$pos = strpos(strtolower($substr), strtolower($needles));
|
$pos = strpos_array($subtr, $needles, $mode);
|
||||||
if ($pos !== FALSE) {
|
if ($pos !== FALSE) {
|
||||||
return $key;
|
return $key;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return FALSE;
|
return FALSE;
|
||||||
} else {
|
} else {
|
||||||
return strpos($haystack, $needles);
|
if ($mode == 'any') {
|
||||||
|
return strpos(strtolower($haystack), strtolower($needles));
|
||||||
|
} else {
|
||||||
|
if ($mode == 'full') {
|
||||||
|
if ($haystack == $needles) {
|
||||||
|
return 0;
|
||||||
|
} else {
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return strpos($haystack, $needles);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
Reference in New Issue
Block a user