Page 1 of 1 1
Topic Options
#69257 - 2002-08-21 05:05 PM how to improve this
Anonymous
Unregistered


any ideas how to improve this? it locks a little bit ugly to me...

code:
SELECT
CASE INGROUP("GL helpdesk-telebilling")
$override1 = "helpdesk.telebilling.dk"

CASE INGROUP("GL Servicerufnummern")
$override2 = "www.ihre-servicerufnummer.de"

CASE INGROUP("GL Call Center")
$override3 = "www.teleauskunft.de;www.bankleitzahlen.de"

;CASE INGROUP("Team Intranet")
; $override4 = "bla.de"

ENDSELECT

; Write ProxyOverride
IF $override1
IF $proxyoverride
$proxyoverride = "$proxyoverride;$override1"
ELSE
$proxyoverride = "$override1"
ENDIF
ENDIF
IF $override2
IF $proxyoverride
$proxyoverride = "$proxyoverride;$override2"
ELSE
$proxyoverride = "$override2"
ENDIF
ENDIF
IF $override3
IF $proxyoverride
$proxyoverride = "$proxyoverride;$override3"
ELSE
$proxyoverride = "$override3"
ENDIF
ENDIF

IF $override4
IF $proxyoverride
$proxyoverride = "$proxyoverride;$override4"
ELSE
$proxyoverride = "$override4"
ENDIF
ENDIF

IF $proxyoverride
$proxyoverride = "$proxyoverride;nc*;192.168.*;*.nordcom.net;10.2.6.7;jurcom5.juris.de;www.alexanderschneeweis.de;<local>"
ELSE
$proxyoverride = "nc*;192.168.*;*.nordcom.net;10.2.6.7;jurcom5.juris.de;www.alexanderschneeweis.de;<local>"
ENDIF

;LogEvent( 0 , 1 , "$proxyoverride")
Writevalue ("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings","ProxyOverride",$proxyoverride,"REG_SZ")




[ 21. August 2002, 17:05: Message edited by: icu ]

Top
#69258 - 2002-08-21 05:14 PM Re: how to improve this
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
as the overrides as selective cases, you can change them all to be just override.
and then you don't need long if's anymore. this way the script would be:
code:
SELECT
CASE INGROUP("GL helpdesk-telebilling")
$override = "helpdesk.telebilling.dk"

CASE INGROUP("GL Servicerufnummern")
$override = "www.ihre-servicerufnummer.de"

CASE INGROUP("GL Call Center")
$override = "www.teleauskunft.de;www.bankleitzahlen.de"

;CASE INGROUP("Team Intranet")
; $override4 = "bla.de"

ENDSELECT

; Write ProxyOverride
IF $override
IF $proxyoverride
$proxyoverride = "$proxyoverride;$override"
ELSE
$proxyoverride = "$override"
ENDIF
ENDIF

IF $proxyoverride
$proxyoverride = "$proxyoverride;nc*;192.168.*;*.nordcom.net;10.2.6.7;jurcom5.juris.de;www.alexanderschneeweis.de;<local>"
ELSE
$proxyoverride = "nc*;192.168.*;*.nordcom.net;10.2.6.7;jurcom5.juris.de;www.alexanderschneeweis.de;<local>"
ENDIF

;LogEvent( 0 , 1 , "$proxyoverride")
Writevalue ("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings","ProxyOverride",$proxyoverride,"REG_SZ")

_________________________
!

download KiXnet

Top
#69259 - 2002-08-21 05:15 PM Re: how to improve this
Anonymous
Unregistered


i had it that way ... but it is possible that a user is member of multiple groups handled in this script...
Top
#69260 - 2002-08-21 05:16 PM Re: how to improve this
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
so, you can't use select-case-endselect then.
_________________________
!

download KiXnet

Top
#69261 - 2002-08-21 05:17 PM Re: how to improve this
Anonymous
Unregistered


let me guess. select stops on the first match? ;-)

*sigh*

"if" is my friend [Smile]

Top
#69262 - 2002-08-21 05:41 PM Re: how to improve this
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Also, there are problems with groupnames that exceed 20 characters, see Limit to group Names
_________________________
There are two types of vessels, submarines and targets.

Top
#69263 - 2002-08-21 05:44 PM Re: how to improve this
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
anyway, you still should use somekind of collection.
like:
if INGROUP("GL helpdesk-telebilling")
$override = "helpdesk.telebilling.dk;"
endif
if INGROUP("GL Servicerufnummern")
$override = $override+"www.ihre-servicerufnummer.de;"
endif
and so on.
then you have only one variable to play with and you only have to add the additional stuff at the end:

$override = $override+"nc*;192.168.*;*.nordcom.net;10.2.6.7;jurcom5.juris.de;www.alexanderschneeweis.de;"
$nul=Writevalue ("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings","ProxyOverride",$override,"REG_SZ")

mmmm... what proxyoverride variable keeps inside?

{edit}
corrected the code a little

[ 21. August 2002, 18:01: Message edited by: Lonkero ]
_________________________
!

download KiXnet

Top
#69264 - 2002-08-21 05:52 PM Re: how to improve this
Anonymous
Unregistered


quote:
mmmm... what proxyoverride variable keeps inside?

nothing at the beginning. i'm just playing around with diffrent solutions.

what if 1 person is in both groups. so only the last $override is set.

Top
#69265 - 2002-08-21 06:00 PM Re: how to improve this
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
so, your full code will be this:
code:
if INGROUP("GL helpdesk-telebilling")
$override = "helpdesk.telebilling.dk;"
endif
if INGROUP("GL Servicerufnummern")
$override = $override+"www.ihre-servicerufnummer.de;"
endif
if INGROUP("GL Call Center")
$override = $override+"www.teleauskunft.de;www.bankleitzahlen.de;"
endif

$override = $override+"nc*;192.168.*;*.nordcom.net;10.2.6.7;jurcom5.juris.de;www.alexanderschneeweis.de;<local>"
$nul=Writevalue ("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings","ProxyOverride",$override,"REG_SZ")

and it works for all.
even if the user is member of all groups.
_________________________
!

download KiXnet

Top
#69266 - 2002-08-21 06:09 PM Re: how to improve this
Anonymous
Unregistered


thx for your help [Smile]
Top
#69267 - 2002-08-21 11:43 PM Re: how to improve this
Fernando Madruga Offline
Starting to like KiXtart

Registered: 2002-08-21
Posts: 149
Loc: Coimbra.Portugal.Europe.Earth....
I'm new to KiXtart (2 days and I only wrote a couple of lines of code in it), but I think you could take advantage of the ini-file reading routines and simplify your code.

Having an ini like this (OVERRIDE.INI):

code:
[GL helpdesk-telebilling]
Site 1 = helpdesk.telebilling.dk

[GL Servicerufnummern]
Site 1 = www.ihre-servicerufnummer.de

[GL Call Center]
Site 1 = www.teleauskunft.de
Site 2 = www.bankleitzahlen.de

[Team Intranet]
Site 1 = override=bla.de

[Everyone]
Site 1 = site.for.everyone.com

The actual key names (Site 1, 2, etc) are not important but have to be present; you can use whatever you like the most...

Then change the program to something like this:
code:
dim $Overrides                                                        ; Declare $Overrides
$OverrideIni = ".\overrides.ini" ; Choose ini filename and location
$Sep = "|" ; Character or string to seperate overrides
$Groups = ReadProfileString( $OverrideIni, "", "" ) ; Get all Groups defined in the .ini
if @ERROR = 0 ; If all went well
for each $Group in split( $Groups, Chr(10) ) ; Process each returned line in turn
if $Group ; Accounts for last "empty" item returned above
if InGroup( $Group ) ; If user is in this group
$Items = ReadProfileString( $OverrideIni, $Group, "" ) ; Get all overrides for the selected Group
for each $Item in split( $Items, Chr(10) ) ; Process each override in turn
if $Item ; Accounts for last "empty" item returned above
$Value = ReadProfileString( $OverrideIni, $Group, $Item ) ; Read it's value
$Overrides = $Overrides + $Sep + $Value ; And add it to the Overrides list
endif ; End if $Item
next ; End for each $Item in split( $Items, Chr(10) )
endif ; End if InGroup( $Group )
endif ; End if $Group
next ; End for each $Group in split( $Groups, Chr(10) )
if $Overrides ; If some override present
$Overrides = substr( $Overrides, 2 ) ; Eliminate spurious $Sep added at start
? $Overrides ; Print it or do whatever needed
else ; else (no overrides found)
? "No overrides found..." ; Act accordingly
endif ; End if $Overrides
else ; Else (error reading INI file)
? "Error reading $OverrideIni" ; Complain
endif ; End if @ERROR = 0

Sorry if it doesn't fit nicely on most displays, but I use a 1600x1200 desktop resolution on my Dell Latitude C810 and I tend to use that resolution... [Smile]

I've "sort of" tested this, and it should work... I say "sort of", because I'm at home now and InGroup seems to require a "live" DC present to work properly...

This way of doing things has the advantage that the core script stays the same and you just have to edit the .INI file to add/delete/change stuff...

Hope this helps,
Fernando Madruga

[ 22. August 2002, 00:06: Message edited by: Fernando Madruga ]
_________________________
Later,   [b]Mad[/b]ruga

Top
#69268 - 2002-08-21 11:55 PM Re: how to improve this
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
good, does not look simple, but I'm sure it's easy to keep up with.
I normally want to keep things in the main script if they are directly related to the logon.

this way, I would do something similar to yours but use arrays to achieve the goal.

like, have strings at the beginning of the strings that determine what to use and where and then just split them and use as arrays.

with the readprofilestring, you can also achieve what I want.
include the "ini" section in your script (propably best at the bottom) and then call the script itself.

anyway, I'd call that ini as logon.ini as you might want to add other stuff in it too.
and name the related sections. in this case:
[proxyoverride]
_________________________
!

download KiXnet

Top
#69269 - 2002-08-22 12:12 AM Re: how to improve this
Fernando Madruga Offline
Starting to like KiXtart

Registered: 2002-08-21
Posts: 149
Loc: Coimbra.Portugal.Europe.Earth....
If so, instead of using
code:
$Groups = ReadProfileString( $OverrideIni, "", "" )

to read ALL the sections, it should read all the keys from a specific section and process them in turn. An easy change to this script.

I did like the idea of adding the ini data to the end of the script itself! Does KiXtart have some sort of __END__ token as perl does to stop processing the file?

The advantage of having code separated from data is that one data mistake won't break the code syntax... And it's easier to "delegate", that is, in my company, we have 3 ppl in charge of sys admin tasks: I'm the one with 20+ years of programming on my back, and the other two don't carry the same experience. It's easier for them to simply change the .INI (there are even tools to let you change an .INI file!), and leave the coding to me...

Bye,
Fernando Madruga
_________________________
Later,   [b]Mad[/b]ruga

Top
#69270 - 2002-08-22 12:25 AM Re: how to improve this
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
hehee!

I can see your point.

anyway, what comes to make separated sections in script is only a matter of "exit 0"

I have multiple subscripts and functions at the end of the script. before them I just simply do two lines:

exit 0 ;script execution stops here
;#######################################

and after those add the separated stuff.
this way, even my co-workers see what is what (well, almost) and can leave the main stuff alone.

anyway, I've used on some job assignments diversed way on the data.

I was introduced this with some tcl-scripts I had to work on (IRC rules) some 10 years ago.

make a "configure" section at the start of the file and then:

;if you touch below this, you can be fired!
;###########################################

anyway, making something for the ppl who seem to ignore the fact that world keeps moving because of the programmers, is good thing.
it can even get you a raise or two.
_________________________
!

download KiXnet

Top
#69271 - 2002-08-22 10:56 AM Re: how to improve this
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11634
Loc: Space
You could also use the AND/OR structure with Select and InGroup to modify for looking for scenarios that you think may come up.

Using the most common at the bottom and the obscure at the top of the CASE statements.

Top
Page 1 of 1 1


Moderator:  Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 1114 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.066 seconds in which 0.028 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org