-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds support for re-writing user names using regular expressions
- Loading branch information
1 parent
c3e20ae
commit f4ec2d5
Showing
11 changed files
with
238 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
src/Lithnet.Pan.RAProxy/ConfigSections/UsernameRewriteCollection.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using System.Configuration; | ||
|
||
namespace Lithnet.Pan.RAProxy | ||
{ | ||
public class UsernameRewriteCollection : ConfigurationElementCollection | ||
{ | ||
public override ConfigurationElementCollectionType CollectionType => ConfigurationElementCollectionType.BasicMap; | ||
|
||
protected override ConfigurationElement CreateNewElement() | ||
{ | ||
return new UsernameRewriteSection(); | ||
} | ||
|
||
protected override object GetElementKey(ConfigurationElement element) | ||
{ | ||
return ((UsernameRewriteSection)element).Key; | ||
} | ||
|
||
public UsernameRewriteSection this[int index] | ||
{ | ||
get { return (UsernameRewriteSection)this.BaseGet(index); } | ||
set | ||
{ | ||
if (this.BaseGet(index) != null) | ||
{ | ||
this.BaseRemoveAt(index); | ||
} | ||
this.BaseAdd(index, value); | ||
} | ||
} | ||
|
||
public new UsernameRewriteSection this[string name] => (UsernameRewriteSection)this.BaseGet(name); | ||
|
||
public int IndexOf(UsernameRewriteSection details) | ||
{ | ||
return this.BaseIndexOf(details); | ||
} | ||
|
||
public void Add(UsernameRewriteSection details) | ||
{ | ||
this.BaseAdd(details); | ||
} | ||
|
||
protected override void BaseAdd(ConfigurationElement element) | ||
{ | ||
this.BaseAdd(element, false); | ||
} | ||
|
||
public void Remove(UsernameRewriteSection details) | ||
{ | ||
if (this.BaseIndexOf(details) >= 0) | ||
this.BaseRemove(details.Key); | ||
} | ||
|
||
public void RemoveAt(int index) | ||
{ | ||
this.BaseRemoveAt(index); | ||
} | ||
|
||
public void Remove(string name) | ||
{ | ||
this.BaseRemove(name); | ||
} | ||
|
||
public void Clear() | ||
{ | ||
this.BaseClear(); | ||
} | ||
|
||
protected override string ElementName => "username-rewrite"; | ||
} | ||
} |
73 changes: 73 additions & 0 deletions
73
src/Lithnet.Pan.RAProxy/ConfigSections/UsernameRewriteSection.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Configuration; | ||
using System.Net; | ||
using System.Net.Sockets; | ||
using System.Text.RegularExpressions; | ||
|
||
namespace Lithnet.Pan.RAProxy | ||
{ | ||
public class UsernameRewriteSection : ConfigurationElement | ||
{ | ||
private Regex match; | ||
|
||
private string key; | ||
|
||
internal string Key | ||
{ | ||
get | ||
{ | ||
if (this.key == null) | ||
{ | ||
this.key = Guid.NewGuid().ToString(); | ||
} | ||
|
||
return this.key; | ||
} | ||
} | ||
|
||
[ConfigurationProperty("match", IsRequired = true)] | ||
public string Match | ||
{ | ||
get | ||
{ | ||
return (string)this["match"]; | ||
} | ||
set | ||
{ | ||
this["match"] = value; | ||
} | ||
} | ||
|
||
[ConfigurationProperty("replace", IsRequired = true)] | ||
public string Replace | ||
{ | ||
get | ||
{ | ||
return (string)this["replace"]; | ||
} | ||
set | ||
{ | ||
this["replace"] = value; | ||
} | ||
} | ||
|
||
internal Regex MatchRegex | ||
{ | ||
get | ||
{ | ||
if (this.match == null) | ||
{ | ||
this.match = new Regex(this.Match, RegexOptions.Compiled | RegexOptions.IgnoreCase); | ||
} | ||
|
||
return this.match; | ||
} | ||
} | ||
|
||
internal string Rewrite(string username) | ||
{ | ||
return this.MatchRegex.Replace(username, this.Replace); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.