private PackageAction syncToVictim(
      RequestContext requestContext, Long sid, Set pkgIdCombos, String option) {

    PackageAction pa = null;
    Date time = new Date(requestContext.getParamAsLong("time"));

    if (isProfileSync(requestContext)) {
      Long prid = requestContext.getRequiredParam("prid");

      pa =
          ProfileManager.syncToProfile(
              requestContext.getCurrentUser(), sid, prid, pkgIdCombos, option, time);

      if (pa == null) {
        createMessage(requestContext.getRequest(), "message.nopackagestosync");
        return null;
      }

      List args = new ArrayList();
      args.add(sid.toString());
      args.add(pa.getId().toString());
      args.add(requestContext.lookupAndBindServer().getName());
      args.add(
          ProfileManager.lookupByIdAndOrg(prid, requestContext.getCurrentUser().getOrg())
              .getName());

      createMessage(requestContext.getRequest(), "message.syncpackages", args);
    } else if (isSystemSync(requestContext)) {
      Long sid1 = requestContext.getRequiredParam("sid_1");
      pa =
          ProfileManager.syncToSystem(
              requestContext.getCurrentUser(), sid, sid1, pkgIdCombos, option, time);

      if (pa == null) {
        createMessage(requestContext.getRequest(), "message.nopackagestosync");
        return null;
      }

      List args = new ArrayList();
      args.add(sid.toString());
      args.add(pa.getId().toString());
      args.add(requestContext.lookupAndBindServer().getName());
      args.add(SystemManager.lookupByIdAndUser(sid1, requestContext.getCurrentUser()).getName());

      createMessage(requestContext.getRequest(), "message.syncpackages", args);
    }

    addHardwareMessage(pa, requestContext);

    return pa;
  }
  /** {@inheritDoc} */
  @Override
  public ActionForward execute(
      ActionMapping mapping,
      ActionForm formIn,
      HttpServletRequest request,
      HttpServletResponse response) {

    RequestContext requestContext = new RequestContext(request);
    Server server = requestContext.lookupAndBindServer();
    Long aid = requestContext.getRequiredParam("aid");

    request.setAttribute("aid", aid);
    request.setAttribute("referrerLink", "History.do");
    request.setAttribute("linkLabel", "system.event.return");
    request.setAttribute("headerLabel", "system.event.header");

    Action action;
    ServerAction serverAction;
    try {
      action = ActionManager.lookupAction(requestContext.getCurrentUser(), aid);
      serverAction = ActionFactory.getServerActionForServerAndAction(server, action);
    } catch (LookupException e) {
      ServerHistoryEvent event = ActionFactory.lookupHistoryEventById(aid);
      request.setAttribute("actiontype", event.getSummary());
      request.setAttribute("earliestaction", event.getCreated());
      request.setAttribute("actionnotes", event.getDetails());
      request.setAttribute("failed", false);
      return mapping.findForward(RhnHelper.DEFAULT_FORWARD);
    }
    ActionFormatter af = action.getFormatter();
    request.setAttribute("actionname", af.getName());
    request.setAttribute("actiontype", af.getActionType());
    request.setAttribute("scheduler", af.getScheduler());
    request.setAttribute("earliestaction", af.getEarliestDate());
    request.setAttribute("actionnotes", af.getDetails(server, requestContext.getCurrentUser()));
    request.setAttribute("failed", serverAction.getStatus().equals(ActionFactory.STATUS_FAILED));
    if (!serverAction.getStatus().equals(ActionFactory.STATUS_COMPLETED)
        && !serverAction.getStatus().equals(ActionFactory.STATUS_FAILED)) {
      request.setAttribute("referrerLink", "Pending.do");
      request.setAttribute("linkLabel", "system.event.pendingReturn");
      request.setAttribute("headerLabel", "system.event.pendingHeader");
    }
    if (isSubmitted((DynaActionForm) formIn)) {
      createSuccessMessage(request, "system.event.rescheduled", action.getName());
      ActionFactory.rescheduleSingleServerAction(action, 5L, server.getId());
      return mapping.findForward("continue");
    }

    return mapping.findForward(RhnHelper.DEFAULT_FORWARD);
  }
Example #3
0
  /** {@inheritDoc} */
  public DataResult<ManagedServerGroup> getResult(RequestContext context) {

    Server server = context.lookupAndBindServer();
    ServerGroupManager manager = ServerGroupManager.getInstance();
    List<ManagedServerGroup> serverGroups = server.getManagedGroups();
    List<ManagedServerGroup> all = context.getCurrentUser().getOrg().getManagedServerGroups();
    List<ManagedServerGroup> ret = new LinkedList<ManagedServerGroup>();
    for (ManagedServerGroup group : all) {
      if (!serverGroups.contains(group) && manager.canAccess(context.getCurrentUser(), group)) {
        ret.add(group);
      }
    }
    return new DataResult<ManagedServerGroup>(ret);
  }
Example #4
0
  /**
   * Wrap a call to loginUserIntoSessionTest since we want that method to return a value and JUnit
   * only calls methods with void return types
   *
   * @throws Exception
   */
  public void testPerformValidUsername() throws Exception {
    HttpServletRequest request = loginUserIntoSessionTest();
    RequestContext requestContext = new RequestContext(request);

    assertNotNull(
        IntegrationService.get().getAuthToken(requestContext.getCurrentUser().getLogin()));
  }
  /** {@inheritDoc} */
  @Override
  public ActionForward handleDispatch(
      ListSessionSetHelper helper,
      ActionMapping mapping,
      ActionForm formIn,
      HttpServletRequest request,
      HttpServletResponse response) {
    RequestContext context = new RequestContext(request);
    ActivationKey key = context.lookupAndBindActivationKey();
    ConfigChannelListProcessor proc = new ConfigChannelListProcessor();
    Set<String> set = helper.getSet();

    for (String id : set) {
      Long ccid = Long.valueOf(id);
      ConfigChannel cc = ConfigurationFactory.lookupConfigChannelById(ccid);
      proc.remove(key.getConfigChannelsFor(context.getCurrentUser()), cc);
    }
    getStrutsDelegate()
        .saveMessage(
            "config_channels_to_unsubscribe.unsubscribe.success",
            new String[] {String.valueOf(set.size())},
            request);

    Map<String, Object> params = new HashMap<String, Object>();
    params.put(RequestContext.TOKEN_ID, key.getToken().getId().toString());
    StrutsDelegate strutsDelegate = getStrutsDelegate();
    return strutsDelegate.forwardParams(mapping.findForward("success"), params);
  }
  /**
   * The second step in the wizard
   *
   * @param mapping ActionMapping for struts
   * @param form DynaActionForm representing the form
   * @param ctx RequestContext request context
   * @param response HttpServletResponse response object
   * @param step WizardStep what step are we on?
   * @return ActionForward struts action forward
   * @throws Exception if something goes amiss
   */
  public ActionForward runSecond(
      ActionMapping mapping,
      DynaActionForm form,
      RequestContext ctx,
      HttpServletResponse response,
      WizardStep step)
      throws Exception {
    log.debug("runSecond");

    if (!StringUtils.isBlank(form.getString(HIDDEN_BOND_SLAVE_INTERFACES))) {
      form.set(BOND_SLAVE_INTERFACES, form.getString(HIDDEN_BOND_SLAVE_INTERFACES).split(","));
    }

    Long sid = (Long) form.get(RequestContext.SID);
    User user = ctx.getCurrentUser();

    if (!validateFirstSelections(form, ctx)) {
      return runFirst(mapping, form, ctx, response, step);
    }
    KickstartScheduleCommand cmd = getScheduleCommand(form, ctx, null, null);

    checkForKickstart(form, cmd, ctx);
    addRequestAttributes(ctx, cmd, form);
    if (!cmd.isCobblerOnly()) {
      List packageProfiles = cmd.getProfiles();
      form.set(SYNCH_PACKAGES, packageProfiles);
      List systemProfiles = cmd.getCompatibleSystems();
      form.set(SYNCH_SYSTEMS, systemProfiles);

      // Disable the package/system sync radio buttons if no profiles are
      // available:
      String syncPackageDisabled = "false";
      if (packageProfiles.size() == 0) {
        syncPackageDisabled = "true";
      }
      String syncSystemDisabled = "false";
      if (systemProfiles.size() == 0) {
        syncSystemDisabled = "true";
      }
      ctx.getRequest().setAttribute(SYNC_PACKAGE_DISABED, syncPackageDisabled);
      ctx.getRequest().setAttribute(SYNC_SYSTEM_DISABLED, syncSystemDisabled);

      if (StringUtils.isEmpty(form.getString(TARGET_PROFILE_TYPE))) {
        form.set(TARGET_PROFILE_TYPE, KickstartScheduleCommand.TARGET_PROFILE_TYPE_NONE);
      }
    } else {
      ctx.getRequest().setAttribute(COBBLER_ONLY_PROFILE, Boolean.TRUE);
    }

    if (StringUtils.isEmpty(form.getString(KERNEL_PARAMS_TYPE))) {
      form.set(KERNEL_PARAMS_TYPE, KERNEL_PARAMS_DISTRO);
    }

    if (StringUtils.isEmpty(form.getString(POST_KERNEL_PARAMS_TYPE))) {
      form.set(POST_KERNEL_PARAMS_TYPE, KERNEL_PARAMS_DISTRO);
    }

    SdcHelper.ssmCheck(ctx.getRequest(), sid, user);
    return mapping.findForward("second");
  }
 /** {@inheritDoc} */
 protected DataResult getDataResult(RequestContext requestContext, ListControl lc) {
   User user = requestContext.getCurrentUser();
   DataResult dr =
       ChannelManager.popularChannelTree(
           user, (Long) requestContext.getRequest().getAttribute("count"), lc);
   return dr;
 }
  /**
   * Applies the selected errata
   *
   * @param mapping ActionMapping
   * @param formIn ActionForm
   * @param request ServletRequest
   * @param response ServletResponse
   * @return The ActionForward to go to next.
   */
  public ActionForward applyErrata(
      ActionMapping mapping,
      ActionForm formIn,
      HttpServletRequest request,
      HttpServletResponse response) {

    Map<String, Object> params = new HashMap<String, Object>();

    RequestContext requestContext = new RequestContext(request);
    StrutsDelegate strutsDelegate = getStrutsDelegate();
    // if they chose errata, send them to the confirmation page
    Long sid = requestContext.getParamAsLong("sid");

    User user = requestContext.getCurrentUser();
    RhnSet set = getSetDecl(sid).get(user);

    // if they chose no errata, return to the same page with a message
    if (set.isEmpty()) {
      ActionMessages msg = new ActionMessages();
      msg.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("errata.applynone"));
      params = makeParamMap(formIn, request);
      strutsDelegate.saveMessages(request, msg);
      return strutsDelegate.forwardParams(mapping.findForward(RhnHelper.DEFAULT_FORWARD), params);
    }

    if (sid != null) {
      params.put("sid", sid);
    }

    return strutsDelegate.forwardParams(mapping.findForward(RhnHelper.CONFIRM_FORWARD), params);
  }
  private Channel makePrivate(DynaActionForm form, ActionErrors errors, RequestContext ctx) {

    User user = ctx.getCurrentUser();
    Long cid = ctx.getParamAsLong("cid");
    Channel channel = ChannelFactory.lookupById(cid);
    unsubscribeOrgsFromChannel(user, channel, Channel.PRIVATE);
    return edit(form, errors, ctx);
  }
  /** {@inheritDoc} */
  public ActionForward execute(
      ActionMapping mapping,
      ActionForm formIn,
      HttpServletRequest request,
      HttpServletResponse response) {

    RequestContext requestContext = new RequestContext(request);
    StrutsDelegate strutsDelegate = getStrutsDelegate();

    User user = requestContext.getCurrentUser();

    Errata errata = requestContext.lookupErratum();
    DataResult dr = ErrataManager.systemsAffected(user, errata.getId(), null);

    RhnSet set = RhnSetDecl.SYSTEMS_AFFECTED.get(user);
    RhnListSetHelper helper = new RhnListSetHelper(request);

    // if its not submitted
    // ==> this is the first visit to this page
    // clear the 'dirty set'
    if (!requestContext.isSubmitted()) {
      set.clear();
      RhnSetManager.store(set);
    }

    if (request.getParameter(DISPATCH) != null) {
      helper.updateSet(set, LIST_NAME);
      if (!set.isEmpty()) {
        // Send to AffectedSystemsAction to handle submit
        return strutsDelegate.forwardParams(
            mapping.findForward("confirm"), request.getParameterMap());
      }
      RhnHelper.handleEmptySelection(request);
    }

    if (ListTagHelper.getListAction(LIST_NAME, request) != null) {
      helper.execute(set, LIST_NAME, dr);
    }

    // if I have a previous set selections populate data using it
    if (!set.isEmpty()) {
      helper.syncSelections(set, dr);
      ListTagHelper.setSelectedAmount(LIST_NAME, set.size(), request);
    }

    TagHelper.bindElaboratorTo("systemAffectedList", dr.getElaborator(), request);
    ListTagHelper.bindSetDeclTo(LIST_NAME, RhnSetDecl.SYSTEMS_AFFECTED, request);

    request.setAttribute(RequestContext.PAGE_LIST, dr);
    request.setAttribute("set", set);
    request.setAttribute("errata", errata);
    request.setAttribute(
        ListTagHelper.PARENT_URL,
        request.getRequestURI() + "?" + RequestContext.ERRATA_ID + "=" + errata.getId());

    return strutsDelegate.forwardParams(
        mapping.findForward(RhnHelper.DEFAULT_FORWARD), request.getParameterMap());
  }
  /** {@inheritDoc} */
  public ActionForward execute(
      ActionMapping mapping,
      ActionForm formIn,
      HttpServletRequest request,
      HttpServletResponse response) {

    RequestContext requestContext = new RequestContext(request);
    User user = requestContext.getCurrentUser();

    Long cid = Long.parseLong(request.getParameter(CID));
    PublishErrataHelper.checkPermissions(user, cid);

    Channel currentChan = ChannelFactory.lookupByIdAndUser(cid, requestContext.getCurrentUser());
    request.setAttribute("channel_name", currentChan.getName());

    request.setAttribute("cid", cid);
    return mapping.findForward("default");
  }
Example #12
0
  private Long create(DynaActionForm form, ActionErrors errors, RequestContext ctx) {

    User loggedInUser = ctx.getCurrentUser();
    Long cid = null;

    // handle submission
    // why can't I just pass in a dictionary? sigh, there are
    // times where python would make this SOOOO much easier.
    CreateChannelCommand ccc = new CreateChannelCommand();
    ccc.setArchLabel((String) form.get("arch"));
    ccc.setChecksumLabel((String) form.get("checksum"));
    ccc.setLabel((String) form.get("label"));
    ccc.setName((String) form.get("name"));
    ccc.setSummary((String) form.get("summary"));
    ccc.setDescription(StringUtil.nullIfEmpty((String) form.get("description")));
    ccc.setParentLabel(null);
    ccc.setUser(loggedInUser);
    ccc.setGpgKeyId(StringUtil.nullIfEmpty((String) form.get("gpg_key_id")));
    ccc.setGpgKeyUrl(StringUtil.nullIfEmpty((String) form.get("gpg_key_url")));
    ccc.setGpgKeyFp(StringUtil.nullIfEmpty((String) form.get("gpg_key_fingerprint")));
    ccc.setMaintainerName(StringUtil.nullIfEmpty((String) form.get("maintainer_name")));
    ccc.setMaintainerEmail(StringUtil.nullIfEmpty((String) form.get("maintainer_email")));
    ccc.setMaintainerPhone(StringUtil.nullIfEmpty((String) form.get("maintainer_phone")));
    ccc.setSupportPolicy(StringUtil.nullIfEmpty((String) form.get("support_policy")));
    ccc.setAccess((String) form.get("org_sharing"));

    String parent = (String) form.get("parent");
    if (parent == null || parent.equals("")) {
      ccc.setParentId(null);
    } else {
      ccc.setParentId(Long.valueOf(parent));
    }

    try {
      Channel c = ccc.create();
      String sharing = (String) form.get("per_user_subscriptions");
      c.setGloballySubscribable(
          (sharing != null) && ("all".equals(sharing)), loggedInUser.getOrg());
      c = (Channel) ChannelFactory.reload(c);
      cid = c.getId();
    } catch (InvalidGPGFingerprintException borg) {
      errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("edit.channel.invalidgpgfp"));
    } catch (InvalidGPGKeyException dukat) {
      errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("edit.channel.invalidgpgkey"));
    } catch (InvalidGPGUrlException khan) {
      errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("edit.channel.invalidgpgurl"));
    } catch (InvalidChannelNameException ferengi) {
      handleChannelNameException(errors, ferengi);
    } catch (InvalidChannelLabelException q) {
      handleChannelLabelException(errors, q);
    } catch (IllegalArgumentException iae) {
      errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage(iae.getMessage()));
    }

    return cid;
  }
  /** {@inheritDoc} */
  protected DataResult getDataResult(User user, ActionForm formIn, HttpServletRequest request) {
    RequestContext requestContext = new RequestContext(request);
    Long sid = requestContext.getRequiredParam("sid");
    Set<String> pkgIdCombos = SessionSetHelper.lookupAndBind(request, getDecl(requestContext, sid));

    if (isProfileSync(requestContext)) {
      Long prid = requestContext.getRequiredParam("prid");

      return ProfileManager.getMissingProfilePackages(
          requestContext.getCurrentUser(), sid, prid, pkgIdCombos, null);
    } else if (isSystemSync(requestContext)) {
      Long sid1 = requestContext.getRequiredParam("sid_1");

      return ProfileManager.getMissingSystemPackages(
          requestContext.getCurrentUser(), sid, sid1, pkgIdCombos, null);
    }

    return null;
  }
  /**
   * Parses the kernel options or Post kernel options from the given form. Called after the advanced
   * options page is typically set.. This is a handy method used in both SSM and SDC KS scheduling.
   *
   * @param form the kickstartScheduleWizardForm that holds the form fields.
   * @param request the servlet request
   * @param profileCobblerId the cobbler profile id
   * @param isPost true if caller is interested in getting the post kernel options and not the pre.
   * @return the kernel options selected by the user.
   */
  public static String parseKernelOptions(
      DynaActionForm form, HttpServletRequest request, String profileCobblerId, boolean isPost) {
    RequestContext context = new RequestContext(request);
    String typeKey = !isPost ? KERNEL_PARAMS_TYPE : POST_KERNEL_PARAMS_TYPE;
    String customKey = !isPost ? KERNEL_PARAMS : POST_KERNEL_PARAMS;
    String type = form.getString(typeKey);

    return parseKernelOptions(
        form.getString(customKey), type, profileCobblerId, isPost, context.getCurrentUser());
  }
  /** {@inheritDoc} */
  public ActionForward execute(
      ActionMapping mapping,
      ActionForm formIn,
      HttpServletRequest request,
      HttpServletResponse response) {

    RequestContext context = new RequestContext(request);
    User user = context.getCurrentUser();

    long cid = context.getRequiredParam("cid");
    Channel chan = ChannelFactory.lookupByIdAndUser(cid, user);
    request.setAttribute("channel_name", chan.getName());
    request.setAttribute("cid", chan.getId());

    Map<String, Object> params = new HashMap<String, Object>();
    params.put(RequestContext.CID, chan.getId().toString());

    ListSessionSetHelper helper = new ListSessionSetHelper(this, request, params);

    if (!context.isSubmitted()) {
      List<ContentSource> result = getResult(context);
      Set<String> preSelect = new HashSet<String>();
      for (int i = 0; i < result.size(); i++) {
        ContentSource src = result.get(i);
        if (src.getChannels().contains(chan)) {
          preSelect.add(src.getId().toString());
        }
      }
      helper.preSelect(preSelect);
    }

    helper.ignoreEmptySelection();
    helper.execute();

    if (helper.isDispatched()) {
      Set<ContentSource> foo = chan.getSources();
      foo.clear();
      Set<String> set = helper.getSet();
      for (String id : set) {
        Long sgid = Long.valueOf(id);
        ContentSource tmp = ChannelFactory.lookupContentSource(sgid, user.getOrg());
        foo.add(tmp);
      }

      ChannelFactory.save(chan);

      StrutsDelegate strutsDelegate = getStrutsDelegate();
      strutsDelegate.saveMessage(
          "channel.edit.repo.updated", new String[] {chan.getName()}, request);

      return strutsDelegate.forwardParams(mapping.findForward("success"), params);
    }

    return mapping.findForward(RhnHelper.DEFAULT_FORWARD);
  }
 /**
  * Returns the kickstart schedule command
  *
  * @param form the dyna aciton form
  * @param ctx the request context
  * @param scheduleTime the schedule time
  * @param host the host url.
  * @return the Ks schedule command
  */
 protected KickstartScheduleCommand getScheduleCommand(
     DynaActionForm form, RequestContext ctx, Date scheduleTime, String host) {
   String cobblerId = form.getString(RequestContext.COBBLER_ID);
   User user = ctx.getCurrentUser();
   KickstartScheduleCommand cmd;
   KickstartData data =
       KickstartFactory.lookupKickstartDataByCobblerIdAndOrg(user.getOrg(), cobblerId);
   if (data != null) {
     cmd =
         new KickstartScheduleCommand(
             (Long) form.get(RequestContext.SID), data, ctx.getCurrentUser(), scheduleTime, host);
   } else {
     org.cobbler.Profile profile =
         org.cobbler.Profile.lookupById(CobblerXMLRPCHelper.getConnection(user), cobblerId);
     cmd =
         KickstartScheduleCommand.createCobblerScheduleCommand(
             (Long) form.get(RequestContext.SID), profile.getName(), user, scheduleTime, host);
   }
   return cmd;
 }
 /**
  * @param mapping ActionMapping
  * @param formIn ActionForm
  * @param request ServletRequest
  * @param response ServletResponse
  * @return The ActionForward to go to next.
  */
 public ActionForward processUnsubscribe(
     ActionMapping mapping,
     ActionForm formIn,
     HttpServletRequest request,
     HttpServletResponse response) {
   Map params = makeParamMap(formIn, request);
   operateOnSelectedSet(mapping, formIn, request, response, "unsubscribeSystems");
   RequestContext requestContext = new RequestContext(request);
   ConfigActionHelper.clearRhnSets(requestContext.getCurrentUser());
   return getStrutsDelegate().forwardParams(mapping.findForward("success"), params);
 }
Example #18
0
 private void grant(DynaActionForm form, ActionErrors errors, RequestContext ctx) {
   Channel c = edit(form, errors, ctx);
   // if there was no exception during the above edit
   // add all of the orgs to the "rhnchanneltrust"
   if (c != null) {
     Org org = ctx.getCurrentUser().getOrg();
     Set<Org> trustedorgs = org.getTrustedOrgs();
     c.setTrustedOrgs(trustedorgs);
     ChannelFactory.save(c);
   }
 }
Example #19
0
  /**
   * @param form form to check
   * @param errors errors to report
   * @param ctx context
   * @return Channel
   */
  private Channel deny(DynaActionForm form, ActionErrors errors, RequestContext ctx) {

    Channel c = edit(form, errors, ctx);
    User user = ctx.getCurrentUser();

    unsubscribeOrgsFromChannel(user, c, Channel.PROTECTED);

    c.getTrustedOrgs().clear();
    ChannelFactory.save(c);
    return c;
  }
  /**
   * @param form the form containing the proxy info
   * @param ctx the request context associated to this request
   * @param cmd the kicktstart command to which the proxy info will be copied..
   */
  protected void storeProxyInfo(
      DynaActionForm form, RequestContext ctx, KickstartScheduleCommand cmd) {
    // if we need to go through a proxy, do it here.
    String phost = form.getString(PROXY_HOST);
    String phostCname = form.getString(PROXY_HOST_CNAME);

    if (!StringUtils.isEmpty(phostCname)) {
      cmd.setProxyHost(phostCname);
    } else if (!StringUtils.isEmpty(phost)) {
      cmd.setProxy(SystemManager.lookupByIdAndOrg(new Long(phost), ctx.getCurrentUser().getOrg()));
    }
  }
 /**
  * {@inheritDoc}
  *
  * @throws Exception sometimes things just don't work out
  */
 public String renderAsync() throws Exception {
   WebContext ctx = WebContextFactory.get();
   HttpServletRequest req = ctx.getHttpServletRequest();
   RequestContext rhnCtx = new RequestContext(req);
   User user = rhnCtx.getCurrentUser();
   PageControl pc = new PageControl();
   pc.setStart(1);
   pc.setPageSize(PAGE_SIZE);
   render(user, pc, req);
   HttpServletResponse resp = ctx.getHttpServletResponse();
   return RendererHelper.renderRequest(getPageUrl(), req, resp);
 }
 protected ActionForward handleSubmit(ActionMapping mapping, RequestContext ctx, Server server) {
   User user = ctx.getCurrentUser();
   RhnSet set = RhnSetDecl.setForSystemCrashes(server).get(user);
   // until we delete crash files from taskomatic, we have to delete them one by one
   for (Iterator<Long> iter =
           RhnSetDecl.setForSystemCrashes(server).get(user).getElementValues().iterator();
       iter.hasNext(); ) {
     CrashManager.deleteCrash(user, iter.next());
   }
   createSuccessMessage(ctx.getRequest(), "message.crashesdeleted", Integer.toString(set.size()));
   Map<String, Object> params = new HashMap<String, Object>();
   params.put("sid", server.getId());
   return getStrutsDelegate().forwardParams(mapping.findForward("delete"), params);
 }
    /** {@inheritDoc} */
    public List getResult(RequestContext ctx) {
      Long sid = ctx.getParamAsLong(RequestContext.SID);
      User user = ctx.getCurrentUser();

      KickstartScheduleCommand cmd = getKickstartScheduleCommand(sid, user);
      DataResult profiles = cmd.getKickstartProfiles();
      if (profiles.size() == 0) {
        addMessage(ctx.getRequest(), "kickstart.schedule.noprofiles");
        ctx.getRequest().setAttribute(HAS_PROFILES, Boolean.FALSE.toString());
      } else {
        ctx.getRequest().setAttribute(HAS_PROFILES, Boolean.TRUE.toString());
      }
      return profiles;
    }
  /** {@inheritDoc} */
  public ActionForward execute(
      ActionMapping mapping,
      ActionForm formIn,
      HttpServletRequest request,
      HttpServletResponse response) {

    RequestContext requestContext = new RequestContext(request);
    User user = requestContext.getCurrentUser();
    DataList result = OrgManager.activeOrgs(user);

    request.setAttribute(ListTagHelper.PAGE_LIST, result);
    request.setAttribute(ListTagHelper.PARENT_URL, request.getRequestURI());

    return mapping.findForward(RhnHelper.DEFAULT_FORWARD);
  }
Example #25
0
  /** {@inheritDoc} */
  public ActionForward execute(
      ActionMapping mapping,
      ActionForm formIn,
      HttpServletRequest request,
      HttpServletResponse response) {

    RequestContext requestContext = new RequestContext(request);
    User user = requestContext.getCurrentUser();
    Long sid = requestContext.getRequiredParam("sid");
    RhnSet set = getSetDecl(sid).get(user);

    ListRhnSetHelper help = new ListRhnSetHelper(this, request, getSetDecl(sid));
    help.setListName(LIST_NAME);
    String parentURL = request.getRequestURI() + "?sid=" + sid;
    help.setParentUrl(parentURL);

    help.execute();

    if (help.isDispatched()) {
      if (requestContext.wasDispatched("errata.jsp.apply")) {
        return applyErrata(mapping, formIn, request, response);
      }
    }

    String showButton = "true";
    // Show the "Apply Errata" button only when unapplied errata exist:
    if (!SystemManager.hasUnscheduledErrata(user, sid)) {
      showButton = "false";
    }

    Map params = new HashMap();
    Set keys = request.getParameterMap().keySet();
    for (Iterator i = keys.iterator(); i.hasNext(); ) {
      String key = (String) i.next();
      params.put(key, request.getParameter(key));
    }

    Server server = SystemManager.lookupByIdAndUser(sid, user);
    SdcHelper.ssmCheck(request, server.getId(), user);
    request.setAttribute("showApplyErrata", showButton);
    request.setAttribute("set", set);
    request.setAttribute("system", server);
    request.setAttribute("combo", getComboList(request));
    request.setAttribute(SELECTOR, request.getParameter(SELECTOR));

    return getStrutsDelegate()
        .forwardParams(mapping.findForward(RhnHelper.DEFAULT_FORWARD), params);
  }
Example #26
0
 /** {@inheritDoc} */
 public List<OrgTrust> getResult(RequestContext ctx) {
   Org org = ctx.getCurrentUser().getOrg();
   Set<Org> trustedorgs = org.getTrustedOrgs();
   List<OrgTrust> trusts = new ArrayList<OrgTrust>();
   for (Org o : trustedorgs) {
     DataResult<Map<String, Object>> dr = SystemManager.sidsInOrgTrust(org.getId(), o.getId());
     OrgTrust trust = new OrgTrust(o);
     if (!dr.isEmpty()) {
       for (Map<String, Object> m : dr) {
         Long sid = (Long) m.get("id");
         trust.getSubscribed().add(sid);
       }
     }
     trusts.add(trust);
   }
   return trusts;
 }
  /**
   * Setup the system for provisioning with cobbler.
   *
   * @param mapping ActionMapping for struts
   * @param form DynaActionForm representing the form
   * @param ctx RequestContext request context
   * @param response HttpServletResponse response object
   * @param step WizardStep what step are we on?
   * @return ActionForward struts action forward
   * @throws Exception if something goes amiss
   */
  public ActionForward runFourth(
      ActionMapping mapping,
      DynaActionForm form,
      RequestContext ctx,
      HttpServletResponse response,
      WizardStep step)
      throws Exception {

    log.debug("runFourth");
    if (!validateFirstSelections(form, ctx)) {
      return runFirst(mapping, form, ctx, response, step);
    }
    Long sid = (Long) form.get(RequestContext.SID);
    String cobblerId = form.getString(RequestContext.COBBLER_ID);

    log.debug("runFourth.cobblerId: " + cobblerId);

    User user = ctx.getCurrentUser();
    Server server = SystemManager.lookupByIdAndUser(sid, user);

    Map params = new HashMap();
    params.put(RequestContext.SID, sid);

    log.debug("Creating cobbler system record");
    org.cobbler.Profile profile =
        org.cobbler.Profile.lookupById(CobblerXMLRPCHelper.getConnection(user), cobblerId);

    KickstartData data =
        KickstartFactory.lookupKickstartDataByCobblerIdAndOrg(user.getOrg(), profile.getUid());

    if (showDiskWarning(data, form)) {
      form.set(NEXT_ACTION, "fourth");
      return mapping.findForward("fifth");
    }

    CobblerSystemCreateCommand cmd =
        new CobblerSystemCreateCommand(server, profile.getName(), data);
    cmd.store();
    log.debug("cobbler system record created.");
    String[] args = new String[2];
    args[0] = server.getName();
    args[1] = profile.getName();
    createMessage(ctx.getRequest(), "kickstart.schedule.cobblercreate", args);
    return getStrutsDelegate().forwardParams(mapping.findForward("cobbler-success"), params);
  }
 /** {@inheritDoc} */
 public ActionForward execute(
     ActionMapping mapping,
     ActionForm formIn,
     HttpServletRequest request,
     HttpServletResponse response) {
   RequestContext ctx = new RequestContext(request);
   Server server = ctx.lookupAndBindServer();
   User user = ctx.getCurrentUser();
   SdcHelper.ssmCheck(ctx.getRequest(), server.getId(), user);
   DynaActionForm form = (DynaActionForm) formIn;
   SystemRecord rec = (SystemRecord) getCobblerObject(server.getCobblerId(), user);
   if (isSubmitted(form)) {
     if (!Boolean.valueOf(rec.isNetbootEnabled()).equals(form.get(NETBOOT_ENABLED))) {
       rec.enableNetboot(Boolean.TRUE.equals(form.get(NETBOOT_ENABLED)));
       rec.save();
     }
   }
   form.set(NETBOOT_ENABLED, rec.isNetbootEnabled());
   return super.execute(mapping, formIn, request, response);
 }
  /** {@inheritDoc} */
  public ActionForward execute(
      ActionMapping mapping,
      ActionForm formIn,
      HttpServletRequest request,
      HttpServletResponse response) {

    RequestContext context = new RequestContext(request);
    context.copyParamToAttributes("sid");
    Server server = context.lookupAndBindServer();

    ListRhnSetHelper helper =
        new ListRhnSetHelper(this, request, RhnSetDecl.setForSystemCrashes(server));
    helper.execute();
    if (helper.isDispatched()) {
      return handleSubmit(mapping, context, server);
    }

    SdcHelper.ssmCheck(request, server.getId(), context.getCurrentUser());

    return mapping.findForward(RhnHelper.DEFAULT_FORWARD);
  }
  /**
   * Sets up the proxy information for the wizard. its public in this class because we reuse this in
   * SSM and only this class knows how to format the name nicely.
   *
   * @param ctx the request context needed for user info and things to bind to the request
   */
  public static void setupProxyInfo(RequestContext ctx) {
    List<OrgProxyServer> proxies = SystemManager.listProxies(ctx.getCurrentUser().getOrg());
    if (proxies != null && proxies.size() > 0) {
      List<LabelValueBean> formatted = new LinkedList<LabelValueBean>();

      formatted.add(lvl10n("kickstart.schedule.default.proxy.jsp", ""));
      Map cnames = new HashMap();
      for (OrgProxyServer serv : proxies) {
        formatted.add(lv(serv.getName() + " (" + serv.getCheckin() + ")", serv.getId().toString()));
        List proxyCnames = Config.get().getList(VALID_CNAMES + serv.getId().toString());
        if (!proxyCnames.isEmpty()) {
          cnames.put(serv.getId().toString(), proxyCnames);
        }
      }
      ctx.getRequest().setAttribute(HAS_PROXIES, Boolean.TRUE.toString());
      ctx.getRequest().setAttribute(PROXIES, formatted);
      ctx.getRequest().setAttribute(CNAMES, cnames);
    } else {
      ctx.getRequest().setAttribute(HAS_PROXIES, Boolean.FALSE.toString());
    }
  }