function register_detail($pname, $dirname) { global $xoopsDB; $qdir = $xoopsDB->quoteString($dirname); $res = $xoopsDB->query("SELECT * FROM " . UPDATE_PKG . " WHERE vcheck={$qdir} AND pversion='HEAD'"); if ($xoopsDB->getRowsNum($res)) { // exist current $pkg = $xoopsDB->fetchArray($res); if ($pkg['pname'] == $pname) { return false; } // unchanged clean_pkginfo($pkg['pkgid']); } $qname = $xoopsDB->quoteString($pname); $curver = get_current_version($pname, $dirname); $par = import_new_package($pname, $curver[1]); $pid = $par ? $par->getVar('pkgid') : 0; $name = $xoopsDB->quoteString($par ? $par->getVar('name') : ''); return $xoopsDB->query("INSERT INTO " . UPDATE_PKG . "(pname,pversion,vcheck,parent,name,ctime) VALUES({$qname},'HEAD',{$qdir},{$pid},{$name}," . time() . ")"); }
function import_new_package($pname, $ver, $dirname = "") { global $xoopsModuleConfig, $xoopsDB; if (!is_string($ver)) { $ver = preg_replace('/0$/', '', sprintf("%.2f", $ver)); } $res = $xoopsDB->query("SELECT * FROM " . UPDATE_PKG . " WHERE pname=" . $xoopsDB->quoteString($pname) . " AND pversion=" . $xoopsDB->quoteString($ver)); if ($res && $xoopsDB->getRowsNum($res) > 0) { return new Package($xoopsDB->fetchArray($res)); } $server = get_update_server(); if (empty($server)) { return null; } $url = $server . "manifesto.php?pkg=" . urlencode($pname) . "&v=" . urlencode($ver); $content = file_get_url($url, 'mani', false, FILE_CACHE_TIME); if (preg_match('/^\\w+ NOT FOUND/', $content)) { // fallback alternatives $url = $server . "list.php?pkg=" . urlencode($pname) . "&ext=1"; $list = file_get_url($url, 'list'); $find = false; // package all versions $vfile = XOOPS_ROOT_PATH . ($dirname ? "/modules/{$dirname}/xoops_version.php" : "/include/version.php"); $hash = md5_file($vfile); foreach (preg_split('/\\n/', $list) as $ln) { $pkg = pkg_info_csv($ln); if ($pkg) { $pv = $pkg['pversion']; if ($hash == $pkg['delegate']) { $find = $pkg; break; } if ($ver == floatval($pv)) { if (empty($find) || $find['dtime'] > $pkg['dtime']) { $find = $pkg; } } } } if (!$find) { return false; } return import_new_package($pname, $find['pversion']); } $pkg = new Package(); if ($pkg->loadStr($content)) { $pkg->store(); } else { return false; } return $pkg; }
function check_packages() { global $xoopsDB, $xoopsModuleConfig, $xoopsConfig; $res = $xoopsDB->query("SELECT p1.*, p2.vcheck dirname, p2.pversion ppversion FROM " . UPDATE_PKG . " p1 LEFT JOIN " . UPDATE_PKG . " p2 ON p1.parent=p2.pkgid WHERE p1.pversion='HEAD' ORDER BY p1.vcheck"); $pkgs = get_packages('all', false); echo "<h3>" . _AM_CHECK_LIST . "</h3>\n"; echo "<table cellspacing='1' class='outer'>\n"; echo "<tr><th>" . _AM_PKG_PNAME . "</th><th>" . _AM_PKG_CURRENT . "</th><th>" . _AM_PKG_DIRNAME . "</th><th>" . _AM_PKG_NEW . "</th><th>" . _AM_PKG_DTIME . "</th><th>" . _AM_CHANGES . "</th><th>" . _AM_MODIFYS . "</th><th></th></tr>\n"; $n = 0; $update = false; // find update package? $modify = false; $errors = array(); $module_handler =& xoops_gethandler('module'); while ($data = $xoopsDB->fetchArray($res)) { $pname = $data['pname']; $dirname = $data['vcheck']; // real dirname $pdir = empty($data['dirname']) ? $dirname : $data['dirname']; $bg = $n++ % 2 ? 'even' : 'odd'; $id = $data['pkgid']; $newpkg = isset($pkgs[$pdir]) ? $pkgs[$pdir] : array(); if (empty($newpkg)) { foreach ($pkgs as $pkg) { // find by name if ($pname == $pkg['pname']) { $newpkg = $pkg; break; } } } $newver = isset($newpkg['pversion']) ? $newpkg['pversion'] : ''; $curver = get_current_version($pname, $dirname); $modver = $curver[1]; // version string (0: normalize, 1: raw) if (empty($data['parent']) || !in_array($data['ppversion'], $curver)) { $par = import_new_package($pname, $modver, $pdir); if (empty($par)) { $errors[] = "{$pname} {$modver}: " . _AM_PKG_NOTFOUND; } else { $pid = $data['parent'] = $par->getVar('pkgid'); $pnm = $data['name'] = $par->getVar('name'); $ctm = $data['ctime'] = time(); $data['ppversion'] = $par->getVar('pversion'); $xoopsDB->queryF("UPDATE " . UPDATE_PKG . " SET parent={$pid}, name=" . $xoopsDB->quoteString($pnm) . ", mtime=0, ctime={$ctm} WHERE pkgid={$id}"); } } if (!empty($data['ppversion'])) { $pversion = $data['ppversion']; $past = time() - $data['mtime']; if ($past > $xoopsModuleConfig['cache_time']) { $pkg = new InstallPackage($data); $pkg->load(); $count = count($pkg->checkFiles()); if (!$count) { $xoopsDB->queryF("UPDATE " . UPDATE_PKG . " SET mtime=" . time() . " WHERE pkgid=" . $id); } } else { $count = 0; } $opt = "&pkgid={$id}"; if (!$count) { $opt .= "&view=yes"; } $op = "<a href='index.php?op=detail{$opt}'>" . ($count ? _AM_MODIFY : _AM_DETAIL) . "</a>"; } else { // no manifesto $pversion = ""; $op = ""; $count = 0; } if ($count) { $modify = true; } if (!empty($newpkg)) { $newver = $newpkg['pversion']; $newdate = formatTimestamp($newpkg['dtime'], "m"); } else { $newver = '-'; $newdate = '-'; } $mcount = count_modify_files($data['pkgid']); if ($pversion != $newver) { $bg = 'up'; $uppkg = import_new_package($pname, $newver); if ($uppkg) { $pid = $uppkg->getVar('pkgid'); $newver = "<a href='index.php?op=detail&pkgid={$id}&new={$pid}&view=yes'>" . htmlspecialchars($newver) . "</a>"; $update = true; } } else { $newver = htmlspecialchars($newver); } if ($count) { $bg = 'fix'; } // check module update $vers = htmlspecialchars($modver); if (!empty($dirname)) { $module = $module_handler->getByDirname($dirname); if (is_object($module)) { // installed? $mver = $module->getVar("version") / 100; if (!in_array($mver, $curver)) { $url = get_system_url("ModuleUpdate", $dirname); $vers = "<a href='{$url}' title='" . _AM_PKG_NEEDUPDATE . "'>{$vers} ({$mver})</a>"; } } else { $url = get_system_url("ModuleInstall", $dirname); $vers = "<a href='{$url}' title='" . _AM_PKG_NOTINSTALL . "'>{$vers} (-)</span>"; } } echo "<tr class='{$bg}'><td><a href='index.php?op=opts&pkgid={$id}'>" . htmlspecialchars($pname) . "</a></td><td>" . $vers . "</td><td>{$dirname}</td><td>" . $newver . "</td><td>{$newdate}</td><td align='right'>{$count}</td><td align='right'>{$mcount}</td><td>{$op}</td></tr>\n"; } echo "</table>\n"; if ($update && !$modify) { echo "<table cellpadding='5'>\n<tr>\n <td><a href='pack.php?op=backup'>" . _AM_UPDATE_BACKUP . "</a></td>\n <td><a href='pack.php?op=update'>" . _AM_UPDATE_ARCHIVE . "</a></td>\n <td>"; if (preg_match('/^Yes/', mysystem("check"))) { echo "\n <form action='pack.php?op=exec' method='post'>\n <input type='submit' value='" . _AM_UPDATE_SUBMIT . "'>\n </form>"; } echo "\n </td>\n</tr>\n</table>\n"; } $rollback = ROLLBACK; if (file_exists($rollback)) { $ctime = filectime($rollback); $expire = $ctime + $xoopsModuleConfig['cache_time']; if ($expire < time()) { unlink($rollback); } else { $tm = _AM_UPDATE_TIME . ' ' . formatTimestamp($ctime, 'm'); $until = _AM_UPDATE_EXPIRE . ' ' . formatTimestamp($expire, 'H:i'); echo "<table cellpadding='5'>\n <tr><td>\n <form action='index.php?op=rollback' method='post'>\n <input type='submit' value='" . _AM_UPDATE_ROLLBACK . "'></form></td>\n <td>{$tm} ({$until})</td></tr>\n</table>\n"; } } if ($errors) { echo "<br/><div class='errorMsg'>\n"; foreach ($errors as $msg) { echo "{$msg}<br/>\n"; } echo "</div>\n"; } }