grthtrhthjhtyjytjytkergtrhtrjytjerhrfh4:24 29/09/2026/** BEGIN COPYRIGHT BLOCK
* This Program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation; version 2 of the License.
*
* This Program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* this Program; if not, write to the Free Software Foundation, Inc., 59 Temple
* Place, Suite 330, Boston, MA 02111-1307 USA.
*
* Copyright (C) 2005 Red Hat, Inc.
* All rights reserved.
* END COPYRIGHT BLOCK **/
imports.gi.versions.Gtk = '3.0'
const Gtk = imports.gi.Gtk;
const Lang = imports.lang;
const Gio = imports.gi.Gio;
const GObject = imports.gi.GObject;
const GLib = imports.gi.GLib;
//Phone Home related Constants
const KEY_ISSUER_URL = "keyIssuerUrl";
const KEY_ISSUER = "keyIssuer";
const TPS_URL = "Operation";
const TPS_UI = "UI";
const SERVICES_TAG = "Services";
const ISSUER_TAG = "IssuerName";
const SERVICE_INFO_TAG = "ServiceInfo";
const ENROLLED_TOKEN_BROWSER_URL = "EnrolledTokenBrowserURL";
const ENROLLED_TOKEN_URL = "EnrolledTokenURL";
const TOKEN_TYPE = "TokenType";
const RESET_PHONE_HOME = "ResetPhoneHome";
const PHONE_HOME_CONFIG_INFO = "Phone Home Configuration Information";
function phoneHome(app) {
if(!app)
return;
this.app = app;
this.url = "";
this.tokenType = "";
this.operationUrl = "";
this.enrolledTokenBrowserURL = "";
this.issuerName = "";
}
phoneHome.prototype = {
getPhoneHomeInfo: function(tokenInfo,forceUserInput) {
if(!tokenInfo && !forceUserInput) {
return null;
}
this.tokenInfo = tokenInfo;
if(!forceUserInput && this.tokenInfo.issuer_info != null) {
this.url = this.tokenInfo.issuerInfo;
this.getPhoneHomeFromServer(tokenInfo);
} else {
this.promptPhoneHomeURL();
}
},
getPhoneHomeFromServer: function(tokenInfo) {
if(!this.url || !tokenInfo) {
return;
}
this.phoneHomeInfo = this.app._phoneHome(this.url);
if(this.phoneHomeInfo) {
this.parse(this.phoneHomeInfo,tokenInfo);
this.app._alert("Phone Home Info Successfully Obtained!");
} else {
this.app._alert("Unable to obtain phone home info!");
}
},
promptPhoneHomeURL: function() {
this.createPhoneHomeDialog();
},
createPhoneHomeDialog: function() {
this.phDialog = new Gtk.Dialog ({ transient_for: this.app._window,
modal: true,
title: PHONE_HOME_CONFIG_INFO, border_width: 20 });
this.phArea = this.phDialog.get_content_area();
this.phMessage = new Gtk.Label ({label: "Enter url: ex: http://test.host.com:8080/tps/phoneHome"});
//this.phArea.add (this.phMessage);
this.phActionArea = this.phDialog.get_action_area();
this.phUrlBox = new Gtk.Entry({width_chars: 35});
this.phGrid = new Gtk.Grid ({halign: Gtk.Align.CENTER,
valign: Gtk.Align.CENTER,
row_spacing: 10, column_spacing: 10});
if(this.tokenInfo.issuer_info) {
this.phUrlBox.set_text(this.tokenInfo.issuer_info);
}
this.phActionArea.add(this.phGrid);
this.phOKButton = Gtk.Button.new_from_stock (Gtk.STOCK_OK);
this.phGrid.add(this.phMessage);
this.phGrid.attach(this.phUrlBox, 0, 1, 1,1);
this.phGrid.attach(this.phOKButton,1, 1,1,1);
// Connect the button to the function that handles what it does
this.phOKButton.connect ("clicked", this.phoneHomeOKHandler.bind(this));
this.phDialog.show_all();
},
phoneHomeOKHandler: function() {
this.url = this.phUrlBox.get_text();
this.getPhoneHomeFromServer(this.tokenInfo);
if(this.phDialog) {
this.phDialog.destroy();
this.phDialog = null;
}
},
parse: function(info,tokenInfo) {
if(!info) {
return;
}
//Find tokenType
this.tokenType = this.findValue(info,"","");
this.operationUrl = this.findValue(info,"","");
this.enrolledTokenBrowserURL = this.findValue(info,"");
this.issuerName = this.findValue(info,"","");
let key_issuer_url = this.app._configValueWithKeyID(tokenInfo.cuid,KEY_ISSUER_URL);
this.app._setConfigValue(key_issuer_url,this.url);
let key_issuer = this.app._configValueWithKeyID(tokenInfo.cuid,KEY_ISSUER);
this.app._setConfigValue(key_issuer,this.issuerName);
let operation_url = this.app._configValueWithKeyID(tokenInfo.cuid,TPS_URL);
this.app._setConfigValue(operation_url,this.operationUrl);
let enrolled_token_browser_url = this.app._configValueWithKeyID(tokenInfo.cuid,ENROLLED_TOKEN_BROWSER_URL);
this.app._setConfigValue(enrolled_token_browser_url, this.enrolledTokenBrowserURL);
let token_type = this.app._configValueWithKeyID(tokenInfo.cuid,TOKEN_TYPE);
this.app._setConfigValue(token_type, this.tokenType);
},
findValue: function(fullString, startTag, endTag) {
if(!fullString || !startTag || !endTag) {
return null;
}
let spos = fullString.search(startTag) + startTag.length;
let epos = fullString.search(endTag);
let value = fullString.slice(spos,epos);
if(value) {
return value.trim();
}
return null;
},
getTokenType: function() {
return this.tokenType;
},
getOperationURL: function() {
return this.operationURL;
},
getEnrolledTokenBrowserURL: function() {
return this.enrolledTokenBrowserURL;
},
getIssuerName: function() {
return this.issuerName;
},
getCachedPhoneHomeValue: function(aKeyID,aValue) {
var retValue = null;
if(!aKeyID || ! aValue)
return null;
var theValue = this.app._configValueWithKeyID(aKeyID,aValue);
if(!theValue)
return null;
retValue = this.app._getConfigValue(theValue);
return retValue;
},
getCachedPhoneHomeURL: function(aKeyID) {
var url = null;
if(!aKeyID)
return null;
var urlValue = this.app._configValueWithKeyID(aKeyID,KEY_ISSUER_URL);
if(!urlValue)
return null;
url = this.app._getConfigValue(urlValue);
return url;
},
getCachedIssuer: function(aKeyID) {
var issuer = null;
if(!aKeyID)
return null;
let issuerValue = this.app._configValueWithKeyID(aKeyID,KEY_ISSUER);
if(issuerValue == null)
return null;
issuer = this.app._getConfigValue(issuerValue);
return issuer;
},
getCachedTPSURL: function(aKeyID) {
var url = null;
if(!aKeyID)
return null;
var urlValue = this.app_.configValueWithKeyID(aKeyID,TPS_URL);
if(!urlValue)
return null;
url = this.app._getConfigValue(urlValue);
return url;
},
getCachedTokenType: function(aKeyID) {
return getCachedPhoneHomeValue(aKeyID,TOKEN_TYPE);
}
}