Example #1
0
/**
 * Repair problems in a Typeframe installation.
 * This command will configure BaseModel schemas and fix writeable directory
 * permissions.
 */
function fixPermissions($dir)
{
    static $ftp = null;
    static $depth = 0;
    $depth++;
    if (is_null($ftp)) {
        $ftp = new Typeframe_File();
    }
    if (!file_exists(TYPEF_DIR . '/files' . $dir)) {
        $ftp->mkdir('/files' . $dir);
    }
    if (substr(sprintf('%o', fileperms(TYPEF_DIR . '/files/' . $dir)), -4) !== '0777') {
        $ftp->chmod(0777, '/files' . $dir);
    }
    $dh = opendir(TYPEF_DIR . '/files' . $dir);
    while (($file = readdir($dh)) !== false) {
        if (substr($file, 0, 1) != '.') {
            if (is_dir(TYPEF_DIR . '/files' . $dir . '/' . $file)) {
                fixPermissions($dir . '/' . $file);
            } else {
                $perm = substr(decoct(fileperms(TYPEF_DIR . '/files/' . $dir . '/' . $file)), 1);
                if ($perm !== '0666' && $perm !== '0777') {
                    $ftp->chmod(0666, '/files/' . $dir . '/' . $file);
                }
            }
        }
    }
    $depth--;
    if ($depth == 0) {
        $ftp->close();
        $ftp = null;
    }
}
Example #2
0
 static function getRunInstallerForm()
 {
     global $controller;
     if (isset($_POST['startinstall']) && $_POST['startinstall'] == 'true') {
         //runtime_csfr::Protect();
         // set base vars
         $start = $_POST['startinstall'];
         $zipfile = $_POST['pkgzip'];
         $pkgInstall = $_POST['pkg'];
         $pkgdb = $_POST['pkgdb'];
         if ($start) {
             if (!isset($_POST['submit'])) {
                 if (isset($_SESSION['zpuid'])) {
                     $userid = $_SESSION['zpuid'];
                     $currentuser = ctrl_users::GetUserDetail($userid);
                     $hostdatadir = ctrl_options::GetOption('hosted_dir') . "" . $currentuser['username'];
                     $userName = $currentuser['username'];
                     $random = rand();
                     $sysOS = php_uname('s');
                     $line = "<h2>Preparing to install " . $pkgInstall . ":</h2>";
                     if (!isset($startinstall)) {
                         if ($pkgdb == "yes") {
                             $line .= "<font color=\"red\"><strong>This package requires a database and database user.</strong></font><br />";
                             $line .= "<a target=\"_blank\" href=\"../../../?module=mysql_databases\">&raquo;Open&laquo; </a> database manager.<br />";
                             $line .= "<a target=\"_blank\" href=\"../../../?module=mysql_users\">&raquo;Open&laquo; </a> database user manager.";
                             $line .= "<p>&nbsp;</p>";
                         }
                         $line .= "<p>Please provide the domain and folder name to start the installation of " . $pkgInstall . ".</p>";
                         $line .= "<form id=\"form\" name=\"doInstall\" action=\"/?module=sentastico\" method=\"post\">";
                         $line .= "<table>\n\t\t\t\t\t\t\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t\t\t\t\t\t\t<td align=\"right\">\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t<label for=\"site_domain\">Select domain: </label>\n\t\t\t\t\t\t\t\t\t\t\t\t\t</td>";
                         $line .= "<td align=\"center\">";
                         $list = ListDomain($currentuser['userid']);
                         $line .= $list;
                         $line .= "</td>\n\t\t\t\t\t\t\t\t\t\t\t\t\t<td>&nbsp;</td>\n\t\t\t\t\t\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t\t\t\t\t\t\t<td align=\"right\">\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t<label for=\"install_to_base_dir\">Tick&nbsp;to&nbsp;install to&nbsp;domain&nbsp;root:</label>\n\t\t\t\t\t\t\t\t\t\t\t\t\t</td>\n\t\t\t\t\t\t\t\t\t\t\t\t\t<td align=\"center\">\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t<input type=\"hidden\" name=\"install_to_base_dir\" value=\"0\" />\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t<input type=\"checkbox\" onClick=\"if (this.checked) { document.getElementById('hiderow').style.display = 'none'; } else { document.getElementById('hiderow').style.display = ''; }\" name=\"install_to_base_dir\" value=\"1\" />\n\t\t\t\t\t\t\t\t\t\t\t\t\t</td>\n\t\t\t\t\t\t\t\t\t\t\t\t\t<td>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t<font size=\"-1\" color=\"red\"><strong>ALL FILES AND FOLDERS WILL BE DELETED!</strong></font>\n\t\t\t\t\t\t\t\t\t\t\t\t\t</td>\n\t\t\t\t\t\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t\t\t\t\t\t\t<tr id=\"hiderow\">\n\t\t\t\t\t\t\t\t\t\t\t\t\t<td align=\"right\">\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t<label for=\"dir_to_install\">Install To Sub-Folder: public_html/[domain]/</label>\n\t\t\t\t\t\t\t\t\t\t\t\t\t</td>\n\t\t\t\t\t\t\t\t\t\t\t\t\t<td>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<input type=\"text\" name=\"dir_to_install\" style=\"width: 300px\"/>\n\t\t\t\t\t\t\t\t\t\t\t\t\t</td>\n\t\t\t\t\t\t\t\t\t\t\t\t\t<td>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<font color=\"red\">NOTE:</font> For multiple subfolders use: subfolder/subsubfolder\n\t\t\t\t\t\t\t\t\t\t\t\t\t</td>\n\t\t\t\t\t\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t\t\t\t\t\t\t<td colspan=\"3\">\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t<p>&nbsp;</p>\n\t\t\t\t\t\t\t\t\t\t\t\t\t</td>\n\t\t\t\t\t\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t\t\t\t\t\t\t<td colspan=\"2\" class=\"button-align\">\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t<!-- inputs -->\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t<input type=\"hidden\" name=\"startinstall\" value=\"true\"> \n\t\t\t\t\t\t\t\t\t\t\t\t\t\t<input type=\"hidden\" name=\"u\" value=" . $currentuser['userid'] . "> \n\t\t\t\t\t\t\t\t\t\t\t\t\t\t<input type=\"hidden\" name=\"pkgzip\" value=" . $zipfile . "> \n\t\t\t\t\t\t\t\t\t\t\t\t\t\t<input type=\"hidden\" name=\"pkg\" value='" . $pkgInstall . "'> \n\t\t\t\t\t\t\t\t\t\t\t\t\t\t<input type=\"hidden\" name=\"pkgdb\" value=" . $_POST['pkgdb'] . ">\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t<button class=\"btn btn-danger btn-small\" type=\"submit\" name=\"submit\" value=\"Install\" onclick=\"\$('#loading').show();\">Install</button>&nbsp;&nbsp;\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t<button class=\"btn btn-danger btn-small\" type=\"button\" name=\"cancel\" value=\"Cancel\" onClick=\"javascript:location.href='?module=sentastico'\">Cancel</button>\n\t\t\t\t\t\t\t\t\t\t\t\t\t</td>\n\t\t\t\t\t\t\t\t\t\t\t\t\t<td>&nbsp;</td>\n\t\t\t\t\t\t\t\t\t\t\t   </tr>\n\t\t\t\t\t\t\t\t\t\t\t</table>";
                         $line .= "</form>";
                         $line .= "<div id=\"loading\" style=\"display:none;\">\n\t\t\t\t\t\t\t\t\t\t\t\tPlease wait...<br />\n\t\t\t\t\t\t\t\t\t\t\t\t<img src=\"modules/sentastico/assets/bar.gif\" alt=\"\" /><br />\n\t\t\t\t\t\t\t\t\t\t\t\tUnpacking " . $pkgInstall . "...\n\t\t\t\t\t\t\t\t\t\t\t</div>";
                     }
                 }
             } else {
                 $userid = $_POST['u'];
                 $installed = @$_SESSION['installed'];
                 $install_to_base_dir = $_POST['install_to_base_dir'];
                 $currentuser = ctrl_users::GetUserDetail($userid);
                 $hostdatadir = ctrl_options::GetOption('hosted_dir') . "" . $currentuser['username'];
                 $site_domain = clean($_POST['site_domain']);
                 $dir_to_install = clean($_POST['dir_to_install']);
                 $install_to_base_dir = clean($_POST['install_to_base_dir']);
                 // Retrieve the directory for the Domain selected
                 $domaindir = FetchDomainDir($userid, $site_domain);
                 $completedir = $hostdatadir . "/public_html" . $domaindir . "/" . $dir_to_install . "";
                 $line = "<h2>Automated " . $pkgInstall . " Installation Status:</h2>";
                 if (file_exists($completedir) && $install_to_base_dir != '1' && empty($dir_to_install) && $installed != 'true') {
                     $line .= "If not empty root folder<br><br>";
                     $line .= "<p><font color=\"red\"><strong>Destination folder already exists!</strong></font><br /><br />Sorry, the install folder (<strong>/public_html" . $domaindir . "/" . $dir_to_install . "</strong>) already exists or contains files.<br />Please go back and create a new folder.</p>";
                     $line .= "<p><button class=\"btn btn-danger btn-small\" type=\"button\" onClick=\"javascript:location.href='?module=sentastico'\">Start over</button></p>";
                     // START issue here with showing folder exists even if folder created upon unzip completion
                 } else {
                     if (file_exists($completedir) && $install_to_base_dir != '1' && isset($dir_to_install) && $installed != 'true') {
                         $line .= "If not empty sub folder<br><br>";
                         $line .= "<p><font color=\"red\"><strong>Destination folder already exists!</strong></font><br /><br />Sorry, the install folder (<strong>/public_html" . $domaindir . "/" . $dir_to_install . "</strong>) already exists or contains files.<br />Please go back and create a new folder.</p>";
                         $line .= "<p><button class=\"btn btn-danger btn-small\" type=\"button\" onClick=\"javascript:location.href='?module=sentastico'\">Start over</button></p>";
                         // START issue here with showing folder exists even if folder created upon unzip completion
                     } else {
                         $line .= "Preparing folder: ";
                         CreateDir($completedir, $domaindir, $dir_to_install);
                         $line .= "<font color=\"green\">Folder created Successfully!</font>";
                         sleep(1);
                         // Remove all Files in the install Folder
                         emptyDir($completedir);
                         sleep(3);
                         set_time_limit(0);
                         $line .= "<br />Installing files: ";
                         $line .= "<form><input type='hidden' name='installed' value='InS'></form>";
                         // Un-Compressing The ZIP Archive
                         if (UnZip($zipfile . ".zip", $completedir, $site_domain, $dir_to_install) == 'true') {
                             $line .= "<font color=\"green\">Unzip was successful</font><br />";
                             $line .= "Package unzipped to: http://" . $site_domain . "/" . $dir_to_install . "<br /><br />";
                             if (file_exists($completedir . "/sentastico-install.php")) {
                                 $line .= "<a target=\"_blank\" href='http://" . $site_domain . "/" . $dir_to_install . "/sentastico-install.php'> <button class=\"btn btn-primary btn-small\" type=\"button\">Install Now</button> </a>";
                                 $line .= "<button class=\"btn btn-danger btn-small\" onClick=\"javascript:location.href='?module=sentastico'\">Install Later</button>";
                             } else {
                                 $line .= "<a target=\"_blank\" href='http://" . $site_domain . "/" . $dir_to_install . "/'><button class=\"btn btn-primary btn-small\" type=\"button\" onClick=\"javascript:location.href='?module=sentastico'\">Install Now</button></a>&nbsp;&nbsp;";
                                 $line .= "<button class=\"btn btn-danger btn-small\" onClick=\"javascript:location.href='?module=sentastico'\">Install Later</button>";
                             }
                         } else {
                             $line .= "<font color=\"red\">Unzip was not successful</font><br /><br />";
                             $line .= "<p><button class=\"btn btn-danger btn-small\" type=\"button\" onClick=\"javascript:location.href='?module=sentastico'\">Start over</button></p>";
                         }
                         $_SESSION['installed'] = 'true';
                         sleep(5);
                         // Set file/folder ownership and permissions if on posix
                         if (php_uname('s') != 'Windows NT') {
                             $line .= "Setting file and folder permissions: " . php_uname('s');
                             fixPermissions($completedir);
                         }
                     }
                 }
             }
         }
         return $line;
     }
 }