OPTION INTERNATIONAL TRUE
SETENVIRON "OUTPUT_CHARSET", "UTF-8"
INCLUDE "/usr/share/BaCon/hug_imports.bac"
INIT
HUGOPTIONS("BASEXFTDPI 78")
HUGOPTIONS("FONT DejaVu Sans 12")
font_mono$="Monospace 13"
proxy_flag=0
http_proxy$="http://foo.org:8080"
ftp_proxy$="ftp://foo.org:8080"
username$=""
password$=""
IF FILEEXISTS("/etc/profile.d/http_proxy") THEN
http_proxy$=EXEC$("cat /etc/profile.d/http_proxy | cut -f 2 -d '=' | sed -e 's%//.*@%//%' | tr '\n' ' ' | tr -d ' '")
username$=EXEC$("cat /etc/profile.d/http_proxy | cut -f 2 -d '=' | grep '@' | sed -e 's%^.*//%%' -e 's%@.*$%%' -e 's%:.*%%' | tr '\n' ' ' | tr -d ' '")
password$=EXEC$("cat /etc/profile.d/http_proxy | cut -f 2 -d '=' | grep ':' | sed -e 's%^.*//%%' -e 's%@.*$%%' -e 's%^.*:%%' | tr '\n' ' ' | tr -d ' '")
proxy_flag=1
ENDIF
IF FILEEXISTS("/etc/profile.d/ftp_proxy") THEN
ftp_proxy$=EXEC$("cat /etc/profile.d/ftp_proxy | cut -f 2 -d '=' | sed -e 's%//.*@%//%' | tr '\n' ' ' | tr -d ' '")
username$=EXEC$("cat /etc/profile.d/ftp_proxy | cut -f 2 -d '=' | grep '@' | sed -e 's%^.*//%%' -e 's%@.*$%%' -e 's%:.*%%' | tr '\n' ' ' | tr -d ' '")
password$=EXEC$("cat /etc/profile.d/ftp_proxy | cut -f 2 -d '=' | grep ':' | sed -e 's%^.*//%%' -e 's%@.*$%%' -e 's%^.*:%%' | tr '\n' ' ' | tr -d ' '")
proxy_flag=1
ENDIF
SUB check1_callback
LOCAL status
status=GET(check1)
IF status = 1 THEN
ENABLE(httpproxy)
ENABLE(ftpproxy)
ENABLE(username)
ENABLE(password1)
ENABLE(password2)
ELSE
DISABLE(httpproxy)
DISABLE(ftpproxy)
DISABLE(username)
DISABLE(password1)
DISABLE(password2)
ENDIF
ENDSUB
SUB ok_callback
LOCAL pass1$,pass2$
status2=GET(check1)
IF status2 = 0 THEN
SYSTEM "rm -f /etc/profile.d/http_proxy"
SYSTEM "rm -f /etc/profile.d/ftp_proxy"
HIDE(mainwin)
SHOW(no_dlg1)
GOTO label1
ENDIF
httpproxy$=GRAB$(httpproxy)
ftpproxy$=GRAB$(ftpproxy)
username$=GRAB$(username)
pass1$=GRAB$(password1)
pass2$=GRAB$(password2)
IF pass1$ != pass2$ THEN
SHOW(err_dlg1)
ELSE
IF httpproxy$ != "" THEN
protocol1$=LEFT$(httpproxy$,5)
IF protocol1$ = "http:" THEN
protocol2$="http://"
httpproxy1$=MID$(httpproxy$,8)
ELSE
IF protocol1$ = "https" THEN
protocol2$="https://"
httpproxy1$=MID$(httpproxy$,9)
ELSE
protocol2$="http://"
httpproxy1$=httpproxy$
ENDIF
ENDIF
IF username$ = "" THEN
httpproxy2$=httpproxy1$
ELSE
IF pass1$ = "" THEN
httpproxy2$=CONCAT$(username$,"@",httpproxy1$)
ELSE
httpproxy2$=CONCAT$(username$,":",pass1$,"@",httpproxy1$)
ENDIF
ENDIF
http_proxy_profile$=CONCAT$("export http_proxy=",protocol2$,httpproxy2$)
OPEN "/etc/profile.d/http_proxy" FOR WRITING AS handle
WRITELN http_proxy_profile$ TO handle
CLOSE FILE handle
ENDIF
IF ftpproxy$ != "" THEN
protocol1$=LEFT$(ftpproxy$,4)
IF protocol1$ = "ftp:" THEN
protocol2$="ftp://"
ftpproxy1$=MID$(ftpproxy$,7)
ELSE
IF protocol1$ = "ftps" THEN
protocol2$="ftps://"
ftpproxy1$=MID$(ftpproxy$,8)
ELSE
protocol2$="ftp://"
ftpproxy1$=ftpproxy$
ENDIF
ENDIF
IF username$ = "" THEN
ftpproxy2$=ftpproxy1$
ELSE
IF pass1$ = "" THEN
ftpproxy2$=CONCAT$(username$,"@",ftpproxy1$)
ELSE
ftpproxy2$=CONCAT$(username$,":",pass1$,"@",ftpproxy1$)
ENDIF
ENDIF
ftp_proxy_profile$=CONCAT$("export ftp_proxy=",protocol2$,ftpproxy2$)
OPEN "/etc/profile.d/ftp_proxy" FOR WRITING AS handle
WRITELN ftp_proxy_profile$ TO handle
CLOSE FILE handle
ENDIF
HIDE(mainwin)
SHOW(yes_dlg1)
ENDIF
LABEL label1
ENDSUB
SUB close_dialog(NUMBER widget)
HIDE(widget)
FOCUS(password1)
ENDSUB
mainwin = WINDOW(INTL$("Proxy server setup"), 425, 285)
image1=IMAGE("/usr/local/lib/X11/pixmaps/www48.png",48,48)
ATTACH(mainwin,image1,10,10)
label_hdr1=MARK(INTL$("If you connect to the Internet through a proxy"),370,15)
ATTACH(mainwin,label_hdr1,58,10)
label_hdr2=MARK(INTL$("server, tick the checkbox and fill in the fields"),370,15)
ATTACH(mainwin,label_hdr2,58,25)
label_hdr3=MARK(INTL$("(leave Username/Password blank if not needed)"),370,15)
ATTACH(mainwin,label_hdr3,58,40)
check1 = CHECK(INTL$("Enable Internet connection through proxy server"),350,20)
ATTACH(mainwin,check1,20,70)
label_http = MARK("HTTP:",100,20)
PROPERTY(label_http,"xalign",1.0)
ATTACH(mainwin, label_http, 10, 100)
httpproxy = ENTRY(http_proxy$,280,20)
ATTACH(mainwin, httpproxy, 120, 100)
FONT(httpproxy,font_mono$)
label_ftp = MARK("FTP:",100,20)
PROPERTY(label_ftp,"xalign",1.0)
ATTACH(mainwin, label_ftp, 10, 130)
ftpproxy = ENTRY(ftp_proxy$,280,20)
ATTACH(mainwin, ftpproxy, 120, 130)
FONT(ftpproxy,font_mono$)
label_user=MARK(INTL$("Username:"),100,20)
PROPERTY(label_user,"xalign",1.0)
ATTACH(mainwin,label_user,10,160)
username = ENTRY(username$,280,20)
ATTACH(mainwin, username, 120, 160)
FONT(username,font_mono$)
label_pass=MARK(INTL$("Password:"),100,20)
PROPERTY(label_pass,"xalign",1.0)
ATTACH(mainwin,label_pass,10,190)
password1=PASSWORD(150,20)
ATTACH(mainwin,password1,120,190)
TEXT(password1,password$)
FONT(password1,font_mono$)
label_pass2=MARK(INTL$("Enter password again:"),170,20)
ATTACH(mainwin,label_pass2,10,220)
password2=PASSWORD(150,20)
ATTACH(mainwin,password2,180,220)
TEXT(password2,password$)
FONT(password2,font_mono$)
ok_btn = BUTTON(INTL$("OKAY"), 65, 25)
ATTACH(mainwin, ok_btn, 240, 250)
cancel_btn = BUTTON(INTL$("Cancel"), 65, 25)
ATTACH(mainwin, cancel_btn, 320, 250)
err_dlg1=MSGDIALOG(INTL$("Sorry, the password entries are not the same"),400,100,3,2)
yes_dlg1=MSGDIALOG(INTL$("Great, you have modified the proxy server settings. Note, you can see the result in files /etc/profile.d/http_profile and /etc/profile.d/ftp_profile. However, MOST IMPORTANT, you must reboot for this to take effect"),500,160,0,1)
no_dlg1=MSGDIALOG(INTL$("You have chosen NOT to use a proxy server. Note, if you previously did have a proxy server enabled, you MUST REBOOT for the change to take effect"),500,140,0,1)
CALLBACK(ok_btn,ok_callback)
CALLBACK(cancel_btn,QUIT)
CALLBACK(check1,check1_callback)
CALLBACK(err_dlg1,close_dialog)
CALLBACK(yes_dlg1,QUIT)
CALLBACK(no_dlg1,QUIT)
SET(check1,1)
SET(check1,proxy_flag)
DISPLAY