# pptp-server-lib.pl # Common functions for PPTP server configuration # XXX help pages BEGIN { push(@INC, ".."); }; use WebminCore; &init_config(); do 'secrets-lib.pl'; %access = &get_module_acl(); $options_pptp = $config{'pptp_ppp_options'} || "/etc/ppp/options.pptp"; # get_config() # Returns the PPTP configuration sub get_config { local @rv; local $lnum = 0; open(FILE, "<".$config{'file'}); while(<FILE>) { s/\r|\n//g; if (/^\s*(#?)\s*(\S+)\s*(\S*)\s*$/) { push(@rv, { 'name' => $2, 'value' => $3, 'enabled' => !$1, 'line' => $lnum, 'index' => scalar(@rv) }); } $lnum++; } close(FILE); return \@rv; } # find_conf(name, &config) sub find_conf { local $c; foreach $c (@{$_[1]}) { if (lc($c->{'name'}) eq lc($_[0]) && $c->{'enabled'}) { return $c->{'value'}; } } return undef; } # save_directive(&config, name, [value]) sub save_directive { local $lref = &read_file_lines($config{'file'}); local ($old) = grep { lc($_->{'name'}) eq lc($_[1]) } @{$_[0]}; if ($old) { if (defined($_[2])) { # Can just update old one $lref->[$old->{'line'}] = "$_[1]\t$_[2]"; } elsif ($old->{'enabled'}) { # Comment out old one $lref->[$old->{'line'}] = "#$old->{'name'}\t$old->{'value'}"; } } elsif (defined($_[2])) { # Add to end of file push(@$lref, "$_[1]\t$_[2]"); } } # get_pptpd_pid() # Returns the PID of the running PPTP server process sub get_pptpd_pid { open(PID, "<".$config{'pid_file'}) || return undef; local $pid = <PID>; $pid = int($pid); close(PID); return $pid; } # get_ppp_hostname() # Returns the hostname that this server uses for authentication sub get_ppp_hostname { local $conf = &get_config(); local $option = &find_conf("option", $conf); $option ||= $config{'ppp_options'}; local @opts = &parse_ppp_options($option); local $name = &find("name", \@opts); return $name ? $name->{'value'} : &get_system_hostname(1); } # parse_ppp_options(file) sub parse_ppp_options { local @rv; local $lnum = 0; open(OPTS, "<".$_[0]); while(<OPTS>) { s/\r|\n//g; s/#.*$//g; if (/^([0-9\.]+):([0-9\.]+)/) { push(@rv, { 'local' => $1, 'remote' => $2, 'file' => $_[0], 'line' => $lnum, 'index' => scalar(@rv) }); } elsif (/^(\S+)\s*(.*)/) { push(@rv, { 'name' => $1, 'value' => $2, 'file' => $_[0], 'line' => $lnum, 'index' => scalar(@rv) }); } $lnum++; } close(OPTS); return @rv; } # find(name, &config) sub find { local @rv = grep { lc($_->{'name'}) eq lc($_[0]) } @{$_[1]}; return wantarray ? @rv : $rv[0]; } # save_ppp_option(&config, file, &old|name, &new) sub save_ppp_option { local $ol = ref($_[2]) || !defined($_[2]) ? $_[2] : &find($_[2], $_[0]); local $nw = $_[3]; local $lref = &read_file_lines($_[1]); local $line; if ($nw) { if ($nw->{'local'}) { $line = $nw->{'local'}.":".$nw->{'remote'}; } else { $line = $nw->{'name'}; $line .= " $nw->{'value'}" if ($nw->{'value'} ne ""); } } if ($ol && $nw) { $lref->[$ol->{'line'}] = $line; } elsif ($ol) { splice(@$lref, $ol->{'line'}, 1); local $c; foreach $c (@{$_[0]}) { $c->{'line'}-- if ($c->{'line'} > $ol->{'line'}); } } elsif ($nw) { push(@$lref, $line); } } # list_connections() # Returns a list of active PPTP connections by checking the process list. # Each element of the list is an array containing the PPP PID, PPTP PID, # client IP, interface, local IP and remote IP, start time and username sub list_connections { local @rv; # Look in the log file for connection messages local (%pppuser, %localip, %remoteip); &open_readfile(LOG, $config{'log_file'}); while(<LOG>) { if (/pppd\[(\d+)\].*authentication\s+succeeded\s+for\s+(\S+)/i) { $pppuser{$1} = $2; } elsif (/pppd\[(\d+)\].*local\s+IP\s+address\s+(\S+)/) { $localip{$1} = $2; } elsif (/pppd\[(\d+)\].*remote\s+IP\s+address\s+(\S+)/) { $remoteip{$1} = $2; } } close(LOG); # Check for running pptpd and pppd processes &foreign_require("proc", "proc-lib.pl"); &foreign_require("net", "net-lib.pl"); local @procs = &proc::list_processes(); local @ifaces = &net::active_interfaces(); foreach $p (@procs) { if ($p->{'args'} =~ /pptpd\s*\[([0-9\.]+)/) { # Found a PPTP connection process .. get the child PPP proc local $rip = $1; local ($ppp) = grep { $_->{'ppid'} == $p->{'pid'} } @procs; local $user = $ppp ? $pppuser{$ppp->{'pid'}} : undef; local $lip; if ($ppp && ($lip=$localip{$ppp->{'pid'}})) { # We got the local and remote IPs from the log file local $rip2 = $remoteip{$ppp->{'pid'}}; local ($iface) = grep { $_->{'address'} eq $lip && $_->{'ptp'} eq $rip } @ifaces; push(@rv, [ $ppp->{'pid'}, $p->{'pid'}, $rip, $iface ? $iface->{'fullname'} : undef, $lip, $rip2, $ppp->{'_stime'}, $user ] ); } elsif ($ppp && $ppp->{'args'} =~ /([0-9\.]+):([0-9\.]+)/) { # Find the matching interface local ($iface) = grep { $_->{'address'} eq $1 && $_->{'ptp'} eq $2 } @ifaces; if ($iface) { push(@rv, [ $ppp->{'pid'}, $p->{'pid'}, $rip, $iface->{'fullname'}, $1, $iface->{'ptp'} || $2, $ppp->{'_stime'}, $user ] ); } else { push(@rv, [ $ppp->{'pid'}, $p->{'pid'}, $rip, undef, $1, $2, $ppp->{'_stime'}, $user ] ); } } elsif ($ppp) { # PPP process doesn't include IPs push(@rv, [ $ppp->{'pid'}, $p->{'pid'}, $rip, undef, undef, undef, $ppp->{'_stime'}, $user ] ); } } } return @rv; } # get_pptpd_version(&out) sub get_pptpd_version { local $out = `$config{'pptpd'} -v 2>&1`; ${$_[0]} = $out; return $out =~ /(PoPToP|pptpd)\s+v?(\S+)/i ? $2 : undef; } # apply_configuration() # Attempts to apply the PPTP server configuration, and returns undef on # success or an error message on failure sub apply_configuration { # Stop first if ($config{'stop_cmd'}) { local $out = &backquote_logged("$config{'stop_cmd'} 2>&1 </dev/null"); return "<pre>$out</pre>" if ($?); } else { local $pid = &get_pptpd_pid(); if (!$pid || !&kill_logged('TERM', $pid)) { return $text{'stop_egone'}; } } # Re-start local $cmd = $config{'start_cmd'} || $config{'pptpd'}; local $temp = &tempname(); local $rv = &system_logged("$cmd >$temp 2>&1 </dev/null"); local $out = `cat $temp`; unlink($temp); if ($rv) { return "<pre>$out</pre>"; } return undef; } 1;
Name | Type | Size | Permission | Actions |
---|---|---|---|---|
help | Folder | 0755 |
|
|
images | Folder | 0755 |
|
|
lang | Folder | 0755 |
|
|
CHANGELOG | File | 213 B | 0644 |
|
acl_security.pl | File | 521 B | 0755 |
|
apply.cgi | File | 283 B | 0755 |
|
backup_config.pl | File | 743 B | 0755 |
|
config | File | 148 B | 0644 |
|
config-debian-linux | File | 254 B | 0644 |
|
config-mandrake-linux | File | 206 B | 0644 |
|
config-open-linux | File | 224 B | 0644 |
|
config-openSUSE-Linux-15.0-ALL | File | 210 B | 0644 |
|
config-suse-linux | File | 214 B | 0644 |
|
config-syno-linux | File | 148 B | 0644 |
|
config-trustix-linux | File | 214 B | 0644 |
|
config-united-linux | File | 214 B | 0644 |
|
config.info | File | 445 B | 0644 |
|
config.info.ca | File | 509 B | 0644 |
|
config.info.de | File | 501 B | 0644 |
|
config.info.es | File | 479 B | 0644 |
|
config.info.fr | File | 0 B | 0644 |
|
config.info.nl | File | 504 B | 0644 |
|
config.info.no | File | 483 B | 0644 |
|
config.info.pt_BR | File | 528 B | 0644 |
|
defaultacl | File | 50 B | 0644 |
|
delete_secrets.cgi | File | 524 B | 0755 |
|
disc.cgi | File | 507 B | 0755 |
|
edit_conf.cgi | File | 2.9 KB | 0755 |
|
edit_options.cgi | File | 4.44 KB | 0755 |
|
edit_secret.cgi | File | 2.99 KB | 0755 |
|
index.cgi | File | 2.72 KB | 0755 |
|
install_check.pl | File | 441 B | 0755 |
|
list_conns.cgi | File | 1.1 KB | 0755 |
|
list_secrets.cgi | File | 1.76 KB | 0755 |
|
log_parser.pl | File | 479 B | 0755 |
|
module.info | File | 216 B | 0644 |
|
module.info.af | File | 0 B | 0644 |
|
module.info.af.auto | File | 138 B | 0644 |
|
module.info.ar | File | 0 B | 0644 |
|
module.info.ar.auto | File | 188 B | 0644 |
|
module.info.be | File | 0 B | 0644 |
|
module.info.be.auto | File | 190 B | 0644 |
|
module.info.bg | File | 0 B | 0644 |
|
module.info.bg.auto | File | 238 B | 0644 |
|
module.info.ca | File | 151 B | 0644 |
|
module.info.ca.auto | File | 14 B | 0644 |
|
module.info.cs | File | 24 B | 0644 |
|
module.info.cs.auto | File | 135 B | 0644 |
|
module.info.da | File | 0 B | 0644 |
|
module.info.da.auto | File | 155 B | 0644 |
|
module.info.de | File | 0 B | 0644 |
|
module.info.de.auto | File | 168 B | 0644 |
|
module.info.el | File | 0 B | 0644 |
|
module.info.el.auto | File | 259 B | 0644 |
|
module.info.es | File | 26 B | 0644 |
|
module.info.es.auto | File | 133 B | 0644 |
|
module.info.eu | File | 0 B | 0644 |
|
module.info.eu.auto | File | 152 B | 0644 |
|
module.info.fa | File | 0 B | 0644 |
|
module.info.fa.auto | File | 233 B | 0644 |
|
module.info.fi | File | 0 B | 0644 |
|
module.info.fi.auto | File | 160 B | 0644 |
|
module.info.fr | File | 0 B | 0644 |
|
module.info.fr.auto | File | 167 B | 0644 |
|
module.info.he | File | 0 B | 0644 |
|
module.info.he.auto | File | 166 B | 0644 |
|
module.info.hr | File | 0 B | 0644 |
|
module.info.hr.auto | File | 157 B | 0644 |
|
module.info.hu | File | 0 B | 0644 |
|
module.info.hu.auto | File | 160 B | 0644 |
|
module.info.it | File | 0 B | 0644 |
|
module.info.it.auto | File | 152 B | 0644 |
|
module.info.ja | File | 0 B | 0644 |
|
module.info.ja.auto | File | 199 B | 0644 |
|
module.info.ko | File | 0 B | 0644 |
|
module.info.ko.auto | File | 166 B | 0644 |
|
module.info.lt | File | 0 B | 0644 |
|
module.info.lt.auto | File | 168 B | 0644 |
|
module.info.lv | File | 0 B | 0644 |
|
module.info.lv.auto | File | 153 B | 0644 |
|
module.info.ms | File | 136 B | 0644 |
|
module.info.ms.auto | File | 14 B | 0644 |
|
module.info.mt | File | 0 B | 0644 |
|
module.info.mt.auto | File | 164 B | 0644 |
|
module.info.nl | File | 24 B | 0644 |
|
module.info.nl.auto | File | 126 B | 0644 |
|
module.info.no | File | 24 B | 0644 |
|
module.info.no.auto | File | 131 B | 0644 |
|
module.info.pl | File | 0 B | 0644 |
|
module.info.pl.auto | File | 143 B | 0644 |
|
module.info.pt | File | 0 B | 0644 |
|
module.info.pt.auto | File | 158 B | 0644 |
|
module.info.pt_BR | File | 29 B | 0644 |
|
module.info.pt_BR.auto | File | 138 B | 0644 |
|
module.info.ro | File | 0 B | 0644 |
|
module.info.ro.auto | File | 162 B | 0644 |
|
module.info.ru | File | 0 B | 0644 |
|
module.info.ru.auto | File | 228 B | 0644 |
|
module.info.sk | File | 0 B | 0644 |
|
module.info.sk.auto | File | 165 B | 0644 |
|
module.info.sl | File | 0 B | 0644 |
|
module.info.sl.auto | File | 145 B | 0644 |
|
module.info.sv | File | 0 B | 0644 |
|
module.info.sv.auto | File | 146 B | 0644 |
|
module.info.th | File | 0 B | 0644 |
|
module.info.th.auto | File | 314 B | 0644 |
|
module.info.tr | File | 0 B | 0644 |
|
module.info.tr.auto | File | 161 B | 0644 |
|
module.info.uk | File | 0 B | 0644 |
|
module.info.uk.auto | File | 200 B | 0644 |
|
module.info.ur | File | 0 B | 0644 |
|
module.info.ur.auto | File | 286 B | 0644 |
|
module.info.vi | File | 0 B | 0644 |
|
module.info.vi.auto | File | 190 B | 0644 |
|
module.info.zh | File | 0 B | 0644 |
|
module.info.zh.auto | File | 136 B | 0644 |
|
module.info.zh_TW | File | 0 B | 0644 |
|
module.info.zh_TW.auto | File | 145 B | 0644 |
|
pptp-server-lib.pl | File | 6.15 KB | 0755 |
|
save_conf.cgi | File | 1.55 KB | 0755 |
|
save_options.cgi | File | 2.56 KB | 0755 |
|
save_secret.cgi | File | 1.48 KB | 0755 |
|
secrets-lib.pl | File | 1.64 KB | 0755 |
|
start.cgi | File | 413 B | 0755 |
|
stop.cgi | File | 456 B | 0755 |
|