Example #1
0
function doAction($mod, $act, $log = false)
{
    global $mos;
    if ($mod == '') {
        return;
    }
    $m = array();
    $m = parse_ini_file($mos . '/etc/pm/installed', true);
    $opts = $m[$mod];
    if (loadModuleOptions($mod, $opts) !== false) {
        $st = $opts['_status'];
        $init = $mos . '/etc/init/' . $opts['init'];
        $haveInit = is_file($init);
    } else {
        $st = 'noinstall';
        $init = '';
        $haveInit = false;
    }
    if ($act == 'start') {
        if ($haveInit) {
            doCommand("{$init} start", $log);
        }
    } elseif ($act == 'stop') {
        if ($haveInit) {
            if ($st == 'start' or $st == 'enable') {
                doCommand("{$init} stop", $log);
            }
        }
    } elseif ($act == 'restart') {
        if ($haveInit) {
            doCommand("{$init} stop", $log);
            doCommand("{$init} start", $log);
        }
    } elseif ($act == 'enable') {
        if ($haveInit) {
            chmod($init, 0755);
            doCommand("{$init} enable", $log);
        }
    } elseif ($act == 'disable') {
        if ($haveInit) {
            if (is_executable("{$init}")) {
                if ($st != 'stop') {
                    doCommand("{$init} stop", $log);
                }
                doCommand("{$init} disable", $log);
                chmod($init, 0644);
            }
        }
    } elseif ($act == 'delete') {
        if ($haveInit) {
            if (is_executable("{$init}")) {
                if ($st != 'stop') {
                    doCommand("{$init} stop", $log);
                }
            }
            chmod($init, 0755);
            doCommand("{$init} disable", $log);
        }
        removeMod($mod, $log);
        getPagesMsgs();
    } elseif ($act == 'install') {
        if (installMod($mod, $log)) {
            doAction($mod, 'enable', $log);
            doAction($mod, 'start', $log);
            getPagesMsgs();
        }
    } elseif ($act == 'update') {
        // store status, activity
        if ($st != 'disable') {
            if (($s = $opts['config_before']) != '') {
                doCommand("{$init} {$s}", $log);
            }
            // stopping, disable module
            doAction($mod, 'disable', $log);
        }
        // store backup
        if (($bc = $opts['backup']) != '') {
            doCommand("tar -cf /tmp/backup_{$mod}.tar -C {$mos}/ {$bc}", $log);
            $bc = "backup_{$mod}.tar";
        }
        // update package
        if (doCommand("{$mos}/bin/pm update {$mod}", $log) == 0) {
            // restore backup
            if ($bc != '') {
                doCommand("tar -xf /tmp/{$bc} -C {$mos}/", $log);
                doCommand("rm -Rf /tmp/{$bc}", $log);
            }
        }
        // restore status
        if ($st != 'disable') {
            doAction($mod, 'enable', $log);
            if ($st != 'stop') {
                doAction($mod, 'start', $log);
            }
            getPagesMsgs();
        } else {
            if ($haveInit) {
                chmod($init, 0644);
            }
        }
    } else {
        if (strpos($opts['actions'], $act) !== false) {
            if ($haveInit) {
                if (is_executable("{$init}")) {
                    doCommand("{$init} " . $act, $log);
                }
            }
        }
    }
}
Example #2
0
 loadOptions();
 $mods = array();
 $mods = parse_ini_file("{$b_dir}/mos_backup.ini", true);
 foreach ($mods as $mod => $item) {
     $st = $item['status'];
     $bc = $item['backup'];
     // install or just stop
     if (isset($nav_modules[$mod])) {
         $is = true;
         if (($ast = $nav_modules[$mod]['_status']) != 'disable') {
             if ($nav_modules[$mod]['role'] != 'core') {
                 doAction($mod, 'stop', false);
             }
         }
     } else {
         if ($is = installMod($mod, false)) {
             $ast = 'disable';
         }
     }
     if (!$is) {
         continue;
     }
     // untar backup
     if ($bc != '') {
         exec("tar -xf {$b_dir}/{$bc} -C {$mos}/");
     }
     // restore status
     if ($st == 'disable') {
         doAction($mod, 'disable');
     } else {
         if ($ast = 'disable') {