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 = 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; try { throw new NotImplementedException(); /* * LoginResult auth = LoginUser.AuthUser(this, Request["userLogin"], Request["password"]); * * if ((auth.Success) && (auth.ChangePassword) && (Session["login"] is LoginData)) * { * Session["entity_id"] = ((LoginData)Session["login"]).Id; * Session["login"] = null; * ret = new WebJsonResponse("/login/changepassword/"); * } * else if ((auth.Success) && (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 = 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 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"]; } 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; 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) { 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/system_roles/" + (Request.Form["hashtag"] != null ? "#" + Request.Form["hashtag"].ToString() : "")); LMenu menu3 = new LMenu("Perfis do sistema", ApplicationVirtualPath + "admin/system_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>"; String infoTemplate = "<tr><td class=\"col1\">{0}</td><td class=\"col2\"><span class=\"no-edit\">{1}</span></td></tr>"; //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 = ""; SystemRoleGetResult selectedRole = 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 { String rData = SafeTrend.Json.JSON.Serialize2(new { jsonrpc = "1.0", method = "systemrole.get", parameters = new { roleid = roleId, permissions = true }, id = 1 }); IAMDatabase database = new IAMDatabase(IAMDatabase.GetWebConnectionString()); String jData = ""; try { jData = WebPageAPI.ExecuteLocal(database, this, rData); } finally { if (database != null) { database.Dispose(); } } selectedRole = JSON.Deserialize <SystemRoleGetResult>(jData); if (selectedRole == null) { error = MessageResource.GetMessage("system_role_not_found"); } else if (selectedRole.error != null) { error = selectedRole.error.data; selectedRole = null; } else if (selectedRole.result == null || selectedRole.result.info == null) { error = MessageResource.GetMessage("system_role_not_found"); selectedRole = null; } else { menu3.Name = selectedRole.result.info.name; menu3.HRef = ApplicationVirtualPath + "admin/system_roles/" + selectedRole.result.info.role_id + "/" + (Request.Form["hashtag"] != null ? "#" + Request.Form["hashtag"].ToString() : ""); } } catch (Exception ex) { error = MessageResource.GetMessage("api_error"); Tools.Tool.notifyException(ex, this); selectedRole = null; } } switch (area) { case "": case "search": case "content": if (newItem) { html = "<h3>Adição de perfil</h3>"; html += "<form id=\"form_add_role\" method=\"post\" action=\"" + ApplicationVirtualPath + "admin/system_roles/action/add_role/\">"; html += "<div class=\"no-tabs fields\"><table><tbody>"; html += String.Format(infoTemplate, "Nome", "<input id=\"add_role_name\" name=\"add_role_name\" placeholder=\"Digite o nome do perfil\" type=\"text\">"); html += String.Format(infoTemplate, "Admin", "<input id=\"enterprise_admin\" name=\"enterprise_admin\" type=\"checkbox\"><span class=\"description\">Perfil com direitos em todas as operações desta empresa</span>"); html += "</select></div>"; html += "</tbody></table></div>"; html += "<button type=\"submit\" id=\"user-profile-password-save\" class=\"button secondary floatleft\">Adicionar</button> <a href=\"" + ApplicationVirtualPath + "admin/system_roles/" + (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 (selectedRole == 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/system_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=\"description\">Permissões atribuidas: {4}"; roleTemplate += " </div>"; roleTemplate += " <div class=\"links\">"; roleTemplate += " <div class=\"line\">"; roleTemplate += " <a href=\"" + ApplicationVirtualPath + "admin/system_roles/{0}/" + (Request.Form["hashtag"] != null ? "#" + Request.Form["hashtag"].ToString() : "") + "\"><div class=\"ico icon-change\">Editar</div></a>"; roleTemplate += " <a href=\"" + ApplicationVirtualPath + "admin/system_roles/{0}/permissions/" + (Request.Form["hashtag"] != null ? "#" + Request.Form["hashtag"].ToString() : "") + "\"><div class=\"ico icon-checkmark\">Permissões</div></a>"; roleTemplate += " <a href=\"" + ApplicationVirtualPath + "admin/system_roles/{0}/add_user/" + (Request.Form["hashtag"] != null ? "#" + Request.Form["hashtag"].ToString() : "") + "\"><div class=\"ico icon-user-add\">Adicionar usuário</div></a>"; roleTemplate += " <a href=\"" + ApplicationVirtualPath + "admin/system_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>"; roleTemplate += " <a class=\"confirm-action\" href=\"" + ApplicationVirtualPath + "admin/system_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>"; roleTemplate += " </div><div class=\"clear-block\"></div>"; roleTemplate += " </div>"; 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)) { rData = SafeTrend.Json.JSON.Serialize2(new { jsonrpc = "1.0", method = "systemrole.list", parameters = new { page_size = pageSize, page = page, permissions = true }, id = 1 }); } else { rData = SafeTrend.Json.JSON.Serialize2(new { jsonrpc = "1.0", method = "systemrole.search", parameters = new { text = query, page_size = pageSize, page = page, permissions = true }, id = 1 }); } IAMDatabase database = new IAMDatabase(IAMDatabase.GetWebConnectionString()); String jData = ""; try { jData = WebPageAPI.ExecuteLocal(database, this, rData); } finally { if (database != null) { database.Dispose(); } } if (String.IsNullOrWhiteSpace(jData)) { throw new Exception(""); } SystemRoleListResult ret2 = JSON.Deserialize <SystemRoleListResult>(jData); if (ret2 == null) { eHtml += String.Format(errorTemplate, MessageResource.GetMessage("system_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("system_role_not_found")); hasNext = false; } else { foreach (SystemRoleData role in ret2.result) { List <String> perm = new List <string>(); if (!role.enterprise_admin && (role.permissions != null) && (role.permissions.Count > 0)) { foreach (SystemRolePermission p in role.permissions) { perm.Add(p.module_name + "/" + p.sub_module_name + "/" + p.name); } } if (role.enterprise_admin) { perm.Add("Administração da empresa - todas as permissões"); } if (perm.Count == 0) { perm.Add("Nenhuma permissão atribuida"); } 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) : ""), String.Join(", ", perm)); } 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 "": html += "<h3>Configurações gerais"; if (hashData.GetValue("edit") != "1") { html += "<div class=\"btn-box\"><div class=\"a-btn ico icon-change\" onclick=\"iamadmin.changeHash( 'edit/1' );\">Editar</div></div>"; } html += "</h3>"; html += "<form id=\"form_add_role\" method=\"post\" action=\"" + ApplicationVirtualPath + "admin/system_roles/" + selectedRole.result.info.role_id + "/action/change_role/\">"; html += "<div class=\"no-tabs fields\"><table><tbody>"; if (hashData.GetValue("edit") == "1") { html += String.Format(infoTemplate, "Nome", "<input id=\"name\" name=\"name\" placeholder=\"Digite o nome do perfil\" type=\"text\" value=\"" + selectedRole.result.info.name + "\">"); html += String.Format(infoTemplate, "Admin", "<input id=\"enterprise_admin\" name=\"enterprise_admin\" type=\"checkbox\" " + (selectedRole.result.info.enterprise_admin ? "checked" : "") + "><span class=\"description\">Perfil com direitos em todas as operações desta empresa</span>"); } else { html += String.Format(infoTemplate, "Nome", selectedRole.result.info.name); html += String.Format(infoTemplate, "Admin", (selectedRole.result.info.enterprise_admin ? MessageResource.GetMessage("yes") : MessageResource.GetMessage("no"))); } html += "</tbody></table></div>"; if (hashData.GetValue("edit") == "1") { html += "<button type=\"submit\" id=\"user-profile-password-save\" class=\"button secondary floatleft\">Salvar</button> <a href=\"" + ApplicationVirtualPath + "admin/system_roles/" + selectedRole.result.info.role_id + "/\" class=\"button link floatleft\">Cancelar</a></form>"; } contentRet = new WebJsonResponse("#content-wrapper", (eHtml != "" ? eHtml : html)); break; 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/system_roles/" + selectedRole.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 de sistema '" + selectedRole.result.info.name + "'?\" ok=\"Excluir\" cancel=\"Cancelar\">Excluir</button></td>"; trTemplate += " </tr>"; try { String rData = ""; rData = SafeTrend.Json.JSON.Serialize2(new { jsonrpc = "1.0", method = "systemrole.users", parameters = new { page_size = pageSize, page = page, roleid = roleId }, id = 1 }); 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/system_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/system_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/', null , function(thisId, selectedItem){ $(thisId).val(''); $('.none').remove(); $('.box-container').append(selectedItem.html); } )"; break; case "permissions": html += "<h3>Permissões"; if ((hashData.GetValue("edit") != "1") && (!selectedRole.result.info.enterprise_admin)) { html += "<div class=\"btn-box\"><div class=\"a-btn ico icon-change\" onclick=\"iamadmin.changeHash( 'edit/1' );\">Editar</div></div>"; } html += "</h3>"; html += "<form id=\"form_add_role\" method=\"post\" action=\"" + ApplicationVirtualPath + "admin/system_roles/" + selectedRole.result.info.role_id + "/action/change_permissions/\">"; html += "<div class=\"no-tabs fields\"><table><tbody>"; String infoTemplate2 = "<tr><td class=\"colfull\">{0}</td></tr>"; if (selectedRole.result.info.enterprise_admin) { html += String.Format(infoTemplate2, "<span style=\"text-align: center; width: 100%; display:block;\">Esto perfil tem permissão de administração total nesta empresa, desta forma não necessita configurar permissões específicas</span>"); } else { String rData = SafeTrend.Json.JSON.Serialize2(new { jsonrpc = "1.0", method = "systemrole.permissionstree", parameters = new { }, id = 1 }); String jData = ""; using (IAMDatabase database = new IAMDatabase(IAMDatabase.GetWebConnectionString())) jData = WebPageAPI.ExecuteLocal(database, this, rData); SystemRolePermissionsTree retPTree = JSON.Deserialize <SystemRolePermissionsTree>(jData); if (retPTree == null) { eHtml += String.Format(errorTemplate, MessageResource.GetMessage("permissions_not_found")); } else if (retPTree.error != null) { eHtml += String.Format(errorTemplate, retPTree.error.data); } else if (retPTree.result == null) { eHtml += String.Format(errorTemplate, MessageResource.GetMessage("permissions_not_found")); } else { if (hashData.GetValue("edit") == "1") { String field = ""; field += "<div id=\"tree\">"; field += "<ul>"; foreach (SystemRolePermissionModule module in retPTree.result) { if (module.submodules.Count > 0) { field += " <li class=\"" + (module.submodules.Count == 0 ? "no-chield" : "") + "\"><input type=\"checkbox\"><span>" + module.name + "</span>"; field += " <ul>"; foreach (SystemRolePermissionSubModule subModule in module.submodules) { if (subModule.permissions.Count > 0) { field += " <li class=\"" + (subModule.permissions.Count == 0 ? "no-chield" : "") + "\"><input type=\"checkbox\"><span>" + subModule.name + "</span>"; field += " <ul>"; foreach (SystemRolePermissionItem permission in subModule.permissions) { field += " <li class=\"no-chield\"><input type=\"checkbox\" name=\"permission_id\" value=\"" + permission.permission_id + "\" " + (selectedRole.result.info.permissions != null && selectedRole.result.info.permissions.Exists(p => (p.permission_id == permission.permission_id)) ? "checked" : "") + "><span>" + permission.name + "</span></li>"; } field += " </ul>"; field += "</li>"; } } field += " </ul>"; field += "</li>"; } } field += "</ul>"; field += "</div>"; html += String.Format(infoTemplate2, field); js = "$('#tree').tree({ dnd: false });"; } else { foreach (SystemRolePermissionModule module in retPTree.result) { if (module.submodules.Count > 0) { foreach (SystemRolePermissionSubModule subModule in module.submodules) { if (subModule.permissions.Count > 0) { List <String> per = new List <string>(); foreach (SystemRolePermissionItem permission in subModule.permissions) { if (selectedRole.result.info.permissions != null && selectedRole.result.info.permissions.Exists(p => (p.permission_id == permission.permission_id))) { per.Add(permission.name); } } if (per.Count == 0) { per.Add("Nenhuma permissão definida"); } html += String.Format(infoTemplate, module.name + "/" + subModule.name, String.Join(", ", per)); } } } } } } } html += "</tbody></table></div>"; if (hashData.GetValue("edit") == "1") { html += "<button type=\"submit\" id=\"user-profile-password-save\" class=\"button secondary floatleft\">Salvar</button> <a href=\"" + ApplicationVirtualPath + "admin/system_roles/" + selectedRole.result.info.role_id + "/permissions/\" class=\"button link floatleft\">Cancelar</a></form>"; } contentRet = new WebJsonResponse("#content-wrapper", (eHtml != "" ? eHtml : html)); contentRet.js = js; 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\"><a href=\"" + menu3.HRef + "\">" + menu3.Name + "</a></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/system_roles/new/" + (Request.Form["hashtag"] != null ? "#" + Request.Form["hashtag"].ToString() : "") + "'\">Novo perfil</button></div>"; if (selectedRole != null) { if (filter != "add_user") { html += "<div class=\"sep\"><button class=\"a-btn-big a-btn\" type=\"button\" onclick=\"window.location='" + ApplicationVirtualPath + "admin/system_roles/" + selectedRole.result.info.role_id + "/add_user/" + (Request.Form["hashtag"] != null ? "#" + Request.Form["hashtag"].ToString() : "") + "'\">Adicionar usuários</button></div>"; } if (filter != "permissions") { html += "<div class=\"sep\"><button class=\"a-btn-big a-btn\" type=\"button\" onclick=\"window.location='" + ApplicationVirtualPath + "admin/system_roles/" + selectedRole.result.info.role_id + "/permissions/" + (Request.Form["hashtag"] != null ? "#" + Request.Form["hashtag"].ToString() : "") + "'\">Alterar permissões</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 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; 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"]; } 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) { 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("Plugins", ApplicationVirtualPath + "admin/plugin/" + (Request.Form["hashtag"] != null ? "#" + Request.Form["hashtag"].ToString() : "")); LMenu menu3 = new LMenu("Plugins do sistema", ApplicationVirtualPath + "admin/plugin/" + (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 pluginId = 0; try { pluginId = Int64.Parse((String)RouteData.Values["id"]); if (pluginId < 0) { pluginId = 0; } } catch { } String error = ""; PluginGetResult retPlugin = null; String filter = ""; HashData hashData = new HashData(this); if (!String.IsNullOrWhiteSpace((String)RouteData.Values["filter"])) { filter = (String)RouteData.Values["filter"]; } if ((pluginId > 0) && (area.ToLower() != "search")) { try { var tmpReq = new { jsonrpc = "1.0", method = "plugin.get", parameters = new { pluginid = pluginId }, 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(""); } retPlugin = JSON.Deserialize <PluginGetResult>(jData); if (retPlugin == null) { error = MessageResource.GetMessage("plugin_not_found"); //ret = new WebJsonResponse("", MessageResource.GetMessage("user_not_found"), 3000, true); } else if (retPlugin.error != null) { error = retPlugin.error.data; retPlugin = null; } else if (retPlugin.result == null || retPlugin.result.info == null) { error = MessageResource.GetMessage("plugin_not_found"); retPlugin = null; } else { menu3.Name = retPlugin.result.info.name; } } catch (Exception ex) { error = MessageResource.GetMessage("api_error"); Tools.Tool.notifyException(ex, this); retPlugin = null; //ret = new WebJsonResponse("", MessageResource.GetMessage("api_error"), 3000, true); } } switch (area) { case "": case "search": case "content": if (newItem) { html += "<div id=\"upload-box\" class=\"upload-box\"><input type=\"file\" name=\"files[]\" multiple=\"\"><div class=\"drag-content\"><span class=\"upload-button-text\">Selecione arquivos para enviar</span><span class=\"upload-drag-drop-description\">Ou arraste e solte aqui</span></div><div class=\"dragDrop-content\"><span class=\"label l1\">Arraste o plugin até aqui</span><span class=\"label l2\">Solte o plugin</span></div></div>"; html += "<h3>Uploads</h3>"; html += "<form id=\"form_plugin_add\" method=\"POST\" action=\"" + ApplicationVirtualPath + "admin/plugin/action/add_new/\">"; html += "<div id=\"files\" class=\"box-container\"><div class=\"no-tabs pb10 none\">Nenhum upload realizado</div></div>"; html += "<button type=\"submit\" id=\"upload-save\" class=\"button secondary floatleft\">Adicionar</button> <a href=\"" + ApplicationVirtualPath + "admin/plugin/" + (Request.Form["hashtag"] != null ? "#" + Request.Form["hashtag"].ToString() : "") + "\" class=\"button link floatleft\">Cancelar</a></form>"; html += "</form>"; contentRet = new WebJsonResponse("#content-wrapper", (eHtml != "" ? eHtml : html)); contentRet.js = "iamadmin.pluginUploader($('#upload-box'), '" + ApplicationVirtualPath + "admin/plugin/action/upload/','" + ApplicationVirtualPath + "admin/plugin/action/upload_item_template/')"; } else { if (retPlugin == null) { Int32 page = 1; Int32 pageSize = 20; Boolean hasNext = true; Int32.TryParse(Request.Form["page"], out page); if (page < 1) { page = 1; } String pluginTemplate = "<div id=\"role-list-{0}\" data-id=\"{0}\" data-name=\"{1}\" data-total=\"{2}\" class=\"app-list-item\">"; pluginTemplate += "<table>"; pluginTemplate += " <tbody>"; pluginTemplate += " <tr>"; pluginTemplate += " <td class=\"col1\">"; pluginTemplate += " <span id=\"total_{0}\" class=\"total \">{2}</span>"; pluginTemplate += " <a href=\"" + ApplicationVirtualPath + "admin/resource_plugin/#plugin/{0}\">"; pluginTemplate += " <div class=\"app-btn a-btn\"><span class=\"a-btn-inner\">Ver vínculos</span></div>"; pluginTemplate += " </a>"; pluginTemplate += " </td>"; pluginTemplate += " <td class=\"col2\">"; pluginTemplate += " <div class=\"title\"><span class=\"name field-editor\">{1}</span><span class=\"date\">{4}</span><div class=\"clear-block\"></div></div>"; pluginTemplate += " <div class=\"links no-bg\">"; pluginTemplate += " <div class=\"first\">Uri: {3}<br clear=\"all\"></div>"; pluginTemplate += " <div class=\"\"><a href=\"" + ApplicationVirtualPath + "admin/plugin/{0}/flow/" + (Request.Form["hashtag"] != null ? "#" + Request.Form["hashtag"].ToString() : "") + "\"><div class=\"ico icon-sitemap\">Fluxo de dados</div></a></div>"; pluginTemplate += " <div class=\"last\">{5}<br clear=\"all\"></div>"; pluginTemplate += " </div><br clear=\"all\">"; pluginTemplate += " </td>"; pluginTemplate += " </tr>"; pluginTemplate += " </tbody>"; pluginTemplate += "</table></div>"; html += "<div id=\"plugin-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 = "plugin.list", parameters = new { page_size = pageSize, page = page }, id = 1 }; rData = SafeTrend.Json.JSON.Serialize2(tmpReq); } else { var tmpReq = new { jsonrpc = "1.0", method = "plugin.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(""); } PluginListResult ret2 = JSON.Deserialize <PluginListResult>(jData); if (ret2 == null) { eHtml += String.Format(errorTemplate, MessageResource.GetMessage("plugin_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("plugin_not_found")); hasNext = false; } else { foreach (PluginData plugin in ret2.result) { html += String.Format(pluginTemplate, plugin.plugin_id, plugin.name, plugin.resource_plugin_qty, plugin.uri, (plugin.create_date > 0 ? "Criado em " + MessageResource.FormatDate(new DateTime(1970, 1, 1).AddSeconds(plugin.create_date), true) : ""), (plugin.enterprise_id > 0 ? "<a class=\"confirm-action\" href=\"" + ApplicationVirtualPath + "admin/plugin/" + plugin.plugin_id + "/action/delete/" + (Request.Form["hashtag"] != null ? "#" + Request.Form["hashtag"].ToString() : "") + "\" confirm-title=\"Exclusão\" confirm-text=\"Deseja excluir definitivamente o plugin '" + plugin.uri + "'?\" 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 plugin-list-loader hide\"></span>"; contentRet = new WebJsonResponse("#content-wrapper", (eHtml != "" ? eHtml : html)); } else { contentRet = new WebJsonResponse("#content-wrapper #plugin-container", (eHtml != "" ? eHtml : html), true); } contentRet.js = js + "$( document ).unbind('end_of_scroll');"; if (hasNext) { contentRet.js += "$( document ).bind( 'end_of_scroll.loader_plugin', function() { $( document ).unbind('end_of_scroll.loader_plugin'); $('.plugin-list-loader').removeClass('hide'); iamadmin.getPageContent2( { page: " + ++page + ", search:'" + (!String.IsNullOrWhiteSpace(query) ? query : "") + "' }, function(){ $('.plugin-list-loader').addClass('hide'); } ); });"; } } else //Esta sendo selecionado o plugin { if (error != "") { contentRet = new WebJsonResponse("#content-wrapper", String.Format(errorTemplate, error)); } else { switch (filter) { case "flow": String js2 = ""; if (filter == "" || filter == "flow") { html += "<h3>Fluxo de dados</h3>"; html += "<div id=\"pluginChart\"></div>"; js2 = "$('#pluginChart').flowchart({load_uri: '" + ApplicationVirtualPath + "admin/chartdata/flow/plugin/" + retPlugin.result.info.plugin_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/plugin/new/" + (Request.Form["hashtag"] != null ? "#" + Request.Form["hashtag"].ToString() : "") + "'\">Novo plugin</button></div>"; } contentRet = new WebJsonResponse("#main aside", html); break; case "mobilebar": break; case "buttonbox": switch (filter) { case "": 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) { WebJsonResponse contentRet = null; String action = ""; if (!String.IsNullOrWhiteSpace((String)RouteData.Values["action"])) { action = (String)RouteData.Values["action"]; } Int64 pluginId = 0; if ((action != "add_plugin") && (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 += " <div class=\"links small\">"; userHtmlTemplate += " <div class=\"last\"><div class=\"ico icon-close\" onclick=\"$('#file{0}').remove();\">Excluir plugin</div></a><div class=\"clear-block\"></div></div>"; userHtmlTemplate += " </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 = ""; DirectoryInfo pluginsDir = null; try { using (ServerDBConfig c = new ServerDBConfig(IAMDatabase.GetWebConnection())) pluginsDir = new DirectoryInfo(Path.Combine(c.GetItem("pluginFolder"), "temp\\" + ((EnterpriseData)Page.Session["enterprise_data"]).Id)); if (!pluginsDir.Exists) { pluginsDir.Create(); } } catch { pluginsDir = null; } if (pluginsDir == null) { d += String.Format(infoTemplate2, "", "Status", "Diretório de plugins não encontrado"); } else { try { if (!pluginsDir.Exists) { pluginsDir.Create(); } Byte[] rawAssembly = new Byte[mpF.Data.Length]; mpF.Data.Read(rawAssembly, 0, rawAssembly.Length); List <String> p2 = new List <String>(); List <String> p2Uri = new List <String>(); try { //Realiza teste de compatibilidade com os plugins List <PluginBase> p1 = Plugins.GetPlugins <PluginBase>(rawAssembly); if (p1.Count > 0) { d += String.Format(infoTemplate2, "", "Status", "Arquivo válido"); } else { d += String.Format(infoTemplate2, "", "Status", "Arquivo de plugin inválido"); } foreach (PluginBase p in p1) { p2.Add(p.GetPluginName()); p2Uri.Add(p.GetPluginId().AbsoluteUri); } } catch { d += String.Format(infoTemplate2, "", "Status", "Arquivo de plugin inválido"); } d += String.Format(infoTemplate2, "", "Nome", mpF.FileName); d += String.Format(infoTemplate2, "", "Tamanho", mpF.Data.Length + " bytes"); 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); } } 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": Dictionary <String, String> files = new Dictionary <string, string>(); foreach (String key in Request.Form.Keys) { if ((key != null) && (key.ToLower().IndexOf("file_name") == 0)) { if (!files.ContainsKey(Request.Form[key].ToLower())) { files.Add(Request.Form[key].ToLower(), Request.Form[Request.Form[key]]); } } } if (files.Count == 0) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("plugin_not_found"), 3000, true); break; } DirectoryInfo pluginsBase = null; DirectoryInfo pluginsTemp = null; try { using (ServerDBConfig c = new ServerDBConfig(IAMDatabase.GetWebConnection())) pluginsBase = new DirectoryInfo(c.GetItem("pluginFolder")); pluginsTemp = new DirectoryInfo(Path.Combine(pluginsBase.FullName, "temp\\" + ((EnterpriseData)Page.Session["enterprise_data"]).Id)); if (!pluginsTemp.Exists) { pluginsTemp.Create(); } } catch { pluginsTemp = null; } if (pluginsTemp == null) { contentRet = new WebJsonResponse("", "Diretório de plugins não encontrado", 3000, true); break; } List <WebJsonResponse> multRet = new List <WebJsonResponse>(); String infoTemplate3 = "<div class=\"line {0}\">"; infoTemplate3 += "<label>{1}</label>"; infoTemplate3 += "<span class=\"no-edit\">{2}</span></div>"; Boolean hasError = false; foreach (String f in files.Keys) { try { FileInfo assemblyFile = new FileInfo(Path.Combine(pluginsTemp.FullName, f)); if (!assemblyFile.Exists) { throw new Exception("Arquivo temporário não encontrado, refaça o upload"); } Byte[] rawAssembly = File.ReadAllBytes(assemblyFile.FullName); List <PluginBase> p1 = Plugins.GetPlugins <PluginBase>(rawAssembly); if (p1.Count == 0) { throw new Exception("Arquivo de plugin inválido"); } foreach (PluginBase p in p1) { using (IAMDatabase database = new IAMDatabase(IAMDatabase.GetWebConnectionString())) { DataTable dt = database.Select("select * from plugin where enterprise_id in (0," + enterpriseId + ") and (assembly = '" + p.GetPluginName() + "' or uri = '" + p.GetPluginId().AbsoluteUri + "')", null); if (dt.Rows.Count > 0) { throw new Exception("Plugin/uri ja cadastrado no sistema"); } } FileInfo newF = new FileInfo(Path.Combine(pluginsBase.FullName, enterpriseId + "-" + assemblyFile.Name)); try { assemblyFile.CopyTo(newF.FullName); DbParameterCollection par = new DbParameterCollection(); par.Add("@enterprise_id", typeof(Int64)).Value = enterpriseId; par.Add("@name", typeof(String)).Value = p.GetPluginName(); par.Add("@scheme", typeof(String)).Value = p.GetPluginId().Scheme; par.Add("@uri", typeof(String)).Value = p.GetPluginId().AbsoluteUri; par.Add("@assembly", typeof(String)).Value = newF.Name; using (IAMDatabase database = new IAMDatabase(IAMDatabase.GetWebConnectionString())) database.ExecuteNonQuery("INSERT INTO plugin ([enterprise_id],[name],[scheme],[uri],[assembly],[create_date]) VALUES(@enterprise_id, @name, @scheme, @uri, @assembly, getdate())", CommandType.Text, par); try { assemblyFile.Delete(); } catch { } } catch (Exception ex) { try { newF.Delete(); } catch { } throw ex; } } multRet.Add(new WebJsonResponse(".file-item[id=file" + files[f] + "] .description", String.Format(infoTemplate3, "", "Status", "Plugin inserido com sucesso"))); multRet.Add(new WebJsonResponse(".file-item[id=file" + files[f] + "] .form-content", "<input type=\"hidden\" />")); } catch (Exception ex) { hasError = true; multRet.Add(new WebJsonResponse(".file-item[id=file" + files[f] + "] .description", String.Format(infoTemplate3, "error", "Error", ex.Message))); } } if (!hasError) { multRet.Clear(); multRet.Add(new WebJsonResponse(Session["ApplicationVirtualPath"] + "admin/plugin/")); } Retorno.Controls.Add(new LiteralControl(JSON.Serialize <List <WebJsonResponse> >(multRet))); contentRet = null; break; case "delete": var reqDel = new { jsonrpc = "1.0", method = "plugin.delete", parameters = new { pluginid = pluginId }, 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("plugin_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("plugin_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"]; } 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())); } }
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 contextId = 0; if (action != "add_context") { try { contextId = Int64.Parse((String)RouteData.Values["id"]); if (contextId < 0) { contextId = 0; } } catch { } if (contextId == 0) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("context_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 = "context.delete", parameters = new { contextid = contextId }, 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("context_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("context_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 = "context.change", parameters = new { contextid = contextId, 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("context_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("context_not_found"), 3000, true); } else if (retD.result == null || retD.result.info == null) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("context_not_found"), 3000, true); } else { contentRet = new WebJsonResponse("#context_name_" + contextId, retD.result.info.name); } break; case "change_login_rules": List <loginRule> items = new List <loginRule>(); //rule_R1410734460301_group String[] rIds = Request.Form["rule_id"].Split(",".ToCharArray()); foreach (String rid in rIds) { if (String.IsNullOrEmpty(Request.Form["rule_" + rid + "_group"])) { contentRet = new WebJsonResponse("", "Grupo não localizado na condição " + rid, 3000, true); break; } if (String.IsNullOrEmpty(Request.Form["rule_" + rid + "_field"])) { contentRet = new WebJsonResponse("", "Campo não localizado na condição " + rid, 3000, true); break; } if (String.IsNullOrEmpty(Request.Form["rule_" + rid + "_order"])) { contentRet = new WebJsonResponse("", "Ordem do campo não localizado na condição " + rid, 3000, true); break; } loginRule newItem = new loginRule(); newItem.group = Request.Form["rule_" + rid + "_group"].Split(",".ToCharArray())[0]; newItem.order = Int32.Parse(Request.Form["rule_" + rid + "_order"].Split(",".ToCharArray())[0]); try { switch (Request.Form["rule_" + rid + "_field"].Split(",".ToCharArray())[0].ToLower()) { case "first_name": case "second_name": case "last_name": case "char_first_name": case "char_second_name": case "char_last_name": case "index": case "dot": case "hyphen": newItem.field = Request.Form["rule_" + rid + "_field"].Split(",".ToCharArray())[0].ToLower(); break; default: throw new Exception(""); break; } } catch { contentRet = new WebJsonResponse("", "ID do campo inválido na condição " + rid, 3000, true); break; } items.Add(newItem); } //Ordena os ítems items.Sort(delegate(loginRule r1, loginRule r2) { return(r1.order.CompareTo(r2.order)); }); List <loginRule> finalRules = new List <loginRule>(); foreach (loginRule li in items) { loginRule gi = finalRules.Find(g => (g.group == li.group)); if (gi == null) { finalRules.Add(li); } else { gi.field += "," + li.field; } } finalRules.Sort(delegate(loginRule r1, loginRule r2) { return(r1.order.CompareTo(r2.order)); }); for (Int32 i = 0; i < finalRules.Count; i++) { finalRules[i].order = i; } List <Dictionary <String, Object> > sItems = new List <Dictionary <string, object> >(); foreach (loginRule li in finalRules) { Dictionary <String, Object> ni = new Dictionary <string, object>(); ni.Add("name", li.field); ni.Add("rule", li.field); ni.Add("order", li.order); sItems.Add(ni); } rData = JSON.Serialize2(new { jsonrpc = "1.0", method = "context.changeloginrules", parameters = new { contextid = contextId, rules = sItems }, id = 1 }); using (IAMDatabase database = new IAMDatabase(IAMDatabase.GetWebConnectionString())) jData = WebPageAPI.ExecuteLocal(database, this, rData); if (String.IsNullOrWhiteSpace(jData)) { throw new Exception(""); } BooleanResult retCL = JSON.Deserialize <BooleanResult>(jData); if (retCL == null) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("context_not_found"), 3000, true); } else if (retCL.error != null) { contentRet = new WebJsonResponse("", retCL.error.data, 3000, true); } else if (!retCL.result) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("context_not_found"), 3000, true); } else { contentRet = new WebJsonResponse(Session["ApplicationVirtualPath"] + "admin/context/" + (Request.Form["hashtag"] != null ? "#" + Request.Form["hashtag"].ToString() : "")); } break; case "change_mail_rules": List <loginRule> mItems = new List <loginRule>(); //rule_R1410734460301_group String[] mrIds = Request.Form["rule_id"].Split(",".ToCharArray()); foreach (String rid in mrIds) { if (String.IsNullOrEmpty(Request.Form["rule_" + rid + "_group"])) { contentRet = new WebJsonResponse("", "Grupo não localizado na condição " + rid, 3000, true); break; } if (String.IsNullOrEmpty(Request.Form["rule_" + rid + "_field"])) { contentRet = new WebJsonResponse("", "Campo não localizado na condição " + rid, 3000, true); break; } if (String.IsNullOrEmpty(Request.Form["rule_" + rid + "_order"])) { contentRet = new WebJsonResponse("", "Ordem do campo não localizado na condição " + rid, 3000, true); break; } loginRule newItem = new loginRule(); newItem.group = Request.Form["rule_" + rid + "_group"].Split(",".ToCharArray())[0]; newItem.order = Int32.Parse(Request.Form["rule_" + rid + "_order"].Split(",".ToCharArray())[0]); try { switch (Request.Form["rule_" + rid + "_field"].Split(",".ToCharArray())[0].ToLower()) { case "first_name": case "second_name": case "last_name": case "char_first_name": case "char_second_name": case "char_last_name": case "index": case "dot": case "hyphen": newItem.field = Request.Form["rule_" + rid + "_field"].Split(",".ToCharArray())[0].ToLower(); break; default: throw new Exception(""); break; } } catch { contentRet = new WebJsonResponse("", "ID do campo inválido na condição " + rid, 3000, true); break; } mItems.Add(newItem); } //Ordena os ítems mItems.Sort(delegate(loginRule r1, loginRule r2) { return(r1.order.CompareTo(r2.order)); }); List <loginRule> mFinalRules = new List <loginRule>(); foreach (loginRule li in mItems) { loginRule gi = mFinalRules.Find(g => (g.group == li.group)); if (gi == null) { mFinalRules.Add(li); } else { gi.field += "," + li.field; } } mFinalRules.Sort(delegate(loginRule r1, loginRule r2) { return(r1.order.CompareTo(r2.order)); }); for (Int32 i = 0; i < mFinalRules.Count; i++) { mFinalRules[i].order = i; } List <Dictionary <String, Object> > msItems = new List <Dictionary <string, object> >(); foreach (loginRule li in mFinalRules) { Dictionary <String, Object> ni = new Dictionary <string, object>(); ni.Add("name", li.field); ni.Add("rule", li.field); ni.Add("order", li.order); msItems.Add(ni); } rData = JSON.Serialize2(new { jsonrpc = "1.0", method = "context.changemailrules", parameters = new { contextid = contextId, rules = msItems }, id = 1 }); using (IAMDatabase database = new IAMDatabase(IAMDatabase.GetWebConnectionString())) jData = WebPageAPI.ExecuteLocal(database, this, rData); if (String.IsNullOrWhiteSpace(jData)) { throw new Exception(""); } BooleanResult mRetCL = JSON.Deserialize <BooleanResult>(jData); if (mRetCL == null) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("context_not_found"), 3000, true); } else if (mRetCL.error != null) { contentRet = new WebJsonResponse("", mRetCL.error.data, 3000, true); } else if (!mRetCL.result) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("context_not_found"), 3000, true); } else { contentRet = new WebJsonResponse(Session["ApplicationVirtualPath"] + "admin/context/" + (Request.Form["hashtag"] != null ? "#" + Request.Form["hashtag"].ToString() : "")); } break; case "add_context": case "change": Boolean change = false; if (action == "change") { change = true; } String contextName = Request.Form["add_context_name"]; if (String.IsNullOrEmpty(contextName)) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("type_context_name"), 3000, true); break; } String passwordRule = Request.Form["pwd_rule"]; if (String.IsNullOrEmpty(passwordRule)) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("type_pwd_rule"), 3000, true); break; } String pwd_length = Request.Form["pwd_length"]; if (String.IsNullOrEmpty(pwd_length)) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("pwd_len_size"), 3000, true); break; } try { Int32 tmp = Int32.Parse(Request.Form["pwd_length"]); if ((tmp < 4) || (tmp > 20)) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("pwd_len_size"), 3000, true); break; } } catch { contentRet = new WebJsonResponse("", MessageResource.GetMessage("pwd_len_size"), 3000, true); break; } if (!change) { var reqAddR = new { jsonrpc = "1.0", method = "context.new", parameters = new { name = contextName, parentid = 0, password_rule = passwordRule, password_length = pwd_length, password_upper_case = (!String.IsNullOrEmpty(Request.Form["pwd_upper_case"]) ? true : false), password_lower_case = (!String.IsNullOrEmpty(Request.Form["pwd_lower_case"]) ? true : false), password_digit = (!String.IsNullOrEmpty(Request.Form["pwd_digit"]) ? true : false), password_symbol = (!String.IsNullOrEmpty(Request.Form["pwd_symbol"]) ? true : false), password_no_name = (!String.IsNullOrEmpty(Request.Form["pwd_no_name"]) ? true : false) }, id = 1 }; rData = JSON.Serialize2(reqAddR); } else { var reqAddR = new { jsonrpc = "1.0", method = "context.change", parameters = new { contextid = contextId, name = contextName, parentid = 0, password_rule = passwordRule, password_length = pwd_length, password_upper_case = (!String.IsNullOrEmpty(Request.Form["pwd_upper_case"]) ? true : false), password_lower_case = (!String.IsNullOrEmpty(Request.Form["pwd_lower_case"]) ? true : false), password_digit = (!String.IsNullOrEmpty(Request.Form["pwd_digit"]) ? true : false), password_symbol = (!String.IsNullOrEmpty(Request.Form["pwd_symbol"]) ? true : false), password_no_name = (!String.IsNullOrEmpty(Request.Form["pwd_no_name"]) ? true : false) }, 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(""); } ContextGetResult retAddR = JSON.Deserialize <ContextGetResult>(jData); if (retAddR == null) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("context_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("context_not_found"), 3000, true); } else { contentRet = new WebJsonResponse(Session["ApplicationVirtualPath"] + "admin/context/" + (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) { 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/container/" + (Request.Form["hashtag"] != null ? "#" + Request.Form["hashtag"].ToString() : "")); LMenu menu3 = new LMenu("Pastas", ApplicationVirtualPath + "admin/container/" + (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 containerId = 0; try { containerId = Int64.Parse((String)RouteData.Values["id"]); if (containerId < 0) { containerId = 0; } } catch { } String error = ""; ContainerGetResult selectedContainer = 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 ((containerId > 0) && (area.ToLower() != "search")) { try { rData = SafeTrend.Json.JSON.Serialize2(new { jsonrpc = "1.0", method = "container.get", parameters = new { containerid = containerId }, id = 1 }); jData = ""; using (IAMDatabase database = new IAMDatabase(IAMDatabase.GetWebConnectionString())) jData = WebPageAPI.ExecuteLocal(database, this, rData); if (String.IsNullOrWhiteSpace(jData)) { throw new Exception(""); } selectedContainer = JSON.Deserialize <ContainerGetResult>(jData); if (selectedContainer == null) { error = MessageResource.GetMessage("container_not_found"); //ret = new WebJsonResponse("", MessageResource.GetMessage("user_not_found"), 3000, true); } else if (selectedContainer.error != null) { error = selectedContainer.error.data; selectedContainer = null; } else if (selectedContainer.result == null || selectedContainer.result.info == null) { error = MessageResource.GetMessage("container_not_found"); selectedContainer = null; } else { menu3.Name = selectedContainer.result.info.name; } } catch (Exception ex) { error = MessageResource.GetMessage("api_error"); Tools.Tool.notifyException(ex, this); selectedContainer = 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>"; 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 pasta</h3>"; html += "<form id=\"form_add_role\" method=\"post\" action=\"" + ApplicationVirtualPath + "admin/container/action/add_container/\">"; 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\"\">"); String select = "<select id=\"container_context\" name=\"container_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); Func <String, Int64, Int64, String> chields = null; chields = new Func <String, long, long, string>(delegate(String padding, Int64 root, Int64 ctx) { String h = ""; foreach (ContainerData c in conteinerList) { if ((c.parent_id == root) && (c.context_id == ctx)) { h += "<option value=\"" + c.container_id + "\" " + (hashData.GetValue("container") == c.container_id.ToString() ? "selected" : "") + ">" + padding + " " + c.name + "</option>"; h += chields(padding + "---", c.container_id, ctx); } } return(h); }); select = "<select id=\"parent_container\" name=\"parent_container\" >"; foreach (ContextData ctx in contextList.result) { select += "<option value=\"0\">Raiz no contexto " + ctx.name + "</option>"; select += chields("|", 0, ctx.context_id); } select += "</select>"; html += String.Format(infoTemplate, "Pasta pai", select); 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/container/" + (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 (selectedContainer == 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/#container/{0}\">"; containerTemplate += " <div class=\"app-btn a-btn\"><span class=\"a-btn-inner\">Ver usuários</span></div>"; containerTemplate += " </a>"; containerTemplate += " </td>"; containerTemplate += " <td class=\"col2\">"; containerTemplate += " <div class=\"title\"><span class=\"name field-editor\" id=\"container_name_{0}\" data-id=\"{0}\" data-function=\"iamadmin.editTextField('#container_name_{0}',null,containerNameEdit);\">{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 += "containerNameEdit = 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 = "container.list", parameters = new { page_size = pageSize, page = page }, id = 1 }); } else { rData = SafeTrend.Json.JSON.Serialize2(new { jsonrpc = "1.0", method = "container.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(""); } ContainerListResult ret2 = JSON.Deserialize <ContainerListResult>(jData); if (ret2 == null) { eHtml += String.Format(errorTemplate, MessageResource.GetMessage("container_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("container_not_found")); hasNext = false; } else { foreach (ContainerData c in ret2.result) { String text = ""; if (c.path != null) { text += "<span>Path: " + c.path + "</span><br />"; } if (c.context_name != null) { text += "<span>Contexto: " + c.context_name + "</span>"; } String links = ""; links += "<a href=\"" + ApplicationVirtualPath + "admin/container/" + c.container_id + "/" + (Request.Form["hashtag"] != null ? "#" + Request.Form["hashtag"].ToString() : "") + "\"><div class=\"ico icon-change\">Editar</div></a>"; links += "<a href=\"" + ApplicationVirtualPath + "admin/container/" + c.container_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/container/" + c.container_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 '" + c.name + "'?\" ok=\"Excluir\" cancel=\"Cancelar\"><div class=\"ico icon-close\">Excluir usuários</div></a>"; links += (c.entity_qty > 0 ? "" : "<a class=\"confirm-action\" href=\"" + ApplicationVirtualPath + "admin/container/" + c.container_id + "/action/delete/" + (Request.Form["hashtag"] != null ? "#" + Request.Form["hashtag"].ToString() : "") + "\" confirm-title=\"Exclusão\" confirm-text=\"Deseja excluir definitivamente a pasta '" + c.name + "'?\" ok=\"Excluir\" cancel=\"Cancelar\"><div class=\"ico icon-close\">Apagar</div></a>"); html += String.Format(containerTemplate, c.container_id, c.name, c.entity_qty, (c.create_date > 0 ? "Criado em " + MessageResource.FormatDate(new DateTime(1970, 1, 1).AddSeconds(c.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 da pasta</h3>"; html += "<form id=\"form_add_role\" method=\"post\" action=\"" + ApplicationVirtualPath + "admin/container/" + selectedContainer.result.info.container_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=\"" + selectedContainer.result.info.name + "\">"); html += String.Format(infoTemplate, "Contexto", selectedContainer.result.info.context_name); Func <String, Int64, Int64, String> chields = null; chields = new Func <String, long, long, string>(delegate(String padding, Int64 root, Int64 ctx) { String h = ""; foreach (ContainerData c in conteinerList) { if ((c.parent_id == root) && (c.context_id == ctx)) { h += "<option value=\"" + c.container_id + "\" " + (selectedContainer.result.info.parent_id.ToString() == c.container_id.ToString() ? "selected" : "") + ">" + padding + " " + c.name + "</option>"; h += chields(padding + "---", c.container_id, ctx); } } return(h); }); String select = "<select id=\"parent_container\" name=\"parent_container\" >"; select += "<option value=\"0\">Raiz no contexto " + selectedContainer.result.info.context_name + "</option>"; select += chields("|", 0, selectedContainer.result.info.context_id); select += "</select>"; html += String.Format(infoTemplate, "Pasta pai", select); 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/container/" + (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/container/" + containerId + "/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/container/" + (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: '" + selectedContainer.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/container/new/" + (Request.Form["hashtag"] != null ? "#" + Request.Form["hashtag"].ToString() : "") + "'\">Nova pasta</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) { 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 = null; LMenu menu2 = null; LMenu menu3 = null; WebJsonResponse contentRet = null; HashData hashData = new HashData(this); String html = ""; String eHtml = ""; String js = null; String errorTemplate = "<span class=\"empty-results\">{0}</span>"; String infoTemplate = "<tr><td class=\"col1\">{0}</td><td class=\"col2\"><span class=\"no-edit\">{1}</span></td></tr>"; switch (area) { case "": case "content": if (newItem) { html += "<div id=\"upload-box\" class=\"upload-box\"><input type=\"file\" name=\"files[]\" multiple=\"\"><div class=\"drag-content\"><span class=\"upload-button-text\">Selecione arquivos para enviar</span><span class=\"upload-drag-drop-description\">Ou arraste e solte aqui</span></div><div class=\"dragDrop-content\"><span class=\"label l1\">Arraste a licença até aqui</span><span class=\"label l2\">Solte a licença</span></div></div>"; html += "<h3>Informações da licença</h3>"; html += "<form id=\"form_plugin_add\" method=\"POST\" action=\"" + ApplicationVirtualPath + "admin/license/action/add_new/\">"; html += "<div id=\"files\" class=\"box-container\"><div class=\"no-tabs pb10 none\">Nenhum upload realizado</div></div>"; html += "<button type=\"submit\" id=\"upload-save\" class=\"button secondary floatleft\">Aplicar licença</button> <a href=\"" + ApplicationVirtualPath + "admin/license/" + (Request.Form["hashtag"] != null ? "#" + Request.Form["hashtag"].ToString() : "") + "\" class=\"button link floatleft\">Cancelar</a></form>"; html += "</form>"; contentRet = new WebJsonResponse("#content-wrapper", (eHtml != "" ? eHtml : html)); contentRet.js = "iamadmin.licenseUploader($('#upload-box'), '" + ApplicationVirtualPath + "admin/license/action/upload/','" + ApplicationVirtualPath + "admin/license/action/upload_item_template/')"; } else { html += "<h3>" + MessageResource.GetMessage("licensing"); if (hashData.GetValue("edit") != "1") { html += "<div class=\"btn-box\"><div class=\"a-btn ico icon-change\" onclick=\"window.location='" + ApplicationVirtualPath + "admin/license/new/'\">Carregar nova licença</div></div>"; } html += "</h3>"; LicenseControl lic = null; using (IAMDatabase db = new IAMDatabase(IAMDatabase.GetWebConnectionString())) lic = LicenseChecker.GetLicenseData(db.Connection, null, enterpriseId); //Carrega o certificado licenciado if (lic != null) { html += "<div class=\"no-tabs fields\"><table><tbody>"; html += String.Format(infoTemplate, "Chave de instalação", lic.InstallationKey); html += String.Format(infoTemplate, "Status da licença", (lic.Valid ? "Válida" : lic.Error)); html += "</tbody></table><div class=\"clear-block\"></div></div>"; } else { eHtml += String.Format(errorTemplate, "Falha ao carregar a licença"); } contentRet = new WebJsonResponse("#content-wrapper", (eHtml != "" ? eHtml : html)); } 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>"; } DbParameterCollection par = new DbParameterCollection();; par.Add("@enterpriseId", typeof(Int64)).Value = enterpriseId; using (IAMDatabase db = new IAMDatabase(IAMDatabase.GetWebConnectionString())) { DataTable dtUsers = db.ExecuteDataTable("sp_user_statistics", System.Data.CommandType.StoredProcedure, par); if ((dtUsers != null) && (dtUsers.Rows.Count > 0)) { Int64 total = (Int64)dtUsers.Rows[0]["total"]; Int64 locked = (Int64)dtUsers.Rows[0]["locked"]; Int64 logged = (Int64)dtUsers.Rows[0]["logged"]; Int32 pLocked = 0; Int32 pLogged = 0; try { pLocked = (Int32)(((Double)locked / (Double)total) * 100F); } catch { } try { pLogged = (Int32)(((Double)logged / (Double)total) * 100F); } catch { } html += "<div class=\"ds1\">"; html += "<div class=\"center\">" + MessageResource.GetMessage("entity") + "</div>"; html += "<div class=\"center\"><span class=\"big\">" + total + "</span><span class=\"small\"> " + MessageResource.GetMessage("total") + "</span></div>"; html += "<div class=\"center\"><canvas id=\"usrLockChart\" width=\"30\" height=\"30\"></canvas><span class=\"big txt1\">" + locked + "<span> <span class=\"small\">" + MessageResource.GetMessage("locked") + "<span></div>"; html += "<div class=\"center\"><canvas id=\"usrLoggedChart\" width=\"30\" height=\"30\"></canvas><span class=\"big txt1\">" + logged + "<span> <span class=\"small\">" + MessageResource.GetMessage("logged") + "<span></div>"; //html += "<div class=\"center\"><canvas id=\"usrTotalChart\" width=\"30\" height=\"30\"></canvas><span class=\"big txt1\">" + total + "<span> <span class=\"small\">Total<span></div>"; html += "</div>"; //js += "iamadmin.buildPercentChart('#usrTotalChart',100,{color:'#2d88b4',showText:false});"; js += "iamadmin.buildPercentChart('#usrLockChart'," + pLocked + ",{color:'#f5663a',showText:false});"; js += "iamadmin.buildPercentChart('#usrLoggedChart'," + pLogged + ",{color:'#76c558',showText:false});"; } html += "<div class=\"ds2\">"; html += "<div class=\"center\">" + MessageResource.GetMessage("licensing") + "</div>"; try { String rData = ""; String query = ""; if (!String.IsNullOrWhiteSpace((String)RouteData.Values["query"])) { query = (String)RouteData.Values["query"]; } var tmpReq = new { jsonrpc = "1.0", method = "license.info", parameters = new String[0], id = 1 }; rData = SafeTrend.Json.JSON.Serialize2(tmpReq); String jData = ""; try { jData = WebPageAPI.ExecuteLocal(db, this, rData); } finally { } if (String.IsNullOrWhiteSpace(jData)) { throw new Exception(""); } License ret2 = JSON.Deserialize <License>(jData); if (ret2 == null) { eHtml += String.Format(errorTemplate, MessageResource.GetMessage("api_error")); } else if (ret2.error != null) { eHtml += String.Format(errorTemplate, ret2.error.data); } else if (ret2.result == null) { eHtml += String.Format(errorTemplate, MessageResource.GetMessage("api_error")); } else { Int32 percent = 0; if (ret2.result.hasLicense) { if (ret2.result.available == 0) //Licença ilimitada { percent = 0; } else if (ret2.result.used > ret2.result.available) { percent = 100; } else { percent = (ret2.result.used / ret2.result.available) * 100; } } else { percent = 100; } String color = "#76c558"; if (percent < 70) { color = "#76c558"; } else if (percent < 85) { color = "#f5663a"; } else { color = "rgb(202, 52, 56)"; } js += "iamadmin.buildPercentChart('#licChart'," + percent + ",{color:'" + color + "',showText:true});"; html += "<canvas id=\"licChart\" width=\"100\" height=\"100\" class=\"big-center\"></canvas>"; if (ret2.result.hasLicense) { html += "<div class=\"center\">" + MessageResource.GetMessage("licensing_total") + "</div>"; html += "<div class=\"center\"><span class=\"big\">" + ret2.result.used + "</span><span class=\"small\"> " + MessageResource.GetMessage("of") + " " + (ret2.result.available == 0 ? MessageResource.GetMessage("unlimited") : ret2.result.available.ToString()) + "</span></div>"; } else { html += "<div class=\"center\"><span class=\"big\">" + MessageResource.GetMessage("no_licecse") + "</span></div>"; } } } catch (Exception ex) { eHtml += String.Format(errorTemplate, MessageResource.GetMessage("api_error")); //ret = new WebJsonResponse("", MessageResource.GetMessage("api_error"), 3000, true); } 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"]; } String ApplicationVirtualPath = Session["ApplicationVirtualPath"].ToString(); LMenu menu1 = new LMenu("Dashboard", ApplicationVirtualPath + "admin/"); LMenu menu2 = new LMenu("Logs", ApplicationVirtualPath + "admin/logs/"); LMenu menu3 = new LMenu("Logs de sistema", ApplicationVirtualPath + "admin/logs/"); WebJsonResponse contentRet = null; String html = ""; String eHtml = ""; HashData hashData = new HashData(this); String errorTemplate = "<span class=\"empty-results\">{0}</span>"; //Verifica se está selecionado o usuário Int64 userId = 0; try { userId = Int64.Parse((String)RouteData.Values["id"]); if (userId < 0) { userId = 0; } } catch { } switch (area) { case "": case "search": case "content": 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 class=\"sorter\"><thead>"; html += " <tr>"; html += " <th class=\"w50 tHide mHide {sorter: false}\"></th>"; html += " <th class=\"pointer w150 tHide mHide header headerSortDown\" data-column=\"date\">Data <div class=\"icomoon\"></div></th>"; html += " <th class=\"pointer w80 tHide mHide header\" data-column=\"source\">Fonte <div class=\"icomoon\"></div></th>"; html += " <th class=\"pointer w100 tHide mHide header\" data-column=\"resource\">Recurso <div class=\"icomoon\"></div></th>"; html += " <th class=\"{sorter: false} header\" data-column=\"text\">Texto <div class=\"icomoon\"></div></th>"; html += " </tr>"; html += "</thead>"; html += "<tbody>"; } String trTemplate = " <tr class=\"system-log\" data-uri=\"/admin/logs/{0}/content/modal/\" data-title=\"{5}\" onclick=\"iamadmin.openLog(this);\">"; trTemplate += " <td class=\"select tHide mHide\"><div class=\"level-icon level-{1}\"></div></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=\"ident10\">{5}</td>"; trTemplate += " </tr>"; String query = ""; try { String rData = ""; if (!String.IsNullOrWhiteSpace((String)RouteData.Values["query"])) { query = (String)RouteData.Values["query"]; } if (String.IsNullOrWhiteSpace(query)) { var tmpReq = new { jsonrpc = "1.0", method = "logs.list", parameters = new { page_size = pageSize, page = page, filter = new { source = hashData.GetValue("source") } }, id = 1 }; rData = SafeTrend.Json.JSON.Serialize2(tmpReq); } else { var tmpReq = new { jsonrpc = "1.0", method = "logs.search", parameters = new { text = query, page_size = pageSize, page = page, filter = new { source = hashData.GetValue("source") } }, 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(""); } SystemLogs ret2 = JSON.Deserialize <SystemLogs>(jData); if (ret2 == null) { eHtml += String.Format(errorTemplate, MessageResource.GetMessage("log_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) { eHtml += String.Format(errorTemplate, MessageResource.GetMessage("log_not_found")); hasNext = false; } else { foreach (LogItem l in ret2.result) { html += String.Format(trTemplate, l.log_id, l.level.ToString().ToLower(), ((DateTime) new DateTime(1970, 1, 1)).AddSeconds(l.date).ToString("yyyy-MM-dd HH:mm:ss"), l.source, l.resource_name, l.text); } 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 system-logs-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.systemLogLoader');"; if (hasNext) { contentRet.js += "$( document ).bind( 'end_of_scroll.systemLogLoader', function() { $( document ).unbind('end_of_scroll.systemLogLoader'); $('.system-logs-loader').removeClass('hide'); iamadmin.getPageContent2( { page: " + ++page + ", search:'" + (!String.IsNullOrWhiteSpace(query) ? query : "") + "' }, function(){ $('.system-logs-loader').addClass('hide'); } ); });"; } break; case "modal": String logId = ""; try { logId = (String)RouteData.Values["id"]; } catch { } try { var tmpReq = new { jsonrpc = "1.0", method = "logs.get", parameters = new { logid = logId }, 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(""); } LogData retLog = JSON.Deserialize <LogData>(jData); if (retLog == null) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("log_not_found"), 3000, true); } else if (retLog.error != null) { contentRet = new WebJsonResponse("", retLog.error.data, 3000, true); } else if (retLog.result == null || retLog.result.log_id == null) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("log_not_found"), 3000, true); } else { html = "<div class=\"log-info\">"; html += "<div class=\"item\">Data:</div>"; html += "<div class=\"description\">" + MessageResource.FormatDate(((DateTime) new DateTime(1970, 1, 1)).AddSeconds(retLog.result.date), false) + "</div>"; html += "<div class=\"item\">Fonte:</div>"; html += "<div class=\"description\">" + retLog.result.source + "</div>"; if (!String.IsNullOrEmpty(retLog.result.resource_name)) { html += "<div class=\"item\">Recurso:</div>"; html += "<div class=\"description\">" + retLog.result.resource_name + "</div>"; } if (!String.IsNullOrEmpty(retLog.result.plugin_name)) { html += "<div class=\"item\">Plugin:</div>"; html += "<div class=\"description\">" + retLog.result.plugin_name + "</div>"; } html += "<div class=\"item\">Executado por:</div>"; html += "<div class=\"description\">" + retLog.result.executed_by_name + "</div>"; html += "<div class=\"item\">Texto:</div>"; html += "<div class=\"description\">" + retLog.result.text + "</div>"; html += "<div class=\"item\">Informações adicionais:</div>"; html += "<div class=\"description\">"; //verifica se é um dado Json para fazer o parse try { html += JSON.Dump(retLog.result.additional_data, true); } catch { html += HttpUtility.HtmlEncode(retLog.result.additional_data); } html += "</div>"; html += "</div>"; contentRet = new WebJsonResponse("#modal-box .alert-box-content", html); } } catch (Exception ex) { Tools.Tool.notifyException(ex, this); contentRet = new WebJsonResponse("", MessageResource.GetMessage("api_error"), 3000, true); } 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", html); break; case "mobilebar": break; case "buttonbox": html += "<select id=\"filter_source\" name=\"filter_source\" ><option value=\"\">Todas as origens</option>"; html += "<option value=\"source/adminapi\" " + (hashData.GetValue("source") == "adminapi" ? "selected" : "") + ">adminapi</option>"; html += "<option value=\"source/api\" " + (hashData.GetValue("source") == "api" ? "selected" : "") + ">api</option>"; html += "<option value=\"source/autoservice\" " + (hashData.GetValue("source") == "autoservice" ? "selected" : "") + ">autoservice</option>"; html += "<option value=\"source/cas\" " + (hashData.GetValue("source") == "cas" ? "selected" : "") + ">cas</option>"; html += "<option value=\"source/deploy\" " + (hashData.GetValue("source") == "deploy" ? "selected" : "") + ">deploy</option>"; html += "<option value=\"source/engine\" " + (hashData.GetValue("source") == "engine" ? "selected" : "") + ">engine</option>"; html += "<option value=\"source/inbound\" " + (hashData.GetValue("source") == "inbound" ? "selected" : "") + ">inbound</option>"; html += "<option value=\"source/proxy\" " + (hashData.GetValue("source") == "proxy" ? "selected" : "") + ">proxy</option>"; html += "<option value=\"source/proxyapi\" " + (hashData.GetValue("source") == "proxyapi" ? "selected" : "") + ">proxyapi</option>"; html += "</select>"; contentRet = new WebJsonResponse("#btnbox", html); contentRet.js = "$('#filter_source').change(function() { iamadmin.changeHash( $( this ).val() ); });"; 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 filterId = 0; if (action != "add_filter") { try { filterId = Int64.Parse((String)RouteData.Values["id"]); if (filterId < 0) { filterId = 0; } } catch { } if (filterId == 0) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("filter_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 = "filter.delete", parameters = new { filterid = filterId }, 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("filter_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("filter_not_found"), 3000, true); } else { contentRet = new WebJsonResponse(); } break; case "add_filter": contentRet = null; FilterRule newItem = GetFilterByForm(out contentRet); if ((contentRet != null) || (newItem == null)) { break; } rData = JSON.Serialize2(new { jsonrpc = "1.0", method = "filter.new", parameters = newItem.ToJsonObject(), id = 1 }); using (IAMDatabase database = new IAMDatabase(IAMDatabase.GetWebConnectionString())) jData = WebPageAPI.ExecuteLocal(database, this, rData); if (String.IsNullOrWhiteSpace(jData)) { throw new Exception(""); } FilterGetResult retN = JSON.Deserialize <FilterGetResult>(jData); if (retN == null) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("filter_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("filter_not_found"), 3000, true); } else if (retN.result == null || retN.result.info == null) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("filter_not_found"), 3000, true); } else { contentRet = new WebJsonResponse(Session["ApplicationVirtualPath"] + "admin/filter/" + retN.result.info.filter_id + "/"); } break; case "change": contentRet = null; FilterRule newItem1 = GetFilterByForm(out contentRet); if ((contentRet != null) || (newItem1 == null)) { break; } Dictionary <String, Object> par = newItem1.ToJsonObject(); par.Add("filterid", filterId); rData = JSON.Serialize2(new { jsonrpc = "1.0", method = "filter.change", parameters = par, id = 1 }); using (IAMDatabase database = new IAMDatabase(IAMDatabase.GetWebConnectionString())) jData = WebPageAPI.ExecuteLocal(database, this, rData); if (String.IsNullOrWhiteSpace(jData)) { throw new Exception(""); } FilterGetResult retC = JSON.Deserialize <FilterGetResult>(jData); if (retC == null) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("filter_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("filter_not_found"), 3000, true); } else if (retC.result == null || retC.result.info == null) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("filter_not_found"), 3000, true); } else { contentRet = new WebJsonResponse("", MessageResource.GetMessage("info_saved"), 3000, false); contentRet.redirectURL = Session["ApplicationVirtualPath"] + "admin/filter/" + retC.result.info.filter_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 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 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 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) { 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) { 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) { 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) { 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 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 contentRet = null; String action = ""; if (!String.IsNullOrWhiteSpace((String)RouteData.Values["action"])) { action = (String)RouteData.Values["action"]; } LoginData login = LoginUser.LogedUser(this.Page); Int64 requestId = 0; if (action != "add_request") { try { requestId = Int64.Parse((String)RouteData.Values["id"]); if (requestId < 0) { requestId = 0; } } catch { } if (requestId == 0) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("workflow_request_not_found"), 3000, true); action = ""; } } String rData = ""; //SqlConnection //conn = DB.GetConnection(); String jData = ""; try { switch (action) { case "add_request": String workflow_id = Request.Form["workflow"]; if (String.IsNullOrEmpty(workflow_id)) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("select_workflow"), 3000, true); break; } String description = Request.Form["description"]; if (String.IsNullOrEmpty(description)) { contentRet = new WebJsonResponse("", MessageResource.GetMessage("type_description"), 3000, true); break; } rData = JSON.Serialize2(new { jsonrpc = "1.0", method = "user.accessrequest", parameters = new { workflowid = workflow_id, userid = login.Id, description = description }, id = 1 }); using (IAMDatabase database = new IAMDatabase(IAMDatabase.GetWebConnectionString())) jData = WebPageAPI.ExecuteLocal(database, this, rData); if (String.IsNullOrWhiteSpace(jData)) { throw new Exception(""); } BooleanResult retAddR = JSON.Deserialize <BooleanResult>(jData); if (retAddR == null) { contentRet = new WebJsonResponse("", "Undefined erro on insert new request", 3000, true); } else if (retAddR.error != null) { contentRet = new WebJsonResponse("", retAddR.error.data, 3000, true); } else if (!retAddR.result) { contentRet = new WebJsonResponse("", "Undefined erro on insert new request", 3000, true); } else { contentRet = new WebJsonResponse(Session["ApplicationVirtualPath"] + "autoservice/access_request/"); } // 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())); } }