@@ -61,7 +61,7 @@ public function mail($to, $subject, $text, $from, $filepath = '', $filetype = 'a
6161 if (is_string ($ to ) && strpos ($ to , ', ' ) !== false ) {
6262 $ to = preg_split ('/\s*,\s*/ ' , $ to );
6363 }
64-
64+
6565 $ app ->ispcmail ->send ($ to );
6666 $ app ->ispcmail ->finish ();
6767
@@ -234,7 +234,7 @@ public function suggest_ips($type = 'IPv4'){
234234 if (preg_match ($ regex , $ result ['ip ' ])) $ ips [] = $ result ['ip ' ];
235235 }
236236 }
237-
237+
238238 $ results = $ app ->db ->queryAllRecords ("SELECT remote_ips FROM web_database WHERE remote_ips != '' " );
239239 if (!empty ($ results ) && is_array ($ results )){
240240 foreach ($ results as $ result ){
@@ -290,6 +290,34 @@ public function formatBytes($size, $precision = 2) {
290290 return round (pow (1024 , $ base -floor ($ base )), $ precision ).$ suffixes [floor ($ base )];
291291 }
292292
293+
294+ /**
295+ * Normalize a path and strip duplicate slashes from it
296+ *
297+ * This will also remove all /../ from the path, reducing the preceding path elements
298+ *
299+ * @param string $path
300+ * @return string
301+ */
302+ public function normalize_path ($ path ) {
303+ $ path = preg_replace ('~[/]{2,}~ ' , '/ ' , $ path );
304+ $ parts = explode ('/ ' , $ path );
305+ $ return_parts = array ();
306+
307+ foreach ($ parts as $ current_part ) {
308+ if ($ current_part === '.. ' ) {
309+ if (!empty ($ return_parts ) && end ($ return_parts ) !== '' ) {
310+ array_pop ($ return_parts );
311+ }
312+ } else {
313+ $ return_parts [] = $ current_part ;
314+ }
315+ }
316+
317+ return implode ('/ ' , $ return_parts );
318+ }
319+
320+
293321 /** IDN converter wrapper.
294322 * all converter classes should be placed in ISPC_CLASS_PATH.'/idn/'
295323 */
@@ -370,42 +398,42 @@ public function idn_decode($domain) {
370398
371399 public function is_allowed_user ($ username , $ restrict_names = false ) {
372400 global $ app ;
373-
401+
374402 $ name_blacklist = array ('root ' ,'ispconfig ' ,'vmail ' ,'getmail ' );
375403 if (in_array ($ username ,$ name_blacklist )) return false ;
376-
404+
377405 if (preg_match ('/^[a-zA-Z0-9\.\-_]{1,32}$/ ' , $ username ) == false ) return false ;
378-
406+
379407 if ($ restrict_names == true && preg_match ('/^web\d+$/ ' , $ username ) == false ) return false ;
380-
408+
381409 return true ;
382410 }
383-
411+
384412 public function is_allowed_group ($ groupname , $ restrict_names = false ) {
385413 global $ app ;
386-
414+
387415 $ name_blacklist = array ('root ' ,'ispconfig ' ,'vmail ' ,'getmail ' );
388416 if (in_array ($ groupname ,$ name_blacklist )) return false ;
389-
417+
390418 if (preg_match ('/^[a-zA-Z0-9\.\-_]{1,32}$/ ' , $ groupname ) == false ) return false ;
391-
419+
392420 if ($ restrict_names == true && preg_match ('/^client\d+$/ ' , $ groupname ) == false ) return false ;
393-
421+
394422 return true ;
395423 }
396-
424+
397425 public function getimagesizefromstring ($ string ){
398426 if (!function_exists ('getimagesizefromstring ' )) {
399427 $ uri = 'data://application/octet-stream;base64, ' . base64_encode ($ string );
400428 return getimagesize ($ uri );
401429 } else {
402430 return getimagesizefromstring ($ string );
403- }
431+ }
404432 }
405-
433+
406434 public function password ($ minLength = 10 , $ special = false ){
407435 global $ app ;
408-
436+
409437 $ iteration = 0 ;
410438 $ password = "" ;
411439 $ maxLength = $ minLength + 5 ;
@@ -430,21 +458,21 @@ public function password($minLength = 10, $special = false){
430458 public function getRandomInt ($ min , $ max ){
431459 return floor ((mt_rand () / mt_getrandmax ()) * ($ max - $ min + 1 )) + $ min ;
432460 }
433-
461+
434462 public function generate_customer_no (){
435463 global $ app ;
436464 // generate customer no.
437465 $ customer_no = mt_rand (100000 , 999999 );
438466 while ($ app ->db ->queryOneRecord ("SELECT client_id FROM client WHERE customer_no = ? " , $ customer_no )) {
439467 $ customer_no = mt_rand (100000 , 999999 );
440468 }
441-
469+
442470 return $ customer_no ;
443471 }
444-
472+
445473 public function generate_ssh_key ($ client_id , $ username = '' ){
446474 global $ app ;
447-
475+
448476 // generate the SSH key pair for the client
449477 $ id_rsa_file = '/tmp/ ' .uniqid ('' ,true );
450478 $ id_rsa_pub_file = $ id_rsa_file .'.pub ' ;
@@ -458,7 +486,7 @@ public function generate_ssh_key($client_id, $username = ''){
458486 $ app ->log ("Failed to create SSH keypair for " .$ username , LOGLEVEL_WARN );
459487 }
460488 }
461-
489+
462490 public function htmlentities ($ value ) {
463491 global $ conf ;
464492
@@ -474,10 +502,10 @@ public function htmlentities($value) {
474502 } else {
475503 $ out = htmlentities ($ value , ENT_QUOTES , $ conf ["html_content_encoding " ]);
476504 }
477-
505+
478506 return $ out ;
479507 }
480-
508+
481509 // Function to check paths before we use it as include. Use with absolute paths only.
482510 public function check_include_path ($ path ) {
483511 if (strpos ($ path ,'// ' ) !== false ) die ('Include path seems to be an URL: ' .$ this ->htmlentities ($ path ));
@@ -488,18 +516,18 @@ public function check_include_path($path) {
488516 if (substr ($ path ,0 ,strlen (ISPC_ROOT_PATH )) != ISPC_ROOT_PATH ) die ('Path ' .$ this ->htmlentities ($ path ).' is outside of ISPConfig installation directory. ' );
489517 return $ path ;
490518 }
491-
519+
492520 // Function to check language strings
493521 public function check_language ($ language ) {
494522 global $ app ;
495523 if (preg_match ('/^[a-z]{2}$/ ' ,$ language )) {
496524 return $ language ;
497525 } else {
498526 $ app ->log ('Wrong language string: ' .$ this ->htmlentities ($ language ),1 );
499- return 'en ' ;
527+ return 'en ' ;
500528 }
501529 }
502-
530+
503531}
504532
505533?>
0 commit comments