Jump to content

andytan91

Members
  • Posts

    43
  • Joined

  • Last visited

    Never

Everything posted by andytan91

  1. thanks guys, i have solved this using JavaScript! I appreciate your help very much
  2. thanks for the replies guys, i think zipping it wouldn't be ideal because my current situation requires user to download winscp.exe to c drive and then run auditgroup.bat straightaway after winscp is downloaded... may i ask how do to generate a separate HTTP request/response? I tried the codes below but it only prompts out the download window for auditgroup.bat if(isset($_POST['submit']) == "Run") { $file = "auditgroup.bat"; $file1= "WinSCP.exe"; //Set headers header("Cache-Control: private"); header("Expires: 0"); header("Pragma: cache"); header("Content-Description: File Transfer"); header("Content-Disposition: attachment; filename=$file1"); header("Content-Type: application/octet-stream"); header("Content-Transfer-Encoding: ASCII"); //Read the file from disk readfile($file1); header("Cache-Control: private"); header("Expires: 0"); header("Pragma: cache"); header("Content-Description: File Transfer"); header("Content-Disposition: attachment; filename=$file"); header("Content-Type: application/octet-stream"); header("Content-Transfer-Encoding: binary"); //Read the file from disk readfile($file); }
  3. Hi guys i am kinda stuck at a part where i want a download button to prompt out two download windows in a click. Currently i am able to prompt out one download window only. I have tried putting another header line of Content Disposition but it doesn't work..i will appreciate if you guys can help me out, thanks! The desired scenario will be WinSCP.exe download prompt will appear first, follow by auditgroup.bat $file1 = "WinSCP.exe"; $file = "auditgroup.bat"; //Set headers header("Cache-Control: private"); header("Expires: 0"); header("Pragma: cache"); header("Content-Description: File Transfer"); header("Content-Disposition: attachment; filename=$file"); header("Content-Type: application/octet-stream"); header("Content-Transfer-Encoding: ASCII"); //Read the file from disk readfile($file);
  4. Edit: Hmm i think what you are suggesting might be right...thanks for the help man! I will post again if i encounter any problem!
  5. Sorry for not being clear..what i want to do is that if that particular string exist in that file, the search function will display the filename. However, as i am using if statement and && operation, i have trouble displaying the filename because if that particular string exist and the others don't, it wont display the file. Ultimately, i want the search function to display the filename if it matches just one preg_match function regardless whether other preg_match function in the if statement can find the other string or not.. Example: User wants to find Service Pack string and Maximum Password Age string which contain "Pass". However, the text file does not contain Audit Account Logon Events" string. Hence, the third preg_match function will not display the file. Sample text Below Service Pack Requirement: Fail Current Settings for Service Pack Requirement: Disabled Maximum Password Age Requirement: Fail Current Settings for Maximum Password Age Requirement: Enabled Minimum Password Length: Pass Current Settings for Minimum Password Length Requirement: Enabled if ((preg_match("/\bService Pack Requirement:(.*)./", $allFiles)) && (preg_match("/\bMaximum Password Age Requirement:(.*)./", $allFiles)) && (preg_match("/\bMinimum Password Length:(.*)./", $allFiles)) && (preg_match("/\bAudit Account Logon Events:(.*)./", $allFiles)) { echo "<a href=\"$file\" target=\"_blank\"> $file </a><br />"; }
  6. Hello guys i am doing a search function whereby users can check whether a setting is Pass or Fail. After user press the search button, it will return the file which contain the settings the user wants. However i have encountered a problem, currently i am using if statement and && operator to search for file so if the file is missing a string whereby the preg_match function couldn't find it, it will not output the file if i check another setting. Hence i am interested on what other options can i use. Also, Is it possible to use while loop? I tried for awhile and my browser just keeps loading and loading. Thanks for the help! Example: I want to check File 1 for Maximum Password Age settings but it does not contain Service Pack Requirement string... if ((preg_match("/\bService Pack Requirement:(.*)./", $allFiles)) && (preg_match("/\bMaximum Password Age Requirement:(.*)./", $allFiles)) && (preg_match("/\bMinimum Password Length:(.*)./", $allFiles)) && (preg_match("/\bAudit Account Logon Events:(.*)./", $allFiles)) { echo "<a href=\"$file\" target=\"_blank\"> $file </a><br />"; }
  7. Eventually i used preg_replace...however i have met a problem here, the strings after Service Pack: are dynamic and thus i cant hardcode " 5.1.2600ServicePack2Build2600" in the replacement array..so how can i pass Example Current Settings stated below into the replacement array? Example Current Settings "Current Settings for Service Pack: 5.1.2600ServicePack2Build2600" foreach($lines as $line) { $string1 = $line; $patterns = array(); $patterns[0] = '/\bCurrent Settings for Service Pack:.*\b/'; $replacements = array(); $replacements[0] = "Current Settings for Service Pack: 5.1.2600ServicePack2Build2600 Recommended Settings for Service Pack: $servicepack"; $string1 = preg_replace($patterns , $replacements , $str
  8. Hello guys i am trying to figure out how to fwrite a string for example "Recommended Settings for Service Pack" under "Current Settings for Service Pack: 5.1.2600ServicePack3Build2600". I figure i cant use line number as an argument because the file report may be dynamic so i will need to use Current Settings as an argument. Please guide me if you have any ideas..thanks:) ! auditreport table ServicePackSetting Service Pack Requirement: Fail Current Settings for Service Pack: 5.1.2600ServicePack3Build2600 MajorAuditandAccountPolicies Maximum Password Age Requirement: Fail Current Settings for Maximum Password Age Requirement: 42 Minimum Password Length: Fail Current Settings for Minimum Password Length Requirement: 0
  9. Hello guys i am trying regex this line string containing $parts = preg_split("/\.\(.*\)\.\(.*\)/", $file); Currently this is what i've done. I would like to only regex the value in the .* placing so i am putting hi as a replacement. However, it doesnt work..i have tried this out for very long..i hope someone can guide me..thanks:) $batch_contents = preg_replace('~\$parts = preg_split\(\"\/\\\.\\\((\.\*\\\)\\\)\\\.\\\((\.\*\\\)\\\)\/\", \$file\);~i' , '\$parts = preg_split\(\"\/\\\.\\\((hi\\\))\\\.\\\((hi\\\))\\\/\", \$file\);', $batch_contents);
  10. hmm i tried $string = "preg_split(\"/\.\(.*\)\.\(.*\)/\", \$file);"; if i do eval($string) and pass it to is_array and count function inside the while loop, theres no result still..
  11. Hello guys i used the eval function but it does not echo anything back in the while loop ..the $new_string function contains "preg_split("/\.\(.*\)\.\(.*\)/", $file);", same as $parts..i need some guidance, thanks! <?php //"$DOCUMENT_ROOT"."new/"; $current_dir = 'C:\xampp\htdocs\Audit_Reports'; //Put in second part, the directory - without a leading slash but with a trailing slash! $dir = opendir($current_dir); // Open the sucker $newArgument = $_POST[argument]; $newArgument1 = $_POST[argument1]; $string ='preg_split("/\.\(.*\)\.\(.*\)/", $file);'; $new_string = preg_replace("#\/\\\.\\\\\(\.\*\\\\\)#","/\.\\($newArgument\)",$string); $new_string = preg_replace("#\\\.\\\\\(\.\*\\\\\)#","\.\\($newArgument1\)", $new_string); echo ("<p><h1>List of Audit Reports:</h1></p><hr><br />"); while ($file = readdir($dir)) // while loop { $parts = preg_split("/\.\(CLIENT\)\.\(.*\)/", $file); // $part = eval($new_string); if (is_array($parts) && count($parts) > 1) { // does the dissected array have more than one part $extension = reset($parts); // set to we can see last file extension if ($extension == "Audit_Report" OR $extension == "audit_report") // is extension ext or EXT ? echo "<a href=\"$file\" target=\"_blank\"> $file </a><br />"; // If so, echo it out else do nothing cos it's not what we want } } echo "<hr><br />"; closedir($dir); // Close the directory after we are done ?> The below codes are done in a while loop Result:ArrayArrayArrayArrayArrayArrayArrayArrayArrayArra yArrayArray $parts = preg_split("/\.\(A\)\.\(A\)/", $file); echo $parts; Result:No Output $part = eval($new_string); echo $part;
  12. I tried the Eval function but it does not echo anything back in the while loop ..the $new_string function contains "preg_split("/\.\(.*\)\.\(.*\)/", $file);", same as $parts The below codes are done in a while loop Result:ArrayArrayArrayArrayArrayArrayArrayArrayArrayArrayArrayArray $parts = preg_split("/\.\(A\)\.\(A\)/", $file); echo $parts; Result:No Output $part = eval($new_string); echo $part;
  13. Hello guys, basically i am doing a search function based on regular expressions. What i have done is to store the string i want to regex as a variable. Variable is named as $new_string -> preg_split("/\.\(.*\)\.\(.*\)/", $file); So inside the while loop, i would like to call another variable to store $new_string. However, I found out that the preg_split function stored inside $new_string doesn't work. If i use preg_split function directly inside the while loop it will work - > refer to //$parts = preg_split("/\.\(.*\)\.\(.*\)/", $file); I have troubleshooted it for like 1 hour plus.hope someone can help me thanks <?php //"$DOCUMENT_ROOT"."new/"; $current_dir = 'C:\xampp\htdocs\Audit_Reports'; //Put in second part, the directory - without a leading slash but with a trailing slash! $dir = opendir($current_dir); // Open the sucker $newArgument = $_POST[argument]; $newArgument1 = $_POST[argument1]; $string ='preg_split("/\.\(.*\)\.\(.*\)/", $file);'; $new_string = preg_replace("#\/\\\.\\\\\(\.\*\\\\\)#","/\.\\($newArgument\)",$string); $new_string = preg_replace("#\\\.\\\\\(\.\*\\\\\)#","\.\\($newArgument1\)", $new_string); echo ("<p><h1>List of Audit Reports:</h1></p><hr><br />"); while ($file = readdir($dir)) // while loop { //$parts = preg_split("/\.\(.*\)\.\(.*\)/", $file); $parts = $new_string; echo $parts; if (is_array($parts) && count($parts) > 1) { // does the dissected array have more than one part $extension = reset($parts); // set to we can see last file extension if ($extension == "Audit_Report" OR $extension == "audit_report") // is extension ext or EXT ? echo "<a href=\"$file\" target=\"_blank\"> $file </a><br />"; // If so, echo it out else do nothing cos it's not what we want } } echo "<hr><br />"; closedir($dir); // Close the directory after we are done ?> <form action="readdirectory.php" method='post'>Search Files:<p> Hostname: <input type="text" name="argument"<p> IP Address: <input type="text" name="argument1"<p> Date: <input type="text" name="argument2"<p> <p><input type="submit" name="submitFinal" value="Update"> <p> </form> </p>
  14. Thanks dude for the help...now the script manages to read every file that i want! However, i am stuck at the file put contents part..lets say for example i have 2 files named Audit_Report_Andy and Audit_Report_Sean. I will need it to output to its individual html file. As of now the problem is the file_put_contents outputs the result of a two files to a single combined html file .. <html> <head> </head> <body> <?php //$file = "Audit_Report.(CLIENT).( 192.168.199.134).(2010-08-1023h59m54s).txt"; //$lines = file($file); foreach(glob("Audit_Report*.txt") as $file){ $lines = file($file); foreach($lines as $line) { $string = $line; $patterns = array(); $patterns[0] = '/\bPass\b/'; $patterns[1] = '/\bFail\b/'; $patterns[2] = '/:/'; $patterns[3] = '/\btable\b/'; $patterns[4] = '/\bendtable\b/'; $patterns[5] = '/\bServicePackSetting\b/'; $patterns[6] = '/\bMajorAuditandAccountPolicies\b/'; $patterns[7] = '/\bAuditPolicy\b/'; $patterns[8] = '/\bAccountPolicy\b/'; $replacements = array(); $replacements[1] = "<font color=red>Fail</font></tr></td>"; $replacements[0] = "<font color=green>Pass</font></tr></td>"; $replacements[2] = ":</td><td>"; $replacements[3] = "<table border=1 cellpadding=1 cellspacing=0 class=whitelinks>"; $replacements[4] = "</table>"; $replacements[5] = "<b>Service Pack</b></td><td></tr></td>"; $replacements[6] = "<b>Major Audit and Account Policies</b></td><td></tr></td>"; $replacements[7] = "<b>Audit Policy</b><br></td><td></tr></td>"; $replacements[8] = "<b>Account Policy</b><br></td><td></tr></td>"; ksort($patterns); ksort($replacements); $a = preg_replace($patterns, $replacements, $string); //echo "$a<br />\n"; file_put_contents(basename($file, substr($file, strpos($file, '.'))) . ".html","<tr><td>$a",FILE_APPEND) or die("Cannot write file"); } }
  15. I tried the glob function, it only show the files which exist in the directory...Hmm what i want is to read and replace every files in the directory starting with the name Audit_Report with the codes under the Foreach statement..hence i will need to find a way for the file() function to accept wildcard extensions..
  16. Hello guys i have been trying to find an alternative file function to read multiple files into an array. My aim is to preg_replace every file in directory starting with Audit_Report with the font colours...i have been googling it for like 2 hours and the closest answer i can get to is using the glob() function but it doesn't work for me still. I would like you guys to give me suggestions if you can..thanks!! <?php $file = "Audit_Report.(SEAN).(192.168.199.129).txt"; $lines = file($file); foreach ($lines as $line) { $string = $line; $patterns = array(); $patterns[0] = '/\bPass\b/'; $patterns[1] = '/\bFail\b/'; $patterns[2]='/\b============ Major Audit and Account Policies============ \b/'; $replacements = array(); $replacements[1] = "<font color=red>Fail</font>"; $replacements[0] = "<font color=green>Pass</font>"; $replacements[2] = "<br><b>==== Major Audit and Account Policies====</b>"; ksort($patterns); ksort($replacements); $a = preg_replace($patterns, $replacements, $string); echo "$a<br />\n"; file_put_contents(basename($file, substr($file, strpos($file, '.'))) . ".html","$a<br />\n", FILE_APPEND) or die("Cannot write file"); } ?>
  17. hello guys i am trying to preg_replace this line --> $parts = preg_split("/\.\(.*\)\.\(.*\)/", $file); The bold characters ".*" is what i am intending to replace with numbers and strings...i hope you guys can help me.. This is the closest i can get to $batch_contents = preg_replace('~(preg_split\("/\\\\.\\\\(\.\*\\\\)\\\\.\\\\()([0-9.]+)(\\\\))~i', '${1}'.$newArgument, $batch_contents);
  18. ahh nevermind...i solved it..thanks all
  19. hello guys i have been trying to regex this string..$blackhole contains "nul"..may i ask what do i need to edit from my current regex? thanks! if %errorlevel% neq 0 ( echo Access This Computer From the Network: Pass >> C:\final.txt) else ( echo Access This Computer From the Network: Fail >> C:\final.txt) $batch_contents = preg_replace('~(if %errorlevel% neq 0 \( echo Access This Computer From the Network: Pass >> )([a-zA-Z0-9-_.*]+)(\) else \( echo Access This Computer From the Network: Fail >> )([a-zA-Z0-9-_.*]+)(\))~','${1}'.$blackhole.'${3}'.$blackhole,$batch_contents);
  20. Hi, I would like to make a search form to search for files in a local file directory. I have been looking around the internet but all I can find are search scripts for mysql. Any help would be appreciated!
  21. Hi guys i am trying to regex this string whereby i could change the digit at the "0" part. The requirement is that i only want the number 1. findstr to change digit when regex is carried out and not number 2 as they are in the same text file....thanks in advance!! 1.findstr /i /C:"LSAAnonymousNameLookup = 0" C:\major_security_settings1.txt 2.findstr /C:"LSAAnonymousNameLookup = 0" C:\major_security_settings1.txt
  22. thanks man..but i have another question.. Right now i am doing an edit policy function which uses the power of regular expression(preg_replace). But i have a problem here. The below is the text output from the DOS command whereby i will need to edit the START_TYPE of the following services. My question is how to make preg_replace to differentiate the START_TYPE that belongs to each service?? or do i have to separate each service to its own text file instead of combining all the services? START_TYPE:DISABLED DISPLAY_NAME:Alerter START_TYPE:AUTO_START DISPLAY_NAME:AutomaticUpdates START_TYPE:DEMAND_START DISPLAY_NAME:BackgroundIntelligentTransferService START_TYPE:DISABLED DISPLAY_NAME:ClipBook
  23. Hello guys basically i am doing an edit policy function which uses the power of regular expression(preg_replace). But i have a problem here. The below is the text output from the DOS command whereby i will need to edit the START_TYPE of the following services. My question is how to make preg_replace to differentiate the START_TYPE that belongs to each service?? START_TYPE:DISABLED DISPLAY_NAME:Alerter START_TYPE:AUTO_START DISPLAY_NAME:AutomaticUpdates START_TYPE:DEMAND_START DISPLAY_NAME:BackgroundIntelligentTransferService START_TYPE:DISABLED DISPLAY_NAME:ClipBook
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.