Exemplo n.º 1
0
        public void DeleteRayPortUser(RayPortUser rayPortUser)
        {
            var rayPort      = GetRayPort(rayPortUser);
            var rayConfigObj = GetRayConfigJObject();

            if (!(rayConfigObj.SelectToken(
                      $"inbounds[?(@port == {rayPort.Port})].settings.clients") is JArray rayUsersObj))
            {
                throw new ArgumentException($"找不到用户{rayPortUser.GetRayPortUserRemark()}");
            }

            var rayUserObjtoDelete = rayUsersObj.SelectToken($"$.[?(@.id == '{rayPortUser.Uuid}')]");

            if (rayUserObjtoDelete == null)
            {
                throw new ArgumentException($"找不到用户{rayPortUser.GetRayPortUserRemark()}");
            }

            if (!rayUsersObj.Remove(rayUserObjtoDelete))
            {
                throw new Exception($"Failed to remove {rayUserObjtoDelete.ToString()}");
            }

            WriteJsonToFile(rayConfigObj);
        }
Exemplo n.º 2
0
        public static void DisplayUser(
            RayPortUser rayPortUser, int?index = null,
            bool showShareUrl = true, bool addReturn = true,
            int intend        = 2)
        {
            if (rayPortUser == null)
            {
                return;
            }
            StringBuilder s  = new StringBuilder("");
            StringWriter  sw = new StringWriter(s);

            s.Append(' ', intend);
            Displayer.ShowConfigItem(s + "索引", index, Program.HighLightColor);
            Displayer.ShowConfigItem(s + "用户", rayPortUser.GetRayPortUserRemark(), Program.WarningColor);
            Displayer.ShowConfigItem(s + "用户Id", rayPortUser.Uuid);
            Displayer.ShowConfigItem(s + "用户额外Id", rayPortUser.AlterId);
            Displayer.ShowConfigItem(s + "等级(Level)", rayPortUser.Level);
            Displayer.ShowConfigItem(s + "邮箱", rayPortUser.Email);
            if (showShareUrl)
            {
                try
                {
                    Displayer.ShowConfigItem(
                        "分享链接",
                        rayPortUser.GenerateShareUrl(RayConfigRepository.GetRayPort(rayPortUser)), Program.ErrorColor);
                }
                catch (Exception) { }
            }

            if (addReturn)
            {
                Console.WriteLine();
            }
        }
Exemplo n.º 3
0
 /// <summary>
 /// 显示用户流量统计
 /// </summary>
 /// <param name="user"></param>
 private void DisplayUserTrafficStatistics(RayPortUser user)
 {
     Displayer.ShowLine(
         user.GetRayPortUserRemark() + ": ",
         addReturn: true,
         color: ConsoleColor.Yellow);
     Displayer.ShowConfigItem(
         "上行流量",
         repo.GetUpLinkTraffic(user).ToTrafficString(),
         valueColor: Displayer.HighLightColor,
         addReture: true);
     Displayer.ShowConfigItem(
         "下行流量",
         repo.GetDownloadLinkTraffic(user).ToTrafficString(),
         valueColor: Displayer.HighLightColor,
         addReture: true);
     Displayer.ShowConfigItem(
         "已使用总流量",
         repo.GetTraffic(user).ToTrafficString(),
         valueColor: Displayer.HighLightColor,
         addReture: true);
 }