summaryrefslogtreecommitdiff
path: root/doc/samples/lsmb02-cli-example.pl
blob: e0084c018143195e60eb84c8507ab0ba56aa262c (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 = 'path=bin/mozilla&login=' . $login . '&password=' . $pwd .
  48. '&action=' . escape(substr($rec[0],0,35)) .
  49. '&db=' . $rec[1] .
  50. '&name=' . escape(substr($rec[2],0,35)) .
  51. '&vendornumber=' . $rec[3] .
  52. '&address1=' . escape(substr($rec[4],0,35)) .
  53. '&address2=' . escape(substr($rec[5],0,35)) .
  54. '&city=' . escape(substr($rec[6],0,35)) .
  55. '&state=' . escape(substr($rec[7],0,35)) .
  56. '&zipcode=' . escape(substr($rec[8],0,35)) .
  57. '&country=' . escape(substr($rec[9],0,35)) .
  58. '&phone=' . escape(substr($rec[10],0,20)) .
  59. '&tax_2150=1' .
  60. '&taxaccounts=2150' .
  61. '&taxincluded=0' .
  62. '&terms=0';
  63. $rc=runLScmd("./ct.pl",$arg);
  64. if ($rc =~ m/Vendor saved!/) {
  65. print "$rec[2] SAVED\n";
  66. } else {
  67. print "$rec[2] ERROR\n";
  68. }
  69. }
  70. $cmd = "login=" . $login . '&password=' . $pwd . '&path=bin&action=logout';
  71. $signin = runLScmd("./login.pl",$cmd);
  72. if ( $signin =~ m/Error:/ ) {
  73. print "\nLogout error\n";
  74. }
  75. exit;
  76. #*******************************************************
  77. # Subroutines
  78. #*******************************************************
  79. sub runLScmd {
  80. my $cmd = shift;
  81. my $args = shift;
  82. my $i = 0;
  83. my $results;
  84. local $CWD = "/usr/local/ledger-smb/";
  85. $cmd = $cmd . " \"" . $args . "\"";
  86. $results = `$cmd 2>&1`;
  87. return $results;
  88. }
  89. sub escape {
  90. my $str = shift;
  91. if ($str) {
  92. decode_entities($str);
  93. $str =~ s/([^a-zA-Z0-9_.-])/sprintf("%%%02x", ord($1))/ge;
  94. }
  95. return $str;
  96. }
  97. #*******************************************************
  98. # Record Format
  99. #*******************************************************
  100. #
  101. # action | db | name | vendornumber | address1 | address2 | city | state | zipcode | country | phone
  102. #
  103. __END__
  104. save|vendor|Parts are Us|1377|238 Riverview|Suite 11|Cheese Head|WI|56743|USA|555-123-3322|
  105. save|vendor|Widget Heaven|1378|41 S. Riparian Way||Show Me|MO|39793|USA|555-231-3309|
  106. save|vendor|Consolidated Spackle|1379|1010 Binary Lane|Dept 1101|Beverly Hills|CA|90210|USA|555-330-7639 x772|