|
|
@@ -0,0 +1,389 @@
|
|
|
1
|
+using System;
|
|
|
2
|
+using System.Collections.Generic;
|
|
|
3
|
+using System.Data;
|
|
|
4
|
+using System.Linq;
|
|
|
5
|
+using System.Text;
|
|
|
6
|
+using System.Web;
|
|
|
7
|
+using System.Web.Mvc;
|
|
|
8
|
+using CallCenter.Utility;
|
|
|
9
|
+using CallCenterApi.Common;
|
|
|
10
|
+using CallCenterApi.DB;
|
|
|
11
|
+using CallCenterApi.Interface.Controllers.Login;
|
|
|
12
|
+
|
|
|
13
|
+namespace CallCenterApi.Interface.App_Start
|
|
|
14
|
+{
|
|
|
15
|
+ public class SqlErrorAttribute : ActionFilterAttribute
|
|
|
16
|
+ {
|
|
|
17
|
+
|
|
|
18
|
+
|
|
|
19
|
+ //sql注入式攻击检查
|
|
|
20
|
+
|
|
|
21
|
+ public override void OnActionExecuting(ActionExecutingContext filterContext)
|
|
|
22
|
+ {
|
|
|
23
|
+ if (filterContext.HttpContext.Request.CurrentExecutionFilePath.Contains("CallOpt"))
|
|
|
24
|
+ {
|
|
|
25
|
+
|
|
|
26
|
+ }
|
|
|
27
|
+ else
|
|
|
28
|
+ {
|
|
|
29
|
+
|
|
|
30
|
+ if (filterContext.HttpContext.Request.CurrentExecutionFilePath.Contains("GetList"))
|
|
|
31
|
+ {
|
|
|
32
|
+ int qw = 0;
|
|
|
33
|
+ }
|
|
|
34
|
+ //当前角色导航判断
|
|
|
35
|
+ var token1 = filterContext.HttpContext.Request["token"];
|
|
|
36
|
+ if (token1 != null)
|
|
|
37
|
+ {
|
|
|
38
|
+ var userDatastr = RedisHelper.StringGet(token1);
|
|
|
39
|
+ if (userDatastr != null)
|
|
|
40
|
+ {
|
|
|
41
|
+ Dictionary<string, string> userData = new Dictionary<string, string>();
|
|
|
42
|
+ userData = userDatastr.ToString().ToObject<Dictionary<string, string>>();
|
|
|
43
|
+ var roleId = Utils.StrToInt(userData["F_RoleID"], 0);
|
|
|
44
|
+ var F_UserID = Utils.StrToInt(userData["F_UserID"], 0);
|
|
|
45
|
+ int qq = geturl(roleId.ToString(), F_UserID);
|
|
|
46
|
+ if (qq > 0)
|
|
|
47
|
+ {
|
|
|
48
|
+ //报错无权限
|
|
|
49
|
+ throw new Exception("操作失败:无权限!");
|
|
|
50
|
+
|
|
|
51
|
+ }
|
|
|
52
|
+ }
|
|
|
53
|
+ }
|
|
|
54
|
+ IList<string> tname = new List<string>();
|
|
|
55
|
+ if (filterContext.HttpContext.Request.Form.Keys.Count > 0)
|
|
|
56
|
+ {
|
|
|
57
|
+ for (int q = 0; q < filterContext.HttpContext.Request.Form.Keys.Count; q++)
|
|
|
58
|
+ {
|
|
|
59
|
+ var tid = filterContext.HttpContext.Request.Form.Keys[q];
|
|
|
60
|
+ if (!tname.Contains(tid))
|
|
|
61
|
+ {
|
|
|
62
|
+ tname.Add(tid);
|
|
|
63
|
+ }
|
|
|
64
|
+ }
|
|
|
65
|
+ }
|
|
|
66
|
+ if (filterContext.HttpContext.Request.QueryString.Count > 0)
|
|
|
67
|
+ {
|
|
|
68
|
+ for (int q = 0; q < filterContext.HttpContext.Request.QueryString.Count; q++)
|
|
|
69
|
+ {
|
|
|
70
|
+ var tid = filterContext.HttpContext.Request.QueryString.AllKeys[q];
|
|
|
71
|
+ if (!tname.Contains(tid))
|
|
|
72
|
+ {
|
|
|
73
|
+ tname.Add(tid);
|
|
|
74
|
+ }
|
|
|
75
|
+
|
|
|
76
|
+ }
|
|
|
77
|
+ }
|
|
|
78
|
+ var actionParameters = filterContext.ActionDescriptor.GetParameters();
|
|
|
79
|
+ var otherController = DependencyResolver.Current.GetService<AES256Controller>();
|
|
|
80
|
+ string urls = filterContext.ActionDescriptor.ActionName;
|
|
|
81
|
+ if (urls != null
|
|
|
82
|
+ && (filterContext.HttpContext.Request.QueryString.Count > 0
|
|
|
83
|
+ || filterContext.HttpContext.Request.Form.Keys.Count > 0))
|
|
|
84
|
+ {
|
|
|
85
|
+ if (filterContext.HttpContext.Request.Form.Keys.Count > 0)
|
|
|
86
|
+ {//post
|
|
|
87
|
+ //遍历字典
|
|
|
88
|
+ //foreach (KeyValuePair<string, object> kvp in filterContext.ActionParameters)
|
|
|
89
|
+ //{
|
|
|
90
|
+ //取值,赋值
|
|
|
91
|
+ //var key = kvp.Key;
|
|
|
92
|
+
|
|
|
93
|
+ ////var tt= filterContext.ActionParameters[key].GetType();
|
|
|
94
|
+ ////var tt2 = filterContext.ActionParameters[key];
|
|
|
95
|
+ ////var t1 = filterContext.ActionParameters.Keys.Count;
|
|
|
96
|
+ ////var t2 = filterContext.ActionParameters.Values.Count;
|
|
|
97
|
+ //object o = filterContext.ActionParameters;
|
|
|
98
|
+ //PropertyDescriptorCollection PropertyList = System.ComponentModel.TypeDescriptor.GetProperties(o);
|
|
|
99
|
+ //Type t = o.GetType();
|
|
|
100
|
+ //PropertyInfo[] pList = t.GetProperties();
|
|
|
101
|
+ //foreach (PropertyInfo item in pList)
|
|
|
102
|
+ //{
|
|
|
103
|
+ // string name = item.Name;
|
|
|
104
|
+ //object value = item.GetValue(o, null);
|
|
|
105
|
+
|
|
|
106
|
+ //if (name == "Values")
|
|
|
107
|
+ //{
|
|
|
108
|
+ for (int w = 0; w < tname.Count; w++)
|
|
|
109
|
+ {
|
|
|
110
|
+ //时间去掉 tname[w]
|
|
|
111
|
+ string v1 = tname[w].ToString();
|
|
|
112
|
+ //&& v1 != "cont"
|
|
|
113
|
+ //编辑器编辑内容排除
|
|
|
114
|
+ if (v1 != "con" && v1 != "cont")
|
|
|
115
|
+ {
|
|
|
116
|
+
|
|
|
117
|
+
|
|
|
118
|
+ var v = filterContext.HttpContext.Request.Form[tname[w]];
|
|
|
119
|
+
|
|
|
120
|
+ FilterSql(v);
|
|
|
121
|
+ }
|
|
|
122
|
+
|
|
|
123
|
+ }
|
|
|
124
|
+
|
|
|
125
|
+ // }
|
|
|
126
|
+
|
|
|
127
|
+ // }
|
|
|
128
|
+
|
|
|
129
|
+ //}
|
|
|
130
|
+ }
|
|
|
131
|
+ else if (filterContext.HttpContext.Request.QueryString.Count > 0)
|
|
|
132
|
+ {//get
|
|
|
133
|
+ for (int w = 0; w < tname.Count; w++)
|
|
|
134
|
+ {
|
|
|
135
|
+ var v = filterContext.HttpContext.Request.QueryString[tname[w]];
|
|
|
136
|
+ FilterSql(v);
|
|
|
137
|
+ }
|
|
|
138
|
+
|
|
|
139
|
+ }
|
|
|
140
|
+
|
|
|
141
|
+ }
|
|
|
142
|
+ }
|
|
|
143
|
+ }
|
|
|
144
|
+
|
|
|
145
|
+
|
|
|
146
|
+
|
|
|
147
|
+ public static void FilterSql(string s)
|
|
|
148
|
+ {
|
|
|
149
|
+ // if (string.IsNullOrEmpty(s)) return string.Empty;
|
|
|
150
|
+ s = s.Trim().ToLower();
|
|
|
151
|
+ string s1 = "";
|
|
|
152
|
+ int i = 0;
|
|
|
153
|
+ string message = "操作失败!!!异常提醒:符号";
|
|
|
154
|
+ if (s.Contains("=")) { i++; message += (s1 + "=,"); };
|
|
|
155
|
+ if (s.Contains("'")) { i++; message += (s1 + "',"); };
|
|
|
156
|
+ if (s.Contains(";")) { i++; message += (s1 + ";,"); };
|
|
|
157
|
+ if (s.Contains(" or ")) { i++; message += (s1 + " or ,"); };
|
|
|
158
|
+ if (s.Contains("select")) { i++; message += (s1 + "select,"); };
|
|
|
159
|
+ if (s.Contains("update")) { i++; message += (s1 + "update,"); };
|
|
|
160
|
+ if (s.Contains("insert")) { i++; message += (s1 + "insert,"); };
|
|
|
161
|
+ if (s.Contains("delete")) { i++; message += (s1 + "delete,"); };
|
|
|
162
|
+ if (s.Contains("declare")) { i++; message += (s1 + "declare,"); };
|
|
|
163
|
+ if (s.Contains("exec")) { i++; message += (s1 + "exec,"); };
|
|
|
164
|
+ if (s.Contains("drop")) { i++; message += (s1 + "drop,"); };
|
|
|
165
|
+ if (s.Contains("create")) { i++; message += (s1 + "create,"); };
|
|
|
166
|
+ if (s.Contains("%")) { i++; message += (s1 + "%,"); };
|
|
|
167
|
+ if (s.Contains("--")) { i++; message += (s1 + "--,"); };
|
|
|
168
|
+ if (s.Contains("_")) { i++; message += (s1 + "_,"); };
|
|
|
169
|
+ if (s.Contains("convert")) { i++; message += (s1 + "convert,"); };
|
|
|
170
|
+ if (s.Contains("@version")) { i++; message += (s1 + "@version,"); };
|
|
|
171
|
+ if (i > 0)
|
|
|
172
|
+ {
|
|
|
173
|
+ throw new Exception(message);
|
|
|
174
|
+ }
|
|
|
175
|
+
|
|
|
176
|
+
|
|
|
177
|
+ }
|
|
|
178
|
+
|
|
|
179
|
+
|
|
|
180
|
+ /// <summary>
|
|
|
181
|
+ /// 导航权限判断
|
|
|
182
|
+ /// </summary>
|
|
|
183
|
+ /// <param name="url">当前进入导航</param>
|
|
|
184
|
+ /// <param name="roleId">当前登陆人角色id </param>
|
|
|
185
|
+ /// <param name="userId">当前登陆人id </param>
|
|
|
186
|
+ /// <returns></returns>
|
|
|
187
|
+ public static int geturl(string roleId, int userId)
|
|
|
188
|
+ {
|
|
|
189
|
+ int a = 0;
|
|
|
190
|
+ int b = 0;
|
|
|
191
|
+ //1:检测用户是否禁用
|
|
|
192
|
+ var u = new BLL.T_Sys_UserAccount().GetModel(userId);
|
|
|
193
|
+ //1-禁用 0-启用
|
|
|
194
|
+ if (u == null)
|
|
|
195
|
+ {
|
|
|
196
|
+ a = 1;
|
|
|
197
|
+ }
|
|
|
198
|
+ else if (u.F_DeleteFlag == 1)
|
|
|
199
|
+ {
|
|
|
200
|
+ a = 1;
|
|
|
201
|
+ }
|
|
|
202
|
+ #region MyRegion
|
|
|
203
|
+ // return ds;
|
|
|
204
|
+
|
|
|
205
|
+
|
|
|
206
|
+
|
|
|
207
|
+
|
|
|
208
|
+ // string url1 = HttpContext.Current.Request.Url.AbsolutePath;
|
|
|
209
|
+ // string url2 = HttpContext.Current.Request.Path;
|
|
|
210
|
+
|
|
|
211
|
+ // DataSet dt = new DataSet();
|
|
|
212
|
+ // Dictionary<String, String> para = new Dictionary<string, String>();
|
|
|
213
|
+
|
|
|
214
|
+
|
|
|
215
|
+ // String sql = @" select f.F_OptUrl
|
|
|
216
|
+ //from dbo.T_Sys_RoleFunction rf
|
|
|
217
|
+ //left join T_Sys_Function f on rf.F_FunctionId=f.F_FunctionId
|
|
|
218
|
+ //where F_RoleId=@RoleId group by f.F_OptUrl ";
|
|
|
219
|
+ // para.Add("@RoleId", roleId);
|
|
|
220
|
+ // dt = DbHelperSQL.Query(sql, para);
|
|
|
221
|
+
|
|
|
222
|
+ // if (dt.Tables.Count > 0)
|
|
|
223
|
+ // {
|
|
|
224
|
+ // for (int i = 0; i < dt.Tables.Count; i++)
|
|
|
225
|
+ // {
|
|
|
226
|
+ // DataTable t = dt.Tables[i];
|
|
|
227
|
+ // string t1=t.Columns[i].ToString();
|
|
|
228
|
+
|
|
|
229
|
+
|
|
|
230
|
+
|
|
|
231
|
+
|
|
|
232
|
+ // //if (url==t.) { }
|
|
|
233
|
+ // }
|
|
|
234
|
+ // }
|
|
|
235
|
+ #endregion
|
|
|
236
|
+
|
|
|
237
|
+ return a;
|
|
|
238
|
+
|
|
|
239
|
+ }
|
|
|
240
|
+
|
|
|
241
|
+
|
|
|
242
|
+
|
|
|
243
|
+ //根据接口找Id 找到 则判断 导航权限
|
|
|
244
|
+ public static int getItemBYUrl(string url, int roleId)
|
|
|
245
|
+ {
|
|
|
246
|
+ int a = 0;
|
|
|
247
|
+ StringBuilder strSql = new StringBuilder();
|
|
|
248
|
+ strSql.Append(@" select F_RoleId
|
|
|
249
|
+from dbo.T_Sys_RoleFunction f left join T_Sys_RoleUrl t
|
|
|
250
|
+on t.F_FunctionId=f.F_FunctionId
|
|
|
251
|
+ ");
|
|
|
252
|
+ strSql.Append(" where [F_UrlInfo] ='" + url + "'");
|
|
|
253
|
+ strSql.Append(" group by F_RoleId");
|
|
|
254
|
+ var ds = DbHelperSQL.Query(strSql.ToString());
|
|
|
255
|
+ DataTable dt = new DataTable();
|
|
|
256
|
+
|
|
|
257
|
+ dt = ds.Tables[0];
|
|
|
258
|
+
|
|
|
259
|
+ if (dt.Rows.Count > 0)
|
|
|
260
|
+ {
|
|
|
261
|
+
|
|
|
262
|
+ for (int i = 0; i < dt.Rows.Count; i++)
|
|
|
263
|
+ {
|
|
|
264
|
+ //列
|
|
|
265
|
+ for (int j = 0; j < dt.Columns.Count; j++)
|
|
|
266
|
+ {
|
|
|
267
|
+ if (dt.Rows[i][j] != null && dt.Rows[i][j].ToString() != "")
|
|
|
268
|
+ {
|
|
|
269
|
+ if (roleId == Convert.ToInt32(dt.Rows[i][j]))
|
|
|
270
|
+ {
|
|
|
271
|
+ a++;
|
|
|
272
|
+ }
|
|
|
273
|
+ }
|
|
|
274
|
+ }
|
|
|
275
|
+ }
|
|
|
276
|
+ }
|
|
|
277
|
+ else
|
|
|
278
|
+ {
|
|
|
279
|
+ a = 1;
|
|
|
280
|
+ }
|
|
|
281
|
+
|
|
|
282
|
+
|
|
|
283
|
+
|
|
|
284
|
+ return a;
|
|
|
285
|
+
|
|
|
286
|
+
|
|
|
287
|
+ }
|
|
|
288
|
+
|
|
|
289
|
+
|
|
|
290
|
+
|
|
|
291
|
+
|
|
|
292
|
+ /// <summary>
|
|
|
293
|
+ /// 检测接口方法权限
|
|
|
294
|
+ /// </summary>
|
|
|
295
|
+ /// <param name="FuntionId">导航id </param>
|
|
|
296
|
+ /// <param name="url">当前接口导航</param>
|
|
|
297
|
+ public static int getItemUrl(int FuntionId, string url, int roleId)
|
|
|
298
|
+ {
|
|
|
299
|
+ if (FuntionId == 19)
|
|
|
300
|
+ {
|
|
|
301
|
+ int qw = 1;
|
|
|
302
|
+ }
|
|
|
303
|
+ int a = 0;
|
|
|
304
|
+ int b = 0;
|
|
|
305
|
+ StringBuilder strSql = new StringBuilder();
|
|
|
306
|
+ strSql.Append(@" select [F_UrlInfo]
|
|
|
307
|
+from T_Sys_RoleUrl t left join dbo.T_Sys_RoleFunction f
|
|
|
308
|
+on t.F_FunctionId=f.F_FunctionId
|
|
|
309
|
+ ");
|
|
|
310
|
+ strSql.Append(" where f.F_FunctionId=" + FuntionId);
|
|
|
311
|
+ string str = " and F_RoleId=" + roleId;
|
|
|
312
|
+ //strSql.Append(" group by f.F_OptUrl ,f.F_FunctionId");
|
|
|
313
|
+
|
|
|
314
|
+ var ds = DbHelperSQL.Query(strSql.ToString() + str);
|
|
|
315
|
+ var ds2 = DbHelperSQL.Query(strSql.ToString());
|
|
|
316
|
+ DataTable dt = new DataTable();
|
|
|
317
|
+ DataTable dt2 = new DataTable();
|
|
|
318
|
+ dt = ds.Tables[0];
|
|
|
319
|
+ dt2 = ds2.Tables[0];
|
|
|
320
|
+ if (dt.Rows.Count > 0)
|
|
|
321
|
+ {
|
|
|
322
|
+
|
|
|
323
|
+ for (int i = 0; i < dt.Rows.Count; i++)
|
|
|
324
|
+ {
|
|
|
325
|
+ //列
|
|
|
326
|
+ for (int j = 0; j < dt.Columns.Count; j++)
|
|
|
327
|
+ {
|
|
|
328
|
+ //用户所具有权限的页面
|
|
|
329
|
+ string f1 = dt.Rows[i][j].ToString();
|
|
|
330
|
+ if (f1 == url)
|
|
|
331
|
+ {
|
|
|
332
|
+ a++;
|
|
|
333
|
+ }
|
|
|
334
|
+
|
|
|
335
|
+
|
|
|
336
|
+ }
|
|
|
337
|
+ }
|
|
|
338
|
+ }
|
|
|
339
|
+ else
|
|
|
340
|
+ {
|
|
|
341
|
+
|
|
|
342
|
+ if (dt2.Rows.Count > 0)
|
|
|
343
|
+ {
|
|
|
344
|
+ a = 0;
|
|
|
345
|
+ }
|
|
|
346
|
+ else
|
|
|
347
|
+ { //T_Sys_RoleUrl 没存数据
|
|
|
348
|
+ a = 1;
|
|
|
349
|
+ }
|
|
|
350
|
+
|
|
|
351
|
+ }
|
|
|
352
|
+
|
|
|
353
|
+ //a>0 / b>0
|
|
|
354
|
+ //a=0
|
|
|
355
|
+ //if (a==0) {
|
|
|
356
|
+ // throw new Exception("操作失败,无权限");
|
|
|
357
|
+ //}
|
|
|
358
|
+ return a;
|
|
|
359
|
+
|
|
|
360
|
+ }
|
|
|
361
|
+
|
|
|
362
|
+
|
|
|
363
|
+ public static int PageFuoction(string Pagename)
|
|
|
364
|
+ {
|
|
|
365
|
+ int a = 0;
|
|
|
366
|
+ StringBuilder strSql = new StringBuilder();
|
|
|
367
|
+ strSql.Append(@" select F_FunctionId from dbo.T_Sys_Function
|
|
|
368
|
+ ");
|
|
|
369
|
+ strSql.Append(" where F_OptUrl like '%" + Pagename + "%'");
|
|
|
370
|
+ // strSql.Append(" group by f.F_OptUrl ,f.F_FunctionId");
|
|
|
371
|
+
|
|
|
372
|
+ var ds = DbHelperSQL.Query(strSql.ToString());
|
|
|
373
|
+ DataTable dt = new DataTable();
|
|
|
374
|
+ dt = ds.Tables[0];
|
|
|
375
|
+ if (dt.Rows.Count > 0)
|
|
|
376
|
+ {
|
|
|
377
|
+
|
|
|
378
|
+ a = Convert.ToInt32(dt.Rows[0][0]);
|
|
|
379
|
+
|
|
|
380
|
+ }
|
|
|
381
|
+
|
|
|
382
|
+
|
|
|
383
|
+ return a;
|
|
|
384
|
+ }
|
|
|
385
|
+
|
|
|
386
|
+
|
|
|
387
|
+ }
|
|
|
388
|
+
|
|
|
389
|
+}
|