Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
//var topPanel = panel.add_Panel(true);
var topPanel = "Util - Browse TeamMentor Libraries v1.0".popupWindow(800,500);
topPanel.insert_LogViewer();
//var defaultServer = "http://localhost:12120";
var defaultServer = "https://owasp.teammentor.net";
var defaultUsername = "";
var defaultPassword = "";
var stopRequests = false;
API_TeamMentor_WebServices teamMentor = null;
Action<string,bool, string,string> connectToServer =
(serverUrl, login, username, password)=>{
teamMentor = new API_TeamMentor_WebServices(serverUrl);
if (teamMentor.ping())
{
teamMentor.load_LibraryData();
if (login)
{
teamMentor.login(username, password);
if (teamMentor.loggedIn())
"Connected and logged in OK to to TM server".info();
else
"Fail to connect or login to server (check if you have a proxy enabled)".error();
}
}
else
{
"teamMentor.ping() failed for url: {0}".error(serverUrl);
}
};
//return teamMentor;
var seetings = topPanel.insert_Above(40,"Settings");
var articlesList = topPanel.title("Selected View").add_TreeView_with_PropertyGrid(false);
var libraryView = topPanel.insert_Left(300,"Libraries").add_TreeView();
var articleView = articlesList.splitContainer().parent().insert_Below("Article Content").add_WebBrowser_Control();
articlesList.splitterDistance(250);
Action<Article_WS, TreeNode> handleDroppedArticle =
(article, treeNode)=> {
"Dropped article was: {0} into {1}".info(article, treeNode);
var tag = treeNode.Tag;
"tag: {0} : {1}".info(tag , tag.typeName());
if (tag is View_WS)
{
"adding to view".info();
(tag as View_WS).Articles.Add(article);
}
else
treeNode.add_Node(article.str(), article);
treeNode.selected();
};
articlesList.onDrag<Article_WS>();
libraryView.onDrop(handleDroppedArticle);
/*libraryView.onDoubleClick<object>(
(tag)=>{
tag.showInfo();
});*/
libraryView.beforeExpand<Library_WS>(
(treeNode, library)=>{
var folders = library.folders();
var views = library.views();
treeNode.clear()
.add_Nodes(folders, true)
.add_Nodes(views, false);
});
libraryView.beforeExpand<Folder_WS>(
(treeNode, folder)=>{
treeNode.add_Nodes(folder.views(),false);
});
libraryView.afterSelect<Library_WS>(
(library)=>{
articlesList.clear().add_Nodes(library.articles())
.selectFirst();
});
libraryView.afterSelect<View_WS>(
(view)=>{
articlesList.clear().add_Nodes(view.Articles)
.selectFirst();
});
articlesList.afterSelect<Article_WS>(
(article)=> {
if (article.Content.valid())
{
articleView.open(article.Content.saveWithExtension(".html"));
return;
}
articlesList.azure();
O2Thread.mtaThread(
()=>{
articleView.open(article.content().saveWithExtension(".html"));
articlesList.white();
});
});
libraryView.afterSelect<Folder_WS>(
(folder)=>{
articlesList.clear().add_Nodes(folder.articles())
.selectFirst();
});
Action loadLibraries =
()=>{
libraryView.clear()
.add_Nodes(teamMentor.libraries(),true)
.selectFirst();
};
Action<bool> setServer =
(login)=>{
libraryView.clear().azure().add_Node("loading data ...");
articlesList.clear();
O2Thread.mtaThread(
()=>{
"Setting server: {0}".info(defaultServer);
//var stopRequests = teamMentor.StopRequests;
connectToServer(defaultServer, login, defaultUsername,defaultPassword);
teamMentor.StopRequests = stopRequests;
loadLibraries();
libraryView.white();
});
};
seetings.add_Label ("Server") .top(2).autoSize().append_TextBox(defaultServer).width(200).onTextChange((value)=> defaultServer = value).onEnter((value)=>setServer(false))
.append_Link("Connect",()=>setServer(false))
.append_Label("Username").top(2).autoSize().append_TextBox(defaultUsername).onTextChange((value)=> defaultUsername = value)
.append_Label("Password").top(2).autoSize().append_TextBox(defaultPassword).onTextChange((value)=> defaultPassword = value).isPasswordField()
.append_Link("Connect and Login",()=>setServer(true))
.append_CheckBox("stop requests",(value)=> stopRequests = value);
var url_TextBox = seetings.control<TextBox>();
url_TextBox.add_ContextMenu()
.add_MenuItem("OWASP library (local)" , true, ()=>{ url_TextBox.set_Text("http://localhost:12110"); setServer(false); } )
.add_MenuItem("TeamMentor library (local)" , true, ()=>{ url_TextBox.set_Text("http://localhost:12120"); setServer(false); })
.add_MenuItem("OWASP library (owasp.teammentor.net)" , true, ()=>{ url_TextBox.set_Text("https://owasp.teammentor.net"); setServer(false); })
.add_MenuItem("TeamMentor library (teammentor.net)" , true, ()=>{ url_TextBox.set_Text("https://teammentor.net"); setServer(false); });
libraryView.add_ContextMenu()
.add_MenuItem("Reload Libraries", ()=> loadLibraries() );
setServer(false);
//connectToServer(defaultServer, false, defaultUsername, defaultPassword);
//loadLibraries();
return topPanel;
//O2File:../APIs/API_TeamMentor_WebServices.cs
//using SecurityInnovation.TeamMentor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.