summaryrefslogtreecommitdiff
path: root/bin/admin.pl
blob: 9642fc62ccb41d01751c6ddb4dd5034de390f582 (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 (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 = new User "${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>Change password</legend>
  89. <p>This is your first time logging into LedgerSMB. Please set your administrative password</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/">LedgerSMB |.$locale->text('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/">LedgerSMB |.$locale->text('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 (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 = new User "${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 = 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. $countrycodes = qq|<option value="">English</option>\n$countrycodes|;
  302. # is there a templates basedir
  303. if (! -d "${LedgerSMB::Sysconfig::templates}") {
  304. $form->error($locale->text('Directory').": ${LedgerSMB::Sysconfig::templates} ".$locale->text('does not exist'));
  305. }
  306. opendir TEMPLATEDIR, "${LedgerSMB::Sysconfig::templates}/." or $form->error("$templates : $!");
  307. @all = grep !/^\.\.?$/, readdir TEMPLATEDIR;
  308. closedir TEMPLATEDIR;
  309. @allhtml = sort grep /\.html/, @all;
  310. @alldir = ();
  311. for (@all) {
  312. if (-d "${LedgerSMB::Sysconfig::templates}/$_") {
  313. push @alldir, $_;
  314. }
  315. }
  316. @allhtml = reverse grep !/Default/, @allhtml;
  317. push @allhtml, 'Default';
  318. @allhtml = reverse @allhtml;
  319. foreach $item (sort @alldir) {
  320. if ($item eq $myconfig->{templates}) {
  321. $usetemplates .= qq|<option selected value="$item">$item</option>\n|;
  322. } else {
  323. $usetemplates .= qq|<option value="$item">$item</option>\n|;
  324. }
  325. }
  326. $lastitem = $allhtml[0];
  327. $lastitem =~ s/-.*//g;
  328. $mastertemplates = qq|<option value="$lastitem">$lastitem</option>\n|;
  329. foreach $item (@allhtml) {
  330. $item =~ s/-.*//g;
  331. if ($item ne $lastitem) {
  332. $mastertemplates .= qq|<option value="$item">$item</option>\n|;
  333. $lastitem = $item;
  334. }
  335. }
  336. opendir CSS, "css/.";
  337. @all = grep /.*\.css$/, readdir CSS;
  338. closedir CSS;
  339. foreach $item (@all) {
  340. if ($item eq $myconfig->{stylesheet}) {
  341. $selectstylesheet .= qq|<option selected value="$item">$item</option>\n|;
  342. } else {
  343. $selectstylesheet .= qq|<option value="$item">$item</option>\n|;
  344. }
  345. }
  346. $selectstylesheet .= "<option></option>\n";
  347. if (%{LedgerSMB::Sysconfig::printer} && ${LedgerSMB::Sysconfig::latex}) {
  348. $selectprinter = "<option></option>\n";
  349. foreach $item (sort keys %{LedgerSMB::Sysconfig::printer}) {
  350. if ($myconfig->{printer} eq $item) {
  351. $selectprinter .= qq|<option value="$item" selected>$item</option>\n|;
  352. } else {
  353. $selectprinter .= qq|<option value="$item">$item</option>\n|;
  354. }
  355. }
  356. $printer = qq|
  357. <tr>
  358. <th align="right">|.$locale->text('Printer').qq|</th>
  359. <td><select name="printer">$selectprinter</select></td>
  360. </tr>
  361. |;
  362. }
  363. $user = $form->{login};
  364. $form->{login} = "root login";
  365. $form->header;
  366. $form->{login} = $user;
  367. print qq|
  368. <body class="admin">
  369. <form method="post" action="$form->{script}">
  370. <table width="100%">
  371. <tr class="listheading"><th colspan="2">$form->{title}</th></tr>
  372. <tr size="5"></tr>
  373. <tr valign="top">
  374. <td>
  375. <table>
  376. <tr>
  377. <th align="right">|.$locale->text('Login').qq|</th>
  378. <td><input name="login" value="$myconfig->{login}" /></td>
  379. </tr>
  380. <tr>
  381. <th align="right">|.$locale->text('Password').qq|</th>
  382. <td><input type="password" name="new_password" size="8" value="$myconfig->{password}" /></td>
  383. <input type="hidden" name="old_password" value="$myconfig->{password}" />
  384. </tr>
  385. <tr>
  386. <th align="right">|.$locale->text('Name').qq|</th>
  387. <td><input name="name" size="15" value="$myconfig->{name}" /></td>
  388. </tr>
  389. <tr>
  390. <th align="right">|.$locale->text('E-mail').qq|</th>
  391. <td><input name="email" size="30" value="$myconfig->{email}" /></td>
  392. </tr>
  393. <tr valign="top">
  394. <th align="right">|.$locale->text('Signature').qq|</th>
  395. <td><textarea name="signature" rows="3" cols="35">$myconfig->{signature}</textarea></td>
  396. </tr>
  397. <tr>
  398. <th align="right">|.$locale->text('Phone').qq|</th>
  399. <td><input name="tel" size="14" value="$myconfig->{tel}" /></td>
  400. </tr>
  401. <tr>
  402. <th align="right">|.$locale->text('Fax').qq|</th>
  403. <td><input name="fax" size="14" value="$myconfig->{fax}" /></td>
  404. </tr>
  405. <tr>
  406. <th align="right">|.$locale->text('Company').qq|</th>
  407. <td><input name="company" size="35" value="$myconfig->{company}" /></td>
  408. </tr>
  409. <tr valign="top">
  410. <th align="right">|.$locale->text('Address').qq|</th>
  411. <td><textarea name="address" rows="4" cols="35">$myconfig->{address}</textarea></td>
  412. </tr>
  413. </table>
  414. </td>
  415. <td>
  416. <table>
  417. <tr>
  418. <th align="right">|.$locale->text('Date Format').qq|</th>
  419. <td><select name="dateformat">$dateformat</select></td>
  420. </tr>
  421. <tr>
  422. <th align="right">|.$locale->text('Number Format').qq|</th>
  423. <td><select name="numberformat">$numberformat</select></td>
  424. </tr>
  425. <tr>
  426. <th align="right">|.$locale->text('Dropdown Limit').qq|</th>
  427. <td><input name="vclimit" value="$myconfig->{vclimit}" /></td>
  428. </tr>
  429. <tr>
  430. <th align="right">|.$locale->text('Menu Width').qq|</th>
  431. <td><input name="menuwidth" value="$myconfig->{menuwidth}" /></td>
  432. </tr>
  433. <tr>
  434. <th align="right">|.$locale->text('Language').qq|</th>
  435. <td><select name="countrycode">$countrycodes</select></td>
  436. </tr>
  437. <tr>
  438. <th align="right">|.$locale->text('Session Timeout').qq|</th>
  439. <td><input name="newtimeout" value="$myconfig->{timeout}" /></td>
  440. </tr>
  441. <tr>
  442. <th align="right">|.$locale->text('Stylesheet').qq|</th>
  443. <td><select name="userstylesheet">$selectstylesheet</select></td>
  444. </tr>
  445. $printer
  446. <tr>
  447. <th align="right">|.$locale->text('Use Templates').qq|</th>
  448. <td><select name="usetemplates">$usetemplates</select></td>
  449. </tr>
  450. <tr>
  451. <th align="right">|.$locale->text('New Templates').qq|</th>
  452. <td><input name="newtemplates" /></td>
  453. </tr>
  454. <tr>
  455. <th align="right">|.$locale->text('Setup Templates').qq|</th>
  456. <td><select name="mastertemplates">$mastertemplates</select></td>
  457. </tr>
  458. </table>
  459. <input type="hidden" name="templates" value="$myconfig->{templates}" />
  460. </td>
  461. </tr>
  462. <tr class="listheading">
  463. <th colspan="2">|.$locale->text('Database').qq|</th>
  464. </tr>|;
  465. # list section for database drivers
  466. foreach $item (User->dbdrivers) {
  467. print qq|
  468. <tr>
  469. <td colspan="2">
  470. <table>
  471. <tr>|;
  472. $checked = "checked";
  473. if ($myconfig->{dbdriver} eq $item) {
  474. for (qw(dbhost dbport dbuser dbpasswd dbname sid)) { $form->{"${item}_$_"} = $myconfig->{$_} }
  475. $checked = "checked";
  476. }
  477. print qq|
  478. <th align="right">|.$locale->text('Driver').qq|</th>
  479. <td><input name="dbdriver" type="radio" class="radio" value="$item" $checked />&nbsp;$item</td>
  480. <th align="right">|.$locale->text('Host').qq|</th>
  481. <td><input name="${item}_dbhost" size="30" value="$form->{"${item}_dbhost"}" /></td>
  482. </tr>
  483. <tr>|;
  484. print qq|
  485. <th align="right">|.$locale->text('Dataset').qq|</th>
  486. <td><input name="${item}_dbname" size="15" value="$form->{"${item}_dbname"}" /></td>
  487. <th align="right">|.$locale->text('Port').qq|</th>
  488. <td><input name="${item}_dbport" size="4" value="$form->{"${item}_dbport"}" /></td>
  489. </tr>
  490. <tr>
  491. <th align="right">|.$locale->text('User').qq|</th>
  492. <td><input name="${item}_dbuser" size="15" value="$form->{"${item}_dbuser"}" /></td>
  493. <th align="right">|.$locale->text('Password').qq|</th>
  494. <td><input name="${item}_dbpasswd" type="password" size="10" value="$form->{"${item}_dbpasswd"}" /></td>
  495. </tr>|;
  496. print qq|
  497. </table>
  498. <input type="hidden" name="old_dbpasswd" value="$myconfig->{dbpasswd}" />
  499. </td>
  500. </tr>
  501. <tr>
  502. <td colspan="2"><hr size="2" noshade /></td>
  503. </tr>
  504. |;
  505. }
  506. # access control
  507. open(FH, $menufile) or $form->error("$menufile : $!");
  508. # scan for first menu level
  509. @a = <FH>;
  510. close(FH);
  511. if (open(FH, "custom_$menufile")) {
  512. push @a, <FH>;
  513. }
  514. close(FH);
  515. foreach $item (@a) {
  516. next unless $item =~ /\[\w+/;
  517. next if $item =~ /\#/;
  518. $item =~ s/(\[|\])//g;
  519. chop $item;
  520. if ($item =~ /--/) {
  521. ($level, $menuitem) = split /--/, $item, 2;
  522. } else {
  523. $level = $item;
  524. $menuitem = $item;
  525. push @acsorder, $item;
  526. }
  527. push @{ $acs{$level} }, $menuitem;
  528. }
  529. %role = ( 'admin' => $locale->text('Administrator'),
  530. 'user' => $locale->text('User'),
  531. 'supervisor' => $locale->text('Supervisor'),
  532. 'manager' => $locale->text('Manager'));
  533. $selectrole = "";
  534. foreach $item (qw(user admin supervisor manager)) {
  535. $selectrole .= ($myconfig->{role} eq $item) ? "<option selected value=\"$item\">$role{$item}</option>\n"
  536. : "<option value=\"$item\">$role{$item}</option>\n";
  537. }
  538. print qq|
  539. <tr class="listheading">
  540. <th colspan="2">|.$locale->text('Access Control').qq|</th>
  541. </tr>
  542. <tr>
  543. <td><select name="role">$selectrole</select></td>
  544. </tr>
  545. |;
  546. foreach $item (split /;/, $myconfig->{acs}) {
  547. ($key, $value) = split /--/, $item, 2;
  548. $excl{$key}{$value} = 1;
  549. }
  550. foreach $key (@acsorder) {
  551. $checked = "checked";
  552. if ($form->{login}) {
  553. $checked = ($excl{$key}{$key}) ? "" : "checked";
  554. }
  555. # can't have variable names with & and spaces
  556. $item = $form->escape("${key}--$key",1);
  557. $acsheading = $key;
  558. $acsheading =~ s/ /&nbsp;/g;
  559. $acsheading = qq|
  560. <td align="left" nowrap="nowrap" style="background-color: #C7E9F7" colspan="2">
  561. <input name="$item" class="checkbox" type="checkbox" value="1" $checked />&nbsp;$acsheading</td><tr><td>\n|;
  562. $menuitems .= "$item;";
  563. $acsdata = "<td style=\"background-color: #F0F0F0\">";
  564. foreach $item (@{ $acs{$key} }) {
  565. next if ($key eq $item);
  566. $checked = "checked";
  567. if ($form->{login}) {
  568. $checked = ($excl{$key}{$item}) ? "" : "checked";
  569. }
  570. $acsitem = $form->escape("${key}--$item",1);
  571. $acsdata .= qq|<br /><input name="$acsitem" class="checkbox" type="checkbox" value="1" $checked />&nbsp;$item|;
  572. $menuitems .= "$acsitem;";
  573. }
  574. $acsdata .= "
  575. </td>";
  576. print qq|
  577. <tr valign="top">$acsheading $acsdata
  578. </tr>
  579. |;
  580. }
  581. print qq|<input type="hidden" name="acs" value="$menuitems" />
  582. <tr>
  583. <td colspan="2"><hr size="3" noshade /></td>
  584. </tr>
  585. </table>
  586. </div>
  587. |;
  588. }
  589. sub save {
  590. # no driver checked
  591. $form->error($locale->text('Database Driver not checked!')) unless $form->{dbdriver};
  592. # no spaces allowed in login name
  593. $form->{login} =~ s/ //g;
  594. $form->isblank("login", $locale->text('Login name missing!'));
  595. # check for duplicates
  596. if (!$form->{edit}) {
  597. $temp = new User "${LedgerSMB::Sysconfig::memberfile}", "$form->{login}";
  598. if ($temp->{login}) {
  599. $form->error("$form->{login} ".$locale->text('is already a member!'));
  600. }
  601. }
  602. # no spaces allowed in directories
  603. $form->{newtemplates} =~ s/( |\.\.|\*)//g;
  604. if ($form->{newtemplates} ne "") {
  605. $form->{templates} = $form->{newtemplates};
  606. } else {
  607. $form->{templates} = ($form->{usetemplates}) ? $form->{usetemplates} : $form->{login};
  608. }
  609. # is there a basedir
  610. if (! -d "${LedgerSMB::Sysconfig::templates}") {
  611. $form->error($locale->text('Directory').": ${LedgerSMB::Sysconfig::templates} ".$locale->text('does not exist'));
  612. }
  613. # add base directory to $form->{templates}
  614. $form->{templates} = "${LedgerSMB::Sysconfig::templates}/$form->{templates}";
  615. $myconfig = new User "${LedgerSMB::Sysconfig::memberfile}", "$form->{login}";
  616. # redo acs variable and delete all the acs codes
  617. @acs = split /;/, $form->{acs};
  618. $form->{acs} = "";
  619. foreach $item (@acs) {
  620. $item = $form->escape($item,1);
  621. if (!$form->{$item}) {
  622. $form->{acs} .= $form->unescape($form->unescape("$item")).";";
  623. }
  624. delete $form->{$item};
  625. }
  626. # check which database was filled in
  627. $form->{dbhost} = $form->{"$form->{dbdriver}_dbhost"};
  628. $form->{dbport} = $form->{"$form->{dbdriver}_dbport"};
  629. $form->{dbpasswd} = $form->{"$form->{dbdriver}_dbpasswd"};
  630. $form->{dbuser} = $form->{"$form->{dbdriver}_dbuser"};
  631. $form->{dbname} = $form->{"$form->{dbdriver}_dbname"};
  632. $form->isblank("dbname", $locale->text('Dataset missing!'));
  633. $form->isblank("dbuser", $locale->text('Database User missing!'));
  634. foreach $item (keys %{$form}) {
  635. $myconfig->{$item} = $form->{$item};
  636. }
  637. $myconfig->{password} = $form->{old_password};
  638. $myconfig->{password} = $form->{new_password} if $form->{new_password} ne $form->{old_password};
  639. $myconfig->{timeout} = $form->{newtimeout};
  640. delete $myconfig->{stylesheet};
  641. if ($form->{userstylesheet}) {
  642. $myconfig->{stylesheet} = $form->{userstylesheet};
  643. }
  644. $myconfig->{packpw} = 1;
  645. $myconfig->save_member(${LedgerSMB::Sysconfig::memberfile}, ${LedgerSMB::Sysconfig::userspath});
  646. # create user template directory and copy master files
  647. if (! -d "$form->{templates}") {
  648. umask(002);
  649. if (mkdir "$form->{templates}", oct("771")) {
  650. umask(007);
  651. # copy templates to the directory
  652. opendir TEMPLATEDIR, "${LedgerSMB::Sysconfig::templates}/." or $form->error("$templates : $!");
  653. @templates = grep /$form->{mastertemplates}-/, readdir TEMPLATEDIR;
  654. closedir TEMPLATEDIR;
  655. foreach $file (@templates) {
  656. open(TEMP, "${LedgerSMB::Sysconfig::templates}/$file") or $form->error("$templates/$file : $!");
  657. $file =~ s/$form->{mastertemplates}-//;
  658. open(NEW, ">$form->{templates}/$file") or $form->error("$form->{templates}/$file : $!");
  659. while ($line = <TEMP>) {
  660. print NEW $line;
  661. }
  662. close(TEMP);
  663. close(NEW);
  664. }
  665. } else {
  666. $form->error("$form->{templates} : $!");
  667. }
  668. }
  669. $form->redirect($locale->text('User saved!'));
  670. }
  671. sub delete {
  672. $form->{templates} = ($form->{templates}) ? "${LedgerSMB::Sysconfig::templates}/$form->{templates}" : "$templates/$form->{login}";
  673. $form->error("${LedgerSMB::Sysconfig::memberfile} ".$locale->text('locked!')) 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. 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 = new User "${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. User->dbupdate(\%$form);
  917. $form->redirect($locale->text('Dataset updated!'));
  918. }
  919. sub create_dataset {
  920. @dbsources = sort 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. 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')." $form->{db} ".$locale->text('successfully created!')
  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 = 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. 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. }