Skip to content

Commit

Permalink
Merge pull request #13 from ukdtom/tmwork
Browse files Browse the repository at this point in the history
V1.1
  • Loading branch information
ukdtom authored May 8, 2019
2 parents 4c2a1d6 + 07ca073 commit 14561a9
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 26 deletions.
73 changes: 52 additions & 21 deletions Windows/ClaimIt/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand All @@ -269,32 +268,68 @@ private void UpdateStatus(string status, Color color)
LWStatus.Items[LWStatus.Items.Count - 1].EnsureVisible();
}

/// <summary>
/// Checks if an IP V4 Address is in private address space
/// </summary>
/// <param name="ipAddress"></param>
/// <returns>True if in private address space, else False</returns>
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
{
Expand All @@ -315,12 +350,8 @@ private void BtnClaimIt_Click(object sender, EventArgs e)
{
FatalError();
}
Cursor.Current = Cursors.Default;
}
else
{
FatalError();
}
Cursor.Current = Cursors.Default;
}
}
}
4 changes: 2 additions & 2 deletions Windows/ClaimIt/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
42 changes: 39 additions & 3 deletions linux/claimpms.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
#************************************************************************

#************************************************************************
Expand All @@ -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
Expand Down Expand Up @@ -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}')
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 14561a9

Please sign in to comment.