ProxyController.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. using molilian.core;
  2. using dodohold.core;
  3. using Microsoft.AspNetCore.Mvc;
  4. using Org.BouncyCastle.Ocsp;
  5. using System.Text.Json;
  6. using System.Runtime.InteropServices;
  7. using TencentCloud.Scf.V20180416.Models;
  8. using Quartz.Impl.AdoJobStore.Common;
  9. using TencentCloud.Gaap.V20180529.Models;
  10. using System.Net;
  11. using TencentCloud.Ie.V20200304.Models;
  12. using TencentCloud.Soe.V20180724.Models;
  13. namespace molilian.api.Controllers
  14. {
  15. [ApiController]
  16. [MyAuthorize("admin")]
  17. [Route("api/[controller]/[action]")]
  18. public class ProxyController : ControllerBase
  19. {
  20. readonly IAuthorizationProvider provider = new AdminProvider();
  21. protected IHttpContextAccessor _accessor;
  22. public ProxyController(IHttpContextAccessor accessor)
  23. {
  24. _accessor = accessor;
  25. }
  26. [HttpGet]
  27. public ActionResult get()
  28. {
  29. var list = new DBContext.Table("proxy_nodes")
  30. .Where("status=@status", new { status = 1 })
  31. .Select<ProxyNodesDTO>();
  32. // 参考数据
  33. //61 1 6 品阅245 品阅辅助网卡 bj http http://172.21.127.245:33128 molilian Bhquvmkn8zLO36lGjuqk 2024-04-09 14:25:53 2024-04-09 14:25:56
  34. //59 1 6 品阅243 品阅辅助网卡 bj http http://172.21.127.243:33128 molilian Bhquvmkn8zLO36lGjuqk 2024-04-09 14:25:53 2024-04-09 14:25:56
  35. foreach (var proxy in list)
  36. {
  37. //通过 curl myip.ipip.net检测proxy可访问行
  38. }
  39. var tasks = new List<Task<int>>
  40. {
  41. Task.Run(()=>{ })
  42. };
  43. // 等待所有任务完成
  44. Task.WhenAll(tasks).Wait();
  45. return new APIResult(new { list });
  46. }
  47. [HttpGet]
  48. public async Task<ActionResult> ChangePublicIpByName(string nodeName)
  49. {
  50. var proxy_node = new DBContext.Table("proxy_nodes").Get<dynamic>("name=@nodeName", new { nodeName });
  51. if (proxy_node == null) return new APIResult(new { success = false, msg = "没有匹配的 proxy_nodes 记录" });
  52. int aliyun_id = proxy_node.aliyun_id;
  53. string proxy_server = proxy_node.server;
  54. var account = new DBContext.Table("aliyun_pool").Get<AliyunPoolDTO>(aliyun_id);
  55. if (account == null) return new APIResult(new { success = false, msg = "没有匹配的 aliyun_pool 记录" });
  56. var uri = new Uri(proxy_server);
  57. string privateIp = uri.Host;
  58. AliyunCore core = new AliyunCore(account);
  59. var success = await core.ChangePublicIpAsync(privateIp);
  60. return new APIResult(new { success = "ok" });
  61. }
  62. [HttpGet]
  63. public async Task<ActionResult> ChangePublicIp(int id)
  64. {
  65. id = id >= 20000 ? id - 20000 : id;
  66. var proxy_node = new DBContext.Table("proxy_nodes").Get<dynamic>(id);
  67. if (proxy_node == null) return new APIResult(new { success = false, msg = "没有匹配的 proxy_nodes 记录" });
  68. int aliyun_id = proxy_node.aliyun_id;
  69. string proxy_server = proxy_node.server;
  70. var account = new DBContext.Table("aliyun_pool").Get<AliyunPoolDTO>(aliyun_id);
  71. if (account == null) return new APIResult(new { success = false, msg = "没有匹配的 aliyun_pool 记录" });
  72. var uri = new Uri(proxy_server);
  73. string privateIp = uri.Host;
  74. AliyunCore core = new AliyunCore(account);
  75. var success = await core.ChangePublicIpAsync(privateIp);
  76. return new APIResult(new { success = "ok" });
  77. }
  78. }
  79. }