source: SMSSender/gateways/Schoolnet/ACSchoolnet/ACSchoolnet.pas @ 75:2d7180a9cd99

2.2
Last change on this file since 75:2d7180a9cd99 was 75:2d7180a9cd99, checked in by Sämy Zehnder <saemy.zehnder@…>, 9 years ago
File size: 4.2 KB
Line 
1unit ACSchoolnet;
2
3 {Schoolnet gateway plugin - The SMSSender-plugin for the Schoolnet platform.
4  Copyright (C) 2008-2009, gorrión. See http://www.gorrion.ch
5
6  This program is free software: you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  GNU General Public License for more details.
15
16  You should have received a copy of the GNU General Public License
17  along with this program.  If not, see <http://www.gnu.org/licenses/>.}
18
19interface
20
21uses
22  IniFiles,
23  Interfaces, SchoolnetInterfaces,
24  AbstractAccount, BCTypes;
25
26const
27  PWD_KEY = 'jw;d=5dkjWda[dmYq3*22_3*';
28
29type
30  TACSchoolnet = class(TAbstractLogInOutAccount, IAccount, ILogInOutAccount, ISchoolnetAccount)
31  public
32    constructor Create; override;
33  private
34    FUsername: String;
35    FPassword: String;
36    FSendFrom: TSendFrom;
37  protected
38    function  getGateway: IGateway; override;
39
40    { IAccount }
41    procedure loadAccountFromIni(ini: TIniFile); override;
42    procedure saveAccountToIni(ini: TIniFile); override;
43
44    function  splitTextToLongSMS(text: String): TStringArray; override;
45    function  splitTextToShortSMS(text: String): TStringArray; override;
46
47    { ISchoolnetAccount}
48    function getUsername: String;
49    function getPassword: String;
50    function getSendFrom: TSendFrom;
51
52    procedure parseLoginPage(html: String);
53
54    procedure setUsername(username: String);
55    procedure setPassword(password: String);
56    procedure setSendFrom(sendFrom: TSendFrom);
57  end;
58
59implementation
60
61uses
62  SysUtils, RegExpr,
63  SZPwd,
64  GtwySchoolnet, BCSettings;
65
66constructor TACSchoolnet.Create;
67begin
68  inherited;
69
70  http.ConnectTimeout := 30000; // Increase to 30s
71end;
72
73procedure TACSchoolnet.parseLoginPage(html: String);
74var
75  exp: TRegExpr;
76begin
77  exp := TRegExpr.Create;
78  try
79    with exp do
80    begin
81      ModifierI  := true; {Ignore case}
82      ModifierG  := false; {Non-Greedy - necessary, no idea why, but otherwise it wont find the substrings correctly}
83
84      Expression := '<span id="userSnPoints"><b>(\d*)</b></span>';
85      if not Exec(html) then
86        raise Exception.Create('Can not fetch the free sms count!');
87
88      setFreeSMSCount(StrToInt(Match[1]));
89    end;
90  finally
91    exp.Free;
92  end;
93end;
94
95function TACSchoolnet.getGateway: IGateway;
96begin
97  Result := TGtwySchoolnet.getInstance;
98end;
99
100procedure TACSchoolnet.loadAccountFromIni(ini: TIniFile);
101begin
102  inherited;
103
104  setUsername(ini.ReadString(getAccountId, 'username', ''));
105  setPassword(mapPassword(ini.ReadString(getAccountId, 'password', ''), PWD_KEY));
106  setSendFrom(StrToSendFrom(ini.ReadString(getAccountId, 'sendFrom', sendFromStr[sfMobileNo])));
107end;
108
109procedure TACSchoolnet.saveAccountToIni(ini: TIniFile);
110begin
111  inherited;
112
113  ini.WriteString(getAccountId, 'username', FUsername);
114  ini.WriteString(getAccountId, 'password', '"' + makePassword(FPassword, PWD_KEY).code + '"');
115  ini.WriteString(getAccountId, 'sendFrom', SendFromStr[FSendFrom]);
116end;
117
118function TACSchoolnet.splitTextToLongSMS(text: String): TStringArray;
119begin
120  Result := (getGateway as ISchoolnetGateway).splitTextToLongSMS(text);
121end;
122function TACSchoolnet.splitTextToShortSMS(text: String): TStringArray;
123begin
124  Result := (getGateway as ISchoolnetGateway).splitTextToShortSMS(text);
125end;
126
127function TACSchoolnet.getUsername: String;
128begin
129  Result := FUsername;
130end;                                                           
131function TACSchoolnet.getPassword: String;
132begin
133  Result := FPassword;
134end;
135function TACSchoolnet.getSendFrom: TSendFrom;
136begin
137  Result := FSendFrom;
138end;
139
140procedure TACSchoolnet.setUsername(username: String);
141begin
142  FUsername := username;
143end;
144procedure TACSchoolnet.setPassword(password: String);
145begin
146  FPassword := password;
147end;
148procedure TACSchoolnet.setSendFrom(sendFrom: TSendFrom);
149begin
150  FSendFrom := sendFrom;
151end;
152
153end.
Note: See TracBrowser for help on using the repository browser.