From: ivan Date: Fri, 5 Apr 2002 23:51:18 +0000 (+0000) Subject: - add message catalog table & beginning of web interface X-Git-Tag: freeside_1_4_0_pre12~108 X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=commitdiff_plain;h=87af741da0dd5f6a76bbb566b4d6c54cd5b15315 - add message catalog table & beginning of web interface - add security_phrase and conf option to svc_acct.pm - random other stuff --- diff --git a/ANNOUCE.1.4.0 b/ANNOUCE.1.4.0 index 8bc16ad3d..c1da9dd4c 100644 --- a/ANNOUCE.1.4.0 +++ b/ANNOUCE.1.4.0 @@ -117,3 +117,5 @@ new export! (well, almost) icradius groups (usergroup table if not radgroupreply & radgroupcheck) +message catalogs (infrastructure, anyway) + diff --git a/CREDITS b/CREDITS index 13d286127..3a356f935 100644 --- a/CREDITS +++ b/CREDITS @@ -95,7 +95,7 @@ and will doubtless send more once he's got his tree under control. Luke Pfeifer contributed the "subscription" price plan. Noment Networks, LLC sponsored ICRADIUS/FreeRADIUS -groups. +groups, message catalogs, and signup server enhancements. Everything else is my (Ivan Kohler ) fault. diff --git a/FS/FS/Conf.pm b/FS/FS/Conf.pm index 2bc5e24c0..bda19c0a2 100644 --- a/FS/FS/Conf.pm +++ b/FS/FS/Conf.pm @@ -843,6 +843,21 @@ httemplate/docs/config.html 'type' => 'checkbox', }, + { + 'key' => 'security_phrase', + 'section' => 'password', + 'description' => 'Enable the tracking of a "security phrase" with each account. Not recommended, as it is vulnerable to social engineering.', + 'type' => 'checkbox', + }, + + { + 'key' => 'locale', + 'section' => 'UI', + 'description' => 'Message locale', + 'type' => 'select', + 'select_enum' => [ qw(en_US) ], + }, + ); 1; diff --git a/FS/FS/msgcat.pm b/FS/FS/msgcat.pm new file mode 100644 index 000000000..53a7aeee6 --- /dev/null +++ b/FS/FS/msgcat.pm @@ -0,0 +1,187 @@ +package FS::msgcat; + +use strict; +use vars qw( @ISA @EXPORT_OK $conf $locale ); +use Exporter; +use FS::UID; +use FS::Record qw( qsearchs ); +use FS::Conf; + +@ISA = qw(FS::Record); +@EXPORT_OK = qw( gettext geterror ); + +$FS::UID::callback{'msgcat'} = sub { + $conf = new FS::Conf; + $locale = $conf->config('locale') || 'en_US'; +}; + +=head1 NAME + +FS::msgcat - Object methods for message catalog entries + +=head1 SYNOPSIS + + use FS::msgcat qw(gettext); + + #simple interface for retreiving messages... + $message = gettext('msgcode'); + #or errors (includes the error code) + $message = geterror('msgcode'); + + #maintenance stuff + $record = new FS::msgcat \%hash; + $record = new FS::msgcat { 'column' => 'value' }; + + $error = $record->insert; + + $error = $new_record->replace($old_record); + + $error = $record->delete; + + $error = $record->check; + +=head1 DESCRIPTION + +An FS::msgcat object represents an message catalog entry. FS::msgcat inherits +from FS::Record. The following fields are currently supported: + +=over 4 + +=item msgnum - primary key + +=item msgcode - Error code + +=item locale - Locale + +=item msg - Message + +=back + +=head1 METHODS + +=over 4 + +=item new HASHREF + +Creates a new example. To add the example to the database, see L<"insert">. + +Note that this stores the hash reference, not a distinct copy of the hash it +points to. You can ask the object for a copy with the I method. + +=cut + +# the new method can be inherited from FS::Record, if a table method is defined + +sub table { 'msgcat'; } + +=item insert + +Adds this record to the database. If there is an error, returns the error, +otherwise returns false. + +=cut + +# the insert method can be inherited from FS::Record + +=item delete + +Delete this record from the database. + +=cut + +# the delete method can be inherited from FS::Record + +=item replace OLD_RECORD + +Replaces the OLD_RECORD with this one in the database. If there is an error, +returns the error, otherwise returns false. + +=cut + +# the replace method can be inherited from FS::Record + +=item check + +Checks all fields to make sure this is a valid example. If there is +an error, returns the error, otherwise returns false. Called by the insert +and replace methods. + +=cut + +# the check method should currently be supplied - FS::Record contains some +# data checking routines + +sub check { + my $self = shift; + + my $error = + $self->ut_numbern('msgnum') + || $self->ut_text('msgcode') + || $self->ut_text('msg') + ; + return $error if $error; + + $self->locale =~ /^([\w\@]+)$/ or return "illegal locale: ". $self->locale; + $self->locale($1); + + ''; #no error +} + +=back + +=head1 SUBROUTINES + +=over 4 + +=item gettext MSGCODE + +Returns the full message for the supplied message code. + +=cut + +sub gettext { + my $msgcode = shift; + my $msgcat = qsearchs('msgcat', { + 'msgcode' => $msgcode, + 'locale' => $locale + } ); + if ( $msgcat ) { + $msgcat->msg; + } else { + warn "WARNING: message for msgcode $msgcode in locale $locale not found"; + $msgcode; + } + +} + +=item geterror MSGCODE + +Returns the full message for the supplied message code, including the message +code. + +=cut + +sub geterror { + my $msgcode = shift; + my $msg = gettext($msgcode); + if ( $msg eq $msgcode ) { + "Error code $msgcode (message for locale $locale not found)"; + } else { + "$msg (error code $msgcode)"; + } +} + +=back + +=head1 BUGS + +i18n/l10n is a mess. + +=head1 SEE ALSO + +L, schema.html from the base documentation. + +=cut + +1; + diff --git a/FS/FS/svc_acct.pm b/FS/FS/svc_acct.pm index 197eec1b5..8d22c21e0 100644 --- a/FS/FS/svc_acct.pm +++ b/FS/FS/svc_acct.pm @@ -1079,6 +1079,7 @@ sub check { my $error = $self->ut_numbern('svcnum') || $self->ut_number('domsvc') + || $self->ut_textn('sec_phrase') ; return $error if $error; diff --git a/FS/MANIFEST b/FS/MANIFEST index 8f7dfe591..dd9eb0906 100644 --- a/FS/MANIFEST +++ b/FS/MANIFEST @@ -72,6 +72,7 @@ FS/raddb.pm FS/radius_usergroup.pm FS/queue.pm FS/queue_arg.pm +FS/msgcat.pm t/agent.t t/agent_type.t t/CGI.t @@ -120,5 +121,6 @@ t/svc_www.t t/type_pkgs.t t/queue.t t/queue_arg.t +t/msgcat.t t/UID.t t/raddb.t diff --git a/FS/t/msgcat.t b/FS/t/msgcat.t new file mode 100644 index 000000000..c38c63935 --- /dev/null +++ b/FS/t/msgcat.t @@ -0,0 +1,5 @@ +BEGIN { $| = 1; print "1..1\n" } +END {print "not ok 1\n" unless $loaded;} +use FS::msgcat; +$loaded=1; +print "ok 1\n"; diff --git a/Makefile b/Makefile index 8f577c579..21aeb4566 100644 --- a/Makefile +++ b/Makefile @@ -6,8 +6,8 @@ DATASOURCE = DBI:Pg:host=localhost;dbname=freeside DB_USER = freeside DB_PASSWORD= -TEMPLATE = asp -#TEMPLATE = mason +#TEMPLATE = asp +TEMPLATE = mason ASP_GLOBAL = /usr/local/etc/freeside/asp-global diff --git a/README.1.4.0pre12 b/README.1.4.0pre12 index abbf6e55c..72353ba4c 100644 --- a/README.1.4.0pre12 +++ b/README.1.4.0pre12 @@ -23,12 +23,23 @@ CREATE TABLE radius_usergroup ( CREATE INDEX radius_usergroup1 ON radius_usergroup ( svcnum ); CREATE INDEX radius_usergroup2 ON radius_usergroup ( groupname ); +ALTER TABLE svc_acct ADD sec_phrase varchar(80) NULL; +CREATE TABLE msgcat ( + msgnum int primary key, + msgcode varchar(80) not null, + locale varchar(16) not null, + msg text not null +); +CREATE INDEX msgcat1 ON msgcat ( msgcode, locale ); + Run bin/dbdef-create Run bin/create-history-tables Run bin/dbdef-create again +Run bin/populate-msgcat + the mxmachines, nsmachines, arecords and cnamerecords configuration values have been deprecated. Use the defaultrecords configuration value instead. New export code has landed! If you were using the icradiusmachines, diff --git a/bin/freeside-session-kill b/bin/freeside-session-kill index 9f11abd5b..d5fd703f6 100755 --- a/bin/freeside-session-kill +++ b/bin/freeside-session-kill @@ -98,3 +98,6 @@ foreach my $join ( @session ) { $dbh->commit or die $dbh->errstr; +sub usage { + die "Usage:\n\n freeside-session-kill user\n"; +} diff --git a/bin/fs-setup b/bin/fs-setup index 01e08f77d..55edeb6dd 100755 --- a/bin/fs-setup +++ b/bin/fs-setup @@ -1,6 +1,6 @@ #!/usr/bin/perl -Tw # -# $Id: fs-setup,v 1.84 2002-03-22 18:56:32 ivan Exp $ +# $Id: fs-setup,v 1.85 2002-04-05 23:51:17 ivan Exp $ #to delay loading dbdef until we're ready BEGIN { $FS::Record::setup_hack = 1; } @@ -752,6 +752,7 @@ sub tables_hash_hack { 'svcnum', 'int', '', '', 'username', 'varchar', '', $username_len, #unique (& remove dup code) '_password', 'varchar', '', 50, #13 for encryped pw's plus ' *SUSPENDED* (mp5 passwords can be 34) + 'sec_phrase', 'varchar', 'NULL', $char_d, 'popnum', 'int', 'NULL', '', 'uid', 'int', 'NULL', '', 'gid', 'int', 'NULL', '', @@ -962,6 +963,18 @@ sub tables_hash_hack { 'index' => [ [ 'svcnum' ], [ 'groupname' ] ], }, + 'msgcat' => { + 'columns' => [ + 'msgnum', 'int', '', '', + 'msgcode', 'varchar', '', $char_d, + 'locale', 'varchar', '', 16, + 'msg', 'text', '', '', + ], + 'primary_key' => 'msgnum', + 'unique' => [ [ 'msgcode', 'locale' ] ], + 'index' => [], + }, + ); %tables; diff --git a/bin/populate-msgcat b/bin/populate-msgcat new file mode 100755 index 000000000..fa88732ce --- /dev/null +++ b/bin/populate-msgcat @@ -0,0 +1,45 @@ +#!/usr/bin/perl + +use FS::UID qw(adminsuidsetup); +use FS::msgcat; + +my $user = shift or die &usage; +adminsuidsetup $user; + +foreach my $del_msgcat ( qsearchs('msgcat', {}) ) { + my $error = $del_msgcat->delete; + die $error if $error; +} + +my %messages = messages(); + +foreach $msgcode ( keys %messages ) { + foreach my $locale ( keys %{$messages{$msgcode}} ) { + my $msgcat = new FS::msgcat( { + 'msgcode' => $msgcode, + 'locale' => $locale, + }); + my $error = $msgcat->insert; + die $error if $error; + } +} + +sub messages { + + # 'msgcode' => { + # 'en_US' => 'Message', + # }, + + ( + + 'msgcode' => { + 'en_US' => 'Message', + }, + + ); +} + +sub usage { + die "Usage:\n\n populate-msgcat user\n"; +} + diff --git a/bin/sqlradius_reset b/bin/sqlradius_reset index 501685449..da98fe6be 100644 --- a/bin/sqlradius_reset +++ b/bin/sqlradius_reset @@ -38,8 +38,8 @@ foreach my $export ( @exports ) { } sub usage { - #die "Usage:\n\n icradius_reset user machine\n"; - die "Usage:\n\n icradius_reset user\n"; + #die "Usage:\n\n sqlradius_reset user machine\n"; + die "Usage:\n\n sqlradius_reset user\n"; } diff --git a/conf/locale b/conf/locale new file mode 100644 index 000000000..7741b83a3 --- /dev/null +++ b/conf/locale @@ -0,0 +1 @@ +en_US diff --git a/eg/table_template-svc.pm b/eg/table_template-svc.pm index c5e8f9670..ebf7299d2 100644 --- a/eg/table_template-svc.pm +++ b/eg/table_template-svc.pm @@ -146,10 +146,6 @@ sub check { =back -=head1 VERSION - -$Id: table_template-svc.pm,v 1.2 2001-08-21 02:44:47 ivan Exp $ - =head1 BUGS The author forgot to customize this manpage. diff --git a/eg/table_template.pm b/eg/table_template.pm index 2cc1e1d6e..d609bd544 100644 --- a/eg/table_template.pm +++ b/eg/table_template.pm @@ -98,10 +98,6 @@ sub check { =back -=head1 VERSION - -$Id: table_template.pm,v 1.2 2000-10-27 20:15:50 ivan Exp $ - =head1 BUGS The author forgot to customize this manpage. diff --git a/htetc/global.asa b/htetc/global.asa index 48d0d6fcd..057695183 100644 --- a/htetc/global.asa +++ b/htetc/global.asa @@ -48,6 +48,7 @@ use FS::svc_www; use FS::type_pkgs; use FS::part_export; use FS::part_export_option; +use FS::msgcat qw(gettext geterror); sub Script_OnStart { $Response->AddHeader('Pragma' => 'no-cache'); diff --git a/htetc/handler.pl b/htetc/handler.pl index 1a746a552..2f8146e3e 100644 --- a/htetc/handler.pl +++ b/htetc/handler.pl @@ -105,6 +105,7 @@ sub handler use FS::type_pkgs; use FS::part_export; use FS::part_export_option; + use FS::msgcat qw(gettext geterror); *CGI::redirect = sub { my( $self, $location ) = @_; diff --git a/httemplate/browse/cust_main_county.cgi b/httemplate/browse/cust_main_county.cgi index 8fbd7faad..5df8dfae6 100755 --- a/httemplate/browse/cust_main_county.cgi +++ b/httemplate/browse/cust_main_county.cgi @@ -95,7 +95,6 @@ END print < - END diff --git a/httemplate/browse/msgcat.cgi b/httemplate/browse/msgcat.cgi new file mode 100755 index 000000000..5dab5cfc9 --- /dev/null +++ b/httemplate/browse/msgcat.cgi @@ -0,0 +1,50 @@ + +<% + +print header("Message catalog", menubar( + 'Main Menu' => $p, + 'Edit message catalog' => $p. "edit/msgcat.cgi", +)), '
'; + +my $widget = new HTML::Widgets::SelectLayers( + 'selected_layer' => 'en_US', + 'options' => { 'en_US'=>'en_US' }, + 'layer_callback' => sub { + my $layer = shift; + my $html = "
Messages for locale $layer
". table(). + "Code". + "Message"; + $html .= "en_US Message" unless $layer eq 'en_US'; + $html .= ''; + + #foreach my $msgcat ( sort { $a->msgcode cmp $b->msgcode } + # qsearchs('msgcat', { 'locale' => $layer } ) ) { + foreach my $msgcat ( qsearchs('msgcat', { 'locale' => $layer } ) ) { + $html .= ''. $msgcat->msgnum. ''. + ''. $msgcat->msgcode. ''. + ''. $msgcat->msg. ''; + unless ( $layer eq 'en_US' ) { + my $en_msgcat = qsearchs('msgcat', { + 'locale' => 'en_US', + 'msgcode' => $msgcat->msgcode, + } ); + $html .= ''. $en_msgcat->msg. ''; + } + $html .= ''; + } + + $html .= ''; + $html; + }, + +); + +print $widget->html; + +print < + + +END + +%> diff --git a/httemplate/browse/part_referral.cgi b/httemplate/browse/part_referral.cgi index bbae8d008..93a6976e1 100755 --- a/httemplate/browse/part_referral.cgi +++ b/httemplate/browse/part_referral.cgi @@ -30,7 +30,6 @@ print <Add a new advertising source - END diff --git a/httemplate/browse/svc_acct_pop.cgi b/httemplate/browse/svc_acct_pop.cgi index fb42aa7e6..f8ee58c05 100755 --- a/httemplate/browse/svc_acct_pop.cgi +++ b/httemplate/browse/svc_acct_pop.cgi @@ -44,7 +44,6 @@ print <Add new Access Number - END diff --git a/httemplate/docs/schema.html b/httemplate/docs/schema.html index 192f56ba9..a7c21c7c9 100644 --- a/httemplate/docs/schema.html +++ b/httemplate/docs/schema.html @@ -298,6 +298,7 @@
  • svcnum - primary key
  • username
  • _password +
  • sec_phrase - security phrase
  • popnum - Point of Presence
  • uid
  • gid @@ -389,5 +390,12 @@
  • svcnum - account
  • groupname +
  • msgcat - i18n message catalog +
      +
    • msgnum - primary key +
    • msgcode - message code +
    • locale - locale +
    • msg - Message text +
    diff --git a/httemplate/docs/upgrade8.html b/httemplate/docs/upgrade8.html index 440024de2..a7b5853b3 100644 --- a/httemplate/docs/upgrade8.html +++ b/httemplate/docs/upgrade8.html @@ -179,6 +179,14 @@ CREATE TABLE radius_usergroup ( CREATE INDEX radius_usergroup1 ON radius_usergroup ( svcnum ); CREATE INDEX radius_usergroup2 ON radius_usergroup ( groupname ); +CREATE TABLE msgcat ( + msgnum int primary key, + msgcode varchar(80) not null, + locale varchar(16) not null, + msg text not null +); +CREATE INDEX msgcat1 ON msgcat ( msgcode, locale ); + ALTER TABLE svc_acct ADD domsvc integer NOT NULL; ALTER TABLE svc_domain ADD catchall integer NULL; ALTER TABLE cust_main ADD referral_custnum integer NULL; @@ -198,6 +206,7 @@ ALTER TABLE cust_credit ADD closed char(1) NULL; ALTER TABLE cust_refund ADD closed char(1) NULL; ALTER TABLE cust_bill_event ADD status varchar(80); ALTER TABLE cust_bill_event ADD statustext text NULL; +ALTER TABLE svc_acct ADD sec_phrase varchar(80) NULL; CREATE INDEX cust_main3 ON cust_main ( referral_custnum ); CREATE INDEX cust_credit_bill1 ON cust_credit_bill ( crednum ); CREATE INDEX cust_credit_bill2 ON cust_credit_bill ( invnum ); diff --git a/httemplate/edit/svc_acct.cgi b/httemplate/edit/svc_acct.cgi index 723c91c29..540d04c38 100755 --- a/httemplate/edit/svc_acct.cgi +++ b/httemplate/edit/svc_acct.cgi @@ -122,6 +122,15 @@ print &ntable("#cccccc",2), < END +if ( $conf->exists('security_phrase') ) { + print <Security phrase + + (for forgotten passwords) + +END +} + #domain my $domsvc = $svc_acct->domsvc || 0; if ( $part_svc->part_svc_column('domsvc')->columnflag eq 'F' ) { diff --git a/httemplate/index.html b/httemplate/index.html index fecd107cc..99d8df956 100644 --- a/httemplate/index.html +++ b/httemplate/index.html @@ -186,6 +186,7 @@
  • View/Edit Access Numbers - Points of Presence
  • View/Edit invoice events - Actions for overdue invoices +
  • View/Edit message catalog - Change error messages and other customizable labels.
    diff --git a/httemplate/view/svc_acct.cgi b/httemplate/view/svc_acct.cgi index b779e8774..496dab366 100755 --- a/httemplate/view/svc_acct.cgi +++ b/httemplate/view/svc_acct.cgi @@ -79,6 +79,12 @@ if ( $conf->exists('showpasswords') ) { print ""; $password = ''; +if ( $conf->exists('security_phrase') ) { + my $sec_phrase = $svc_acct->sec_phrase; + print 'Security phrase'. + $svc_acct->sec_phrase. '; +} + my $svc_acct_pop = qsearchs('svc_acct_pop',{'popnum'=>$svc_acct->popnum}); print "Access number". "". $svc_acct_pop->text. ''