Skip to content

Commit

Permalink
finishing up the first draft of domain token auth.
Browse files Browse the repository at this point in the history
  • Loading branch information
lart2150 committed Jun 4, 2022
1 parent 126e482 commit b63211e
Show file tree
Hide file tree
Showing 7 changed files with 202 additions and 105 deletions.
8 changes: 7 additions & 1 deletion .classpath
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,14 @@
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="images"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="lib" path="lib/jmdns.jar"/>
<classpathentry kind="lib" path="lib/tivo-libre.jar"/>
<classpathentry kind="lib" path="lib/httpclient5-5.1.3.jar"/>
<classpathentry kind="lib" path="lib/httpcore5-5.1.3.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
152 changes: 70 additions & 82 deletions build.xml
Original file line number Diff line number Diff line change
@@ -1,106 +1,94 @@
<?xml version="1.0"?>
<project name="kmttg" basedir="." default="all">
<property name="rversion" value="v2.4p"/>
<tstamp/>
<property name="bversion" value="${DSTAMP}-${TSTAMP}"/>
<property name="lib" value="lib"/>
<property name="release" value="release"/>
<property name="main" value="."/>
<property name="main.class" value="com.tivo.kmttg.main.kmttg"/>
<property name="debuglevel" value="source,lines,vars"/>
<property name="target" value="1.8"/>
<property name="source" value="1.8"/>
<property name="rversion" value="v2.5-l"/>
<tstamp/>
<property name="bversion" value="${DSTAMP}-${TSTAMP}"/>
<property name="lib" value="lib"/>
<property name="release" value="release"/>
<property name="main" value="."/>
<property name="main.class" value="com.tivo.kmttg.main.kmttg"/>
<property name="debuglevel" value="source,lines,vars"/>
<property name="target" value="1.8"/>
<property name="source" value="1.8"/>
<path id="main.classpath">
<pathelement location="${lib}/jmdns.jar"/>
<pathelement location="${lib}/tivo-libre.jar"/>
<pathelement location="${lib}/jmdns.jar"/>
<pathelement location="${lib}/tivo-libre.jar"/>
<pathelement location="${lib}/httpclient5-5.1.3.jar"/>
<pathelement location="${lib}/httpcore5-5.1.3.jar"/>
</path>

<target name="clean">
<delete dir="bin"/>
<delete dir="dist"/>
<delete dir="bin"/>
<delete dir="dist"/>
</target>


<target name="create">
<mkdir dir="bin"/>
<mkdir dir="${release}"/>
</target>
<target name="create-dist">
<mkdir dir="dist"/>
<mkdir dir="dist/${dist}"/>
<mkdir dir="dist"/>
<mkdir dir="dist/${dist}"/>
</target>
<target name="create-dist-src" depends="create-dist">
<mkdir dir="dist/${dist}-src"/>

<mkdir dir="dist/${dist}-src"/>
</target>
<target name="writeversion">
<echo file="${main}/version.txt" append="false" message="${ant.project.name}|${version}"/>
</target>

<target name="writeversion">
<echo file="${main}/version.txt" append="false" message="${ant.project.name}|${version}"/>
</target>
<target name="jar" depends="build">
<delete file="${release}/kmttg.jar"/>
<jar destfile="${release}/kmttg.jar">
<fileset dir="${main}/bin"/>
<fileset dir="${main}/images"/>
<zipgroupfileset dir="${lib}" includes="jmdns.jar"/>
<zipgroupfileset dir="${lib}" includes="tivo-libre.jar"/>
<manifest>
<attribute name="Main-Class" value="${main.class}" />
</manifest>
</jar>
<jar destfile="${release}/kmttg.jar">
<fileset dir="${main}/bin"/>
<fileset dir="${main}/images"/>
<zipgroupfileset dir="${lib}" includes="jmdns.jar"/>
<zipgroupfileset dir="${lib}" includes="tivo-libre.jar"/>
<zipgroupfileset dir="${lib}" includes="httpclient5-5.1.3.jar"/>
<zipgroupfileset dir="${lib}" includes="httpcore5-5.1.3.jar"/>
<manifest>
<attribute name="Main-Class" value="${main.class}"/>
</manifest>
</jar>
</target>
<target name="build" depends="create">
<javac debug="true" debuglevel="${debuglevel}" destdir="bin" source="${source}" target="${target}">
<src path="src"/>
<classpath refid="main.classpath"/>
</javac>
</target>
<target name="init">
<property name="version" value="${bversion}"/>
<property name="dist" value="kmttg_${version}"/>

</target>
<target name="all" depends="init,clean,build,jar,dist-both"/>
<target name="release">
<property name="version" value="${rversion}"/>
<antcall target="all"/>
</target>
<target name="dist-src" depends="create-dist-src">
<copy todir="dist/${dist}-src">
<fileset dir=".">
<include name="src/**"/>
<include name="build.xml"/>
<include name="release/**"/>
</fileset>
</copy>
<chmod file="dist/${release}/kmttg" perm="ugo+x"/>
<chmod file="dist/${release}/kmttg.bat" perm="ugo+x"/>

<zip destfile="dist/${dist}-src.zip">
<zipfileset dir="dist/${dist}-src" prefix="${dist}"
includes="**"
excludes="release META-INF"/>
<zipfileset file="dist/${dist}-src/${release}/kmttg" filemode="755"
prefix="${dist}"/>
<zipfileset file="dist/${dist}-src/${release}/kmttg.bat" filemode="755"
prefix="${dist}"/>
</zip>

<delete dir="dist/${dist}-src"/>
</target>

<target name="dist-both" depends="create-dist">
<antcall target="build"/>
<copy todir="dist/${dist}/release">
<fileset dir="release"/>
</copy>
<chmod file="dist/${dist}/${release}/kmttg" perm="ugo+x"/>

<zip destfile="dist/${dist}.zip">
<zipfileset dir="dist/${dist}/${release}" filemode="755"
includes="**"/>
</zip>
<delete dir="dist/${dist}"/>
</target>

<target name="init">
<property name="version" value="${bversion}"/>
<property name="dist" value="kmttg_${version}"/>
</target>
<target name="all" depends="init,clean,build,jar,dist-both"/>
<target name="release">
<property name="version" value="${rversion}"/>
<antcall target="all"/>
</target>
<target name="dist-src" depends="create-dist-src">
<copy todir="dist/${dist}-src">
<fileset dir=".">
<include name="src/**"/>
<include name="build.xml"/>
<include name="release/**"/>
</fileset>
</copy>
<chmod file="dist/${release}/kmttg" perm="ugo+x"/>
<chmod file="dist/${release}/kmttg.bat" perm="ugo+x"/>
<zip destfile="dist/${dist}-src.zip">
<zipfileset dir="dist/${dist}-src" prefix="${dist}" includes="**" excludes="release META-INF"/>
<zipfileset file="dist/${dist}-src/${release}/kmttg" filemode="755" prefix="${dist}"/>
<zipfileset file="dist/${dist}-src/${release}/kmttg.bat" filemode="755" prefix="${dist}"/>
</zip>
<delete dir="dist/${dist}-src"/>
</target>
<target name="dist-both" depends="create-dist">
<antcall target="build"/>
<copy todir="dist/${dist}/release">
<fileset dir="release"/>
</copy>
<chmod file="dist/${dist}/${release}/kmttg" perm="ugo+x"/>
<zip destfile="dist/${dist}.zip">
<zipfileset dir="dist/${dist}/${release}" filemode="755" includes="**"/>
</zip>
<delete dir="dist/${dist}"/>
</target>
</project>
49 changes: 45 additions & 4 deletions src/com/tivo/kmttg/gui/dialog/configMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
import com.tivo.kmttg.main.jobData;
import com.tivo.kmttg.main.jobMonitor;
import com.tivo.kmttg.main.mdns;
import com.tivo.kmttg.rpc.GetDomainToken;
import com.tivo.kmttg.task.autotune;
import com.tivo.kmttg.task.custom;
import com.tivo.kmttg.util.debug;
Expand All @@ -81,6 +82,7 @@ public class configMain {

private static Button add = null;
private static Button del = null;
private static Button domain_token = null;
private static Button share_add = null;
private static Button share_del = null;
private static Button OK = null;
Expand Down Expand Up @@ -433,6 +435,29 @@ private static void delCB() {
}
}

// Callback for tivo del button
private static void domainTokenCB() {
log.warn("Refreshing token");
Thread t = new Thread()
{
public void run() {
GetDomainToken getDT = new GetDomainToken();
try {
getDT.getToken();
} catch (Exception e) {
log.error("Failed to get domain token. Check your tivo.com username or password.");
return;
}
if (config.isDomainTokenExpired()) {
log.error("Failed to get domain token. Check your tivo.com username or password.");
return;
}
log.warn("Successfully got token");
}
};
t.start();
}

// Callback for share del button
private static void share_delCB() {
debug.print("");
Expand Down Expand Up @@ -2251,6 +2276,7 @@ private static void create(Stage frame) {

add = new Button();
del = new Button();
domain_token = new Button();
share_add = new Button();
share_del = new Button();
Label VRDexe_label = new Label();
Expand Down Expand Up @@ -2403,6 +2429,14 @@ public void handle(ActionEvent e) {
}
});

domain_token.setText("Refresh Token");
domain_token.setOnAction(new EventHandler<ActionEvent>() {
public void handle(ActionEvent e) {
domainTokenCB();
}
});


share_add.setText("ADD");
share_add.setOnAction(new EventHandler<ActionEvent>() {
public void handle(ActionEvent e) {
Expand Down Expand Up @@ -2995,6 +3029,8 @@ public void handle(MouseEvent mouseEvent) {
gy++;
tivo_panel.add(tivo_password_label, 0, gy);
tivo_panel.add(tivo_password, 1, gy);
tivo_panel.add(domain_token, 4, gy);


// autotune panel
GridPane autotune_panel = new GridPane();
Expand Down Expand Up @@ -3616,7 +3652,8 @@ public static void setToolTips() {
autotune_chan2.setTooltip(getToolTip("autotune_chan2"));
autotune_tivoName.setTooltip(getToolTip("autotune_tivoName"));
add.setTooltip(getToolTip("add"));
del.setTooltip(getToolTip("del"));
del.setTooltip(getToolTip("del"));
domain_token.setTooltip(getToolTip("domain_token"));
share_add.setTooltip(getToolTip("share_add"));
share_del.setTooltip(getToolTip("share_del"));
remove_tivo.setTooltip(getToolTip("remove_tivo"));
Expand Down Expand Up @@ -3810,9 +3847,13 @@ else if (component.equals("del")) {
text = "<b>DEL</b><br>";
text += "Remove currently selected entry in <b>Tivos</b> list.";
}
else if (component.equals("share_add")) {
text = "<b>ADD</b><br>";
text += "Add specified <b>Share Name</b> and associated <b>Share Directory</b> to <b>Shares</b> list.";
else if (component.equals("del")) {
text = "<b>DEL</b><br>";
text += "Remove currently selected entry in <b>Tivos</b> list.";
}
else if (component.equals("domain_token")) {
text = "<b>Refresh Domain token</b><br>";
text += "Force a refresh of your domain token. This uses the tivo.com username and password.";
}
else if (component.equals("share_del")) {
text = "<b>DEL</b><br>";
Expand Down
33 changes: 32 additions & 1 deletion src/com/tivo/kmttg/main/config.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Date;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Iterator;
Expand All @@ -39,7 +40,7 @@
import com.tivo.kmttg.httpserver.kmttgServer;

public class config {
public static String kmttg = "kmttg v2.4p";
public static String kmttg = "kmttg v2.5-l";

// encoding related
public static String encProfDir = "";
Expand Down Expand Up @@ -222,6 +223,8 @@ public class config {
public static int middlemind_port = 443;
private static String tivo_username = "";
private static String tivo_password = "";
private static String tivo_domain_token = "";
private static long tivo_domain_token_expires = 0;

// httpserver related
public static int httpserver_enable = 0;
Expand Down Expand Up @@ -659,6 +662,24 @@ public static String getTivoPassword() {
public static void setTivoPassword(String password) {
tivo_password = password;
}

public static String getDomainToken() {
if (tivo_domain_token.length() == 0 && !isDomainTokenExpired())
return null;
return tivo_domain_token;
}

public static boolean isDomainTokenExpired() {
System.out.println("DomainToken: " + tivo_domain_token_expires);
System.out.println("now: " + (new Date()).getTime());
return (new Date()).getTime() > tivo_domain_token_expires;
}

public static void setDomainToken(String token, long expires) {
tivo_domain_token = token;
tivo_domain_token_expires = expires;
}


private static void defineDefaults() {
debug.print("");
Expand Down Expand Up @@ -1135,6 +1156,12 @@ private static Boolean parseIni(String config) {
if (key.equals("tivo_password")) {
tivo_password = line;
}
if (key.equals("tivo_domain_token")) {
tivo_domain_token = line;
}
if (key.equals("tivo_domain_token_expires")) {
tivo_domain_token_expires = Long.parseLong(string.removeLeadingTrailingSpaces(line));
}
/*if (key.equals("pyTivo_config")) {
pyTivo_config = line;
}
Expand Down Expand Up @@ -1470,6 +1497,10 @@ public static Boolean save() {

ofp.write("<tivo_password>\n" + tivo_password + "\n\n");

ofp.write("<tivo_domain_token>\n" + tivo_domain_token + "\n\n");

ofp.write("<tivo_domain_token_expires>\n" + tivo_domain_token_expires + "\n\n");

//ofp.write("<pyTivo_config>\n" + pyTivo_config + "\n\n");

//ofp.write("<pyTivo_host>\n" + pyTivo_host + "\n\n");
Expand Down
Loading

0 comments on commit b63211e

Please sign in to comment.