LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 03-24-2008, 04:07 PM   #1
CoffeeKing!!!
Member
 
Registered: Mar 2008
Posts: 117

Rep: Reputation: Disabled
Trying to make a GUI for Moblock


Hi
I've down load a gui that was built on gnome glade but won't to build one myself. Here's what the one I DL'd looks like:
// File: MoBlockGUI.cs
// Author: brk3

using System;
using System.Diagnostics;
using System.IO;
using System.Text.RegularExpressions;
using Gtk;
using Glade;

public class MoBlockGUI {

public MoBlockGUI(string[] args) {
Application.Init();

Glade.XML gxml = new Glade.XML (null, "MoBlockGUI.glade", "window1", null);
gxml.Autoconnect (this);

btnEnableDisable.Clicked += btnEnableDisableEvent;
btnClear.Clicked += btnClearEvent;
updatelabelIP();

// check if moblock is already running and set up gui accordingly
if(isMoBlockRunning()) {
labelStatus.Markup = "Status: <span color='darkgreen'>Enabled</span>";
btnEnableDisable.Label = "Disable Moblock";
startClock();
} else {
labelStatus.Markup = "Status: <span color='red'>Disabled</span>";
btnEnableDisable.Label = "Enable Moblock";
}

Application.Run();
}

private void startClock() {
// update log view every 2 seconds
updateLogView();
GLib.Timeout.Add (2000, new GLib.TimeoutHandler(updateLogView));
}

private void updatelabelIP() {
string ipsBlocked = "0";

StreamReader sIn = new StreamReader("/var/log/moblock.log");
string line;
while((line = sIn.ReadLine()) != null)
if(Regex.IsMatch(line, "Ranges loaded:"))
ipsBlocked = Regex.Match(line, @"\d+").ToString();

if(!File.Exists("/var/log/moblock.log") || (!isMoBlockRunning()))
ipsBlocked = "0";

labelIP.Text = "IP's blocked: " + ipsBlocked;
}

private bool updateLogView() {
Process tailProcess = new Process();
tailProcess.StartInfo.FileName = "tail";
tailProcess.StartInfo.Arguments = "/var/log/moblock.log";
tailProcess.StartInfo.UseShellExecute = false;
tailProcess.StartInfo.RedirectStandardOutput = true;
tailProcess.Start();

StreamReader sOut = tailProcess.StandardOutput;

tailProcess.WaitForExit();

logView.Buffer.Text = sOut.ReadToEnd();

sOut.Close();
tailProcess.Close();

return true;
}

private bool isMoBlockRunning() {
Process pidof = new Process();
pidof.StartInfo.FileName = "pidof";
pidof.StartInfo.Arguments = "moblock";
pidof.StartInfo.UseShellExecute = false;
pidof.StartInfo.RedirectStandardOutput = true;
pidof.Start();

StreamReader sOut = pidof.StandardOutput;

pidof.WaitForExit();

string pId = sOut.ReadToEnd();

return (pId.Length > 0) ? true : false;
}

public void btnEnableDisableEvent(object o, EventArgs e) {
if(isMoBlockRunning()) {
Process.Start("gksudo --disable-grab /etc/init.d/moblock-nfq stop");
btnEnableDisable.Label = "Enable Moblock";
labelStatus.Markup = "Status: <span color='red'>Disabled</span>";
} else {
Process.Start("gksudo --disable-grab /etc/init.d/moblock-nfq start");
btnEnableDisable.Label = "Disable Moblock";
labelStatus.Markup = "Status: <span color='darkgreen'>Enabled</span>";
startClock();
}
updatelabelIP();
}

public void btnClearEvent(object o, EventArgs e) {
logView.Buffer.Text = "";
Process.Start("gksudo --disable-grab rm /var/log/moblock.log");
Process.Start("gksudo --disable-grab /etc/init.d/moblock-nfq stop");
Process.Start("gksudo --disable-grab /etc/init.d/moblock-nfq start");
}

public static void Main (string[] args) {
new MoBlockGUI(args);
}

[Glade.Widget]
TextView logView;

[Glade.Widget]
Label labelStatus;

[Glade.Widget]
Label labelIP;

[Glade.Widget]
Button btnEnableDisable;

[Glade.Widget]
Button btnClear;


I can see that gnome glade was use to make this GUI but I would like to do one myself. Could someone point to good way to make a GUI and a ".cs" such as this one. I am a complete beginner here, I scarecely recognize anything on this ".cs"
Thanks
 
Old 03-26-2008, 08:29 AM   #2
v00d00101
Member
 
Registered: Jun 2003
Location: UK
Distribution: Devuan Beowulf
Posts: 514
Blog Entries: 1

Rep: Reputation: 37
There is a section on the forums at phoenixlabs where you can get support for MoBlock. Your question would be answered quicker if you posted there (since thats where the developer hangs out).

http://forums.phoenixlabs.org/forumdisplay.php?f=15
 
Old 03-27-2008, 08:17 AM   #3
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
As a general comment, I don't think you'll be able to easily create a GUI if you've not done any programming before, even if you're using an interface designer like Glade. So, the first thing to do would be to learn a language, presumably C# in your case.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Shorewall + Moblock? opioid Linux - Security 2 12-11-2007 12:46 PM
How to make a GUI for a Script oldstinkyfish Programming 5 07-25-2004 03:18 AM
why are people reluctant to make a GUI LinToWinWin Linux - Newbie 11 03-15-2004 03:06 PM
Make a GUI? Ghost429 Programming 4 01-19-2004 02:32 AM
Is it possible to make a window or a GUI in C without ... purpleburple Programming 4 06-29-2002 11:11 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 01:01 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration