]> git.stg.codes - stg.git/blob - projects/stargazer/plugins/configuration/sgconfig-ng/parser_getusers.cpp
Fix comilation issues for sgauth
[stg.git] / projects / stargazer / plugins / configuration / sgconfig-ng / parser_getusers.cpp
1 // TODO: Fix this shit!
2 #include "../../../admin.h"
3 #include "../../../users.h"
4
5 #include "parser_getusers.h"
6
7 PARSER_GET_USERS::PARSER_GET_USERS(const ADMIN * ca, USERS * u)
8     : PARSER(),
9       result("<error message=\"Not implemented yet\"/>"),
10       currAdmin(ca),
11       users(u)
12 {
13 }
14
15 PARSER_GET_USERS::~PARSER_GET_USERS()
16 {
17 }
18
19 bool PARSER_GET_USERS::StartTag(const char * name, const char ** attr)
20 {
21     std::string tag(name);
22     if (tag != "GetUsers") {
23         return false;
24     }
25
26     return true;
27 }
28
29 bool PARSER_GET_USERS::EndTag(const char * name)
30 {
31     std::string tag(name);
32     if (tag != "GetUsers") {
33         return false;
34     }
35
36     int handle = users->OpenSearch();
37     if (!handle) {
38         printfd(__FILE__, "PARSER_GET_USERS::EndTag() OpenSearch error\n");
39         users->CloseSearch(handle);
40         result = "<error message=\"Internal error (OpenSearch failed)\"/>";
41         return false;
42     }
43
44     std::stringstream answer;
45
46     answer << "<Users>\n";
47
48     while (1) {
49         user_iter ui;
50
51         if (users->SearchNext(handle, &ui)) {
52             break;
53         }
54
55         answer << "\t<User>\n";
56         answer << "\t\t<login value=\"" << ui->GetLogin() << "\"/>\n";
57         if (currAdmin->GetPriv()->userConf || currAdmin->GetPriv()->userPasswd) {
58             answer << "\t\t<password value=\"" << ui->property.password.Get() << "\"/>\n";
59         } else {
60             answer << "\t\t<password value=\"++++++++\"/>\n";
61         }
62         answer << "\t\t<cash value=\"" << ui->property.cash.Get() << "\"/>\n";
63         answer << "\t\t<freemb value=\"" << ui->property.freeMb.Get() << "\"/>\n";
64         answer << "\t\t<credit value=\"" << ui->property.credit.Get() << "\"/>\n";
65         if (ui->property.nextTariff.Get() != "") {
66             answer << "\t\t<tariff value=\"" << ui->property.tariffName.Get()
67                    << "/" << ui->property.nextTariff.Get() << "\"/>\n";
68         } else {
69             answer << "\t\t<tariff value=\"" << ui->property.tariffName.Get() << "\"/>\n";
70         }
71
72         std::string encoded;
73         Encode12str(encoded, ui->property.note.Get());
74         answer << "\t\t<note value=\"" << encoded << "\"/>\n";
75         Encode12str(encoded, ui->property.phone.Get());
76         answer << "\t\t<phone value=\"" << encoded << "\"/>\n";
77         Encode12str(encoded, ui->property.address.Get());
78         answer << "\t\t<address value=\"" << encoded << "\"/>\n";
79         Encode12str(encoded, ui->property.email.Get());
80         answer << "\t\t<email value=\"" << encoded << "\"/>\n";
81         Encode12str(encoded, ui->property.realName.Get());
82         answer << "\t\t<name value=\"" << encoded << "\"/>\n";
83         Encode12str(encoded, ui->property.group.Get());
84         answer << "\t\t<group value=\"" << encoded << "\"/>\n";
85
86         // TODO: Fix this shit!
87         // <SHIT_BEGIN>
88         Encode12str(encoded, ui->property.userdata0.Get()); answer << "\t\t<userdata0 value=\"" << encoded << "\"/>\n";
89         Encode12str(encoded, ui->property.userdata1.Get()); answer << "\t\t<userdata1 value=\"" << encoded << "\"/>\n";
90         Encode12str(encoded, ui->property.userdata2.Get()); answer << "\t\t<userdata2 value=\"" << encoded << "\"/>\n";
91         Encode12str(encoded, ui->property.userdata3.Get()); answer << "\t\t<userdata3 value=\"" << encoded << "\"/>\n";
92         Encode12str(encoded, ui->property.userdata4.Get()); answer << "\t\t<userdata4 value=\"" << encoded << "\"/>\n";
93         Encode12str(encoded, ui->property.userdata5.Get()); answer << "\t\t<userdata5 value=\"" << encoded << "\"/>\n";
94         Encode12str(encoded, ui->property.userdata6.Get()); answer << "\t\t<userdata6 value=\"" << encoded << "\"/>\n";
95         Encode12str(encoded, ui->property.userdata7.Get()); answer << "\t\t<userdata7 value=\"" << encoded << "\"/>\n";
96         Encode12str(encoded, ui->property.userdata8.Get()); answer << "\t\t<userdata8 value=\"" << encoded << "\"/>\n";
97         Encode12str(encoded, ui->property.userdata9.Get()); answer << "\t\t<userdata9 value=\"" << encoded << "\"/>\n";
98         // <SHIT_END>
99
100         answer << "\t\t<status value=\"" << ui->GetConnected() << "\"/>\n";
101         answer << "\t\t<aonline value=\"" << ui->property.alwaysOnline.Get() << "\"/>\n";
102         answer << "\t\t<currip value=\"" << inet_ntostring(ui->GetCurrIP()) << "\"/>\n";
103         answer << "\t\t<pingtime value=\"" << ui->GetPingTime() << "\"/>\n";
104         answer << "\t\t<ip value=\"" << ui->property.ips.Get() << "\"/>\n";
105         answer << "\t\t<lastcash value=\"" << ui->property.lastCashAdd.Get() << "\"/>\n";
106         answer << "\t\t<lasttimecash value=\"" << ui->property.lastCashAddTime.Get() << "\"/>\n";
107         answer << "\t\t<lastactivitytime value=\"" << ui->property.lastActivityTime.Get() << "\"/>\n";
108         answer << "\t\t<creditexpire value=\"" << ui->property.creditExpire.Get() << "\"/>\n";
109         answer << "\t\t<down value=\"" << ui->property.disabled.Get() << "\"/>\n";
110         answer << "\t\t<passive value=\"" << ui->property.passive.Get() << "\"/>\n";
111         answer << "\t\t<disabledetailstat value=\"" << ui->property.disabledDetailStat.Get() << "\"/>\n";
112
113         // TODO: Fix this shit!
114         // <SHIT_BEGIN>
115         answer << "\t\t<traff ";
116         DIR_TRAFF up(ui->property.up.Get());
117         DIR_TRAFF down(ui->property.down.Get());
118         for (int i = 0; i < DIR_NUM; ++i) {
119             answer << "MU" << i << "=\"" << up[i] << "\" ";
120             answer << "MD" << i << "=\"" << down[i] << "\" ";
121         }
122         answer << "/>\n";
123         // <SHIT_END>
124
125         answer << "\t</User>\n";
126     }
127
128     answer << "</Users>";
129
130     users->CloseSearch(handle);
131
132     result = answer.str();
133
134     return true;
135 }