summaryrefslogtreecommitdiff
path: root/doc/samples/lsmb02-cli-example.pl
blob: 2aa2657ee4200503266e41847893d3278389e7ce (plain)
  1. #!/usr/bin/perl -w
  2. #
  3. # File: lsmb02-cli-example.pl
  4. # Environment: Ledger-SMB 1.2.0+
  5. # Author: Louis B. Moore
  6. #
  7. # Copyright (C) 2006 Louis B. Moore
  8. #
  9. # This program is free software; you can redistribute it and/or
  10. # modify it under the terms of the GNU General Public License
  11. # as published by the Free Software Foundation; either version 2
  12. # of the License, or (at your option) any later version.
  13. #
  14. # This program is distributed in the hope that it will be useful,
  15. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. # GNU General Public License for more details.
  18. #
  19. # You should have received a copy of the GNU General Public License
  20. # along with this program; if not, write to the Free Software
  21. # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  22. #
  23. # Revision:
  24. # $Id$
  25. #
  26. #
  27. use File::chdir;
  28. use HTML::Entities;
  29. print "\n\nLedger-SMB login: ";
  30. my $login = <STDIN>;
  31. chomp($login);
  32. print "\nLedger-SMB password: ";
  33. system("stty -echo");
  34. my $pwd = <STDIN>;
  35. system("stty echo");
  36. chomp($pwd);
  37. print "\n\n";
  38. $cmd = "login=" . $login . '&password=' . $pwd . '&path=bin&action=login';
  39. $signin = runLScmd( "./login.pl", $cmd );
  40. if ( $signin =~ m/Error:/ ) {
  41. print "\nLogin error\n";
  42. exit;
  43. }
  44. while (<main::DATA>) {
  45. chomp;
  46. @rec = split(/\|/);
  47. $arg =
  48. 'path=bin/mozilla&login=' . $login
  49. . '&password='
  50. . $pwd
  51. . '&action='
  52. . escape( substr( $rec[0], 0, 35 ) ) . '&db='
  53. . $rec[1]
  54. . '&name='
  55. . escape( substr( $rec[2], 0, 35 ) )
  56. . '&vendornumber='
  57. . $rec[3]
  58. . '&address1='
  59. . escape( substr( $rec[4], 0, 35 ) )
  60. . '&address2='
  61. . escape( substr( $rec[5], 0, 35 ) )
  62. . '&city='
  63. . escape( substr( $rec[6], 0, 35 ) )
  64. . '&state='
  65. . escape( substr( $rec[7], 0, 35 ) )
  66. . '&zipcode='
  67. . escape( substr( $rec[8], 0, 35 ) )
  68. . '&country='
  69. . escape( substr( $rec[9], 0, 35 ) )
  70. . '&phone='
  71. . escape( substr( $rec[10], 0, 20 ) )
  72. . '&tax_2150=1'
  73. . '&taxaccounts=2150'
  74. . '&taxincluded=0'
  75. . '&terms=0';
  76. $rc = runLScmd( "./ct.pl", $arg );
  77. if ( $rc =~ m/Vendor saved!/ ) {
  78. print "$rec[2] SAVED\n";
  79. }
  80. else {
  81. print "$rec[2] ERROR\n";
  82. }
  83. }
  84. $cmd = "login=" . $login . '&password=' . $pwd . '&path=bin&action=logout';
  85. $signin = runLScmd( "./login.pl", $cmd );
  86. if ( $signin =~ m/Error:/ ) {
  87. print "\nLogout error\n";
  88. }
  89. exit;
  90. #*******************************************************
  91. # Subroutines
  92. #*******************************************************
  93. sub runLScmd {
  94. my $cmd = shift;
  95. my $args = shift;
  96. my $i = 0;
  97. my $results;
  98. local $CWD = "/usr/local/ledger-smb/";
  99. $cmd = $cmd . " \"" . $args . "\"";
  100. $results = `$cmd 2>&1`;
  101. return $results;
  102. }
  103. sub escape {
  104. my $str = shift;
  105. if ($str) {
  106. decode_entities($str);
  107. $str =~ s/([^a-zA-Z0-9_.-])/sprintf("%%%02x", ord($1))/ge;
  108. }
  109. return $str;
  110. }
  111. #*******************************************************
  112. # Record Format
  113. #*******************************************************
  114. #
  115. # action | db | name | vendornumber | address1 | address2 | city | state | zipcode | country | phone
  116. #
  117. __END__
  118. save|vendor|Parts are Us|1377|238 Riverview|Suite 11|Cheese Head|WI|56743|USA|555-123-3322|
  119. save|vendor|Widget Heaven|1378|41 S. Riparian Way||Show Me|MO|39793|USA|555-231-3309|
  120. save|vendor|Consolidated Spackle|1379|1010 Binary Lane|Dept 1101|Beverly Hills|CA|90210|USA|555-330-7639 x772|