]> git.llucax.com Git - software/pymin.git/blobdiff - pymin/services/ppp/__init__.py
Merge branch 'master' of git.llucax.com.ar:/var/lib/git/software/pymin
[software/pymin.git] / pymin / services / ppp / __init__.py
index 91070e79cc652441b6909e36cda6a06a31939aab..db2a53541857d45f5f9bb4884563c657e81572d6 100644 (file)
@@ -1,6 +1,9 @@
 # vim: set encoding=utf-8 et sw=4 sts=4 :
 
 # vim: set encoding=utf-8 et sw=4 sts=4 :
 
+import os
+import subprocess
 from os import path
 from os import path
+from signal import SIGTERM
 
 from pymin.seqtools import Sequence
 from pymin.dispatcher import Handler, handler, HandlerError
 
 from pymin.seqtools import Sequence
 from pymin.dispatcher import Handler, handler, HandlerError
@@ -104,7 +107,7 @@ class PppHandler(Restorable, ConfigWriter, ReloadHandler, TransactionalHandler):
         for name in names:
             if name in self.conns:
                 if not self.conns[name]._running:
         for name in names:
             if name in self.conns:
                 if not self.conns[name]._running:
-                    call(('pon', name))
+                    call(('pppd', 'call', name))
                     self.conns[name]._running = True
                     self._dump_attr('conns')
             else:
                     self.conns[name]._running = True
                     self._dump_attr('conns')
             else:
@@ -118,7 +121,12 @@ class PppHandler(Restorable, ConfigWriter, ReloadHandler, TransactionalHandler):
         for name in names:
             if name in self.conns:
                 if self.conns[name]._running:
         for name in names:
             if name in self.conns:
                 if self.conns[name]._running:
-                    call(('poff', name))
+                    if path.exists('/var/run/ppp-' + name + '.pid'):
+                        pid = file('/var/run/ppp-' + name + '.pid').readline()
+                        try:
+                            os.kill(int(pid.strip()), SIGTERM)
+                        except OSError:
+                            pass # XXX report error?
                     self.conns[name]._running = False
                     self._dump_attr('conns')
             else:
                     self.conns[name]._running = False
                     self._dump_attr('conns')
             else:
@@ -154,6 +162,16 @@ class PppHandler(Restorable, ConfigWriter, ReloadHandler, TransactionalHandler):
         else:
             raise ConnectionNotFoundError(name)
 
         else:
             raise ConnectionNotFoundError(name)
 
+    def handle_timer(self):
+        for c in self.conns.values():
+            p = subprocess.Popen(('pgrep', '-f', 'pppd call ' + c.name),
+                                    stdout=subprocess.PIPE)
+            pid = p.communicate()[0]
+            if p.wait() == 0 and len(pid) > 0:
+                c._running = True
+            else:
+                c._running = False
+
     def _write_config(self):
         r"_write_config() -> None :: Generate all the configuration files."
         #guardo los pass que van el pap-secrets
     def _write_config(self):
         r"_write_config() -> None :: Generate all the configuration files."
         #guardo los pass que van el pap-secrets
@@ -178,6 +196,7 @@ class PppHandler(Restorable, ConfigWriter, ReloadHandler, TransactionalHandler):
 
 
 if __name__ == '__main__':
 
 
 if __name__ == '__main__':
+
     p = PppHandler()
     p.conn.add('ppp_c','nico','nico',type='PPP',device='tty0')
     p.conn.add('pppoe_c','fede','fede',type='OE',device='tty1')
     p = PppHandler()
     p.conn.add('ppp_c','nico','nico',type='PPP',device='tty0')
     p.conn.add('pppoe_c','fede','fede',type='OE',device='tty1')
@@ -185,3 +204,4 @@ if __name__ == '__main__':
     p.commit()
     print p.conn.list()
     print p.conn.show()
     p.commit()
     print p.conn.list()
     print p.conn.show()
+