1. Список говнокодов пользователя AliceGoth

    Всего: 58

  2. Си / Говнокод #11432

    +142

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    void do_statfs(const struct mntent *fs)
    {
    	struct statvfs vfs;
    
       	if (fs->mnt_fsname[0] != '/')	/* skip nonreal filesystems */
       		return;
    
    	if (statvfs(fs->mnt_dir, & vfs) != 0) {
    		fprintf(stderr, "%s: %s: statfs failed: %s\n",
    			myname, fs->mnt_dir, strerror(errno));
    		errors++;
    		return;
    	}
    	if(fi!=1){
    	long used = 100 - (int)(((float)vfs.f_bfree/(float)vfs.f_blocks)*100);
    	printf("%12s", fs->mnt_fsname);//Filesystem
    	printf("%16ld",((vfs.f_blocks)>>10)*vfs.f_bsize);//1K-blocks
     	printf("%11ld", ((vfs.f_blocks - vfs.f_bfree)>>10)*vfs.f_bsize);//Used
    	printf("%11ld",(vfs.f_bavail>>10)*vfs.f_bsize);		//Available
    	if(used>0 && used<=100){
    	printf("%8d%%    ", 100 - (int)(((float)vfs.f_bfree/(float)vfs.f_blocks)*100));//Use%
    	} else { printf("%8s    ","-");}
    	} else {
    	  long used = 100 - (int)(((float)vfs.f_ffree/(float)vfs.f_files)*100);
    	  printf("%8s", fs->mnt_fsname);//Filesystem
    	  printf("%11ld",vfs.f_files);//Inodes
    	  printf("%11ld", (vfs.f_files - vfs.f_ffree));//IUsed
    	  printf("%11ld",vfs.f_ffree);//IFree
    	  if(used>0 && used<=100){
    	    printf("%8d%%    ", used);//Use%
    	} else { printf("%8s    ","-");}
    	}
    	printf("%s\n", fs->mnt_dir);//Mounted on
    }

    Свой df

    AliceGoth, 17 Июля 2012

    Комментарии (0)
  3. Си / Говнокод #11431

    +141

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    65. 65
    66. 66
    67. 67
    68. 68
    69. 69
    70. 70
    71. 71
    72. 72
    73. 73
    74. 74
    75. 75
    76. 76
    77. 77
    78. 78
    79. 79
    80. 80
    81. 81
    82. 82
    83. 83
    84. 84
    85. 85
    86. 86
    87. 87
    88. 88
    89. 89
    90. 90
    91. 91
    92. 92
    93. 93
    94. 94
    95. 95
    char **fpwd=(char**)malloc(160);
    int lstat(const char *path, struct stat *buf);
    int process_dir(const char *dir,struct stat *st1,ino_t cit);
    char *cdir=".";
    ino_t ci=0;
    struct stat cstat;
    int errors = 0;
    char *myname;
    int cnt=0;
    int main(int argc,char **argv){
      myname=argv[0];
      cdir=(char*)malloc(512);
      if(cdir==NULL){
        perror("Not sufficient memory");
        errors++;
        return -1;
      }
       memset(cdir,'\0',512);
      strcat(cdir,cdir);
      strcat(cdir,".");
      if(fpwd==NULL){
        fprintf(stderr, "%s: out of memory: %s\n",
      			myname, strerror(errno));
      		errors++;
     		return 0;
     }
    for(int i=0;i<=160;i++){
      *(fpwd+i)=(char*)malloc(1600);
     if(*(fpwd+i)==NULL){perror("Not sufficient memory");
     errors++;
     return -1;
     }
    }
    while(ci!=2){
      if(lstat(".",&cstat)==-1){
        fprintf(stderr, "%s: can't find file:%s %s\n",
     			myname, cdir, strerror(errno));
        errors++;
    	return -1;
      };
      ci=cstat.st_ino;
      if(process_dir("..",&cstat,ci)==-1){
            fprintf(stderr, "%s: can't process dir:%s %s\n",
     			myname, cdir, strerror(errno));
        errors++;
    	return -1;
      };
      int fd=open("..",O_RDONLY);
      if(fd<0){
       perror("open");
       errors++;return -1;
      }
        if(fchdir(fd)==-1){
          fprintf(stderr, "%s: can't chdir:%s\n",
     			myname, strerror(errno));
        errors++;return -1;
        };
        strcat(cdir,"/..");
    }
     for(int i=cnt-1;i>=0;i--){
        printf("/%s",fpwd[i]);
      }
      printf("\n");return 0;
    }
    int process_dir(const char *dir,struct stat *st1,ino_t cit/*,char **fpwd*/){
        DIR *dp;
        struct dirent *ent;
        struct stat *dstat;
        if ((dp = opendir(dir)) == NULL) {
    		fprintf(stderr, "%s: cannot open for reading: %s\n", dir, strerror(errno));errors++;return -1;
    	}
        if(lstat(dir,dstat)==-1){
    	    fprintf(stderr, "%s: can't find file:%s %s\n",
     			myname, cdir, strerror(errno));
    			errors++;
    	return -1;
          }
    	while ((ent = readdir(dp)) != NULL){
    	  if(ent->d_ino==cit && strcmp(ent->d_name,".")!=0 && strcmp(ent->d_name,"..")!=0){
    	    strcat(fpwd[cnt++],ent->d_name);
    	     if (closedir(dp) != 0) {
    		fprintf(stderr, "%s: closedir: %s\n", dir, strerror(errno));
    		errors++;
    		return 1;
    	      }
    	    return 0;
    	  }
    	}
    	if (closedir(dp) != 0) {
    		fprintf(stderr, "%s: closedir: %s\n", dir, strerror(errno));
    		errors++;
    		return 1;
    	}
    	return 0;
    }

    AliceGoth, 17 Июля 2012

    Комментарии (0)
  4. Си / Говнокод #11374

    +121

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    65. 65
    66. 66
    67. 67
    68. 68
    69. 69
    70. 70
    71. 71
    72. 72
    73. 73
    74. 74
    75. 75
    76. 76
    #include "uni.h"
    
    int getopt_long(int argc, char *const argv[],const char *optstring,const struct option *longopts, int *longindex);
    int getopt__long_only(int argc, char *const argv[],const char *optstring,const struct option *longopts, int *longindex);
    int chown(const char *path, uid_t owner, gid_t group);
    uid_t getuid(void);
    int mkdir(const char *pathname, mode_t mode);
    gid_t getgid(void);
    
    char *dirname;
    mode_t perm;
    uid_t owner;
    gid_t group;
    
    int main(int argc,char **argv){
      owner=getuid();
      group=getgid();
      perm=0600;
    char *pEnd;
    char *dirname=(char*)malloc(16);
      if(dirname==NULL){fprintf(stderr, "out of memory!\n");return -1;}
       memset( dirname,'\0',16); 
       strcat(dirname,argv[argc-1]);
    struct option longopts[] = {
      { "mode", required_argument, NULL, 'm' },
      { "parents", NULL, NULL, 'p'},
      { "verbose", required_argument, NULL, 'v'},
      { "context", required_argument, NULL, 'c'},
      { "help", NULL, NULL, 'h'},
      { "version", NULL, NULL, 'r'},
    { 0, 0, 0, 0 } 
    };
    char c;
    while((c=getopt_long(argc,argv,"m:p:v:c:r:h",longopts,NULL)) != -1) {
      switch (c) {
        case 'm':
          perm=strtol(optarg,&pEnd,8);
          printf("%s\n",pEnd);
          break;
        case 'p':
          if(rmdir(dirname)<0){
            fprintf(stderr, "don't manage to delete folder!\n");return -1;
          }
          break;
        case 'v':
          if(mkdir(dirname,perm)<0){
            fprintf(stderr, "mkdir: cannot create directory `%s`: file exists\n",dirname);return -1;
          } else {
            printf("mkdir: created directory `%s`\n",dirname);
            return 0;
          }
          break;
        case 'c':
          break;
        case 'h':
          printf("Usage: mkdir [OPTION]... DIRECTORY...\n");
          printf("Create the DIRECTORY(ies), if they do not already exist.\n");
          printf("\n");
          printf("Mandatory arguments to long options are mandatory for short options too.\n");
          printf("  -m, --mode=MODE   set file mode (as in chmod), not a=rwx - umask\n");
          printf("  -p, --parents     no error if existing, make parent directories as needed\n");
          printf("  -v, --verbose     print a message for each created directory\n");
          printf("  -Z, --context=CTX  set the SELinux security context of each created\n");
          printf("                      directory to CTX\n");
          printf("      --help     display this help and exit\n");
          printf("      --version  output version information and exit\n");
          printf("\tAuthor AliceGoth\n");
          return 0;
          break;
        case 'r':
          printf("\tMy own mkdir\n");
          printf("\tVersion 1.0\n");
          printf("\tAuthor AliceGoth\n");
          printf("\tEmail [email protected]\n");
          break;
        case 1:

    Мой mkdir

    AliceGoth, 07 Июля 2012

    Комментарии (28)
  5. Си / Говнокод #11373

    +126

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    65. 65
    66. 66
    67. 67
    68. 68
    69. 69
    70. 70
    71. 71
    72. 72
    73. 73
    74. 74
    75. 75
    76. 76
    77. 77
    78. 78
    79. 79
    80. 80
    81. 81
    82. 82
    83. 83
    84. 84
    85. 85
    86. 86
    87. 87
    88. 88
    89. 89
    90. 90
    91. 91
    92. 92
    93. 93
    94. 94
    95. 95
    96. 96
    97. 97
    #include "uni.h"
    #include "xreadlink.h"
    
    int process(char *dir);
    char *cd;
    char *scd;
    struct stat st1;
    
    ino_t cino;
    dev_t cdev;
    int main(){
    cd = (char *)malloc(160+1);
    if(cd==NULL){
     perror("Not enough memory");
     return -1;
    }
    scd = (char *)malloc(1600+1);
    if(scd==NULL){
     perror("Not enough memory");
     return -1;
    }
    memset(cd,'\0',1601);
    memset(scd,'\0',1601);
    strcat(scd,".");
    if(lstat(scd,&st1)==-1){
       perror("stat");
                   exit(EXIT_FAILURE);
    };
    cino = st1.st_ino;
    cdev = st1.st_rdev;
    //printf("inode %lu cdev %llu\n",cino,cdev);
      process(scd);
      return 0;
    };
    
    int process(char *dir){
      DIR *dp;
      struct dirent *ent;
      ino_t lino;
    dev_t ldev;
      ino_t lino2;
    dev_t ldev2;
    int cnt=0;
    char *mydir=(char*)malloc(1600);
    char *mydir2=(char*)malloc(1600);
    char **fpwd=(char**)malloc(160);
    for(int i=0;i<=160;i++){
      *(fpwd+i)=(char*)malloc(1600);
     if(*(fpwd+i)==NULL){perror("Not sufficient memory");
     return -1;
     }
    }
    if(mydir==NULL)return -1;
    if(*fpwd==NULL)return -1;
    strcpy(mydir,dir);
    strcpy(mydir2,dir);
    struct stat lstt;
    struct stat lstt2;
    struct stat stt;
      while(lino!=lino2 || ldev!=ldev2){
        if(lstat(mydir,&lstt)==-1){
            perror("not sufficient memory");
            return -1;
        }
        strcat(mydir2,"/..");
         if(lstat(mydir2,&lstt2)==-1){
            perror("not sufficient memory");
            return -1;
        }
        //printf("yes\n");
        lino=lstt.st_ino;
        ldev=lstt.st_rdev;
        lino2=lstt2.st_ino;
        ldev2=lstt2.st_rdev;
        if ((dp = opendir(mydir2)) == NULL) {
                    fprintf(stderr, "%s: cannot open for reading: %s\n", dir, strerror(errno));
                    return 1;
            }
          if(lstat(mydir2,&stt)==-1){
            perror("not sufficient memory");
            return -1;
          }
          //if(chdir("/")<0){perror("chdir");return -1;};
            while ((ent = readdir(dp)) != NULL){
             if(ent->d_ino==lino && strcmp(ent->d_name,".")!=0 && strcmp(ent->d_name,"..")!=0 && stt.st_rdev==ldev){
                    //printf("%8ld %s\n", ent->d_ino, ent->d_name);
                    strcat(fpwd[cnt++],ent->d_name);
             }
            }
            if (closedir(dp) != 0) {
                    fprintf(stderr, "%s: closedir: %s\n", dir, strerror(errno));
                    return 1;
            }
        //printf("mydir %s inode %lu cdev %llu inode %lu cdev %llu\n",mydir,lino,ldev,lino2,ldev2);
            strcat(mydir,"/..");
        strcpy(mydir2,mydir);
      }

    Поиск текущего каталога в дереве каталогов.

    AliceGoth, 07 Июля 2012

    Комментарии (0)
  6. Си / Говнокод #11280

    +130

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    int print_entry(const char* name, const char* dir,const struct stat* st)
    {
      if(!S_ISDIR(st->st_mode)){
          if(S_ISREG(st->st_mode)){
            printf("<file type=\"regular file\" owner=\"%d\" group=\"%d\">%s/%s</file>\n",st->st_uid,st->st_gid,dir,name);
          };
          if(S_ISCHR(st->st_mode)){
            printf("<file type=\"charcter device\" owner=\"%d\" group=\"%d\">%s/%s</file>\n",st->st_uid,st->st_gid,dir,name);
          }
          if(S_ISBLK(st->st_mode)){
            printf("<file type=\"block device\" owner=\"%d\" group=\"%d\">%s/%s</file>\n",st->st_uid,st->st_gid,dir,name);
          }
          if(S_ISFIFO(st->st_mode)){
            printf("<file type=\"FIFO(named pipe)\" owner=\"%d\" group=\"%d\">%s/%s</file>\n",st->st_uid,st->st_gid,dir,name);
          }
          if(S_ISLNK(st->st_mode)){
             char *linkname;
             ssize_t r;
             char *lname=strcat(dir,"");
             linkname =  new char[st->st_size + 1];
             if (linkname == NULL) {
                fprintf(stderr, "insufficient memory\n");
                exit(EXIT_FAILURE);
             }
            r=readlink(lname, linkname, st->st_size + 1);
            if (r < 0) {
              return 0;
            }
               if (r > st->st_size) {
            fprintf(stderr, "symlink increased in size "
                            "between lstat() and readlink()\n");
            exit(EXIT_FAILURE);
        }
    
            linkname[st->st_size] = '\0';
            printf("<file type=\"symbolic link\" owner=\"%d\" group=\"%d\" linkname=\"%s\">%s/%s</file>\n",st->st_uid,st->st_gid,linkname,dir,name);
          }
          if(S_ISSOCK(st->st_mode)){
            printf("<file type=\"socket\" owner=\"%d\" group=\"%d\">%s/%s</file>\n",st->st_uid,st->st_gid,dir,name);
          }
        }
        return 0;
    }
     
    int main(int argc, char* argv[])
    {
    if(argc != 2)
        {
        fprintf(stderr, "Usage: %s DIR\n", argv[0]);
        exit(1);
        }
        printf("<dir name=\"%s\">\n",argv[1]);
        walk(argv[1], print_entry, 1,0);
        printf("</dir>",argv[1]);
    }

    Создание xml файла всех директорий, поддиректорий и их файлов

    AliceGoth, 22 Июня 2012

    Комментарии (23)
  7. PHP / Говнокод #11274

    +50

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    65. 65
    66. 66
    67. 67
    68. 68
    69. 69
    70. 70
    71. 71
    72. 72
    73. 73
    74. 74
    75. 75
    76. 76
    <?php
     require('url_to_absolute.php');
    ini_set('display_errors','On');
    error_reporting('E_ALL');
    $ext=array(
    'pictures'=>array('bmp','jpg','jpeg','pgm','rgb','tga','png','gif','ico'),
    'docs'=>array('rtf','doc','docx','pdf','txt'),
    'html'=>array('shtml','html','xml','css','htm','xhtml'),
    'audio'=>array('mp3','mp4','mpeg','flv','3gp','webm'),
    'arch'=>array('zip','rar','gz','bz2','tar','7zip','ar','tar\.gz','tar\.bz2','xz'),
    'pack'=>array('deb','rpm','jar'),
    'scripts'=>array('sh','pl','py','php','js')
    );
    $murl="";
    $sext="";
    $routh='|((?<=[" ])[^" ]+/[a-z0-9-_%.]+\.';
    foreach($ext as $sk=>$sval){
    foreach($sval as $exts){
      $routh.='(?!'.$exts.'")';
    }
    }
    $routh.='[a-z0-9]{1,5}(?=[" ]))|i';
    echo $routh."<br\ >";
    if(isset($_GET['url'])){
    $url=$_GET['url'];echo $url."<br>";
    preg_match('|(ftp)?(http)?(?:s)?://[a-z0-9-]+\.[a-z]+(\.[a-z0-9-_&+?=%]+)*(?::[0-9]+)?|i',$url,$ures);
    if(!empty($ures[0])){echo $ures[0];$murl=$ures[0];echo "<br>murl ".$murl."<br> ";}
    $html=file_get_contents($url);
    
    foreach($ext as $key=>$val){
    echo "<h2>$key</h2><br\>";
    foreach($val as $mext){
    echo "$mext<br>";
    preg_match_all('|((/[.a-z0-9_-]*)*/[a-z0-9-_.%]+\.'.$mext.'(?![a-z])(?!/))|i',$html,$result);
      if(!empty($result)){
      if(!empty($result[0])){
        $result[0]=array_unique($result[0]);
      foreach($result[0] as $vres){
        $aurl=url_to_absolute($url,$vres);
        echo("<a href=\"$aurl\">".$aurl."</a> ");}
    }
    }
    preg_match_all('|((http(?:s)?://)[a-z0-9-]+\.[a-z]+(?:\.[a-z0-9-_&+?=%]+)*(?::[0-9]+)?(?:/[a-z0-9_-.]*)/[.a-z0-9-_%]+\.'.$mext.'(?![a-z])(?!/))|i',$html,$result);
    if(!empty($result)){
    if(!empty($result[0])){
      $result[0]=array_unique($result[0]);
      foreach($result[0] as $vres){
        $aurl=url_to_absolute($url,$vres);
    echo("<a href=\"$aurl\">".$aurl."</a> ");}
    }
    }
    preg_match_all('|((?<=[" ])[^" ]+\.'.$mext.'(?=[" ]))|i',$html,$result);
    if(!empty($result)){
    if(!empty($result[0])){
    $result[0]=array_unique($result[0]);
    foreach($result[0] as $vres){
        $aurl=url_to_absolute($url,$vres);
    echo("<a href=\"$aurl\">".$aurl."</a> ");}
    }
    }
    
    }
    }
    preg_match_all($routh,$html,$result);
    if(!empty($result)){
    if(!empty($result[0])){
    $result[0]=array_unique($result[0]);
    echo "<br><h2>Other documents</h2><br>";
    foreach($result[0] as $vres){
        $aurl=url_to_absolute($url,$vres);
    echo("<a href=\"$aurl\">".$aurl."</a><br \> ");
    }
    }
    }
    } else { printf("No url\n");}
    ?>

    Вытягивает ссылки на картинки с html файла

    AliceGoth, 21 Июня 2012

    Комментарии (6)
  8. PHP / Говнокод #11273

    +142

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    65. 65
    66. 66
    67. 67
    68. 68
    69. 69
    70. 70
    71. 71
    72. 72
    73. 73
    74. 74
    75. 75
    76. 76
    <?php
     require('url_to_absolute.php');
    ini_set('display_errors','On');
    error_reporting('E_ALL');
    $ext=array(
    'pictures'=>array('bmp','jpg','jpeg','pgm','rgb','tga','png','gif','ico'),
    'docs'=>array('rtf','doc','docx','pdf','txt'),
    'html'=>array('shtml','html','xml','css','htm','xhtml'),
    'audio'=>array('mp3','mp4','mpeg','flv','3gp','webm'),
    'arch'=>array('zip','rar','gz','bz2','tar','7zip','ar','tar\.gz','tar\.bz2','xz'),
    'pack'=>array('deb','rpm','jar'),
    'scripts'=>array('sh','pl','py','php','js')
    );
    $murl="";
    $sext="";
    $routh='|((?<=[" ])[^" ]+/[a-z0-9-_%.]+\.';
    foreach($ext as $sk=>$sval){
    foreach($sval as $exts){
      $routh.='(?!'.$exts.'")';
    }
    }
    $routh.='[a-z0-9]{1,5}(?=[" ]))|i';
    echo $routh."<br\ >";
    if(isset($_GET['url'])){
    $url=$_GET['url'];echo $url."<br>";
    preg_match('|(ftp)?(http)?(?:s)?://[a-z0-9-]+\.[a-z]+(\.[a-z0-9-_&+?=%]+)*(?::[0-9]+)?|i',$url,$ures);
    if(!empty($ures[0])){echo $ures[0];$murl=$ures[0];echo "<br>murl ".$murl."<br> ";}
    $html=file_get_contents($url);
    
    foreach($ext as $key=>$val){
    echo "<h2>$key</h2><br\>";
    foreach($val as $mext){
    echo "$mext<br>";
    preg_match_all('|((/[.a-z0-9_-]*)*/[a-z0-9-_.%]+\.'.$mext.'(?![a-z])(?!/))|i',$html,$result);
      if(!empty($result)){
      if(!empty($result[0])){
        $result[0]=array_unique($result[0]);
      foreach($result[0] as $vres){
        $aurl=url_to_absolute($url,$vres);
        echo("<a href=\"$aurl\">".$aurl."</a> ");}
    }
    }
    preg_match_all('|((http(?:s)?://)[a-z0-9-]+\.[a-z]+(?:\.[a-z0-9-_&+?=%]+)*(?::[0-9]+)?(?:/[a-z0-9_-.]*)/[.a-z0-9-_%]+\.'.$mext.'(?![a-z])(?!/))|i',$html,$result);
    if(!empty($result)){
    if(!empty($result[0])){
      $result[0]=array_unique($result[0]);
      foreach($result[0] as $vres){
        $aurl=url_to_absolute($url,$vres);
    echo("<a href=\"$aurl\">".$aurl."</a> ");}
    }
    }
    preg_match_all('|((?<=[" ])[^" ]+\.'.$mext.'(?=[" ]))|i',$html,$result);
    if(!empty($result)){
    if(!empty($result[0])){
    $result[0]=array_unique($result[0]);
    foreach($result[0] as $vres){
        $aurl=url_to_absolute($url,$vres);
    echo("<a href=\"$aurl\">".$aurl."</a> ");}
    }
    }
    
    }
    }
    preg_match_all($routh,$html,$result);
    if(!empty($result)){
    if(!empty($result[0])){
    $result[0]=array_unique($result[0]);
    echo "<br><h2>Other documents</h2><br>";
    foreach($result[0] as $vres){
        $aurl=url_to_absolute($url,$vres);
    echo("<a href=\"$aurl\">".$aurl."</a><br \> ");
    }
    }
    }
    } else { printf("No url\n");}
    ?>

    Вытягивает ссылки на картинки с html файла

    AliceGoth, 21 Июня 2012

    Комментарии (3)
  9. PHP / Говнокод #11272

    +41

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    65. 65
    66. 66
    67. 67
    68. 68
    69. 69
    70. 70
    71. 71
    72. 72
    73. 73
    74. 74
    75. 75
    76. 76
    77. 77
    78. 78
    79. 79
    80. 80
    81. 81
    82. 82
    83. 83
    84. 84
    85. 85
    86. 86
    87. 87
    88. 88
    89. 89
    90. 90
    91. 91
    92. 92
    93. 93
    94. 94
    95. 95
    96. 96
    <?php
    ini_set('display_errors','On');
    error_reporting('E_ALL');
    mysql_connect("localhost","MySQL","satanus") or die(mysql_error());
    echo "Connected to mysql<br>";
    mysql_select_db("myurl") or die(mysql_error());
    echo "Connected to Database";
    $ms=mysql_info();
    echo $ms;
    
    function isValidURL($url)
    {
    return preg_match('|^(http)(s)?://([a-z0-9-]+\.[a-z-]+)?(localhost)?(\.[a-z0-9-_/&+?=%]+)*(:[0-9]+)?(/[^.]+)?$|i', $url);
    }
    function parse_secure($arg){
      $txt=preg_replace('/((<[^>]*>(.*)<\/[^>]*>|\'|")|(<[^>]*>)|(?:(\s+|>|<|\d+)(?:SELECT|FROM|UNION|ORDER BY|GROUP BY|UPDATE|DELETE|INSERT|OR|AND|NOT)(\s+|>|<|\d+))|<)/i','',$arg);
      return $txt;
    }
    
    if(isset($_GET['pid'])){
        $pid=$_GET['pid'];
        $pid=parse_secure($pid);
        $options=array('options'=>array('min_range'=>0,'max_range'=>1000001));
          if(filter_var($pid,FILTER_VALIDATE_INT,$options)){
            printf("pid correct %d",$pid);
        } else {
            printf("pid incorrect");exit(2);  
        }
        $query="SELECT url FROM myurl.base WHERE id='$pid'";
        $res=mysql_query($query);
        if($res){
          $row=mysql_fetch_assoc($res);
          header('Location: '.$row['url']);
        }
    };
    
    if(isset($_GET['cat']) && isset($_GET['scat'])){
      $cat=$_GET['cat'];
      $cat=parse_secure($cat);
      if(isset($_GET['ps'])){
        $ps = $_GET['ps'];
        $ps=parse_secure($ps);
      } else {
      $ps =0;
      };
      $catl=iconv_strlen($thm);
      echo "<html><head><title>Short url generator</title></head><body>";
      echo "<h1>$cat</h1><br>";
          $qry="SELECT bs.id as pid,bs.url url,bs.subcategory scat,bs.category cat FROM base bs INNER JOIN category ct ON ct.id=bs.category WHERE bs.subcategory=\"".$_GET['scat']."\" AND bs.category=\"".parse_secure($_GET['cat'])."\"";
          $res=mysql_query($qry);
          if($res){
            while($row=mysql_fetch_assoc($res)){
              echo "<a href=\"http://".$_SERVER['SERVER_NAME'].$_SERVER['SCRIPT_NAME']."?pid=".$row['pid']."\">http://".$_SERVER['SERVER_NAME'].$_SERVER['SCRIPT_NAME']."?pid=".$row['pid']."</a> ".$row['url'];
              echo " <a href=\"http://".$_SERVER['SERVER_NAME'].$_SERVER['SCRIPT_NAME']."?cat=".$row['cat']."&scat=".$row['scat']."\">http://".$_SERVER['SERVER_NAME'].$_SERVER['SCRIPT_NAME']."?cat=".$row['cat']."&scat=".$row['scat']."</a>".$row['url'];
              echo "<br>";
            }
          }
    exit(3);
    };
    
    if(isset($_GET['cat'])){
      $cat=parse_secure($_GET['cat']);
      $scat=parse_secure($_GET['scat']);
      if(isset($_GET['ps'])){
        $ps = $_GET['ps'];
      } else {
      $ps =0;
      };
      $catl=iconv_strlen($thm);
      echo "<html><head><title>Short url generator</title></head><body>";
      echo "<h1>$cat</h1><br>";
          $qry="SELECT bs.id as pid,bs.url url,bs.subcategory scat,bs.category cat FROM base bs INNER JOIN category ct ON ct.id=bs.category WHERE bs.category=\"".$cat."\" OR ( bs.subcategory=\"".$scat."\" AND bs.category=\"".$cat."\")";
          $res=mysql_query($qry);
          if($res){
            while($row=mysql_fetch_assoc($res)){
              echo "<a href=\"http://".$_SERVER['SERVER_NAME'].$_SERVER['SCRIPT_NAME']."?pid=".$row['pid']."\">http://".$_SERVER['SERVER_NAME'].$_SERVER['SCRIPT_NAME']."?pid=".$row['pid']."</a>".$row['url'];
              echo " <a href=\"http://".$_SERVER['SERVER_NAME'].$_SERVER['SCRIPT_NAME']."?cat=".$row['cat']."&scat=".$row['scat']."\">http://".$_SERVER['SERVER_NAME'].$_SERVER['SCRIPT_NAME']."?cat=".$row['cat']."&scat=".$row['scat']."</a>".$row['url'];
              echo "<br>";
            }
          }
    };
    
    if(isset($_POST['url']) && (isset($_POST['category']) || isset($_POST['cat'])) && (isset($_POST['subcat']) || isset($_POST['scat']))){
      $url=$_POST['url'];
    $purl=substr($url,0,26);
      if($purl=="http://".$_SERVER['SERVER_NAME']."/")exit(0);
    $purl=substr($url,0,30);
      if($purl=="http://www.".$_SERVER['SERVER_NAME']."/")exit(0);
      $cat=parse_secure($_POST['category']);
      $catid=parse_secure($_POST['cat']);
      $scat=parse_secure($_POST['subcat']);
      $scatid=parse_secure($_POST['scat']);
      if($url) {
          if(!isValidURL($url))
    {
    $errMsg .= "* Please enter valid URL including http://<br>";

    AliceGoth, 21 Июня 2012

    Комментарии (10)
  10. C++ / Говнокод #11271

    −40

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    #include <stdio.h>
    #include <unistd.h> 
    #include <stdlib.h> 
    #include <string.h>
    #include <iostream>
    #include <string>
    using namespace std;
    
    static char ifnm[100];
    string *tags = new string [100];
    int tags_init(string stag[]){
      int i=0;
      stag[i++]="root";
      stag[i++]="word";
      stag[i++]="english";
      stag[i++]="russian";
      stag[i++]="russian2";
    //  stag[i++]="id";
      return i;
    };
    int main(int argc,char *argv[]){
    FILE *fp;
    if(argc=0){printf("No file name\n");exit(0);}
    strcpy(ifnm,argv[1]);
    fp = fopen(ifnm, "r");
    if (fp == NULL)exit(-1);
      //Error;
    char str[180];
    int tn=tags_init(tags);
    cout<<"<"<<tags[0]<<">"<<endl;
    while(fgets(str, 180,fp))
    {
      fgets(str,180, fp);
      //cout<<str<<endl;
      char *pname;
        pname = strtok (str,"-");
        int ti=0;
        cout<<"<"<<tags[1]<<">"<<endl;
        ti=1;
      while (pname != NULL && ti<=tn)
      {
        ti++;
        cout<<"<"<<tags[ti]<<">"<<endl;
        printf ("\t%s\n",pname);
        cout<<"</"<<tags[ti]<<">"<<endl;
        pname = strtok (NULL, "-");
      }
    cout<<"</"<<tags[1]<<">"<<endl;
    }
    cout<<"</"<<tags[0]<<">"<<endl;
    
    fclose(fp);
    }

    Преобразует текстовый файл в xml формат

    AliceGoth, 21 Июня 2012

    Комментарии (58)
  11. bash / Говнокод #11270

    −118

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    65. 65
    66. 66
    67. 67
    68. 68
    69. 69
    70. 70
    71. 71
    72. 72
    73. 73
    74. 74
    75. 75
    76. 76
    77. 77
    78. 78
    79. 79
    80. 80
    81. 81
    82. 82
    #!/bin/bash
    
    prefix=$HOME"/crypthome"
    pictures=(bmp jpg jpeg pgm rgb tga png gif ico)
    docs=(rtf doc docx pdf txt)
    html=(shtml html xml css htm xhtml xslt xls)
    audio=(mp3 mp4 mpeg flv 3gp webm)
    arch=(zip rar gz bz2 tar 7zip ar tar\.gz tar\.bz2 xz 7z)
    pack=(deb rpm jar)
    scripts=(sh pl py php js cpp c sql)
    conf=(conf cfg)
    torrent=(torrent)
    an=""
    mdt=""
    function get_date
    {
      dt=`date`
      pt1=${dt:4:7}
      pt1=`echo $pt1 | tr [:space:] _`
      echo $pt1
      pt2=${dt:25:25}
      echo $pt2
      mdt=$pt1$pt2
      echo $mdt
    }
    
    function recogn
    {
    recogn_arr=("$@")
    for fname in  ${recogn_arr[@]}  ; do
    if [ -f $fnm ]; then
      rslt=`echo $an" "$fnm | grep -i \.$fname$`;
    if [ -n "$rslt" ]
    then
        echo $rslt
    if [ -d $prefix"/"$an ]; then
        echo "dir" | ls -l $prefix"/"$an
        cd $prefix"/"$an
        pwd
    else
        mkdir $prefix"/"$an
    fi
    pc="Pictures"
    if [[ $an == "Pictures" ]]; then
    get_date
    if [ -d $prefix"/"$an"/"$mdt ]; then
     echo $prefix"/"$an"/"$mdt"/" | xargs -I {} mv $fnm {}
      exit 1
    else
      mkdir -p $prefix"/"$an"/"$mdt
     echo $prefix"/"$an"/"$mdt"/" | xargs -I {} mv $fnm {}
     exit 1
    fi
    fi
        echo $prefix"/"$an"/" | xargs -I {} mv $fnm {}
    fi
    else
      echo "No file"
      exit 1
    fi
    done
    }
    fnm=`find $1 -amin -1 | grep $2$`
    echo $fnm
    an="Pictures"
    recogn "${pictures[@]}"
    an="books"
    recogn "${docs[@]}"
    an="Downloads"
    recogn "${html[@]}"
    an="music"
    recogn "${audio[@]}"
    an="arch"
    recogn "${arch[@]}"
    an="pack"
    recogn "${pack[@]}"
    an="src"
    recogn "${scripts[@]}"
    an="conf"
    recogn "${conf[@]}"
    an="torrent"
    recogn "${torrent[@]}"

    Копирует файлы с определенным расширением в соответствующую директорию.

    AliceGoth, 21 Июня 2012

    Комментарии (4)