Django-based control (running of Web Server shell scripts) Guide
<! Doctype HTML public "-// W3C // dtd html 4.01 transitional // en" <br/> "http://www.w3.org/TR/html4/loose.dtd"> <br/> <HTML> <br/> <pead> <br/> <meta http-equiv = "Content-Type" content = "text/html; charset = utf8 "> <br/> <title> pop up </title> <br/> <MCE: script language =" JavaScript "> <! -- <Br/> function closeit () {<br/> setTimeout ("self. close () ", 10000 )//.. <br/>}< br/> // --> </MCE: SCRIPT> <br/> </pead> <br/> <body onload = "closeit () "> <br/> <p align =" Left "> after 10 second, this page will be forced to close automatically. <br/> <form> <br/> <input type = 'button 'value = 'close' onclick = 'window. close () '> <br/> </form> <br/> </body> <br/> </ptml>
In this page.html, two functions are implemented.
1. the pop-up page is automatically closed in 10 seconds.
2. added an auto-close button.
How did the pop-up page pop up?
<Script language = "JavaScript" type = "text/JavaScript"> <! -- <Br/> window. open ('page.html ', 'newwindow', 'height = 100, width = 400, Top = 0, Left = 0, toolbar = No, menubar = No, scrollbars = No, resizable = No, location = No, status = no') <br/> // --> </MCE: SCRIPT>
Place this script in the header and automatically open the page.html page.
Add in page.html
<Form method = "Post" Action = "/711/auth/"> <br/> <p align = "Left" class = "style5"> step one, account authentication: <br/> <input type = "Submit" name = "submit2" value = "authentication"> <br/> </form> <br/>
When you click the authentication button, the/711/auth function is executed.
In URLs,
From Django. conf. URLs. defaults import * </P> <p> # uncomment the next two lines to enable the admin: <br/> # from Django. contrib import admin <br/> # admin. autodiscover () </P> <p> urlpatterns = patterns ('', <br/> # example: <br/> (R' ^ 711/index/$ ', 'webcontrol. foo. web '), <br/> (R' ^ 711/index/page.html $', 'webcontrol. foo. pop '), <br/> (R' ^ 711/auth/$', 'webcontrol. foo. auth '), <br/> (R' ^ 711/auth/page.html $', 'webcontrol. foo. pop '), <br/> (R' ^ 711/refresh/$', 'webcontrol. foo. refresh '), <br/> (R' ^ 711/refresh/page.html $', 'webcontrol. foo. pop '), <br/> (R' ^ 711/Firewall/$', 'webcontrol. foo. firewall'), <br/> (R' ^ 711/Firewall/page.html $ ', 'webcontrol. foo. pop '), <br/> (R' ^ 711/auto/$', 'webcontrol. foo. auto'), <br/> (R' ^ 711/auto/page.html $ ', 'webcontrol. foo. pop '), </P> <p> # uncomment the admin/DOC line below and add' Django. contrib. admindocs '<br/> # To installed_apps to enable admin documentation: <br/> # (R' ^ admin/doc/', include ('django. contrib. admindocs. URLs '), </P> <p> # uncomment the next line to enable the admin: <br/> # (R' ^ admin /(. *) ', admin. site. root), <br/>) <br/>
'Webcontrol. Foo. Auth.
Let's look at what 'webcontrol. Foo. Auth is. This is in Foo. py:
from Django. shortcuts import render_to_response <br/> Import OS </P> <p> def web (request): <br/> return render_to_response('index.html ') <br/> def auto (request ): <br/> OS. system ("sudo/home/fpzeng/Server/Debian/routing/auto. sh ") <br/> return render_to_response('popup.html ') <br/> def auth (request): <br/> OS. system ("sudo/home/fpzeng/Server/Debian/routing/inode-client.sh") <br/> return render_to_response('popup.html ') <br/> def refresh (request ): <br/> OS. system ("sudo dhclient eth0") <br/> return render_to_response('popup.html ') <br/> def firewall (request): <br/> OS. system ("sudo/home/fpzeng/Server/Debian/routing/iptbl. sh ") <br/> return render_to_response('popup.html ') <br/> def POP (prequest): <br/> return render_to_response('page.html ') <br/>
Webcontrol. Foo. Auth will execute the "sudo/home/fpzeng/Server/Debian/routing/auto.sh”script file and return to the popup.html page.
In URLs processing, this page is "(R' ^ 711/auth/page.html $ ', 'webcontrol. Foo. Pop '),"
In this way, the shell of the local machine of the finished server can be executed on the WebProgram.
Of course, this sudo permission must be granted to the sudo Group in advance. The user name used to run the apache2 program is www-data.