~ubuntu-branches/debian/squeeze/alpine/squeeze

« back to all changes in this revision

Viewing changes to web/cgi/alpine/conf_process.tcl

  • Committer: Bazaar Package Importer
  • Author(s): Asheesh Laroia
  • Date: 2007-02-17 13:17:42 UTC
  • Revision ID: james.westby@ubuntu.com-20070217131742-99x5c6cpg1pbkdhw
Tags: upstream-0.82+dfsg
ImportĀ upstreamĀ versionĀ 0.82+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!./tclsh
 
2
# $Id: conf_process.tcl 391 2007-01-25 03:53:59Z mikes@u.washington.edu $
 
3
# ========================================================================
 
4
# Copyright 2006 University of Washington
 
5
#
 
6
# Licensed under the Apache License, Version 2.0 (the "License");
 
7
# you may not use this file except in compliance with the License.
 
8
# You may obtain a copy of the License at
 
9
#
 
10
#     http://www.apache.org/licenses/LICENSE-2.0
 
11
#
 
12
# ========================================================================
 
13
 
 
14
#  conf_process.tcl
 
15
#
 
16
#  Purpose:  CGI script to perform various message/mailbox
 
17
#            oriented operations
 
18
 
 
19
source genvars.tcl
 
20
 
 
21
set cfs_vars {
 
22
  {cid          "Missing Command ID"}
 
23
  {oncancel     "Missing oncancel"}
 
24
  {cp_op       {}      noop}
 
25
  {save         {}      0}
 
26
  {delete       {}      0}
 
27
  {compose      {}      0}
 
28
  {cancel       {}      0}
 
29
  {gtab         {}      0}
 
30
  {mltab        {}      0}
 
31
  {mvtab        {}      0}
 
32
  {ctab         {}      0}
 
33
  {abtab        {}      0}
 
34
  {ftab         {}      0}
 
35
  {rtab         {}      0}
 
36
  {wv           {}      ""}
 
37
  {varlistadd   {}      ""}
 
38
  {newconf      {}      0}
 
39
}
 
40
 
 
41
## read vars
 
42
foreach item $cfs_vars {
 
43
  if {[catch {cgi_import [lindex $item 0].x}]} {
 
44
    if {[catch {eval WPImport $item} result]} {
 
45
      error [list _action "Impart Variable" $result]
 
46
    }
 
47
  } else {
 
48
    set [lindex $item 0] 1
 
49
  }
 
50
}
 
51
 
 
52
proc wpGetVar {_var} {
 
53
  upvar $_var var
 
54
 
 
55
  if {[catch {cgi_import_as $_var var} result]} {
 
56
    error [list _action "Import Var  $_var" $result]
 
57
  }
 
58
}
 
59
 
 
60
proc wpGetVarAs {_var _varas} {
 
61
  upvar $_varas varas
 
62
 
 
63
  if {[catch {cgi_import_as $_var varas} result]} {
 
64
    set varas ""
 
65
  }
 
66
}
 
67
 
 
68
if {$cid != [WPCmd PEInfo key]} {
 
69
  catch {WPCmd PEInfo statmsg "Invalid Command ID"}
 
70
}
 
71
 
 
72
proc wpGetGoodVars {} {
 
73
  global wv
 
74
  global general_vars msglist_vars composer_vars folder_vars address_vars msgview_vars rule_vars
 
75
 
 
76
  switch -- $wv {
 
77
    msgl {
 
78
      set goodvars $msglist_vars
 
79
    }
 
80
    msgv {
 
81
      set goodvars $msgview_vars
 
82
    }
 
83
    address {
 
84
      set goodvars $address_vars
 
85
    }
 
86
    composer {
 
87
      set goodvars $composer_vars
 
88
    }
 
89
    folder {
 
90
      set goodvars $folder_vars
 
91
    }
 
92
    rule {
 
93
      set goodvars $rule_vars
 
94
    }
 
95
    general {
 
96
      set goodvars $general_vars
 
97
    }
 
98
  }
 
99
  return $goodvars
 
100
}
 
101
 
 
102
proc fieldPos {fmt field} {
 
103
  for {set i 0} {$i < [llength $fmt]} {incr i} {
 
104
    if {[string compare [string toupper [lindex [lindex $fmt $i] 0]] [string toupper $field]] == 0} {
 
105
      return $i
 
106
    }
 
107
  }
 
108
 
 
109
  return -1
 
110
}
 
111
 
 
112
set op $cp_op
 
113
if {[catch {WPCmd set conf_page} conftype]} {
 
114
  set conftype general
 
115
}
 
116
if {[string length $wv]} {
 
117
  set conftype $wv
 
118
  set op tab
 
119
}
 
120
if {$save == 1 || [string compare $save Save] == 0} {
 
121
  set op tab
 
122
  set subop save
 
123
} elseif {$newconf} {
 
124
  set op noop
 
125
} elseif {$gtab} {
 
126
  set op "tab"
 
127
  set conftype "general"
 
128
} elseif {$mltab} {
 
129
  set op "tab"
 
130
  set conftype "msgl"
 
131
} elseif {$mvtab} {
 
132
  set op "tab"
 
133
  set conftype "msgv"
 
134
} elseif {$ctab} {
 
135
  set op "tab"
 
136
  set conftype "composer"
 
137
} elseif {$abtab} {
 
138
  set op "tab"
 
139
  set conftype "address"
 
140
} elseif {$ftab} {
 
141
  set op "tab"
 
142
  set conftype "folder"
 
143
} elseif {$rtab} {
 
144
  set op "tab"
 
145
  set conftype "rule"
 
146
} elseif {$cancel == 1 || [string compare $cancel Cancel] == 0} {
 
147
  set op "cancel"
 
148
}
 
149
 
 
150
proc wpGetRulePattern {} {
 
151
    set patlist {}
 
152
 
 
153
    set patfields {
 
154
        nickname
 
155
        to
 
156
        from
 
157
        sender
 
158
        cc
 
159
        recip
 
160
        partic
 
161
        news
 
162
        subj
 
163
        alltext
 
164
        stat_new
 
165
        stat_del
 
166
        stat_imp
 
167
        stat_ans
 
168
        ftype
 
169
        folder
 
170
    }
 
171
 
 
172
    foreach patfield $patfields {
 
173
        wpGetVarAs $patfield tval
 
174
        lappend patlist [list $patfield $tval]
 
175
    }
 
176
 
 
177
    return $patlist
 
178
 
 
179
}
 
180
 
 
181
proc wpGetRuleAction {tosave} {
 
182
    set actlist {}
 
183
    wpGetVar action
 
184
    if {$tosave == 1} {
 
185
      lappend actlist [list "action" $action]
 
186
    } else {
 
187
      switch -- $action {
 
188
        move {lappend actlist [list "kill" 0]}
 
189
        delete {lappend actlist [list "kill" 1]}
 
190
      }
 
191
    }
 
192
    wpGetVar actionfolder
 
193
    lappend actlist [list "folder" $actionfolder]
 
194
    wpGetVarAs moind moind
 
195
    if {[string compare $moind "on"] == 0} {
 
196
      lappend actlist [list [expr {$tosave == 1 ? "moind" : "move_only_if_not_deleted"}] "1"]
 
197
    } else {
 
198
      lappend actlist [list [expr {$tosave == 1 ? "moind" : "move_only_if_not_deleted"}] "0"]
 
199
    }
 
200
}
 
201
 
 
202
        #
 
203
        # Meat and potatoes of processing goes on here.
 
204
        # Errors are barfed up as they occur,
 
205
        # otherwise the result is communicated below...
 
206
        #
 
207
        set setfeatures [WPCmd PEConfig featuresettings]
 
208
        set script fr_tconfig.tcl
 
209
        switch -- $op {
 
210
            tab {
 
211
              if {[info exists goodvars] == 0} {
 
212
                set goodvars [wpGetGoodVars]
 
213
              }
 
214
              foreach goodvar $goodvars {
 
215
                set vtypeinp [lindex $goodvar 0]
 
216
                set varname [lindex $goodvar 1]
 
217
                set hlpthisvar 0
 
218
                wpGetVarAs hlp.$varname.x thlp
 
219
                if {[string length $thlp]} {
 
220
                  set hlpthisvar 1
 
221
                  set helpcancelset conf_process
 
222
                }
 
223
                switch -- $vtypeinp {
 
224
                  special {
 
225
                    switch -- $varname {
 
226
                      wp-columns {
 
227
                        if {$hlpthisvar} {
 
228
                          set subop varhelp
 
229
                          set varhelpname wp-columns
 
230
                        } else {
 
231
                          wpGetVar columns
 
232
                          WPCmd PEConfig columns $columns
 
233
                        }
 
234
                      }
 
235
                      signature {
 
236
                        wpGetVar signature
 
237
                        set cursig [string trimright [join [WPCmd PEConfig rawsig] "\n"]]
 
238
                        set signature [string trimright $signature]
 
239
                        if {[string compare $cursig $signature]} {
 
240
                          WPCmd PEConfig rawsig [split $signature "\n"]
 
241
                        }
 
242
                      }
 
243
                      filters {
 
244
                        wpGetVarAs $varname-sz sz
 
245
                        wpGetVarAs vla.$varname.x fltadd
 
246
                        wpGetVarAs hlp.$varname.x do_help
 
247
                        if {[string length $do_help]} {
 
248
                          set subop varhelp
 
249
                          set varhelpname filtconf
 
250
                        } elseif {[string length $fltadd]} {
 
251
                          set script "fr_filtedit.tcl"
 
252
                          set filtedit_add 1
 
253
                          set filtedit_onfiltcancel conf_process
 
254
                        } else {
 
255
                          if {[string length $sz] == 0} {
 
256
                            error [list _action "ERROR" "No size given for filters"]
 
257
                          }
 
258
                          for {set i 0} {$i < $sz} {incr i} {
 
259
                            wpGetVarAs vle.$varname.$i.x vle
 
260
                            wpGetVarAs vld.$varname.$i.x vld
 
261
                            wpGetVarAs vlsu.$varname.$i.x vlsu
 
262
                            wpGetVarAs vlsd.$varname.$i.x vlsd
 
263
                            set flt_ret 0
 
264
                            set flt_res ""
 
265
                            if {[string length $vle]} {
 
266
                              set script "fr_filtedit.tcl"
 
267
                              set filtedit_fno $i
 
268
                              set filtedit_onfiltcancel conf_process
 
269
                            } elseif {[string length $vld]} {
 
270
                              set flt_ret [catch {WPCmd PEConfig ruleset filter delete $i} flt_res]
 
271
                            } elseif {[string length $vlsu]} {
 
272
                              set flt_ret [catch {WPCmd PEConfig ruleset filter shuffup $i} flt_res]
 
273
                            } elseif {[string length $vlsd]} {
 
274
                              set flt_ret [catch {WPCmd PEConfig ruleset filter shuffdown $i} flt_res]
 
275
                            }
 
276
                            if {$flt_ret} {
 
277
                              # error
 
278
                            } elseif {[string length $flt_res]} {
 
279
                              # something wrong here
 
280
                            }
 
281
                          }
 
282
                        }
 
283
                      }
 
284
                      collections {
 
285
                        wpGetVarAs $varname-sz sz
 
286
                        wpGetVarAs vla.$varname.x cladd
 
287
                        if {[string length $cladd]} {
 
288
                          set script "fr_cledit.tcl"
 
289
                          set cledit_add 1
 
290
                          set cledit_onclecancel conf_process
 
291
                        } else {
 
292
                          if {[string length $sz] == 0} {
 
293
                            error [list _action "ERROR" "No size given for collections"]
 
294
                          }
 
295
                          for {set i 0} {$i < $sz} {incr i} {
 
296
                            wpGetVarAs vle.$varname.$i.x vle
 
297
                            wpGetVarAs vld.$varname.$i.x vld
 
298
                            wpGetVarAs vlsu.$varname.$i.x vlsu
 
299
                            wpGetVarAs vlsd.$varname.$i.x vlsd
 
300
                            set cle_ret 0
 
301
                            set cle_res ""
 
302
                            if {[string length $vle]} {
 
303
                              set script "fr_cledit.tcl"
 
304
                              set cledit_cl $i
 
305
                              set cledit_onclecancel conf_process
 
306
                            } elseif {[string length $vld]} {
 
307
                              set cle_ret [catch {WPCmd PEConfig cldel $i} cle_res]
 
308
                            } elseif {[string length $vlsu]} {
 
309
                              set cle_ret [catch {WPCmd PEConfig clshuff up $i} cle_res]
 
310
                            } elseif {[string length $vlsd]} {
 
311
                              set cle_ret [catch {WPCmd PEConfig clshuff down $i} cle_res]
 
312
                            }
 
313
                            if {$cle_ret} {
 
314
                              # error
 
315
                            } elseif {[string length $cle_res]} {
 
316
                              WPCmd PEInfo statmsg $cle_res
 
317
                              # something wrong here
 
318
                            }
 
319
                          }
 
320
                        }
 
321
                      }
 
322
                      index-format {
 
323
                        wpGetVarAs index-format iformat
 
324
 
 
325
                        set varchanged 0
 
326
 
 
327
                        if {$hlpthisvar} {
 
328
                          set subop varhelp
 
329
                          set varhelpname index-format
 
330
                        } elseif {[catch {cgi_import hlp.index_tokens.x} result] == 0} {
 
331
                          set subop secthelp
 
332
                          set topicclass plain
 
333
                          set feathelpname h_index_tokens
 
334
                          set varhelpname h_index_tokens
 
335
                        }
 
336
 
 
337
                        if {[catch {cgi_import indexadd}] == 0
 
338
                            && [string compare "Add Field" $indexadd] == 0
 
339
                            && [catch {cgi_import indexaddfield}] == 0} {
 
340
                          if {[lsearch $iformat $indexaddfield] < 0} {
 
341
                            set iformat [linsert $iformat 0 $indexaddfield]
 
342
                            set varchanged 1
 
343
                          }
 
344
                        } elseif {[catch {cgi_import adjust}] == 0
 
345
                                   && [string compare Change $adjust] == 0
 
346
                                   && [catch {cgi_import iop}] == 0
 
347
                                   && [catch {cgi_import ifield}] == 0
 
348
                                   && [set pos [fieldPos $iformat $ifield]] >= 0} {
 
349
                          switch $iop {
 
350
                            left {
 
351
                              set iformat [lreplace $iformat $pos $pos]
 
352
                              set iformat [linsert $iformat [incr pos -1] $ifield]
 
353
                              set varchanged 1
 
354
                            }
 
355
                            right {
 
356
                              set iformat [lreplace $iformat $pos $pos]
 
357
                              set iformat [linsert $iformat [incr pos] $ifield]
 
358
                              set varchanged 1
 
359
                            }
 
360
                            widen {
 
361
                              set f [lindex [lindex $iformat $pos] 0]
 
362
                              set w [lindex [lindex $iformat $pos] 1]
 
363
                              set dw [expr {round((100/[llength $iformat]) * [WPTFIndexWidthRatio $iformat $f])}]
 
364
 
 
365
                              if {[regexp {([0123456789]+)[%]} $w dummy w] == 0} {
 
366
                                set w $dw
 
367
                              }
 
368
 
 
369
                              if {$w < 95} {
 
370
                                incr w 5
 
371
                              } else {
 
372
                                set w 99
 
373
                              }
 
374
 
 
375
                              if {$w == $dw} {
 
376
                                set ws ""
 
377
                              } else {
 
378
                                set ws "${w}%"
 
379
                              }
 
380
 
 
381
                              set iformat [lreplace $iformat $pos $pos [list $f $ws]]
 
382
                              set varchanged 1
 
383
                            }
 
384
                            narrow {
 
385
                              set f [lindex [lindex $iformat $pos] 0]
 
386
                              set w [lindex [lindex $iformat $pos] 1]
 
387
                              set dw [expr {round((100/[llength $iformat]) * [WPTFIndexWidthRatio $iformat $f])}]
 
388
 
 
389
                              if {[regexp {([0123456789]+)[%]} $w dummy w] == 0} {
 
390
                                set w $dw
 
391
                              }
 
392
 
 
393
                              if {$w > 5} {
 
394
                                incr w -5
 
395
                              } else {
 
396
                                set w 1
 
397
                              }
 
398
 
 
399
                              if {$w == $dw} {
 
400
                                set ws ""
 
401
                              } else {
 
402
                                set ws "${w}%"
 
403
                              }
 
404
 
 
405
                              set iformat [lreplace $iformat $pos $pos [list $f $ws]]
 
406
                              set varchanged 1
 
407
                            }
 
408
                            remove {
 
409
                              set iformat [lreplace $iformat $pos $pos]
 
410
                              set varchanged 1
 
411
                            }
 
412
                          }
 
413
                        } else {
 
414
                          foreach f $iformat {
 
415
                            if {[catch {cgi_import_as shrm.${f}.x shift} result] == 0} {
 
416
                              if {[set pos [fieldPos $iformat $f]] >= 0} {
 
417
                                set iformat [lreplace $iformat $pos $pos]
 
418
                                set varchanged 1
 
419
                              }
 
420
                            } elseif {[catch {cgi_import_as shlf.${f}.x shift} result] == 0} {
 
421
                              if {[set pos [fieldPos $iformat $f]] > 0} {
 
422
                                set iformat [lreplace $iformat $pos $pos]
 
423
                                set iformat [linsert $iformat [incr pos -1] $f]
 
424
                                set varchanged 1
 
425
                              }
 
426
                            } elseif {[catch {cgi_import_as shrt.${f}.x shift} result] == 0} {
 
427
                              if {[set pos [fieldPos $iformat $f]] >= 0} {
 
428
                                set iformat [lreplace $iformat $pos $pos]
 
429
                                set iformat [linsert $iformat [incr pos] $f]
 
430
                                set varchanged 1
 
431
                              }
 
432
                            }
 
433
                          }
 
434
                        }
 
435
 
 
436
                        if {$varchanged} {
 
437
                          foreach f $iformat {
 
438
                            if {[string length [lindex $f 1]]} {
 
439
                              lappend ifv "[lindex $f 0]([lindex $f 1])"
 
440
                            } else {
 
441
                              lappend ifv [lindex $f 0]
 
442
                            }
 
443
                          }
 
444
 
 
445
                          WPCmd PEConfig varset index-format [list $ifv]
 
446
                        }
 
447
                      }
 
448
                      view-colors {
 
449
                        if {$hlpthisvar} {
 
450
                          set subop varhelp
 
451
                          set varhelpname index-format
 
452
                        } elseif {[catch {cgi_import_as colormap.x colx}] == 0
 
453
                                  && [catch {cgi_import_as colormap.y coly}] == 0} {
 
454
                          set rgbs {"000" "051" "102" "153" "204" "255"}
 
455
                          set xrgbs {"00" "33" "66" "99" "CC" "FF"}
 
456
                          set rgblen [llength $rgbs]
 
457
                          set imappixwidth 10
 
458
 
 
459
                          set colx [expr {${colx} / $imappixwidth}]
 
460
                          set coly [expr {${coly} / $imappixwidth}]
 
461
                          if {($coly >= 0 && $coly < $rgblen)
 
462
                              && ($colx >= 0 && $colx < [expr {$rgblen * $rgblen}])} {
 
463
                            set ired $coly
 
464
                            set igreen [expr {($colx / $rgblen) % $rgblen}]
 
465
                            set iblue [expr {$colx % $rgblen}]
 
466
                            set rgb "[lindex $rgbs $ired],[lindex $rgbs ${igreen}],[lindex $rgbs ${iblue}]"
 
467
                            set xrgb "[lindex $xrgbs $ired][lindex $xrgbs ${igreen}][lindex $xrgbs ${iblue}]"
 
468
 
 
469
                            if {[catch {cgi_import_as text tt}] == 0} {
 
470
                              set type [split $tt .]
 
471
                              catch {WPCmd set config_deftext [lindex $type end]}
 
472
 
 
473
                              if {[catch {cgi_import_as ground ground}] == 0} {
 
474
                                switch $ground {
 
475
                                  f {
 
476
                                    catch {WPCmd set config_defground f}
 
477
                                    set fg $xrgb
 
478
                                  }
 
479
                                  b {
 
480
                                    catch {WPCmd set config_defground b}
 
481
                                    set bg $xrgb
 
482
                                  }
 
483
                                }
 
484
 
 
485
                                if {[info exists fg] || [info exists bg]} {
 
486
                                  switch [lindex $type 0] {
 
487
                                    hdr {
 
488
                                      set type [lindex $type 1]
 
489
                                      if {[catch {cgi_import_as add.${type} foo}] == 0} {
 
490
                                        set colop add
 
491
                                      } elseif {[catch {cgi_import_as hi.${type} hindex}] == 0} {
 
492
                                        set colop change
 
493
                                      }
 
494
 
 
495
                                      if {[info exists colop]} {
 
496
                                        if {![info exists bg] && [catch {cgi_import_as dbg.$type bg} result]} {
 
497
                                          WPCmd PEInfo statmsg "Can't import default background: $result"
 
498
                                        } elseif {![info exists fg] && [catch {cgi_import_as dfg.$type fg} result]} {
 
499
                                          WPCmd PEInfo statmsg "Can't import default foreground: $result"
 
500
                                        }
 
501
 
 
502
                                        switch $colop {
 
503
                                          change {
 
504
                                            if {[catch {WPCmd PEConfig colorset viewer-hdr-colors update [list $hindex $type ""] [list $fg $bg]} result]} {
 
505
                                              WPCmd PEInfo statmsg "Problem changing $type color: $result"
 
506
                                            }
 
507
                                          }
 
508
                                          add {
 
509
                                            if {[catch {WPCmd PEConfig colorset viewer-hdr-colors add [list $type ""] [list $fg $bg]} result]} {
 
510
                                              WPCmd PEInfo statmsg "Problem adding $type color: $result"
 
511
                                            }
 
512
                                          }
 
513
                                        }
 
514
 
 
515
                                      }
 
516
                                    }
 
517
                                    default {
 
518
                                      if {![info exists bg] && [catch {cgi_import_as dbg.$type bg} result]} {
 
519
                                        WPCmd PEInfo statmsg "Can't import default background: $result"
 
520
                                      } elseif {![info exists fg] && [catch {cgi_import_as dfg.$type fg} result]} {
 
521
                                        WPCmd PEInfo statmsg "Can't import default foreground: $result"
 
522
                                      } elseif {[catch {WPCmd PEConfig colorset $type [list $fg $bg]} result]} {
 
523
                                        WPCmd PEInfo statmsg "Can't set $type color: $result"
 
524
                                      }
 
525
                                    }
 
526
                                  }
 
527
                                } else {
 
528
                                    WPCmd PEInfo statmsg "Invalid fore/back ground input!"
 
529
                                }
 
530
                              } else {
 
531
                                WPCmd PEInfo statmsg "Choose foreground or background!"
 
532
                              }
 
533
                            } else {
 
534
                              WPCmd PEInfo statmsg "Choose the type of text to color!"
 
535
                            }
 
536
                          } else {
 
537
                            WPCmd PEInfo statmsg "Invalid RGB Input!"
 
538
                          }
 
539
                        } elseif {[catch {cgi_import addfield}] == 0
 
540
                                  && [string compare "add " [string tolower [string range $addfield 0 3]]] == 0
 
541
                                  && [catch {cgi_import newfield}] == 0
 
542
                                  && [string length [set newfield [string trim $newfield]]]
 
543
                                  && [catch {cgi_import_as dfg.normal dfg}] == 0
 
544
                                  && [catch {cgi_import_as dbg.normal dbg}] == 0} {
 
545
                          if {[catch {WPCmd PEConfig colorset viewer-hdr-colors add [list $newfield ""] [list $dfg $dbg]} result]} {
 
546
                            WPCmd PEInfo statmsg "Problem adding $type color: $result"
 
547
                          }
 
548
                        } elseif {[catch {cgi_import reset}] == 0
 
549
                                  && [string compare "restore " [string tolower [string range $reset 0 7]]] == 0} {
 
550
                          if {[catch {cgi_import_as text tt}] == 0} {
 
551
                            if {[llength [set type [split $tt .]]] == 2 && [string compare [lindex $type 0] hdr] == 0} {
 
552
                              set hdr [lindex $type end]
 
553
                              if {[catch {cgi_import_as hi.$hdr hindex}] == 0} {
 
554
                                if {[catch {WPCmd PEConfig colorset viewer-hdr-colors delete $hindex} result]} {
 
555
                                  # bug: reloads cause this error - need better way to report it
 
556
                                  #WPCmd PEInfo statmsg "Can't reset $hdr ($hindex) text: $result!"
 
557
                                } else {
 
558
                                  catch {WPCmd PEInfo unset config_deftext}
 
559
                                }
 
560
                              }
 
561
                            } elseif {[string compare normal $tt] == 0} {
 
562
                              if {[catch {WPCmd PEConfig varset normal-foreground-color ""} result]
 
563
                                  || [catch {WPCmd PEConfig varset normal-background-color ""} result]} {
 
564
                                WPCmd PEInfo statmsg "Can't reset normal text: $result!"
 
565
                              }
 
566
                            } elseif {[catch {cgi_import_as dfg.normal dfg}] == 0
 
567
                                      && [catch {cgi_import_as dbg.normal dbg}] == 0} {
 
568
                              catch {WPCmd set config_deftext $tt}
 
569
                              if {[catch {WPCmd PEConfig colorset $tt [list $dfg $dbg]} result]} {
 
570
                                WPCmd PEInfo statmsg "Can't reset $tt text: $result!"
 
571
                              }
 
572
                            }
 
573
                          } else {
 
574
                            WPCmd PEInfo statmsg "Choose the type of text to color!"
 
575
                          }
 
576
                        }
 
577
                      }
 
578
                    }
 
579
                  }
 
580
                  var {
 
581
                    wpGetVarAs $varname formval
 
582
                    set varvals [WPCmd PEConfig varget $varname]
 
583
                    set vals [lindex $varvals 0]
 
584
                    set vartype [lindex $varvals 1]
 
585
                    set formvals [split $formval "\n"]
 
586
                    set varchanged 0
 
587
 
 
588
                    if {$hlpthisvar} {
 
589
                      set subop varhelp
 
590
                      set varhelpname $varname
 
591
                    }
 
592
 
 
593
                    if {[string compare $vartype textarea] == 0} {
 
594
                      wpGetVarAs vla.$varname.x vlavar
 
595
                      wpGetVarAs $varname-sz sz
 
596
                      wpGetVarAs $varname-add valadd
 
597
                      if {[string length $vlavar]} {
 
598
                        set fr_tconfig_vlavar $varname
 
599
                      }
 
600
                      set formvals {}
 
601
                      if {[string length $valadd]} {
 
602
                        lappend formvals $valadd
 
603
                      }
 
604
                      if {[string length $sz]} {
 
605
                        set prevwassd 0
 
606
                        for {set i 0} {$i < $sz} {incr i} {
 
607
                          wpGetVarAs vle.$varname.$i fval
 
608
                          wpGetVarAs vld.$varname.$i.x fvaldel
 
609
                          wpGetVarAs vlsu.$varname.$i.x fvalsu
 
610
                          wpGetVarAs vlsd.$varname.$i.x fvalsd
 
611
                          set fed 0
 
612
                          set fdel 0
 
613
                          set fsu 0
 
614
                          set fsd 0
 
615
                          if {[string length $fval]} {
 
616
                            set fed 1
 
617
                          }
 
618
                          if {[string length $fvaldel]} {
 
619
                            set fdel 1
 
620
                          } elseif {[string length $fvalsu]} {
 
621
                            set fsu 1
 
622
                          } elseif {[string length $fvalsd]} {
 
623
                            set fsd 1
 
624
                          }
 
625
                          if {$fed && $fdel == 0 && $prevwassd} {
 
626
                            set prevwassd 0
 
627
                            set formvals [linsert $formvals [expr {[llength $formvals] - 1}] $fval]
 
628
                          } elseif {$fed && $fdel == 0 && $fsu == 0} {
 
629
                            lappend formvals $fval
 
630
                            if {$fsd} {
 
631
                              set prevwassd 1
 
632
                            }
 
633
                          } elseif {$fed && $fdel == 0 && $fsu} {
 
634
                            set fvallen [llength $formvals]
 
635
                            if {$fvallen} {
 
636
                              set formvals [linsert $formvals [expr {$fvallen - 2}] $fval]
 
637
                            } else {
 
638
                              lappend formvals $fval
 
639
                            }
 
640
                          }
 
641
                        }
 
642
                      }
 
643
                      set len [llength $formvals]
 
644
                      if {$len != [llength $vals]} {
 
645
                        set varchanged 1
 
646
                      } else {
 
647
                        for {set i 0} {$i < $len} {incr i} {
 
648
                          if {[string compare [lindex $formvals $i] [lindex $vals $i]]} {
 
649
                            set varchanged 1
 
650
                            break
 
651
                          }
 
652
                        }
 
653
                      }
 
654
                    } elseif {[llength $formvals] != [llength $vals]} {
 
655
                      set varchanged 1
 
656
                    } else {
 
657
                      set valslength [llength $vals]
 
658
                      for {set i 0} {$i < $valslength} {incr i} {
 
659
                        if {[string compare [lindex $vals $i] [lindex $formvals $i]]} {
 
660
                          set varchanged 1
 
661
                          break
 
662
                        }
 
663
                      }
 
664
                    }
 
665
                    if {$varchanged} {
 
666
                      WPCmd PEConfig varset $varname $formvals
 
667
                    }
 
668
                    # what about wp-indexheight?
 
669
                  }
 
670
                  feat {
 
671
                    wpGetVarAs $varname tval
 
672
                    if {$hlpthisvar} {
 
673
                      set subop feathelp
 
674
                      set feathelpname $varname
 
675
                    }
 
676
                    set featset [expr {[lsearch $setfeatures $varname] >= 0}]
 
677
                    set formfeatset [expr {[string compare $tval on] == 0}]
 
678
                    if {$formfeatset != $featset} {
 
679
                      WPCmd PEConfig feature $varname $formfeatset
 
680
                    }
 
681
                  }
 
682
                }
 
683
              }
 
684
              if {[info exists subop]} {
 
685
                switch -- $subop {
 
686
                  varhelp {
 
687
                    catch {WPCmd PEInfo unset help_context}
 
688
                    catch {WPCmd set oncancel $oncancel}
 
689
                    set help_vars [list topic topicclass]
 
690
                    set topic $varhelpname
 
691
                    set _cgi_uservar(topic) $varhelpname
 
692
                    set topicclass variable
 
693
                    set _cgi_uservar(topicclass) variable
 
694
                    set _cgi_uservar(oncancel) conf_process
 
695
                    set script help
 
696
                  }
 
697
                  feathelp {
 
698
                    catch {WPCmd PEInfo unset help_context}
 
699
                    catch {WPCmd set oncancel $oncancel}
 
700
                    set help_vars [list topic topicclass oncancel]
 
701
                    set topic $feathelpname
 
702
                    set _cgi_uservar(topic) $feathelpname
 
703
                    set topicclass feature
 
704
                    set _cgi_uservar(topicclass) feature
 
705
                    set _cgi_uservar(oncancel) conf_process
 
706
                    set script help
 
707
                  }
 
708
                  secthelp {
 
709
                    catch {WPCmd PEInfo unset help_context}
 
710
                    catch {WPCmd set oncancel $oncancel}
 
711
                    set help_vars [list topic topicclass oncancel]
 
712
                    set topic $feathelpname
 
713
                    set _cgi_uservar(topic) $feathelpname
 
714
                    set topicclass $topicclass
 
715
                    set _cgi_uservar(topicclass) $topicclass
 
716
                    set _cgi_uservar(oncancel) conf_process
 
717
                    set script help
 
718
                  }
 
719
                  save {
 
720
                    if {$cid != [WPCmd PEInfo key]} {
 
721
                      error [list _close "Invalid Operation ID"]
 
722
                    }
 
723
                    WPCmd PEConfig saveconf
 
724
                    set script $oncancel
 
725
                    catch {WPCmd PEInfo unset config_deftext}
 
726
                  }
 
727
                }
 
728
              }
 
729
            }
 
730
            filtconfig {
 
731
              wpGetVar fno
 
732
              wpGetVar subop
 
733
 
 
734
              if {[catch {wpGetVar filtcancel}]} {
 
735
                if {[catch {wpGetVar filthelp}] == 0} {
 
736
                  catch {WPCmd PEInfo unset help_context}
 
737
                  catch {WPCmd set oncancel $oncancel}
 
738
                  if {[string compare $subop "edit"] == 0 || [string compare $subop "add"] == 0} {
 
739
                    set patlist [wpGetRulePattern]
 
740
                    set actlist [wpGetRuleAction 0]
 
741
                    # we have to save this exactly as it would look when getting it from alpined
 
742
                    set ftsadd [expr {[string compare $subop "add"] == 0 ? 1 : 0}]
 
743
                    set ftsform [list [list "pattern" $patlist] [list "filtaction" $actlist]]
 
744
                    catch {WPCmd set filttmpstate [list $ftsadd $fno $ftsform]}
 
745
                  }
 
746
                  set help_vars [list topic]
 
747
                  set topic filtedit
 
748
                  set _cgi_uservar(topic) filtedit
 
749
                  switch -- $subop {
 
750
                    edit {
 
751
                      set fakeimg "vle.filters.$fno"
 
752
                      set fakesz [expr {$fno + 1}]
 
753
                    }
 
754
                    add  {
 
755
                      set fakeimg "vla.filters"
 
756
                      set fakesz 1
 
757
                    }
 
758
                  }
 
759
 
 
760
                  set _cgi_uservar(oncancel) [WPPercentQuote "conf_process&wv=rule&filters-sz=${fakesz}&${fakeimg}.x=1&${fakeimg}.y=1&oncancel=main.tcl"]
 
761
                  set script help
 
762
                } elseif {[catch {wpGetVar headers}] == 0} {
 
763
                  WPCmd PEInfo statmsg "Should CREATE HEADER"             
 
764
                } else {
 
765
                  switch -- $subop {
 
766
                    edit -
 
767
                    add {
 
768
                      set patlist [wpGetRulePattern]
 
769
                      set actlist [wpGetRuleAction 1]
 
770
                      set ret [catch {WPCmd PEConfig ruleset filter $subop $fno $patlist $actlist} res]
 
771
                      if {$ret} {
 
772
                        error [list _action "Filter Set" $res]
 
773
                      } elseif {[string length $res]} {
 
774
                        WPCmd PEInfo statmsg "Filter setting failed: $res"
 
775
 
 
776
                        set filtedit_fno $fno
 
777
                        set filtedit_add [expr {[string compare $subop add] == 0 ? 1 : 0}]
 
778
                        set filtedit_onfiltcancel conf_process
 
779
                        set script "fr_filtedit.tcl"
 
780
                      }
 
781
                    }
 
782
                  }
 
783
                }
 
784
              }
 
785
            }
 
786
            clconfig {
 
787
              wpGetVar cl
 
788
              wpGetVar nick
 
789
              wpGetVar server
 
790
              wpGetVar user
 
791
              wpGetVar stype
 
792
              wpGetVar path
 
793
              wpGetVar view
 
794
              wpGetVar add
 
795
              wpGetVarAs cle_cancel.x cle_cancel
 
796
              wpGetVarAs cle_save.x cle_save
 
797
 
 
798
              set cledit_add $add
 
799
              set cledit_cl $cl
 
800
              set cledit_onclecancel conf_process
 
801
              if {[string length $cle_save]} {
 
802
                if {[catch {cgi_import_as "ssl" sslval}]} {
 
803
                  set ssl 0
 
804
                } else {
 
805
                  if {[string compare $sslval on] == 0} {
 
806
                    set ssl 1
 
807
                  } else {
 
808
                    set ssl 0
 
809
                  }
 
810
                }
 
811
                regexp "\{?(\[^\}\]*)\}?(.*)" $server match serverb serverrem
 
812
                if {[string length $serverb]} {
 
813
                  if {$ssl == 1} {
 
814
                    set serverb "$serverb/ssl"
 
815
                  }
 
816
                  if {[string compare "" "$user"]} {
 
817
                    set serverb "$serverb/user=$user"
 
818
                  }
 
819
                  if {[string compare "imap" [string tolower $stype]]} {
 
820
                    set serverb "$serverb/[string tolower $stype]"
 
821
                  }
 
822
                  if {[string compare "nntp" [string tolower $stype]] == 0} {
 
823
                    regsub -nocase {^(#news\.)?(.*)$} "$path" "#news.\\2" path
 
824
                    if {[string compare "" $path] == 0} {
 
825
                      set path "#news."
 
826
                    }
 
827
                  }
 
828
                  set result ""
 
829
                  set ret 0
 
830
                  set servera "\{$serverb\}$serverrem"
 
831
                  if {$add} {
 
832
                    set ret [catch {WPCmd PEConfig cladd $cl $nick $servera $path $view} result]
 
833
                  } else {
 
834
                    set ret [catch {WPCmd PEConfig cledit $cl $nick $servera $path $view} result]
 
835
                  }
 
836
                  if {$ret != 0} {
 
837
                    error [list _action "Collection List Set" $result]
 
838
                  } elseif {[string compare "" $result]} {
 
839
                    if {$add} {
 
840
                      set clerrtext "Add failed: $result"
 
841
                    } else {
 
842
                      set clerrtext "Edit failed: $result"
 
843
                    }
 
844
                    WPCmd PEInfo statmsg $clerrtext
 
845
                    set script "fr_cledit.tcl"
 
846
                  }
 
847
                } else {
 
848
                  set clerrtext "Bad data: Nothing defined for Server"
 
849
                  WPCmd PEInfo statmsg $clerrtext
 
850
                  set script "fr_cledit.tcl"
 
851
                }
 
852
              }
 
853
            }
 
854
            noop {
 
855
                catch {WPCmd PEInfo noop}
 
856
            }
 
857
            cancel {
 
858
              set script $oncancel
 
859
              catch {WPCmd PEInfo unset conf_page} res
 
860
            }
 
861
            default {
 
862
                error [list _close "Unknown process operation: $op"]
 
863
            }
 
864
        }
 
865
 
 
866
 
 
867
source [WPTFScript $script]