Пример #1
0
function ShowUpdatePage()
{
    global $LNG, $CONF, $db;
    $Patchlevel = explode(".", VERSION);
    if ($_REQUEST['action'] == 'history') {
        $Level = 0;
    } elseif (isset($Patchlevel[2])) {
        $Level = $Patchlevel[2];
    } else {
        $Level = 1159;
    }
    $opts = array('http' => array('method' => "GET", 'header' => "Patchlevel: " . $Level . "\r\nUser-Agent: 2Moons Update API (Rev " . $Patchlevel[2] . ")\r\n"));
    $context = stream_context_create($opts);
    switch ($_REQUEST['action']) {
        case "download":
            require_once ROOT_PATH . 'includes/libs/zip/zip.lib.' . PHP_EXT;
            $UpdateArray = unserialize(file_get_contents("http://update.2moons-systems.com/index.php?action=getupdate", FALSE, $context));
            if (!is_array($UpdateArray['revs'])) {
                exitupdate(array('debug' => array('noupdate' => "Kein Update vorhanden!")));
            }
            $SVN_ROOT = $UpdateArray['info']['svn'];
            $zipfile = new zipfile();
            $TodoDelete = "";
            foreach ($UpdateArray['revs'] as $Rev => $RevInfo) {
                if (!empty($RevInfo['add'])) {
                    foreach ($RevInfo['add'] as $File) {
                        if (strpos($File, '.') !== false) {
                            $zipfile->addFile(file_get_contents($SVN_ROOT . $File), str_replace("/trunk/", "", $File), $RevInfo['timestamp']);
                        }
                    }
                }
                if (!empty($RevInfo['edit'])) {
                    foreach ($RevInfo['edit'] as $File) {
                        if (strpos($File, '.') !== false) {
                            $zipfile->addFile(file_get_contents($SVN_ROOT . $File), str_replace("/trunk/", "", $File), $RevInfo['timestamp']);
                        }
                    }
                }
                if (!empty($RevInfo['del'])) {
                    foreach ($RevInfo['del'] as $File) {
                        if (strpos($File, '.') !== false) {
                            $TodoDelete .= str_replace("/trunk/", "", $File) . "\r\n";
                        }
                    }
                }
                $LastRev = $Rev;
            }
            if (!empty($TodoDelete)) {
                $zipfile->addFile($TodoDelete, "!TodoDelete!.txt", $RevInfo['timestamp']);
            }
            update_config('VERSION', str_replace("RC", "", $Patchlevel[0]) . "." . $Patchlevel[1] . "." . $LastRev);
            // Header für Download senden
            header("HTTP/1.1 200 OK");
            header("Content-Type: application/force-download");
            header('Content-Disposition: attachment; filename="patch_' . $Level . '_to_' . $LastRev . '.zip"');
            header("Content-Transfer-Encoding: binary");
            // Zip File senden
            echo $zipfile->file();
            exit;
            break;
        case "update":
            require_once ROOT_PATH . 'includes/libs/ftp/ftp.class.' . PHP_EXT;
            require_once ROOT_PATH . 'includes/libs/ftp/ftpexception.class.' . PHP_EXT;
            $UpdateArray = unserialize(file_get_contents("http://update.2moons-systems.com/index.php?action=getupdate", FALSE, $context));
            if (!is_array($UpdateArray['revs'])) {
                exitupdate(array('debug' => array('noupdate' => "Kein Update vorhanden!")));
            }
            $SVN_ROOT = $UpdateArray['info']['svn'];
            $CONFIG = array("host" => $CONF['ftp_server'], "username" => $CONF['ftp_user_name'], "password" => $CONF['ftp_user_pass'], "port" => 21);
            try {
                $ftp = FTP::getInstance();
                $ftp->connect($CONFIG);
                $LOG['debug']['connect'] = "FTP-Verbindungsaufbau: OK!";
            } catch (FTPException $error) {
                $LOG['debug']['connect'] = "FTP-Verbindungsaufbau: ERROR! " . $error->getMessage();
                exitupdate($LOG);
            }
            if ($ftp->changeDir($CONF['ftp_root_path'])) {
                $LOG['debug']['chdir'] = "FTP-Changedir(" . $CONF['ftp_root_path'] . "): OK!";
            } else {
                $LOG['debug']['chdir'] = "FTP-Changedir(" . $CONF['ftp_root_path'] . "): ERROR! Pfad nicht gefunden!";
                exitupdate($LOG);
            }
            foreach ($UpdateArray['revs'] as $Rev => $RevInfo) {
                if (!empty($RevInfo['add'])) {
                    foreach ($RevInfo['add'] as $File) {
                        if ($File == "/trunk/updates/update_" . $Rev . ".sql") {
                            $db->multi_query(str_replace("prefix_", DB_PREFIX, file_get_contents($SVN_ROOT . $File)));
                            continue;
                        } elseif ($File == "/trunk/updates/update_" . $Rev . ".php") {
                            require $SVN_ROOT . $File;
                        } else {
                            if (strpos($File, '.') !== false) {
                                $Data = fopen($SVN_ROOT . $File, "r");
                                if ($ftp->uploadFromFile($Data, str_replace("/trunk/", "", $File))) {
                                    $LOG['update'][$Rev][$File] = "OK! - Updated";
                                } else {
                                    $LOG['update'][$Rev][$File] = "ERROR! - Konnte Datei nicht hochladen";
                                }
                                fclose($Data);
                            } else {
                                if ($ftp->makeDir(str_replace("/trunk/", "", $File), 1)) {
                                    if (PHP_SAPI == 'apache2handler') {
                                        $ftp->chmod(str_replace("/trunk/", "", $File), '0777');
                                    } else {
                                        $ftp->chmod(str_replace("/trunk/", "", $File), '0755');
                                    }
                                    $LOG['update'][$Rev][$File] = "OK! - Updated";
                                } else {
                                    $LOG['update'][$Rev][$File] = "ERROR! - Konnte Datei nicht hochladen";
                                }
                            }
                        }
                    }
                }
                if (!empty($RevInfo['edit'])) {
                    foreach ($RevInfo['edit'] as $File) {
                        if (strpos($File, '.') !== false) {
                            if ($File == "/trunk/updates/update_" . $Rev . ".sql") {
                                $db->multi_query(str_replace("prefix_", DB_PREFIX, file_get_contents($SVN_ROOT . $File)));
                                continue;
                            } else {
                                $Data = fopen($SVN_ROOT . $File, "r");
                                if ($ftp->uploadFromFile($Data, str_replace("/trunk/", "", $File))) {
                                    $LOG['update'][$Rev][$File] = "OK! - Updated";
                                } else {
                                    $LOG['update'][$Rev][$File] = "ERROR! - Konnte Datei nicht hochladen";
                                }
                                fclose($Data);
                            }
                        }
                    }
                }
                if (!empty($RevInfo['del'])) {
                    foreach ($RevInfo['del'] as $File) {
                        if (strpos($File, '.') !== false) {
                            if ($ftp->delete(str_replace("/trunk/", "", $File))) {
                                $LOG['update'][$Rev][$File] = "OK! - Gelöscht";
                            } else {
                                $LOG['update'][$Rev][$File] = "ERROR! - Konnte Datei nicht löschen";
                            }
                        } else {
                            if ($ftp->removeDir(str_replace("/trunk/", "", $File), 1)) {
                                $LOG['update'][$Rev][$File] = "OK! - Gelöscht";
                            } else {
                                $LOG['update'][$Rev][$File] = "ERROR! - Konnte Datei nicht löschen";
                            }
                        }
                    }
                }
                $LastRev = $Rev;
            }
            $LOG['finish']['atrev'] = "UPDATE: OK! At Revision: " . $LastRev;
            // Verbindung schließen
            update_config('VERSION', str_replace("RC", "", $Patchlevel[0]) . "." . $Patchlevel[1] . "." . $LastRev);
            exitupdate($LOG);
            break;
        default:
            $template = new template();
            $template->page_header();
            $RevList = '';
            $Update = '';
            $Info = '';
            if (!function_exists('file_get_contents') || !function_exists('fsockopen')) {
                $template->message('Function file_get_contents oder fsockopen deactive', false, 0, true);
            } elseif (($RAW = @file_get_contents("http://update.2moons-systems.com/index.php?action=update", FALSE, $context)) !== false) {
                $UpdateArray = unserialize($RAW);
                if (is_array($UpdateArray['revs'])) {
                    foreach ($UpdateArray['revs'] as $Rev => $RevInfo) {
                        if (!(empty($RevInfo['add']) && empty($RevInfo['edit'])) && $Patchlevel[2] < $Rev) {
                            $Update = "<tr><th><a href=\"?page=update&amp;action=update\">Update</a> - <a href=\"?page=update&amp;action=download\">Download Patch Files</a></th></tr>";
                            $Info = "<tr><td class=\"c\" colspan=\"5\">Aktuelle Updates</td></tr>";
                        }
                        $edit = "";
                        if (!empty($RevInfo['edit']) || is_array($RevInfo['edit'])) {
                            foreach ($RevInfo['edit'] as $file) {
                                $edit .= '<a href="http://code.google.com/p/2moons/source/diff?spec=svn' . $Rev . '&r=' . $Rev . '&format=side&path=' . $file . '" target="diff">' . str_replace("/trunk/", "", $file) . '</a><br>';
                            }
                        }
                        $RevList .= "<tr>\r\n\t\t\t\t\t\t" . ($Patchlevel[2] == $Rev ? "<td class=c colspan=5>Momentane Version</td></tr><tr>" : ($Patchlevel[2] - 1 == $Rev ? "<td class=c colspan=5>Alte Updates</td></tr><tr>" : "")) . "\r\n\t\t\t\t\t\t<td class=c >" . ($Patchlevel[2] == $Rev ? "<font color=\"red\">" : "") . "Revision " . $Rev . " " . date("d. M y H:i:s", $RevInfo['timestamp']) . " von " . $RevInfo['author'] . ($Patchlevel[2] == $Rev ? "</font>" : "") . "</td></tr>\r\n\t\t\t\t\t\t<tr><th>" . makebr($RevInfo['log']) . "</th></tr>\r\n\t\t\t\t\t\t" . (!empty($RevInfo['add']) ? "<tr><th>ADD:<br>" . str_replace("/trunk/", "", implode("<br>\n", $RevInfo['add'])) . "</b></th></tr>" : "") . "\r\n\t\t\t\t\t\t" . (!empty($RevInfo['edit']) ? "<tr><th>EDIT:<br>" . $edit . "</b></th></tr>" : "") . "\r\n\t\t\t\t\t\t" . (!empty($RevInfo['del']) ? "<tr><th>DEL:<br>" . str_replace("/trunk/", "", implode("<br>\n", $RevInfo['del'])) . "</b></th></tr>" : "") . "\r\n\t\t\t\t\t\t</tr>";
                    }
                }
                $template->assign_vars(array('RevList' => $RevList, 'Update' => $Update, 'Info' => $Info));
                $template->show('adm/UpdatePage.tpl');
            } else {
                $template->message('Update Server currently not available', false, 0, true);
            }
            break;
    }
}
Пример #2
0
function ShowUpdatePage()
{
    global $LNG, $CONF, $db;
    if (isset($_REQUEST['version'])) {
        $Temp = explode('.', $_REQUEST['version']);
        $Temp = array_map('intval', $Temp);
        update_config(array('VERSION' => $Temp[0] . '.' . $Temp[1] . '.' . $Temp[2]), true);
    }
    $Patchlevel = explode(".", $GLOBALS['CONF']['VERSION']);
    if ($_REQUEST['action'] == 'history') {
        $Level = 0;
    } elseif (isset($Patchlevel[2])) {
        $Level = $Patchlevel[2];
    }
    switch ($_REQUEST['action']) {
        case "download":
            $UpdateArray = getDatafromServer('getupdate');
            if (!is_array($UpdateArray['revs'])) {
                exitupdate(array('debug' => array('noupdate' => $LNG['up_kein_update'])));
            }
            require_once ROOT_PATH . 'includes/libs/zip/zip.lib.php';
            $SVN_ROOT = $UpdateArray['info']['svn'];
            $zipfile = new zipfile();
            $TodoDelete = "";
            $Files = array('add' => array(), 'edit' => array(), 'del' => array());
            $FirstRev = 0;
            $LastRev = 0;
            foreach ($UpdateArray['revs'] as $Rev => $RevInfo) {
                if (!empty($RevInfo['add'])) {
                    foreach ($RevInfo['add'] as $File) {
                        if (in_array($File, $Files['add']) || strpos($File, '.') === false) {
                            continue;
                        }
                        $Files['add'][] = $File;
                        $zipfile->addFile(@file_get_contents($SVN_ROOT . $File), str_replace("/trunk/", "", $File), $RevInfo['timestamp']);
                    }
                }
                if (!empty($RevInfo['edit'])) {
                    foreach ($RevInfo['edit'] as $File) {
                        if (in_array($File, $Files['edit']) || strpos($File, '.') === false) {
                            continue;
                        }
                        $Files['edit'][] = $File;
                        $zipfile->addFile(@file_get_contents($SVN_ROOT . $File), str_replace("/trunk/", "", $File), $RevInfo['timestamp']);
                    }
                }
                if (!empty($RevInfo['del'])) {
                    foreach ($RevInfo['del'] as $File) {
                        if (in_array($File, $Files['del']) || strpos($File, '.') === false) {
                            continue;
                        }
                        $Files['del'][] = $File;
                        $TodoDelete .= str_replace("/trunk/", "", $File) . "\r\n";
                    }
                }
                if ($FirstRev === 0) {
                    $FirstRev = $Rev;
                }
                $LastRev = $Rev;
            }
            if (!empty($TodoDelete)) {
                $zipfile->addFile($TodoDelete, "!TodoDelete!.txt", $RevInfo['timestamp']);
            }
            update_config(array('VERSION' => $Patchlevel[0] . "." . $Patchlevel[1] . "." . $LastRev), true);
            // Header für Download senden
            $File = $zipfile->file();
            header("Content-length: " . strlen($File));
            header("Content-Type: application/force-download");
            header('Content-Disposition: attachment; filename="patch_' . $FirstRev . '_to_' . $LastRev . '.zip"');
            header("Content-Transfer-Encoding: binary");
            // Zip File senden
            echo $File;
            exit;
            break;
        case "update":
            require_once ROOT_PATH . 'includes/libs/ftp/ftp.class.php';
            require_once ROOT_PATH . 'includes/libs/ftp/ftpexception.class.php';
            $UpdateArray = getDatafromServer('getupdate');
            if (!is_array($UpdateArray['revs'])) {
                exitupdate(array('debug' => array('noupdate' => $LNG['up_kein_update'])));
            }
            $SVN_ROOT = $UpdateArray['info']['svn'];
            $CONFIG = array("host" => $CONF['ftp_server'], "username" => $CONF['ftp_user_name'], "password" => $_POST['password'], "port" => 21);
            try {
                $ftp = FTP::getInstance();
                $ftp->connect($CONFIG);
                $LOG['debug']['connect'] = $LNG['up_ftp_ok'];
            } catch (FTPException $error) {
                $LOG['debug']['connect'] = $LNG['up_ftp_error'] . "" . $error->getMessage();
                exitupdate($LOG);
            }
            if ($ftp->changeDir($CONF['ftp_root_path'])) {
                $LOG['debug']['chdir'] = $LNG['up_ftp_change'] . "" . $CONF['ftp_root_path'] . "): " . $LNG['up_ftp_ok'];
            } else {
                $LOG['debug']['chdir'] = $LNG['up_ftp_change'] . "" . $CONF['ftp_root_path'] . "): " . $LNG['up_ftp_change_error'];
                exitupdate($LOG);
            }
            $Files = array('add' => array(), 'edit' => array(), 'del' => array());
            $Check = 0;
            foreach ($UpdateArray['revs'] as $Rev => $RevInfo) {
                if ($Check === 0) {
                    $Check = 1;
                    if ($Rev - 1 != $Level) {
                        $LOG['debug']['rev'] = "UpdateServer requrie Revision " . ($Rev - 1) . ".";
                        exitupdate($LOG);
                    }
                }
                if (!empty($RevInfo['add'])) {
                    foreach ($RevInfo['add'] as $File) {
                        if (in_array($File, $Files['add'])) {
                            continue;
                        }
                        $Files['add'][] = $File;
                        if ($File == "/trunk/updates/update_" . $Rev . ".sql") {
                            $db->multi_query(str_replace("prefix_", DB_PREFIX, @file_get_contents($SVN_ROOT . $File)));
                            continue;
                        } elseif ($File == "/trunk/updates/update_" . $Rev . ".php") {
                            require $SVN_ROOT . $File;
                        } else {
                            if (strpos($File, '.') !== false) {
                                $Data = fopen($SVN_ROOT . $File, "r");
                                if ($ftp->uploadFromFile($Data, str_replace("/trunk/", "", $File))) {
                                    $LOG['update'][$Rev][$File] = $LNG['up_ok_update'];
                                } else {
                                    $LOG['update'][$Rev][$File] = $LNG['up_error_update'];
                                }
                                fclose($Data);
                            } else {
                                if ($ftp->makeDir(str_replace("/trunk/", "", $File), 1)) {
                                    if (PHP_SAPI == 'apache2handler') {
                                        $ftp->chmod(str_replace("/trunk/", "", $File), '0777');
                                    } else {
                                        $ftp->chmod(str_replace("/trunk/", "", $File), '0755');
                                    }
                                    $LOG['update'][$Rev][$File] = $LNG['up_ok_update'];
                                } else {
                                    $LOG['update'][$Rev][$File] = $LNG['up_error_update'];
                                }
                            }
                        }
                    }
                }
                if (!empty($RevInfo['edit'])) {
                    foreach ($RevInfo['edit'] as $File) {
                        if (in_array($File, $Files['edit'])) {
                            continue;
                        }
                        $Files['edit'][] = $File;
                        if (strpos($File, '.') !== false) {
                            if ($File == "/trunk/updates/update_" . $Rev . ".sql") {
                                $db->multi_query(str_replace("prefix_", DB_PREFIX, @file_get_contents($SVN_ROOT . $File)));
                                continue;
                            } else {
                                $Data = fopen($SVN_ROOT . $File, "r");
                                if ($ftp->uploadFromFile($Data, str_replace("/trunk/", "", $File))) {
                                    $LOG['update'][$Rev][$File] = $LNG['up_ok_update'];
                                } else {
                                    $LOG['update'][$Rev][$File] = $LNG['up_error_update'];
                                }
                                fclose($Data);
                            }
                        }
                    }
                }
                if (!empty($RevInfo['del'])) {
                    foreach ($RevInfo['del'] as $File) {
                        if (in_array($File, $Files['del'])) {
                            continue;
                        }
                        $Files['del'][] = $File;
                        if (strpos($File, '.') !== false) {
                            if ($ftp->delete(str_replace("/trunk/", "", $File))) {
                                $LOG['update'][$Rev][$File] = $LNG['up_delete_file'];
                            } else {
                                $LOG['update'][$Rev][$File] = $LNG['up_error_delete_file'];
                            }
                        } else {
                            if ($ftp->removeDir(str_replace("/trunk/", "", $File), 1)) {
                                $LOG['update'][$Rev][$File] = $LNG['up_delete_file'];
                            } else {
                                $LOG['update'][$Rev][$File] = $LNG['up_error_delete_file'];
                            }
                        }
                    }
                }
                $LastRev = $Rev;
            }
            $LOG['finish']['atrev'] = $LNG['up_update_ok_rev'] . " " . $LastRev;
            // Verbindung schließen
            ClearCache();
            update_config(array('VERSION' => $Patchlevel[0] . "." . $Patchlevel[1] . "." . $LastRev), true);
            exitupdate($LOG);
            break;
        default:
            $template = new template();
            $RevList = '';
            $Update = '';
            $Info = '';
            $UpdateArray = getDatafromServer('update');
            if (!is_array($UpdateArray)) {
                $template->message($UpdateArray);
            } else {
                if (is_array($UpdateArray['revs'])) {
                    foreach ($UpdateArray['revs'] as $Rev => $RevInfo) {
                        if (!(empty($RevInfo['add']) && empty($RevInfo['edit'])) && $Patchlevel[2] < $Rev) {
                            $Update = "<tr><td><a href=\"#\" onclick=\"openPWDialog();return false;\">Update</a>" . (function_exists('gzcompress') ? " - <a href=\"?page=update&amp;action=download\">" . $LNG['up_download_patch_files'] . "</a>" : "") . "</td></tr>";
                            $Info = "<tr><th colspan=\"5\">" . $LNG['up_aktuelle_updates'] . "</th></tr>";
                        }
                        $edit = "";
                        if (!empty($RevInfo['edit']) || is_array($RevInfo['edit'])) {
                            foreach ($RevInfo['edit'] as $file) {
                                $edit .= '<a href="http://code.google.com/p/2moons/source/diff?spec=svn' . $Rev . '&r=' . $Rev . '&format=side&path=' . $file . '" target="diff">' . str_replace("/trunk/", "", $file) . '</a><br>';
                            }
                        }
                        $RevList .= "<tr>\r\n\t\t\t\t\t\t" . ($Patchlevel[2] == $Rev ? "<th colspan=5>" . $LNG['up_momentane_version'] . "</th></tr><tr>" : ($Patchlevel[2] - 1 == $Rev ? "<th colspan=5>" . $LNG['up_alte_updates'] . "</th></tr><tr>" : "")) . "\r\n\t\t\t\t\t\t<th>" . ($Patchlevel[2] == $Rev ? "<font color=\"red\">" : "") . "" . $LNG['up_revision'] . "" . $Rev . " " . date(TDFORMAT, $RevInfo['timestamp']) . " " . $LNG['ml_from'] . " " . $RevInfo['author'] . ($Patchlevel[2] == $Rev ? "</font>" : "") . "</th></tr>\r\n\t\t\t\t\t\t<tr><td>" . makebr($RevInfo['log']) . "</th></tr>\r\n\t\t\t\t\t\t" . (!empty($RevInfo['add']) ? "<tr><td>" . $LNG['up_add'] . "<br>" . str_replace("/trunk/", "", implode("<br>\n", $RevInfo['add'])) . "</b></td></tr>" : "") . "\r\n\t\t\t\t\t\t" . (!empty($RevInfo['edit']) ? "<tr><td>" . $LNG['up_edit'] . "<br>" . $edit . "</b></td></tr>" : "") . "\r\n\t\t\t\t\t\t" . (!empty($RevInfo['del']) ? "<tr><td>" . $LNG['up_del'] . "<br>" . str_replace("/trunk/", "", implode("<br>\n", $RevInfo['del'])) . "</b></td></tr>" : "") . "\r\n\t\t\t\t\t\t</tr>";
                    }
                }
                $template->assign_vars(array('up_password_title' => $LNG['up_password_title'], 'up_password_info' => $LNG['up_password_info'], 'up_password_label' => $LNG['up_password_label'], 'up_submit' => $LNG['up_submit'], 'up_version' => $LNG['up_version'], 'version' => $CONF['VERSION'], 'RevList' => $RevList, 'Update' => $Update, 'Info' => $Info));
                $template->show('adm/UpdatePage.tpl');
            }
            break;
    }
}