diff --git a/Windows/ClaimIt/Form1.cs b/Windows/ClaimIt/Form1.cs
index 0aa797c..3c02528 100644
--- a/Windows/ClaimIt/Form1.cs
+++ b/Windows/ClaimIt/Form1.cs
@@ -255,8 +255,7 @@ private Boolean ClaimIt()
{
UpdateStatus("PROBLEM: Can't Claim PMS.....Job Aborted", Color.Red);
UpdateStatus("Error was: " + ex.Message, Color.Red);
- UpdateStatus("If status code is 401, then most likely the PMS was already claimed, and belongs to somebody else!", Color.Red);
- UpdateStatus("If this really is your server, then see: https://support.plex.tv/articles/204281528-why-am-i-locked-out-of-server-settings-and-how-do-i-get-in/", Color.Red);
+ UpdateStatus("Please see: https://github.com/ukdtom/ClaimIt/wiki/Error-Codes", Color.Red);
return false;
}
}
@@ -269,32 +268,68 @@ private void UpdateStatus(string status, Color color)
LWStatus.Items[LWStatus.Items.Count - 1].EnsureVisible();
}
+ ///
+ /// Checks if an IP V4 Address is in private address space
+ ///
+ ///
+ /// True if in private address space, else False
+ private bool _IsPrivate(string ipAddress)
+ {
+ int[] ipParts = ipAddress.Split(new String[] { "." }, StringSplitOptions.RemoveEmptyEntries)
+ .Select(s => int.Parse(s)).ToArray();
+ // in private ip range
+ if (ipParts[0] == 10 ||
+ (ipParts[0] == 192 && ipParts[1] == 168) ||
+ (ipParts[0] == 172 && (ipParts[1] >= 16 && ipParts[1] <= 31)))
+ {
+ return true;
+ }
+
+ // IP Address is probably public.
+ // This doesn't catch some VPN ranges like OpenVPN and Hamachi.
+ return false;
+ }
+
private void BtnClaimIt_Click(object sender, EventArgs e)
{
Cursor.Current = Cursors.WaitCursor;
PMSUsr = this.tbPlexTVName.Text;
PMSPwd = this.tbPlexTvPassword.Text;
PMSIPAddr = mtbIPAddress.Text.Replace(" ", "");
- // Get IP of PC running this
- IPAddress[] localIPs = Dns.GetHostAddresses(Dns.GetHostName());
- foreach (var IP in localIPs)
+ // Check if address is either loopback or Private
+ if (!((PMSIPAddr == "127.0.0.1") || _IsPrivate(PMSIPAddr)))
{
- this.LWStatus.Items.Add(LWItem("This app is running on IP: " + IP.ToString(), Color.Gray));
+ UpdateStatus("The IP address entered is not in Private Address Space", Color.Red);
+ UpdateStatus("Please see: https://github.com/ukdtom/ClaimIt/wiki/IP-Address-requirement", Color.Red);
+ FatalError();
}
- UpdateStatus("PMS IP: " + PMSIPAddr, Color.Gray);
- UpdateStatus("Starting to work...", Color.Gray);
- if (ComparePwd())
- {
- if (GetPMSIdentifier())
+ else
+ {
+ // Get IP of PC running this
+ IPAddress[] localIPs = Dns.GetHostAddresses(Dns.GetHostName());
+ foreach (var IP in localIPs)
+ {
+ this.LWStatus.Items.Add(LWItem("This app is running on IP: " + IP.ToString(), Color.Gray));
+ }
+ UpdateStatus("PMS IP: " + PMSIPAddr, Color.Gray);
+ UpdateStatus("Starting to work...", Color.Gray);
+ if (ComparePwd())
{
- if (GetUserToken())
+ if (GetPMSIdentifier())
{
- if (GetClaimToken())
+ if (GetUserToken())
{
- if (ClaimIt())
+ if (GetClaimToken())
{
- UpdateStatus("All Done", Color.Green);
- UpdateStatus(string.Format("Please close your browser, reopen, and browse to http://{0}:32400/web", PMSIPAddr), Color.Green);
+ if (ClaimIt())
+ {
+ UpdateStatus("All Done", Color.Green);
+ UpdateStatus(string.Format("Please close your browser, reopen, and browse to http://{0}:32400/web", PMSIPAddr), Color.Green);
+ }
+ else
+ {
+ FatalError();
+ }
}
else
{
@@ -315,12 +350,8 @@ private void BtnClaimIt_Click(object sender, EventArgs e)
{
FatalError();
}
+ Cursor.Current = Cursors.Default;
}
- else
- {
- FatalError();
- }
- Cursor.Current = Cursors.Default;
}
}
}
diff --git a/Windows/ClaimIt/Properties/AssemblyInfo.cs b/Windows/ClaimIt/Properties/AssemblyInfo.cs
index c747e0f..45db835 100644
--- a/Windows/ClaimIt/Properties/AssemblyInfo.cs
+++ b/Windows/ClaimIt/Properties/AssemblyInfo.cs
@@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
-[assembly: AssemblyVersion("1.0.0.0")]
-[assembly: AssemblyFileVersion("1.0.0.0")]
+[assembly: AssemblyVersion("1.1.0.0")]
+[assembly: AssemblyFileVersion("1.1.0.0")]
diff --git a/linux/claimpms.sh b/linux/claimpms.sh
index 1c28a17..322b13d 100644
--- a/linux/claimpms.sh
+++ b/linux/claimpms.sh
@@ -8,6 +8,10 @@
#
# Made by dane22, a Plex community member
# Mark Walker/ZiGGiMoN, a Plex hobbyist
+#
+# Version: 1.1.0.0
+#
+# Home: https://github.com/ukdtom/ClaimIt
#************************************************************************
#************************************************************************
@@ -26,6 +30,26 @@ function ComparePwd()
fi
}
+function ValidateIP()
+# Check if IP has valid format
+{
+ if [ "`echo $ippms | awk -F'.' 'NF==4 && $1 > 0 && $1<256 && $2<256 && $3<256 && $4<256 && !/\.\./'`" == "$ippms" ]
+ then
+ if echo "$ippms" | grep -Eq '(^127\.0\.0\.1)|(^10\.)|(^172\.1[6-9]\.)|(^172\.2[0-9]\.)|(^172\.3[0-1]\.)|(^192\.168\.)' >/dev/null; then
+ return 0
+ else
+ echo "The IP address entered is not in Private Address Space"
+ echo "Either '127.0.0.1' or an address in private address space is needed to claim a server"
+ echo "See: https://github.com/ukdtom/ClaimIt/wiki/IP-Address-requirement"
+ exit 1
+ fi
+ return 0
+ else
+ echo "IP is not valid"
+ exit 1 # terminate and indicate error
+ fi
+}
+
function GetClaimToken()
#*****************************************
#* Get claim token from plex.tv
@@ -85,7 +109,7 @@ function GetLoginToken()
function GetClientIdentifier()
# Get PMS machineIdentifier
{
- url="$ippms:32400/identity"
+ url="http://$ippms:32400/identity"
content=$(curl -i -k -L -s $url)
local machineIdentifier=$(printf %s "$content" | awk -F= '$1=="machineIdentifier"{print $2}' RS=' '| cut -d '"' -f 2)
local http_status=$(echo "$content" | grep HTTP | awk '{print $2}')
@@ -156,10 +180,12 @@ echo "*"
echo "*"
echo "* Made by dane22, a Plex community member"
echo "* And Mark Walker/ZiGGiMoN, a Plex hobbyist"
+echo "*"
+echo "* Version 1.1.0.0"
+echo "*"
+echo "* To see the manual, please visit https://github.com/ukdtom/ClaimIt/wiki"
echo "************************************************************************"
-
-
read -p 'plex.tv Username: ' uservar
echo ''
read -sp 'plex.tv Password: ' passvar
@@ -173,6 +199,16 @@ echo "Comparing entered passwords"
ComparePwd
echo "Comparing entered passwords ok"
+echo "Validating IP address"
+if ! CheckIPValidity=$(ValidateIP);
+then
+ echo "******** ERROR ********"
+ echo "The IP address entered is not in Private Address Space"
+ echo "Either '127.0.0.1' or an address in private address space is needed to claim a server"
+ echo "See: https://github.com/ukdtom/ClaimIt/wiki/IP-Address-requirement"
+ exit 1
+fi
+
echo "Getting PMS Server Identifier"
if ! XPlexClientIdentifier=$(GetClientIdentifier);
then