/[scire]/trunk/scire/script.php
Gentoo

Contents of /trunk/scire/script.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 347 - (show annotations) (download)
Fri Jan 11 03:18:59 2008 UTC (6 years, 3 months ago) by codeman
File size: 4909 byte(s)
adding a regex-replace to strip carriage returns from script data.

1 <?php
2 include('.lib/common.php');
3
4 $smarty->assign('leftbar', "on");
5 $leftbar_menu = array();
6 $leftbar_submenu = array();
7 $smarty->assign('desc', "Manage scripts.");
8 #add_leftbar($leftbar_menu, "Main Settings", "settings.php");
9 #add_leftbar($leftbar_menu, "Clients Page", "settings.php?View=Clients");
10 $smarty->assign('leftbar_submenu_title', "Actions");
11 add_leftbar($leftbar_submenu, "Add Script", "script.php?Action=create");
12
13 if ($_POST['add_script']) {
14 #What are the required fields?
15 #name, description, location, script_data,log_location, success_code, run_as, priority, permission, pp_location, pp_script_data.
16 if ($_POST['addname'] and $_POST['desc']) {
17 $script['name'] = $_POST['addname'];
18 $script['desc'] = $_POST['desc'];
19 } else {
20 $status .= "Error: name or description missing!";
21 }
22 if ($_POST['script_data_type']) {
23 $script['location'] = "Embedded";
24 if ($_POST['script_data_type'] == "load") {
25 $script['script_data'] = $_POST['script_data_upload']; #FIXME how is this done?
26 } elseif ($_POST['script_data_type'] == "manual") {
27 $script['script_data'] = $_POST['script_data_manual'];
28 $script['script_data'] = preg_replace('/\r\n/',"\n",$script['script_data']);
29 }
30 } else {
31 $status .= "Error: You must select a script type (Load from file or manual input!";
32 }
33 if ($_POST['runas_radio']) {
34 $script['run_as'] = $_POST['runas_radio'];
35 } elseif ($_POST['runas']) {
36 $script['run_as'] = $_POST['runas'];
37 } else {
38 $status .= "No run_as selected, defaulting to root!!! ";
39 $script['run_as'] = "root";
40 }
41 if ($_POST['priority']) {
42 $script['priority'] = $_POST['priority'];
43 } else {
44 $status .= "No priority selected, defaulting to 5. ";
45 $script['priority'] = "5";
46 }
47 if ($_POST['success_code']) {
48 $script['success_code'] = $_POST['success_code'];
49 } else {
50 $status .= "No success code selected, defaulting to 0. ";
51 $script['success_code'] = "0";
52 }
53 if ($_POST['permission']) {
54 $script['permission'] = $_POST['permission'];
55 }
56 if ($_POST['pps_type']) {
57 $script['pp_location'] = "Embedded";
58 if ($_POST['pps_type'] == "load") {
59 $script['pp_script_data'] = $_POST['pps_load']; #FIXME how is this done?
60 } elseif ($_POST['pps_type'] == "manual") {
61 $script['pp_script_data'] = $_POST['pps_data'];
62 }
63 }
64
65 #Look for tags.
66
67 foreach ($_POST as $name => $value) {
68 if (substr($name,0, 4) == "tag_" and $value) {
69 $temp = substr($name,4);
70 $script_tags[$temp] = $value;
71 }
72 }
73 #Ok, i think we got everything, now lets add it
74 $result = scire_add_script($script['name'], $script['desc'], $script['location'], $script['script_data'], $script['log_location'], $script['success_code'], $script['run_as'], $script['priority'], $script['permission'], $script['pp_location'], $script['pp_script_data'], $script_tags);
75 if (!$result) { #success
76 $status .= "Scipt addition successfull!";
77 } else {
78 $status .= "BAD BAD! Error during query. $result";
79 }
80 } #/if add_script
81 elseif ($_POST['continue']) {
82 #They pressed the continue button, so just repost the fields, and then add tags as we find them.
83 if ($_POST['addname']) { $smarty->assign('addname', $_POST['addname']); }
84 if ($_POST['desc']) { $smarty->assign('desc', $_POST['desc']); }
85 if ($_POST['runas_radio']) { $smarty->assign('runas', $_POST['runas_radio']); }
86 if ($_POST['runas']) { $smarty->assign('runas', $_POST['runas']); }
87 if ($_POST['priority']) { $smarty->assign('priority', $_POST['priority']); }
88 if ($_POST['permission']) { $smarty->assign('permission', $_POST['permission']); }
89 if ($_POST['script_data_manual']) { $script_data = $_POST['script_data_manual']; }
90 #if ($_POST['script_data_upload']) { $script_data = #FIXME some way get this file and parse it. potential security issue? }
91
92 preg_match_all('/%%(.*?)%%/', $script_data, $matches);
93 # pre_var_dump($dyn_tag);
94 # pre_var_dump($matches);
95 $smarty->assign('dyn_tags', $matches[1]);
96
97 }
98
99 $permissions = array();
100 $perm_categories = array();
101 $smarty->assign('priorities', get_priorities() );
102 $all_permissions = $acl->get_objects(NULL, 1, 'ACO');
103 foreach ($all_permissions as $categoryname => $cat) {
104 #print "Perm: $perm<br>Permname: $permname<br>";
105 if ($categoryname != $scire_ui_section) {
106 foreach ($cat as $perm) {
107 $tmp_perm[id] = $acl->get_object_id($categoryname,$perm,'ACO');
108 $tmp_perm[name] = $perm;
109 array_push($permissions, $tmp_perm);
110 }
111 array_push($perm_categories, $categoryname);
112 }
113 }
114 if (!$script_data) {
115 $script_data = '#!/bin/bash' . "\n" . 'emerge sync';
116 }
117 $smarty->assign('script_data', $script_data);
118
119 $smarty->assign('perm_categories',$perm_categories);
120 $smarty->assign('perms', $permissions);
121
122 $smarty->assign('leftbar_menu', $leftbar_menu);
123 $smarty->assign('leftbar_submenu', $leftbar_submenu);
124 $smarty->assign('View', $_GET['View']);
125 $smarty->assign('Action', $_GET['Action']);
126 $smarty->assign('status', $status);
127 $smarty->display('script.tpl');
128 #var_dump($all_permissions);
129 ?>

  ViewVC Help
Powered by ViewVC 1.1.20