summaryrefslogtreecommitdiff
path: root/bin/admin.pl
blob: 1922e69224aa4237f2163dc769905344919639de (plain)
  1. #=====================================================================
  2. # LedgerSMB
  3. # Small Medium Business Accounting software
  4. # http://www.ledgersmb.org/
  5. #
  6. #
  7. # Copyright (C) 2006
  8. # This work contains copyrighted information from a number of sources all used
  9. # with permission.
  10. #
  11. # This file contains source code included with or based on SQL-Ledger which
  12. # is Copyright Dieter Simader and DWS Systems Inc. 2000-2005 and licensed
  13. # under the GNU General Public License version 2 or, at your option, any later
  14. # version. For a full list including contact information of contributors,
  15. # maintainers, and copyright holders, see the CONTRIBUTORS file.
  16. #
  17. # Original Copyright Notice from SQL-Ledger 2.6.17 (before the fork):
  18. # Copyright (c) 2000
  19. #
  20. # Author: DWS Systems Inc.
  21. # Web: http://www.sql-ledger.org
  22. #
  23. # Contributors:
  24. #
  25. #
  26. #======================================================================
  27. #
  28. # This file has undergone whitespace cleanup.
  29. #
  30. #======================================================================
  31. #
  32. # setup module
  33. # add/edit/delete users
  34. #
  35. #======================================================================
  36. $menufile = "menu.ini";
  37. use LedgerSMB::Form;
  38. use LedgerSMB::Locale;
  39. use LedgerSMB::User;
  40. $form = new Form;
  41. $locale = LedgerSMB::Locale->get_handle(${LedgerSMB::Sysconfig::language}) or
  42. $form->error("Locale not loaded: $!\n");
  43. $locale->encoding('UTF-8');
  44. $form->{charset} = 'UTF-8';
  45. #$form->{charset} = $locale->encoding;
  46. eval { require DBI; };
  47. $form->error($locale->text('DBI not installed!')) if ($@);
  48. $form->{stylesheet} = "ledger-smb.css";
  49. $form->{favicon} = "favicon.ico";
  50. $form->{timeout} = 600;
  51. require "bin/pw.pl";
  52. # customization
  53. if (-f "bin/custom/$form->{script}") {
  54. eval { require "bin/custom/$form->{script}"; };
  55. $form->error($@) if ($@);
  56. }
  57. if ($form->{action}) {
  58. &check_password unless $form->{action} eq 'logout';
  59. &{ $form->{action} };
  60. } else {
  61. # if there are no drivers bail out
  62. $form->error($locale->text('No Database Drivers available!')) unless (LedgerSMB::User->dbdrivers);
  63. # create memberfile
  64. if (! -f ${LedgerSMB::Sysconfig::memberfile}) {
  65. open(FH, ">${LedgerSMB::Sysconfig::memberfile}") or $form->error("$memberfile : $!");
  66. print FH qq|# LedgerSMB Accounting members
  67. [root login]
  68. password=
  69. |;
  70. close FH;
  71. }
  72. $root = LedgerSMB::User->new("${LedgerSMB::Sysconfig::memberfile}", "root login");
  73. unless($root && $root->{password}) {
  74. &setup_initial_password();
  75. exit;
  76. }
  77. &adminlogin;
  78. }
  79. 1;
  80. # end
  81. sub setup_initial_password {
  82. $form->header();
  83. print qq|
  84. <body class="admin" onload="sf()">
  85. <div align="center">
  86. <a href="http://www.ledgersmb.org/"><img src="ledger-smb.png" width="200" height="100" border="0" alt="LedgerSMB Logo" /></a>
  87. <h1 class="login">|.$locale->text('Version').qq| $form->{version} <br />|.$locale->text('Administration').qq|</h1>
  88. <fieldset><legend>|.$locale->text('Change password').qq|</legend>
  89. <p>|.$locale->text('This is your first time logging into LedgerSMB. Please set your administrative password').qq|</p>
  90. <form method="post" action="$form->{script}" name="admin">
  91. <table>
  92. <tr>
  93. <th align="right">|.$locale->text('Password').qq|</th>
  94. <td><input type="password" name="new_password" /></td>
  95. </tr>
  96. <tr>
  97. <th align="right">|.$locale->text('Confirm').qq|</th>
  98. <td><input type="password" name="confirm_password" /></td>
  99. </tr>
  100. </table>
  101. <input type="hidden" name="path" value="$form->{path}" />
  102. <input type="hidden" name="sessionid" value="$form->{sessionid}" />
  103. <p><button type="submit" class="submit" name="action" value="change_password">|.$locale->text('Change Password').qq|</button></p>
  104. </form>
  105. <a href="http://www.ledgersmb.org/">|.$locale->text('LedgerSMB website').qq|</a>
  106. </div>
  107. </body>
  108. </html>
  109. |;
  110. }
  111. sub adminlogin {
  112. $form->{title} = qq|LedgerSMB $form->{version} |.$locale->text('Administration');
  113. $myheaderadd = qq|
  114. <script language="JavaScript" type="text/javascript">
  115. <!--
  116. function sf(){
  117. document.admin.password.focus();
  118. }
  119. // End -->
  120. </script>
  121. |;
  122. $form->header(undef, $myheaderadd);
  123. print qq|
  124. <body class="admin" onload="sf()">
  125. <div align="center">
  126. <a href="http://www.ledgersmb.org/"><img src="ledger-smb.png" width="200" height="100" border="0" alt="LedgerSMB Logo" /></a>
  127. <h1 class="login">|.$locale->text('Version').qq| $form->{version} <br />|.$locale->text('Administration').qq|</h1>
  128. <form method="post" action="$form->{script}" name="admin">
  129. <table>
  130. <tr>
  131. <th>|.$locale->text('Password').qq|</th>
  132. <td><input type="password" name="password" /></td>
  133. <td><button type="submit" class="submit" name="action" value="login">|.$locale->text('Login').qq|</button></td>
  134. </tr>
  135. </table>
  136. <input type="hidden" name="action" value="login" />
  137. <input type="hidden" name="path" value="$form->{path}" />
  138. </form>
  139. <p><a href="login.pl"
  140. >|.$locale->text("Application Login").qq|</a></p>
  141. <a href="http://www.ledgersmb.org/">|.$locale->text('LedgerSMB website').qq|</a>
  142. </div>
  143. </body>
  144. </html>
  145. |;
  146. }
  147. sub login {
  148. &list_users;
  149. }
  150. sub logout {
  151. $form->{callback} = "$form->{script}?path=$form->{path}&amp;endsession=1";
  152. unlink "${LedgerSMB::Sysconfig::userspath}/adminhash";
  153. print qq|Set-Cookie: LedgerSMB=; path=/;\n|;
  154. $form->redirect($locale->text('You are logged out'));
  155. }
  156. sub add_user {
  157. $form->{title} = "LedgerSMB ".$locale->text('Accounting')." ".$locale->text('Administration')." / ".$locale->text('Add User');
  158. if (-f "css/ledger-smb.css") {
  159. $myconfig->{stylesheet} = "ledger-smb.css";
  160. }
  161. $myconfig->{vclimit} = 1000;
  162. $myconfig->{menuwidth} = 155;
  163. $myconfig->{timeout} = 3600;
  164. &form_header;
  165. &form_footer;
  166. }
  167. sub edit {
  168. $form->{title} = "LedgerSMB ".$locale->text('Accounting')." ".$locale->text('Administration')." / ".$locale->text('Edit User');
  169. $form->{edit} = 1;
  170. &form_header;
  171. &form_footer;
  172. }
  173. sub form_footer {
  174. if ($form->{edit}) {
  175. $delete = qq|<button type="submit" class="submit" name="action" value="delete">|.$locale->text('Delete').qq|</button>
  176. <input type="hidden" name="edit" value="1" />|;
  177. }
  178. print qq|
  179. <input name="callback" type="hidden" value="$form->{script}?action=list_users&amp;path=$form->{path}&amp;sessionid=$form->{sessionid}" />
  180. <input type="hidden" name="path" value="$form->{path}" />
  181. <input type="hidden" name="sessionid" value="$form->{sessionid}" />
  182. <button type="submit" class="submit" name="action" value="save">|.$locale->text('Save').qq|</button>
  183. $delete
  184. </form>
  185. </body>
  186. </html>
  187. |;
  188. }
  189. sub list_users {
  190. open(FH, "${LedgerSMB::Sysconfig::memberfile}") or $form->error("$memberfile : $!");
  191. $nologin = qq|<button type="submit" class="submit" name="action" value="lock_system">|.$locale->text('Lock System').qq|</button>|;
  192. if (-e "${LedgerSMB::Sysconfig::userspath}/nologin") {
  193. $nologin = qq|<button type="submit" class="submit" name="action" value="unlock_system">|.$locale->text('Unlock System').qq|</button>|;
  194. }
  195. while (<FH>) {
  196. chop;
  197. if (/^\[.*\]/) {
  198. $login = $_;
  199. $login =~ s/(\[|\])//g;
  200. }
  201. if (/^(name=|company=|templates=|dbuser=|dbdriver=|dbname=|dbhost=)/) {
  202. chop ($var = $&);
  203. ($null, $member{$login}{$var}) = split /=/, $_, 2;
  204. }
  205. }
  206. close(FH);
  207. # type=submit $locale->text('Pg Database Administration')
  208. # type=submit $locale->text('PgPP Database Administration')
  209. foreach $item (LedgerSMB::User->dbdrivers) {
  210. $dbdrivers .= qq|<button name="action" type="submit" class="submit" value="|.(lc $item).'_database_administration">'.$locale->text("$item Database Administration").qq|</button>|;
  211. }
  212. $column_header{login} = qq|<th>|.$locale->text('Login').qq|</th>|;
  213. $column_header{name} = qq|<th>|.$locale->text('Name').qq|</th>|;
  214. $column_header{company} = qq|<th>|.$locale->text('Company').qq|</th>|;
  215. $column_header{dbdriver} = qq|<th>|.$locale->text('Driver').qq|</th>|;
  216. $column_header{dbhost} = qq|<th>|.$locale->text('Host').qq|</th>|;
  217. $column_header{dataset} = qq|<th>|.$locale->text('Dataset').qq|</th>|;
  218. $column_header{templates} = qq|<th>|.$locale->text('Templates').qq|</th>|;
  219. @column_index = qw(login name company dbdriver dbhost dataset templates);
  220. $form->{title} = "LedgerSMB ".$locale->text('Accounting')." ".$locale->text('Administration');
  221. $form->{login} = "root login";
  222. $form->header;
  223. print qq|
  224. <body class="admin">
  225. <form method="post" action="$form->{script}">
  226. <table width="100%">
  227. <tr class="listheading">
  228. <th>$form->{title}</th>
  229. </tr>
  230. <tr size="5"></tr>
  231. <tr>
  232. <td>
  233. <table width="100%">
  234. <tr class="listheading">|;
  235. for (@column_index) { print "$column_header{$_}\n" }
  236. print qq| </tr>|;
  237. foreach $key (sort keys %member) {
  238. $href = "$script?action=edit&amp;login=$key&amp;path=$form->{path}&amp;sessionid=$form->{sessionid}";
  239. $href =~ s/ /%20/g;
  240. $member{$key}{templates} =~ s/^${LedgerSMB::Sysconfig::templates}\///;
  241. $member{$key}{dbhost} = $locale->text('localhost') unless $member{$key}{dbhost};
  242. $column_data{login} = qq|<td><a href="$href">$key</a></td>|;
  243. $column_data{name} = qq|<td>$member{$key}{name}</td>|;
  244. $column_data{company} = qq|<td>$member{$key}{company}</td>|;
  245. $column_data{dbdriver} = qq|<td>$member{$key}{dbdriver}</td>|;
  246. $column_data{dbhost} = qq|<td>$member{$key}{dbhost}</td>|;
  247. $column_data{dataset} = qq|<td>$member{$key}{dbname}</td>|;
  248. $column_data{templates} = qq|<td>$member{$key}{templates}</td>|;
  249. $i++; $i %= 2;
  250. print qq| <tr class="listrow$i">|;
  251. for (@column_index) { print "$column_data{$_}\n"; }
  252. print qq| </tr>|;
  253. }
  254. print qq| </table>
  255. </td>
  256. </tr>
  257. <tr>
  258. <td><hr size="3" noshade /></td>
  259. </tr>
  260. </table>
  261. <input type="hidden" name="path" value="$form->{path}" />
  262. <input type="hidden" name="sessionid" value="$form->{sessionid}" />
  263. <br />
  264. <button type="submit" class="submit" name="action" value="add_user">|.$locale->text('Add User').qq|</button>
  265. <button type="submit" class="submit" name="action" value="change_admin_password">|.$locale->text('Change Admin Password').qq|</button>
  266. $dbdrivers
  267. $nologin
  268. <button type="submit" class="submit" name="action" value="logout">|.$locale->text('Logout').qq|</button>
  269. </form>
  270. |.$locale->text('Click on login name to edit!').qq|
  271. <br />
  272. |.$locale->text('To add a user to a group edit a name, change the login name and save. A new user with the same variables will then be saved under the new login name.').qq|
  273. </body>
  274. </html>|;
  275. }
  276. sub form_header {
  277. # if there is a login, get user
  278. if ($form->{login}) {
  279. # get user
  280. $myconfig = LedgerSMB::User->new("${LedgerSMB::Sysconfig::memberfile}", "$form->{login}");
  281. for (qw(company address signature)) { $myconfig->{$_} = $form->quote($myconfig->{$_}) }
  282. for (qw(address signature)) { $myconfig->{$_} =~ s/\\n/\n/g }
  283. # strip basedir from templates directory
  284. $myconfig->{templates} =~ s/^${LedgerSMB::Sysconfig::templates}\///;
  285. $myconfig->{dbpasswd} = unpack 'u', $myconfig->{dbpasswd};
  286. }
  287. foreach $item (qw(mm-dd-yy mm/dd/yy dd-mm-yy dd/mm/yy dd.mm.yy yyyy-mm-dd)) {
  288. $dateformat .= ($item eq $myconfig->{dateformat}) ? "<option selected>$item</option>\n" : "<option>$item</option>\n";
  289. }
  290. my @formats = qw(1,000.00 1000.00 1.000,00 1000,00 1'000.00);
  291. push @formats, '1 000.00';
  292. foreach $item (@formats) {
  293. $numberformat .= ($item eq $myconfig->{numberformat}) ? "<option selected>$item</option>\n" : "<option>$item</option>\n";
  294. }
  295. %countrycodes = LedgerSMB::User->country_codes;
  296. $countrycodes = "";
  297. foreach $key (sort { $countrycodes{$a} cmp $countrycodes{$b} } keys %countrycodes) {
  298. $countrycodes .= ($myconfig->{countrycode} eq $key) ? qq|<option selected value="$key">$countrycodes{$key}</option>|
  299. : qq|<option value="$key">$countrycodes{$key}</option>|;
  300. }
  301. # is there a templates basedir
  302. if (! -d "${LedgerSMB::Sysconfig::templates}") {
  303. $form->error($locale->text('Directory [_1] does not exist', ${LedgerSMB::Sysconfig::templates}));
  304. }
  305. opendir TEMPLATEDIR, "${LedgerSMB::Sysconfig::templates}/." or $form->error("$templates : $!");
  306. @all = grep !/^\.\.?$/, readdir TEMPLATEDIR;
  307. closedir TEMPLATEDIR;
  308. @allhtml = sort grep /\.html/, @all;
  309. @alldir = ();
  310. for (@all) {
  311. if (-d "${LedgerSMB::Sysconfig::templates}/$_") {
  312. push @alldir, $_;
  313. }
  314. }
  315. @allhtml = reverse grep !/Default/, @allhtml;
  316. push @allhtml, 'Default';
  317. @allhtml = reverse @allhtml;
  318. foreach $item (sort @alldir) {
  319. if ($item eq $myconfig->{templates}) {
  320. $usetemplates .= qq|<option selected value="$item">$item</option>\n|;
  321. } else {
  322. $usetemplates .= qq|<option value="$item">$item</option>\n|;
  323. }
  324. }
  325. $lastitem = $allhtml[0];
  326. $lastitem =~ s/-.*//g;
  327. $mastertemplates = qq|<option value="$lastitem">$lastitem</option>\n|;
  328. foreach $item (@allhtml) {
  329. $item =~ s/-.*//g;
  330. if ($item ne $lastitem) {
  331. $mastertemplates .= qq|<option value="$item">$item</option>\n|;
  332. $lastitem = $item;
  333. }
  334. }
  335. opendir CSS, "css/.";
  336. @all = grep /.*\.css$/, readdir CSS;
  337. closedir CSS;
  338. foreach $item (@all) {
  339. if ($item eq $myconfig->{stylesheet}) {
  340. $selectstylesheet .= qq|<option selected value="$item">$item</option>\n|;
  341. } else {
  342. $selectstylesheet .= qq|<option value="$item">$item</option>\n|;
  343. }
  344. }
  345. $selectstylesheet .= "<option></option>\n";
  346. if (%{LedgerSMB::Sysconfig::printer} && ${LedgerSMB::Sysconfig::latex}) {
  347. $selectprinter = "<option></option>\n";
  348. foreach $item (sort keys %{LedgerSMB::Sysconfig::printer}) {
  349. if ($myconfig->{printer} eq $item) {
  350. $selectprinter .= qq|<option value="$item" selected>$item</option>\n|;
  351. } else {
  352. $selectprinter .= qq|<option value="$item">$item</option>\n|;
  353. }
  354. }
  355. $printer = qq|
  356. <tr>
  357. <th align="right">|.$locale->text('Printer').qq|</th>
  358. <td><select name="printer">$selectprinter</select></td>
  359. </tr>
  360. |;
  361. }
  362. $user = $form->{login};
  363. $form->{login} = "root login";
  364. $form->header;
  365. $form->{login} = $user;
  366. print qq|
  367. <body class="admin">
  368. <form method="post" action="$form->{script}">
  369. <table width="100%">
  370. <tr class="listheading"><th colspan="2">$form->{title}</th></tr>
  371. <tr size="5"></tr>
  372. <tr valign="top">
  373. <td>
  374. <table>
  375. <tr>
  376. <th align="right">|.$locale->text('Login').qq|</th>
  377. <td><input name="login" value="$myconfig->{login}" /></td>
  378. </tr>
  379. <tr>
  380. <th align="right">|.$locale->text('Password').qq|</th>
  381. <td><input type="password" name="new_password" size="8" value="$myconfig->{password}" /></td>
  382. <input type="hidden" name="old_password" value="$myconfig->{password}" />
  383. </tr>
  384. <tr>
  385. <th align="right">|.$locale->text('Name').qq|</th>
  386. <td><input name="name" size="15" value="$myconfig->{name}" /></td>
  387. </tr>
  388. <tr>
  389. <th align="right">|.$locale->text('E-mail').qq|</th>
  390. <td><input name="email" size="30" value="$myconfig->{email}" /></td>
  391. </tr>
  392. <tr valign="top">
  393. <th align="right">|.$locale->text('Signature').qq|</th>
  394. <td><textarea name="signature" rows="3" cols="35">$myconfig->{signature}</textarea></td>
  395. </tr>
  396. <tr>
  397. <th align="right">|.$locale->text('Phone').qq|</th>
  398. <td><input name="tel" size="14" value="$myconfig->{tel}" /></td>
  399. </tr>
  400. <tr>
  401. <th align="right">|.$locale->text('Fax').qq|</th>
  402. <td><input name="fax" size="14" value="$myconfig->{fax}" /></td>
  403. </tr>
  404. <tr>
  405. <th align="right">|.$locale->text('Company').qq|</th>
  406. <td><input name="company" size="35" value="$myconfig->{company}" /></td>
  407. </tr>
  408. <tr valign="top">
  409. <th align="right">|.$locale->text('Address').qq|</th>
  410. <td><textarea name="address" rows="4" cols="35">$myconfig->{address}</textarea></td>
  411. </tr>
  412. </table>
  413. </td>
  414. <td>
  415. <table>
  416. <tr>
  417. <th align="right">|.$locale->text('Date Format').qq|</th>
  418. <td><select name="dateformat">$dateformat</select></td>
  419. </tr>
  420. <tr>
  421. <th align="right">|.$locale->text('Number Format').qq|</th>
  422. <td><select name="numberformat">$numberformat</select></td>
  423. </tr>
  424. <tr>
  425. <th align="right">|.$locale->text('Dropdown Limit').qq|</th>
  426. <td><input name="vclimit" value="$myconfig->{vclimit}" /></td>
  427. </tr>
  428. <tr>
  429. <th align="right">|.$locale->text('Menu Width').qq|</th>
  430. <td><input name="menuwidth" value="$myconfig->{menuwidth}" /></td>
  431. </tr>
  432. <tr>
  433. <th align="right">|.$locale->text('Language').qq|</th>
  434. <td><select name="countrycode">$countrycodes</select></td>
  435. </tr>
  436. <tr>
  437. <th align="right">|.$locale->text('Session Timeout').qq|</th>
  438. <td><input name="newtimeout" value="$myconfig->{timeout}" /></td>
  439. </tr>
  440. <tr>
  441. <th align="right">|.$locale->text('Stylesheet').qq|</th>
  442. <td><select name="userstylesheet">$selectstylesheet</select></td>
  443. </tr>
  444. $printer
  445. <tr>
  446. <th align="right">|.$locale->text('Use Templates').qq|</th>
  447. <td><select name="usetemplates">$usetemplates</select></td>
  448. </tr>
  449. <tr>
  450. <th align="right">|.$locale->text('New Templates').qq|</th>
  451. <td><input name="newtemplates" /></td>
  452. </tr>
  453. <tr>
  454. <th align="right">|.$locale->text('Setup Templates').qq|</th>
  455. <td><select name="mastertemplates">$mastertemplates</select></td>
  456. </tr>
  457. </table>
  458. <input type="hidden" name="templates" value="$myconfig->{templates}" />
  459. </td>
  460. </tr>
  461. <tr class="listheading">
  462. <th colspan="2">|.$locale->text('Database').qq|</th>
  463. </tr>|;
  464. # list section for database drivers
  465. foreach $item (LedgerSMB::User->dbdrivers) {
  466. print qq|
  467. <tr>
  468. <td colspan="2">
  469. <table>
  470. <tr>|;
  471. $checked = "checked";
  472. if ($myconfig->{dbdriver} eq $item) {
  473. for (qw(dbhost dbport dbuser dbpasswd dbname sid)) { $form->{"${item}_$_"} = $myconfig->{$_} }
  474. $checked = "checked";
  475. }
  476. print qq|
  477. <th align="right">|.$locale->text('Driver').qq|</th>
  478. <td><input name="dbdriver" type="radio" class="radio" value="$item" $checked />&nbsp;$item</td>
  479. <th align="right">|.$locale->text('Host').qq|</th>
  480. <td><input name="${item}_dbhost" size="30" value="$form->{"${item}_dbhost"}" /></td>
  481. </tr>
  482. <tr>|;
  483. print qq|
  484. <th align="right">|.$locale->text('Dataset').qq|</th>
  485. <td><input name="${item}_dbname" size="15" value="$form->{"${item}_dbname"}" /></td>
  486. <th align="right">|.$locale->text('Port').qq|</th>
  487. <td><input name="${item}_dbport" size="4" value="$form->{"${item}_dbport"}" /></td>
  488. </tr>
  489. <tr>
  490. <th align="right">|.$locale->text('User').qq|</th>
  491. <td><input name="${item}_dbuser" size="15" value="$form->{"${item}_dbuser"}" /></td>
  492. <th align="right">|.$locale->text('Password').qq|</th>
  493. <td><input name="${item}_dbpasswd" type="password" size="10" value="$form->{"${item}_dbpasswd"}" /></td>
  494. </tr>|;
  495. print qq|
  496. </table>
  497. <input type="hidden" name="old_dbpasswd" value="$myconfig->{dbpasswd}" />
  498. </td>
  499. </tr>
  500. <tr>
  501. <td colspan="2"><hr size="2" noshade /></td>
  502. </tr>
  503. |;
  504. }
  505. # access control
  506. open(FH, $menufile) or $form->error("$menufile : $!");
  507. # scan for first menu level
  508. @a = <FH>;
  509. close(FH);
  510. if (open(FH, "custom_$menufile")) {
  511. push @a, <FH>;
  512. }
  513. close(FH);
  514. foreach $item (@a) {
  515. next unless $item =~ /\[\w+/;
  516. next if $item =~ /\#/;
  517. $item =~ s/(\[|\])//g;
  518. chop $item;
  519. if ($item =~ /--/) {
  520. ($level, $menuitem) = split /--/, $item, 2;
  521. } else {
  522. $level = $item;
  523. $menuitem = $item;
  524. push @acsorder, $item;
  525. }
  526. push @{ $acs{$level} }, $menuitem;
  527. }
  528. %role = ( 'admin' => $locale->text('Administrator'),
  529. 'user' => $locale->text('User'),
  530. 'supervisor' => $locale->text('Supervisor'),
  531. 'manager' => $locale->text('Manager'));
  532. $selectrole = "";
  533. foreach $item (qw(user admin supervisor manager)) {
  534. $selectrole .= ($myconfig->{role} eq $item) ? "<option selected value=\"$item\">$role{$item}</option>\n"
  535. : "<option value=\"$item\">$role{$item}</option>\n";
  536. }
  537. print qq|
  538. <tr class="listheading">
  539. <th colspan="2">|.$locale->text('Access Control').qq|</th>
  540. </tr>
  541. <tr>
  542. <td><select name="role">$selectrole</select></td>
  543. </tr>
  544. |;
  545. foreach $item (split /;/, $myconfig->{acs}) {
  546. ($key, $value) = split /--/, $item, 2;
  547. $excl{$key}{$value} = 1;
  548. }
  549. foreach $key (@acsorder) {
  550. $checked = "checked";
  551. if ($form->{login}) {
  552. $checked = ($excl{$key}{$key}) ? "" : "checked";
  553. }
  554. # can't have variable names with & and spaces
  555. $item = $form->escape("${key}--$key",1);
  556. $acsheading = $key;
  557. $acsheading =~ s/ /&nbsp;/g;
  558. $acsheading = qq|
  559. <td align="left" nowrap="nowrap" style="background-color: #C7E9F7" colspan="2">
  560. <input name="$item" class="checkbox" type="checkbox" value="1" $checked />&nbsp;$acsheading</td><tr><td>\n|;
  561. $menuitems .= "$item;";
  562. $acsdata = "<td style=\"background-color: #F0F0F0\">";
  563. foreach $item (@{ $acs{$key} }) {
  564. next if ($key eq $item);
  565. $checked = "checked";
  566. if ($form->{login}) {
  567. $checked = ($excl{$key}{$item}) ? "" : "checked";
  568. }
  569. $acsitem = $form->escape("${key}--$item",1);
  570. $acsdata .= qq|<br /><input name="$acsitem" class="checkbox" type="checkbox" value="1" $checked />&nbsp;$item|;
  571. $menuitems .= "$acsitem;";
  572. }
  573. $acsdata .= "
  574. </td>";
  575. print qq|
  576. <tr valign="top">$acsheading $acsdata
  577. </tr>
  578. |;
  579. }
  580. print qq|<input type="hidden" name="acs" value="$menuitems" />
  581. <tr>
  582. <td colspan="2"><hr size="3" noshade /></td>
  583. </tr>
  584. </table>
  585. </div>
  586. |;
  587. }
  588. sub save {
  589. # no driver checked
  590. $form->error($locale->text('Database Driver not checked!')) unless $form->{dbdriver};
  591. # no spaces allowed in login name
  592. $form->{login} =~ s/ //g;
  593. $form->isblank("login", $locale->text('Login name missing!'));
  594. # check for duplicates
  595. if (!$form->{edit}) {
  596. $temp = LedgerSMB::User->new("${LedgerSMB::Sysconfig::memberfile}", "$form->{login}");
  597. if ($temp->{login}) {
  598. $form->error($locale->text('[_1] is already a member!', $form->{login}));
  599. }
  600. }
  601. # no spaces allowed in directories
  602. $form->{newtemplates} =~ s/( |\.\.|\*)//g;
  603. if ($form->{newtemplates} ne "") {
  604. $form->{templates} = $form->{newtemplates};
  605. } else {
  606. $form->{templates} = ($form->{usetemplates}) ? $form->{usetemplates} : $form->{login};
  607. }
  608. # is there a basedir
  609. if (! -d "${LedgerSMB::Sysconfig::templates}") {
  610. $form->error($locale->text('Directory [_1] does not exist', ${LedgerSMB::Sysconfig::templates}));
  611. }
  612. # add base directory to $form->{templates}
  613. $form->{templates} = "${LedgerSMB::Sysconfig::templates}/$form->{templates}";
  614. $myconfig = LedgerSMB::User->new("${LedgerSMB::Sysconfig::memberfile}", "$form->{login}");
  615. # redo acs variable and delete all the acs codes
  616. @acs = split /;/, $form->{acs};
  617. $form->{acs} = "";
  618. foreach $item (@acs) {
  619. $item = $form->escape($item,1);
  620. if (!$form->{$item}) {
  621. $form->{acs} .= $form->unescape($form->unescape("$item")).";";
  622. }
  623. delete $form->{$item};
  624. }
  625. # check which database was filled in
  626. $form->{dbhost} = $form->{"$form->{dbdriver}_dbhost"};
  627. $form->{dbport} = $form->{"$form->{dbdriver}_dbport"};
  628. $form->{dbpasswd} = $form->{"$form->{dbdriver}_dbpasswd"};
  629. $form->{dbuser} = $form->{"$form->{dbdriver}_dbuser"};
  630. $form->{dbname} = $form->{"$form->{dbdriver}_dbname"};
  631. $form->isblank("dbname", $locale->text('Dataset missing!'));
  632. $form->isblank("dbuser", $locale->text('Database User missing!'));
  633. foreach $item (keys %{$form}) {
  634. $myconfig->{$item} = $form->{$item};
  635. }
  636. $myconfig->{password} = $form->{old_password};
  637. $myconfig->{password} = $form->{new_password} if $form->{new_password} ne $form->{old_password};
  638. $myconfig->{timeout} = $form->{newtimeout};
  639. delete $myconfig->{stylesheet};
  640. if ($form->{userstylesheet}) {
  641. $myconfig->{stylesheet} = $form->{userstylesheet};
  642. }
  643. $myconfig->{packpw} = 1;
  644. $myconfig->save_member(${LedgerSMB::Sysconfig::memberfile}, ${LedgerSMB::Sysconfig::userspath});
  645. # create user template directory and copy master files
  646. if (! -d "$form->{templates}") {
  647. umask(002);
  648. if (mkdir "$form->{templates}", oct("771")) {
  649. umask(007);
  650. # copy templates to the directory
  651. opendir TEMPLATEDIR, "${LedgerSMB::Sysconfig::templates}/." or $form->error("$templates : $!");
  652. @templates = grep /$form->{mastertemplates}-/, readdir TEMPLATEDIR;
  653. closedir TEMPLATEDIR;
  654. foreach $file (@templates) {
  655. open(TEMP, "${LedgerSMB::Sysconfig::templates}/$file") or $form->error("$templates/$file : $!");
  656. $file =~ s/$form->{mastertemplates}-//;
  657. open(NEW, ">$form->{templates}/$file") or $form->error("$form->{templates}/$file : $!");
  658. while ($line = <TEMP>) {
  659. print NEW $line;
  660. }
  661. close(TEMP);
  662. close(NEW);
  663. }
  664. } else {
  665. $form->error("$form->{templates} : $!");
  666. }
  667. }
  668. $form->redirect($locale->text('User saved!'));
  669. }
  670. sub delete {
  671. $form->{templates} = ($form->{templates}) ? "${LedgerSMB::Sysconfig::templates}/$form->{templates}" : "$templates/$form->{login}";
  672. $form->error($locale->text("[_1] locked!",
  673. ${LedgerSMB::Sysconfig::memberfile})) if (-f ${memberfile}.LCK);
  674. open(FH, ">${memberfile}.LCK") or $form->error("${memberfile}.LCK : $!");
  675. close(FH);
  676. if (! open(CONF, "+<${LedgerSMB::Sysconfig::memberfile}")) {
  677. unlink "${memberfile}.LCK";
  678. $form->error("${LedgerSMB::Sysconfig::memberfile} : $!");
  679. }
  680. @config = <CONF>;
  681. seek(CONF, 0, 0);
  682. truncate(CONF, 0);
  683. while ($line = shift @config) {
  684. chop $line;
  685. if ($line =~ /^\[/) {
  686. last if ($line eq "[$form->{login}]");
  687. $login = &login_name($line);
  688. }
  689. if ($line =~ /^templates=/) {
  690. ($null, $user{$login}) = split /=/, $line, 2;
  691. }
  692. print CONF "$line\n";
  693. }
  694. # remove everything up to next login or EOF
  695. # and save template variable
  696. while ($line = shift @config) {
  697. chop $line;
  698. ($key, $value) = split /=/, $line, 2;
  699. $myconfig{$key} = $value;
  700. last if ($line =~ /^\[/);
  701. }
  702. # this one is either the next login or EOF
  703. print CONF "$line\n";
  704. $login = &login_name($line);
  705. while ($line = shift @config) {
  706. chop $line;
  707. if ($line =~ /^\[/) {
  708. $login = &login_name($line);
  709. }
  710. if ($line =~ /^templates=/) {
  711. ($null, $user{$login}) = split /=/, $line, 2;
  712. }
  713. print CONF "$line\n";
  714. }
  715. close(CONF);
  716. unlink "${memberfile}.LCK";
  717. # scan %user for $templatedir
  718. foreach $login (keys %user) {
  719. last if ($found = ($form->{templates} eq $user{$login}));
  720. }
  721. # if found keep directory otherwise delete
  722. if (!$found) {
  723. # delete it if there is a template directory
  724. $dir = "$form->{templates}";
  725. if (-d "$dir") {
  726. unlink <$dir/*>;
  727. rmdir "$dir";
  728. }
  729. }
  730. if ($myconfig{dbconnect}) {
  731. $myconfig{dbpasswd} = unpack 'u', $myconfig{dbpasswd};
  732. for (keys %myconfig) { $form->{$_} = $myconfig{$_} }
  733. LedgerSMB::User->delete_login(\%$form);
  734. # delete config file for user
  735. unlink "${LedgerSMB::Sysconfig::userspath}/$form->{login}.conf";
  736. }
  737. $form->redirect($locale->text('User deleted!'));
  738. }
  739. sub login_name {
  740. my $login = shift;
  741. $login =~ s/\[\]//g;
  742. return ($login) ? $login : undef;
  743. }
  744. sub change_admin_password {
  745. $form->{title} = qq|LedgerSMB |.$locale->text('Accounting')." ".$locale->text('Administration')." / ".$locale->text('Change Admin Password');
  746. $form->{login} = "root login";
  747. $form->header;
  748. print qq|
  749. <body class="admin">
  750. <form method="post" action="$form->{script}">
  751. <table>
  752. <tr class="listheading">
  753. <th>|.$locale->text('Change Password').qq|</th>
  754. </tr>
  755. <tr size="5"></tr>
  756. <tr>
  757. <td>
  758. <table width="100%">
  759. <tr>
  760. <th align="right">|.$locale->text('Password').qq|</th>
  761. <td><input type="password" name="new_password" /></td>
  762. </tr>
  763. <tr>
  764. <th align="right">|.$locale->text('Confirm').qq|</th>
  765. <td><input type="password" name="confirm_password" /></td>
  766. </tr>
  767. </table>
  768. </td>
  769. </tr>
  770. </table>
  771. <br />
  772. <hr size="3" noshade />
  773. <input type="hidden" name="path" value="$form->{path}" />
  774. <input type="hidden" name="sessionid" value="$form->{sessionid}" />
  775. <p><button type="submit" class="submit" name="action" value="change_password">|.$locale->text('Change Password').qq|</button></p>
  776. </form>
  777. </body>
  778. </html>
  779. |;
  780. }
  781. sub change_password {
  782. $form->error($locale->text('Passwords do not match!')) if $form->{new_password} ne $form->{confirm_password};
  783. $root->{password} = $form->{new_password};
  784. $root->{'root login'} = 1;
  785. $root->save_member(${LedgerSMB::Sysconfig::memberfile});
  786. $form->{callback} = "$form->{script}?action=list_users&amp;path=$form->{path}&amp;sessionid=$form->{sessionid}";
  787. $form->redirect($locale->text('Password changed!'));
  788. }
  789. sub get_hash {
  790. use Digest::MD5;
  791. $form->{hash} = Digest::MD5::md5_hex rand();
  792. }
  793. sub check_password {
  794. $root = LedgerSMB::User->new("${LedgerSMB::Sysconfig::memberfile}", "root login");
  795. if ($root->{password}) {
  796. if ($form->{password}) {
  797. $form->{callback} .= "&amp;password=$form->{password}" if $form->{callback};
  798. $form->{sessionid} = time;
  799. if ($root->{password} ne crypt $form->{password}, 'ro') {
  800. &getpassword;
  801. exit;
  802. }
  803. &get_hash;
  804. open(HASHFILE, "> ${LedgerSMB::Sysconfig::userspath}/adminhash") || $form->error("Can't Open Hashfile: $!");
  805. print HASHFILE $form->{hash};
  806. print qq|Set-Cookie: LedgerSMB=$form->{hash}; path=/;\n|;
  807. } else {
  808. if ($ENV{HTTP_USER_AGENT}) {
  809. $ENV{HTTP_COOKIE} =~ s/;\s*/;/g;
  810. %cookie = split /[=;]/, $ENV{HTTP_COOKIE}; # Changeme to %cookies
  811. $cookie = ($form->{path} eq 'bin/lynx') ? $cookie{login} : $cookie{"LedgerSMB-root login"};
  812. #fixes problem with first login and such
  813. if (!(-f "${LedgerSMB::Sysconfig::userspath}/adminhash")) {
  814. &get_hash;
  815. open(HASHFILE, "> ${LedgerSMB::Sysconfig::userspath}/adminhash") || $form->error("Can't Open Hashfile: $!");
  816. print HASHFILE $form->{hash};
  817. close(HASHFILE);
  818. }
  819. open (HASHFILE, "< ${LedgerSMB::Sysconfig::userspath}/adminhash") || $form->error("Can't Open Hashfile: $!");
  820. chomp($form->{hash} = <HASHFILE>);
  821. %cookies = split /[=;]/, $ENV{HTTP_COOKIE};
  822. if (! $cookie || $cookie ne $form->{sessionid} || $form->{hash} ne $cookies{LedgerSMB}) {
  823. &getpassword;
  824. exit;
  825. }
  826. }
  827. }
  828. }
  829. }
  830. sub pg_database_administration {
  831. $form->{dbdriver} = 'Pg';
  832. &dbselect_source;
  833. }
  834. sub pgpp_database_administration {
  835. $form->{dbdriver} = 'PgPP';
  836. &dbselect_source;
  837. }
  838. sub dbdriver_defaults {
  839. # load some defaults for the selected driver
  840. %driverdefaults = ( 'Pg' => { dbport => '',
  841. dbuser => 'ledger-smb',
  842. dbdefault => 'template1',
  843. dbhost => '',
  844. connectstring => $locale->text('Connect to')
  845. } );
  846. $driverdefaults{PgPP} = $driverdefaults{Pg};
  847. for (keys %{ $driverdefaults{Pg} }) { $form->{$_} = $driverdefaults{$form->{dbdriver}}{$_} }
  848. }
  849. sub dbselect_source {
  850. &dbdriver_defaults;
  851. $form->{title} = "LedgerSMB ".$locale->text('Accounting')." / ".$locale->text('Database Administration');
  852. $form->{login} = "root login";
  853. $form->header;
  854. #an insane amount of table nesting here, this should be cleaned up.
  855. print qq|
  856. <body class="admin">
  857. <center>
  858. <h2>$form->{title}</h2>
  859. <form method="post" action="$form->{script}" />
  860. <table>
  861. <tr>
  862. <td>
  863. <table>
  864. <tr class="listheading">
  865. <th colspan="4">|.$locale->text('Database').qq|</th>
  866. </tr>
  867. <tr>
  868. <td>
  869. <table>
  870. <tr>
  871. <th align="right">|.$locale->text('Host').qq|</th>
  872. <td><input name="dbhost" size="25" value="$form->{dbhost}" /></td>
  873. <th align="right">|.$locale->text('Port').qq|</th>
  874. <td><input name="dbport" size="5" value="$form->{dbport}" /></td>
  875. </tr>
  876. <tr>
  877. <th align="right">|.$locale->text('User').qq|</th>
  878. <td><input name="dbuser" size="10" value="$form->{dbuser}" /></td>
  879. <th align="right">|.$locale->text('Password').qq|</th>
  880. <td><input type="password" name="dbpasswd" size="10" /></td>
  881. </tr>
  882. <tr>
  883. <th align="right">$form->{connectstring}</th>
  884. <td colspan="3"><input name="dbdefault" size="10" value="$form->{dbdefault}" /></td>
  885. </tr>
  886. <th align="right">|.$locale->text("Superuser").qq|</th>
  887. <td><input name="dbsuperuser" size="10" value="$form->{dbsuperuser}" /></td>
  888. <th align="right">|.$locale->text('Password').qq|</th>
  889. <td><input type="password" name="dbsuperpasswd" size="10" /></td>
  890. </table>
  891. </td>
  892. </tr>
  893. </table>
  894. </td>
  895. </tr>
  896. </table>
  897. <input type="hidden" name="dbdriver" value="$form->{dbdriver}" />
  898. <input name="callback" type="hidden" value="$form->{script}?action=list_users&amp;path=$form->{path}&amp;sessionid=$form->{sessionid}" />
  899. <input type="hidden" name="path" value="$form->{path}" />
  900. <input type="hidden" name="sessionid" value="$form->{sessionid}" />
  901. <br />
  902. <button type="submit" class="submit" name="action" value="create_dataset">|.$locale->text('Create Dataset').qq|</button>
  903. <button type="submit" class="submit" name="action" value="delete_dataset">|.$locale->text('Delete Dataset').qq|</button>
  904. </form>
  905. <p>|.$locale->text('This is a preliminary check for existing sources. Nothing will be created or deleted at this stage!')
  906. .qq|</p>
  907. </center>
  908. </body>
  909. </html>
  910. |;
  911. }
  912. sub continue {
  913. &{ $form->{nextsub} };
  914. }
  915. sub dbupdate {
  916. LedgerSMB::User->dbupdate(\%$form);
  917. $form->redirect($locale->text('Dataset updated!'));
  918. }
  919. sub create_dataset {
  920. @dbsources = sort LedgerSMB::User->dbsources(\%$form);
  921. opendir SQLDIR, "sql/." or $form->error($!);
  922. foreach $item (sort grep /-chart\.sql/, readdir SQLDIR) {
  923. next if ($item eq 'Default-chart.sql');
  924. $item =~ s/-chart\.sql//;
  925. push @charts, qq|<input name="chart" class="radio" type="radio" value="$item" />$item|;
  926. }
  927. closedir SQLDIR;
  928. # add Default at beginning
  929. unshift @charts, qq|<input name="chart" class="radio" type="radio" value="Default" checked />Default|;
  930. $selectencoding = qq|<option></option>
  931. <option value="SQL_ASCII">ASCII</option>
  932. <option value="EUC_JP">Japanese EUC</option>
  933. <option value="EUC_CN">Chinese EUC</option>
  934. <option value="EUC_KR">Korean EUC</option>
  935. <option value="JOHAB">Korean EUC (Hangle base)</option>
  936. <option value="EUC_TW">Taiwan EUC</option>
  937. <option value="UNICODE">Unicode (UTF-8)</option>
  938. <option value="MULE_INTERNAL">Mule internal type</option>
  939. <option value="LATIN1">ISO 8859-1/ECMA 94 (Latin alphabet no. 1)</option>
  940. <option value="LATIN2">ISO 8859-2/ECMA 94 (Latin alphabet no. 2)</option>
  941. <option value="LATIN3">ISO 8859-3/ECMA 94 (Latin alphabet no. 3)</option>
  942. <option value="LATIN4">ISO 8859-4/ECMA 94 (Latin alphabet no. 4)</option>
  943. <option value="LATIN5">ISO 8859-9/ECMA 128 (Latin alphabet no. 5)</option>
  944. <option value="LATIN6">ISO 8859-10/ECMA 144 (Latin alphabet no. 6)</option>
  945. <option value="LATIN7">ISO 8859-13 (Latin alphabet no. 7)</option>
  946. <option value="LATIN8">ISO 8859-14 (Latin alphabet no. 8)</option>
  947. <option value="LATIN9">ISO 8859-15 (Latin alphabet no. 9)</option>
  948. <option value="LATIN10">ISO 8859-16/ASRO SR 14111 (Latin alphabet no. 10)</option>
  949. <option value="ISO_8859_5">ISO 8859-5/ECMA 113 (Latin/Cyrillic)</option>
  950. <option value="ISO_8859_6">ISO 8859-6/ECMA 114 (Latin/Arabic)</option>
  951. <option value="ISO_8859_7">ISO 8859-7/ECMA 118 (Latin/Greek)</option>
  952. <option value="ISO_8859_8">ISO 8859-8/ECMA 121 (Latin/Hebrew)</option>
  953. <option value="KOI8">KOI8-R(U)</option>
  954. <option value="WIN">Windows CP1251</option>
  955. <option value="ALT">Windows CP866</option>
  956. <option value="WIN1256">Windows CP1256 (Arabic)</option>
  957. <option value="TCVN">Windows CP1258 (Vietnamese)</option>
  958. <option value="WIN874">Windows CP874 (Thai)</option>
  959. |;
  960. $form->{title} = "LedgerSMB ".$locale->text('Accounting')
  961. ." ".$locale->text('Database Administration')
  962. ." / ".$locale->text('Create Dataset');
  963. $form->{login} = "root login";
  964. $form->header;
  965. print qq|
  966. <body class="admin">
  967. <center>
  968. <h2>$form->{title}</h2>
  969. <form method="post" action="$form->{script}" />
  970. <table width="100%">
  971. <tr class="listheading">
  972. <th colspan="2">&nbsp;</th>
  973. </tr>
  974. <tr>
  975. <th align="right" nowrap="nowrap">|.$locale->text('Existing Datasets').qq|</th>
  976. <td>
  977. |;
  978. for (@dbsources) { print "[&nbsp;$_&nbsp;] " }
  979. print qq|
  980. </td>
  981. </tr>
  982. <tr>
  983. <th align="right" nowrap="nowrap">|.$locale->text('Create Dataset').qq|</th>
  984. <td><input name="db" /></td>
  985. </tr>
  986. <tr>
  987. <th align="right" nowrap="nowrap">|.$locale->text('Multibyte Encoding').qq|</th>
  988. <td><select name="encoding">$selectencoding</select></td>
  989. </tr>
  990. <tr>
  991. <th align="right" nowrap="nowrap">|.$locale->text('Create Chart of Accounts').qq|</th>
  992. <td>
  993. <table>
  994. |;
  995. while (@charts) {
  996. print qq| <tr>|;
  997. for (0 .. 2) { print "<td>$charts[$_]</td>\n" }
  998. print qq| </tr>|;
  999. splice @charts, 0, 3;
  1000. }
  1001. print qq| </table>
  1002. </td>
  1003. </tr>
  1004. <tr>
  1005. <td colspan="2">
  1006. <hr size="3" noshade />
  1007. </td>
  1008. </tr>
  1009. </table>
  1010. |;
  1011. $form->hide_form(qw(dbdriver dbsuperuser dbsuperpasswd dbuser dbhost dbport dbpasswd dbdefault path sessionid));
  1012. print qq|
  1013. <input name="callback" type="hidden" value="$form->{script}?action=list_users&amp;path=$form->{path}&amp;sessionid=$form->{sessionid}" />
  1014. <input type="hidden" name="nextsub" value="dbcreate" />
  1015. <br />
  1016. <button type="submit" class="submit" name="action" value="continue">|.$locale->text('Continue').qq|</button>
  1017. </form>
  1018. </body>
  1019. </html>
  1020. |;
  1021. }
  1022. sub dbcreate {
  1023. $form->isblank("db", $locale->text('Dataset missing!'));
  1024. LedgerSMB::User->dbcreate(\%$form);
  1025. $form->{title} = "LedgerSMB ".$locale->text('Accounting')
  1026. ." ".$locale->text('Database Administration')
  1027. ." / ".$locale->text('Create Dataset');
  1028. $form->{login} = "root login";
  1029. $form->header;
  1030. print qq|
  1031. <body class="admin">
  1032. <center>
  1033. <h2>$form->{title}</h2>
  1034. <form method="post" action="$form->{script}">|
  1035. .$locale->text('Dataset [_1] successfully created!', $form->{db})
  1036. .qq|
  1037. <input type="hidden" name="path" value="$form->{path}" />
  1038. <input type="hidden" name="sessionid" value="$form->{sessionid}" />
  1039. <input type="hidden" name="nextsub" value="list_users" />
  1040. <p><button type="submit" class="submit" name="action" value="continue">|.$locale->text('Continue').qq|</button></p>
  1041. </form>
  1042. </center>
  1043. </body>
  1044. </html>
  1045. |;
  1046. }
  1047. sub delete_dataset {
  1048. if (@dbsources = LedgerSMB::User->dbsources_unused(\%$form, ${LedgerSMB::Sysconfig::memberfile})) {
  1049. foreach $item (sort @dbsources) {
  1050. $dbsources .= qq|<input name="db" class="radio" type="radio" value="$item" />&nbsp;$item |;
  1051. }
  1052. } else {
  1053. $form->error($locale->text('Nothing to delete!'));
  1054. }
  1055. $form->{title} = "LedgerSMB ".$locale->text('Accounting')
  1056. ." ".$locale->text('Database Administration')
  1057. ." / ".$locale->text('Delete Dataset');
  1058. $form->{login} = "root login";
  1059. $form->header;
  1060. print qq|
  1061. <body class="admin">
  1062. <h2>$form->{title}</h2>
  1063. <form method="post" action="$form->{script}" />
  1064. <input type="hidden" name="dbdriver" value="$form->{dbdriver}" />
  1065. <input type="hidden" name="dbuser" value="$form->{dbuser}" />
  1066. <input type="hidden" name="dbhost" value="$form->{dbhost}" />
  1067. <input type="hidden" name="dbport" value="$form->{dbport}" />
  1068. <input type="hidden" name="dbpasswd" value="$form->{dbpasswd}" />
  1069. <input type="hidden" name="dbdefault" value="$form->{dbdefault}" />
  1070. <input name=callback type="hidden" value="$form->{script}?action=list_users&amp;path=$form->{path}&amp;sessionid=$form->{sessionid}">
  1071. <input type="hidden" name="path" value="$form->{path}" />
  1072. <input type="hidden" name="sessionid" value="$form->{sessionid}" />
  1073. <input type="hidden" name="nextsub" value="dbdelete" />
  1074. <table width="100%">
  1075. <tr class="listheading">
  1076. <th>|.$locale->text('The following Datasets are not in use and can be deleted').qq|</th>
  1077. </tr>
  1078. <tr>
  1079. <td>
  1080. $dbsources
  1081. </td>
  1082. </tr>
  1083. <tr>
  1084. <td>
  1085. <hr size="3" noshade />
  1086. <br />
  1087. <button type="submit" class="submit" name="action" value="continue">|.$locale->text('Continue').qq|</button>
  1088. </td>
  1089. </tr>
  1090. </table>
  1091. </form>
  1092. </body>
  1093. </html>
  1094. |;
  1095. }
  1096. sub dbdelete {
  1097. if (!$form->{db}) {
  1098. $form->error($locale->text('No Dataset selected!'));
  1099. }
  1100. LedgerSMB::User->dbdelete(\%$form);
  1101. $form->{title} = "LedgerSMB ".$locale->text('Accounting')
  1102. ." ".$locale->text('Database Administration')
  1103. ." / ".$locale->text('Delete Dataset');
  1104. $form->{login} = "root login";
  1105. $form->header;
  1106. print qq|
  1107. <body class="admin">
  1108. <center>
  1109. <h2>$form->{title}</h2>
  1110. $form->{db} |.$locale->text('successfully deleted!')
  1111. .qq|
  1112. <form method="post" action="$form->{script}" />
  1113. <input type="hidden" name="path" value="$form->{path}" />
  1114. <input type="hidden" name="sessionid" value="$form->{sessionid}" />
  1115. <input type="hidden" name="nextsub" value="list_users" />
  1116. <p><button type="submit" class="submit" name="action" value="continue">|.$locale->text('Continue').qq|</button></p>
  1117. </form>
  1118. </body>
  1119. </html>
  1120. |;
  1121. }
  1122. sub unlock_system {
  1123. unlink "${LedgerSMB::Sysconfig::userspath}/nologin";
  1124. $form->{callback} = "$form->{script}?action=list_users&amp;path=$form->{path}&amp;sessionid=$form->{sessionid}";
  1125. $form->redirect($locale->text('Lockfile removed!'));
  1126. }
  1127. sub lock_system {
  1128. open(FH, ">${LedgerSMB::Sysconfig::userspath}/nologin") or $form->error($locale->text('Cannot create Lock!'));
  1129. close(FH);
  1130. $form->{callback} = "$form->{script}?action=list_users&amp;path=$form->{path}&amp;sessionid=$form->{sessionid}";
  1131. $form->redirect($locale->text('Lockfile created!'));
  1132. }