protected void Page_Load(object sender, EventArgs e) { WebJsonResponse ret = null; try { String p = Tools.Tool.TrataInjection(Request["password"]); PasswordStrength pwdcheck = new PasswordStrength(); pwdcheck.SetPassword(p); Color cor = pwdcheck.GetStrengthColor(); ret = new WebJsonResponse("#passwordStrength", "<label>" + MessageResource.GetMessage("password_strength") + "</label><div class=\"form-group-content\"><span>" + pwdcheck.GetPasswordStrength() + "</span><div class=\"bar\" style=\"background: rgb(" + cor.R + "," + cor.G + "," + cor.B + ")\"></div></div>"); } catch (Exception ex) { Tools.Tool.notifyException(ex); throw ex; } if (ret != null) { ReturnHolder.Controls.Add(new LiteralControl(ret.ToJSON())); } }
protected void Page_Load(object sender, EventArgs e) { WebJsonResponse ret = null; try { LoginResult auth = LoginUser.AuthUser(this, Request["userLogin"], Request["password"]); if ((auth.Status) && (auth.ChangePassword) && (Session["login"] is LoginData)) { Session["entity_id"] = ((LoginData)Session["login"]).Id; Session["login"] = null; ret = new WebJsonResponse("/login/changepassword/"); } else if ((auth.Status) && (Session["login"] is LoginData)) { Int64 enterpriseId = 0; LoginData login = (LoginData)Session["login"]; if ((Session["enterprise_data"]) != null && (Session["enterprise_data"] is EnterpriseData)) { enterpriseId = ((EnterpriseData)Session["enterprise_data"]).Id; } ret = new WebJsonResponse(Session["ApplicationVirtualPath"] + "autoservice/"); using (IAMDatabase database = new IAMDatabase(IAMDatabase.GetWebConnectionString())) { try { using (IAMRBAC rbac = new IAMRBAC()) if (rbac.UserAdmin(database, login.Id, enterpriseId)) { ret = new WebJsonResponse(Session["ApplicationVirtualPath"] + "admin/"); } } catch { } } } else { ret = new WebJsonResponse("", auth.Text, 3000, true); } } catch (Exception ex) { Tools.Tool.notifyException(ex); throw ex; } if (ret != null) { ReturnHolder.Controls.Add(new LiteralControl(ret.ToJSON())); } }
protected void Page_Load(object sender, EventArgs e) { WebJsonResponse ret = new WebJsonResponse(Session["ApplicationVirtualPath"] + "admin/"); if (ret != null) { ReturnHolder.Controls.Add(new LiteralControl(ret.ToJSON())); } }
protected void Page_Load(object sender, EventArgs e) { WebJsonResponse ret = null; //if (Request.HttpMethod == "POST") //{ if (!EnterpriseIdentify.Identify(this, true)) //Se houver falha na identificação da empresa finaliza a resposta { return; } try { if ((RouteData.Values["module"] == null) || (RouteData.Values["module"].ToString() == "")) { ret = new WebJsonResponse("", MessageResource.GetMessage("invalid_module"), 3000, true); } else { LoadPage("/_admin/chartdata/" + RouteData.Values["module"] + ".aspx"); } } catch (Exception ex) { if ((ex is HttpException) && (((HttpException)ex).GetHttpCode() == 404)) { ret = new WebJsonResponse("", MessageResource.GetMessage("not_implemented"), 3000, true); } else { ret = new WebJsonResponse("", MessageResource.GetMessage("api_error"), 3000, true); } try { using (IAMDatabase db = new IAMDatabase(IAMDatabase.GetWebConnectionString())) db.AddUserLog(LogKey.API_Error, null, "AdminAPI", UserLogLevel.Error, 0, (((Page.Session["enterprise_data"]) != null && (Page.Session["enterprise_data"] is EnterpriseData) && (((EnterpriseData)Page.Session["enterprise_data"]).Id != null)) ? ((EnterpriseData)Page.Session["enterprise_data"]).Id : 0), 0, 0, 0, 0, 0, "API error: " + ex.Message, "{ \"ipaddr\":\"" + Tools.Tool.GetIPAddress() + "\"} "); } catch { } Tools.Tool.notifyException(ex, this); } /*} * else * { * ret = new WebJsonResponse("", MessageResource.GetMessage("invalid_http_method"), 3000, true); * }*/ if (ret != null) { Retorno.Controls.Add(new LiteralControl(ret.ToJSON())); } }
protected void Page_Load(object sender, EventArgs e) { WebJsonResponse ret = null; Session.Abandon(); ret = new WebJsonResponse("/"); if (ret != null) { ReturnHolder.Controls.Add(new LiteralControl(ret.ToJSON())); } }
protected void Page_Load(object sender, EventArgs e) { WebJsonResponse ret = null; try { LoginData login = LoginUser.LogedUser(this); String err = ""; if (!EnterpriseIdentify.Identify(this, false, out err)) //Se houver falha na identificação da empresa finaliza a resposta { ret = new WebJsonResponse("", err, 3000, true); } else if (login == null) { ret = new WebJsonResponse("", MessageResource.GetMessage("expired_session"), 3000, true, "/login/"); } else { String container = Request.Form["container"]; String field = Request.Form["field"]; String id = field + Guid.NewGuid().ToString(); String html = ""; String content = "<div >{0}</div>"; html = "teste ok - " + field; ret = new WebJsonResponse(container, String.Format(content, html), true); } } catch (Exception ex) { Tools.Tool.notifyException(ex); throw ex; } if (ret != null) { ReturnHolder.Controls.Add(new LiteralControl(ret.ToJSON())); } }
protected void Page_Load(object sender, EventArgs e) { WebJsonResponse ret = null; //ResourceManager rm = new ResourceManager("Resources.Strings", System.Reflection.Assembly.Load("App_GlobalResources")); //CultureInfo ci = Thread.CurrentThread.CurrentCulture; try { Int64 enterpriseID = ((EnterpriseData)Page.Session["enterprise_data"]).Id; Int64 entityId = 0; String err = ""; entityId = LoginUser.FindUser(this, Request["userLogin"], out err); if (entityId > 0) { Session["entityId"] = entityId; LoginUser.NewCode(this, entityId, out err); if (err == "") { String html = ""; using (IAMDatabase db = new IAMDatabase(IAMDatabase.GetWebConnectionString())) { DataTable c = db.Select("select * from vw_entity_confirmations where enterprise_id = " + enterpriseID + " and entity_id = " + entityId); html += "<form id=\"serviceRecover\" name=\"serviceRecover\" method=\"post\" action=\"/consoleapi/recover2/\">"; if ((c != null) && (c.Rows.Count > 0)) { html += "<div class=\"login_form\">"; html += "<input type=\"hidden\" name=\"do\" value=\"recover2\" />"; html += "<ul>"; html += " <li>"; html += " <p style=\"width:100%;padding:0 0 5px 0;color:#000;\">" + MessageResource.GetMessage("send_conf_to") + "</p>"; html += " </li>"; foreach (DataRow dr in c.Rows) { String data = LoginUser.MaskData(dr["value"].ToString(), (Boolean)dr["is_mail"], (Boolean)dr["is_sms"]); if (data != "") { html += " <li><p style=\"width:400px;padding:0 0 5px 10px;color:#000;\"><input name=\"sentTo\" type=\"radio\" value=\"" + data + "\">" + data + "</p></li>"; } } html += " <li>"; html += " <span class=\"forgot\"> <a href=\"/\">" + MessageResource.GetMessage("cancel") + "</a> " + MessageResource.GetMessage("or") + " </span>"; html += " <button tabindex=\"4\" id=\"submitBtn\" class=\"action button floatright\">" + MessageResource.GetMessage("send_code") + "</button>"; html += " </li>"; html += "</ul> "; html += "</div>"; } else { html += "<div class=\"login_form\">"; html += "<input type=\"hidden\" name=\"do\" value=\"recover2\" />"; html += "<ul>"; html += " <li>"; html += " <p style=\"width:100%;padding:0 0 5px 0;color:#000;\">No method available</p>"; html += " </li>"; html += " <li>"; html += " <span class=\"forgot\"> <a href=\"/\">" + MessageResource.GetMessage("cancel") + "</a></span>"; html += " </li>"; html += "</ul> "; html += "</div>"; } html += "</form>"; } //ret = new WebJsonResponse("recover1.aspx"); ret = new WebJsonResponse("#recover_container", html); } else { ret = new WebJsonResponse("", err, 3000, true); } } else { ret = new WebJsonResponse("", err, 3000, true); } } catch (Exception ex) { Tools.Tool.notifyException(ex); throw ex; } if (ret != null) { ReturnHolder.Controls.Add(new LiteralControl(ret.ToJSON())); } }
protected void Page_Load(object sender, EventArgs e) { WebJsonResponse ret = null; try { LoginData login = LoginUser.LogedUser(this); String err = ""; if (!EnterpriseIdentify.Identify(this, false, out err)) //Se houver falha na identificação da empresa finaliza a resposta { ret = new WebJsonResponse("", err, 3000, true); } else if (login == null) { ret = new WebJsonResponse("", MessageResource.GetMessage("expired_session"), 3000, true, "/login/"); } else { using (IAMDatabase db = new IAMDatabase(IAMDatabase.GetWebConnectionString())) { DataTable c = db.Select("select * from entity where deleted = 0 and id = " + login.Id); if ((c != null) && (c.Rows.Count > 0)) { String html = ""; String content = "<div>{0}</div>"; html = ""; html += "<form id=\"serviceRecover\" name=\"serviceRecover\" method=\"post\" action=\"/consoleapi/changepassword/\" onsubmit=\"return iam.GenericSubmit('#serviceRecover');\">"; html += "<div class=\"login_form\">"; html += "<h1>" + MessageResource.GetMessage("change_password_title") + "</h1> "; html += "<ul>"; html += " <li>"; html += " <p style=\"width:100%;padding:0 0 5px 0;color:#000;\">" + MessageResource.GetMessage("change_password_text") + "</p>"; html += " </li>"; html += " <li>"; html += " <span class=\"inputWrap\">"; html += " <span id=\"ph_current_password\" class=\"noSel\" style=\"position: absolute; z-index: 1; top: 13px; left: 53px; color: rgb(204, 204, 204); display: block;\">"+ MessageResource.GetMessage("current_password") + "</span>"; html += " <input type=\"password\" id=\"current_password\" tabindex=\"1\" name=\"current_password\" value=\"\" style=\"\" onkeyup=\"fnLogin.keyup('current_password');\" onfocus=\"$('#current_password').addClass('focus'); fnLogin.keyup('password');\" onblur=\"$('#current_password').removeClass('focus');\" />"; html += " <span id=\"ph_passwordIcon\" onclick=\"$('#password').focus();\"></span>"; html += " </span>"; html += " </li>"; html += " <li>"; html += " <span class=\"inputWrap\">"; html += " <span id=\"ph_password\" class=\"noSel\" style=\"position: absolute; z-index: 1; top: 13px; left: 53px; color: rgb(204, 204, 204); display: block;\">"+ MessageResource.GetMessage("new_password") + "</span>"; html += " <input type=\"password\" id=\"password\" tabindex=\"1\" name=\"password\" value=\"\" style=\"\" onkeyup=\"fnLogin.keyup('password'); iam.passwordStrength('#password');\" onfocus=\"$('#password').addClass('focus'); fnLogin.keyup('password');\" onblur=\"$('#password').removeClass('focus');\" />"; html += " <span id=\"ph_passwordIcon\" onclick=\"$('#password').focus();\"></span>"; html += " </span>"; html += " </li>"; html += " <li>"; html += " <span class=\"inputWrap\">"; html += " <span id=\"ph_password2\" class=\"noSel\" style=\"position: absolute; z-index: 1; top: 13px; left: 53px; color: rgb(204, 204, 204); display: block;\">"+ MessageResource.GetMessage("new_password_confirm") + "</span>"; html += " <input type=\"password\" id=\"password2\" tabindex=\"1\" name=\"password2\" value=\"\" style=\"\" onkeyup=\"fnLogin.keyup('password2');\" onfocus=\"$('#password2').addClass('focus'); fnLogin.keyup('password2');\" onblur=\"$('#password2').removeClass('focus');\" />"; html += " <span id=\"ph_passwordIcon\" onclick=\"$('#password2').focus();\"></span>"; html += " </span>"; html += " </li>"; html += " <li>"; html += " <div id=\"passwordStrength\"><span>" + MessageResource.GetMessage("password_strength") + ": " + MessageResource.GetMessage("unknow") + "</span><div class=\"bar\"></div></div>"; html += " </li>"; html += " <li>"; html += " <span class=\"forgot\"> <a class=\"cancel\">" + MessageResource.GetMessage("cancel") + "</a></span>"; html += " <input type=\"submit\" tabindex=\"4\" id=\"submitBtn\" value=\"" + MessageResource.GetMessage("change_password") + "\" class=\"action btn btn-success\" />"; html += " </li>"; html += "</ul> "; html += "</div>"; html += "</form>"; ret = new WebJsonResponse("#pn-password .content", String.Format(content, html)); } else { ret = new WebJsonResponse("", MessageResource.GetMessage("valid_username"), 3000, true); } } } } catch (Exception ex) { Tools.Tool.notifyException(ex); throw ex; } if (ret != null) { ReturnHolder.Controls.Add(new LiteralControl(ret.ToJSON())); } }
protected void Page_Load(object sender, EventArgs e) { WebJsonResponse contentRet = null; Int64 requestId = 0; try { requestId = Int64.Parse((String)RouteData.Values["id"]); if (requestId < 0) { requestId = 0; } } catch { } String action = ""; if (!String.IsNullOrWhiteSpace((String)RouteData.Values["action"])) { action = (String)RouteData.Values["action"]; } if (requestId == 0) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("access_request_not_found"), 3000, true); action = ""; } String rData = ""; //SqlConnection //conn = DB.GetConnection(); String jData = ""; try { switch (action) { case "allow": rData = JSON.Serialize2(new { jsonrpc = "1.0", method = "workflow.accessrequestallow", parameters = new { requestid = requestId }, id = 1 }); using (IAMDatabase database = new IAMDatabase(IAMDatabase.GetWebConnectionString())) jData = WebPageAPI.ExecuteLocal(database, this, rData); if (String.IsNullOrWhiteSpace(jData)) { throw new Exception(""); } BooleanResult retA = JSON.Deserialize <BooleanResult>(jData); if (retA == null) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("access_request_not_found"), 3000, true); } else if (retA.error != null) { contentRet = new WebJsonResponse("", retA.error.data, 3000, true); } else if (!retA.result) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("access_request_not_found"), 3000, true); } else { contentRet = new WebJsonResponse("", "Requisição aprovada com sucesso", 3000, false); contentRet.containerId = "#request_" + requestId; contentRet.html = " "; } break; case "deny": rData = JSON.Serialize2(new { jsonrpc = "1.0", method = "workflow.accessrequestdeny", parameters = new { requestid = requestId }, id = 1 }); using (IAMDatabase database = new IAMDatabase(IAMDatabase.GetWebConnectionString())) jData = WebPageAPI.ExecuteLocal(database, this, rData); if (String.IsNullOrWhiteSpace(jData)) { throw new Exception(""); } BooleanResult retD = JSON.Deserialize <BooleanResult>(jData); if (retD == null) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("access_request_not_found"), 3000, true); } else if (retD.error != null) { contentRet = new WebJsonResponse("", retD.error.data, 3000, true); } else if (!retD.result) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("access_request_not_found"), 3000, true); } else { contentRet = new WebJsonResponse("", "Requisição negada com sucesso", 3000, false); contentRet.containerId = "#request_" + requestId; contentRet.html = " "; } break; case "revoke": rData = JSON.Serialize2(new { jsonrpc = "1.0", method = "workflow.accessrequestrevoke", parameters = new { requestid = requestId }, id = 1 }); using (IAMDatabase database = new IAMDatabase(IAMDatabase.GetWebConnectionString())) jData = WebPageAPI.ExecuteLocal(database, this, rData); if (String.IsNullOrWhiteSpace(jData)) { throw new Exception(""); } BooleanResult retR = JSON.Deserialize <BooleanResult>(jData); if (retR == null) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("access_request_not_found"), 3000, true); } else if (retR.error != null) { contentRet = new WebJsonResponse("", retR.error.data, 3000, true); } else if (!retR.result) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("access_request_not_found"), 3000, true); } else { contentRet = new WebJsonResponse("", "Acesso revogada com sucesso", 3000, false); contentRet.containerId = "#request_" + requestId; contentRet.html = " "; } break; } } catch (Exception ex) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("api_error"), 3000, true); } finally { } if (contentRet != null) { if (!String.IsNullOrWhiteSpace((String)Request["cid"])) { contentRet.callId = (String)Request["cid"]; } Retorno.Controls.Add(new LiteralControl(contentRet.ToJSON())); } }
protected void Page_Load(object sender, EventArgs e) { WebJsonResponse contentRet = null; String action = ""; if (!String.IsNullOrWhiteSpace((String)RouteData.Values["action"])) { action = (String)RouteData.Values["action"]; } Int64 roleId = 0; if (action != "add_role") { try { roleId = Int64.Parse((String)RouteData.Values["id"]); if (roleId < 0) { roleId = 0; } } catch { } if (roleId == 0) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("role_not_found"), 3000, true); action = ""; } } String rData = ""; //SqlConnection //conn = DB.GetConnection(); String jData = ""; try { switch (action) { case "delete": var reqDel = new { jsonrpc = "1.0", method = "role.delete", parameters = new { roleid = roleId }, id = 1 }; rData = JSON.Serialize2(reqDel); using (IAMDatabase database = new IAMDatabase(IAMDatabase.GetWebConnectionString())) jData = WebPageAPI.ExecuteLocal(database, this, rData); if (String.IsNullOrWhiteSpace(jData)) { throw new Exception(""); } RoleDeleteResult retDel = JSON.Deserialize <RoleDeleteResult>(jData); if (retDel == null) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("role_not_found"), 3000, true); } else if (retDel.error != null) { contentRet = new WebJsonResponse("", retDel.error.data, 3000, true); } else if (!retDel.result) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("role_not_found"), 3000, true); } else { contentRet = new WebJsonResponse(); } break; case "delete_all_users": var reqDelUsr = new { jsonrpc = "1.0", method = "role.deleteallusers", parameters = new { roleid = roleId }, id = 1 }; rData = JSON.Serialize2(reqDelUsr); using (IAMDatabase database = new IAMDatabase(IAMDatabase.GetWebConnectionString())) jData = WebPageAPI.ExecuteLocal(database, this, rData); if (String.IsNullOrWhiteSpace(jData)) { throw new Exception(""); } RoleDeleteResult retDelUsr = JSON.Deserialize <RoleDeleteResult>(jData); if (retDelUsr == null) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("role_not_found"), 3000, true); } else if (retDelUsr.error != null) { contentRet = new WebJsonResponse("", retDelUsr.error.data, 3000, true); } else if (!retDelUsr.result) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("role_not_found"), 3000, true); } else { contentRet = new WebJsonResponse(); } break; case "delete_user": var reqDelUsr2 = new { jsonrpc = "1.0", method = "role.deleteuser", parameters = new { roleid = roleId, userid = (String)RouteData.Values["filter"] }, id = 1 }; rData = JSON.Serialize2(reqDelUsr2); using (IAMDatabase database = new IAMDatabase(IAMDatabase.GetWebConnectionString())) jData = WebPageAPI.ExecuteLocal(database, this, rData); if (String.IsNullOrWhiteSpace(jData)) { throw new Exception(""); } RoleDeleteResult retDelUsr2 = JSON.Deserialize <RoleDeleteResult>(jData); if (retDelUsr2 == null) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("role_not_found"), 3000, true); } else if (retDelUsr2.error != null) { contentRet = new WebJsonResponse("", retDelUsr2.error.data, 3000, true); } else if (!retDelUsr2.result) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("role_not_found"), 3000, true); } else { contentRet = new WebJsonResponse(); } break; case "change_name": String name = Request.Form["name"]; if (String.IsNullOrEmpty(name)) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("invalid_name"), 3000, true); break; } var reqD = new { jsonrpc = "1.0", method = "role.change", parameters = new { roleid = roleId, name = name }, id = 1 }; rData = JSON.Serialize2(reqD); using (IAMDatabase database = new IAMDatabase(IAMDatabase.GetWebConnectionString())) jData = WebPageAPI.ExecuteLocal(database, this, rData); if (String.IsNullOrWhiteSpace(jData)) { throw new Exception(""); } RoleGetResult retD = JSON.Deserialize <RoleGetResult>(jData); if (retD == null) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("role_not_found"), 3000, true); } else if (retD.error != null) { contentRet = new WebJsonResponse("", retD.error.data, 3000, true); } else if (retD.result == null) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("role_not_found"), 3000, true); } else if (retD.result == null || retD.result.info == null) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("role_not_found"), 3000, true); } else { contentRet = new WebJsonResponse("#role_name_" + roleId, retD.result.info.name); } break; case "add_user": String user_id = Request.Form["user_id"]; if (String.IsNullOrEmpty(user_id)) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("select_username"), 3000, true); break; } var reqAdd = new { jsonrpc = "1.0", method = "role.adduser", parameters = new { roleid = roleId, userid = user_id }, id = 1 }; rData = JSON.Serialize2(reqAdd); using (IAMDatabase database = new IAMDatabase(IAMDatabase.GetWebConnectionString())) jData = WebPageAPI.ExecuteLocal(database, this, rData); if (String.IsNullOrWhiteSpace(jData)) { throw new Exception(""); } RoleDeleteResult retAdd = JSON.Deserialize <RoleDeleteResult>(jData); if (retAdd == null) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("role_not_found"), 3000, true); } else if (retAdd.error != null) { contentRet = new WebJsonResponse("", retAdd.error.data, 3000, true); //Tools.Tool.notifyException(new Exception(retAdd.error.data + retAdd.error.debug), this); } else if (!retAdd.result) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("role_not_found"), 3000, true); } else { contentRet = new WebJsonResponse(Session["ApplicationVirtualPath"] + "admin/roles/" + (Request.Form["hashtag"] != null ? "#" + Request.Form["hashtag"].ToString() : "")); } // break; case "add_role": String roleName = Request.Form["add_role_name"]; if (String.IsNullOrEmpty(roleName)) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("type_role_name"), 3000, true); break; } String context_id = Request.Form["add_role_context"]; if (String.IsNullOrEmpty(context_id)) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("select_context"), 3000, true); break; } var reqAddR = new { jsonrpc = "1.0", method = "role.new", parameters = new { name = roleName, contextid = context_id, parentid = 0 }, id = 1 }; rData = JSON.Serialize2(reqAddR); using (IAMDatabase database = new IAMDatabase(IAMDatabase.GetWebConnectionString())) jData = WebPageAPI.ExecuteLocal(database, this, rData); if (String.IsNullOrWhiteSpace(jData)) { throw new Exception(""); } RoleGetResult retAddR = JSON.Deserialize <RoleGetResult>(jData); if (retAddR == null) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("role_not_found"), 3000, true); } else if (retAddR.error != null) { contentRet = new WebJsonResponse("", retAddR.error.data, 3000, true); //Tools.Tool.notifyException(new Exception(retAdd.error.data + retAdd.error.debug), this); } else if ((retAddR.result == null) || (retAddR.result.info == null)) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("role_not_found"), 3000, true); } else { contentRet = new WebJsonResponse(Session["ApplicationVirtualPath"] + "admin/roles/" + retAddR.result.info.role_id + "/add_user/" + (Request.Form["hashtag"] != null ? "#" + Request.Form["hashtag"].ToString() : "")); } // break; } } catch (Exception ex) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("api_error"), 3000, true); } finally { } if (contentRet != null) { if (!String.IsNullOrWhiteSpace((String)Request["cid"])) { contentRet.callId = (String)Request["cid"]; } Retorno.Controls.Add(new LiteralControl(contentRet.ToJSON())); } }
protected void Page_Load(object sender, EventArgs e) { WebJsonResponse contentRet = null; String action = ""; if (!String.IsNullOrWhiteSpace((String)RouteData.Values["action"])) { action = (String)RouteData.Values["action"]; } Int64 fieldId = 0; if (action != "add_field") { try { fieldId = Int64.Parse((String)RouteData.Values["id"]); if (fieldId < 0) { fieldId = 0; } } catch { } if (fieldId == 0) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("field_not_found"), 3000, true); action = ""; } } String rData = ""; //SqlConnection //conn = DB.GetConnection(); String jData = ""; try { switch (action) { case "delete": var reqDel = new { jsonrpc = "1.0", method = "field.delete", parameters = new { fieldid = fieldId }, id = 1 }; rData = JSON.Serialize2(reqDel); using (IAMDatabase database = new IAMDatabase(IAMDatabase.GetWebConnectionString())) jData = WebPageAPI.ExecuteLocal(database, this, rData); if (String.IsNullOrWhiteSpace(jData)) { throw new Exception(""); } FieldDeleteResult retDel = JSON.Deserialize <FieldDeleteResult>(jData); if (retDel == null) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("field_not_found"), 3000, true); } else if (retDel.error != null) { contentRet = new WebJsonResponse("", retDel.error.data, 3000, true); } else if (!retDel.result) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("field_not_found"), 3000, true); } else { contentRet = new WebJsonResponse(); } break; case "add_field": String name = Request.Form["field_name"]; if (String.IsNullOrEmpty(name)) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("invalid_name"), 3000, true); break; } String data_type = Request.Form["data_type"]; if (String.IsNullOrEmpty(data_type)) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("select_data_type"), 3000, true); break; } var reqN = new { jsonrpc = "1.0", method = "field.new", parameters = new { name = name, data_type = data_type, public_field = (!String.IsNullOrEmpty(Request.Form["public"]) ? true : false), user_field = (!String.IsNullOrEmpty(Request.Form["user"]) ? true : false) }, id = 1 }; rData = JSON.Serialize2(reqN); using (IAMDatabase database = new IAMDatabase(IAMDatabase.GetWebConnectionString())) jData = WebPageAPI.ExecuteLocal(database, this, rData); if (String.IsNullOrWhiteSpace(jData)) { throw new Exception(""); } FieldGetResult retN = JSON.Deserialize <FieldGetResult>(jData); if (retN == null) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("field_not_found"), 3000, true); } else if (retN.error != null) { contentRet = new WebJsonResponse("", retN.error.data, 3000, true); } else if (retN.result == null) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("field_not_found"), 3000, true); } else if (retN.result == null || retN.result.info == null) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("field_not_found"), 3000, true); } else { contentRet = new WebJsonResponse(Session["ApplicationVirtualPath"] + "admin/field/" + retN.result.info.field_id + "/"); } break; case "change": String name1 = Request.Form["name"]; if (String.IsNullOrEmpty(name1)) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("invalid_name"), 3000, true); break; } String data_type1 = Request.Form["data_type"]; if (String.IsNullOrEmpty(data_type1)) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("select_data_type"), 3000, true); break; } var reqC = new { jsonrpc = "1.0", method = "field.change", parameters = new { fieldid = fieldId, name = name1, data_type = data_type1, public_field = (!String.IsNullOrEmpty(Request.Form["public"]) ? true : false), user_field = (!String.IsNullOrEmpty(Request.Form["user"]) ? true : false) }, id = 1 }; rData = JSON.Serialize2(reqC); using (IAMDatabase database = new IAMDatabase(IAMDatabase.GetWebConnectionString())) jData = WebPageAPI.ExecuteLocal(database, this, rData); if (String.IsNullOrWhiteSpace(jData)) { throw new Exception(""); } FieldGetResult retC = JSON.Deserialize <FieldGetResult>(jData); if (retC == null) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("field_not_found"), 3000, true); } else if (retC.error != null) { contentRet = new WebJsonResponse("", retC.error.data, 3000, true); } else if (retC.result == null) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("field_not_found"), 3000, true); } else if (retC.result == null || retC.result.info == null) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("field_not_found"), 3000, true); } else { contentRet = new WebJsonResponse(Session["ApplicationVirtualPath"] + "admin/field/" + retC.result.info.field_id + "/"); } break; } } catch (Exception ex) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("api_error"), 3000, true); } finally { } if (contentRet != null) { if (!String.IsNullOrWhiteSpace((String)Request["cid"])) { contentRet.callId = (String)Request["cid"]; } Retorno.Controls.Add(new LiteralControl(contentRet.ToJSON())); } }
protected void Page_Load(object sender, EventArgs e) { WebJsonResponse contentRet = null; Int64 userId = 0; try { userId = Int64.Parse((String)RouteData.Values["id"]); if (userId < 0) { userId = 0; } } catch { } String action = ""; if (!String.IsNullOrWhiteSpace((String)RouteData.Values["action"])) { action = (String)RouteData.Values["action"]; } if ((userId == 0) && (action != "add_user")) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("user_not_found"), 3000, true); action = ""; } String rData = ""; //SqlConnection //conn = DB.GetConnection(); String jData = ""; try { switch (action) { case "add_user": Int64 rpId = 0; try { rpId = Int64.Parse((String)Request.Form["resource_plugin"]); if (rpId < 0) { rpId = 0; } } catch { } String[] fItems = (String.IsNullOrEmpty(Request.Form["field_id"]) ? new String[0] : Request.Form["field_id"].Split(",".ToCharArray())); if (fItems.Length == 0) { contentRet = new WebJsonResponse("", "Nenhum campo mapeado", 3000, false); break; } List <Dictionary <String, String> > properties = new List <Dictionary <String, String> >(); WebJsonResponse iError = null; foreach (String sfId in fItems) { Int64 fId = 0; try { fId = Int64.Parse(sfId); String[] values = (String.IsNullOrEmpty(Request.Form[sfId]) ? new String[0] : Request.Form[sfId].Split(",".ToCharArray())); foreach (String v in values) { if (!String.IsNullOrWhiteSpace(v)) { Dictionary <String, String> newItem = new Dictionary <string, string>(); newItem.Add("field_id", fId.ToString()); newItem.Add("value", v.Trim()); properties.Add(newItem); } } } catch { iError = new WebJsonResponse("", "Campo '" + fId + "' inválido", 3000, false); break; } } if (iError != null) { contentRet = iError; break; } if (properties.Count == 0) { contentRet = new WebJsonResponse("", "Nenhum campo mapeado", 3000, false); break; } rData = SafeTrend.Json.JSON.Serialize2(new { jsonrpc = "1.0", method = "user.new", parameters = new { resourcepluginid = rpId, properties = properties }, id = 1 }); using (IAMDatabase database = new IAMDatabase(IAMDatabase.GetWebConnectionString())) jData = WebPageAPI.ExecuteLocal(database, this, rData); if (String.IsNullOrWhiteSpace(jData)) { throw new Exception(""); } GetResult retNew = JSON.Deserialize <GetResult>(jData); if (retNew == null) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("user_not_found"), 3000, true); } else if (retNew.error != null) { contentRet = new WebJsonResponse("", retNew.error.data, 3000, true); } else if (retNew.result == null) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("user_not_found"), 3000, true); } else { contentRet = new WebJsonResponse(Session["ApplicationVirtualPath"] + "admin/users/" + retNew.result.info.userid + "/"); } break; case "deploy": var reqD = new { jsonrpc = "1.0", method = "user.deploy", parameters = new { userid = userId }, id = 1 }; rData = JSON.Serialize2(reqD); using (IAMDatabase database = new IAMDatabase(IAMDatabase.GetWebConnectionString())) jData = WebPageAPI.ExecuteLocal(database, this, rData); if (String.IsNullOrWhiteSpace(jData)) { throw new Exception(""); } Logs retD = JSON.Deserialize <Logs>(jData); if (retD == null) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("user_not_found"), 3000, true); } else if (retD.error != null) { contentRet = new WebJsonResponse("", retD.error.data, 3000, true); } else if (retD.result == null) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("user_not_found"), 3000, true); } else { contentRet = new WebJsonResponse("", "Dados do usuário enviados para replicação", 3000, false); } break; case "change_container": String containerId = Request.Form["container"]; if (String.IsNullOrEmpty(containerId)) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("select_container"), 3000, true); break; } var reqAdd = new { jsonrpc = "1.0", method = "user.changecontainer", parameters = new { containerid = containerId, userid = userId }, id = 1 }; rData = JSON.Serialize2(reqAdd); using (IAMDatabase database = new IAMDatabase(IAMDatabase.GetWebConnectionString())) jData = WebPageAPI.ExecuteLocal(database, this, rData); if (String.IsNullOrWhiteSpace(jData)) { throw new Exception(""); } BooleanResult retCCont = JSON.Deserialize <BooleanResult>(jData); if (retCCont == null) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("user_not_found"), 3000, true); } else if (retCCont.error != null) { contentRet = new WebJsonResponse("", retCCont.error.data, 3000, true); //Tools.Tool.notifyException(new Exception(retAdd.error.data + retAdd.error.debug), this); } else if (!retCCont.result) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("user_not_found"), 3000, true); } else { contentRet = new WebJsonResponse(Session["ApplicationVirtualPath"] + "admin/users/" + userId); } break; case "change_property": List <Dictionary <String, String> > prop = new List <Dictionary <String, String> >(); String[] findex = (String.IsNullOrEmpty(Request.Form["field_index"]) ? new String[0] : Request.Form["field_index"].Split(",".ToCharArray())); foreach (String sfId in findex) { if ((!String.IsNullOrEmpty(Request.Form["field_id_" + sfId])) && (!String.IsNullOrEmpty(Request.Form["field_value_" + sfId]))) { Int64 fieldId = Int64.Parse(Request.Form["field_id_" + sfId]); Dictionary <String, String> newItem = new Dictionary <string, string>(); newItem.Add("field_id", fieldId.ToString()); newItem.Add("value", Request.Form["field_value_" + sfId]); prop.Add(newItem); } } rData = SafeTrend.Json.JSON.Serialize2(new { jsonrpc = "1.0", method = "user.changeproperty", parameters = new { userid = userId, properties = prop }, id = 1 }); using (IAMDatabase database = new IAMDatabase(IAMDatabase.GetWebConnectionString())) jData = WebPageAPI.ExecuteLocal(database, this, rData); if (String.IsNullOrWhiteSpace(jData)) { throw new Exception(""); } GetResult retChange = JSON.Deserialize <GetResult>(jData); if (retChange == null) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("user_not_found"), 3000, true); } else if (retChange.error != null) { contentRet = new WebJsonResponse("", retChange.error.data, 3000, true); } else if (retChange.result == null) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("user_not_found"), 3000, true); } else { contentRet = new WebJsonResponse(Session["ApplicationVirtualPath"] + "admin/users/" + retChange.result.info.userid + "/property/"); } break; case "resetpwd": var tmpReq = new { jsonrpc = "1.0", method = "user.resetpassword", parameters = new { userid = userId, must_change = true }, id = 1 }; rData = JSON.Serialize2(tmpReq); using (IAMDatabase database = new IAMDatabase(IAMDatabase.GetWebConnectionString())) jData = WebPageAPI.ExecuteLocal(database, this, rData); if (String.IsNullOrWhiteSpace(jData)) { throw new Exception(""); } Logs ret = JSON.Deserialize <Logs>(jData); if (ret == null) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("user_not_found"), 3000, true); } else if (ret.error != null) { contentRet = new WebJsonResponse("", ret.error.data, 3000, true); } else if (ret.result == null) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("user_not_found"), 3000, true); } else { contentRet = new WebJsonResponse("", "Senha do usuário redefinida para o padrão do sistema", 3000, false); } break; case "lock": case "unlock": var unReq = new { jsonrpc = "1.0", method = "user." + (action == "lock" ? "lock" : "unlock"), parameters = new { userid = userId }, id = 1 }; rData = JSON.Serialize2(unReq); try { using (IAMDatabase database = new IAMDatabase(IAMDatabase.GetWebConnectionString())) jData = WebPageAPI.ExecuteLocal(database, this, rData); } finally { } if (String.IsNullOrWhiteSpace(jData)) { throw new Exception(""); } Logs unRet = JSON.Deserialize <Logs>(jData); if (unRet == null) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("user_not_found"), 3000, true); } else if (unRet.error != null) { contentRet = new WebJsonResponse("", unRet.error.data, 3000, true); } else if (unRet.result == null) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("user_not_found"), 3000, true); } else { contentRet = new WebJsonResponse("", "Usuário " + (action == "lock" ? "Bloqueado" : "Desbloqueado") + " com sucesso", 5000, false); } break; case "delete_identity": var reqDel = new { jsonrpc = "1.0", method = "user.deleteidentity", parameters = new { userid = userId, identityid = (String)RouteData.Values["filter"] }, id = 1 }; rData = JSON.Serialize2(reqDel); using (IAMDatabase database = new IAMDatabase(IAMDatabase.GetWebConnectionString())) jData = WebPageAPI.ExecuteLocal(database, this, rData); if (String.IsNullOrWhiteSpace(jData)) { throw new Exception(""); } RoleDeleteResult retDel = JSON.Deserialize <RoleDeleteResult>(jData); if (retDel == null) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("identity_not_found"), 3000, true); } else if (retDel.error != null) { contentRet = new WebJsonResponse("", retDel.error.data, 3000, true); } else if (!retDel.result) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("identity_not_found"), 3000, true); } else { contentRet = new WebJsonResponse(); } break; case "unlock_identity": rData = JSON.Serialize2(new { jsonrpc = "1.0", method = "user.unlockidentity", parameters = new { userid = userId, identityid = (String)RouteData.Values["filter"] }, id = 1 }); using (IAMDatabase database = new IAMDatabase(IAMDatabase.GetWebConnectionString())) jData = WebPageAPI.ExecuteLocal(database, this, rData); if (String.IsNullOrWhiteSpace(jData)) { throw new Exception(""); } RoleDeleteResult retUnlockIdentity = JSON.Deserialize <RoleDeleteResult>(jData); if (retUnlockIdentity == null) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("identity_not_found"), 3000, true); } else if (retUnlockIdentity.error != null) { contentRet = new WebJsonResponse("", retUnlockIdentity.error.data, 3000, true); } else if (!retUnlockIdentity.result) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("identity_not_found"), 3000, true); } else { contentRet = new WebJsonResponse(); } break; } } catch (Exception ex) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("api_error"), 3000, true); } finally { } if (contentRet != null) { if (!String.IsNullOrWhiteSpace((String)Request["cid"])) { contentRet.callId = (String)Request["cid"]; } Retorno.Controls.Add(new LiteralControl(contentRet.ToJSON())); } }
protected void Page_Load(object sender, EventArgs e) { if (Request.HttpMethod != "POST") { return; } String area = ""; if (!String.IsNullOrWhiteSpace((String)RouteData.Values["area"])) { area = (String)RouteData.Values["area"]; } String ApplicationVirtualPath = Session["ApplicationVirtualPath"].ToString(); EnterpriseData ent = (EnterpriseData)Page.Session["enterprise_data"]; LMenu menu1 = new LMenu("Dashboard", ApplicationVirtualPath + "admin/"); LMenu menu2 = new LMenu("Empresa", ApplicationVirtualPath + "admin/enterprise/"); LMenu menu3 = new LMenu(ent.Name, ApplicationVirtualPath + "admin/enterprise/"); WebJsonResponse contentRet = null; String html = ""; String eHtml = ""; String error = ""; String filter = ""; HashData hashData = new HashData(this); EnterpriseGetResult selectedEnterprise = null; //No caso específico da empresa (que não possibilita que o usuário selecione outra) //O ID se tornará o filtro if (!String.IsNullOrWhiteSpace((String)RouteData.Values["id"])) { filter = (String)RouteData.Values["id"]; } String errorTemplate = "<span class=\"empty-results\">{0}</span>"; if (area.ToLower() != "search") { try { var tmpReq = new { jsonrpc = "1.0", method = "enterprise.get", parameters = new { enterpriseid = ent.Id }, id = 1 }; String rData = SafeTrend.Json.JSON.Serialize2(tmpReq); String jData = ""; using (IAMDatabase database = new IAMDatabase(IAMDatabase.GetWebConnectionString())) jData = WebPageAPI.ExecuteLocal(database, this, rData); if (String.IsNullOrWhiteSpace(jData)) { throw new Exception(""); } selectedEnterprise = JSON.Deserialize <EnterpriseGetResult>(jData); if (selectedEnterprise == null) { error = MessageResource.GetMessage("enterprise_not_found"); //ret = new WebJsonResponse("", MessageResource.GetMessage("user_not_found"), 3000, true); } else if (selectedEnterprise.error != null) { error = selectedEnterprise.error.data; selectedEnterprise = null; } else if (selectedEnterprise.result == null || selectedEnterprise.result.info == null) { error = MessageResource.GetMessage("enterprise_not_found"); selectedEnterprise = null; } else { menu3.Name = selectedEnterprise.result.info.name; } } catch (Exception ex) { error = MessageResource.GetMessage("api_error"); Tools.Tool.notifyException(ex, this); selectedEnterprise = null; //ret = new WebJsonResponse("", MessageResource.GetMessage("api_error"), 3000, true); } } switch (area) { case "": case "content": if (selectedEnterprise != null) { switch (filter) { case "": case "info": String infoTemplate = "<div class=\"form-group\">"; infoTemplate += "<label>{0}</label>"; infoTemplate += "<span class=\"no-edit\">{1}</span></div>"; String jsAdd = ""; if (filter == "" || filter == "info") { if (hashData.GetValue("edit") == "1") { html += "<form id=\"form_enterprise_change\" method=\"POST\" action=\"" + ApplicationVirtualPath + "admin/enterprise/action/change/\">"; html += "<h3>Informações gerais</h3>"; html += "<div class=\"no-tabs pb10\">"; html += String.Format(infoTemplate, "Nome", "<input id=\"name\" name=\"name\" placeholder=\"Digite o nome da empresa\" type=\"text\"\" value=\"" + selectedEnterprise.result.info.name + "\">"); html += String.Format(infoTemplate, "Host principal", selectedEnterprise.result.info.fqdn); html += String.Format(infoTemplate, "Criado em", MessageResource.FormatDate(((DateTime) new DateTime(1970, 1, 1)).AddSeconds(selectedEnterprise.result.info.create_date), false)); //Resgata a listagem dos plugins de autenticação disponíveis List <AuthBase> plugins = AuthBase.GetPlugins <AuthBase>(); String select = ""; select += "<select id=\"auth_plugin\" name=\"auth_plugin\" >"; foreach (AuthBase p in plugins) { select += "<option selector=\"" + p.GetPluginId().AbsoluteUri.Replace("/", "").Replace(":", "") + "\" value=\"" + p.GetPluginId().AbsoluteUri + "\" " + (p.Equal(new Uri(selectedEnterprise.result.info.auth_plugin)) ? "selected=\"selected\"" : "") + ">" + p.GetPluginName() + "</option>"; } select += "</select>"; html += String.Format(infoTemplate, "Serviço de autenticação", select); //Caso tenha algum paràmetro p/ o plugin exibe foreach (AuthBase p in plugins) { AuthConfigFields[] fields = p.GetConfigFields(); if (fields.Length > 0) { html += "<div class=\"auth_cont " + p.GetPluginId().AbsoluteUri.Replace("/", "").Replace(":", "") + "\" " + (p.Equal(new Uri(selectedEnterprise.result.info.auth_plugin)) ? "" : "style=\"display:none;\"") + ">"; foreach (AuthConfigFields f in fields) { String value = ""; try { foreach (EnterpriseAuthPars par in selectedEnterprise.result.auth_parameters) { if (par.key == f.Key) { value = par.value; } } } catch { } html += String.Format(infoTemplate, f.Name, "<input id=\"f_" + f.Key + "\" name=\"f_" + f.Key + "\" placeholder=\"" + f.Description + "\" type=\"text\"\" value=\"" + value + "\">"); } html += "</div>"; } } html += "<div class=\"clear-block\"></div></div>"; } else { html += "<h3>Informações gerais<div class=\"btn-box\"><div class=\"a-btn ico icon-change\" onclick=\"iamadmin.changeHash( 'edit/1' );\">Editar</div></div></h3>"; html += "<div class=\"no-tabs pb10\">"; html += String.Format(infoTemplate, "Nome", selectedEnterprise.result.info.name); html += String.Format(infoTemplate, "Host principal", selectedEnterprise.result.info.fqdn); html += String.Format(infoTemplate, "Criado em", MessageResource.FormatDate(((DateTime) new DateTime(1970, 1, 1)).AddSeconds(selectedEnterprise.result.info.create_date), false)); try { AuthBase plugin = AuthBase.GetPlugin(new Uri(selectedEnterprise.result.info.auth_plugin)); html += String.Format(infoTemplate, "Serviço de autenticação", plugin.GetPluginName()); AuthConfigFields[] fields = plugin.GetConfigFields(); if (fields.Length > 0) { foreach (AuthConfigFields f in fields) { String value = ""; try { foreach (EnterpriseAuthPars par in selectedEnterprise.result.auth_parameters) { if (par.key == f.Key) { value = par.value; } } } catch { } html += String.Format(infoTemplate, f.Name, value); } } } catch { html += String.Format(infoTemplate, "Serviço de autenticação", "Erro ao carregar informações do plugin"); } html += "<div class=\"clear-block\"></div></div>"; } html += "<h3>Hosts complementares</h3>"; html += "<div class=\"no-tabs pb10\">"; if (hashData.GetValue("edit") == "1") { html += "<div id=\"enterprise_hosts\">"; if (selectedEnterprise.result.fqdn_alias != null) { for (Int32 i = 1; i <= selectedEnterprise.result.fqdn_alias.Count; i++) { html += String.Format(infoTemplate, "Host " + i, "<input id=\"host_" + i + "\" name=\"host_" + i + "\" placeholder=\"Digite o host\" type=\"text\"\" value=\"" + selectedEnterprise.result.fqdn_alias[i - 1] + "\">"); } } html += "</div>"; //Div enterprise_hosts html += String.Format(infoTemplate, "", "<div class=\"a-btn blue secondary floatleft\" onclick=\"iamfnc.addHostField()\">Adicionar host</div>"); jsAdd = "iamfnc = $.extend({}, iamfnc, { addHostField: function() { var host = 'host_'+ new Date().getTime(); $('#enterprise_hosts').append('" + String.Format(infoTemplate, "Host ", "<input id=\"'+ host +'\" name=\"'+ host +'\" placeholder=\"Digite o host\" type=\"text\">") + "'); } });"; jsAdd += "$('#auth_plugin').change(function() { $('.auth_cont').css('display','none'); $('.' + $('#auth_plugin option:selected').attr('selector') ).css('display','block'); });"; } else { if (selectedEnterprise.result.fqdn_alias != null) { for (Int32 i = 1; i <= selectedEnterprise.result.fqdn_alias.Count; i++) { html += String.Format(infoTemplate, "Host " + i, selectedEnterprise.result.fqdn_alias[i - 1]); } } } html += "<div class=\"clear-block\"></div></div>"; if (hashData.GetValue("edit") == "1") { html += "<button type=\"submit\" id=\"user-profile-password-save\" class=\"button secondary floatleft\">Salvar</button> <a class=\"button link floatleft\" onclick=\"iamadmin.changeHash( 'edit/0' );\">Cancelar</a></form>"; } } contentRet = new WebJsonResponse("#content-wrapper", html); contentRet.js = jsAdd; break; case "flow": String js2 = ""; if (filter == "" || filter == "flow") { html += "<h3>Fluxo de dados</h3>"; html += "<div id=\"enterpriseChart\"></div>"; js2 = "$('#enterpriseChart').flowchart({load_uri: '" + ApplicationVirtualPath + "admin/chartdata/flow/enterprise/'});"; } contentRet = new WebJsonResponse("#content-wrapper", html); contentRet.js = js2; break; } } else { contentRet = new WebJsonResponse("#content-wrapper", String.Format(errorTemplate, error)); } break; case "sidebar": if (menu1 != null) { html += "<div class=\"section-nav-header\">"; html += " <div class=\"crumbs\">"; html += " <div class=\"subject subject-color\">"; html += " <a href=\"" + menu1.HRef + "\">" + menu1.Name + "</a>"; html += " </div>"; if (menu2 != null) { html += " <div class=\"topic topic-color\">"; html += " <a href=\"" + menu2.HRef + "\">" + menu2.Name + "</a>"; html += " </div>"; } html += " </div>"; if (menu3 != null) { html += " <div class=\"crumbs tutorial-title\">"; html += " <h2 class=\"title tutorial-color\">" + menu3.Name + "</h2>"; html += " </div>"; } html += "</div>"; } if (selectedEnterprise != null) { html += "<ul class=\"user-profile\">"; html += "<li " + (filter == "" ? "class=\"bold\"" : "") + "><span><a href=\"" + ApplicationVirtualPath + "admin/enterprise/\">Todas as informações</a></span></li>"; html += "<li " + (filter == "flow" ? "class=\"bold\"" : "") + "><span><a href=\"" + ApplicationVirtualPath + "admin/enterprise/flow\">Fluxo</a></span></li>"; html += "</ul>"; } contentRet = new WebJsonResponse("#main aside", html); break; case "mobilebar": break; case "buttonbox": break; } if (contentRet != null) { if (!String.IsNullOrWhiteSpace((String)Request["cid"])) { contentRet.callId = (String)Request["cid"]; } Retorno.Controls.Add(new LiteralControl(contentRet.ToJSON())); } }
protected void Page_Load(object sender, EventArgs e) { if (Request.HttpMethod != "POST") { return; } String area = ""; if (!String.IsNullOrWhiteSpace((String)RouteData.Values["area"])) { area = (String)RouteData.Values["area"]; } Int64 enterpriseId = 0; if ((Session["enterprise_data"]) != null && (Session["enterprise_data"] is EnterpriseData)) { enterpriseId = ((EnterpriseData)Session["enterprise_data"]).Id; } Boolean newItem = false; if ((RouteData.Values["new"] != null) && (RouteData.Values["new"] == "1")) { newItem = true; } String ApplicationVirtualPath = Session["ApplicationVirtualPath"].ToString(); LMenu menu1 = new LMenu("Dashboard", ApplicationVirtualPath + "admin/"); LMenu menu2 = new LMenu("Contexto", ApplicationVirtualPath + "admin/context/" + (Request.Form["hashtag"] != null ? "#" + Request.Form["hashtag"].ToString() : "")); LMenu menu3 = new LMenu("Contexto", ApplicationVirtualPath + "admin/context/" + (Request.Form["hashtag"] != null ? "#" + Request.Form["hashtag"].ToString() : "")); WebJsonResponse contentRet = null; String html = ""; String eHtml = ""; String js = null; String errorTemplate = "<span class=\"empty-results\">{0}</span>"; //Verifica se está sendo selecionada uma role Int64 contextId = 0; try { contextId = Int64.Parse((String)RouteData.Values["id"]); if (contextId < 0) { contextId = 0; } } catch { } String error = ""; ContextGetResult selectedContext = null; String filter = ""; HashData hashData = new HashData(this); if (!String.IsNullOrWhiteSpace((String)RouteData.Values["filter"])) { filter = (String)RouteData.Values["filter"]; } if ((contextId > 0) && (area.ToLower() != "search")) { try { String rData = SafeTrend.Json.JSON.Serialize2(new { jsonrpc = "1.0", method = "context.get", parameters = new { contextid = contextId }, id = 1 }); String jData = ""; using (IAMDatabase database = new IAMDatabase(IAMDatabase.GetWebConnectionString())) jData = WebPageAPI.ExecuteLocal(database, this, rData); if (String.IsNullOrWhiteSpace(jData)) { throw new Exception(""); } selectedContext = JSON.Deserialize <ContextGetResult>(jData); if (selectedContext == null) { error = MessageResource.GetMessage("context_not_found"); //ret = new WebJsonResponse("", MessageResource.GetMessage("user_not_found"), 3000, true); } else if (selectedContext.error != null) { error = selectedContext.error.data; selectedContext = null; } else if (selectedContext.result == null || selectedContext.result.info == null) { error = MessageResource.GetMessage("context_not_found"); selectedContext = null; } else { menu3.Name = selectedContext.result.info.name; } } catch (Exception ex) { error = MessageResource.GetMessage("api_error"); Tools.Tool.notifyException(ex, this); selectedContext = null; //ret = new WebJsonResponse("", MessageResource.GetMessage("api_error"), 3000, true); } } String groupTemplate = "<div id=\"{0}\"><div class=\"group\" group-id=\"{0}\"><div class=\"wrapper\"><div class=\"cmd-bar\"><div class=\"ico icon-close floatright\"></div></div>{1}<div class=\"cmd-bar1\"><div class=\"ico icon-plus floatright\"></div></div></div><div class=\"clear-block\"></div></div><div class=\"selector-wrapper\">{2}</div></div>"; String groupSelectorTemplate = "<div class=\"group-selector\"><div class=\"item selected\" value=\"or\">OU</div><div class=\"clear-block\"></div></div>"; String filterSelectorTemplate = "<div class=\"filter-selector\"><div class=\"item selected\">+</div><div class=\"clear-block\"></div></div>"; switch (area) { case "": case "search": case "content": if (newItem) { html = "<h3>Adição de contexto</h3>"; html += "<form id=\"form_add_role\" method=\"post\" action=\"" + ApplicationVirtualPath + "admin/context/action/add_context/\"><div class=\"no-tabs pb10\">"; html += "<div class=\"form-group\"><label>Nome</label><input id=\"add_context_name\" name=\"add_context_name\" placeholder=\"Digite o nome do contexto\" type=\"text\"\"></div>"; html += "<div class=\"form-group\"><label>Regra de senha</label><div class=\"custom-item\" id=\"pwd_rule\" onclick=\"iamadmin.buildPwdRule(this);\" data-uri=\"" + ApplicationVirtualPath + "admin/context/new/content/pwd-build/\"><input type=\"hidden\" name=\"pwd_rule\" /><span>Nenhuma regra definida</span><i class=\"icon-change\"></i></div></div>"; html += "<div class=\"clear-block\"></div></div>"; html += "<h3>Complexidade de senha</h3><div class=\"no-tabs pb10\">"; html += "<div class=\"form-group\"><label>Tamanho mínimo</label><input id=\"pwd_length\" name=\"pwd_length\" placeholder=\"Digite o tamanho mínimo de senha\" type=\"text\"\" value=\"8\"></div>"; html += "<div class=\"form-group\"><label>Caracter maiúsculo</label><input id=\"pwd_upper_case\" name=\"pwd_upper_case\" type=\"checkbox\" checked><span class=\"checkbox-label\">Exigir</span></div>"; html += "<div class=\"form-group\"><label>Caracter minúsculo</label><input id=\"pwd_lower_case\" name=\"pwd_lower_case\" type=\"checkbox\" checked><span class=\"checkbox-label\">Exigir</span></div>"; html += "<div class=\"form-group\"><label>Número</label><input id=\"pwd_digit\" name=\"pwd_digit\" type=\"checkbox\" checked><span class=\"checkbox-label\">Exigir</span></div>"; html += "<div class=\"form-group\"><label>Caracter especiais</label><input id=\"pwd_symbol\" name=\"pwd_symbol\" type=\"checkbox\" checked><span class=\"checkbox-label\">Exigir</span></div>"; html += "<div class=\"form-group\"><label>Parte do nome</label><input id=\"pwd_no_name\" name=\"pwd_no_name\" type=\"checkbox\" checked><span class=\"checkbox-label\">Não permitir</span></div>"; html += "<div class=\"clear-block\"></div></div>"; html += "<button type=\"submit\" id=\"user-profile-password-save\" class=\"button secondary floatleft\">Adicionar</button> <a href=\"" + ApplicationVirtualPath + "admin/context/" + (Request.Form["hashtag"] != null ? "#" + Request.Form["hashtag"].ToString() : "") + "\" class=\"button link floatleft\">Cancelar</a></form>"; contentRet = new WebJsonResponse("#content-wrapper", (eHtml != "" ? eHtml : html)); } else { if (selectedContext == null) { Int32 page = 1; Int32 pageSize = 20; Boolean hasNext = true; Int32.TryParse(Request.Form["page"], out page); if (page < 1) { page = 1; } String roleTemplate = "<div id=\"role-list-{0}\" data-id=\"{0}\" data-name=\"{1}\" data-total=\"{2}\" class=\"app-list-item\">"; roleTemplate += "<table>"; roleTemplate += " <tbody>"; roleTemplate += " <tr>"; roleTemplate += " <td class=\"col1\">"; roleTemplate += " <span id=\"total_{0}\" class=\"total \">{2}</span>"; roleTemplate += " <a href=\"" + ApplicationVirtualPath + "admin/users/#context/{0}\">"; roleTemplate += " <div class=\"app-btn a-btn\"><span class=\"a-btn-inner\">Ver usuários</span></div>"; roleTemplate += " </a>"; roleTemplate += " </td>"; roleTemplate += " <td class=\"col2\">"; roleTemplate += " <div class=\"title\"><span class=\"name field-editor\" id=\"context_name_{0}\" data-id=\"{0}\" data-function=\"iamadmin.editTextField('#context_name_{0}',null,contextNameEdit);\">{1}</span><span class=\"date\">{3}</span><div class=\"clear-block\"></div></div>"; roleTemplate += " <div class=\"links no-bg\">"; roleTemplate += " <div class=\"first\"><a href=\"" + ApplicationVirtualPath + "admin/context/{0}/" + (Request.Form["hashtag"] != null ? "#" + Request.Form["hashtag"].ToString() : "") + "\"><div class=\"ico icon-change\">Editar</div></a><a href=\"" + ApplicationVirtualPath + "admin/context/{0}/login_rule/" + (Request.Form["hashtag"] != null ? "#" + Request.Form["hashtag"].ToString() : "") + "\"><div class=\"ico icon-cogs\">Regra de criação de login</div></a><a href=\"" + ApplicationVirtualPath + "admin/context/{0}/mail_rule/" + (Request.Form["hashtag"] != null ? "#" + Request.Form["hashtag"].ToString() : "") + "\"><div class=\"ico icon-cogs\">Regra de criação de e-mails</div></a><br clear=\"all\"></div>"; roleTemplate += " <div class=\"\"><a href=\"" + ApplicationVirtualPath + "admin/context/{0}/flow/" + (Request.Form["hashtag"] != null ? "#" + Request.Form["hashtag"].ToString() : "") + "\"><div class=\"ico icon-sitemap\">Fluxo de dados</div></a></div>"; roleTemplate += " <div class=\"last\"><a class=\"confirm-action\" href=\"" + ApplicationVirtualPath + "admin/context/{0}/action/delete/" + (Request.Form["hashtag"] != null ? "#" + Request.Form["hashtag"].ToString() : "") + "\" confirm-title=\"Exclusão\" confirm-text=\"Deseja excluir definitivamente o contexto '{1}'?\" ok=\"Excluir\" cancel=\"Cancelar\"><div class=\"ico icon-close\">Apagar</div></a><br clear=\"all\"></div>"; roleTemplate += " </div><br clear=\"all\">"; roleTemplate += " </td>"; roleTemplate += " </tr>"; roleTemplate += " </tbody>"; roleTemplate += "</table></div>"; js += "contextNameEdit = function(thisId, changedText) { iamadmin.changeName(thisId,changedText); };"; html += "<div id=\"box-container\" class=\"box-container\">"; String query = ""; try { String rData = ""; if (!String.IsNullOrWhiteSpace((String)RouteData.Values["query"])) { query = (String)RouteData.Values["query"]; } if (String.IsNullOrWhiteSpace(query) && !String.IsNullOrWhiteSpace(hashData.GetValue("query"))) { query = hashData.GetValue("query"); } if (String.IsNullOrWhiteSpace(query)) { var tmpReq = new { jsonrpc = "1.0", method = "context.list", parameters = new { page_size = pageSize, page = page }, id = 1 }; rData = SafeTrend.Json.JSON.Serialize2(tmpReq); } else { var tmpReq = new { jsonrpc = "1.0", method = "context.search", parameters = new { text = query, page_size = pageSize, page = page }, id = 1 }; rData = SafeTrend.Json.JSON.Serialize2(tmpReq); } String jData = ""; using (IAMDatabase database = new IAMDatabase(IAMDatabase.GetWebConnectionString())) jData = WebPageAPI.ExecuteLocal(database, this, rData); if (String.IsNullOrWhiteSpace(jData)) { throw new Exception(""); } ContextListResult ret2 = JSON.Deserialize <ContextListResult>(jData); if (ret2 == null) { eHtml += String.Format(errorTemplate, MessageResource.GetMessage("context_not_found")); hasNext = false; } else if (ret2.error != null) { #if DEBUG eHtml += String.Format(errorTemplate, ret2.error.data + ret2.error.debug); #else eHtml += String.Format(errorTemplate, ret2.error.data); #endif hasNext = false; } else if (ret2.result == null || (ret2.result.Count == 0 && page == 1)) { eHtml += String.Format(errorTemplate, MessageResource.GetMessage("context_not_found")); hasNext = false; } else { foreach (ContextData role in ret2.result) { html += String.Format(roleTemplate, role.context_id, role.name, role.entity_qty, (role.create_date > 0 ? "Criado em " + MessageResource.FormatDate(new DateTime(1970, 1, 1).AddSeconds(role.create_date), true) : "")); } if (ret2.result.Count < pageSize) { hasNext = false; } } } catch (Exception ex) { eHtml += String.Format(errorTemplate, MessageResource.GetMessage("api_error")); } if (page == 1) { html += "</div>"; html += "<span class=\"empty-results content-loading role-list-loader hide\"></span>"; contentRet = new WebJsonResponse("#content-wrapper", (eHtml != "" ? eHtml : html)); } else { contentRet = new WebJsonResponse("#content-wrapper #box-container", (eHtml != "" ? eHtml : html), true); } contentRet.js = js + "$( document ).unbind('end_of_scroll');"; if (hasNext) { contentRet.js += "$( document ).bind( 'end_of_scroll.loader_role', function() { $( document ).unbind('end_of_scroll.loader_role'); $('.role-list-loader').removeClass('hide'); iamadmin.getPageContent2( { page: " + ++page + ", search:'" + (!String.IsNullOrWhiteSpace(query) ? query : "") + "' }, function(){ $('.role-list-loader').addClass('hide'); } ); });"; } } else //Esta sendo selecionado a role { String jData = ""; String rData = ""; if (error != "") { contentRet = new WebJsonResponse("#content-wrapper", String.Format(errorTemplate, error)); } else { switch (filter) { case "": html = "<h3>Edição de contexto</h3>"; html += "<form id=\"form_add_role\" method=\"post\" action=\"" + ApplicationVirtualPath + "admin/context/" + selectedContext.result.info.context_id + "/action/change/\"><div class=\"no-tabs pb10\">"; html += "<div class=\"form-group\"><label>Nome</label><input id=\"add_context_name\" name=\"add_context_name\" placeholder=\"Digite o nome do contexto\" type=\"text\"\" value=\"" + selectedContext.result.info.name + "\"></div>"; html += "<div class=\"form-group\"><label>Regra de senha</label><div class=\"custom-item\" id=\"pwd_rule\" onclick=\"iamadmin.buildPwdRule(this);\" data-uri=\"" + ApplicationVirtualPath + "admin/context/new/content/pwd-build/\"><input type=\"hidden\" name=\"pwd_rule\" value=\"" + selectedContext.result.info.password_rule + "\" /><span>" + selectedContext.result.info.password_rule + "</span><i class=\"icon-change\"></i></div></div>"; html += "<div class=\"clear-block\"></div></div>"; html += "<h3>Complexidade de senha</h3><div class=\"no-tabs pb10\">"; html += "<div class=\"form-group\"><label>Tamanho mínimo</label><input id=\"pwd_length\" name=\"pwd_length\" placeholder=\"Digite o tamanho mínimo de senha\" type=\"text\"\" value=\"" + selectedContext.result.info.password_length + "\"></div>"; html += "<div class=\"form-group\"><label>Caracter maiúsculo</label><input id=\"pwd_upper_case\" name=\"pwd_upper_case\" type=\"checkbox\" " + (selectedContext.result.info.password_upper_case ? "checked" : "") + "><span class=\"checkbox-label\">Exigir</span></div>"; html += "<div class=\"form-group\"><label>Caracter minúsculo</label><input id=\"pwd_lower_case\" name=\"pwd_lower_case\" type=\"checkbox\" " + (selectedContext.result.info.password_lower_case ? "checked" : "") + "><span class=\"checkbox-label\">Exigir</span></div>"; html += "<div class=\"form-group\"><label>Número</label><input id=\"pwd_digit\" name=\"pwd_digit\" type=\"checkbox\" " + (selectedContext.result.info.password_digit ? "checked" : "") + "><span class=\"checkbox-label\">Exigir</span></div>"; html += "<div class=\"form-group\"><label>Caracter especiais</label><input id=\"pwd_symbol\" name=\"pwd_symbol\" type=\"checkbox\" " + (selectedContext.result.info.password_symbol ? "checked" : "") + "><span class=\"checkbox-label\">Exigir</span></div>"; html += "<div class=\"form-group\"><label>Parte do nome</label><input id=\"pwd_no_name\" name=\"pwd_no_name\" type=\"checkbox\" " + (selectedContext.result.info.password_no_name ? "checked" : "") + "><span class=\"checkbox-label\">Não permitir</span></div>"; html += "<div class=\"clear-block\"></div></div>"; html += "<button type=\"submit\" id=\"user-profile-password-save\" class=\"button secondary floatleft\">Salvar</button> <a href=\"" + ApplicationVirtualPath + "admin/context/" + (Request.Form["hashtag"] != null ? "#" + Request.Form["hashtag"].ToString() : "") + "\" class=\"button link floatleft\">Cancelar</a></form>"; contentRet = new WebJsonResponse("#content-wrapper", (eHtml != "" ? eHtml : html)); break; case "login_rule": // rData = SafeTrend.Json.JSON.Serialize2(new { jsonrpc = "1.0", method = "context.getloginrules", parameters = new { contextid = contextId }, id = 1 }); using (IAMDatabase database = new IAMDatabase(IAMDatabase.GetWebConnectionString())) jData = WebPageAPI.ExecuteLocal(database, this, rData); if (String.IsNullOrWhiteSpace(jData)) { throw new Exception(""); } ContextLoginMailRulesResult ctxLoginRules = JSON.Deserialize <ContextLoginMailRulesResult>(jData); if (ctxLoginRules == null) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("context_not_found"), 3000, true); } else if (ctxLoginRules.error != null) { error = ctxLoginRules.error.data; contentRet = new WebJsonResponse("", ctxLoginRules.error.data, 3000, true); } else if (ctxLoginRules.result == null) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("context_not_found"), 3000, true); } else { String loginTemplate = GetLoginTemplate(""); html = "<form id=\"form_add_role\" method=\"post\" action=\"" + ApplicationVirtualPath + "admin/context/" + selectedContext.result.info.context_id + "/action/change_login_rules/\">"; html += "<h3>Regra para criação de login</h3><div class=\"no-tabs pb10\">"; html += "<div id=\"filter_conditions\"><div><div class=\"a-btn blue secondary\" onclick=\"iamfnc.addRule();\">Inserir regra</div></div>"; html += "<div class=\"filter-groups\">"; if (ctxLoginRules.result.Count == 0) { String rules = String.Format(loginTemplate, "R0", "0", ""); html += String.Format(groupTemplate, "0", rules, ""); } else { for (Int32 r = 0; r < ctxLoginRules.result.Count; r++) { String rules = ""; //Split items String[] fi = ctxLoginRules.result[r].rule.Split(",".ToCharArray()); for (Int32 fIndex = 0; fIndex < fi.Length; fIndex++) { String fId = r + "-" + fIndex; String ft = GetLoginTemplate(fi[fIndex]); rules += String.Format(ft, "R" + fId, r, (fIndex < fi.Length - 1 ? String.Format(filterSelectorTemplate, fId) : "")); } html += String.Format(groupTemplate, r, rules, (r < ctxLoginRules.result.Count - 1 ? String.Format(groupSelectorTemplate, r) : "")); //html += String.Format(groupTemplate, fr.FilterGroups[g].GroupId, filters, (g < fr.FilterGroups.Count - 1 ? (fr.FilterGroups[g].Selector == FilterSelector.AND ? String.Format(groupSelectorTemplate, fr.FilterGroups[g].GroupId, "", "selected") : String.Format(groupSelectorTemplate, fr.FilterGroups[g].GroupId, "selected", "")) : "")); } } html += "</div>"; html += "</div><div class=\"clear-block\"></div></div>"; html += "<button type=\"submit\" id=\"user-profile-password-save\" class=\"button secondary floatleft\">Salvar</button> <a href=\"" + ApplicationVirtualPath + "admin/context/" + (Request.Form["hashtag"] != null ? "#" + Request.Form["hashtag"].ToString() : "") + "\" class=\"button link floatleft\">Cancelar</a></form>"; contentRet = new WebJsonResponse("#content-wrapper", (eHtml != "" ? eHtml : html)); contentRet.js = GetLoginJS(groupTemplate, groupSelectorTemplate, loginTemplate, filterSelectorTemplate); } break; case "mail_rule": // rData = SafeTrend.Json.JSON.Serialize2(new { jsonrpc = "1.0", method = "context.getmailrules", parameters = new { contextid = contextId }, id = 1 }); using (IAMDatabase database = new IAMDatabase(IAMDatabase.GetWebConnectionString())) jData = WebPageAPI.ExecuteLocal(database, this, rData); if (String.IsNullOrWhiteSpace(jData)) { throw new Exception(""); } ContextLoginMailRulesResult ctxMailRules = JSON.Deserialize <ContextLoginMailRulesResult>(jData); if (ctxMailRules == null) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("context_not_found"), 3000, true); } else if (ctxMailRules.error != null) { error = ctxMailRules.error.data; contentRet = new WebJsonResponse("", ctxMailRules.error.data, 3000, true); } else if (ctxMailRules.result == null) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("context_not_found"), 3000, true); } else { String loginTemplate = GetLoginTemplate(""); html = "<form id=\"form_add_role\" method=\"post\" action=\"" + ApplicationVirtualPath + "admin/context/" + selectedContext.result.info.context_id + "/action/change_mail_rules/\">"; html += "<h3>Regra para criação de e-mail</h3><div class=\"no-tabs pb10\">"; html += "<div id=\"filter_conditions\"><div><div class=\"a-btn blue secondary\" onclick=\"iamfnc.addRule();\">Inserir regra</div></div>"; html += "<div class=\"filter-groups\">"; if (ctxMailRules.result.Count == 0) { String rules = String.Format(loginTemplate, "R0", "0", ""); html += String.Format(groupTemplate, "0", rules, ""); } else { for (Int32 r = 0; r < ctxMailRules.result.Count; r++) { String rules = ""; //Split items String[] fi = ctxMailRules.result[r].rule.Split(",".ToCharArray()); for (Int32 fIndex = 0; fIndex < fi.Length; fIndex++) { String fId = r + "-" + fIndex; String ft = GetLoginTemplate(fi[fIndex]); rules += String.Format(ft, "R" + fId, r, (fIndex < fi.Length - 1 ? String.Format(filterSelectorTemplate, fId) : "")); } html += String.Format(groupTemplate, r, rules, (r < ctxMailRules.result.Count - 1 ? String.Format(groupSelectorTemplate, r) : "")); //html += String.Format(groupTemplate, fr.FilterGroups[g].GroupId, filters, (g < fr.FilterGroups.Count - 1 ? (fr.FilterGroups[g].Selector == FilterSelector.AND ? String.Format(groupSelectorTemplate, fr.FilterGroups[g].GroupId, "", "selected") : String.Format(groupSelectorTemplate, fr.FilterGroups[g].GroupId, "selected", "")) : "")); } } html += "</div>"; html += "</div><div class=\"clear-block\"></div></div>"; html += "<button type=\"submit\" id=\"user-profile-password-save\" class=\"button secondary floatleft\">Salvar</button> <a href=\"" + ApplicationVirtualPath + "admin/context/" + (Request.Form["hashtag"] != null ? "#" + Request.Form["hashtag"].ToString() : "") + "\" class=\"button link floatleft\">Cancelar</a></form>"; contentRet = new WebJsonResponse("#content-wrapper", (eHtml != "" ? eHtml : html)); contentRet.js = GetLoginJS(groupTemplate, groupSelectorTemplate, loginTemplate, filterSelectorTemplate); } break; case "flow": String js2 = ""; if (filter == "" || filter == "flow") { html += "<h3>Fluxo de dados</h3>"; html += "<div id=\"contextChart\"></div>"; js2 = "$('#contextChart').flowchart({load_uri: '" + ApplicationVirtualPath + "admin/chartdata/flow/context/" + selectedContext.result.info.context_id + "/'});"; } contentRet = new WebJsonResponse("#content-wrapper", html); contentRet.js = js2; break; } } } } break; case "sidebar": if (menu1 != null) { html += "<div class=\"sep\"><div class=\"section-nav-header\">"; html += " <div class=\"crumbs\">"; html += " <div class=\"subject subject-color\">"; html += " <a href=\"" + menu1.HRef + "\">" + menu1.Name + "</a>"; html += " </div>"; if (menu2 != null) { html += " <div class=\"topic topic-color\">"; html += " <a href=\"" + menu2.HRef + "\">" + menu2.Name + "</a>"; html += " </div>"; } html += " </div>"; if (menu3 != null) { html += " <div class=\"crumbs tutorial-title\">"; html += " <h2 class=\"title tutorial-color\">" + menu3.Name + "</h2>"; html += " </div>"; } html += "</div></div>"; } if (!newItem) { html += "<div class=\"sep\"><button class=\"a-btn-big a-btn\" type=\"button\" onclick=\"window.location='" + ApplicationVirtualPath + "admin/context/new/" + (Request.Form["hashtag"] != null ? "#" + Request.Form["hashtag"].ToString() : "") + "'\">Novo contexto</button></div>"; switch (filter) { case "add_user": case "login_rule": break; default: if (selectedContext != null) { html += "<div class=\"sep\"><button class=\"a-btn-big a-btn\" type=\"button\" style=\"font-size: 13px;\" onclick=\"window.location='" + ApplicationVirtualPath + "admin/context/" + selectedContext.result.info.context_id + "/login_rule/" + (Request.Form["hashtag"] != null ? "#" + Request.Form["hashtag"].ToString() : "") + "'\">Regras de criação de login</button></div>"; } break; } } contentRet = new WebJsonResponse("#main aside", html); break; case "mobilebar": break; case "buttonbox": switch (filter) { case "": break; } break; case "pwd-build": html += "<div class=\"no-tabs pb10\" style=\"width:480px;\">"; html += "<div class=\"form-group\"><label>Tipo</label><select id=\"pwd_rule\" name=\"pwd_rule\"><option value=\"\"></option><option value=\"default\">Senha padrão</option><option value=\"random\">Senha randomica</option></select></div>"; html += "<div class=\"form-group\" style=\"visibility:hidden;\" id=\"field_pass\"><label>Senha padrão</label><input id=\"pwd_pass\" name=\"pwd_pass\" placeholder=\"Digite a senha padrão\" type=\"text\"\"></div>"; html += "<div class=\"clear-block\"></div></div>"; contentRet = new WebJsonResponse("#modal-box .alert-box-content", html); contentRet.js = "$('#modal-box #pwd_rule').change(function(oThis){ if ($( this ).val() == 'default'){ $('#modal-box #field_pass').css('visibility','visible') }else{ $('#modal-box #field_pass').css('visibility','hidden') } });"; break; } if (contentRet != null) { if (!String.IsNullOrWhiteSpace((String)Request["cid"])) { contentRet.callId = (String)Request["cid"]; } Retorno.Controls.Add(new LiteralControl(contentRet.ToJSON())); } }
protected void Page_Load(object sender, EventArgs e) { if (Request.HttpMethod != "POST") { return; } String area = ""; if (!String.IsNullOrWhiteSpace((String)RouteData.Values["area"])) { area = (String)RouteData.Values["area"]; } Int64 enterpriseId = 0; if ((Session["enterprise_data"]) != null && (Session["enterprise_data"] is EnterpriseData)) { enterpriseId = ((EnterpriseData)Session["enterprise_data"]).Id; } String ApplicationVirtualPath = Session["ApplicationVirtualPath"].ToString(); LMenu menu1 = null; LMenu menu2 = null; LMenu menu3 = null; WebJsonResponse contentRet = null; String html = ""; String eHtml = ""; String js = null; String errorTemplate = "<span class=\"empty-results\">{0}</span>"; switch (area) { case "": case "content": html += "<h3>" + MessageResource.GetMessage("users") + "</h3>"; html += "<div id=\"chartUserFlow\"></div>"; html += "<h3>" + MessageResource.GetMessage("config") + "</h3>"; html += "<div id=\"chartConfigFlow\"></div>"; js += "$('#chartUserFlow').flowchart({load_uri: '" + ApplicationVirtualPath + "admin/chartdata/flow/users/'});"; js += "$('#chartConfigFlow').flowchart({load_uri: '" + ApplicationVirtualPath + "admin/chartdata/flow/config/'});"; contentRet = new WebJsonResponse("#content-wrapper", (eHtml != "" ? eHtml : html)); contentRet.js = js; break; case "sidebar": if (menu1 != null) { html += "<div class=\"section-nav-header\">"; html += " <div class=\"crumbs\">"; html += " <div class=\"subject subject-color\">"; html += " <a href=\"" + menu1.HRef + "\">" + menu1.Name + "</a>"; html += " </div>"; if (menu2 != null) { html += " <div class=\"topic topic-color\">"; html += " <a href=\"" + menu2.HRef + "\">" + menu2.Name + "</a>"; html += " </div>"; } html += " </div>"; if (menu3 != null) { html += " <div class=\"crumbs tutorial-title\">"; html += " <h2 class=\"title tutorial-color\">" + menu3.Name + "</h2>"; html += " </div>"; } html += "</div>"; } contentRet = new WebJsonResponse("#main aside", (eHtml != "" ? eHtml : html)); contentRet.js = js; break; case "mobilebar": break; case "buttonbox": break; } if (contentRet != null) { if (!String.IsNullOrWhiteSpace((String)Request["cid"])) { contentRet.callId = (String)Request["cid"]; } Retorno.Controls.Add(new LiteralControl(contentRet.ToJSON())); } }
protected void Page_Load(object sender, EventArgs e) { if (Request.HttpMethod != "POST") { return; } String area = ""; if (!String.IsNullOrWhiteSpace((String)RouteData.Values["area"])) { area = (String)RouteData.Values["area"]; } Int64 enterpriseId = 0; if ((Session["enterprise_data"]) != null && (Session["enterprise_data"] is EnterpriseData)) { enterpriseId = ((EnterpriseData)Session["enterprise_data"]).Id; } Boolean newItem = false; if ((RouteData.Values["new"] != null) && (RouteData.Values["new"] == "1")) { newItem = true; } String ApplicationVirtualPath = Session["ApplicationVirtualPath"].ToString(); LMenu menu1 = new LMenu("Dashboard", ApplicationVirtualPath + "admin/"); LMenu menu2 = new LMenu("Campos", ApplicationVirtualPath + "admin/field/" + (Request.Form["hashtag"] != null ? "#" + Request.Form["hashtag"].ToString() : "")); LMenu menu3 = new LMenu("Campos", ApplicationVirtualPath + "admin/field/" + (Request.Form["hashtag"] != null ? "#" + Request.Form["hashtag"].ToString() : "")); WebJsonResponse contentRet = null; String html = ""; String eHtml = ""; String js = null; String errorTemplate = "<span class=\"empty-results\">{0}</span>"; //Verifica se está sendo selecionada uma role Int64 fieldId = 0; try { fieldId = Int64.Parse((String)RouteData.Values["id"]); if (fieldId < 0) { fieldId = 0; } } catch { } String error = ""; FieldGetResult retField = null; String filter = ""; HashData hashData = new HashData(this); if (!String.IsNullOrWhiteSpace((String)RouteData.Values["filter"])) { filter = (String)RouteData.Values["filter"]; } if ((fieldId > 0) && (area.ToLower() != "search")) { try { var tmpReq = new { jsonrpc = "1.0", method = "field.get", parameters = new { fieldid = fieldId }, id = 1 }; String rData = SafeTrend.Json.JSON.Serialize2(tmpReq); String jData = ""; using (IAMDatabase database = new IAMDatabase(IAMDatabase.GetWebConnectionString())) jData = WebPageAPI.ExecuteLocal(database, this, rData); if (String.IsNullOrWhiteSpace(jData)) { throw new Exception(""); } retField = JSON.Deserialize <FieldGetResult>(jData); if (retField == null) { error = MessageResource.GetMessage("field_not_found"); //ret = new WebJsonResponse("", MessageResource.GetMessage("user_not_found"), 3000, true); } else if (retField.error != null) { error = retField.error.data; retField = null; } else if (retField.result == null || retField.result.info == null) { error = MessageResource.GetMessage("field_not_found"); retField = null; } else { menu3.Name = retField.result.info.name; } } catch (Exception ex) { error = MessageResource.GetMessage("api_error"); Tools.Tool.notifyException(ex, this); retField = null; //ret = new WebJsonResponse("", MessageResource.GetMessage("api_error"), 3000, true); } } switch (area) { case "": case "search": case "content": if (newItem) { html = "<h3>Adição de campo</h3>"; html += "<form id=\"form_add_resource\" method=\"post\" action=\"" + ApplicationVirtualPath + "admin/field/action/add_field/\"><div class=\"no-tabs pb10\">"; html += "<div class=\"form-group\"><label>Nome</label><input id=\"field_name\" name=\"field_name\" placeholder=\"Digite o nome do campo\" type=\"text\"\"></div>"; html += "<div class=\"form-group\"><label>Tipo de dado</label><select id=\"data_type\" name=\"data_type\" >"; html += "<option value=\"string\">Texto</option>"; html += "<option value=\"numeric\">Número</option>"; html += "<option value=\"datetime\">Data e Hora</option>"; html += "</select></div>"; html += "<div class=\"form-group\"><label>Público</label><input id=\"public\" name=\"public\" type=\"checkbox\"><span class=\"checkbox-label\">Permite visualização por todos os usuários</span></div>"; html += "<div class=\"form-group\"><label>Permite edição</label><input id=\"user\" name=\"user\" type=\"checkbox\"><span class=\"checkbox-label\">Permite que o usuário altere o valor</span></div>"; html += "<div class=\"clear-block\"></div></div>"; html += "<button type=\"submit\" id=\"field-save\" class=\"button secondary floatleft\">Adicionar</button> <a href=\"" + ApplicationVirtualPath + "admin/field/" + (Request.Form["hashtag"] != null ? "#" + Request.Form["hashtag"].ToString() : "") + "\" class=\"button link floatleft\">Cancelar</a></form>"; contentRet = new WebJsonResponse("#content-wrapper", (eHtml != "" ? eHtml : html)); } else { if (retField == null) { Int32 page = 1; Int32 pageSize = 20; Boolean hasNext = true; Int32.TryParse(Request.Form["page"], out page); if (page < 1) { page = 1; } if (page == 1) { html += "<table id=\"users-table\" class=\"sorter\"><thead>"; html += " <tr>"; html += " <th class=\"w50 mHide {sorter: false}\"><div class=\"select-all\"></div></th>"; html += " <th class=\"pointer header headerSortDown\" data-column=\"name\">Campo <div class=\"icomoon\"></div></th>"; html += " <th class=\"pointer tHide mHide header\" data-column=\"login\">Público <div class=\"icomoon\"></div></th>"; html += " <th class=\"pointer tHide mHide header\" data-column=\"login\">Permite edição <div class=\"icomoon\"></div></th>"; html += " <th class=\"pointer tHide mHide header\" data-column=\"login\">Tipo de dado <div class=\"icomoon\"></div></th>"; html += " <th class=\"pointer w200 tHide mHide header\" data-column=\"last_login\">Ações <div class=\"icomoon\"></div></th>"; html += " </tr>"; html += "</thead>"; html += "<tbody>"; } String trTemplate = " <tr class=\"user\" data-id=\"{0}\">"; trTemplate += " <td class=\"select mHide\"><div class=\"checkbox\"></div></td>"; trTemplate += " <td class=\"ident10\">{1}</td>"; trTemplate += " <td class=\"tHide mHide\">{2}</td>"; trTemplate += " <td class=\"tHide mHide\">{3}</td>"; trTemplate += " <td class=\"tHide mHide\">{4}</td>"; trTemplate += " <td class=\"tHide mHide\"><button class=\"a-btn\" onclick=\"window.location = '" + ApplicationVirtualPath + "admin/field/{0}/';\">Abrir</button> <button href=\"" + ApplicationVirtualPath + "admin/field/{0}/action/delete/" + (Request.Form["hashtag"] != null ? "#" + Request.Form["hashtag"].ToString() : "") + "\" class=\"a-btn confirm-action\" confirm-title=\"Exclusão\" confirm-text=\"Deseja excluir definitivamente do campo '{1}'?\" ok=\"Excluir\" cancel=\"Cancelar\">Excluir</button></td>"; trTemplate += " </tr>"; try { String rData = ""; String query = ""; if (!String.IsNullOrWhiteSpace((String)RouteData.Values["query"])) { query = (String)RouteData.Values["query"]; } if (String.IsNullOrWhiteSpace(query) && !String.IsNullOrWhiteSpace(hashData.GetValue("query"))) { query = hashData.GetValue("query"); } if (String.IsNullOrWhiteSpace(query)) { var tmpReq = new { jsonrpc = "1.0", method = "field.list", parameters = new { page_size = pageSize, page = page }, id = 1 }; rData = SafeTrend.Json.JSON.Serialize2(tmpReq); } else { var tmpReq = new { jsonrpc = "1.0", method = "field.search", parameters = new { text = query, page_size = pageSize, page = page }, id = 1 }; rData = SafeTrend.Json.JSON.Serialize2(tmpReq); } String jData = ""; using (IAMDatabase database = new IAMDatabase(IAMDatabase.GetWebConnectionString())) jData = WebPageAPI.ExecuteLocal(database, this, rData); if (String.IsNullOrWhiteSpace(jData)) { throw new Exception(""); } FieldListResult ret2 = JSON.Deserialize <FieldListResult>(jData); if (ret2 == null) { eHtml += String.Format(errorTemplate, MessageResource.GetMessage("field_not_found")); //ret = new WebJsonResponse("", MessageResource.GetMessage("user_not_found"), 3000, true); hasNext = false; } else if (ret2.error != null) { eHtml += String.Format(errorTemplate, ret2.error.data); //ret = new WebJsonResponse("", ret2.error.data, 3000, true); hasNext = false; } else if (ret2.result == null || (ret2.result.Count == 0 && page == 1)) { eHtml += String.Format(errorTemplate, MessageResource.GetMessage("field_not_found")); hasNext = false; } else { foreach (FieldData field in ret2.result) { html += String.Format(trTemplate, field.field_id, field.name, (field.public_field ? MessageResource.GetMessage("yes") : MessageResource.GetMessage("no")), (field.user_field ? MessageResource.GetMessage("yes") : MessageResource.GetMessage("no")), MessageResource.GetMessage(field.data_type.ToLower())); } if (ret2.result.Count < pageSize) { hasNext = false; } } } catch (Exception ex) { eHtml += String.Format(errorTemplate, MessageResource.GetMessage("api_error")); //ret = new WebJsonResponse("", MessageResource.GetMessage("api_error"), 3000, true); } if (page == 1) { html += "</tbody></table>"; html += "<span class=\"empty-results content-loading user-list-loader hide\"></span>"; contentRet = new WebJsonResponse("#content-wrapper", (eHtml != "" ? eHtml : html)); } else { contentRet = new WebJsonResponse("#content-wrapper tbody", (eHtml != "" ? eHtml : html), true); } contentRet.js = "$( document ).unbind('end_of_scroll.loader_usr');"; if (hasNext) { contentRet.js += "$( document ).bind( 'end_of_scroll.loader_usr', function() { $( document ).unbind('end_of_scroll.loader_usr'); $('.user-list-loader').removeClass('hide'); iamadmin.getPageContent2( { page: " + ++page + ", search:'' }, function(){ $('.user-list-loader').addClass('hide'); } ); });"; } } else //Esta sendo selecionado a role { if (error != "") { contentRet = new WebJsonResponse("#content-wrapper", String.Format(errorTemplate, error)); } else { switch (filter) { case "": String infoTemplate = "<div class=\"form-group\">"; infoTemplate += "<label>{0}</label>"; infoTemplate += "<span class=\"no-edit\">{1}</span></div>"; String jsAdd = ""; if (hashData.GetValue("edit") == "1") { html += "<form id=\"form_resource_change\" method=\"POST\" action=\"" + ApplicationVirtualPath + "admin/field/" + retField.result.info.field_id + "/action/change/\">"; html += "<h3>Edição de campo</h3>"; html += "<div class=\"no-tabs pb10\">"; html += String.Format(infoTemplate, "Nome", "<input id=\"name\" name=\"name\" placeholder=\"Digite o nome do recurso\" type=\"text\"\" value=\"" + retField.result.info.name + "\">"); html += String.Format(infoTemplate, "Tipo de campo", "<select id=\"data_type\" name=\"data_type\" ><option value=\"string\" " + (retField.result.info.data_type == "string" ? "selected" : "") + ">Texto</option><option value=\"numeric\" " + (retField.result.info.data_type == "numeric" ? "selected" : "") + ">Número</option><option value=\"datetime\" " + (retField.result.info.data_type == "datetime" ? "selected" : "") + ">Data e Hora</option></select>"); html += String.Format(infoTemplate, "Público", "<input id=\"public\" name=\"public\" type=\"checkbox\" " + (retField.result.info.public_field? "checked":"") + "><span class=\"checkbox-label\">Permite visualização por todos os usuários</span>"); html += String.Format(infoTemplate, "Permite edição", "<input id=\"user\" name=\"user\" type=\"checkbox\" " + (retField.result.info.user_field ? "checked" : "") + "><span class=\"checkbox-label\">Permite que o usuário altere o valor</span>"); html += "<div class=\"clear-block\"></div></div>"; } else { html += "<h3>Informações gerais<div class=\"btn-box\"><div class=\"a-btn ico icon-change\" onclick=\"iamadmin.changeHash( 'edit/1' );\">Editar</div></div></h3>"; html += "<div class=\"no-tabs pb10\">"; html += String.Format(infoTemplate, "Nome", retField.result.info.name); html += String.Format(infoTemplate, "Tipo de campo", MessageResource.GetMessage(retField.result.info.data_type.ToLower())); html += String.Format(infoTemplate, "Público", (retField.result.info.public_field ? MessageResource.GetMessage("yes") : MessageResource.GetMessage("no"))); html += String.Format(infoTemplate, "Permite edição", (retField.result.info.user_field ? MessageResource.GetMessage("yes") : MessageResource.GetMessage("no"))); html += "<div class=\"clear-block\"></div></div>"; } if (hashData.GetValue("edit") == "1") { html += "<button type=\"submit\" id=\"resource-save\" class=\"button secondary floatleft\">Salvar</button> <a class=\"button link floatleft\" onclick=\"iamadmin.changeHash( 'edit/0' );\">Cancelar</a></form>"; } contentRet = new WebJsonResponse("#content-wrapper", html); contentRet.js = jsAdd; break; } } } } break; case "sidebar": if (menu1 != null) { html += "<div class=\"sep\"><div class=\"section-nav-header\">"; html += " <div class=\"crumbs\">"; html += " <div class=\"subject subject-color\">"; html += " <a href=\"" + menu1.HRef + "\">" + menu1.Name + "</a>"; html += " </div>"; if (menu2 != null) { html += " <div class=\"topic topic-color\">"; html += " <a href=\"" + menu2.HRef + "\">" + menu2.Name + "</a>"; html += " </div>"; } html += " </div>"; if (menu3 != null) { html += " <div class=\"crumbs tutorial-title\">"; html += " <h2 class=\"title tutorial-color\">" + menu3.Name + "</h2>"; html += " </div>"; } html += "</div></div>"; } if (!newItem) { html += "<div class=\"sep\"><button class=\"a-btn-big a-btn\" type=\"button\" onclick=\"window.location='" + ApplicationVirtualPath + "admin/field/new/" + (Request.Form["hashtag"] != null ? "#" + Request.Form["hashtag"].ToString() : "") + "'\">Novo campo</button></div>"; switch (filter) { case "add_user": break; default: /*if (retRole != null) * html += "<div class=\"sep\"><button class=\"a-btn-big a-btn\" type=\"button\" onclick=\"window.location='" + ApplicationVirtualPath + "admin/roles/" + retRole.result.info.role_id + "/add_user/" + (Request.Form["hashtag"] != null ? "#" + Request.Form["hashtag"].ToString() : "") + "'\">Adicionar usuários</button></div>";*/ break; } } contentRet = new WebJsonResponse("#main aside", html); break; case "mobilebar": break; case "buttonbox": break; } if (contentRet != null) { if (!String.IsNullOrWhiteSpace((String)Request["cid"])) { contentRet.callId = (String)Request["cid"]; } Retorno.Controls.Add(new LiteralControl(contentRet.ToJSON())); } }
protected void Page_Load(object sender, EventArgs e) { WebJsonResponse contentRet = null; String action = ""; if (!String.IsNullOrWhiteSpace((String)RouteData.Values["action"])) { action = (String)RouteData.Values["action"]; } Int64 proxyId = 0; if (action != "add_proxy") { try { proxyId = Int64.Parse((String)RouteData.Values["id"]); if (proxyId < 0) { proxyId = 0; } } catch { } if (proxyId == 0) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("proxy_not_found"), 3000, true); action = ""; } } String rData = ""; //SqlConnection //conn = DB.GetConnection(); String jData = ""; try { switch (action) { case "delete": var reqDel = new { jsonrpc = "1.0", method = "proxy.delete", parameters = new { proxyid = proxyId }, id = 1 }; rData = JSON.Serialize2(reqDel); using (IAMDatabase database = new IAMDatabase(IAMDatabase.GetWebConnectionString())) jData = WebPageAPI.ExecuteLocal(database, this, rData); if (String.IsNullOrWhiteSpace(jData)) { throw new Exception(""); } RoleDeleteResult retDel = JSON.Deserialize <RoleDeleteResult>(jData); if (retDel == null) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("role_not_found"), 3000, true); } else if (retDel.error != null) { contentRet = new WebJsonResponse("", retDel.error.data, 3000, true); } else if (!retDel.result) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("role_not_found"), 3000, true); } else { contentRet = new WebJsonResponse(); } break; case "restart": var reqDst = new { jsonrpc = "1.0", method = "proxy.restart", parameters = new { proxyid = proxyId }, id = 1 }; rData = JSON.Serialize2(reqDst); using (IAMDatabase database = new IAMDatabase(IAMDatabase.GetWebConnectionString())) jData = WebPageAPI.ExecuteLocal(database, this, rData); if (String.IsNullOrWhiteSpace(jData)) { throw new Exception(""); } RoleDeleteResult retRst = JSON.Deserialize <RoleDeleteResult>(jData); if (retRst == null) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("role_not_found"), 3000, true); } else if (retRst.error != null) { contentRet = new WebJsonResponse("", retRst.error.data, 3000, true); } else if (!retRst.result) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("role_not_found"), 3000, true); } else { contentRet = new WebJsonResponse(); } break; case "change_name": String name = Request.Form["name"]; if (String.IsNullOrEmpty(name)) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("invalid_name"), 3000, true); break; } var reqD = new { jsonrpc = "1.0", method = "proxy.change", parameters = new { proxyid = proxyId, name = name }, id = 1 }; rData = JSON.Serialize2(reqD); using (IAMDatabase database = new IAMDatabase(IAMDatabase.GetWebConnectionString())) jData = WebPageAPI.ExecuteLocal(database, this, rData); if (String.IsNullOrWhiteSpace(jData)) { throw new Exception(""); } ProxyGetResult retD = JSON.Deserialize <ProxyGetResult>(jData); if (retD == null) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("proxy_not_found"), 3000, true); } else if (retD.error != null) { contentRet = new WebJsonResponse("", retD.error.data, 3000, true); } else if (retD.result == null) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("proxy_not_found"), 3000, true); } else if (retD.result == null || retD.result.info == null) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("proxy_not_found"), 3000, true); } else { contentRet = new WebJsonResponse("#proxy_name_" + proxyId, retD.result.info.name); } break; case "add_proxy": String proxyName = Request.Form["proxy_name"]; if (String.IsNullOrEmpty(proxyName)) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("type_proxy_name"), 3000, true); break; } var reqAddR = new { jsonrpc = "1.0", method = "proxy.new", parameters = new { name = proxyName }, id = 1 }; rData = JSON.Serialize2(reqAddR); using (IAMDatabase database = new IAMDatabase(IAMDatabase.GetWebConnectionString())) jData = WebPageAPI.ExecuteLocal(database, this, rData); if (String.IsNullOrWhiteSpace(jData)) { throw new Exception(""); } ProxyGetResult retAddR = JSON.Deserialize <ProxyGetResult>(jData); if (retAddR == null) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("proxy_not_found"), 3000, true); } else if (retAddR.error != null) { contentRet = new WebJsonResponse("", retAddR.error.data, 3000, true); //Tools.Tool.notifyException(new Exception(retAdd.error.data + retAdd.error.debug), this); } else if ((retAddR.result == null) || (retAddR.result.info == null)) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("proxy_not_found"), 3000, true); } else { contentRet = new WebJsonResponse(Session["ApplicationVirtualPath"] + "admin/proxy/" + (Request.Form["hashtag"] != null ? "#" + Request.Form["hashtag"].ToString() : "")); } // break; } } catch (Exception ex) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("api_error"), 3000, true); } finally { } if (contentRet != null) { if (!String.IsNullOrWhiteSpace((String)Request["cid"])) { contentRet.callId = (String)Request["cid"]; } Retorno.Controls.Add(new LiteralControl(contentRet.ToJSON())); } }
protected void Page_Load(object sender, EventArgs e) { WebJsonResponse contentRet = null; String action = ""; if (!String.IsNullOrWhiteSpace((String)RouteData.Values["action"])) { action = (String)RouteData.Values["action"]; } Int64 containerId = 0; if (action != "add_container") { try { containerId = Int64.Parse((String)RouteData.Values["id"]); if (containerId < 0) { containerId = 0; } } catch { } if (containerId == 0) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("container_not_found"), 3000, true); action = ""; } } String rData = ""; //SqlConnection //conn = DB.GetConnection(); String jData = ""; try { switch (action) { case "delete": var reqDel = new { jsonrpc = "1.0", method = "container.delete", parameters = new { containerid = containerId }, id = 1 }; rData = JSON.Serialize2(reqDel); using (IAMDatabase database = new IAMDatabase(IAMDatabase.GetWebConnectionString())) jData = WebPageAPI.ExecuteLocal(database, this, rData); if (String.IsNullOrWhiteSpace(jData)) { throw new Exception(""); } ContainerDeleteResult retDel = JSON.Deserialize <ContainerDeleteResult>(jData); if (retDel == null) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("container_not_found"), 3000, true); } else if (retDel.error != null) { contentRet = new WebJsonResponse("", retDel.error.data, 3000, true); } else if (!retDel.result) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("container_not_found"), 3000, true); } else { contentRet = new WebJsonResponse(); } break; case "delete_all_users": var reqDelUsr = new { jsonrpc = "1.0", method = "container.deleteallusers", parameters = new { containerid = containerId }, id = 1 }; rData = JSON.Serialize2(reqDelUsr); using (IAMDatabase database = new IAMDatabase(IAMDatabase.GetWebConnectionString())) jData = WebPageAPI.ExecuteLocal(database, this, rData); if (String.IsNullOrWhiteSpace(jData)) { throw new Exception(""); } ContainerDeleteResult retDelUsr = JSON.Deserialize <ContainerDeleteResult>(jData); if (retDelUsr == null) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("container_not_found"), 3000, true); } else if (retDelUsr.error != null) { contentRet = new WebJsonResponse("", retDelUsr.error.data, 3000, true); } else if (!retDelUsr.result) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("container_not_found"), 3000, true); } else { contentRet = new WebJsonResponse(); } break; case "delete_user_inactive": var reqDelUsr2 = new { jsonrpc = "1.0", method = "container.deleteuser", parameters = new { containerid = containerId, userid = (String)RouteData.Values["filter"] }, id = 1 }; rData = JSON.Serialize2(reqDelUsr2); using (IAMDatabase database = new IAMDatabase(IAMDatabase.GetWebConnectionString())) jData = WebPageAPI.ExecuteLocal(database, this, rData); if (String.IsNullOrWhiteSpace(jData)) { throw new Exception(""); } ContainerDeleteResult retDelUsr2 = JSON.Deserialize <ContainerDeleteResult>(jData); if (retDelUsr2 == null) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("container_not_found"), 3000, true); } else if (retDelUsr2.error != null) { contentRet = new WebJsonResponse("", retDelUsr2.error.data, 3000, true); } else if (!retDelUsr2.result) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("container_not_found"), 3000, true); } else { contentRet = new WebJsonResponse(); } break; case "change_name": String name = Request.Form["name"]; if (String.IsNullOrEmpty(name)) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("invalid_name"), 3000, true); break; } rData = JSON.Serialize2(new { jsonrpc = "1.0", method = "container.change", parameters = new { containerid = containerId, name = name }, id = 1 }); using (IAMDatabase database = new IAMDatabase(IAMDatabase.GetWebConnectionString())) jData = WebPageAPI.ExecuteLocal(database, this, rData); if (String.IsNullOrWhiteSpace(jData)) { throw new Exception(""); } ContainerGetResult retD = JSON.Deserialize <ContainerGetResult>(jData); if (retD == null) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("container_not_found"), 3000, true); } else if (retD.error != null) { contentRet = new WebJsonResponse("", retD.error.data, 3000, true); } else if (retD.result == null) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("container_not_found"), 3000, true); } else if (retD.result == null || retD.result.info == null) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("container_not_found"), 3000, true); } else { contentRet = new WebJsonResponse("#container_name_" + containerId, retD.result.info.name); } break; case "change": String name1 = Request.Form["container_name"]; if (String.IsNullOrEmpty(name1)) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("invalid_name"), 3000, true); break; } String parent_id1 = Request.Form["parent_container"]; if (String.IsNullOrEmpty(parent_id1)) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("select_parent_container"), 3000, true); break; } rData = JSON.Serialize2(new { jsonrpc = "1.0", method = "container.change", parameters = new { containerid = containerId, parentid = parent_id1, name = name1 }, id = 1 }); using (IAMDatabase database = new IAMDatabase(IAMDatabase.GetWebConnectionString())) jData = WebPageAPI.ExecuteLocal(database, this, rData); if (String.IsNullOrWhiteSpace(jData)) { throw new Exception(""); } ContainerGetResult retC1 = JSON.Deserialize <ContainerGetResult>(jData); if (retC1 == null) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("container_not_found"), 3000, true); } else if (retC1.error != null) { contentRet = new WebJsonResponse("", retC1.error.data, 3000, true); } else if (retC1.result == null) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("container_not_found"), 3000, true); } else if (retC1.result == null || retC1.result.info == null) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("container_not_found"), 3000, true); } else { contentRet = new WebJsonResponse("", "Atualização realizada com sucesso", 3000, false); } break; case "add_user": String user_id = Request.Form["user_id"]; if (String.IsNullOrEmpty(user_id)) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("select_username"), 3000, true); break; } var reqAdd = new { jsonrpc = "1.0", method = "container.adduser", parameters = new { containerid = containerId, userid = user_id }, id = 1 }; rData = JSON.Serialize2(reqAdd); using (IAMDatabase database = new IAMDatabase(IAMDatabase.GetWebConnectionString())) jData = WebPageAPI.ExecuteLocal(database, this, rData); if (String.IsNullOrWhiteSpace(jData)) { throw new Exception(""); } ContainerDeleteResult retAdd = JSON.Deserialize <ContainerDeleteResult>(jData); if (retAdd == null) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("container_not_found"), 3000, true); } else if (retAdd.error != null) { contentRet = new WebJsonResponse("", retAdd.error.data, 3000, true); //Tools.Tool.notifyException(new Exception(retAdd.error.data + retAdd.error.debug), this); } else if (!retAdd.result) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("container_not_found"), 3000, true); } else { contentRet = new WebJsonResponse(Session["ApplicationVirtualPath"] + "admin/container/" + (Request.Form["hashtag"] != null ? "#" + Request.Form["hashtag"].ToString() : "")); } // break; case "add_container": String containerName = Request.Form["container_name"]; if (String.IsNullOrEmpty(containerName)) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("type_role_name"), 3000, true); break; } String context_id = Request.Form["container_context"]; if (String.IsNullOrEmpty(context_id)) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("select_context"), 3000, true); break; } String parent_id = Request.Form["parent_container"]; if (String.IsNullOrEmpty(parent_id)) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("select_parent_container"), 3000, true); break; } if (parent_id != "0") { rData = SafeTrend.Json.JSON.Serialize2(new { jsonrpc = "1.0", method = "container.list", parameters = new { page_size = Int32.MaxValue, page = 1 }, id = 1 }); jData = ""; using (IAMDatabase database = new IAMDatabase(IAMDatabase.GetWebConnectionString())) jData = WebPageAPI.ExecuteLocal(database, this, rData); List <ContainerData> conteinerList = new List <ContainerData>(); ContainerListResult cl = JSON.Deserialize <ContainerListResult>(jData); if ((cl != null) && (cl.error == null) && (cl.result != null) && (cl.result.Count > 0)) { conteinerList.AddRange(cl.result); } ContainerData cd = null; foreach (ContainerData c in conteinerList) { if (c.container_id.ToString() == parent_id) { cd = c; } } if (cd == null) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("select_parent_container"), 3000, true); break; } if (cd.context_id.ToString() != context_id) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("container_context_not_same"), 3000, true); break; } } var reqAddR = new { jsonrpc = "1.0", method = "container.new", parameters = new { name = containerName, contextid = context_id, parentid = parent_id }, id = 1 }; rData = JSON.Serialize2(reqAddR); using (IAMDatabase database = new IAMDatabase(IAMDatabase.GetWebConnectionString())) jData = WebPageAPI.ExecuteLocal(database, this, rData); if (String.IsNullOrWhiteSpace(jData)) { throw new Exception(""); } ContainerGetResult retAddR = JSON.Deserialize <ContainerGetResult>(jData); if (retAddR == null) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("container_not_found"), 3000, true); } else if (retAddR.error != null) { contentRet = new WebJsonResponse("", retAddR.error.data, 3000, true); //Tools.Tool.notifyException(new Exception(retAdd.error.data + retAdd.error.debug), this); } else if ((retAddR.result == null) || (retAddR.result.info == null)) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("container_not_found"), 3000, true); } else { contentRet = new WebJsonResponse(Session["ApplicationVirtualPath"] + "admin/container/" + retAddR.result.info.container_id + "/add_user/" + (Request.Form["hashtag"] != null ? "#" + Request.Form["hashtag"].ToString() : "")); } // break; } } catch (Exception ex) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("api_error"), 3000, true); } finally { } if (contentRet != null) { if (!String.IsNullOrWhiteSpace((String)Request["cid"])) { contentRet.callId = (String)Request["cid"]; } Retorno.Controls.Add(new LiteralControl(contentRet.ToJSON())); } }
protected void Page_Load(object sender, EventArgs e) { WebJsonResponse contentRet = null; String action = ""; if (!String.IsNullOrWhiteSpace((String)RouteData.Values["action"])) { action = (String)RouteData.Values["action"]; } String serviceName = ""; try { serviceName = (String)RouteData.Values["id"]; } catch { } if (String.IsNullOrEmpty(serviceName)) { return; } String rData = ""; //SqlConnection //conn = DB.GetConnection(); String jData = ""; try { switch (action) { case "restart": using (IAMDatabase db = new IAMDatabase(IAMDatabase.GetWebConnectionString())) { DbParameterCollection par = new DbParameterCollection(); par.Add("@service_name", typeof(String)).Value = serviceName; DataTable dtServices = db.ExecuteDataTable("select * from service_status where service_name = @service_name", CommandType.Text, par); if ((dtServices != null) && (dtServices.Rows.Count > 0)) { if (serviceName.ToLower() != "watchdog") { db.ExecuteNonQuery("update service_status set started_at = null where service_name = @service_name", CommandType.Text, par); } contentRet = new WebJsonResponse(); } else { contentRet = new WebJsonResponse("", MessageResource.GetMessage("service_not_found"), 3000, true); } } break; } } catch (Exception ex) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("api_error"), 3000, true); } finally { } if (contentRet != null) { if (!String.IsNullOrWhiteSpace((String)Request["cid"])) { contentRet.callId = (String)Request["cid"]; } Retorno.Controls.Add(new LiteralControl(contentRet.ToJSON())); } }
protected void Page_Load(object sender, EventArgs e) { WebJsonResponse contentRet = null; EnterpriseData ent = (EnterpriseData)Page.Session["enterprise_data"]; String action = ""; if (!String.IsNullOrWhiteSpace((String)RouteData.Values["action"])) { action = (String)RouteData.Values["action"]; } String rData = ""; ////SqlConnection //conn = DB.GetConnection(); String jData = ""; try { switch (action) { case "change": String name = Request.Form["name"]; if (String.IsNullOrEmpty(name)) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("invalid_name"), 3000, true); break; } String auth_plugin = Request.Form["auth_plugin"]; if (String.IsNullOrEmpty(auth_plugin)) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("select_auth_service"), 3000, true); break; } AuthBase plugin = null; try { plugin = AuthBase.GetPlugin(new Uri(auth_plugin)); if (plugin == null) { throw new Exception(); } } catch { contentRet = new WebJsonResponse("", MessageResource.GetMessage("invalid_auth_service"), 3000, true); break; } Dictionary <String, String> pgValues = new Dictionary <string, string>(); AuthConfigFields[] fields = plugin.GetConfigFields(); if (fields.Length > 0) { WebJsonResponse err = null; foreach (AuthConfigFields f in fields) { String value = Request.Form["f_" + f.Key]; if (!String.IsNullOrEmpty(value)) { pgValues.Add(f.Key, value); } if (f.Required && !pgValues.ContainsKey(f.Key)) { err = new WebJsonResponse("", MessageResource.GetMessage("required_field") + " " + f.Name, 3000, true); break; } } if (err != null) { contentRet = err; break; } } List <String> hosts = new List <String>(); foreach (String key in Request.Form.Keys) { if (key.ToLower().IndexOf("host_") == 0) { String[] ht = Request.Form[key].ToString().Split(",".ToCharArray()); foreach (String host in ht) { if (!String.IsNullOrWhiteSpace(host)) { hosts.Add(host); } } } } var reqD = new { jsonrpc = "1.0", method = "enterprise.change", parameters = new { enterpriseid = ent.Id, name = name, auth_plugin = auth_plugin, fqdn_alias = hosts.ToArray(), auth_paramters = pgValues }, id = 1 }; rData = JSON.Serialize2(reqD); using (IAMDatabase database = new IAMDatabase(IAMDatabase.GetWebConnectionString())) jData = WebPageAPI.ExecuteLocal(database, this, rData); if (String.IsNullOrWhiteSpace(jData)) { throw new Exception(""); } RoleGetResult retD = JSON.Deserialize <RoleGetResult>(jData); if (retD == null) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("enterprise_not_found"), 3000, true); } else if (retD.error != null) { contentRet = new WebJsonResponse("", retD.error.data, 3000, true); } else if (retD.result == null) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("enterprise_not_found"), 3000, true); } else if (retD.result == null || retD.result.info == null) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("enterprise_not_found"), 3000, true); } else { contentRet = new WebJsonResponse(Session["ApplicationVirtualPath"] + "admin/enterprise/"); } break; } } catch (Exception ex) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("api_error"), 3000, true); } finally { } if (contentRet != null) { if (!String.IsNullOrWhiteSpace((String)Request["cid"])) { contentRet.callId = (String)Request["cid"]; } Retorno.Controls.Add(new LiteralControl(contentRet.ToJSON())); } }
protected void Page_Load(object sender, EventArgs e) { WebJsonResponse ret = null; //ResourceManager rm = new ResourceManager("Resources.Strings", System.Reflection.Assembly.Load("App_GlobalResources")); //CultureInfo ci = Thread.CurrentThread.CurrentCulture; try { Int64 enterpriseID = ((EnterpriseData)Page.Session["enterprise_data"]).Id; Int64 entityId = 0; String err = ""; String userCode = Request["userCode"]; if ((userCode == null) || (userCode == "")) { ret = new WebJsonResponse("", MessageResource.GetMessage("type_code"), 3000, true); } else { if (Session["entityId"] != null) { entityId = (Int64)Session["entityId"]; } if (entityId > 0) { using (IAMDatabase db = new IAMDatabase(IAMDatabase.GetWebConnectionString())) { DataTable c = db.Select("select * from entity where deleted = 0 and id = " + entityId + " and recovery_code = '" + Tools.Tool.TrataInjection(userCode) + "'"); if ((c != null) && (c.Rows.Count > 0)) { Session["userCode"] = c.Rows[0]["recovery_code"].ToString(); String html = ""; html += "<form id=\"serviceRecover\" name=\"serviceRecover\" method=\"post\" action=\"/consoleapi/recover4/\">"; html += "<div class=\"login_form\">"; html += "<input type=\"hidden\" name=\"do\" value=\"recover4\" />"; html += "<ul>"; html += " <li>"; html += " <p style=\"width:100%;padding:0 0 5px 0;color:#000;\">" + MessageResource.GetMessage("new_password_title") + "</p>"; html += " </li>"; html += " <li>"; html += " <span class=\"inputWrap\">"; //html += " <span id=\"ph_password\" class=\"noSel\" style=\"position: absolute; z-index: 1; top: 13px; left: 53px; color: rgb(204, 204, 204); display: block;\">" + MessageResource.GetMessage("new_password") + "</span>"; html += " <input type=\"password\" id=\"password\" tabindex=\"1\" name=\"password\" value=\"\" style=\"\" placeholder=\""+ MessageResource.GetMessage("new_password") + "\" onkeyup=\"iamadmin.passwordStrength('#password');\" onfocus=\"$('#password').addClass('focus');\" onblur=\"$('#password').removeClass('focus');\" />"; html += " <span id=\"ph_passwordIcon\" onclick=\"$('#password').focus();\"></span>"; html += " </span>"; html += " </li>"; html += " <li>"; html += " <span class=\"inputWrap\">"; //html += " <span id=\"ph_password2\" class=\"noSel\" style=\"position: absolute; z-index: 1; top: 13px; left: 53px; color: rgb(204, 204, 204); display: block;\">" + MessageResource.GetMessage("new_password_confirm") + "</span>"; html += " <input type=\"password\" id=\"password2\" tabindex=\"1\" name=\"password2\" value=\"\" style=\"\" placeholder=\""+ MessageResource.GetMessage("new_password_confirm") + "\" onfocus=\"$('#password2').addClass('focus');\" onblur=\"$('#password2').removeClass('focus');\" />"; html += " <span id=\"ph_passwordIcon\" onclick=\"$('#password2').focus();\"></span>"; html += " </span>"; html += " </li>"; html += " <li>"; html += " <div id=\"passwordStrength\"><span>" + MessageResource.GetMessage("password_strength") + ": " + MessageResource.GetMessage("unknow") + "</span><div class=\"bar\"></div></div>"; html += " </li>"; html += " <li>"; html += " <span class=\"forgot\"> <a href=\"/\">" + MessageResource.GetMessage("cancel") + "</a> " + MessageResource.GetMessage("or") + " </span>"; html += " <button tabindex=\"4\" id=\"submitBtn\" class=\"action button floatright\">" + MessageResource.GetMessage("change_password") + "</button>"; html += " </li>"; html += "</ul> "; html += "</div>"; html += "</form>"; ret = new WebJsonResponse("#recover_container", html); } else { ret = new WebJsonResponse("", MessageResource.GetMessage("invalid_code"), 3000, true); } } } else { ret = new WebJsonResponse("", MessageResource.GetMessage("invalid_session"), 3000, true); } } } catch (Exception ex) { Tools.Tool.notifyException(ex); throw ex; } if (ret != null) { ReturnHolder.Controls.Add(new LiteralControl(ret.ToJSON())); } }
protected void Page_Load(object sender, EventArgs e) { if (Request.HttpMethod != "POST") { return; } String area = ""; if (!String.IsNullOrWhiteSpace((String)RouteData.Values["area"])) { area = (String)RouteData.Values["area"]; } Int64 enterpriseId = 0; if ((Session["enterprise_data"]) != null && (Session["enterprise_data"] is EnterpriseData)) { enterpriseId = ((EnterpriseData)Session["enterprise_data"]).Id; } Boolean newItem = false; if ((RouteData.Values["new"] != null) && (RouteData.Values["new"] == "1")) { newItem = true; } String ApplicationVirtualPath = Session["ApplicationVirtualPath"].ToString(); LMenu menu1 = new LMenu("Dashboard", ApplicationVirtualPath + "admin/"); LMenu menu2 = new LMenu("Perfis", ApplicationVirtualPath + "admin/roles/" + (Request.Form["hashtag"] != null ? "#" + Request.Form["hashtag"].ToString() : "")); LMenu menu3 = new LMenu("Perfis de usuário", ApplicationVirtualPath + "admin/roles/" + (Request.Form["hashtag"] != null ? "#" + Request.Form["hashtag"].ToString() : "")); WebJsonResponse contentRet = null; String html = ""; String eHtml = ""; String js = null; String errorTemplate = "<span class=\"empty-results\">{0}</span>"; //Verifica se está sendo selecionada uma role Int64 roleId = 0; try { roleId = Int64.Parse((String)RouteData.Values["id"]); if (roleId < 0) { roleId = 0; } } catch { } String error = ""; RoleGetResult retRole = null; String filter = ""; HashData hashData = new HashData(this); if (!String.IsNullOrWhiteSpace((String)RouteData.Values["filter"])) { filter = (String)RouteData.Values["filter"]; } if ((roleId > 0) && (area.ToLower() != "search")) { try { var tmpReq = new { jsonrpc = "1.0", method = "role.get", parameters = new { roleid = roleId }, id = 1 }; String rData = SafeTrend.Json.JSON.Serialize2(tmpReq); String jData = ""; using (IAMDatabase database = new IAMDatabase(IAMDatabase.GetWebConnectionString())) jData = WebPageAPI.ExecuteLocal(database, this, rData); if (String.IsNullOrWhiteSpace(jData)) { throw new Exception(""); } retRole = JSON.Deserialize <RoleGetResult>(jData); if (retRole == null) { error = MessageResource.GetMessage("role_not_found"); //ret = new WebJsonResponse("", MessageResource.GetMessage("user_not_found"), 3000, true); } else if (retRole.error != null) { error = retRole.error.data; retRole = null; } else if (retRole.result == null || retRole.result.info == null) { error = MessageResource.GetMessage("role_not_found"); retRole = null; } else { menu3.Name = retRole.result.info.name; } } catch (Exception ex) { error = MessageResource.GetMessage("api_error"); Tools.Tool.notifyException(ex, this); retRole = null; //ret = new WebJsonResponse("", MessageResource.GetMessage("api_error"), 3000, true); } } switch (area) { case "": case "search": case "content": if (newItem) { try { var tmpReq = new { jsonrpc = "1.0", method = "context.list", parameters = new { }, id = 1 }; error = ""; String rData = SafeTrend.Json.JSON.Serialize2(tmpReq); String jData = ""; using (IAMDatabase database = new IAMDatabase(IAMDatabase.GetWebConnectionString())) jData = WebPageAPI.ExecuteLocal(database, this, rData); if (String.IsNullOrWhiteSpace(jData)) { throw new Exception(""); } ContextListResult contextList = JSON.Deserialize <ContextListResult>(jData); if (contextList == null) { error = MessageResource.GetMessage("context_not_found"); //ret = new WebJsonResponse("", MessageResource.GetMessage("user_not_found"), 3000, true); } else if (contextList.error != null) { error = contextList.error.data; retRole = null; } else if (contextList.result == null) { error = MessageResource.GetMessage("context_not_found"); retRole = null; } else { html = "<h3>Adição de perfil</h3>"; html += "<form id=\"form_add_role\" method=\"post\" action=\"" + ApplicationVirtualPath + "admin/roles/action/add_role/\"><div class=\"no-tabs pb10\">"; html += "<div class=\"form-group\"><label>Nome</label><input id=\"add_role_name\" name=\"add_role_name\" placeholder=\"Digite o nome do perfil\" type=\"text\"\"></div>"; html += "<div class=\"form-group\"><label>Contexto</label><select id=\"add_role_context\" name=\"add_role_context\" ><option value=\"\"></option>"; foreach (ContextData c in contextList.result) { html += "<option value=\"" + c.context_id + "\" " + (hashData.GetValue("context") == c.context_id.ToString() ? "selected" : "") + ">" + c.name + "</option>"; } html += "</select></div>"; html += "<div class=\"clear-block\"></div></div>"; html += "<button type=\"submit\" id=\"user-profile-password-save\" class=\"button secondary floatleft\">Adicionar</button> <a href=\"" + ApplicationVirtualPath + "admin/roles/" + (Request.Form["hashtag"] != null ? "#" + Request.Form["hashtag"].ToString() : "") + "\" class=\"button link floatleft\">Cancelar</a></form>"; contentRet = new WebJsonResponse("#content-wrapper", (eHtml != "" ? eHtml : html)); } } catch (Exception ex) { error = MessageResource.GetMessage("api_error"); } if (error != "") { contentRet = new WebJsonResponse("#content-wrapper", String.Format(errorTemplate, error)); } } else { if (retRole == null) { Int32 page = 1; Int32 pageSize = 20; Boolean hasNext = true; Int32.TryParse(Request.Form["page"], out page); if (page < 1) { page = 1; } String roleTemplate = "<div id=\"role-list-{0}\" data-id=\"{0}\" data-name=\"{1}\" data-total=\"{2}\" class=\"app-list-item\">"; roleTemplate += "<table>"; roleTemplate += " <tbody>"; roleTemplate += " <tr>"; roleTemplate += " <td class=\"col1\">"; roleTemplate += " <span id=\"total_{0}\" class=\"total \">{2}</span>"; roleTemplate += " <a href=\"" + ApplicationVirtualPath + "admin/roles/{0}/users/" + (Request.Form["hashtag"] != null ? "#" + Request.Form["hashtag"].ToString() : "") + "\">"; roleTemplate += " <div class=\"app-btn a-btn\"><span class=\"a-btn-inner\">Ver usuários</span></div>"; roleTemplate += " </a>"; roleTemplate += " </td>"; roleTemplate += " <td class=\"col2\">"; roleTemplate += " <div class=\"title\"><span class=\"name field-editor\" id=\"role_name_{0}\" data-id=\"{0}\" data-function=\"iamadmin.editTextField('#role_name_{0}',null,roleNameEdit);\">{1}</span><span class=\"date\">{3}</span><div class=\"clear-block\"></div></div>"; roleTemplate += " <div class=\"links no-bg\">"; roleTemplate += " <div class=\"first\"><a href=\"" + ApplicationVirtualPath + "admin/roles/{0}/add_user/" + (Request.Form["hashtag"] != null ? "#" + Request.Form["hashtag"].ToString() : "") + "\"><div class=\"ico icon-user-add\">Adicionar usuário</div></a><br clear=\"all\"></div>"; roleTemplate += " <div class=\"\"><a href=\"" + ApplicationVirtualPath + "admin/roles/{0}/action/delete_all_users/" + (Request.Form["hashtag"] != null ? "#" + Request.Form["hashtag"].ToString() : "") + "\" class=\"confirm-action\" confirm-title=\"Exclusão\" confirm-text=\"Deseja excluir definitivamente todos os usuários do perfil '{1}'?\" ok=\"Excluir\" cancel=\"Cancelar\"><div class=\"ico icon-close\">Excluir usuários</div></a></div>"; roleTemplate += " <div class=\"last\"><a class=\"confirm-action\" href=\"" + ApplicationVirtualPath + "admin/roles/{0}/action/delete/" + (Request.Form["hashtag"] != null ? "#" + Request.Form["hashtag"].ToString() : "") + "\" confirm-title=\"Exclusão\" confirm-text=\"Deseja excluir definitivamente o perfil '{1}'?\" ok=\"Excluir\" cancel=\"Cancelar\"><div class=\"ico icon-close\">Apagar</div></a><br clear=\"all\"></div>"; roleTemplate += " </div><br clear=\"all\">"; roleTemplate += " </td>"; roleTemplate += " </tr>"; roleTemplate += " </tbody>"; roleTemplate += "</table></div>"; js += "roleNameEdit = function(thisId, changedText) { iamadmin.changeName(thisId,changedText); };"; html += "<div id=\"box-container\" class=\"box-container\">"; String query = ""; try { String rData = ""; if (!String.IsNullOrWhiteSpace((String)RouteData.Values["query"])) { query = (String)RouteData.Values["query"]; } if (String.IsNullOrWhiteSpace(query) && !String.IsNullOrWhiteSpace(hashData.GetValue("query"))) { query = hashData.GetValue("query"); } if (String.IsNullOrWhiteSpace(query)) { var tmpReq = new { jsonrpc = "1.0", method = "role.list", parameters = new { page_size = pageSize, page = page, filter = new { contextid = hashData.GetValue("context") } }, id = 1 }; rData = SafeTrend.Json.JSON.Serialize2(tmpReq); } else { var tmpReq = new { jsonrpc = "1.0", method = "role.search", parameters = new { text = query, page_size = pageSize, page = page, filter = new { contextid = hashData.GetValue("context") } }, id = 1 }; rData = SafeTrend.Json.JSON.Serialize2(tmpReq); } String jData = ""; using (IAMDatabase database = new IAMDatabase(IAMDatabase.GetWebConnectionString())) jData = WebPageAPI.ExecuteLocal(database, this, rData); if (String.IsNullOrWhiteSpace(jData)) { throw new Exception(""); } RoleListResult ret2 = JSON.Deserialize <RoleListResult>(jData); if (ret2 == null) { eHtml += String.Format(errorTemplate, MessageResource.GetMessage("role_not_found")); hasNext = false; } else if (ret2.error != null) { #if DEBUG eHtml += String.Format(errorTemplate, ret2.error.data + ret2.error.debug); #else eHtml += String.Format(errorTemplate, ret2.error.data); #endif hasNext = false; } else if (ret2.result == null || (ret2.result.Count == 0 && page == 1)) { eHtml += String.Format(errorTemplate, MessageResource.GetMessage("role_not_found")); hasNext = false; } else { foreach (RoleData role in ret2.result) { html += String.Format(roleTemplate, role.role_id, role.name, role.entity_qty, (role.create_date > 0 ? "Criado em " + MessageResource.FormatDate(new DateTime(1970, 1, 1).AddSeconds(role.create_date), true) : "")); } if (ret2.result.Count < pageSize) { hasNext = false; } } } catch (Exception ex) { eHtml += String.Format(errorTemplate, MessageResource.GetMessage("api_error")); } if (page == 1) { html += "</div>"; html += "<span class=\"empty-results content-loading role-list-loader hide\"></span>"; contentRet = new WebJsonResponse("#content-wrapper", (eHtml != "" ? eHtml : html)); } else { contentRet = new WebJsonResponse("#content-wrapper #box-container", (eHtml != "" ? eHtml : html), true); } contentRet.js = js + "$( document ).unbind('end_of_scroll');"; if (hasNext) { contentRet.js += "$( document ).bind( 'end_of_scroll.loader_role', function() { $( document ).unbind('end_of_scroll.loader_role'); $('.role-list-loader').removeClass('hide'); iamadmin.getPageContent2( { page: " + ++page + ", search:'" + (!String.IsNullOrWhiteSpace(query) ? query : "") + "' }, function(){ $('.role-list-loader').addClass('hide'); } ); });"; } } else //Esta sendo selecionado a role { if (error != "") { contentRet = new WebJsonResponse("#content-wrapper", String.Format(errorTemplate, error)); } else { switch (filter) { case "": case "users": Int32 page = 1; Int32 pageSize = 20; Boolean hasNext = true; Int32.TryParse(Request.Form["page"], out page); if (page < 1) { page = 1; } if (page == 1) { html += "<table id=\"users-table\" class=\"sorter\"><thead>"; html += " <tr>"; html += " <th class=\"w50 mHide {sorter: false}\"><div class=\"select-all\"></div></th>"; html += " <th class=\"pointer header headerSortDown\" data-column=\"name\">Nome <div class=\"icomoon\"></div></th>"; html += " <th class=\"pointer tHide mHide header\" data-column=\"login\">Login <div class=\"icomoon\"></div></th>"; html += " <th class=\"pointer w200 tHide mHide header\" data-column=\"last_login\">Ações <div class=\"icomoon\"></div></th>"; html += " </tr>"; html += "</thead>"; html += "<tbody>"; } String trTemplate = " <tr class=\"user\" data-login=\"{1}\" data-userid=\"{0}\">"; trTemplate += " <td class=\"select mHide\"><div class=\"checkbox\"></div></td>"; trTemplate += " <td class=\"ident10\">{2}</td>"; trTemplate += " <td class=\"tHide mHide\">{1}</td>"; trTemplate += " <td class=\"tHide mHide\"><button class=\"a-btn\" onclick=\"window.location = '" + ApplicationVirtualPath + "admin/users/{0}/';\">Abrir</button> <button href=\"" + ApplicationVirtualPath + "admin/roles/" + retRole.result.info.role_id + "/action/delete_user/{0}/" + (Request.Form["hashtag"] != null ? "#" + Request.Form["hashtag"].ToString() : "") + "\" class=\"a-btn confirm-action\" confirm-title=\"Exclusão\" confirm-text=\"Deseja excluir definitivamente o vínculo do usuário '{2}' com o perfil '" + retRole.result.info.name + "'?\" ok=\"Excluir\" cancel=\"Cancelar\">Excluir</button></td>"; trTemplate += " </tr>"; try { String rData = ""; var tmpReq = new { jsonrpc = "1.0", method = "role.users", parameters = new { page_size = pageSize, page = page, roleid = roleId }, id = 1 }; rData = SafeTrend.Json.JSON.Serialize2(tmpReq); String jData = ""; using (IAMDatabase database = new IAMDatabase(IAMDatabase.GetWebConnectionString())) jData = WebPageAPI.ExecuteLocal(database, this, rData); if (String.IsNullOrWhiteSpace(jData)) { throw new Exception(""); } SearchResult ret2 = JSON.Deserialize <SearchResult>(jData); if (ret2 == null) { eHtml += String.Format(errorTemplate, MessageResource.GetMessage("user_not_found")); //ret = new WebJsonResponse("", MessageResource.GetMessage("user_not_found"), 3000, true); hasNext = false; } else if (ret2.error != null) { eHtml += String.Format(errorTemplate, ret2.error.data); //ret = new WebJsonResponse("", ret2.error.data, 3000, true); hasNext = false; } else if (ret2.result == null || (ret2.result.Count == 0 && page == 1)) { eHtml += String.Format(errorTemplate, MessageResource.GetMessage("user_not_found")); hasNext = false; } else { foreach (UserData user in ret2.result) { html += String.Format(trTemplate, user.userid, user.login, user.full_name); } if (ret2.result.Count < pageSize) { hasNext = false; } } } catch (Exception ex) { eHtml += String.Format(errorTemplate, MessageResource.GetMessage("api_error")); //ret = new WebJsonResponse("", MessageResource.GetMessage("api_error"), 3000, true); } if (page == 1) { html += "</tbody></table>"; html += "<span class=\"empty-results content-loading user-list-loader hide\"></span>"; contentRet = new WebJsonResponse("#content-wrapper", (eHtml != "" ? eHtml : html)); } else { contentRet = new WebJsonResponse("#content-wrapper tbody", (eHtml != "" ? eHtml : html), true); } contentRet.js = "$( document ).unbind('end_of_scroll.loader_usr');"; if (hasNext) { contentRet.js += "$( document ).bind( 'end_of_scroll.loader_usr', function() { $( document ).unbind('end_of_scroll.loader_usr'); $('.user-list-loader').removeClass('hide'); iamadmin.getPageContent2( { page: " + ++page + ", search:'' }, function(){ $('.user-list-loader').addClass('hide'); } ); });"; } break; case "add_user": html = "<h3>Adição de usuário</h3>"; html += "<form id=\"form_add_user\" method=\"post\" action=\"" + ApplicationVirtualPath + "admin/roles/" + roleId + "/action/add_user/\"><div class=\"no-tabs pb10\">"; html += "<div class=\"form-group\" id=\"add_user\"><label>Usuário</label><input id=\"add_user_text\" placeholder=\"Digite o nome do usuário\" type=\"text\"\"></div>"; html += "<div class=\"clear-block\"></div></div>"; html += "<h3>Usuários selecionados</h3>"; html += "<div id=\"box-container\" class=\"box-container\"><div class=\"no-tabs pb10 none\">"; html += "Nenhum usuário selecionado"; html += "</div></div>"; html += "<button type=\"submit\" id=\"user-profile-password-save\" class=\"button secondary floatleft\">Cadastrar</button> <a href=\"" + ApplicationVirtualPath + "admin/roles/" + (Request.Form["hashtag"] != null ? "#" + Request.Form["hashtag"].ToString() : "") + "\" class=\"button link floatleft\">Cancelar</a></form>"; contentRet = new WebJsonResponse("#content-wrapper", (eHtml != "" ? eHtml : html)); contentRet.js = "iamadmin.autoCompleteText('#add_user_text', '" + ApplicationVirtualPath + "admin/users/content/search_user/', {context_id: '" + retRole.result.info.context_id + "'} , function(thisId, selectedItem){ $(thisId).val(''); $('.none').remove(); $('.box-container').append(selectedItem.html); } )"; break; } } } } break; case "sidebar": if (menu1 != null) { html += "<div class=\"sep\"><div class=\"section-nav-header\">"; html += " <div class=\"crumbs\">"; html += " <div class=\"subject subject-color\">"; html += " <a href=\"" + menu1.HRef + "\">" + menu1.Name + "</a>"; html += " </div>"; if (menu2 != null) { html += " <div class=\"topic topic-color\">"; html += " <a href=\"" + menu2.HRef + "\">" + menu2.Name + "</a>"; html += " </div>"; } html += " </div>"; if (menu3 != null) { html += " <div class=\"crumbs tutorial-title\">"; html += " <h2 class=\"title tutorial-color\">" + menu3.Name + "</h2>"; html += " </div>"; } html += "</div></div>"; } if (!newItem) { html += "<div class=\"sep\"><button class=\"a-btn-big a-btn\" type=\"button\" onclick=\"window.location='" + ApplicationVirtualPath + "admin/roles/new/" + (Request.Form["hashtag"] != null ? "#" + Request.Form["hashtag"].ToString() : "") + "'\">Novo perfil</button></div>"; switch (filter) { case "add_user": break; default: if (retRole != null) { html += "<div class=\"sep\"><button class=\"a-btn-big a-btn\" type=\"button\" onclick=\"window.location='" + ApplicationVirtualPath + "admin/roles/" + retRole.result.info.role_id + "/add_user/" + (Request.Form["hashtag"] != null ? "#" + Request.Form["hashtag"].ToString() : "") + "'\">Adicionar usuários</button></div>"; } break; } } contentRet = new WebJsonResponse("#main aside", html); break; case "mobilebar": break; case "buttonbox": switch (filter) { case "": try { var tmpReq = new { jsonrpc = "1.0", method = "context.list", parameters = new { }, id = 1 }; error = ""; String rData = SafeTrend.Json.JSON.Serialize2(tmpReq); String jData = ""; using (IAMDatabase database = new IAMDatabase(IAMDatabase.GetWebConnectionString())) jData = WebPageAPI.ExecuteLocal(database, this, rData); if (String.IsNullOrWhiteSpace(jData)) { throw new Exception(""); } ContextListResult contextList = JSON.Deserialize <ContextListResult>(jData); if (contextList == null) { error = MessageResource.GetMessage("context_not_found"); //ret = new WebJsonResponse("", MessageResource.GetMessage("user_not_found"), 3000, true); } else if (contextList.error != null) { error = contextList.error.data; retRole = null; } else if (contextList.result == null) { error = MessageResource.GetMessage("context_not_found"); retRole = null; } else { html += "<select id=\"filter_context\" name=\"filter_context\" ><option value=\"\">Todos os contextos</option>"; foreach (ContextData c in contextList.result) { html += "<option value=\"context/" + c.context_id + "\" " + (hashData.GetValue("context") == c.context_id.ToString() ? "selected" : "") + ">" + c.name + "</option>"; } html += "</select>"; contentRet = new WebJsonResponse("#btnbox", html); contentRet.js = "$('#filter_context').change(function() { iamadmin.changeHash( $( this ).val() ); });"; } } catch (Exception ex) { error = MessageResource.GetMessage("api_error"); } break; } break; } if (contentRet != null) { if (!String.IsNullOrWhiteSpace((String)Request["cid"])) { contentRet.callId = (String)Request["cid"]; } Retorno.Controls.Add(new LiteralControl(contentRet.ToJSON())); } }
protected void Page_Load(object sender, EventArgs e) { if (Request.HttpMethod != "POST") { return; } String area = ""; if (!String.IsNullOrWhiteSpace((String)RouteData.Values["area"])) { area = (String)RouteData.Values["area"]; } Int64 enterpriseId = 0; if ((Session["enterprise_data"]) != null && (Session["enterprise_data"] is EnterpriseData)) { enterpriseId = ((EnterpriseData)Session["enterprise_data"]).Id; } Boolean newItem = false; if ((RouteData.Values["new"] != null) && (RouteData.Values["new"] == "1")) { newItem = true; } String ApplicationVirtualPath = Session["ApplicationVirtualPath"].ToString(); LMenu menu1 = new LMenu("Dashboard", ApplicationVirtualPath + "admin/"); LMenu menu2 = new LMenu("Filtros", ApplicationVirtualPath + "admin/filter/" + (Request.Form["hashtag"] != null ? "#" + Request.Form["hashtag"].ToString() : "")); LMenu menu3 = new LMenu("Filtros", ApplicationVirtualPath + "admin/filter/" + (Request.Form["hashtag"] != null ? "#" + Request.Form["hashtag"].ToString() : "")); WebJsonResponse contentRet = null; String html = ""; String eHtml = ""; String js = null; String errorTemplate = "<span class=\"empty-results\">{0}</span>"; //Verifica se está sendo selecionada uma role Int64 filterId = 0; try { filterId = Int64.Parse((String)RouteData.Values["id"]); if (filterId < 0) { filterId = 0; } } catch { } String error = ""; FilterGetResult retFilter = null; String filter = ""; HashData hashData = new HashData(this); String rData = null; //SqlConnection conn = null; String jData = ""; Int32 page = 1; Int32 pageSize = 20; Boolean hasNext = true; if (!String.IsNullOrWhiteSpace((String)RouteData.Values["filter"])) { filter = (String)RouteData.Values["filter"]; } if ((filterId > 0) && (area.ToLower() != "search")) { try { rData = SafeTrend.Json.JSON.Serialize2(new { jsonrpc = "1.0", method = "filter.get", parameters = new { filterid = filterId }, id = 1 }); jData = ""; using (IAMDatabase database = new IAMDatabase(IAMDatabase.GetWebConnectionString())) jData = WebPageAPI.ExecuteLocal(database, this, rData); if (String.IsNullOrWhiteSpace(jData)) { throw new Exception(""); } retFilter = JSON.Deserialize <FilterGetResult>(jData); if (retFilter == null) { error = MessageResource.GetMessage("filter_not_found"); //ret = new WebJsonResponse("", MessageResource.GetMessage("user_not_found"), 3000, true); } else if (retFilter.error != null) { error = retFilter.error.data; retFilter = null; } else if (retFilter.result == null || retFilter.result.info == null) { error = MessageResource.GetMessage("filter_not_found"); retFilter = null; } else { menu3.Name = retFilter.result.info.name; } } catch (Exception ex) { error = MessageResource.GetMessage("api_error"); Tools.Tool.notifyException(ex, this); retFilter = null; //ret = new WebJsonResponse("", MessageResource.GetMessage("api_error"), 3000, true); } } String infoTemplate = "<tr><td class=\"col1\">{0}</td><td class=\"col2\"><span class=\"no-edit\">{1}</span></td></tr>"; String groupTemplate = "<div id=\"{0}\"><div class=\"group\" group-id=\"{0}\"><div class=\"wrapper\"><div class=\"cmd-bar\"><div class=\"ico icon-close floatright\"></div></div>{1}<div class=\"cmd-bar1\"><div class=\"ico icon-plus floatright\"></div></div></div><div class=\"clear-block\"></div></div><div class=\"selector-wrapper\">{2}</div></div>"; String groupSelectorTemplate = "<div class=\"group-selector\"><select type=\"checkbox\" name=\"group_{0}_selector\"><option value=\"or\" {1}>or</option><option value=\"and\" {2}>and</option></select><div class=\"item {1}\" value=\"or\">OU</div><div class=\"item {2}\" value=\"and\">E</div><div class=\"clear-block\"></div></div>"; String filterSelectorTemplate = "<div class=\"filter-selector\"><select type=\"checkbox\" name=\"filter_{0}_selector\"><option value=\"or\" {1}>or</option><option value=\"and\" {2}>and</option></select> <div class=\"item {1}\" value=\"or\">OU</div><div class=\"item {2}\" value=\"and\">E</div><div class=\"clear-block\"></div></div>"; switch (area) { case "": case "search": case "content": if (newItem) { rData = SafeTrend.Json.JSON.Serialize2(new { jsonrpc = "1.0", method = "field.list", parameters = new { page_size = Int32.MaxValue }, id = 1 }); jData = ""; using (IAMDatabase database = new IAMDatabase(IAMDatabase.GetWebConnectionString())) jData = WebPageAPI.ExecuteLocal(database, this, rData); List <FieldData> fieldList = new List <FieldData>(); FieldListResult flR = JSON.Deserialize <FieldListResult>(jData); if ((flR != null) && (flR.error == null) && (flR.result != null)) { fieldList = flR.result; } String filterTemplate = GetFilterTemplate(fieldList, 0, "", ""); html = "<h3>Adição do filtro</h3>"; html += "<form id=\"form_add_role\" method=\"post\" action=\"" + ApplicationVirtualPath + "admin/filter/action/add_filter/\">"; html += "<div class=\"no-tabs fields\"><table><tbody>"; html += String.Format(infoTemplate, "Nome", "<input id=\"filter_name\" name=\"filter_name\" placeholder=\"Digite o nome do filtro\" type=\"text\"\">"); html += "</tbody></table><div class=\"clear-block\"></div></div>"; html += "<h3>Parametros de filtragem</h3><div class=\"no-tabs pb10\">"; html += "<div id=\"filter_conditions\"><div><div class=\"a-btn blue secondary\" onclick=\"iamfnc.addGroup();\">Inserir grupo</div></div>"; html += "<div class=\"filter-groups\">"; String filters = String.Format(filterTemplate, "F0", "0", ""); html += String.Format(groupTemplate, "0", filters, ""); html += "</div>"; html += "</div><div class=\"clear-block\"></div></div>"; html += "<button type=\"submit\" id=\"user-profile-password-save\" class=\"button secondary floatleft\">Salvar</button> <a href=\"" + ApplicationVirtualPath + "admin/filter/" + (Request.Form["hashtag"] != null ? "#" + Request.Form["hashtag"].ToString() : "") + "\" class=\"button link floatleft\">Cancelar</a></form>"; contentRet = new WebJsonResponse("#content-wrapper", (eHtml != "" ? eHtml : html)); contentRet.js = GetFilterJS(groupTemplate, groupSelectorTemplate, filterTemplate, filterSelectorTemplate); } else { if (retFilter == null) { Int32.TryParse(Request.Form["page"], out page); if (page < 1) { page = 1; } String proxyTemplate = "<div id=\"proxy-list-{0}\" data-id=\"{0}\" data-name=\"{1}\" data-total=\"{2}\" class=\"app-list-item\">"; proxyTemplate += "<table>"; proxyTemplate += " <tbody>"; proxyTemplate += " <tr>"; proxyTemplate += " <td class=\"col1\">"; proxyTemplate += " <span id=\"total_{0}\" class=\"total \">{2}</span>"; proxyTemplate += " <a href=\"" + ApplicationVirtualPath + "admin/filter/{0}/use/\">"; proxyTemplate += " <div class=\"app-btn a-btn\"><span class=\"a-btn-inner\">Ver utilizações</span></div>"; proxyTemplate += " </a>"; proxyTemplate += " </td>"; proxyTemplate += " <td class=\"col2\">"; proxyTemplate += " <div class=\"title\"><span class=\"name field-editor\" id=\"filter_name_{0}\" data-id=\"{0}\" data-function=\"iamadmin.editTextField('#filter_name_{0}',null,filterNameEdit);\">{1}</span><span class=\"date\">{3}</span><div class=\"clear-block\"></div></div>"; proxyTemplate += " <div class=\"description\">"; proxyTemplate += " <div class=\"first\">{4}</div>"; proxyTemplate += " </div>"; proxyTemplate += " <div class=\"links\">"; proxyTemplate += " <div class=\"last\">{5}</div>"; proxyTemplate += " </div>"; proxyTemplate += " </td>"; proxyTemplate += " </tr>"; proxyTemplate += " </tbody>"; proxyTemplate += "</table></div>"; js += "filterNameEdit = function(thisId, changedText) { iamadmin.changeName(thisId,changedText); };"; html += "<div id=\"box-container\" class=\"box-container\">"; String query = ""; try { rData = ""; if (!String.IsNullOrWhiteSpace((String)RouteData.Values["query"])) { query = (String)RouteData.Values["query"]; } if (String.IsNullOrWhiteSpace(query) && !String.IsNullOrWhiteSpace(hashData.GetValue("query"))) { query = hashData.GetValue("query"); } if (String.IsNullOrWhiteSpace(query)) { rData = SafeTrend.Json.JSON.Serialize2(new { jsonrpc = "1.0", method = "filter.list", parameters = new { page_size = pageSize, page = page }, id = 1 }); } else { rData = SafeTrend.Json.JSON.Serialize2(new { jsonrpc = "1.0", method = "filter.search", parameters = new { text = query, page_size = pageSize, page = page }, id = 1 }); } jData = ""; using (IAMDatabase database = new IAMDatabase(IAMDatabase.GetWebConnectionString())) jData = WebPageAPI.ExecuteLocal(database, this, rData); if (String.IsNullOrWhiteSpace(jData)) { throw new Exception(""); } FilterListResult ret2 = JSON.Deserialize <FilterListResult>(jData); if (ret2 == null) { eHtml += String.Format(errorTemplate, MessageResource.GetMessage("filter_not_found")); hasNext = false; } else if (ret2.error != null) { #if DEBUG eHtml += String.Format(errorTemplate, ret2.error.data + ret2.error.debug); #else eHtml += String.Format(errorTemplate, ret2.error.data); #endif hasNext = false; } else if (ret2.result == null || (ret2.result.Count == 0 && page == 1)) { eHtml += String.Format(errorTemplate, MessageResource.GetMessage("filter_not_found")); hasNext = false; } else { foreach (FilterData f in ret2.result) { String text = "<span>" + f.conditions_description + "</span>"; String links = ""; links += "<a href=\"" + ApplicationVirtualPath + "admin/filter/" + f.filter_id + "/" + (Request.Form["hashtag"] != null ? "#" + Request.Form["hashtag"].ToString() : "") + "\"><div class=\"ico icon-change\">Editar</div></a>"; links += (f.ignore_qty > 0 || f.lock_qty > 0 || f.role_qty > 0 ? "" : "<a class=\"confirm-action\" href=\"" + ApplicationVirtualPath + "admin/filter/" + f.filter_id + "/action/delete/" + (Request.Form["hashtag"] != null ? "#" + Request.Form["hashtag"].ToString() : "") + "\" confirm-title=\"Exclusão\" confirm-text=\"Deseja excluir definitivamente o filtro '" + f.name + "'?\" ok=\"Excluir\" cancel=\"Cancelar\"><div class=\"ico icon-close\">Apagar</div></a>"); html += String.Format(proxyTemplate, f.filter_id, f.name, f.ignore_qty + f.lock_qty + f.role_qty, (f.create_date > 0 ? "Criado em " + MessageResource.FormatDate(new DateTime(1970, 1, 1).AddSeconds(f.create_date), true) : ""), text, links); } if (ret2.result.Count < pageSize) { hasNext = false; } } } catch (Exception ex) { eHtml += String.Format(errorTemplate, MessageResource.GetMessage("api_error")); } if (page == 1) { html += "</div>"; html += "<span class=\"empty-results content-loading proxy-list-loader hide\"></span>"; contentRet = new WebJsonResponse("#content-wrapper", (eHtml != "" ? eHtml : html)); } else { contentRet = new WebJsonResponse("#content-wrapper #box-container", (eHtml != "" ? eHtml : html), true); } contentRet.js = js + "$( document ).unbind('end_of_scroll');"; if (hasNext) { contentRet.js += "$( document ).bind( 'end_of_scroll.loader_role', function() { $( document ).unbind('end_of_scroll.loader_role'); $('.proxy-list-loader').removeClass('hide'); iamadmin.getPageContent2( { page: " + ++page + ", search:'" + (!String.IsNullOrWhiteSpace(query) ? query : "") + "' }, function(){ $('.proxy-list-loader').addClass('hide'); } ); });"; } } else //Esta sendo selecionado o filtro { if (error != "") { contentRet = new WebJsonResponse("#content-wrapper", String.Format(errorTemplate, error)); } else { switch (filter) { case "": rData = SafeTrend.Json.JSON.Serialize2(new { jsonrpc = "1.0", method = "field.list", parameters = new { page_size = Int32.MaxValue }, id = 1 }); jData = ""; using (IAMDatabase database = new IAMDatabase(IAMDatabase.GetWebConnectionString())) jData = WebPageAPI.ExecuteLocal(database, this, rData); List <FieldData> fieldList = new List <FieldData>(); FieldListResult flR = JSON.Deserialize <FieldListResult>(jData); if ((flR != null) && (flR.error == null) && (flR.result != null)) { fieldList = flR.result; } String filterTemplate = GetFilterTemplate(fieldList, 0, "", ""); html = "<h3>Edição do filtro</h3>"; html += "<form id=\"form_add_role\" method=\"post\" action=\"" + ApplicationVirtualPath + "admin/filter/" + retFilter.result.info.filter_id + "/action/change/\">"; html += "<div class=\"no-tabs fields\"><table><tbody>"; html += String.Format(infoTemplate, "Nome", "<input id=\"filter_name\" name=\"filter_name\" placeholder=\"Digite o nome do filtro\" type=\"text\"\" value=\"" + retFilter.result.info.name + "\">"); html += "</tbody></table><div class=\"clear-block\"></div></div>"; html += "<h3>Parametros de filtragem</h3><div class=\"no-tabs pb10\">"; html += "<div id=\"filter_conditions\"><div><div class=\"a-btn blue secondary\" onclick=\"iamfnc.addGroup();\">Inserir grupo</div></div>"; html += "<div class=\"filter-groups\">"; FilterRule fr = new FilterRule(retFilter.result.info.name); foreach (IAM.GlobalDefs.WebApi.FilterCondition cond in retFilter.result.info.conditions) { fr.AddCondition(cond.group_id.ToString(), cond.group_selector, cond.field_id, cond.field_name, cond.data_type, cond.text, cond.condition, cond.selector); } for (Int32 g = 0; g < fr.FilterGroups.Count; g++) { String filters = ""; for (Int32 fIndex = 0; fIndex < fr.FilterGroups[g].FilterRules.Count; fIndex++) { String fId = fr.FilterGroups[g].GroupId + "-" + fIndex; String ft = GetFilterTemplate(fieldList, fr.FilterGroups[g].FilterRules[fIndex].FieldId, fr.FilterGroups[g].FilterRules[fIndex].DataString, fr.FilterGroups[g].FilterRules[fIndex].ConditionType.ToString()); filters += String.Format(ft, fId, fr.FilterGroups[g].GroupId, (fIndex < fr.FilterGroups[g].FilterRules.Count - 1 ? (fr.FilterGroups[g].FilterRules[fIndex].Selector == FilterSelector.AND ? String.Format(filterSelectorTemplate, fId, "", "selected") : String.Format(filterSelectorTemplate, fId, "selected", "")) : "")); } html += String.Format(groupTemplate, fr.FilterGroups[g].GroupId, filters, (g < fr.FilterGroups.Count - 1 ? (fr.FilterGroups[g].Selector == FilterSelector.AND ? String.Format(groupSelectorTemplate, fr.FilterGroups[g].GroupId, "", "selected") : String.Format(groupSelectorTemplate, fr.FilterGroups[g].GroupId, "selected", "")) : "")); } html += "</div>"; html += "</div><div class=\"clear-block\"></div></div>"; html += "<button type=\"submit\" id=\"user-profile-password-save\" class=\"button secondary floatleft\">Salvar</button> <a href=\"" + ApplicationVirtualPath + "admin/filter/" + (Request.Form["hashtag"] != null ? "#" + Request.Form["hashtag"].ToString() : "") + "\" class=\"button link floatleft\">Cancelar</a></form>"; contentRet = new WebJsonResponse("#content-wrapper", (eHtml != "" ? eHtml : html)); contentRet.js = GetFilterJS(groupTemplate, groupSelectorTemplate, filterTemplate, filterSelectorTemplate); break; case "use": if (retFilter != null) { Int32.TryParse(Request.Form["page"], out page); if (page < 1) { page = 1; } if (page == 1) { html = "<h3>Utilização deste perfil</h3>"; html += "<table id=\"users-table\" class=\"sorter\"><thead>"; html += " <tr>"; html += " <th class=\"w50 mHide {sorter: false}\"><div class=\"select-all\"></div></th>"; html += " <th class=\"pointer header headerSortDown\" data-column=\"name\">Recurso x Plugin <div class=\"icomoon\"></div></th>"; html += " <th class=\"pointer tHide mHide header\" data-column=\"login\">Bloqueio <div class=\"icomoon\"></div></th>"; html += " <th class=\"pointer tHide mHide header\" data-column=\"login\">Vínculo com perfil <div class=\"icomoon\"></div></th>"; html += " <th class=\"pointer tHide mHide header\" data-column=\"login\">Desconsiderar registros <div class=\"icomoon\"></div></th>"; html += " <th class=\"pointer w200 tHide mHide header\" data-column=\"last_login\">Ações <div class=\"icomoon\"></div></th>"; html += " </tr>"; html += "</thead>"; html += "<tbody>"; } String trTemplate = " <tr class=\"user\" data-userid=\"{0}\">"; trTemplate += " <td class=\"select mHide\"><div class=\"checkbox\"></div></td>"; trTemplate += " <td class=\"ident10\">{2}</td>"; trTemplate += " <td class=\"tHide mHide\">{3}</td>"; trTemplate += " <td class=\"tHide mHide\">{4}</td>"; trTemplate += " <td class=\"tHide mHide\">{5}</td>"; trTemplate += " <td class=\"tHide mHide\"><button class=\"a-btn\" onclick=\"window.location = '" + ApplicationVirtualPath + "admin/resource_plugin/{1}/';\">Abrir</button></td>"; trTemplate += " </tr>"; try { rData = SafeTrend.Json.JSON.Serialize2(new { jsonrpc = "1.0", method = "filter.use", parameters = new { page_size = pageSize, page = page, filterid = retFilter.result.info.filter_id }, id = 1 }); jData = ""; using (IAMDatabase database = new IAMDatabase(IAMDatabase.GetWebConnectionString())) jData = WebPageAPI.ExecuteLocal(database, this, rData); if (String.IsNullOrWhiteSpace(jData)) { throw new Exception(""); } FilterUseResult ret2 = JSON.Deserialize <FilterUseResult>(jData); if (ret2 == null) { eHtml += String.Format(errorTemplate, MessageResource.GetMessage("filter_not_found")); //ret = new WebJsonResponse("", MessageResource.GetMessage("user_not_found"), 3000, true); hasNext = false; } else if (ret2.error != null) { eHtml += String.Format(errorTemplate, ret2.error.data); //ret = new WebJsonResponse("", ret2.error.data, 3000, true); hasNext = false; } else if (ret2.result == null || (ret2.result.Count == 0 && page == 1)) { eHtml += String.Format(errorTemplate, MessageResource.GetMessage("filter_not_found")); hasNext = false; } else { foreach (FilterUseData f in ret2.result) { html += String.Format(trTemplate, f.filter_id, f.resource_plugin_id, f.resource_plugin_name, f.lock_qty, f.role_qty, f.ignore_qty); } if (ret2.result.Count < pageSize) { hasNext = false; } } } catch (Exception ex) { eHtml += String.Format(errorTemplate, MessageResource.GetMessage("api_error")); //ret = new WebJsonResponse("", MessageResource.GetMessage("api_error"), 3000, true); } if (page == 1) { html += "</tbody></table>"; html += "<span class=\"empty-results content-loading user-list-loader hide\"></span>"; contentRet = new WebJsonResponse("#content-wrapper", (eHtml != "" ? eHtml : html)); } else { contentRet = new WebJsonResponse("#content-wrapper tbody", (eHtml != "" ? eHtml : html), true); } contentRet.js = "$( document ).unbind('end_of_scroll.loader_usr');"; if (hasNext) { contentRet.js += "$( document ).bind( 'end_of_scroll.loader_usr', function() { $( document ).unbind('end_of_scroll.loader_usr'); $('.user-list-loader').removeClass('hide'); iamadmin.getPageContent2( { page: " + ++page + ", search:'' }, function(){ $('.user-list-loader').addClass('hide'); } ); });"; } } break; } } } } break; case "sidebar": if (menu1 != null) { html += "<div class=\"sep\"><div class=\"section-nav-header\">"; html += " <div class=\"crumbs\">"; html += " <div class=\"subject subject-color\">"; html += " <a href=\"" + menu1.HRef + "\">" + menu1.Name + "</a>"; html += " </div>"; if (menu2 != null) { html += " <div class=\"topic topic-color\">"; html += " <a href=\"" + menu2.HRef + "\">" + menu2.Name + "</a>"; html += " </div>"; } html += " </div>"; if (menu3 != null) { html += " <div class=\"crumbs tutorial-title\">"; html += " <h2 class=\"title tutorial-color\">" + menu3.Name + "</h2>"; html += " </div>"; } html += "</div></div>"; } if (!newItem) { html += "<div class=\"sep\"><button class=\"a-btn-big a-btn\" type=\"button\" onclick=\"window.location='" + ApplicationVirtualPath + "admin/filter/new/" + (Request.Form["hashtag"] != null ? "#" + Request.Form["hashtag"].ToString() : "") + "'\">Novo filtro</button></div>"; } contentRet = new WebJsonResponse("#main aside", html); break; case "mobilebar": break; case "buttonbox": break; } if (contentRet != null) { if (!String.IsNullOrWhiteSpace((String)Request["cid"])) { contentRet.callId = (String)Request["cid"]; } Retorno.Controls.Add(new LiteralControl(contentRet.ToJSON())); } }
protected void Page_Load(object sender, EventArgs e) { WebJsonResponse contentRet = null; Int64 enterpriseId = 0; if ((Session["enterprise_data"]) != null && (Session["enterprise_data"] is EnterpriseData)) { enterpriseId = ((EnterpriseData)Session["enterprise_data"]).Id; } String area = ""; if (!String.IsNullOrWhiteSpace((String)RouteData.Values["area"])) { area = (String)RouteData.Values["area"]; } Int64 proxyId = 0; try { proxyId = Int64.Parse((String)RouteData.Values["id"]); if (proxyId < 0) { proxyId = 0; } } catch { } if (proxyId == 0) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("proxy_not_found"), 3000, true); area = ""; } String rData = ""; String jData = ""; ProxyGetResult retProxy = null; try { rData = SafeTrend.Json.JSON.Serialize2(new { jsonrpc = "1.0", method = "proxy.get", parameters = new { proxyid = proxyId }, id = 1 }); jData = ""; using (IAMDatabase database = new IAMDatabase(IAMDatabase.GetWebConnectionString())) jData = WebPageAPI.ExecuteLocal(database, this, rData); if (String.IsNullOrWhiteSpace(jData)) { throw new Exception(""); } retProxy = JSON.Deserialize <ProxyGetResult>(jData); if (retProxy == null) { //error = MessageResource.GetMessage("proxy_not_found"); //ret = new WebJsonResponse("", MessageResource.GetMessage("user_not_found"), 3000, true); } else if (retProxy.error != null) { //error = retProxy.error.data; retProxy = null; } else if (retProxy.result == null || retProxy.result.info == null) { //error = MessageResource.GetMessage("proxy_not_found"); retProxy = null; } else { //menu3.Name = retProxy.result.info.name; } } catch (Exception ex) { //error = MessageResource.GetMessage("api_error"); Tools.Tool.notifyException(ex, this); retProxy = null; //ret = new WebJsonResponse("", MessageResource.GetMessage("api_error"), 3000, true); } try { switch (area) { case "download": if (retProxy != null) { DirectoryInfo tempPath = null; DirectoryInfo proxyPath = null; try { //Cria o diretório temporário tempPath = new DirectoryInfo(Path.Combine(Path.GetTempPath(), Path.GetRandomFileName())); proxyPath = new DirectoryInfo(Path.Combine(tempPath.FullName, "proxies\\" + enterpriseId + "_" + retProxy.result.info.name)); if (!proxyPath.Exists) { proxyPath.Create(); } //Realiza a leitura dos arquivos originais Byte[] multProxy = File.ReadAllBytes(Path.Combine(Request.PhysicalApplicationPath, "_data\\multproxy.zip")); Byte[] proxy = File.ReadAllBytes(Path.Combine(Request.PhysicalApplicationPath, "_data\\proxy.zip")); //Descompacta os zips em uma estrutura temporária ZIPUtil.DecompressData(multProxy, tempPath); ZIPUtil.DecompressData(proxy, proxyPath); //Cria o arquivo de configuração do proxy String config = ""; config += "server=" + Request.Url.Host + (Request.Url.Port != 80 && Request.Url.Port != 443 ? ":" + Request.Url.Port : "") + Environment.NewLine; config += "usehttps=" + (Tools.Tool.IsUsingHTTPS() ? "1" : "0") + Environment.NewLine; config += "hostname=" + retProxy.result.info.name + Environment.NewLine; //Resgata os dados de certificado using (ProxyConfig cfg = new ProxyConfig()) { cfg.GetDBConfig(IAMDatabase.GetWebConnection(), enterpriseId, retProxy.result.info.name); config += "c1=" + cfg.server_cert + Environment.NewLine; config += "c2=" + cfg.client_cert + Environment.NewLine; } File.WriteAllText(Path.Combine(proxyPath.FullName, "proxy.conf"), config, Encoding.UTF8); //Cria o arquivo zip com os dados e retorna Byte[] bRet = ZIPUtil.Compress(tempPath); Response.Clear(); Response.ContentType = "application/zip"; Response.AddHeader("Content-Disposition", "attachment; filename=IAMProxy.zip"); Response.AddHeader("Content-Length", bRet.Length.ToString()); Response.Status = "200 OK"; Response.StatusCode = 200; Response.OutputStream.Write(bRet, 0, bRet.Length); Response.OutputStream.Flush(); } catch (Exception ex) { Response.Status = "500 Internal Error"; Response.StatusCode = 500; } finally { try { if (tempPath != null) { tempPath.Delete(true); } } catch { } } contentRet = null; } break; } } catch (Exception ex) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("api_error"), 3000, true); } if (contentRet != null) { if (!String.IsNullOrWhiteSpace((String)Request["cid"])) { contentRet.callId = (String)Request["cid"]; } Retorno.Controls.Add(new LiteralControl(contentRet.ToJSON())); } }
protected void Page_Load(object sender, EventArgs e) { WebJsonResponse ret = null; try { Int64 enterpriseID = ((EnterpriseData)Page.Session["enterprise_data"]).Id; Int64 entityId = 0; String err = ""; String password = Tools.Tool.TrataInjection(Request["password"]); String password2 = Request["password2"]; if ((password == null) || (password == "")) { ret = new WebJsonResponse("", MessageResource.GetMessage("type_password"), 3000, true); } else if ((password2 == null) || (password2 == "")) { ret = new WebJsonResponse("", MessageResource.GetMessage("type_password_confirm"), 3000, true); } else if (password != password2) { ret = new WebJsonResponse("", MessageResource.GetMessage("password_not_equal"), 3000, true); } else { Int64 enterpriseId = 0; if ((Page.Session["enterprise_data"]) != null && (Page.Session["enterprise_data"] is EnterpriseData) && (((EnterpriseData)Page.Session["enterprise_data"]).Id != null)) { enterpriseId = ((EnterpriseData)Page.Session["enterprise_data"]).Id; } String code = ""; if (Session["entityId"] != null) { entityId = (Int64)Session["entityId"]; } if (Session["userCode"] != null) { code = Session["userCode"].ToString(); } if ((entityId > 0) && (code != "")) { using (IAMDatabase db = new IAMDatabase(IAMDatabase.GetWebConnectionString())) { UserPasswordStrength usrCheck = new UserPasswordStrength(db.Connection, entityId); UserPasswordStrengthResult check = usrCheck.CheckPassword(password); if (check.HasError) { if (check.NameError) { ret = new WebJsonResponse("", MessageResource.GetMessage("password_name_part"), 3000, true); } else { String txt = "* " + MessageResource.GetMessage("number_char") + ": " + (!check.LengthError ? MessageResource.GetMessage("ok") : MessageResource.GetMessage("fail")) + "<br />"; txt += "* " + MessageResource.GetMessage("uppercase") + ": " + (!check.UpperCaseError ? MessageResource.GetMessage("ok") : MessageResource.GetMessage("fail")) + "<br />"; txt += "* " + MessageResource.GetMessage("lowercase") + ": " + (!check.LowerCaseError ? MessageResource.GetMessage("ok") : MessageResource.GetMessage("fail")) + "<br />"; txt += "* " + MessageResource.GetMessage("numbers") + ": " + (!check.DigitError ? MessageResource.GetMessage("ok") : MessageResource.GetMessage("fail")) + "<br />"; txt += "* " + MessageResource.GetMessage("symbols") + ": " + (!check.SymbolError ? MessageResource.GetMessage("ok") : MessageResource.GetMessage("fail")); ret = new WebJsonResponse("", MessageResource.GetMessage("password_complexity") + ": <br />" + txt, 5000, true); } } else { DataTable c = db.Select("select * from entity where deleted = 0 and id = " + entityId + " and recovery_code = '" + code + "'"); if ((c != null) && (c.Rows.Count > 0)) { using (EnterpriseKeyConfig sk = new EnterpriseKeyConfig(db.Connection, enterpriseId)) using (CryptApi cApi = new CryptApi(sk.ServerCert, Encoding.UTF8.GetBytes(password))) db.ExecuteNonQuery("update entity set password = '******', recovery_code = null, last_login = getdate(), change_password = getdate(), must_change_password = 0 where id = " + entityId, CommandType.Text, null); db.AddUserLog(LogKey.User_PasswordChanged, null, "AutoService", UserLogLevel.Info, 0, enterpriseId, 0, 0, 0, entityId, 0, "Password changed through recovery code", "{ \"ipaddr\":\"" + Tools.Tool.GetIPAddress() + "\"} "); //Cria o pacote com os dados atualizados deste usuário //Este processo vija agiliar a aplicação das informações pelos plugins db.ExecuteNonQuery("insert into deploy_now (entity_id) values(" + entityId + ")", CommandType.Text, null); String html = ""; html += "<div class=\"login_form\">"; html += "<ul>"; html += " <li class=\"title\">"; html += " <strong>" + MessageResource.GetMessage("password_changed_sucessfully") + "</strong>"; html += " </li>"; html += " <li>"; html += " <p style=\"width:100%;padding:0 0 5px 0;color:#000;\">" + MessageResource.GetMessage("password_changed_text") + "</p>"; html += " </li>"; html += " <li>"; html += " <span class=\"forgot\"> <a href=\"/\">" + MessageResource.GetMessage("return_default") + "</a></span>"; html += " </li>"; html += "</ul> "; html += "</div>"; ret = new WebJsonResponse("#recover_container", html); } else { ret = new WebJsonResponse("", MessageResource.GetMessage("invalid_code"), 3000, true); } } } } else { ret = new WebJsonResponse("", MessageResource.GetMessage("invalid_session"), 3000, true); } } } catch (Exception ex) { Tools.Tool.notifyException(ex); throw ex; } if (ret != null) { ReturnHolder.Controls.Add(new LiteralControl(ret.ToJSON())); } }
protected void Page_Load(object sender, EventArgs e) { if (Request.HttpMethod != "POST") { return; } String area = ""; if (!String.IsNullOrWhiteSpace((String)RouteData.Values["area"])) { area = (String)RouteData.Values["area"]; } Int64 enterpriseId = 0; if ((Session["enterprise_data"]) != null && (Session["enterprise_data"] is EnterpriseData)) { enterpriseId = ((EnterpriseData)Session["enterprise_data"]).Id; } Boolean newItem = false; if ((RouteData.Values["new"] != null) && (RouteData.Values["new"] == "1")) { newItem = true; } String ApplicationVirtualPath = Session["ApplicationVirtualPath"].ToString(); LMenu menu1 = new LMenu("Dashboard", ApplicationVirtualPath + "admin/"); LMenu menu2 = new LMenu("Recursos", ApplicationVirtualPath + "admin/resource/" + (Request.Form["hashtag"] != null ? "#" + Request.Form["hashtag"].ToString() : "")); LMenu menu3 = new LMenu("Recursos", ApplicationVirtualPath + "admin/resource/" + (Request.Form["hashtag"] != null ? "#" + Request.Form["hashtag"].ToString() : "")); WebJsonResponse contentRet = null; String html = ""; String eHtml = ""; String js = null; String errorTemplate = "<span class=\"empty-results\">{0}</span>"; //Verifica se está sendo selecionada uma role Int64 resourceId = 0; try { resourceId = Int64.Parse((String)RouteData.Values["id"]); if (resourceId < 0) { resourceId = 0; } } catch { } String error = ""; ResourceGetResult retResource = null; String filter = ""; HashData hashData = new HashData(this); if (!String.IsNullOrWhiteSpace((String)RouteData.Values["filter"])) { filter = (String)RouteData.Values["filter"]; } if ((resourceId > 0) && (area.ToLower() != "search")) { try { var tmpReq = new { jsonrpc = "1.0", method = "resource.get", parameters = new { resourceid = resourceId }, id = 1 }; String rData = SafeTrend.Json.JSON.Serialize2(tmpReq); String jData = ""; using (IAMDatabase database = new IAMDatabase(IAMDatabase.GetWebConnectionString())) jData = WebPageAPI.ExecuteLocal(database, this, rData); if (String.IsNullOrWhiteSpace(jData)) { throw new Exception(""); } retResource = JSON.Deserialize <ResourceGetResult>(jData); if (retResource == null) { error = MessageResource.GetMessage("resource_not_found"); //ret = new WebJsonResponse("", MessageResource.GetMessage("user_not_found"), 3000, true); } else if (retResource.error != null) { error = retResource.error.data; retResource = null; } else if (retResource.result == null || retResource.result.info == null) { error = MessageResource.GetMessage("resource_not_found"); retResource = null; } else { menu3.Name = retResource.result.info.name; } } catch (Exception ex) { error = MessageResource.GetMessage("api_error"); Tools.Tool.notifyException(ex, this); retResource = null; //ret = new WebJsonResponse("", MessageResource.GetMessage("api_error"), 3000, true); } } switch (area) { case "": case "search": case "content": if (newItem) { try { var tmpReq = new { jsonrpc = "1.0", method = "context.list", parameters = new { }, id = 1 }; error = ""; String rData = SafeTrend.Json.JSON.Serialize2(tmpReq); String jData = ""; using (IAMDatabase database = new IAMDatabase(IAMDatabase.GetWebConnectionString())) jData = WebPageAPI.ExecuteLocal(database, this, rData); if (String.IsNullOrWhiteSpace(jData)) { throw new Exception(""); } ContextListResult contextList = JSON.Deserialize <ContextListResult>(jData); if (contextList == null) { error = MessageResource.GetMessage("context_not_found"); //ret = new WebJsonResponse("", MessageResource.GetMessage("user_not_found"), 3000, true); } else if (contextList.error != null) { error = contextList.error.data; } else if (contextList.result == null) { error = MessageResource.GetMessage("context_not_found"); } else { var tmpReq2 = new { jsonrpc = "1.0", method = "proxy.list", parameters = new { }, id = 1 }; error = ""; rData = SafeTrend.Json.JSON.Serialize2(tmpReq2); jData = ""; using (IAMDatabase database = new IAMDatabase(IAMDatabase.GetWebConnectionString())) jData = WebPageAPI.ExecuteLocal(database, this, rData); if (String.IsNullOrWhiteSpace(jData)) { throw new Exception(""); } ProxyListResult proxyList = JSON.Deserialize <ProxyListResult>(jData); if (proxyList == null) { error = MessageResource.GetMessage("proxy_not_found"); //ret = new WebJsonResponse("", MessageResource.GetMessage("user_not_found"), 3000, true); } else if (proxyList.error != null) { error = proxyList.error.data; } else if (proxyList.result == null) { error = MessageResource.GetMessage("proxy_not_found"); } else { html = "<h3>Adição de recurso</h3>"; html += "<form id=\"form_add_resource\" method=\"post\" action=\"" + ApplicationVirtualPath + "admin/resource/action/add_resource/\"><div class=\"no-tabs pb10\">"; html += "<div class=\"form-group\"><label>Nome</label><input id=\"resource_name\" name=\"resource_name\" placeholder=\"Digite o nome do recurso\" type=\"text\"\"></div>"; html += "<div class=\"form-group\"><label>Contexto</label><select id=\"resource_context\" name=\"resource_context\" ><option value=\"\"></option>"; foreach (ContextData c in contextList.result) { html += "<option value=\"" + c.context_id + "\" " + (hashData.GetValue("context") == c.context_id.ToString() ? "selected" : "") + ">" + c.name + "</option>"; } html += "</select></div>"; html += "<div class=\"form-group\"><label>Proxy</label><select id=\"resource_proxy\" name=\"resource_proxy\" ><option value=\"\"></option>"; foreach (ProxyData p in proxyList.result) { html += "<option value=\"" + p.proxy_id + "\" " + (hashData.GetValue("proxy") == p.proxy_id.ToString() ? "selected" : "") + ">" + p.name + "</option>"; } html += "</select></div>"; html += "<div class=\"clear-block\"></div></div>"; html += "<button type=\"submit\" id=\"user-profile-password-save\" class=\"button secondary floatleft\">Adicionar</button> <a href=\"" + ApplicationVirtualPath + "admin/resource/" + (Request.Form["hashtag"] != null ? "#" + Request.Form["hashtag"].ToString() : "") + "\" class=\"button link floatleft\">Cancelar</a></form>"; contentRet = new WebJsonResponse("#content-wrapper", (eHtml != "" ? eHtml : html)); } } } catch (Exception ex) { error = MessageResource.GetMessage("api_error"); } if (error != "") { contentRet = new WebJsonResponse("#content-wrapper", String.Format(errorTemplate, error)); } } else { if (retResource == null) { Int32 page = 1; Int32 pageSize = 20; Boolean hasNext = true; Int32.TryParse(Request.Form["page"], out page); if (page < 1) { page = 1; } String roleTemplate = "<div id=\"role-list-{0}\" data-id=\"{0}\" data-name=\"{1}\" data-total=\"{2}\" class=\"app-list-item\">"; roleTemplate += "<table>"; roleTemplate += " <tbody>"; roleTemplate += " <tr>"; roleTemplate += " <td class=\"col1\">"; roleTemplate += " <span id=\"total_{0}\" class=\"total \">{2}</span>"; roleTemplate += " <a href=\"" + ApplicationVirtualPath + "admin/resource_plugin/#resource/{0}\">"; roleTemplate += " <div class=\"app-btn a-btn\"><span class=\"a-btn-inner\">Ver vínculos</span></div>"; roleTemplate += " </a>"; roleTemplate += " </td>"; roleTemplate += " <td class=\"col2\">"; roleTemplate += " <div class=\"title\"><span class=\"name field-editor\" id=\"resource_name_{0}\" data-id=\"{0}\" data-function=\"iamadmin.editTextField('#resource_name_{0}',null,resourceNameEdit);\">{1}</span><span class=\"date\">{3}</span><div class=\"clear-block\"></div></div>"; roleTemplate += " <div class=\"description\">"; roleTemplate += " <div class=\"first\">{4}</div>"; roleTemplate += " </div>"; roleTemplate += " <div class=\"links\">"; roleTemplate += " <div class=\"\"><a href=\"" + ApplicationVirtualPath + "admin/resource/{0}/" + (Request.Form["hashtag"] != null ? "#" + Request.Form["hashtag"].ToString() : "") + "\"><div class=\"ico icon-change\">Editar</div></a><a href=\"" + ApplicationVirtualPath + "admin/roles/{0}/action/delete_all_users/" + (Request.Form["hashtag"] != null ? "#" + Request.Form["hashtag"].ToString() : "") + "\" class=\"confirm-action\" confirm-title=\"Exclusão\" confirm-text=\"Deseja excluir definitivamente todos os usuários do perfil '{1}'?\" ok=\"Excluir\" cancel=\"Cancelar\"><div class=\"ico icon-close\">Excluir usuários</div></a></div>"; roleTemplate += " <div class=\"last\">{5}</div>"; roleTemplate += " </div>"; roleTemplate += " </td>"; roleTemplate += " </tr>"; roleTemplate += " </tbody>"; roleTemplate += "</table></div>"; js += "resourceNameEdit = function(thisId, changedText) { iamadmin.changeName(thisId,changedText); };"; html += "<div id=\"box-container\" class=\"box-container\">"; String query = ""; try { String rData = ""; if (!String.IsNullOrWhiteSpace((String)RouteData.Values["query"])) { query = (String)RouteData.Values["query"]; } if (String.IsNullOrWhiteSpace(query) && !String.IsNullOrWhiteSpace(hashData.GetValue("query"))) { query = hashData.GetValue("query"); } if (String.IsNullOrWhiteSpace(query)) { var tmpReq = new { jsonrpc = "1.0", method = "resource.list", parameters = new { page_size = pageSize, page = page, filter = new { contextid = hashData.GetValue("context"), proxyid = hashData.GetValue("proxy") } }, id = 1 }; rData = SafeTrend.Json.JSON.Serialize2(tmpReq); } else { var tmpReq = new { jsonrpc = "1.0", method = "resource.search", parameters = new { text = query, page_size = pageSize, page = page, filter = new { contextid = hashData.GetValue("context"), proxyid = hashData.GetValue("proxy") } }, id = 1 }; rData = SafeTrend.Json.JSON.Serialize2(tmpReq); } String jData = ""; using (IAMDatabase database = new IAMDatabase(IAMDatabase.GetWebConnectionString())) jData = WebPageAPI.ExecuteLocal(database, this, rData); if (String.IsNullOrWhiteSpace(jData)) { throw new Exception(""); } ResourceListResult ret2 = JSON.Deserialize <ResourceListResult>(jData); if (ret2 == null) { eHtml += String.Format(errorTemplate, MessageResource.GetMessage("resource_not_found")); hasNext = false; } else if (ret2.error != null) { #if DEBUG eHtml += String.Format(errorTemplate, ret2.error.data + ret2.error.debug); #else eHtml += String.Format(errorTemplate, ret2.error.data); #endif hasNext = false; } else if (ret2.result == null || (ret2.result.Count == 0 && page == 1)) { eHtml += String.Format(errorTemplate, MessageResource.GetMessage("resource_not_found")); hasNext = false; } else { foreach (ResourceData resource in ret2.result) { String text = "Contexto: " + resource.context_name + ", Proxy: " + resource.proxy_name; html += String.Format(roleTemplate, resource.resource_id, resource.name, resource.resource_plugin_qty, (resource.create_date > 0 ? "Criado em " + MessageResource.FormatDate(new DateTime(1970, 1, 1).AddSeconds(resource.create_date), true) : ""), text, (resource.resource_plugin_qty > 0 ? "" : "<a class=\"confirm-action\" href=\"" + ApplicationVirtualPath + "admin/resource/" + resource.resource_id + "/action/delete/" + (Request.Form["hashtag"] != null ? "#" + Request.Form["hashtag"].ToString() : "") + "\" confirm-title=\"Exclusão\" confirm-text=\"Deseja excluir definitivamente o recurso '" + resource.name + "'?\" ok=\"Excluir\" cancel=\"Cancelar\"><div class=\"ico icon-close\">Apagar</div></a>")); } if (ret2.result.Count < pageSize) { hasNext = false; } } } catch (Exception ex) { eHtml += String.Format(errorTemplate, MessageResource.GetMessage("api_error")); } if (page == 1) { html += "</div>"; html += "<span class=\"empty-results content-loading role-list-loader hide\"></span>"; contentRet = new WebJsonResponse("#content-wrapper", (eHtml != "" ? eHtml : html)); } else { contentRet = new WebJsonResponse("#content-wrapper #box-container", (eHtml != "" ? eHtml : html), true); } contentRet.js = js + "$( document ).unbind('end_of_scroll');"; if (hasNext) { contentRet.js += "$( document ).bind( 'end_of_scroll.loader_role', function() { $( document ).unbind('end_of_scroll.loader_role'); $('.role-list-loader').removeClass('hide'); iamadmin.getPageContent2( { page: " + ++page + ", search:'" + (!String.IsNullOrWhiteSpace(query) ? query : "") + "' }, function(){ $('.role-list-loader').addClass('hide'); } ); });"; } } else //Esta sendo selecionado a role { if (error != "") { contentRet = new WebJsonResponse("#content-wrapper", String.Format(errorTemplate, error)); } else { switch (filter) { case "": String infoTemplate = "<div class=\"form-group\">"; infoTemplate += "<label>{0}</label>"; infoTemplate += "<span class=\"no-edit\">{1}</span></div>"; String jsAdd = ""; if (hashData.GetValue("edit") == "1") { var tmpReq = new { jsonrpc = "1.0", method = "context.list", parameters = new { }, id = 1 }; error = ""; String rData = SafeTrend.Json.JSON.Serialize2(tmpReq); String jData = ""; using (IAMDatabase database = new IAMDatabase(IAMDatabase.GetWebConnectionString())) jData = WebPageAPI.ExecuteLocal(database, this, rData); if (String.IsNullOrWhiteSpace(jData)) { throw new Exception(""); } ContextListResult contextList = JSON.Deserialize <ContextListResult>(jData); if (contextList == null) { error = MessageResource.GetMessage("context_not_found"); //ret = new WebJsonResponse("", MessageResource.GetMessage("user_not_found"), 3000, true); } else if (contextList.error != null) { error = contextList.error.data; } else if (contextList.result == null) { error = MessageResource.GetMessage("context_not_found"); } else { var tmpReq2 = new { jsonrpc = "1.0", method = "proxy.list", parameters = new { }, id = 1 }; error = ""; rData = SafeTrend.Json.JSON.Serialize2(tmpReq2); jData = ""; using (IAMDatabase database = new IAMDatabase(IAMDatabase.GetWebConnectionString())) jData = WebPageAPI.ExecuteLocal(database, this, rData); if (String.IsNullOrWhiteSpace(jData)) { throw new Exception(""); } ProxyListResult proxyList = JSON.Deserialize <ProxyListResult>(jData); if (contextList == null) { error = MessageResource.GetMessage("proxy_not_found"); //ret = new WebJsonResponse("", MessageResource.GetMessage("user_not_found"), 3000, true); } else if (contextList.error != null) { error = contextList.error.data; } else if (contextList.result == null) { error = MessageResource.GetMessage("proxy_not_found"); } else { html += "<form id=\"form_resource_change\" method=\"POST\" action=\"" + ApplicationVirtualPath + "admin/resource/" + retResource.result.info.resource_id + "/action/change/\">"; html += "<h3>Edição de recurso</h3>"; html += "<div class=\"no-tabs pb10\">"; String contexto = ""; contexto += "<select id=\"resource_context\" name=\"resource_context\" ><option value=\"\"></option>"; foreach (ContextData c in contextList.result) { contexto += "<option value=\"" + c.context_id + "\" " + (retResource.result.info.context_id == c.context_id ? "selected" : "") + ">" + c.name + "</option>"; } contexto += "</select>"; String proxy = ""; proxy += "<select id=\"resource_proxy\" name=\"resource_proxy\" ><option value=\"\"></option>"; foreach (ProxyData c in proxyList.result) { proxy += "<option value=\"" + c.proxy_id + "\" " + (retResource.result.info.proxy_id == c.proxy_id ? "selected" : "") + ">" + c.name + "</option>"; } proxy += "</select>"; html += String.Format(infoTemplate, "Nome", "<input id=\"name\" name=\"name\" placeholder=\"Digite o nome do recurso\" type=\"text\"\" value=\"" + retResource.result.info.name + "\">"); html += String.Format(infoTemplate, "Contexto", contexto); html += String.Format(infoTemplate, "Proxy", proxy); html += String.Format(infoTemplate, "Desabilitado", "<input id=\"disabled\" name=\"disabled\" type=\"checkbox\" " + (!retResource.result.info.enabled ? "checked" : "") + ">"); html += String.Format(infoTemplate, "Criado em", MessageResource.FormatDate(((DateTime) new DateTime(1970, 1, 1)).AddSeconds(retResource.result.info.create_date), false)); html += "<div class=\"clear-block\"></div></div>"; } } } else { html += "<h3>Informações gerais<div class=\"btn-box\"><div class=\"a-btn ico icon-change\" onclick=\"iamadmin.changeHash( 'edit/1' );\">Editar</div></div></h3>"; html += "<div class=\"no-tabs pb10\">"; html += String.Format(infoTemplate, "Nome", retResource.result.info.name); html += String.Format(infoTemplate, "Contexto", retResource.result.info.context_name); html += String.Format(infoTemplate, "Proxy", retResource.result.info.proxy_name); html += String.Format(infoTemplate, "Desabilitado", (!retResource.result.info.enabled ? MessageResource.GetMessage("yes") : MessageResource.GetMessage("no"))); html += String.Format(infoTemplate, "Criado em", MessageResource.FormatDate(((DateTime) new DateTime(1970, 1, 1)).AddSeconds(retResource.result.info.create_date), false)); html += "<div class=\"clear-block\"></div></div>"; } if (hashData.GetValue("edit") == "1") { html += "<button type=\"submit\" id=\"resource-save\" class=\"button secondary floatleft\">Salvar</button> <a class=\"button link floatleft\" onclick=\"iamadmin.changeHash( 'edit/0' );\">Cancelar</a></form>"; } contentRet = new WebJsonResponse("#content-wrapper", html); contentRet.js = jsAdd; break; case "identity": break; } } } } break; case "sidebar": if (menu1 != null) { html += "<div class=\"sep\"><div class=\"section-nav-header\">"; html += " <div class=\"crumbs\">"; html += " <div class=\"subject subject-color\">"; html += " <a href=\"" + menu1.HRef + "\">" + menu1.Name + "</a>"; html += " </div>"; if (menu2 != null) { html += " <div class=\"topic topic-color\">"; html += " <a href=\"" + menu2.HRef + "\">" + menu2.Name + "</a>"; html += " </div>"; } html += " </div>"; if (menu3 != null) { html += " <div class=\"crumbs tutorial-title\">"; html += " <h2 class=\"title tutorial-color\">" + menu3.Name + "</h2>"; html += " </div>"; } html += "</div></div>"; } if (!newItem) { html += "<div class=\"sep\"><button class=\"a-btn-big a-btn\" type=\"button\" onclick=\"window.location='" + ApplicationVirtualPath + "admin/resource/new/" + (Request.Form["hashtag"] != null ? "#" + Request.Form["hashtag"].ToString() : "") + "'\">Novo recurso</button></div>"; switch (filter) { case "add_user": break; default: /*if (retRole != null) * html += "<div class=\"sep\"><button class=\"a-btn-big a-btn\" type=\"button\" onclick=\"window.location='" + ApplicationVirtualPath + "admin/roles/" + retRole.result.info.role_id + "/add_user/" + (Request.Form["hashtag"] != null ? "#" + Request.Form["hashtag"].ToString() : "") + "'\">Adicionar usuários</button></div>";*/ break; } } contentRet = new WebJsonResponse("#main aside", html); break; case "mobilebar": break; case "buttonbox": switch (filter) { case "": if (retResource == null) { js = ""; try { String rData = SafeTrend.Json.JSON.Serialize2(new { jsonrpc = "1.0", method = "context.list", parameters = new { page_size = Int32.MaxValue }, id = 1 }); String jData = ""; using (IAMDatabase database = new IAMDatabase(IAMDatabase.GetWebConnectionString())) jData = WebPageAPI.ExecuteLocal(database, this, rData); ContextListResult contextList = JSON.Deserialize <ContextListResult>(jData); if ((contextList != null) && (contextList.error == null) && (contextList.result != null)) { html += "<select id=\"filter_context\" name=\"filter_context\" ><option value=\"\">Todos os contextos</option>"; foreach (ContextData c in contextList.result) { html += "<option value=\"context/" + c.context_id + "\" " + (hashData.GetValue("context") == c.context_id.ToString() ? "selected" : "") + ">" + c.name + "</option>"; } html += "</select>"; js += "$('#filter_context').change(function() { iamadmin.changeHash( $( this ).val() ); });"; } } catch (Exception ex) { } try { String rData = SafeTrend.Json.JSON.Serialize2(new { jsonrpc = "1.0", method = "proxy.list", parameters = new { page_size = Int32.MaxValue }, id = 1 }); String jData = ""; using (IAMDatabase database = new IAMDatabase(IAMDatabase.GetWebConnectionString())) jData = WebPageAPI.ExecuteLocal(database, this, rData); ProxyListResult proxyList = JSON.Deserialize <ProxyListResult>(jData); if ((proxyList != null) && (proxyList.error == null) && (proxyList.result != null)) { html += "<select id=\"filter_proxy\" name=\"filter_proxy\" ><option value=\"\">Todos os proxies</option>"; foreach (ProxyData p in proxyList.result) { html += "<option value=\"proxy/" + p.proxy_id + "\" " + (hashData.GetValue("proxy") == p.proxy_id.ToString() ? "selected" : "") + ">" + p.name + "</option>"; } html += "</select>"; js += "$('#filter_proxy').change(function() { iamadmin.changeHash( $( this ).val() ); });"; } } catch (Exception ex) { } contentRet = new WebJsonResponse("#btnbox", html); contentRet.js = js; } break; } break; } if (contentRet != null) { if (!String.IsNullOrWhiteSpace((String)Request["cid"])) { contentRet.callId = (String)Request["cid"]; } Retorno.Controls.Add(new LiteralControl(contentRet.ToJSON())); } }
protected void Page_Load(object sender, EventArgs e) { if (Request.HttpMethod != "POST") { return; } String area = ""; if (!String.IsNullOrWhiteSpace((String)RouteData.Values["area"])) { area = (String)RouteData.Values["area"]; } Int64 enterpriseId = 0; if ((Session["enterprise_data"]) != null && (Session["enterprise_data"] is EnterpriseData)) { enterpriseId = ((EnterpriseData)Session["enterprise_data"]).Id; } Boolean newItem = false; if ((RouteData.Values["new"] != null) && (RouteData.Values["new"] == "1")) { newItem = true; } String ApplicationVirtualPath = Session["ApplicationVirtualPath"].ToString(); LMenu menu1 = new LMenu("Dashboard", ApplicationVirtualPath + "admin/"); LMenu menu2 = new LMenu("Proxy", ApplicationVirtualPath + "admin/proxy/" + (Request.Form["hashtag"] != null ? "#" + Request.Form["hashtag"].ToString() : "")); LMenu menu3 = new LMenu("Proxy", ApplicationVirtualPath + "admin/proxy/" + (Request.Form["hashtag"] != null ? "#" + Request.Form["hashtag"].ToString() : "")); WebJsonResponse contentRet = null; String html = ""; String eHtml = ""; String js = null; String errorTemplate = "<span class=\"empty-results\">{0}</span>"; //Verifica se está sendo selecionada uma role Int64 proxyId = 0; try { proxyId = Int64.Parse((String)RouteData.Values["id"]); if (proxyId < 0) { proxyId = 0; } } catch { } String error = ""; ProxyGetResult retProxy = null; String filter = ""; HashData hashData = new HashData(this); if (!String.IsNullOrWhiteSpace((String)RouteData.Values["filter"])) { filter = (String)RouteData.Values["filter"]; } if ((proxyId > 0) && (area.ToLower() != "search")) { try { String rData = SafeTrend.Json.JSON.Serialize2(new { jsonrpc = "1.0", method = "proxy.get", parameters = new { proxyid = proxyId }, id = 1 }); String jData = ""; using (IAMDatabase database = new IAMDatabase(IAMDatabase.GetWebConnectionString())) jData = WebPageAPI.ExecuteLocal(database, this, rData); if (String.IsNullOrWhiteSpace(jData)) { throw new Exception(""); } retProxy = JSON.Deserialize <ProxyGetResult>(jData); if (retProxy == null) { error = MessageResource.GetMessage("proxy_not_found"); //ret = new WebJsonResponse("", MessageResource.GetMessage("user_not_found"), 3000, true); } else if (retProxy.error != null) { error = retProxy.error.data; retProxy = null; } else if (retProxy.result == null || retProxy.result.info == null) { error = MessageResource.GetMessage("proxy_not_found"); retProxy = null; } else { menu3.Name = retProxy.result.info.name; } } catch (Exception ex) { error = MessageResource.GetMessage("api_error"); Tools.Tool.notifyException(ex, this); retProxy = null; //ret = new WebJsonResponse("", MessageResource.GetMessage("api_error"), 3000, true); } } switch (area) { case "": case "search": case "content": if (newItem) { html = "<h3>Adição de proxy</h3>"; html += "<form id=\"form_add_proxy\" method=\"post\" action=\"" + ApplicationVirtualPath + "admin/proxy/action/add_proxy/\"><div class=\"no-tabs pb10\">"; html += "<div class=\"form-group\"><label>Nome</label><input id=\"proxy_name\" name=\"proxy_name\" placeholder=\"Digite o nome do proxy\" type=\"text\"\"></div>"; html += "<div class=\"clear-block\"></div></div>"; html += "<button type=\"submit\" id=\"user-profile-password-save\" class=\"button secondary floatleft\">Adicionar</button> <a href=\"" + ApplicationVirtualPath + "admin/proxy/" + (Request.Form["hashtag"] != null ? "#" + Request.Form["hashtag"].ToString() : "") + "\" class=\"button link floatleft\">Cancelar</a></form>"; contentRet = new WebJsonResponse("#content-wrapper", (eHtml != "" ? eHtml : html)); } else { if (retProxy == null) { Int32 page = 1; Int32 pageSize = 20; Boolean hasNext = true; Int32.TryParse(Request.Form["page"], out page); if (page < 1) { page = 1; } String proxyTemplate = "<div id=\"proxy-list-{0}\" data-id=\"{0}\" data-name=\"{1}\" data-total=\"{2}\" class=\"app-list-item\">"; proxyTemplate += "<table>"; proxyTemplate += " <tbody>"; proxyTemplate += " <tr>"; proxyTemplate += " <td class=\"col1\">"; proxyTemplate += " <span id=\"total_{0}\" class=\"total \">{2}</span>"; proxyTemplate += " <a href=\"" + ApplicationVirtualPath + "admin/resource/#proxy/{0}\">"; proxyTemplate += " <div class=\"app-btn a-btn\"><span class=\"a-btn-inner\">Ver recursos</span></div>"; proxyTemplate += " </a>"; proxyTemplate += " </td>"; proxyTemplate += " <td class=\"col2\">"; proxyTemplate += " <div class=\"title\"><span class=\"name field-editor\" id=\"proxy_name_{0}\" data-id=\"{0}\" data-function=\"iamadmin.editTextField('#proxy_name_{0}',null,proxyNameEdit);\">{1}</span><span class=\"date\">{3}</span><div class=\"clear-block\"></div></div>"; proxyTemplate += " <div class=\"description\">"; proxyTemplate += " <div class=\"first\">{4}</div>"; proxyTemplate += " </div>"; proxyTemplate += " <div class=\"links\">"; proxyTemplate += " <div class=\"last\">{5}</div>"; proxyTemplate += " </div>"; proxyTemplate += " </td>"; proxyTemplate += " </tr>"; proxyTemplate += " </tbody>"; proxyTemplate += "</table></div>"; js += "proxyNameEdit = function(thisId, changedText) { iamadmin.changeName(thisId,changedText); };"; html += "<div id=\"box-container\" class=\"box-container\">"; String query = ""; try { String rData = ""; if (!String.IsNullOrWhiteSpace((String)RouteData.Values["query"])) { query = (String)RouteData.Values["query"]; } if (String.IsNullOrWhiteSpace(query) && !String.IsNullOrWhiteSpace(hashData.GetValue("query"))) { query = hashData.GetValue("query"); } if (String.IsNullOrWhiteSpace(query)) { var tmpReq = new { jsonrpc = "1.0", method = "proxy.list", parameters = new { page_size = pageSize, page = page }, id = 1 }; rData = SafeTrend.Json.JSON.Serialize2(tmpReq); } else { var tmpReq = new { jsonrpc = "1.0", method = "proxy.search", parameters = new { text = query, page_size = pageSize, page = page }, id = 1 }; rData = SafeTrend.Json.JSON.Serialize2(tmpReq); } String jData = ""; using (IAMDatabase database = new IAMDatabase(IAMDatabase.GetWebConnectionString())) jData = WebPageAPI.ExecuteLocal(database, this, rData); if (String.IsNullOrWhiteSpace(jData)) { throw new Exception(""); } ProxyListResult ret2 = JSON.Deserialize <ProxyListResult>(jData); if (ret2 == null) { eHtml += String.Format(errorTemplate, MessageResource.GetMessage("proxy_not_found")); hasNext = false; } else if (ret2.error != null) { #if DEBUG eHtml += String.Format(errorTemplate, ret2.error.data + ret2.error.debug); #else eHtml += String.Format(errorTemplate, ret2.error.data); #endif hasNext = false; } else if (ret2.result == null || (ret2.result.Count == 0 && page == 1)) { eHtml += String.Format(errorTemplate, MessageResource.GetMessage("proxy_not_found")); hasNext = false; } else { foreach (ProxyData proxy in ret2.result) { String text = ""; if (proxy.last_sync > 0) { DateTime lastSync = new DateTime(1970, 1, 1).AddSeconds(proxy.last_sync); TimeSpan ts = DateTime.Now - lastSync; if (ts.TotalSeconds > 60) { text = "<span class=\"red-text\">Última conexão a " + MessageResource.FormatTs(ts) + " através do endereço " + proxy.last_sync_address + ". Versão: " + proxy.last_sync_version + "</span>"; } else { text = "On-line através do endereço " + proxy.last_sync_address + ". Versão: " + proxy.last_sync_version + ". Pid: " + proxy.last_sync_pid; } } else { text = "<span class=\"red-text\">Nunca se conectou no servidor</span>"; } String links = ""; links += (proxy.resource_qty > 0 ? "" : "<a class=\"confirm-action\" href=\"" + ApplicationVirtualPath + "admin/proxy/" + proxy.proxy_id + "/action/delete/" + (Request.Form["hashtag"] != null ? "#" + Request.Form["hashtag"].ToString() : "") + "\" confirm-title=\"Exclusão\" confirm-text=\"Deseja excluir definitivamente o proxy '" + proxy.name + "'?\" ok=\"Excluir\" cancel=\"Cancelar\"><div class=\"ico icon-close\">Apagar</div></a>"); links += "<a class=\"confirm-action\" href=\"" + ApplicationVirtualPath + "admin/proxy/" + proxy.proxy_id + "/action/restart/" + (Request.Form["hashtag"] != null ? "#" + Request.Form["hashtag"].ToString() : "") + "\" confirm-title=\"Reset\" confirm-text=\"Deseja reiniciar o proxy '" + proxy.name + "' no servidor remoto?\" ok=\"Reiniciar\" cancel=\"Cancelar\"><div class=\"ico icon-loop\">Reiniciar</div></a>"; links += "<a href=\"" + ApplicationVirtualPath + "admin/proxy/" + proxy.proxy_id + "/direct/download/" + (Request.Form["hashtag"] != null ? "#" + Request.Form["hashtag"].ToString() : "") + "\"><div class=\"ico icon-download-alt\">Download (instalador e configuração)</div></a>"; html += String.Format(proxyTemplate, proxy.proxy_id, proxy.name, proxy.resource_qty, (proxy.create_date > 0 ? "Criado em " + MessageResource.FormatDate(new DateTime(1970, 1, 1).AddSeconds(proxy.create_date), true) : ""), text, links); } if (ret2.result.Count < pageSize) { hasNext = false; } } } catch (Exception ex) { eHtml += String.Format(errorTemplate, MessageResource.GetMessage("api_error")); } if (page == 1) { html += "</div>"; html += "<span class=\"empty-results content-loading proxy-list-loader hide\"></span>"; contentRet = new WebJsonResponse("#content-wrapper", (eHtml != "" ? eHtml : html)); } else { contentRet = new WebJsonResponse("#content-wrapper #box-container", (eHtml != "" ? eHtml : html), true); } contentRet.js = js + "$( document ).unbind('end_of_scroll');"; if (hasNext) { contentRet.js += "$( document ).bind( 'end_of_scroll.loader_role', function() { $( document ).unbind('end_of_scroll.loader_role'); $('.proxy-list-loader').removeClass('hide'); iamadmin.getPageContent2( { page: " + ++page + ", search:'" + (!String.IsNullOrWhiteSpace(query) ? query : "") + "' }, function(){ $('.proxy-list-loader').addClass('hide'); } ); });"; } } else //Esta sendo selecionado o proxy { if (error != "") { contentRet = new WebJsonResponse("#content-wrapper", String.Format(errorTemplate, error)); } else { } } } break; case "sidebar": if (menu1 != null) { html += "<div class=\"sep\"><div class=\"section-nav-header\">"; html += " <div class=\"crumbs\">"; html += " <div class=\"subject subject-color\">"; html += " <a href=\"" + menu1.HRef + "\">" + menu1.Name + "</a>"; html += " </div>"; if (menu2 != null) { html += " <div class=\"topic topic-color\">"; html += " <a href=\"" + menu2.HRef + "\">" + menu2.Name + "</a>"; html += " </div>"; } html += " </div>"; if (menu3 != null) { html += " <div class=\"crumbs tutorial-title\">"; html += " <h2 class=\"title tutorial-color\">" + menu3.Name + "</h2>"; html += " </div>"; } html += "</div></div>"; } if (!newItem) { html += "<div class=\"sep\"><button class=\"a-btn-big a-btn\" type=\"button\" onclick=\"window.location='" + ApplicationVirtualPath + "admin/proxy/new/" + (Request.Form["hashtag"] != null ? "#" + Request.Form["hashtag"].ToString() : "") + "'\">Novo proxy</button></div>"; } contentRet = new WebJsonResponse("#main aside", html); break; case "mobilebar": break; case "buttonbox": break; } if (contentRet != null) { if (!String.IsNullOrWhiteSpace((String)Request["cid"])) { contentRet.callId = (String)Request["cid"]; } Retorno.Controls.Add(new LiteralControl(contentRet.ToJSON())); } }
protected void Page_Load(object sender, EventArgs e) { WebJsonResponse contentRet = null; String action = ""; if (!String.IsNullOrWhiteSpace((String)RouteData.Values["action"])) { action = (String)RouteData.Values["action"]; } Int64 pluginId = 0; if ((action != "add_license") && (action != "upload_item_template") && (action != "upload") && (action != "add_new")) { try { pluginId = Int64.Parse((String)RouteData.Values["id"]); if (pluginId < 0) { pluginId = 0; } } catch { } if (pluginId == 0) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("plugin_not_found"), 3000, true); action = ""; } } Int64 enterpriseId = 0; if ((Session["enterprise_data"]) != null && (Session["enterprise_data"] is EnterpriseData)) { enterpriseId = ((EnterpriseData)Session["enterprise_data"]).Id; } String rData = ""; //SqlConnection //conn = DB.GetConnection(); String jData = ""; try { switch (action) { case "upload_item_template": String id = Request.Form["id"]; String file = Request.Form["file"]; String tSize = Request.Form["size"]; if (String.IsNullOrEmpty(id)) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("role_not_found"), 3000, true); } else if (String.IsNullOrEmpty(file)) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("role_not_found"), 3000, true); } else if (String.IsNullOrEmpty(tSize)) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("role_not_found"), 3000, true); } else { String userHtmlTemplate = "<div id=\"file{0}\" data-id=\"{0}\" data-name=\"{1}\" class=\"app-list-item file-item\">"; userHtmlTemplate += "<div class=\"form-content\"><input type=\"hidden\" name=\"file_name_{0}\" value=\"{1}\">"; userHtmlTemplate += "<input type=\"hidden\" name=\"{1}\" value=\"{0}\"></div>"; userHtmlTemplate += "<table>"; userHtmlTemplate += " <tbody>"; userHtmlTemplate += " <tr>"; userHtmlTemplate += " <td class=\"colfull\">"; userHtmlTemplate += " <div class=\"title\"><span class=\"name\" id=\"file_name_{0}\" data-id=\"{0}\">{1}</span><div class=\"clear-block\"></div></div>"; userHtmlTemplate += " <div class=\"description\">{2}</div></div>"; userHtmlTemplate += " </td>"; userHtmlTemplate += " </tr>"; userHtmlTemplate += " </tbody>"; userHtmlTemplate += "</table></div>"; String infoTemplate = "<div class=\"line\">"; infoTemplate += "<label>{1}</label>"; infoTemplate += "<span class=\"no-edit {0}\">{2}</span></div>"; String desc = ""; desc += String.Format(infoTemplate, "status", "Status", "Enviando"); String tHtml = String.Format(userHtmlTemplate, id, file, desc); contentRet = new WebJsonResponse("#" + id, tHtml); } break; case "upload": MultipartFormDataParser mp = new MultipartFormDataParser(Request.InputStream); List <String> fls = new List <String>(); String infoTemplate2 = "<div class=\"line\">"; infoTemplate2 += "<label>{1}</label>"; infoTemplate2 += "<span class=\"no-edit {0}\">{2}</span></div>"; // Loop through all the files foreach (FilePart mpF in mp.Files) { try { String d = ""; try { Byte[] rawAssembly = new Byte[mpF.Data.Length]; mpF.Data.Read(rawAssembly, 0, rawAssembly.Length); IAMKeyData memKey = null; String fileData = Convert.ToBase64String(rawAssembly); try { memKey = IAMKey.ExtractFromCert(fileData); } catch { } if (memKey != null) { d += String.Format(infoTemplate2, "", "Nome", mpF.FileName); d += String.Format(infoTemplate2, "", "Tamanho", mpF.Data.Length + " bytes"); Boolean useLicense = false; if (memKey.IsServerKey) { d += String.Format(infoTemplate2, "", "Definitiva?", (memKey.IsTemp ? MessageResource.GetMessage("no") : MessageResource.GetMessage("yes"))); if (memKey.IsTemp) { d += String.Format(infoTemplate2, "", "Expiração", (memKey.TempDate.HasValue ? MessageResource.FormatDate(memKey.TempDate.Value, true) : "não definido")); } d += String.Format(infoTemplate2, "", "Entidades", (memKey.NumLic == 0 ? MessageResource.GetMessage("unlimited") : memKey.NumLic.ToString())); String installKey = ""; using (IAM.Config.ServerKey2 sk = new IAM.Config.ServerKey2(IAMDatabase.GetWebConnection())) installKey = sk.ServerInstallationKey.AbsoluteUri; d += String.Format(infoTemplate2, "", "Chave de instalação", (memKey.InstallKey == installKey ? "Válida" : "Inválida")); if (memKey.InstallKey == installKey) { if (!memKey.IsTemp) { useLicense = true; } else if ((memKey.IsTemp) && (memKey.TempDate.Value.CompareTo(DateTime.Now) > 0)) { useLicense = true; } } } else { d += String.Format(infoTemplate2, "", "Status", "Licença inválida"); } if (useLicense) { d += "<input type=\"hidden\" name=\"key_data\" value=\"" + fileData + "\">"; } /* * if (p2.Count > 0) * d += String.Format(infoTemplate2, "", "Plugins", String.Join(", ", p2)); * else * d += String.Format(infoTemplate2, "", "Plugins", "Nenhum plugin encontrado no arquivo enviado"); * * if (p2.Count > 0) * { * using (IAMDatabase database = new IAMDatabase(IAMDatabase.GetWebConnectionString())) * { * DataTable dt = database.Select("select * from plugin where enterprise_id in (0," + enterpriseId + ") and (assembly in ('" + String.Join("','", p2) + "') or uri in ('" + String.Join("','", p2Uri) + "'))"); * * if (dt.Rows.Count > 0) * throw new Exception("Plugin/uri ja cadastrado no sistema"); * } * * FileInfo newFile = new FileInfo(Path.Combine(pluginsDir.FullName, mpF.FileName)); * if (newFile.Exists) * newFile.Delete(); * File.WriteAllBytes(newFile.FullName, rawAssembly); * }*/ } else { d += String.Format(infoTemplate2, "", "Status", "Arquivo válido"); } } catch (Exception ex) { d = String.Format(infoTemplate2, "", "Status", "Erro ao realizar o upload"); d += String.Format(infoTemplate2, "", "Informação do erro", ex.Message); } fls.Add(JSON.Serialize2(new { name = mpF.FileName, html = d })); } catch { fls.Add(JSON.Serialize2(new { name = mpF.FileName, error = "Erro enviando o arquivo" })); } } Retorno.Controls.Add(new LiteralControl("{\"files\": [" + String.Join(",", fls) + "]}")); contentRet = null; break; case "add_new": String key_data = ""; key_data = Request.Form["key_data"]; if (!String.IsNullOrEmpty(key_data)) { IAMKeyData memKey = null; try { memKey = IAMKey.ExtractFromCert(key_data); } catch { } if (memKey != null) { Boolean useLicense = false; if (memKey.IsServerKey) { String installKey = ""; using (IAM.Config.ServerKey2 sk = new IAM.Config.ServerKey2(IAMDatabase.GetWebConnection())) installKey = sk.ServerInstallationKey.AbsoluteUri; if (memKey.InstallKey == installKey) { if (!memKey.IsTemp) { useLicense = true; } else if ((memKey.IsTemp) && (memKey.TempDate.Value.CompareTo(DateTime.Now) > 0)) { useLicense = true; } } if (useLicense) { using (IAMDatabase db = new IAMDatabase(IAMDatabase.GetWebConnectionString())) { db.openDB(); Object trans = db.BeginTransaction(); try { db.ExecuteNonQuery("delete from license where enterprise_id = " + enterpriseId, CommandType.Text, null, trans); using (DbParameterCollection par = new DbParameterCollection()) { par.Add("@enterprise_id", typeof(Int64)).Value = enterpriseId; par.Add("@license", typeof(String)).Value = key_data; db.ExecuteNonQuery("insert into license (enterprise_id,license_data) VALUES(@enterprise_id,@license)", CommandType.Text, par, trans); } db.Commit(); contentRet = new WebJsonResponse(Session["ApplicationVirtualPath"] + "admin/license/"); } catch (Exception ex) { db.Rollback(); contentRet = new WebJsonResponse("", "Falha ao aplicar a licença", 5000, true); } } } else { contentRet = new WebJsonResponse("", "Licença inválida", 5000, true); } } else { contentRet = new WebJsonResponse("", "Licença inválida", 5000, true); } } } else { contentRet = new WebJsonResponse("", "Nenhuma licença válida encontrada para aplicar", 5000, true); } break; } } catch (Exception ex) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("api_error"), 3000, true); } finally { } if (contentRet != null) { if (!String.IsNullOrWhiteSpace((String)Request["cid"])) { contentRet.callId = (String)Request["cid"]; } Retorno.Controls.Add(new LiteralControl(contentRet.ToJSON())); } }
protected void Page_Load(object sender, EventArgs e) { WebJsonResponse ret = null; LoginData login = LoginUser.LogedUser(this); String err = ""; if (!EnterpriseIdentify.Identify(this, false, out err)) //Se houver falha na identificação da empresa finaliza a resposta { ret = new WebJsonResponse("", err, 3000, true); } else if (login == null) { ret = new WebJsonResponse("", MessageResource.GetMessage("expired_session"), 3000, true, "/login/"); } else { try { Int64 enterpriseId = 0; if ((Page.Session["enterprise_data"]) != null && (Page.Session["enterprise_data"] is EnterpriseData) && (((EnterpriseData)Page.Session["enterprise_data"]).Id != null)) { enterpriseId = ((EnterpriseData)Page.Session["enterprise_data"]).Id; } String currentPassword = Tools.Tool.TrataInjection(Request["current_password"]); String password = Tools.Tool.TrataInjection(Request["password"]); String password2 = Request["password2"]; if ((currentPassword == null) || (currentPassword == "")) { ret = new WebJsonResponse("", MessageResource.GetMessage("type_password_current"), 3000, true); } else if ((password == null) || (password == "")) { ret = new WebJsonResponse("", MessageResource.GetMessage("type_password"), 3000, true); } else if ((password2 == null) || (password2 == "")) { ret = new WebJsonResponse("", MessageResource.GetMessage("type_password_confirm"), 3000, true); } else if (password != password2) { ret = new WebJsonResponse("", MessageResource.GetMessage("password_not_equal"), 3000, true); } else { using (IAMDatabase db = new IAMDatabase(IAMDatabase.GetWebConnectionString())) { try { UserPasswordStrength usrCheck = new UserPasswordStrength(db.Connection, login.Id); UserPasswordStrengthResult check = usrCheck.CheckPassword(password); if (check.HasError) { if (check.NameError) { ret = new WebJsonResponse("", MessageResource.GetMessage("password_name_part"), 3000, true); } else { String txt = "* " + MessageResource.GetMessage("number_char") + ": " + (!check.LengthError ? MessageResource.GetMessage("ok") : MessageResource.GetMessage("fail")) + "<br />"; txt += "* " + MessageResource.GetMessage("uppercase") + ": " + (!check.UpperCaseError ? MessageResource.GetMessage("ok") : MessageResource.GetMessage("fail")) + "<br />"; txt += "* " + MessageResource.GetMessage("lowercase") + ": " + (!check.LowerCaseError ? MessageResource.GetMessage("ok") : MessageResource.GetMessage("fail")) + "<br />"; txt += "* " + MessageResource.GetMessage("numbers") + ": " + (!check.DigitError ? MessageResource.GetMessage("ok") : MessageResource.GetMessage("fail")) + "<br />"; txt += "* " + MessageResource.GetMessage("symbols") + ": " + (!check.SymbolError ? MessageResource.GetMessage("ok") : MessageResource.GetMessage("fail")); ret = new WebJsonResponse("", MessageResource.GetMessage("password_complexity") + ": <br />" + txt, 5000, true); } } else { DataTable c = db.Select("select * from entity where deleted = 0 and id = " + login.Id); if ((c != null) && (c.Rows.Count > 0)) { //Verifica a senha atual using (EnterpriseKeyConfig sk = new EnterpriseKeyConfig(db.Connection, enterpriseId)) using (CryptApi cApi = CryptApi.ParsePackage(sk.ServerPKCS12Cert, Convert.FromBase64String(c.Rows[0]["password"].ToString()))) if (Encoding.UTF8.GetString(cApi.clearData) != currentPassword) { ret = new WebJsonResponse("", MessageResource.GetMessage("current_password_invalid"), 3000, true); } else { using (SqlConnection conn1 = IAMDatabase.GetWebConnection()) using (EnterpriseKeyConfig sk1 = new EnterpriseKeyConfig(conn1, enterpriseId)) using (CryptApi cApi1 = new CryptApi(sk.ServerCert, Encoding.UTF8.GetBytes(password))) { DbParameterCollection pPar = new DbParameterCollection();; String b64 = Convert.ToBase64String(cApi1.ToBytes()); pPar.Add("@password", typeof(String), b64.Length).Value = b64; db.ExecuteNonQuery("update entity set password = @password, change_password = getdate() , recovery_code = null, must_change_password = 0 where id = " + login.Id, CommandType.Text, pPar); } db.AddUserLog(LogKey.User_PasswordChanged, null, "AutoService", UserLogLevel.Info, 0, enterpriseId, 0, 0, 0, login.Id, 0, "Password changed through autoservice logged user", "{ \"ipaddr\":\"" + Tools.Tool.GetIPAddress() + "\"} "); //Cria o pacote com os dados atualizados deste usuário //Este processo visa agiliar a aplicação das informações pelos plugins db.ExecuteNonQuery("insert into deploy_now (entity_id) values(" + login.Id + ")", CommandType.Text, null); /* * IAMDeploy deploy = null; * * using (ServerDBConfig conf = new ServerDBConfig(IAMDatabase.GetWebConnection())) * deploy = new IAMDeploy("WebServer", DB.GetConnectionString(), conf.GetItem("outboundFiles")); * * if (deploy != null) * deploy.DeployOne(login.Id);*/ String html = ""; html += "<div class=\"no-tabs pb10\">"; html += " <div class=\"form-group\">"; html += " <h1>" + MessageResource.GetMessage("password_changed_sucessfully") + "</h1> "; html += " </div>"; html += " <div class=\"form-group\"><span class=\"text-message\">" + MessageResource.GetMessage("password_changed_text") + "</span></div>"; html += "</div>"; ret = new WebJsonResponse("#pwdForm", html); } } else { ret = new WebJsonResponse("", "Internal error", 3000, true); } } } finally { } } } } catch (Exception ex) { Tools.Tool.notifyException(ex); throw ex; } } if (ret != null) { ReturnHolder.Controls.Add(new LiteralControl(ret.ToJSON())); } }
protected void Page_Load(object sender, EventArgs e) { if (Request.HttpMethod != "POST") { return; } String area = ""; if (!String.IsNullOrWhiteSpace((String)RouteData.Values["area"])) { area = (String)RouteData.Values["area"]; } Int64 enterpriseId = 0; if ((Session["enterprise_data"]) != null && (Session["enterprise_data"] is EnterpriseData)) { enterpriseId = ((EnterpriseData)Session["enterprise_data"]).Id; } Boolean newItem = false; if ((RouteData.Values["new"] != null) && (RouteData.Values["new"] == "1")) { newItem = true; } String ApplicationVirtualPath = Session["ApplicationVirtualPath"].ToString(); LMenu menu1 = new LMenu("Dashboard", ApplicationVirtualPath + "admin/"); LMenu menu2 = new LMenu("Pastas", ApplicationVirtualPath + "admin/workflow/" + (Request.Form["hashtag"] != null ? "#" + Request.Form["hashtag"].ToString() : "")); LMenu menu3 = new LMenu("Pastas", ApplicationVirtualPath + "admin/workflow/" + (Request.Form["hashtag"] != null ? "#" + Request.Form["hashtag"].ToString() : "")); WebJsonResponse contentRet = null; String html = ""; String eHtml = ""; String js = null; String errorTemplate = "<span class=\"empty-results\">{0}</span>"; //Verifica se está sendo selecionada uma role Int64 workflowId = 0; try { workflowId = Int64.Parse((String)RouteData.Values["id"]); if (workflowId < 0) { workflowId = 0; } } catch { } String error = ""; WorkflowGetResult selectedWorkflow = null; String filter = ""; HashData hashData = new HashData(this); String rData = null; //SqlConnection conn = null; String jData = ""; Int32 page = 1; Int32 pageSize = 20; Boolean hasNext = true; if (!String.IsNullOrWhiteSpace((String)RouteData.Values["filter"])) { filter = (String)RouteData.Values["filter"]; } if ((workflowId > 0) && (area.ToLower() != "search")) { try { rData = SafeTrend.Json.JSON.Serialize2(new { jsonrpc = "1.0", method = "workflow.get", parameters = new { workflowid = workflowId }, id = 1 }); jData = ""; using (IAMDatabase database = new IAMDatabase(IAMDatabase.GetWebConnectionString())) jData = WebPageAPI.ExecuteLocal(database, this, rData); if (String.IsNullOrWhiteSpace(jData)) { throw new Exception(""); } selectedWorkflow = JSON.Deserialize <WorkflowGetResult>(jData); if (selectedWorkflow == null) { error = MessageResource.GetMessage("workflow_not_found"); //ret = new WebJsonResponse("", MessageResource.GetMessage("user_not_found"), 3000, true); } else if (selectedWorkflow.error != null) { error = selectedWorkflow.error.data; selectedWorkflow = null; } else if (selectedWorkflow.result == null || selectedWorkflow.result.info == null) { error = MessageResource.GetMessage("workflow_not_found"); selectedWorkflow = null; } else { menu3.Name = selectedWorkflow.result.info.name; } } catch (Exception ex) { error = MessageResource.GetMessage("api_error"); Tools.Tool.notifyException(ex, this); selectedWorkflow = null; //ret = new WebJsonResponse("", MessageResource.GetMessage("api_error"), 3000, true); } } String infoTemplate = "<tr {0}><td class=\"col1\">{1}</td><td class=\"col2\"><span class=\"no-edit\">{2}</span></td></tr>"; switch (area) { case "": case "search": case "content": if (newItem) { error = ""; rData = SafeTrend.Json.JSON.Serialize2(new { jsonrpc = "1.0", method = "context.list", parameters = new { }, id = 1 }); jData = ""; using (IAMDatabase database = new IAMDatabase(IAMDatabase.GetWebConnectionString())) jData = WebPageAPI.ExecuteLocal(database, this, rData); if (String.IsNullOrWhiteSpace(jData)) { throw new Exception(""); } ContextListResult contextList = JSON.Deserialize <ContextListResult>(jData); if (contextList == null) { error = MessageResource.GetMessage("context_not_found"); //ret = new WebJsonResponse("", MessageResource.GetMessage("user_not_found"), 3000, true); } else if (contextList.error != null) { error = contextList.error.data; } else if (contextList.result == null) { error = MessageResource.GetMessage("context_not_found"); } else { rData = SafeTrend.Json.JSON.Serialize2(new { jsonrpc = "1.0", method = "container.list", parameters = new { page_size = Int32.MaxValue, page = 1 }, id = 1 }); jData = ""; using (IAMDatabase database = new IAMDatabase(IAMDatabase.GetWebConnectionString())) jData = WebPageAPI.ExecuteLocal(database, this, rData); List <ContainerData> conteinerList = new List <ContainerData>(); ContainerListResult cl = JSON.Deserialize <ContainerListResult>(jData); if ((cl != null) && (cl.error == null) && (cl.result != null) && (cl.result.Count > 0)) { conteinerList.AddRange(cl.result); } html = "<h3>Adição de workflow</h3>"; html += "<form id=\"form_add_role\" method=\"post\" action=\"" + ApplicationVirtualPath + "admin/workflow/action/add_container/\">"; html += "<div class=\"no-tabs fields\"><table><tbody>"; html += String.Format(infoTemplate, "", "Nome", "<input id=\"workflow_name\" name=\"workflow_name\" placeholder=\"Digite o nome do workflow\" type=\"text\"\">"); String select = "<select id=\"workflow_context\" name=\"workflow_context\" ><option value=\"\"></option>"; foreach (ContextData c in contextList.result) { select += "<option value=\"" + c.context_id + "\" " + (hashData.GetValue("context") == c.context_id.ToString() ? "selected" : "") + ">" + c.name + "</option>"; } select += "</select>"; html += String.Format(infoTemplate, "", "Contexto", select); select = "<select id=\"workflow_type\" name=\"workflow_type\" ><option value=\"\"></option>"; foreach (IAM.Workflow.WorkflowAccessType type in (IAM.Workflow.WorkflowAccessType[])Enum.GetValues(typeof(IAM.Workflow.WorkflowAccessType))) { if (type != IAM.Workflow.WorkflowAccessType.None) { select += "<option value=\"" + (Int32)type + "\">" + MessageResource.GetMessage("wf_" + type.ToString().ToLower(), type.ToString()) + "</option>"; } } select += "</select>"; html += String.Format(infoTemplate, "", "Tipo", select); html += String.Format(infoTemplate, "id=\"" + (Int32)IAM.Workflow.WorkflowAccessType.RoleGrant + "\" class=\"workflow_type_hidden\" style=\"display:none;\"", "Perfis", "<input id=\"role\" name=\"role\" placeholder=\"Digite o nome do perfil desejado\" type=\"text\"\"><div id=\"selected_role\" class=\"item-box\"></div><span class=\"description red-text none-role\" style=\"opacity:1;\">Nenhum perfil selecionado</span>"); html += String.Format(infoTemplate, "", "Proprietário", "<input id=\"owner\" name=\"owner\" placeholder=\"Digite o nome do usuário\" type=\"text\"\"><div id=\"selected_user\" class=\"item-box\"></div><span class=\"description red-text none-user\" style=\"opacity:1;\">Nenhum usuário selecionado</span>"); html += String.Format(infoTemplate, "", "Descrição", "<textarea id=\"description\" name=\"description\" rows=\"5\" placeholder=\"Digite a descrição que será exibida ao usuário requisitante do acesso\"></textarea>"); html += "</tbody></table><div class=\"clear-block\"></div></div>"; html += "<h3>Passos de aprovação</h3>"; html += "<div class=\"no-tabs fields\"><table><tbody>"; String stepTemplate = "<div class=\"custom-item\" id=\"act_[id]\" onclick=\"iamadmin.buildWorkflowAct(this);\" data-uri=\"" + ApplicationVirtualPath + "admin/workflow/content/activity-build/\"><input type=\"hidden\" name=\"act\" value=\"[id]\" /><input type=\"hidden\" name=\"act_key_[id]\" class=\"key\" /><span></span><i class=\"icon-change\"></i></div><div class=\"ico icon-add act-add-subtract left\" onclick=\"iamfnc.addActivity(this);\"></div>"; html += String.Format(infoTemplate, "class=\"activity\"", "Passo de aprovação", stepTemplate.Replace("[id]", "1")); html += "</tbody></table><div class=\"clear-block\"></div></div>"; html += "<button type=\"submit\" id=\"user-profile-password-save\" class=\"button secondary floatleft\">Salvar</button> <a href=\"" + ApplicationVirtualPath + "admin/workflow/" + (Request.Form["hashtag"] != null ? "#" + Request.Form["hashtag"].ToString() : "") + "\" class=\"button link floatleft\">Cancelar</a></form>"; js = "iamadmin.autoCompleteText('#owner', '" + ApplicationVirtualPath + "admin/workflow/content/search_user/', { content_id: 'owner_id' } , function(thisId, selectedItem){ $(thisId).val(''); $('.none-user').remove(); $('#selected_user').html(selectedItem.html); } );"; js += "iamadmin.autoCompleteText('#role', '" + ApplicationVirtualPath + "admin/workflow/content/search_role/', { content_id: 'role_id' } , function(thisId, selectedItem){ $(thisId).val(''); $('.none-role').remove(); $('#selected_role').append(selectedItem.html); } );"; js += "$('#workflow_type').change(function() {"; js += " $('.workflow_type_hidden').css('display','none');"; js += " $('#' + $( this ).val()).css('display','table-row');"; js += "});"; js += "iamfnc.addActivity = function(objThis){ "; js += " var lc = $(objThis).closest('.activity');"; js += " var id = new Date().getTime(); console.log(lc);"; js += " $('" + String.Format(infoTemplate, "class=\"activity\"", "Passo de aprovação", stepTemplate + "<div class=\"ico icon-subtract act-add-subtract left\" onclick=\"iamadmin.removeLine(this);\"></div>") + "'.replace(/\\[id\\]/g,id)).insertAfter(lc);"; js += "};"; js += "iamadmin.removeLine = function(objThis){ "; js += " $(objThis).closest('.activity').remove();"; js += "};"; //js += "$('#filter_context').change(function() { iamadmin.changeHash( $( this ).val() ); });"; contentRet = new WebJsonResponse("#content-wrapper", (eHtml != "" ? eHtml : html)); contentRet.js = js; } } else { if (selectedWorkflow == null) { Int32.TryParse(Request.Form["page"], out page); if (page < 1) { page = 1; } String containerTemplate = "<div id=\"proxy-list-{0}\" data-id=\"{0}\" data-name=\"{1}\" data-total=\"{2}\" class=\"app-list-item\">"; containerTemplate += "<table>"; containerTemplate += " <tbody>"; containerTemplate += " <tr>"; containerTemplate += " <td class=\"col1\">"; containerTemplate += " <span id=\"total_{0}\" class=\"total \">{2}</span>"; containerTemplate += " <a href=\"" + ApplicationVirtualPath + "admin/users/\">"; containerTemplate += " <div class=\"app-btn a-btn\"><span class=\"a-btn-inner\">Requisições</span></div>"; containerTemplate += " </a>"; containerTemplate += " </td>"; containerTemplate += " <td class=\"col2\">"; containerTemplate += " <div class=\"title\"><span class=\"name field-editor\" id=\"workflow_name_{0}\" data-id=\"{0}\" data-function=\"iamadmin.editTextField('#workflow_name_{0}',null,workflowNameEdit);\">{1}</span><span class=\"date\">{3}</span><div class=\"clear-block\"></div></div>"; containerTemplate += " <div class=\"description\">"; containerTemplate += " <div class=\"first\">{4}</div>"; containerTemplate += " </div>"; containerTemplate += " <div class=\"links\">"; containerTemplate += " <div class=\"line\">{5}</div><div class=\"clear-block\"></div>"; containerTemplate += " </div>"; containerTemplate += " </td>"; containerTemplate += " </tr>"; containerTemplate += " </tbody>"; containerTemplate += "</table></div>"; js += "workflowNameEdit = function(thisId, changedText) { iamadmin.changeName(thisId,changedText); };"; html += "<div id=\"box-container\" class=\"box-container\">"; String query = ""; try { rData = ""; if (!String.IsNullOrWhiteSpace((String)RouteData.Values["query"])) { query = (String)RouteData.Values["query"]; } if (String.IsNullOrWhiteSpace(query) && !String.IsNullOrWhiteSpace(hashData.GetValue("query"))) { query = hashData.GetValue("query"); } if (String.IsNullOrWhiteSpace(query)) { rData = SafeTrend.Json.JSON.Serialize2(new { jsonrpc = "1.0", method = "workflow.list", parameters = new { page_size = pageSize, page = page }, id = 1 }); } else { rData = SafeTrend.Json.JSON.Serialize2(new { jsonrpc = "1.0", method = "workflow.search", parameters = new { text = query, page_size = pageSize, page = page }, id = 1 }); } jData = ""; using (IAMDatabase database = new IAMDatabase(IAMDatabase.GetWebConnectionString())) jData = WebPageAPI.ExecuteLocal(database, this, rData); if (String.IsNullOrWhiteSpace(jData)) { throw new Exception(""); } WorkflowListResult ret2 = JSON.Deserialize <WorkflowListResult>(jData); if (ret2 == null) { eHtml += String.Format(errorTemplate, MessageResource.GetMessage("workflow_not_found")); hasNext = false; } else if (ret2.error != null) { #if DEBUG eHtml += String.Format(errorTemplate, ret2.error.data + ret2.error.debug); #else eHtml += String.Format(errorTemplate, ret2.error.data); #endif hasNext = false; } else if (ret2.result == null || (ret2.result.Count == 0 && page == 1)) { eHtml += String.Format(errorTemplate, MessageResource.GetMessage("workflow_not_found")); hasNext = false; } else { foreach (WorkflowData w in ret2.result) { String text = ""; if (w.description != null) { text += "<span>Descrição: " + w.description + "</span><br />"; } if (w.activities != null) { text += "<span>Atividades de aprovação: " + (w.activities.Count == 0 ? "Nenhuma atividade cadastrada":""); foreach (WorkflowDataActivity a in w.activities) { text += "<div style=\"padding-left: 20px;\">" + a.name + "</div>"; } text += "</span>"; } //if (w. != null) // text += "<span>Contexto: " + c.context_name + "</span>"; String links = ""; links += "<a href=\"" + ApplicationVirtualPath + "admin/workflow/" + w.workflow_id + "/" + (Request.Form["hashtag"] != null ? "#" + Request.Form["hashtag"].ToString() : "") + "\"><div class=\"ico icon-change\">Editar</div></a>"; links += "<a href=\"" + ApplicationVirtualPath + "admin/workflow/" + w.workflow_id + "/add_user/" + (Request.Form["hashtag"] != null ? "#" + Request.Form["hashtag"].ToString() : "") + "\"><div class=\"ico icon-user-add\">Adicionar usuário</div></a>"; links += "<a href=\"" + ApplicationVirtualPath + "admin/workflow/" + w.workflow_id + "/action/delete_all_users/" + (Request.Form["hashtag"] != null ? "#" + Request.Form["hashtag"].ToString() : "") + "\" class=\"confirm-action\" confirm-title=\"Exclusão\" confirm-text=\"Deseja excluir definitivamente todos os usuários da pasta '" + w.name + "'?\" ok=\"Excluir\" cancel=\"Cancelar\"><div class=\"ico icon-close\">Excluir usuários</div></a>"; links += "<a class=\"confirm-action\" href=\"" + ApplicationVirtualPath + "admin/workflow/" + w.workflow_id + "/action/delete/" + (Request.Form["hashtag"] != null ? "#" + Request.Form["hashtag"].ToString() : "") + "\" confirm-title=\"Exclusão\" confirm-text=\"Deseja excluir definitivamente a pasta '" + w.name + "'?\" ok=\"Excluir\" cancel=\"Cancelar\"><div class=\"ico icon-close\">Apagar</div></a>"; html += String.Format(containerTemplate, w.workflow_id, w.name, w.request_qty, (w.create_date > 0 ? "Criado em " + MessageResource.FormatDate(new DateTime(1970, 1, 1).AddSeconds(w.create_date), true) : ""), text, links); } if (ret2.result.Count < pageSize) { hasNext = false; } } } catch (Exception ex) { eHtml += String.Format(errorTemplate, MessageResource.GetMessage("api_error")); } if (page == 1) { html += "</div>"; html += "<span class=\"empty-results content-loading proxy-list-loader hide\"></span>"; contentRet = new WebJsonResponse("#content-wrapper", (eHtml != "" ? eHtml : html)); } else { contentRet = new WebJsonResponse("#content-wrapper #box-container", (eHtml != "" ? eHtml : html), true); } contentRet.js = js + "$( document ).unbind('end_of_scroll');"; if (hasNext) { contentRet.js += "$( document ).bind( 'end_of_scroll.loader_role', function() { $( document ).unbind('end_of_scroll.loader_role'); $('.proxy-list-loader').removeClass('hide'); iamadmin.getPageContent2( { page: " + ++page + ", search:'" + (!String.IsNullOrWhiteSpace(query) ? query : "") + "' }, function(){ $('.proxy-list-loader').addClass('hide'); } ); });"; } } else //Esta sendo selecionado o content { if (error != "") { contentRet = new WebJsonResponse("#content-wrapper", String.Format(errorTemplate, error)); } else { switch (filter) { case "": rData = SafeTrend.Json.JSON.Serialize2(new { jsonrpc = "1.0", method = "container.list", parameters = new { page_size = Int32.MaxValue, page = 1 }, id = 1 }); jData = ""; using (IAMDatabase database = new IAMDatabase(IAMDatabase.GetWebConnectionString())) jData = WebPageAPI.ExecuteLocal(database, this, rData); List <ContainerData> conteinerList = new List <ContainerData>(); ContainerListResult cl = JSON.Deserialize <ContainerListResult>(jData); if ((cl != null) && (cl.error == null) && (cl.result != null) && (cl.result.Count > 0)) { conteinerList.AddRange(cl.result); } html = "<h3>Edição do workflow</h3>"; html += "<form id=\"form_add_role\" method=\"post\" action=\"" + ApplicationVirtualPath + "admin/workflow/" + selectedWorkflow.result.info.workflow_id + "/action/change/\">"; html += "<div class=\"no-tabs fields\"><table><tbody>"; html += String.Format(infoTemplate, "", "Nome", "<input id=\"container_name\" name=\"container_name\" placeholder=\"Digite o nome da pasta\" type=\"text\"\" value=\"" + selectedWorkflow.result.info.name + "\">"); html += String.Format(infoTemplate, "", "Contexto", selectedWorkflow.result.info.name); html += "</tbody></table><div class=\"clear-block\"></div></div>"; html += "<button type=\"submit\" id=\"user-profile-password-save\" class=\"button secondary floatleft\">Salvar</button> <a href=\"" + ApplicationVirtualPath + "admin/workflow/" + (Request.Form["hashtag"] != null ? "#" + Request.Form["hashtag"].ToString() : "") + "\" class=\"button link floatleft\">Cancelar</a></form>"; contentRet = new WebJsonResponse("#content-wrapper", (eHtml != "" ? eHtml : html)); break; case "add_user": html = "<h3>Adição de usuário</h3>"; html += "<form id=\"form_add_user\" method=\"post\" action=\"" + ApplicationVirtualPath + "admin/workflow/" + workflowId + "/action/add_user/\"><div class=\"no-tabs pb10\">"; html += "<div class=\"form-group\" id=\"add_user\"><label>Usuário</label><input id=\"add_user_text\" placeholder=\"Digite o nome do usuário\" type=\"text\"\"></div>"; html += "<div class=\"clear-block\"></div></div>"; html += "<h3>Usuários selecionados</h3>"; html += "<div id=\"box-container\" class=\"box-container\"><div class=\"no-tabs pb10 none\">"; html += "Nenhum usuário selecionado"; html += "</div></div>"; html += "<button type=\"submit\" id=\"user-profile-password-save\" class=\"button secondary floatleft\">Cadastrar</button> <a href=\"" + ApplicationVirtualPath + "admin/workflow/" + (Request.Form["hashtag"] != null ? "#" + Request.Form["hashtag"].ToString() : "") + "\" class=\"button link floatleft\">Cancelar</a></form>"; contentRet = new WebJsonResponse("#content-wrapper", (eHtml != "" ? eHtml : html)); contentRet.js = "iamadmin.autoCompleteText('#add_user_text', '" + ApplicationVirtualPath + "admin/users/content/search_user/', {context_id: '" + selectedWorkflow.result.info.context_id + "'} , function(thisId, selectedItem){ $(thisId).val(''); $('.none').remove(); $('.box-container').append(selectedItem.html); } )"; break; } } } } break; case "sidebar": if (menu1 != null) { html += "<div class=\"sep\"><div class=\"section-nav-header\">"; html += " <div class=\"crumbs\">"; html += " <div class=\"subject subject-color\">"; html += " <a href=\"" + menu1.HRef + "\">" + menu1.Name + "</a>"; html += " </div>"; if (menu2 != null) { html += " <div class=\"topic topic-color\">"; html += " <a href=\"" + menu2.HRef + "\">" + menu2.Name + "</a>"; html += " </div>"; } html += " </div>"; if (menu3 != null) { html += " <div class=\"crumbs tutorial-title\">"; html += " <h2 class=\"title tutorial-color\">" + menu3.Name + "</h2>"; html += " </div>"; } html += "</div></div>"; } if (!newItem) { html += "<div class=\"sep\"><button class=\"a-btn-big a-btn\" type=\"button\" onclick=\"window.location='" + ApplicationVirtualPath + "admin/workflow/new/" + (Request.Form["hashtag"] != null ? "#" + Request.Form["hashtag"].ToString() : "") + "'\">Novo workflow</button></div>"; } contentRet = new WebJsonResponse("#main aside", html); break; case "mobilebar": break; case "buttonbox": break; case "search_user": List <AutoCompleteItem> users = new List <AutoCompleteItem>(); try { rData = SafeTrend.Json.JSON.Serialize2(new { jsonrpc = "1.0", method = "user.search", parameters = new { page_size = 20, page = 1, text = Request.Form["text"], filter = new { contextid = Request.Form["context_id"] } }, id = 1 }); jData = ""; using (IAMDatabase database = new IAMDatabase(IAMDatabase.GetWebConnectionString())) jData = WebPageAPI.ExecuteLocal(database, this, rData); if (String.IsNullOrWhiteSpace(jData)) { throw new Exception(""); } SearchResult ret2 = JSON.Deserialize <SearchResult>(jData); if (ret2 == null) { //eHtml += String.Format(errorTemplate, MessageResource.GetMessage("user_not_found")); //ret = new WebJsonResponse("", MessageResource.GetMessage("user_not_found"), 3000, true); } else if (ret2.error != null) { eHtml += String.Format(errorTemplate, ret2.error.data); } else if (ret2.result == null) { //eHtml += String.Format(errorTemplate, MessageResource.GetMessage("user_not_found")); } else { foreach (UserData user in ret2.result) { String tHtml = "<div class=\"item\"><input type=\"hidden\" name=\"" + Request.Form["content_id"] + "\" id=\"" + Request.Form["content_id"] + "\" value=\"" + user.userid + "\"><div class=\"text\">" + user.login + "</div><div class=\"delete ico icon-close\" onclick=\"$(this).closest('.item').remove();\"></div><div class=\"clear-block\"></div></div>"; users.Add(new AutoCompleteItem(user.userid, "(" + user.login + ") " + user.full_name, tHtml)); } } } catch (Exception ex) { eHtml += String.Format(errorTemplate, MessageResource.GetMessage("api_error")); //ret = new WebJsonResponse("", MessageResource.GetMessage("api_error"), 3000, true); } if (users.Count == 0) { users.Add(new AutoCompleteItem(0, MessageResource.GetMessage("user_not_found"), "")); } Retorno.Controls.Add(new LiteralControl(JSON.Serialize <List <AutoCompleteItem> >(users))); break; case "search_role": List <AutoCompleteItem> roles = new List <AutoCompleteItem>(); try { rData = SafeTrend.Json.JSON.Serialize2(new { jsonrpc = "1.0", method = "role.search", parameters = new { page_size = 20, page = 1, text = Request.Form["text"], filter = new { contextid = Request.Form["context_id"] } }, id = 1 }); jData = ""; using (IAMDatabase database = new IAMDatabase(IAMDatabase.GetWebConnectionString())) jData = WebPageAPI.ExecuteLocal(database, this, rData); if (String.IsNullOrWhiteSpace(jData)) { throw new Exception(""); } RoleListResult ret2 = JSON.Deserialize <RoleListResult>(jData); if (ret2 == null) { //eHtml += String.Format(errorTemplate, MessageResource.GetMessage("user_not_found")); //ret = new WebJsonResponse("", MessageResource.GetMessage("user_not_found"), 3000, true); } else if (ret2.error != null) { eHtml += String.Format(errorTemplate, ret2.error.data); } else if (ret2.result == null) { //eHtml += String.Format(errorTemplate, MessageResource.GetMessage("user_not_found")); } else { foreach (RoleData role in ret2.result) { String tHtml = "<div class=\"item\"><input type=\"hidden\" name=\"" + Request.Form["content_id"] + "\" id=\"" + Request.Form["content_id"] + "\" value=\"" + role.role_id + "\"><div class=\"text\">" + role.name + "</div><div class=\"delete ico icon-close\" onclick=\"$(this).closest('.item').remove();\"></div><div class=\"clear-block\"></div></div>"; roles.Add(new AutoCompleteItem(role.role_id, role.name, tHtml)); } } } catch (Exception ex) { eHtml += String.Format(errorTemplate, MessageResource.GetMessage("api_error")); //ret = new WebJsonResponse("", MessageResource.GetMessage("api_error"), 3000, true); } if (roles.Count == 0) { roles.Add(new AutoCompleteItem(0, MessageResource.GetMessage("role_not_found"), "")); } Retorno.Controls.Add(new LiteralControl(JSON.Serialize <List <AutoCompleteItem> >(roles))); break; } if (contentRet != null) { if (!String.IsNullOrWhiteSpace((String)Request["cid"])) { contentRet.callId = (String)Request["cid"]; } Retorno.Controls.Add(new LiteralControl(contentRet.ToJSON())); } }