@@ -857,13 +857,13 @@ function rename($filename, $new_filename, $allow_symlink = false) {
857857 return rename ($ filename , $ new_filename );
858858 }
859859
860- function mkdir ($ dirname , $ allow_symlink = false ) {
860+ function mkdir ($ dirname , $ allow_symlink = false , $ mode = 0777 , $ recursive = false ) {
861861 global $ app ;
862862 if ($ allow_symlink == false && $ this ->checkpath ($ dirname ) == false ) {
863863 $ app ->log ("Action aborted, file is a symlink: $ dirname " , LOGLEVEL_WARN );
864864 return false ;
865865 }
866- if (@mkdir ($ dirname )) {
866+ if (@mkdir ($ dirname, $ mode , $ recursive )) {
867867 return true ;
868868 } else {
869869 $ app ->log ("mkdir failed: $ dirname " , LOGLEVEL_DEBUG );
@@ -894,6 +894,35 @@ function touch($file, $allow_symlink = false){
894894 }
895895 }
896896
897+ public function create_relative_link ($ f , $ t ) {
898+ global $ app ;
899+
900+ // $from already exists
901+ $ from = realpath ($ f );
902+
903+ // realpath requires the traced file to exist - so, lets touch it first, then remove
904+ @$ app ->system ->unlink ($ t ); touch ($ t );
905+ $ to = realpath ($ t );
906+ @$ app ->system ->unlink ($ t );
907+
908+ // Remove from the left side matching path elements from $from and $to
909+ // and get path elements counts
910+ $ a1 = explode ('/ ' , $ from ); $ a2 = explode ('/ ' , $ to );
911+ for ($ c = 0 ; $ a1 [$ c ] == $ a2 [$ c ]; $ c ++) {
912+ unset($ a1 [$ c ]); unset($ a2 [$ c ]);
913+ }
914+ $ cfrom = implode ('/ ' , $ a1 );
915+
916+ // Check if a path is fully a subpath of another - no way to create symlink in the case
917+ if (count ($ a1 ) == 0 || count ($ a2 ) == 0 ) return false ;
918+
919+ // Add ($cnt_to-1) number of "../" elements to left side of $cfrom
920+ for ($ c = 0 ; $ c < (count ($ a2 )-1 ); $ c ++) { $ cfrom = '../ ' .$ cfrom ; }
921+ if (strstr ($ to ,'/etc/letsencrypt/archive/ ' )) $ to = str_replace ('/etc/letsencrypt/archive/ ' ,'/etc/letsencrypt/live/ ' ,$ to );
922+
923+ return symlink ($ cfrom , $ to );
924+ }
925+
897926 function checkpath ($ path ) {
898927 $ path = trim ($ path );
899928 //* We allow only absolute paths
@@ -1656,6 +1685,16 @@ function mkdirpath($path, $mode = 0755, $user = '', $group = '') {
16561685 }
16571686
16581687 }
1688+
1689+ function _exec ($ command ) {
1690+ global $ app ;
1691+ $ out = array ();
1692+ $ ret = 0 ;
1693+ $ app ->log ('exec: ' .$ command , LOGLEVEL_DEBUG );
1694+ exec ($ command , $ out , $ ret );
1695+ if ($ ret != 0 ) return false ;
1696+ else return true ;
1697+ }
16591698
16601699 //* Check if a application is installed
16611700 function is_installed ($ appname ) {
0 commit comments