Skip to content

Commit

Permalink
Changed the ILIAS service reference to be dynamically editable
Browse files Browse the repository at this point in the history
  • Loading branch information
Viperinius committed Aug 19, 2018
1 parent bfb3771 commit 699c374
Show file tree
Hide file tree
Showing 13 changed files with 4,508 additions and 371 deletions.
93 changes: 93 additions & 0 deletions IliasDL/CConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
using System.Threading.Tasks;
using System.Configuration;
using System.Collections.Specialized;
using System.Xml;
using System.Net;
using System.IO;

namespace IliasDL
{
Expand Down Expand Up @@ -61,7 +64,97 @@ private void ClearAppSetting(string key)
}


public void SetIliasReference(string sUrl)
{
//load config
XmlDocument doc = new XmlDocument();
doc.Load(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile);
XmlNodeList endpoints = doc.GetElementsByTagName("endpoint");
//search for url
foreach (XmlNode node in endpoints)
{
var addressAttribute = node.Attributes["address"];

if (!(addressAttribute is null))
{
addressAttribute.Value = sUrl;
}
}
doc.Save(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile);
}

private bool IliasUrlIsCorrect(string sUrl)
{
if (sUrl.Contains(@"/webservice/soap/server.php") || sUrl.Contains(@"/login.php"))
{
return true;
}
return false;
}

private string IliasGetClientId(string sUrl)
{
CookieContainer cookieJar = new CookieContainer();
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(sUrl);

request.CookieContainer = cookieJar;
request.Method = "POST";
request.Credentials = CredentialCache.DefaultCredentials;

Stream dataStream = request.GetRequestStream();
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
var test = response.Cookies;
response.Close();

return test[0].Value;
}

public string FormatIliasUrlToWebServiceLink(string sUrl, ref string sClient)
{
if (!IliasUrlIsCorrect(sUrl))
{
//url unlike expected login or webservice page
return "";
}

string sResult = "";
if (sUrl.Contains(@"/login.php"))
{
//given url is login page

//get client id for further use (login)
if (sUrl.Contains(@"client_id="))
{
string sClientTemplate = "client_id=";
sClient = sUrl.Substring(sUrl.LastIndexOf(sClientTemplate) + sClientTemplate.Length, sUrl.Length - (sUrl.LastIndexOf(sClientTemplate) + sClientTemplate.Length));
if (sClient.Contains("&"))
{
sClient = sClient.Split('&')[0];
}
}
else
{
sClient = IliasGetClientId(sUrl);
}

sResult = sUrl.Substring(0, sUrl.LastIndexOf("login.php")) + @"webservice/soap/server.php";
return sResult;
}
else if (sUrl.Contains(@"/webservice/soap/server.php"))
{
//given url is webservice page
if (sUrl.Contains("?"))
{
sResult = sUrl.Split('?')[0];
}
else
{
sResult = sUrl;
}
return sResult;
}
return "";
}

public void SetPath(string sPath)
{
Expand Down
1 change: 1 addition & 0 deletions IliasDL/Form1.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 21 additions & 17 deletions IliasDL/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,9 @@ namespace IliasDL
{
public partial class Form1 : Form
{
private bool bShowOnly;
private bool bOnlyNewFiles;

private string sIliasUrl;
private string sUsername;
private string sPassword;
private string sIliasClient;
public bool bLoggedIn;
private bool bLogInFail;

Expand All @@ -50,7 +47,7 @@ public partial class Form1 : Form
private int iCurrentCourseNum = 0;
private bool bCoursesDone = false;

private bool success;
private bool bSuccess;


public Form1()
Expand All @@ -61,18 +58,12 @@ public Form1()
InitializeComponent();

updater = new CUpdate(notifyIcon1);

bShowOnly = false;
bOnlyNewFiles = false;

//sIliasUrl = "https://nbl.fh-bielefeld.de/login.php?target=&soap_pw=&ext_uid=&client_id=FH-Bielefeld&lang=de";
sIliasUrl = "https://nbl.fh-bielefeld.de/webservice/soap/server.php";


sUsername = "";
sPassword = "";
bLoggedIn = false;
bLogInFail = false;

sIliasClient = "";
}

private void EnglishToolStripMenuItem_Click(object sender, EventArgs e)
Expand Down Expand Up @@ -284,6 +275,17 @@ private void TrayIconToolStripMenuItem_Click(object sender, EventArgs e)
}
}

private void ServerToolStripMenuItem_Click(object sender, EventArgs e)
{
using (FormServer serverForm = new FormServer())
{
if (serverForm.ShowDialog() == DialogResult.OK)
{
serverForm.Close();
}
}
}

private void AddToListView(string sStatus, string sName, string sPath, string sDate, string sSize, string sRefId)
{
string[] row = { sStatus, sName, sPath, sDate, sSize, sRefId };
Expand Down Expand Up @@ -1190,7 +1192,7 @@ private void LoginWorker_DoWork(object sender, DoWorkEventArgs e)
{
if (bLoggedIn)
{
success = Logout(ref client, sSessionId);
bSuccess = Logout(ref client, sSessionId);
//Console.WriteLine("Logging out.");
}
else
Expand All @@ -1207,12 +1209,14 @@ private void LoginWorker_DoWork(object sender, DoWorkEventArgs e)
//connect to ILIAS SOAP
try
{
//get client id
sIliasClient = config.GetClient();

//get session id / log in
sSessionId = client.loginLDAP("FH-Bielefeld", sUsername, sPassword);
//Console.WriteLine(sSessionId);
sSessionId = client.loginLDAP(sIliasClient, sUsername, sPassword);

//get user id
iUserId = client.getUserIdBySid(sSessionId);
//Console.WriteLine(iUserId);
}
catch (Exception)
{
Expand Down
Loading

0 comments on commit 699c374

Please sign in to comment.