= 6 && $ver < 7) { $phpArr = array("PHP7.3", "PHP7.2","PHP7.0", "PHP5.6"); $phpStopped = ""; $phpVer = ""; configureWebStation(); $phpVer = fetchPHPVersion(); createConfFile($phpVer); } $ver = getSynoDSMVersion(); $wdir = "web" . (($ver >= 7)? '_packages' : ''); $htmlFile = "/var/services/$wdir/IDrive/index.html"; if(file_exists($htmlFile)) `rm $htmlFile`; function fetchPHPVersion() { GLOBAL $phpArr, $phpVer, $phpStopped; $installPHP = installPHP(); if($installPHP != "") { //echo "\n\n Installed PHP VERSION IS: ".$installPHP."\n"; return $installPHP; } } /********************************************************************************************************* * Subroutine Name : getSynoDSMVersion * Objective : Finds the Synology DSM version * Added By : Sabin Cheruvattil **********************************************************************************************************/ function getSynoDSMVersion() { $verarr = explode("\n", `cat /etc.defaults/VERSION`); array_walk($verarr, 'trim'); $kvp = preg_split('/=/', $verarr[0]); $ver = (int)trim($kvp[1], '"'); return $ver; } # function to start PHP function startPHP() { GLOBAL $phpStopped, $phpVer ; $commmand = "synopkg start ".$phpStopped; $result = `$commmand`; if(strstr($result,"start successfully")){ $phpVer = $phpStopped; return true; } return false; } # function to install PHP function installPHP() { GLOBAL $phpArr, $phpVer, $phpStopped ; foreach($phpArr as $php){ $commmand = "synopkg install_from_server ".$php; $result = trim(shell_exec($commmand)); if($result == "" || strstr($result,"already installed")) { $phpVer = $php; break; } } return $phpVer; } # function to install PHP function configureWebStation() { $webStationStatusCmd = "synopkg status WebStation"; $webStationStatusResult = `$webStationStatusCmd`; if(strstr($webStationStatusResult,"package is started")){ return true; }else if(strstr($webStationStatusResult,"package is stopped")){ $commmandToStart = "synopkg start WebStation"; $result = `$commmandToStart`; if(strstr($result,"start successfully")) return true; }else if(strstr($webStationStatusResult,"No such package")){ $commmandToInstall = "synopkg install_from_server WebStation"; $output = trim(shell_exec($commmandToInstall)); /*if($output == "" || strstr($output,"already installed")) { echo "Web station installed successfully"; }*/ } } # function to check which PHP Exist function checkPHPExistsOrNot() { GLOBAL $phpArr, $phpVer, $phpStopped ; foreach($phpArr as $php){ $commmand = "synopkg status ".$php; $result = `$commmand`; if(strstr($result,"package is started")){ $phpVer = $php; break; }else if(strstr($result,"package is stopped")){ $phpStopped = $php; break; } $phpVer = ""; } return $phpVer; } /**************************************************************************************************** * Function Name : createConfFile * Objective : This method is used to create link for IDrive conf and php fpm. * Added By : Anil Kumar ******************************************************************************************************/ function createConfFile($phpVer){ $val1 = strtolower($phpVer); $val2 = str_replace(".","",$val1); $confPath = "/var/packages/IDrive/target/nginx_conf"; $header = 'location ^~ /IDrive/ { fastcgi_read_timeout 3600; root /var/services/web; include /usr/syno/etc/packages/IDrive/nginx/*.conf; location ~ ^/IDrive/(.*)/\. { deny all; } location ~* \.(jpg|jpeg|png|gif|css|js|ico)$ { expires max; log_not_found off; } location ~ \.php$ { include fastcgi.conf; fastcgi_pass unix:/run/php-fpm/'; $footer = ' } location = /IDrive/doc/html/ { return 301 https://www.idrive.com/help/synology/default; } location ~ ^/IDrive/doc/html/.*\.html$ { rewrite ^/IDrive/doc/html/(.*) https://www.idrive.com/help/synology/default permanent; } } location = /IDrive { fastcgi_read_timeout 300; root /var/services/web; include /usr/syno/etc/packages/IDrive/nginx/*.conf; try_files $uri/ /IDrive/index.php$is_args$args; } '; $content = $header.$val2."-fpm.sock;".$footer; #Create conf file if (is_dir($confPath)) `rm -rf $confPath`; `mkdir $confPath`; `chmod 777 $confPath`; file_put_contents($confPath."/www.IDrive.enable.conf", $content); `chmod 644 "/var/packages/IDrive/target/nginx_conf/www.IDrive.enable.conf"`; `ln -sf "/var/packages/IDrive/target/nginx_conf/www.IDrive.enable.conf" "/usr/local/etc/nginx/conf.d/"`; $updatePkgDeps = "\n[WebStation]\ndsm_min_ver=6.0-0000\n[$phpVer]\ndsm_min_ver=6.0-0000\n"; $pkgDeps = "/var/packages/IDrive/conf/PKG_DEPS"; file_put_contents($pkgDeps, $updatePkgDeps); } ?>